1 / 35

Android Introduction

Android Introduction. Outlines. Acitivity Lifecycle UI View UI Input State. What is Android .

dalia
Download Presentation

Android Introduction

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. Android Introduction

  2. Outlines • Acitivity Lifecycle • UI View • UI Input • State

  3. What is Android • “Android is a software stack for mobile devices that includes an operation system, middleware and key apllications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.”

  4. The Sample Application

  5. Preconditions • Install Java 6 • Install Android SDK • Learn Java

  6. Project: Directory and Files Prject Src Gen Assets Res - drawable-hdpi - drawable-mdpi - drawable-ldpi - layout - menu - values

  7. File: AndroidManifext.xml • Configuration for the application • Versioning, icon, initializatioon <manifest package="com.monead.games.android.sequence" android:versionName="01.06" android:versionCode="17"> <application android:icon="@drawable/launch_seq" android:label="@string/title_app_name"> <activity android:name=".Sequence" Android:label="@string/title_app_name"> <intent-filter>...</intent-filter> </activity> </application> <uses-sdkandroid:targetSdkVersion="8" android:minSdkVersion="4"> </uses-sdk> </manifest>

  8. Directory:src • Application source code\

  9. Directory: res/drawable-* • Image files • 3 directories to deal with various screen resolutions

  10. Directory:res/layout • UI definitions • Layouts • Widgets

  11. Directory: res/main • Defines first interface to the user

  12. Directory: res/values • Constants, supports internationalization

  13. Activity Lifecycle • An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.

  14. Activity Lifecycle Depiction

  15. Lifecycle Method • Void onCreate(Bundle savedInstanceState) • Void onStart() • Void onRestart() • Void onResume() • Void onPause() • Void onStop() • Void onDestroy()

  16. onCreate(Bundle savedState)

  17. onPause() and onResume

  18. Explore Some Source Code • We’ll switch to Eclipse and look at an Activity using some lifecycle methods

  19. UI View • Perferred approach to define the UI is to use XML files located in the res/layout directory • Using the Eclipse plugin for Android development simplifies the development cycle since there is a build step required to turn the UI definitions into code so that you may programmatically access the widgets defined in the XML file

  20. Simple Layout

  21. Code using the Prior UI

  22. Result Screen

  23. Prgrammatic UI • Can define the vew by extending the android.view.view class • Overrie the onDray(Canvas canvas) method • Receives a Canvas instance, which represents the screen • Use invalidate() method to force the view to redraw itself on the device

  24. Drawing on Canvas

  25. Resulting Screen

  26. Internationalization • Define strings in a resource file • Examples

  27. res/values/strings.xml • <?xml version="1.0" encoding="utf-8"?> • <resources> • <string name="app_name">Sudoku</string> • <string name="main_title">Android Sudoku</string> • <string name="continue_label">Continue</string> • <string name="new_game_label">New Game</string> • <string name="about_label">About</string> • <string name="exit_label">Exit</string> • <string name="settings_label">Settings...</string> • <string name="settings_title">Sudoku settings</string> • <string name="settings_shortcut">s</string> ........

  28. Res/values/color.xml • <?xml version="1.0" encoding="utf-8" ?> • <resources> • <color name="background">#00000000</color> • <color name="puzzle_background">#ffe6f0ff</color> • <color name="puzzle_hilite">#ffffffff</color> • <color name="puzzle_light">#64c6d4ef</color> • <color name="puzzle_dark">#6456648f</color> • <color name="puzzle_foreground">#ff000000</color> • <color name="puzzle_foreground_input">#ff0000ff</color> • <color name="puzzle_hint_0">#64ff0000</color> • <color name="puzzle_hint_1">#6400ff80</color> • <color name="puzzle_hint_2">#2000ff80</color> • <color name="puzzle_selected">#64ff8000</color> • <color name="puzzle_red">#ffffff00</color> • </resources>

  29. Get a Value – In a View • <?xml version="1.0" encoding="utf-8"?> • <ScrollView • xmlns:android="http://schemas.android.com/apk/res/android" • android:orientation="vertical" • android:layout_width="match_parent" • android:layout_height="match_parent" • android:padding="10dip"> • <TextView • android:id= "@+id/about_content" • android:layout_width="wrap_content" • android:layout_height="wrap_content" • android:text="@string/about_text" • /> • </ScrollView>

  30. Get a Value In Program

  31. UI Input Typical input sources – Keyboard – Touch Screen Event-based Paradigm – Register to listen for device events

  32. Could be physical or vitual • - No difference for developer • Activity will receive the events using callback methods • - Override to process input • onKeyDown() • onKeyUp() • onKeyLongPress() • onKeyMultiple()

  33. onKeyDown() Example

  34. Persisting State The Android SDK provides emulators that can mimic a variety of Android versions, screen dimensions and phone behaviors Runs slower than on a real phone So don't get too worried if your application feels sluggish in the emulator Provides support for all the features and lifecycle events including persistingstate, writing local files, etc From Eclipse it launches automatically when you run the application

  35. Questions?

More Related