40
ANDROID TRAINING SESSION – 2 -Hussain KMR Behestee

Android session 2-behestee

Embed Size (px)

DESCRIPTION

Android Training session at Jaxara IT

Citation preview

Page 1: Android session 2-behestee

ANDROID TRAININGSESSION – 2

-Hussain KMR Behestee

Page 2: Android session 2-behestee

AGENDAS

• UI Design for Android– Layout– Drawable

• Activity• Intent

– Explicit Intent – Implicite Intent

Page 3: Android session 2-behestee

UI DESIGN FOR ANDROID

Page 4: Android session 2-behestee

UI DESIGN FOR ANDROID

• Layout– Common layout

• Linear layout• Relative layout

– Layout with adapter• Grid View• List View

Page 5: Android session 2-behestee

LAYOUT

Page 6: Android session 2-behestee

COMMON LAYOUT

Linear Relative

Page 7: Android session 2-behestee

LINEAR LAYOUT

Page 8: Android session 2-behestee

RELATIVE LAYOUT

Page 9: Android session 2-behestee

RELATIVE LAYOUT• android:layout_alignParentTop

– If "true", makes the top edge of this view match the top edge of the parent. • android:layout_centerVertical

– If "true", centers this child vertically within its parent. • android:layout_below

– Positions the top edge of this view below the view specified with a resource ID.

• android:layout_toRightOf – Positions the left edge of this view to the right of the view specified with a

resource ID.

These are just a few examples. All layout attributes are documented at RelativeLayout.LayoutParams.

Page 10: Android session 2-behestee

LAYOUT WITH ADAPTER

Grid View List View

Page 11: Android session 2-behestee

GRIDS

Page 12: Android session 2-behestee

GRIDS

Page 13: Android session 2-behestee

LIST

Page 14: Android session 2-behestee

LISTCreating adapter

Setting adapter

Adding click listener

Page 15: Android session 2-behestee

UI DESIGN FOR ANDROID

• Drawables– State List

• Drawable / Color

– Styles– Themes– Menu– Nine-Patch

Page 16: Android session 2-behestee

STATE LIST

— android:state_pressed

— android:state_focused

— android:state_hovered

— android:state_selected

— android:state_checkable

— android:state_checked

— android:state_enabled

— android:state_activated

— android:state_window_focused

Page 17: Android session 2-behestee

DRAWABLE / COLOR

• android:drawable – Drawable resource. Required. Reference to a

drawable resource• android:color

– Hexadeximal color. Required. RGB value or Alpha-Red-Green-Blue

Page 18: Android session 2-behestee

DRAWABLE / COLOR

android:drawable- File name with res/drawable/button.xml

Page 19: Android session 2-behestee

DRAWABLE / COLOR

android:color- File name with res/color/buttontext.xml

Page 20: Android session 2-behestee

DRAWABLE / COLOR

Page 21: Android session 2-behestee

STYLESInline styles

Styles definition

Using style

Page 22: Android session 2-behestee

STYLES• Inheritance – by adding parent it can be inherited:

<style name="GreenText" parent="@android:style/TextAppearance"><item name="android:textColor">#00FF00</item>

</style>

• If the parent is your style then don’t use parent, Just make the prefix:<style name="CodeFont.Red">

        <item name="android:textColor">#FF0000</item>    </style>

[refrence will be : @style/CodeFont.Red.]

• You can continue inheritance this way:<style name="CodeFont.Red.Big">

        <item name="android:textSize">30sp</item>    </style>

Page 23: Android session 2-behestee

THEMES• To set a theme for all the activities of your application, open the

AndroidManifest.xml file and edit the <application> tag to include the android:theme attribute with the style name. For example:

• If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the <activity> tag instead.

Page 24: Android session 2-behestee

THEMES• If you like a theme, but want to tweak it, just add the theme as the parent

of your custom theme. For example, you can modify the traditional light theme to use your own color like this:

• Now use CustomTheme instead of Theme.Light inside the Android Manifest:

• Android Styles (styles.xml)• Android Themes (themes.xml)

Page 25: Android session 2-behestee

MENU• Beginning with Android 3.0 (API level 11), the action bar is included• If you've created a custom theme, be sure it uses one of the Theme.Holo

themes as its parent. For details, see Styling the Action Bar.• Adding the action bar when running on versions older than Android 3.0

(down to Android 2.1 [API level 7]) requires that you include the Android Support Library in your application.

• Update your activity so that it extends ActionBarActivity. For example:

• In your manifest file, update either the <application> element or individual <activity> elements to use one of the Theme.AppCompat themes. For example:

Page 26: Android session 2-behestee

MENU / ACTION BAR• Adding Action Buttons

• Specify the Actions in XML

Page 27: Android session 2-behestee

MENU / ACTION BAR• If your app is using the Support Library, the showAsAction attribute is not

available from the android: namespace.

[NB: A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.]

Page 28: Android session 2-behestee

MENU / ACTION BAR• Add the Actions to the Action Bar:

Page 29: Android session 2-behestee

MENU / ACTION BAR• Respond to Action Buttons:

Page 30: Android session 2-behestee

MENU / ACTION BAR• Add Up Button for Low-level Activities like as:-

• Add the Parent Activity for a child activity as bellow:

Page 31: Android session 2-behestee

NINE-PATCH• Launch the draw9patch

application from your SDK /tools directory

• File > Open 9-patch... to locate the file

• Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) content area. Right-click (or hold Shift and click, on Mac) to erase previously drawn lines.

• When done, select File > Save 9-patch... Your image will be saved with the .9.png file name.

Page 32: Android session 2-behestee

ACTIVITY• Understand the Lifecycle Callbacks

Page 33: Android session 2-behestee

ACTIVITY• Specify Your App's Launcher Activity

• You need to know all that facts clearly for better designing the Application: – Does not crash if the user receives a phone call or switches to another app while using your

app.– Does not consume valuable system resources when the user is not actively using it.– Does not lose the user's progress if they leave your app and return to it at a later time.– Does not crash or lose the user's progress when the screen rotates between landscape and

portrait orientation.

Page 34: Android session 2-behestee

ACTIVITY• Save Your Activity State

Page 35: Android session 2-behestee

ACTIVITY• Restore Your Activity State

Page 36: Android session 2-behestee

INTENT• Explicit Intent:

– We generally do so with an explicit intent, which defines the exact class name of the component you want to start.

• Implicite Intent: – when we want to have a separate app perform an action, such as "view a

map," you must use an implicit intent.

Page 37: Android session 2-behestee

IMPLICITE INTENT• View a web page:

• To make a phone call from your app:

• Send an email with an attachment:

Page 38: Android session 2-behestee

IMPLICITE INTENT• Caution: If you invoke an intent and there is no app available on the

device that can handle the intent, your app will crash.• To verify there is an activity available that can respond to the intent, call

queryIntentActivities() to get a list of activities capable of handling your Intent. If the returned List is not empty, you can safely use the intent. For example:

• Please see details at here.

Page 39: Android session 2-behestee

QUESTION?

?

Page 40: Android session 2-behestee

THANK YOU