Android session 2-behestee

Post on 18-Nov-2014

315 views 0 download

Tags:

description

Android Training session at Jaxara IT

transcript

ANDROID TRAININGSESSION – 2

-Hussain KMR Behestee

AGENDAS

• UI Design for Android– Layout– Drawable

• Activity• Intent

– Explicit Intent – Implicite Intent

UI DESIGN FOR ANDROID

UI DESIGN FOR ANDROID

• Layout– Common layout

• Linear layout• Relative layout

– Layout with adapter• Grid View• List View

LAYOUT

COMMON LAYOUT

Linear Relative

LINEAR LAYOUT

RELATIVE LAYOUT

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.

LAYOUT WITH ADAPTER

Grid View List View

GRIDS

GRIDS

LIST

LISTCreating adapter

Setting adapter

Adding click listener

UI DESIGN FOR ANDROID

• Drawables– State List

• Drawable / Color

– Styles– Themes– Menu– Nine-Patch

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

DRAWABLE / COLOR

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

drawable resource• android:color

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

DRAWABLE / COLOR

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

DRAWABLE / COLOR

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

DRAWABLE / COLOR

STYLESInline styles

Styles definition

Using style

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>

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.

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)

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:

MENU / ACTION BAR• Adding Action Buttons

• Specify the Actions in XML

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

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

MENU / ACTION BAR• Respond to Action Buttons:

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

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

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.

ACTIVITY• Understand the Lifecycle Callbacks

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.

ACTIVITY• Save Your Activity State

ACTIVITY• Restore Your Activity State

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.

IMPLICITE INTENT• View a web page:

• To make a phone call from your app:

• Send an email with an attachment:

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.

QUESTION?

?

THANK YOU