SlideShare ist ein Scribd-Unternehmen logo
1 von 98
Downloaden Sie, um offline zu lesen
Android Programming 101
for NTU Workshop 2013
About Me

Name
Work at
No. of apps
Find me at

Junda Ong
Hoiio
20+
just2me.com, samwize.com
@samwize, G+
Hoiio API
Hoiio Business Communication
Hoiio Phone
My Hobby Projects
txeet
SG 4D

BAD Example of Porting
About You ?
Today’s Programme
8am - 10am

Setting Up Android Studio

10am - 12pm

Introduction to Android Programming

12pm - 1pm

Lunch

1pm - 5pm

3 x hands-on (each 1 hr)
Objectives

Understand Android development process
Master Android Studio
Kickstart basic Android programming
Pre-requisite: Java Programming

Java Programming Guide:
http://mobile.tutsplus.com/tutorials/android/java-tutorial/
Introduction to Android
The Android OS

• Linux Kernel
• Write in Java code
• Dalvik Virtual Machine
• Application Framework
Android Architecture
Platform Versions
Development Process
Design

Develop

Distribute
Learn how to Design
Understanding Design

• Principles/Guidelines
• UI Components
• Common Patterns
Design Principles

• Simple
• Looks the same, act the same
• Customizable
• Icon style
• Don’t mimic iPhone UI
UI Components

• Buttons
• Text Fields
• Dialogs
• Spinners
• Action Bar
Button
Text Fields
Dialogs
Alerts
Spinner
Action Bar
Common Patterns
Change view on a set of data
Select multiple items
Dashboard
Devices & Resolutions
dpi = dots per inch

dp = density independent pixels

for graphics

(1dp might be 1 pixel or 2 pixels, depending on the dpi)

sp = scale independent pixels

for fonts
App Icon
48x48 dp

48x48 px

72x72 px

96x96 px

144x144 px
Learn how to Code
AndroidManifest.xml
4 Main Components

1. Activity
2. Service
3. Content Provider
4. Broadcast Receiver
Activity

• Activity = Screen
• An app is made up of 1 or more activities
• Stack of activities/screens
• Activity lifecycle
Activity

• App-X can activate App-Y component
• Intent
• App-X can access App-Y shared data
• Content Resolver
HelloWorldActivity

Activity class has functions to handle onCreate, onResume, onPause, etc
Activity

• Launch an Activity by calling
startActivity(intent)

Launch a known Activity
Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);

Launch a system Activity
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);
startActivity(intent);
Activity

•

Activity must be declared in AndroidManifest.xml
<manifest ... >
  <application ... >
      <activity android:name=".HelloWorldActivity" />
      ...
  </application ... >
  ...
</manifest >

.HelloWorldActivity is shorthand for com.just2us.helloworld.HelloWorldActivity
Service

•

Service runs in the background, even when user is not
interacting with your app

•
•
•

Service or Thread ?
To start, call startService()
Similar to Activity, has its lifecycle and various event
callbacks
ContentProvider

• A way to share data across applications,
including apps such as phonebook,
calendar, etc.

• You can access the phonebook data using a
ContentResolver

• Have query, insert, delete methods (SQLite)
ContentResolver cr = getContentResolver();
cr.query(“content://android.provider.Contacts.Phones.CONTACT_URI”,
projection,
selection, selectionArg,
sortOrder)
BroadcastReceiver

• Responds to system-wide broadcast

announcements such as incoming phone
call, SMS sent, picture captured, etc
User Interfaces

Slides on http://www.slideshare.net/samwize
View Hierarchy

1. View - Android UI component, view or widget
2. ViewGroup - Layout or container view
View

• UI components can be found in
android.widget package

•

Basic UI:

•
•
•
•
•
•

TextView
Button
TextField
Progress bar
List
etc..
ViewGroup
(aka layout manager)

A simple LinearLayout
ViewGroup

TableLayout
ViewGroup

RelativeLayout
User Interfaces

• 3 ways to construct UI
1. Drag-and-drop interface builder
2. XML
3. Code
The way of XML
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>

looks in /res/values/string.xml, and
find the value for the key “hello”
Equivalently..
android:text="Hello world too!"
The way of XML
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

setContentView() inflate main.xml and set the views
The way of Code
package com.just2us.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView textview = new TextView(this);
       textview.setText("Hello, Android");
       setContentView(textview);
   }
}

Creating a TextView and set the text
Similarly to the way of XML, setContentView()
Preferences

• The easiest way to store information
• NOT only store preferences/settings, but
also arbitrary key-value pairs

• SharedPreference class
• getBoolean, setBoolean, etc..
Preferences
public class Calc extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile";
    @Override
    protected void onCreate(Bundle state){
       super.onCreate(state);
 
 
 
 
 

 
 
 
 
 

 
 
 
 
}

 // Restore preferences
 SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
 boolean silent = settings.getBoolean("silentMode", false);
 setSilent(silent);

    @Override
    protected void onStop(){
       super.onStop();
 
 
 
 
 

 
 
 
 
 

 
 
 
 
 

// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);

      // Commit the edits!
      editor.commit();
    }
}
Network

• Connect to web services over HTTP
• Permission needed in Manifest
<uses-permission android:name="android.permission.INTERNET" />

• A few different ways to connect
• HttpClient is most robust
Network - GET
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.myserver.com/script1.php");
// Execute HTTP GET request and get response
HttpResponse response = client.execute(request);
InputStream is = response.getEntity().getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
// Do what you need with content StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String content = sb.toString();
// Do what you need with content
...
Network - POST

HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://www.myserver.com/login_script.php");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", "samwize"));
nameValuePairs.add(new BasicNameValuePair("password", "123456"));
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP POST Request
HttpResponse response = httpclient.execute(request);
       
Multimedia

• Camera
• Playback audio and video
Multimedia - Camera

• 2 ways to capture photo
• Using capture intent
• Using Camera class directly
Multimedia - Camera

private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private Uri fileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
    // start the image capture Intent
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

Capture photo
Multimedia - Camera
private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
private Uri fileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //create new Intent
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);  // create a file to save the video
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  // set the image file name
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
    // start the Video Capture Intent
    startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
}

Capture video
Multimedia - Camera
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            // Image captured and saved to fileUri specified in the Intent
            Toast.makeText(this, "Image saved to:n" +
                     data.getData(), Toast.LENGTH_LONG).show();
        } else if (resultCode == RESULT_CANCELED) {
            // User cancelled the image capture
        } else {
            // Image capture failed, advise user
        }
    }
 
 
 
 
 
 
 
 
 
 
 
}

 
 
 
 
 
 
 
 
 
 
 

if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
    if (resultCode == RESULT_OK) {
        // Video captured and saved to fileUri specified in the Intent
        Toast.makeText(this, "Video saved to:n" +
                 data.getData(), Toast.LENGTH_LONG).show();
    } else if (resultCode == RESULT_CANCELED) {
        // User cancelled the video capture
    } else {
        // Video capture failed, advise user
    }
}

Handling after photo/video is captured by camera app
Multimedia - MediaPlayer

• Play audio and video from:
• /res/raw/
• File system (internal or external)
• Stream over Internet
• MediaPlayer class
Multimedia - MediaPlayer

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start();
...
mediaPlayer.stop();

Playing /res/raw/sound_file_1.mp3
1. Hello World [60 min]
Objectives

• Create new project
• Understand project structure
• Navigate in Android Studio
• Run & Debug
Demo!
Project Structure

Java Code
Project Structure

Resources
The steps in brief..

• Create new project
• Change App name
• Run
• View logs
• Debug
Refer to hand-out 1 notes
2. Stopwatch [60 min]
Objectives

• Create widgets in design mode
• Edit widgets in XML text mode
• Code how stopwatch works
Demo!
The steps in brief..

• Create 2 buttons
• Edit the names and id
• Code the stopwatch logic
Refer to hand-out 2 notes
3. Polish Stopwatch [60 min]
Objectives

• Create Responsive Layout
• Style the UI
• Enhance UX
Demo!
The steps in brief..

• Edit layout
• Add background image
• Custom font
• Button with background image
• Button with states
Refer to hand-out 3 notes
What’s Next?
Database

• Tabular data
• SQLite behind the scenes
• Extend SQLiteOpenHelper
Database
public class DictionaryOpenHelper extends SQLiteOpenHelper {
 
 
 
 
 
 

 
 
 
 
 
 

private
private
private
       
       
       

static final int DATABASE_VERSION = 2;
static final String DICTIONARY_TABLE_NAME = "dictionary";
static final String DICTIONARY_TABLE_CREATE =
    "CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +
    KEY_WORD + " TEXT, " +
    KEY_DEFINITION + " TEXT);";

    DictionaryOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
 
 
 
 
}

 
 
 
 

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(DICTIONARY_TABLE_CREATE);
}
Database

• Call getWritableDatabase() or

getReadableDatabase() to get an
SQLiteDatabase object

• With SQLiteDatabase, call query() to
execute SQL queries
More Topics

• Location (GPS) and Map
• Bluetooth
• USB host and accessory
• Animation
• OpenGL ES
• Push Messaging (GCM)
Arduino & Bluetooth
Important Resources

• http://developer.android.com
• http://stackoverflow.com/
• http://www.google.com/

Weitere ähnliche Inhalte

Was ist angesagt?

Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
EverNote iOS SDK introduction & practices
EverNote iOS SDK introduction & practices EverNote iOS SDK introduction & practices
EverNote iOS SDK introduction & practices MaoYang Chien
 
Apple Watch and WatchKit - A Technical Overview
Apple Watch and WatchKit - A Technical OverviewApple Watch and WatchKit - A Technical Overview
Apple Watch and WatchKit - A Technical OverviewSammy Sunny
 
Selendroid - Selenium for Android
Selendroid - Selenium for AndroidSelendroid - Selenium for Android
Selendroid - Selenium for AndroidDominik Dary
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMohammad Shaker
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium IntroNicholas Jansma
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mohammad Shaker
 
Getting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingGetting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingBitbar
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidSittiphol Phanvilai
 
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)Kelly Shuster
 
Android Intermediatte IAK full
Android Intermediatte IAK fullAndroid Intermediatte IAK full
Android Intermediatte IAK fullAhmad Arif Faizin
 
Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Daniel Knott
 
What's new in Android Wear 2.0
What's new in Android Wear 2.0What's new in Android Wear 2.0
What's new in Android Wear 2.0Peter Friese
 
Mobile Web Development with HTML5
Mobile Web Development with HTML5Mobile Web Development with HTML5
Mobile Web Development with HTML5Roy Clarkson
 
SgCodeJam24 Workshop Extract
SgCodeJam24 Workshop ExtractSgCodeJam24 Workshop Extract
SgCodeJam24 Workshop Extractremko caprio
 
Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5Oswald Campesato
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android WearPeter Friese
 

Was ist angesagt? (20)

Android Test Automation Workshop
Android Test Automation WorkshopAndroid Test Automation Workshop
Android Test Automation Workshop
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
EverNote iOS SDK introduction & practices
EverNote iOS SDK introduction & practices EverNote iOS SDK introduction & practices
EverNote iOS SDK introduction & practices
 
Apple Watch and WatchKit - A Technical Overview
Apple Watch and WatchKit - A Technical OverviewApple Watch and WatchKit - A Technical Overview
Apple Watch and WatchKit - A Technical Overview
 
Selendroid - Selenium for Android
Selendroid - Selenium for AndroidSelendroid - Selenium for Android
Selendroid - Selenium for Android
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium Intro
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.
 
Getting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingGetting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App Testing
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in Android
 
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
 
Android Intermediatte IAK full
Android Intermediatte IAK fullAndroid Intermediatte IAK full
Android Intermediatte IAK full
 
Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012
 
What's new in Android Wear 2.0
What's new in Android Wear 2.0What's new in Android Wear 2.0
What's new in Android Wear 2.0
 
Parse par Nicolas Lauquin
Parse par Nicolas LauquinParse par Nicolas Lauquin
Parse par Nicolas Lauquin
 
Android Development Tutorial V3
Android Development Tutorial   V3Android Development Tutorial   V3
Android Development Tutorial V3
 
Mobile Web Development with HTML5
Mobile Web Development with HTML5Mobile Web Development with HTML5
Mobile Web Development with HTML5
 
SgCodeJam24 Workshop Extract
SgCodeJam24 Workshop ExtractSgCodeJam24 Workshop Extract
SgCodeJam24 Workshop Extract
 
Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 

Andere mochten auch

Software proposal on android
Software proposal on androidSoftware proposal on android
Software proposal on androidKamrul Chowdhury
 
Advance Android application development workshop day 1
Advance Android application development workshop day 1Advance Android application development workshop day 1
Advance Android application development workshop day 1cresco
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Davide Cerbo
 
Advance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basicsAdvance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basicsayman diab
 
Memory problems in android programming
Memory problems in android programmingMemory problems in android programming
Memory problems in android programmingAiTi Education
 
Asynchronous Programming in Android
Asynchronous Programming in AndroidAsynchronous Programming in Android
Asynchronous Programming in AndroidJohn Pendexter
 
Android UI Reference
Android UI ReferenceAndroid UI Reference
Android UI ReferenceGauntFace
 
Advance Android application development workshop day 3
Advance Android application development workshop day 3Advance Android application development workshop day 3
Advance Android application development workshop day 3cresco
 
Tips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programmingTips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programmingZalo_app
 
Stream upload and asynchronous job processing in large scale systems
Stream upload and asynchronous job processing  in large scale systemsStream upload and asynchronous job processing  in large scale systems
Stream upload and asynchronous job processing in large scale systemsZalo_app
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersReto Meier
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Android app development - Java Programming for Android
Android app development - Java Programming for AndroidAndroid app development - Java Programming for Android
Android app development - Java Programming for AndroidOUM SAOKOSAL
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
 

Andere mochten auch (20)

Software proposal on android
Software proposal on androidSoftware proposal on android
Software proposal on android
 
Google Map V2
Google Map V2Google Map V2
Google Map V2
 
Advance Android application development workshop day 1
Advance Android application development workshop day 1Advance Android application development workshop day 1
Advance Android application development workshop day 1
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Advance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basicsAdvance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basics
 
Memory problems in android programming
Memory problems in android programmingMemory problems in android programming
Memory problems in android programming
 
Asynchronous Programming in Android
Asynchronous Programming in AndroidAsynchronous Programming in Android
Asynchronous Programming in Android
 
Android UI Reference
Android UI ReferenceAndroid UI Reference
Android UI Reference
 
Advance Android application development workshop day 3
Advance Android application development workshop day 3Advance Android application development workshop day 3
Advance Android application development workshop day 3
 
Web Development Fundamentals
Web Development FundamentalsWeb Development Fundamentals
Web Development Fundamentals
 
Tips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programmingTips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programming
 
Stream upload and asynchronous job processing in large scale systems
Stream upload and asynchronous job processing  in large scale systemsStream upload and asynchronous job processing  in large scale systems
Stream upload and asynchronous job processing in large scale systems
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Coding defines reality
Coding defines realityCoding defines reality
Coding defines reality
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App Developers
 
Advance Android Layout Walkthrough
Advance Android Layout WalkthroughAdvance Android Layout Walkthrough
Advance Android Layout Walkthrough
 
Android Programming
Android ProgrammingAndroid Programming
Android Programming
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Android app development - Java Programming for Android
Android app development - Java Programming for AndroidAndroid app development - Java Programming for Android
Android app development - Java Programming for Android
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 

Ähnlich wie Android Workshop 2013

Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android DevelopmentJussi Pohjolainen
 
Top Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsTop Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsMotorola Mobility - MOTODEV
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 
Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Luc Bors
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen Chen
 
ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013Mathias Seguy
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1Hussain Behestee
 
JMP103 : Extending Your App Arsenal With OpenSocial
JMP103 : Extending Your App Arsenal With OpenSocialJMP103 : Extending Your App Arsenal With OpenSocial
JMP103 : Extending Your App Arsenal With OpenSocialRyan Baxter
 
IBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocial
IBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocialIBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocial
IBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocialIBM Connections Developers
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaRainer Stropek
 
Scott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium ModulesScott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium ModulesAxway Appcelerator
 
Hieu Xamarin iOS9, Android M 3-11-2015
Hieu Xamarin iOS9, Android M  3-11-2015Hieu Xamarin iOS9, Android M  3-11-2015
Hieu Xamarin iOS9, Android M 3-11-2015Nguyen Hieu
 
Designing for Windows Phone 8
Designing for Windows Phone 8Designing for Windows Phone 8
Designing for Windows Phone 8David Isbitski
 
Android Development project
Android Development projectAndroid Development project
Android Development projectMinhaj Kazi
 

Ähnlich wie Android Workshop 2013 (20)

Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
Top Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsTop Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on Tablets
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)
 
Lightning Talk - Xamarin
Lightning Talk - Xamarin Lightning Talk - Xamarin
Lightning Talk - Xamarin
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
Android
AndroidAndroid
Android
 
ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
JMP103 : Extending Your App Arsenal With OpenSocial
JMP103 : Extending Your App Arsenal With OpenSocialJMP103 : Extending Your App Arsenal With OpenSocial
JMP103 : Extending Your App Arsenal With OpenSocial
 
IBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocial
IBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocialIBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocial
IBM Connect 2014 - JMP103: Extending Your Application Arsenal With OpenSocial
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
 
Scott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium ModulesScott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium Modules
 
Hieu Xamarin iOS9, Android M 3-11-2015
Hieu Xamarin iOS9, Android M  3-11-2015Hieu Xamarin iOS9, Android M  3-11-2015
Hieu Xamarin iOS9, Android M 3-11-2015
 
Designing for Windows Phone 8
Designing for Windows Phone 8Designing for Windows Phone 8
Designing for Windows Phone 8
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Activities.pptx
Activities.pptxActivities.pptx
Activities.pptx
 
Android Development project
Android Development projectAndroid Development project
Android Development project
 

Mehr von Junda Ong

Opportunity with audio
Opportunity with audioOpportunity with audio
Opportunity with audioJunda Ong
 
Enhance offline experience
Enhance offline experienceEnhance offline experience
Enhance offline experienceJunda Ong
 
Disrupt flyer
Disrupt flyerDisrupt flyer
Disrupt flyerJunda Ong
 
Build your product 10x faster
Build your product 10x fasterBuild your product 10x faster
Build your product 10x fasterJunda Ong
 
Build travel apps the easy way
Build travel apps the easy wayBuild travel apps the easy way
Build travel apps the easy wayJunda Ong
 
Hoiio API: An introduction
Hoiio API: An introductionHoiio API: An introduction
Hoiio API: An introductionJunda Ong
 
Build Voice App the Easy Way
Build Voice App the Easy WayBuild Voice App the Easy Way
Build Voice App the Easy WayJunda Ong
 
How mac fonts appear in slideshare?
How mac fonts appear in slideshare?How mac fonts appear in slideshare?
How mac fonts appear in slideshare?Junda Ong
 
Pull Toy Design
Pull Toy DesignPull Toy Design
Pull Toy DesignJunda Ong
 
NYP Talk - Sharing Mobile Development Experience
NYP Talk - Sharing Mobile Development ExperienceNYP Talk - Sharing Mobile Development Experience
NYP Talk - Sharing Mobile Development ExperienceJunda Ong
 
Using AppEngine for Mobile Apps
Using AppEngine for Mobile AppsUsing AppEngine for Mobile Apps
Using AppEngine for Mobile AppsJunda Ong
 

Mehr von Junda Ong (11)

Opportunity with audio
Opportunity with audioOpportunity with audio
Opportunity with audio
 
Enhance offline experience
Enhance offline experienceEnhance offline experience
Enhance offline experience
 
Disrupt flyer
Disrupt flyerDisrupt flyer
Disrupt flyer
 
Build your product 10x faster
Build your product 10x fasterBuild your product 10x faster
Build your product 10x faster
 
Build travel apps the easy way
Build travel apps the easy wayBuild travel apps the easy way
Build travel apps the easy way
 
Hoiio API: An introduction
Hoiio API: An introductionHoiio API: An introduction
Hoiio API: An introduction
 
Build Voice App the Easy Way
Build Voice App the Easy WayBuild Voice App the Easy Way
Build Voice App the Easy Way
 
How mac fonts appear in slideshare?
How mac fonts appear in slideshare?How mac fonts appear in slideshare?
How mac fonts appear in slideshare?
 
Pull Toy Design
Pull Toy DesignPull Toy Design
Pull Toy Design
 
NYP Talk - Sharing Mobile Development Experience
NYP Talk - Sharing Mobile Development ExperienceNYP Talk - Sharing Mobile Development Experience
NYP Talk - Sharing Mobile Development Experience
 
Using AppEngine for Mobile Apps
Using AppEngine for Mobile AppsUsing AppEngine for Mobile Apps
Using AppEngine for Mobile Apps
 

Kürzlich hochgeladen

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Kürzlich hochgeladen (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

Android Workshop 2013

  • 1. Android Programming 101 for NTU Workshop 2013
  • 2. About Me Name Work at No. of apps Find me at Junda Ong Hoiio 20+ just2me.com, samwize.com @samwize, G+
  • 8. SG 4D BAD Example of Porting
  • 10. Today’s Programme 8am - 10am Setting Up Android Studio 10am - 12pm Introduction to Android Programming 12pm - 1pm Lunch 1pm - 5pm 3 x hands-on (each 1 hr)
  • 11.
  • 12. Objectives Understand Android development process Master Android Studio Kickstart basic Android programming
  • 13. Pre-requisite: Java Programming Java Programming Guide: http://mobile.tutsplus.com/tutorials/android/java-tutorial/
  • 15.
  • 16. The Android OS • Linux Kernel • Write in Java code • Dalvik Virtual Machine • Application Framework
  • 18.
  • 21. Learn how to Design
  • 22. Understanding Design • Principles/Guidelines • UI Components • Common Patterns
  • 23. Design Principles • Simple • Looks the same, act the same • Customizable • Icon style • Don’t mimic iPhone UI
  • 24. UI Components • Buttons • Text Fields • Dialogs • Spinners • Action Bar
  • 32. Change view on a set of data
  • 36. dpi = dots per inch dp = density independent pixels for graphics (1dp might be 1 pixel or 2 pixels, depending on the dpi) sp = scale independent pixels for fonts
  • 37. App Icon 48x48 dp 48x48 px 72x72 px 96x96 px 144x144 px
  • 38. Learn how to Code
  • 40. 4 Main Components 1. Activity 2. Service 3. Content Provider 4. Broadcast Receiver
  • 41. Activity • Activity = Screen • An app is made up of 1 or more activities • Stack of activities/screens • Activity lifecycle
  • 42. Activity • App-X can activate App-Y component • Intent • App-X can access App-Y shared data • Content Resolver
  • 43.
  • 44. HelloWorldActivity Activity class has functions to handle onCreate, onResume, onPause, etc
  • 45. Activity • Launch an Activity by calling startActivity(intent) Launch a known Activity Intent intent = new Intent(this, SignInActivity.class); startActivity(intent); Launch a system Activity Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, recipientArray); startActivity(intent);
  • 46. Activity • Activity must be declared in AndroidManifest.xml <manifest ... >   <application ... >       <activity android:name=".HelloWorldActivity" />       ...   </application ... >   ... </manifest > .HelloWorldActivity is shorthand for com.just2us.helloworld.HelloWorldActivity
  • 47. Service • Service runs in the background, even when user is not interacting with your app • • • Service or Thread ? To start, call startService() Similar to Activity, has its lifecycle and various event callbacks
  • 48. ContentProvider • A way to share data across applications, including apps such as phonebook, calendar, etc. • You can access the phonebook data using a ContentResolver • Have query, insert, delete methods (SQLite) ContentResolver cr = getContentResolver(); cr.query(“content://android.provider.Contacts.Phones.CONTACT_URI”, projection, selection, selectionArg, sortOrder)
  • 49. BroadcastReceiver • Responds to system-wide broadcast announcements such as incoming phone call, SMS sent, picture captured, etc
  • 50. User Interfaces Slides on http://www.slideshare.net/samwize
  • 51.
  • 52. View Hierarchy 1. View - Android UI component, view or widget 2. ViewGroup - Layout or container view
  • 53. View • UI components can be found in android.widget package • Basic UI: • • • • • • TextView Button TextField Progress bar List etc..
  • 54. ViewGroup (aka layout manager) A simple LinearLayout
  • 57. User Interfaces • 3 ways to construct UI 1. Drag-and-drop interface builder 2. XML 3. Code
  • 58. The way of XML /res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> looks in /res/values/string.xml, and find the value for the key “hello” Equivalently.. android:text="Hello world too!"
  • 59. The way of XML /res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } setContentView() inflate main.xml and set the views
  • 60. The way of Code package com.just2us.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        TextView textview = new TextView(this);        textview.setText("Hello, Android");        setContentView(textview);    } } Creating a TextView and set the text Similarly to the way of XML, setContentView()
  • 61. Preferences • The easiest way to store information • NOT only store preferences/settings, but also arbitrary key-value pairs • SharedPreference class • getBoolean, setBoolean, etc..
  • 62. Preferences public class Calc extends Activity {     public static final String PREFS_NAME = "MyPrefsFile";     @Override     protected void onCreate(Bundle state){        super.onCreate(state);                             }  // Restore preferences  SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);  boolean silent = settings.getBoolean("silentMode", false);  setSilent(silent);     @Override     protected void onStop(){        super.onStop();                               // We need an Editor object to make preference changes. // All objects are from android.context.Context SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("silentMode", mSilentMode);       // Commit the edits!       editor.commit();     } }
  • 63. Network • Connect to web services over HTTP • Permission needed in Manifest <uses-permission android:name="android.permission.INTERNET" /> • A few different ways to connect • HttpClient is most robust
  • 64. Network - GET HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("http://www.myserver.com/script1.php"); // Execute HTTP GET request and get response HttpResponse response = client.execute(request); InputStream is = response.getEntity().getContent(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Do what you need with content StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String content = sb.toString(); // Do what you need with content ...
  • 65. Network - POST HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost("http://www.myserver.com/login_script.php"); // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("username", "samwize")); nameValuePairs.add(new BasicNameValuePair("password", "123456")); request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP POST Request HttpResponse response = httpclient.execute(request);        
  • 67. Multimedia - Camera • 2 ways to capture photo • Using capture intent • Using Camera class directly
  • 68. Multimedia - Camera private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; private Uri fileUri; @Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     // create Intent to take a picture and return control to the calling application     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);     fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image     intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name     // start the image capture Intent     startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } Capture photo
  • 69. Multimedia - Camera private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200; private Uri fileUri; @Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     //create new Intent     Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);     fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);  // create a file to save the video     intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  // set the image file name     intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high     // start the Video Capture Intent     startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); } Capture video
  • 70. Multimedia - Camera private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {         if (resultCode == RESULT_OK) {             // Image captured and saved to fileUri specified in the Intent             Toast.makeText(this, "Image saved to:n" +                      data.getData(), Toast.LENGTH_LONG).show();         } else if (resultCode == RESULT_CANCELED) {             // User cancelled the image capture         } else {             // Image capture failed, advise user         }     }                       }                       if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {     if (resultCode == RESULT_OK) {         // Video captured and saved to fileUri specified in the Intent         Toast.makeText(this, "Video saved to:n" +                  data.getData(), Toast.LENGTH_LONG).show();     } else if (resultCode == RESULT_CANCELED) {         // User cancelled the video capture     } else {         // Video capture failed, advise user     } } Handling after photo/video is captured by camera app
  • 71. Multimedia - MediaPlayer • Play audio and video from: • /res/raw/ • File system (internal or external) • Stream over Internet • MediaPlayer class
  • 72. Multimedia - MediaPlayer MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1); mediaPlayer.start(); ... mediaPlayer.stop(); Playing /res/raw/sound_file_1.mp3
  • 73. 1. Hello World [60 min]
  • 74.
  • 75. Objectives • Create new project • Understand project structure • Navigate in Android Studio • Run & Debug
  • 76. Demo!
  • 79. The steps in brief.. • Create new project • Change App name • Run • View logs • Debug Refer to hand-out 1 notes
  • 81.
  • 82.
  • 83. Objectives • Create widgets in design mode • Edit widgets in XML text mode • Code how stopwatch works
  • 84. Demo!
  • 85. The steps in brief.. • Create 2 buttons • Edit the names and id • Code the stopwatch logic Refer to hand-out 2 notes
  • 87.
  • 88.
  • 89. Objectives • Create Responsive Layout • Style the UI • Enhance UX
  • 90. Demo!
  • 91. The steps in brief.. • Edit layout • Add background image • Custom font • Button with background image • Button with states Refer to hand-out 3 notes
  • 93. Database • Tabular data • SQLite behind the scenes • Extend SQLiteOpenHelper
  • 94. Database public class DictionaryOpenHelper extends SQLiteOpenHelper {                         private private private                         static final int DATABASE_VERSION = 2; static final String DICTIONARY_TABLE_NAME = "dictionary"; static final String DICTIONARY_TABLE_CREATE =     "CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +     KEY_WORD + " TEXT, " +     KEY_DEFINITION + " TEXT);";     DictionaryOpenHelper(Context context) {         super(context, DATABASE_NAME, null, DATABASE_VERSION);     }         }         @Override public void onCreate(SQLiteDatabase db) {     db.execSQL(DICTIONARY_TABLE_CREATE); }
  • 95. Database • Call getWritableDatabase() or getReadableDatabase() to get an SQLiteDatabase object • With SQLiteDatabase, call query() to execute SQL queries
  • 96. More Topics • Location (GPS) and Map • Bluetooth • USB host and accessory • Animation • OpenGL ES • Push Messaging (GCM)
  • 98. Important Resources • http://developer.android.com • http://stackoverflow.com/ • http://www.google.com/