Date post: | 26-Jan-2017 |
Category: |
Mobile |
Upload: | ganesh-kanna-s |
View: | 72 times |
Download: | 1 times |
Workshop on Android Programming
Why Android?
Distribution - Chart
API Level
Android Architecture
Android Components
• ActivityUI component typically corresponds to one screen
• Intent ReceiverReceives events from phone
• ServiceFaceless task that runs in the background
• Content ProviderStores data and makes it available to other applications
Activity Life Cycle
Back Stack
App Resources
Same Resource
App Resources
Multiple Resource
App Resources
Providing Resources
App Resources
Accessing Resources
App Resources
Localization• res/values/strings.xml
Contains English text for all the strings that the application uses, including text for a string named title.
• res/values-fr/strings.xmlContain French text for all the strings, including title.
• res/values-ja/strings.xmlContain Japanese text for all the strings except title.
App Resources
Resources Types• Animation Resources
Define pre-determined animations.Tween animations are saved in res/anim/ and accessed from the R.anim class.Frame animations are saved in res/drawable/ and accessed from the R.drawable class.
• Color State List ResourceDefine a color resources that changes based on the View state.Saved in res/color/ and accessed from the R.color class.
App Resources
Resources Types• Drawable Resources
Define various graphics with bitmaps or XML.Saved in res/drawable/ and accessed from the R.drawable class.
• Layout ResourceDefine the layout for your application UI.Saved in res/layout/ and accessed from the R.layout class.
• Menu ResourceDefine the contents of your application menus.Saved in res/menu/ and accessed from the R.menu class.
App Resources
Resource Types• String Resources
Define strings, string arrays, and plurals (and include string formatting and styling).Saved in res/values/ and accessed from the R.string, R.array, and R.plurals classes.
• Style ResourceDefine the look and format for UI elements.Saved in res/values/ and accessed from the R.style class.
User Interface
Layouts – Linear Layout
VerticalHorizontal
User Interface
Layouts – Relative Layout
User Interface
Layouts – List View/ Grid View
Displays a scrolling single column list.
Displays a scrolling grid of columns and rows
User Interface
Input Controls
User Interface
Input Controls – Spinner
User Interface
Input Controls – Picker
Supporting Multiple Screens
Screen sizeScreen densityOrientationResolutionDevice Independent Pixel
px = dp * (dpi / 160)
Supporting Multiple Screen
◦ ldpi (low) ~120dpi◦ mdpi (medium) ~160dpi◦ hdpi (high) ~240dpi◦ xhdpi (extra-high) ~320dpi◦ xxhdpi (extra-extra-high) ~480dpi◦ xxxhdpi (extra-extra-extra-high) ~640dpi
Supporting Multiple Screen
Supporting Multiple Screen
Supporting Multiple Screen
• 36x36 (0.75x) for low-density• 48x48 (1.0x baseline) for medium-density• 72x72 (1.5x) for high-density• 96x96 (2.0x) for extra-high-density• 144x144 (3.0x) for extra-extra-high-density• 192x192 (4.0x) for extra-extra-extra-high-density
Code Snippets
Views
• TextView• Button• ToggleButton• CheckBox• RadioButton• Spinner• SeekBar• Switch
Views
• TextFields• Layouts• Containers• Images• AppCompat
Events• onClick()• onLongClick()• onFocusChange()• onKey()• onTouch()• onCreateContextMenu()
Utilities to Know
Call to PhoneIntent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:"+number)); startActivity(callIntent); <uses-permission android:name="android.permission.CALL_PHONE" />
Utilities to Know
Open URL in browser
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));startActivity(browserIntent);
Utilities to Know
Open E-mail App
Intent i = new Intent(Intent.ACTION_SEND);i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);i.putExtra(android.content.Intent.EXTRA_TEXT, text);startActivity(Intent.createChooser(i, "Send email"));
Data Storage
Shared PreferencesStore private primitive data in key-value
pairs.Internal Storage
Store private data on the device memory.External Storage
Store public data on the shared external storage.SQLite Databases
Store structured data in a private database.Network Connection
Store data on the web with your own network server.
Data Storage
Shared Preferences
// Restore preferencesSharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);boolean silent = settings.getBoolean("silentMode", false);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);SharedPreferences.Editor editor = settings.edit();editor.putBoolean("silentMode", mSilentMode);// Commit the edits!editor.commit();
Fragments• A fragment has its own layout and its own behavior with its
own life cycle callbacks.• You can add or remove fragments in an activity while the
activity is running.• You can combine multiple fragments in a single activity to
build a multi-plane UI.• A fragment can be used in multiple activities.
Android Challanges
• Software Fragmentation• Hardware Fragmentation• No Software/Hardware Standardization• Several Carriers• Security
References• https://developer.android.com• http://stackoverflow.com/questions/tagged/android• https://developer.android.com/design/index.html• https://material.google.com
Questions?
THANK YOU!