Your SlideShare is downloading. ×
Intro to Android App Development A Hobbyist's Perspective
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Intro to Android App Development A Hobbyist's Perspective

3,139
views

Published on


0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,139
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
143
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Intro to Android App Development A Hobbyist's Perspective presented by Steve Wiley ● Compare iPhone vs Android ● Getting started with Android ● SimpleCalc walk through    
  • 2. Language Comparison ● iPhone → Objective­C ● Android → Java Objective­C Java Header files No header files Object reference counting Automatic garbage collection Class extension None Messages to objects with [] Dot notation    
  • 3. Language Comparion Objective­C [instance setWidth:5 andHeight:[tgt getHeight]]; Java instance.setWidthAndHeight(     5, tgt.getHeight()     );    
  • 4. IDE Comparison ● iPhone → XCode – Intellisense – Integrated debugging ● Often force to resort to ”printf” debugging due to ”out  of scope” errors. ● Android → Eclipse with Android Plug­in – Very full­featured – I've bairly scratched the surface    
  • 5. Cost Comparison iPhone  Android ● Mac required ● Mac, Linux,  Windows ● Tools → free ● Tools → free ● Device installation →  $100/year ● Device installation  → free ● App­store submittal → free ● App­store submittal  ● Apple's take → 30% → $25 one­time ● Google's take →  30%    
  • 6. Getting Started ● Install Eclipse – http://www.eclipse.org ● Install the ADT plug­in for Eclipse – http://www.android.com/sdk/index.html ● Add a browser bookmark for the documentation – <install­dir>/docs/guide/samples/index.html    
  • 7. Create a New Project ● Start Eclipse ● Click ”Workbench” ● Window  Android SDK and AVD Manager ‒ Available Packages ‒ https://dl­ssl.google.com/android/repository/repository.xml ‒ Virtual Devices ● File  New  Android Project ‒ Specify lowest possible SDK    
  • 8. What's Created for You? ● Activity in DefaultActivity.java ● res/layout/main.xml ● res/values/strings.xml    
  • 9. … and ● AndroidManifest.xml    
  • 10. Simple Calc RPN Simple Calculator ● 0 – 9 keys ● Add, Subtract,  Multiply Divide ● Change Sign ● Backspace ● Decimal Point ● Exit    
  • 11. First... Create the Layouts ● Portrait & Landscape ‒ res/layout­port/main.xml ‒ res/layout­land/main.xml ● Contents: Layout Controls... ● Common Layout Choices: ‒ AbsoluteLayout, FrameLayout, LinearLayout,  RelativeLayout, TableLayout    
  • 12. Nested TableLayouts Outer Table Inner Table TableRows    
  • 13. Orientation <FrameLayout <FrameLayout android:layout_width="fill_parent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_height="fill_parent" android:padding="0dip"> android:padding="0dip"> android:orientation="vertical" android:orientation="horizontal" <TableLayout... <TableLayout...    
  • 14. Results TextView <TableRow> <TextView ● Use ”+id” notation to  android:id="@+id/resultsView" provide lookup of control  android:layout_span="3" android:typeface="sans" in code. android:gravity="right|fill_vertical" android:text="@string/hello" ● @string resources are pulled  android:clickable="false" android:cursorVisible="false" from  android:focusable="false" res/values/string.xml. android:focusableInTouchMode="false" android:lines="1" android:layout_margin="2sp" ● @drawable resources come  android:background="@drawable/yellowbox" out of res/drawable/*.png android:textColor="@color/black" android:textStyle="bold" android:textSize="40dip"/> ● @color resources come out  </TableRow> of res/values/colors,xml.    
  • 15. Enter Button <TableRow> ● Layout_span = 2  <Button android:text="@string/Enter" causes the Enter  android:id="@+id/enterButton" button to span 2  android:layout_span="2" columns. android:typeface="serif" android:textStyle="bold" android:height="50dip" android:textSize="30dip" android:gravity="center" android:padding="0px"/> <Button.../> </TableRow>    
  • 16. Next... Add Controls to Code ● Declare controls within DefaultActivity class: private Button changeSignBtn; private Button enterBtn; ● Within DefaultActivity's onCreate() method: ‒ this.setContentView( R.layout.main ); for res/layout­*/main.xml ● Assign Controls using findViewById(): this.changeSignBtn = (Button)    this.findViewById( R.id.changeSignButton ); this.enterBtn = (Button) this.findViewById( R.id.enterButton );    
  • 17. Then... Connect Clicks to Actions this.changeSignBtn.setOnClickListener( new OnClickListener() { public void onClick( View v ) { DefaultActivity.this.indicateClick(); DefaultActivity.this.toggleSignOfScratch(); } } ); this.enterBtn.setOnClickListener( new OnClickListener() { public void onClick( View v ) { DefaultActivity.this.indicateClick(); DefaultActivity.this.onEnterClick(); } } );    
  • 18. At This Point ● UI is Layed Out ● Controls are Connected to Actions ● What next? ‒ Add preferences for:  # of digits to display  Keystroke feedback: ‒ Clicks (redundant) ‒ Vibrations (redundant) ‒ Animated Visual    
  • 19. Preferences ● Create folder res/xml ● Add preferences.xml ‒ Right­click on xml folder ‒ New / Other... / Android XML File    
  • 20. New Android XML File Dialog ● Name the file  ”preferences.xml” ● Check ”Preferene” ● No Qualifier needed ● Finish    
  • 21. Types of Preferences ● CheckBoxPreference – checked/unchecked ‒ Click on Key Press (on/off) ‒ Vibrate on Key Press (on/off) ‒ Animation on Key Pres (on/off) ● RingtonePreference – sound selection ● EditTextPreference – editable text ● ListPreference – select a string from a list ● DialogPreference – customization ‒ # of Digits to Display ‒ SeekBar from http://android.hlidskialf.com/blog/code/android­seekbar­preference    
  • 22. Edit preferences.xml <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <CheckBoxPreference android:key="AudibleKeyStrokes" android:title="@string/AudibleKeyStrokes" android:defaultValue="true"/> <CheckBoxPreference android:key="VibrationOnKeyStroke" android:title="@string/VibrationOnKeyStroke" android:defaultValue="false"/> <CheckBoxPreference android:key="AnimateKeyStrokes" android:title="@string/AnimateKeyStrokes" android:defaultValue="false"/> <com.boisecodecamp.wiley.steve.SeekBarPreference android:key="digits" android:title="Fraction digits" android:defaultValue="2" android:summary="Number of digits to display = %?" android:dialogMessage="Fraction digits" android:text=" digits" android:max="8"/> </PreferenceScreen>    
  • 23. Create Preferences Activity ● Right­click package ● New / Class... ● Set Superclass to: android.preference.PreferenceActivity ● Add following in  onCreate() method: this.addPreferencesFromResource( R.xml.preferences  ); ● ”preferences” is from the  name of the xml file  created earlier    
  • 24. Binding Preferences ● Override onCreateOptionsMenu() @Override public boolean onCreateOptionsMenu( Menu menu ) { menu.add( R.string.DecimalDigitsSetting ) .setIcon( android.R.drawable.ic_menu_preferences ); return super.onCreateOptionsMenu( menu ); } ● Override onOptionsItemSelected() @Override public boolean onOptionsItemSelected( MenuItem item ) { super.onOptionsItemSelected( item ); Intent optionsItent = new Intent().setClass( this, SimpleCalcPreferenceActivity.class ); this.startActivityForResult( optionsItent, 0 ); return true; }    
  • 25. Binding Preferences... ● Override onActivityResult() @Override protected void onActivityResult( int requestCode,  int resultCode, Intent data ) { super.onActivityResult( requestCode, resultCode, data ); this.setPreferences(); }    
  • 26. Binding Preferences... private void setPreferences() { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences( this ); this.stackManager.setVibrate( sharedPref.getBoolean( "VibrationOnKeyStroke", false ) ); this.stackManager.setBeep( sharedPref.getBoolean(  "AudibleKeyStrokes", true ) ); this.stackManager.setAnimateKeystrokes( sharedPref.getBoolean( "AnimateKeyStrokes", false ) ); this.stackManager.setDigits( sharedPref.getInt(  "digits", 2 ) ); }    
  • 27. Adding Menus Override two methods: ● onCreateOptionsMenu – invoked when the users presses the Menu  button. ‒ Create menu items. ● OnOptionsItemSelected – invoked when the user selects a  MenuItem. ‒ Perform the desired action.    
  • 28. For Example, Settings Menu @Override public boolean onCreateOptionsMenu( Menu menu ) { menu.add( R.string.DecimalDigitsSetting ) .setIcon( android.R.drawable.ic_menu_preferences ); return super.onCreateOptionsMenu( menu ); } @Override public boolean onOptionsItemSelected( MenuItem item ) { super.onOptionsItemSelected( item ); Intent optionsIntent = new Intent().setClass(  this, SimpleCalcPreferenceActivity.class ); this.startActivityForResult( optionsIntent, 0 ); return true; }    
  • 29. Maintaining State Android moves Activites  through states. Changing orientation will  cause a Stop/Create cycle.    
  • 30. Saving State Override at least these methods to save state: @Override protected void onSaveInstanceState( Bundle outState ) { super.onSaveInstanceState( outState ); outState.putParcelable(  DefaultActivity.stackManagerName, this.stackManager ); } @Override protected void onPause() { super.onPause(); final ObjectOutputStream out = new ObjectOutputStream(  this.openFileOutput( SETTINGS_FILENAME, MODE_PRIVATE ) ); out.writeObject( this.stackManager ); out.close(); }    
  • 31. Restoring State public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); if( savedInstanceState != null ) { this.stackManager = savedInstanceState.getParcelable(  DefaultActivity.stackManagerName ); } if( this.stackManager == null ) { ObjectInputStream in = new ObjectInputStream( this.openFileInput( SETTINGS_FILENAME ) ); this.stackManager = (StackManager) in.readObject(); } if( this.stackManager == null ) { this.stackManager = new StackManager(); }    
  • 32. Now What do We Have? ● Functional UI ● Preferences ● Menu to Invoke Preferences ● Next: ‒ Run it in the Emulator    
  • 33. Creating a Virtual Device Within Eclipse:  Window / Android SDK and AVD  Manager ● New... ‒ Name ‒ Target    
  • 34. Start an Emulator Can be started from Eclipse or Command Line: ‒ Just be sure $PATH is set correctly ● Emulator ­avd <avd­name> ­scale 0.8 ‒ Scale as needed for best results Telnet to the Emulator to help debug. Favorite keys: Cntl­F11 Rotate F6 Trackball    
  • 35. Run within Emulator ● Run / Debug... ● Android Application / OK ● Choose Emulator / OK    
  • 36. Run on a Device ● Attached the device via USB ● Enable USB debugging on the device ● Run or Debug... ● Android Application / OK ● Choose Device    
  • 37. Thank You ● Questions?    

×