1 / 59

Lecture 3 agenda Layouts Intents (both explicit and implicit) ListViews and Adapters

Lecture 3 agenda Layouts Intents (both explicit and implicit) ListViews and Adapters. Layouts in Android. layout_margin (layout means in relation to parent) padding. SP scale independent pixels respects the users' settings for font size. (layout means in relation to parent). weight.

lesterm
Download Presentation

Lecture 3 agenda Layouts Intents (both explicit and implicit) ListViews and Adapters

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 3 agenda Layouts Intents (both explicit and implicit) ListViews and Adapters

  2. Layouts in Android

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

  4. SP scale independent pixels respects the users' settings for font size.

  5. (layout means in relation to parent)

  6. weight

  7. FrameLayout

  8. Fragments...what good are they?

  9. Intents

  10. From Google: An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity)

  11. Activated by Intents Activities Services Broadcast Receivers (aka Receivers) (http://developer.android.com/guide/components/intents-filters.html)

  12. ResultActivity.class Explicit Intent //Explicit; all you need is the Context and the target class Intent itn = new Intent(this, ResultActivity.class); Explicit

  13. ResultActivity.class CORRECT: 5 INCORRECT: 3 PLAYER: Adam Explicit Intent //Explicit; all you need is the packageContext and the target class Intent itn = new Intent(this, ResultActivity.class); itn.putExtra(QuizActivity.CORRECT, mCorrect); itn.putExtra(QuizActivity.INCORRECT, mIncorrect); itn.putExtra(QuizActivity.NAME, mName); Explicit

  14. ComponentName name : Adam Gerber Action email : gerber@cs.uchicago.edu Data ret : something... Scheme Categories Intent Architecture::Action/Data/etc //Explicit; all you need is the ComponentName and optionally the bundle. //Implicit; usually Action/Data and then optionally the bundle. Explicit Implicit

  15. Explicit Intents: intra-app call by name //******************************** //This method works great for intra-app calls between activities //******************************** //use the calling class and the called class as params to constructor. Intent itn = new Intent(this, Second.class); startActivity(itn); //

  16. Explicit Intents: intra-app call by name Intent itnThird = new Intent(this, ThirdActivity.class); itnThird.putExtra("name", "Adam Gerber"); itnThird.putExtra("email", "gerber@cs.uchicago.edu"); startActivity(itnThird);

  17. Implicit Intents: inter-app call Implicit intents are anonymous and loosely-coupled. You request the component like a service of the operating system. Intent itn = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/")); startActivity(itn);

  18. Implicit Intents: Action/Data pairs ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1". ACTION_DIAL content://contacts/people/1 -- Display the phone dialer with the person filled in. ACTION_VIEW tel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what what is considered the most reasonable thing for a particular URI. ACTION_DIAL tel:123 -- Display the phone dialer with the given number filled in. ACTION_EDIT content://contacts/people/1 -- Edit information about the person whose identifier is "1". ACTION_VIEW content://contacts/people/ -- Display a list of people, which the user can browse through. This example is a typical top-level entry into the Contacts application, showing you the list of people.

  19. ComponentName name : Adam Gerber Action email : gerber@cs.uchicago.edu Data ret : something... Scheme Categories Intent Architecture::Bundle (aka extras) //The bundle is a data structure inside the Intent. //It holds key/value pairs. //Keys are always Strings, and values are always primitives, Serializable or Parcelable.

  20. Serializable versus Parcelable Parcelable is an Interface very much like Serializable only it has been optimized for Android. Unlike Serializeable, all the reflection meta-data has been stripped-out of the parcelized object.  

  21. Intents Intent messaging is a facility for late run-time binding between components in the same or different applications.  Intents are handled by the Android OS. In order for the OS to know about a component, it must be declared in the application manifest file. If a component does not define Intent filters, it can only be called by explicit Intents. A component with filters can receive both explicit and implicit intents. 6/12/12

  22. AndroidManifest.xml file Is an inventory of all the components in an application. If the component is not listed there, the Android OS won't know it's there. Not even intra-app component communication will resolve. 6/12/12

  23. Android OS AndroidManifest.xml I *A A A *A

  24. Categories //Use Categories to further refine your Intent //Most important is CATEGORY_DEFAULT <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter>

  25. ListViews and Adapters

  26. Adapters

  27. AdapterViews

  28. Resources in Android

  29. 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.

  30. 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.

  31. 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

  32. Lifecycle in Android

More Related