Date post: | 22-Jan-2018 |
Category: |
Mobile |
Upload: | shanmugapriya-d |
View: | 238 times |
Download: | 0 times |
Android Application
Fundamentals
• Basic Java Programming Language
• Basic Knowledge about XML
Example
App Components
• Activities
• Services
• Content Providers
• Broadcast Receivers
• Intents and Intents Filters
Activities & Services
Broadcast Receivers
& Content Providers
Activities Lifecycle
Intents and Intent Filters
• An Intent is a messaging object you can use to
request an action from another app component.
• Intent Types: 1. Explicit Intent 2. Implicit Intent
1. Explicit Intent: specify the component to start by
name (the fully-qualified class name). You'll typically
use an explicit intent to start a component in your
own app, because you know the class name of the
activity or service you want to start. For example,
start a new activity in response to a user action or
start a service to download a file in the background.
2. Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.
Intent Filters:
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Ex:
<data android:mimeType="application/vnd.google.panorama360+jpg"/>
<data android:mimeType="image/*"/>
<data android:mimeType="video/*"/>
Application Permission
• Requests a permission that the application must be
granted in order for it to operate correctly. Permissions
are granted by the user when the application is installed,
not while it's running
1. android.permission.CALL_EMERGENCY_NUMBERS
2. android.permission.READ_OWNER_DATA
3. android.permission.SET_WALLPAPER
4. android.permission.DEVICE_POWER
5. android.hardware.bluetooth
Views, Layouts and UI
Components• Provides classes that expose basic user interface classes
that handle screen layout and interaction with the user
• Layouts:
Linear layout
Relative layout
Frame layout
UI Components• Input Controls
Menu & Action bar
Android Version before 3.0
List view and Grid View
• Android List View is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database.
• An adapter actually bridges between UI components and the data source that fill data into UI Component. Adapter can be used to supply the data to like spinner, list view, grid view etc.
• The List View and Grid View are subclasses of Adapter View and they can be populated by binding them to an Adapter, which retrieves data from an external source and creates a View that represents each data entry. Android provides several subclasses of Adapter that are useful for retrieving different kinds of data and building views for an Adapter View
Example:
String[] countryArray = {"India", "Pakistan", "USA",
"UK"};
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.ListView,
StringArray);
ListView listView = (ListView)
findViewById(R.id.listview);
listView.setAdapter(adapter);
Grid View
• Android GridView shows items in two-dimensional scrolling
grid (rows & columns) and the grid items are not
necessarily predetermined but they automatically inserted
to the layout using a ListAdapter
• An adapter actually bridges between UI components and
the data source that fill data into UI Component. Adapter
can be used to supply the data to like spinner, list view,
grid view etc.
• The ListView and GridView are subclasses of AdapterView
and they can be populated by binding them to an Adapter,
which retrieves data from an external source and creates a
View that represents each data entry.
public Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new
GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENT
ER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else { imageView = (ImageView) convertView; }
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
Tab layout & Swiper Views• TabLayout provides a horizontal layout to display tabs
Swipe views
• Efficient navigation is one of the cornerstones of a well-
designed app.
Example Code:
Adding Styles and
Themes• A style is a collection of properties that specify the look and
format for a view or window. A style can specify properties
such as height, padding, font color, font size, background
color, and much more. A style is defined in an XML resource
that is separate from the XML that specifies the layout.
Ex:
<TextView
style="@style/CodeFont"
android:text="@string/hello" />
END