1 / 55

Lecture 2: Setting up Projects Properly, Review Git Config, Java Event Model, Anatomy of an Android Application

This lecture covers topics such as setting up projects correctly, reviewing git configurations, Java event model, and the anatomy of an Android application. It also includes information on activity lifecycle state changes, saving and restoring state, and the model-view-controller in Android.

brownnicole
Télécharger la présentation

Lecture 2: Setting up Projects Properly, Review Git Config, Java Event Model, Anatomy of an Android Application

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 2 agenda Setting-up projects properly Review git config Java event model Anatomy of and Android Application Activity Lifecycle State Changes; saving and restoring state Model-View-Controller in Android Views, View Groups, Layouts A/S Designer Tool layouts and resources

  2. git config --global user.name "Your Name" git config --global user.email "your_email@whatever.com" csgerber/proCapitalquiz3g csgerber/labLifeCycle3g

  3. What's inside an APK

  4. Basic Git Commands Git Review

  5. add/reset/commit: move files from working-dir to stage-dir(aka index) git add . git add res/. git add src/. git add res/values/strings.xml move files from stage-dir(aka index) to working-dir git reset HEAD . git reset head res/. git reset head src/. git reset head res/values/strings.xml git commit -m “your commit message.”

  6. Reverting (does the exact opposite) git revert 0da8 --no-edit git revert head --no-edit git revert head~3 --no-edit To clear all local changes since last push git reset --hard origin/master To delete a remote branch git push origin :branchName

  7. Amending: Every commit is associated with a sha-1 hash. That hash is derived from 1/ the file changes in that commit and 2/ the previous commit. You can not change any commit unless that commit is at the head. Since no other commits depend on the head, you may safely change the head. To change the head, use git commit --amend -m “your message” git commit --amend --no-edit

  8. Branching: To list the branches in a project: git branch git branch -r git branch --all To create a branch: git checkout -b branchName c39b git checkout -b branchName To delete a branch: git branch -D branchName To checkout a branch: git checkout 7afe git checkout master

  9. Pushing to remotes: To see the remotes: git remote -v show To push to a remote: git push origin master git push --all To clear all local changes since last push git reset --hard origin/master

  10. Android Studio Default keymap: http://android.cs.uchicago.edu/content/slides/keymap.pdf File || settings || keymap

  11. The Event Model

  12. Event-Source (Button) No Event-Listener listening Event (onClick) No Catcher No Event Listener

  13. OnClick-Listener Event-Listener listening Event-Source (Button) Event (onClick) Any Object Catcher ready to catch

  14. Wrong Event

  15. Event source not registered

  16. OnClick-Listener OnMouse-Listener Event-Listener listening Event-Source (Button) Event (onClick) Any Object Event (onMouse) Catcher ready to catch

  17. Resources in Android

  18. Layouts and resources Code: Java (or C if you use NDK) Metafiles: AndroidManifest, project.properties, .gitignore. These all describe the project. Resources “anything in android that is not code or metafiles” Activities have one or more layouts, and all Layouts have a root-ViewGroup. This root-ViewGroup is the container for the Views. R.java (gen directory) is a bridge between your resources and your code. If you want to interact programmatically with a resource, it must have an id.

  19. Inspecting layouts and resources You can view both xml and design mode in AS. You can see how it would look on multiple devices || preview all screens, and toggle with remove previews.

  20. Layouts and resources res directories can have suffixes, such as layout-land, or drawable-hdpi, values-es, etc. These suffixes allow you to differentiate at RUNTIME depending on the settings, hardware, and configuration of the device. For example, if your device is in landscape mode, it'll try to fetch the layout from layout-land first, then it will try to fetch the layout from layout. Vice versa as well; if it's in portait mode, it'll try for layout-port, then layout. shown in preview mode of resource and rotate device

  21. strings.xml <string name="earth">Earth</string> <string name="moon">Moon</string> <string-array name="system"> <item>@string/earth</item> <item>@string/moon</item> </string-array>

  22. colors.xml <color name="gray">#eaeaea</color> <color name="titlebackgroundcolor">#00abd7</color> <color name="titlecolor">#666666</color> <color name="opaque_red">#f00</color><color name="translucent_red">#80ff0000</color> #RGB #ARGB #RRGGBB #AARRGGBB

  23. dimens.xml <dimenname="textview_height">25dp</dimen><dimenname="textview_width">150dp</dimen><dimenname="ball_radius">30dp</dimen><dimenname="font_size">16sp</dimen>

  24. bools.xml <boolname="screen_small">true</bool><boolname="adjust_view_bounds">true</bool>

  25. dp stands for density independent pixels It's relative to a 160 dpi screen. So 1dp is one pixel on a 160dpi screen. Don't worry about calculating the dp's. Android does that for you.

  26. Add resources from the Add Resources from the graphical editor and also manually. #FFFFFF white getResources(). getStringArray(R.array.whatever)

  27. Navigating in Android Studio alt-1 is project view (alt-F1 is show it in project view) alt-2 is favorites (including bookmarks and breakpoints) alt-3 is the search view (cntl-shift-F to find) alt-4 run-console alt-5 is debug alt-6 is android view (ddms, logcat) alt-7 is structure view (see members and methods) alt-9 is changes(VCS) view Look at the margin of your project

  28. Get help cntl-shift-A (find anything in Android studio) Searching (on mac, replace cntrl with command) cntl-F (find something in the local file) cntl-shift-F (find something in the project) Go to file in code (on mac, replace cntrl with command) cntl-N (go to files typically in src) cntl-shift-n (go to any file, including res) cntl-E (open recent files) Go to file in project alt-F1

  29. Go to definition cntl-B (go directly to the method definition) Javadocs cntl-Q (open the javadocs) Live Templates cntl-J adding your own Live Templates (cntl-shift-A “live template”)

  30. Debugging Using the debugger (alt-5) See bookmarks and breakpoints (alt-2) F11 to toggle bookmark Using logcat (alt-6) Using lint and AS analyzer: Analyze || Inspect Code ///TODO this is my todo message

  31. Lifecycle in Android

  32. proCapitalQuiz (in class)

  33. labLifeCycle (in class)

  34. Layouts in Android

  35. layout_margin (layout means in relation to parent) padding

  36. (layout means in relation to parent)

  37. weight

  38. FrameLayout

More Related