Android basics

443 views

Published on

Published in: Self Improvement
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
443
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android basics

  1. 1. Android ProgrammingWorkshop in University College Ghent Ismo Harjunmaa
  2. 2. Content of the Workshop:1. How android programming differs from plain Java programming2. Tools for developers3. Making Hello World4. Making simple game5. Deploying application to Android device6. Publishing application in Adnroid Marketplace 2Ismo Harjunmaa – Workshop Gent 9.2.2012
  3. 3. Folder structure of Android project  .java Source files are in src-folder  R.java resource class in gen-folder  Fonts etc. in assets-folder  Project specific resources res-folder  Graphic files in drawable-folders  Vertical UI layout in layout-folder  User-interface texts, tables, styles and colors in values-folder 3Ismo Harjunmaa – Workshop Gent 9.2.2012
  4. 4. Activity-class The core of your application All the event handlers are implemented in this class (these classes) 4Ismo Harjunmaa – Workshop Gent 9.2.2012
  5. 5. UI layout in XML-file By default main.xml file is created in folder res/layout All the User Interface elements are described in XML-file Root element is the layout and there is eight different ones to pick from 5Ismo Harjunmaa – Workshop Gent 9.2.2012
  6. 6. Designing UI layout UI is designed in Eclipse either in graphical layout view or writing elements with attributes to main.xml Elements are placed by dragging them from library 6Ismo Harjunmaa – Workshop Gent 9.2.2012
  7. 7. Description file AndroidManifest.xml The most important description file AndroidManifest.xml is created in the root folder of your project In this file you can specify level of the API, screen resolution support, testing methods, permissions etc. Eclipse shows the attributes of the file either in plain text or selection fields 7Ismo Harjunmaa – Workshop Gent 9.2.2012
  8. 8. Content of the Workshop:1. How android programming differs from plain Java programming2. Tools for developers3. Making Hello World4. Making simple game5. Deploying application to Android device6. Publishing application in Adnroid Marketplace 8Ismo Harjunmaa – Workshop Gent 9.2.2012
  9. 9. DDMS (Dalvik Debug Monitor Server) Perspective in Eclipse that shows all running emulators or device Inside this perspective is a view where you can emulate incoming call, SMS or GPS-signal In this perspective you can browse the folder structure of the emulator or device 9Ismo Harjunmaa – Workshop Gent 9.2.2012
  10. 10. Android-SDK command-line tools All of the tools that Eclipse uses are actually in the Android-SDK as command-line tools One command-line tool is NOT in Eclipse: adb (Android Debug Bridge) With adb you can list processes, connect to SQLite databases etc. 10Ismo Harjunmaa – Workshop Gent 9.2.2012
  11. 11. Tools for developers: LogCat Developer needs to know bit more what is the state of the application Under folder android-sdk/platform-tools is the adb command Adb logcat shows the logs that device has output 11Ismo Harjunmaa – Workshop Gent 9.2.2012
  12. 12. Tools for developers: LogCat In the code you use logs like this:import android.util.Log;private static final String TAG = HelloWorldActivity.class.getSimpleName();Log.d(TAG, ”This is DEBUG level msg”);Log.e(TAG, ”This is ERROR level msg”); 12Ismo Harjunmaa – Workshop Gent 9.2.2012
  13. 13. Tools for developers: traceview Writes full log from all events into SD-card Remember to choose SD-card size when creating the AVD Application needs permission to write external file Permissions are given in the applications AndroidManifest.xml -file After the trace file is commited traceview is the tool to analyze the trace file 13Ismo Harjunmaa – Workshop Gent 9.2.2012
  14. 14. Tools for developers: draw9patch Application windows have frames which consists nine pieces: upper-left corner, top... etc. So called patch dividing tool is installed with Android SDK Before using the tool you have to draw button, window or frame in drawing tool like photoshop Go to Android­sdk/tools folder and open draw9patch 14Ismo Harjunmaa – Workshop Gent 9.2.2012
  15. 15. Tools for developers: zipalign If you are NOT using Eclipses ADT Plug-in, you have to run zipalign tool which compacts the APK-package 15Ismo Harjunmaa – Workshop Gent 9.2.2012
  16. 16. Tools for developers: sqlite3 In the android-SDK package there is SQLite3 database ready-to-use public class DatabaseHelper extends SQLiteOpenHelper { private static String DATABASE_NAME = "SensorGame"; private static int DATABASE_VERSION = 3; public DatabaseHelper(Context context, String name,  CursorFactory factory,int version) { super(context, DATABASE_NAME, null,  DATABASE_VERSION); } ... 16Ismo Harjunmaa – Workshop Gent 9.2.2012
  17. 17. Content of the Workshop:1. How android programming differs from plain Java programming2. Tools for developers3. Making Hello World4. Making simple game5. Deploying application to Android device6. Publishing application in Adnroid Marketplace 17Ismo Harjunmaa – Workshop Gent 9.2.2012
  18. 18. Making Hello World Open Eclipse Choose from menu: File > New... > Android Project Choose Build Target from option list: Android 3.X Android Open Source Project Open main.xml from folder res/layout While on Graphical Layout view drag TextView-element on the layout and set text 18Ismo Harjunmaa – Workshop Gent 9.2.2012
  19. 19. Media player Found in package android.media Can play music or video Played resources are positioned in res/raw folder Common methods are available playing: play() pausing: pause() stopping: stop() 19Ismo Harjunmaa – Workshop Gent 9.2.2012
  20. 20. Sensors in Android Device From version 1.6: Light, Proximity, Temperature, Pressure, Gyroscope, Accelerometer, Magnetic field, Orientation From version 2.3: Gravity, Linear acceleration, Rotation vector, Near Field Communication Not all of them are in your device SensorManager is the class which controls the sensors 20Ismo Harjunmaa – Workshop Gent 9.2.2012
  21. 21. Making simple game Create another Android project: File > New... > Android Project Drag three textViews and three seekBars onto the main.xml Give names for views and bars like XView, XBar, YView, YBar... so you can reference them 21Ismo Harjunmaa – Workshop Gent 9.2.2012
  22. 22. Making simple game In this example we are using Acceleration sensor Use the SensorManager to create the acceleration sensor For using sensor you have to first register the sensor and on leave unregister 22Ismo Harjunmaa – Workshop Gent 9.2.2012
  23. 23. References Komatinemi, MacLean & Hashimi: Pro Android 3

×