Beruflich Dokumente
Kultur Dokumente
A. Module Descriptions This module explain about how to develop android application such as simple calculator, ebook application and etc. In this module we will learn about basic for android programming such as layout, image, text , dialog, widget, intent, multimedia and database. Before learn this module , participants must have
B. Module Manual At the begining of lesson the participants learn about using ADT-Bundle Software to develop Android Application. It will follow with creating mobile application projects with Android programming.
C. Competence Standard After learning this module the participants are able to develop mobile application with Android programming.
Page 1
A. Learning Objectives In this section, we will be discussing the characteristics of mobile devices and how it affects program development for these devices. We will be introduced to the Android. At the end of the lesson, the participants should be able to: Creating a new blank project in Eclipse Understanding errors Creating an emulator Setting up and copying launch configurations Running your first app Studying the anatomy of a project Creating Layout Displaying Image
B. Description 1. Android Overview Computing is more accessible than ever before. Handheld devices have transformed into computing platforms.Be it a phone or a tablet, the mobile device is now so capable of general-purpose computing that its becoming the realpersonal computer (PC). Every traditional PC manufacturer isproducing devices of variousform factors based on the Android OS. The battles between operating systems, computing platforms, programming languages, and development frameworks are being shifted and reapplied to mobile devices.
applications start to offer mobile counterparts. In this book, well show you how to take advantage of your Java skills to write programs for devices that run on Googles Android platform (http://developer.android.com/index.html), an open source platform for mobile and tablet development.
Why Develop for Android? Market share As a developer, you have an opportunity to develop apps for a fairly new market that is booming on a daily basis. Android is currently set to outpace many other carriers in market share in the industry in coming months. With so many users, its never been easier to write an application that can be downloaded and used by real people! The Android Market puts your app right into your users hands easily! Users dont have to go searching the Internet to find an app to install. They just simply go to the Android Market that is preinstalled on their device, and they have access to all your apps. Because the Android Market comes preinstalled on most Android devices (I discuss a few exceptions later), users typically search the Android Market for all of their app needs. Its not hard to see an apps number of downloads soar in just a few days. Time to market With all the application programming interfaces (APIs) that Android comes packed with, its easy to develop full -featured applications in a relatively short time frame. After youve signed up with the Android Market, just upload your apps and publish them. Wait, you may say, are you sure? Why, yes, I am! Unlike other mobile marketplaces, the Android Market has no app-approval process. All you have to do is write apps and publish them.Technically, anyone can publish anything, but its good karma to keep within Googles terms of service and keep your apps family-friendly. Remember that Android users come from diverse areas of the world and are in all age categories.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 3
Open platform The Android operating system is open platform,meaning that its not tied toone hardware manufacturer and/or one provider. As you can imagine, the openness of Android is allowing it to gain market share quickly. All hardware manufacturers and providers can make and sell Android devices. The Android source code is available at
http://source.android.comfor you to view and/or modify. Nothing is holding you back from digging into the source code to see how a certain task is handled. The open-source code allows phone manufacturers to create custom user interfaces (UIs) and add built-in features to some devices. This also puts all developers on an even playing field. Everyone can access the raw Android source code.
Android Programming Basics If youve never programmed before, this book may not be the best place to start. I advise that you pick up a copy of Beginning Programming with Java For Dummies,by Barry Burd (Wiley Publishing), to learn the ropes. After you have a basic understanding of Java under your belt, you should be ready to tackle this book. Although the majority of Android is Java, small parts of the framework arent. Android also encompasses the XML language as well as basic Apache Ant scripting for build processes. I advise you to have a basic understanding of XML before delving into this book.
If you need an introduction to XML, check out XML For Dummies,by Lucinda Dykes and Ed Tittel (Wiley). If you already know Java and XML, congratulations youre ahead of the curve!
Page 4
Java: Your Android programming language Android applications are written in Java not the full-blown Java that J2EE developers are used to, but a subset of Java that is sometimes known as the Dalvik virtual machine.This smaller subset of Java excludes classes that dont make sense for mobile devices. If you have any experience in Java, you should be right at home.
It may be a good idea to keep a Java reference book on hand, but in any ase, you can always Google what you dont understand. Because Java is nothing new, you can find plenty of examples on the Web that demonstrate how to do just about anything.
In Java source code, not all libraries are included. Verify that the package is available to you. If its not, an alternative is probably bundled with Android that can work for your needs.
Activities Android applications are made up of one or more activities. Your app must contain at least one activity, but an Android application can contain several. Think of an activity as being a container for your UI, holding your UI as well as the code that runs it. Its kind of like a for m, for you Windows programmers out there.
Intents Intentsmake up the core message system that runs Android. An intent is composed of an action that it needs to perform (View, Edit, Dial, and so on) and data. The action is the general action to be performed when the intent is received, and the data is the data to operate on. The data might be a contact item, for example.
Page 5
Intents are used to start activities and to communicate among various parts of the Android system. Your application can either broadcast an intent or receive an intent.
Cursorless controls Unlike PCs, which let you use a mouse to move the cursor across the screen, Android devices let you use your fingers to do just about anything a mouse can do. But how do you right-click? Instead of supporting right-clicking, Android has implemented the long press. Press and hold a button, icon, or screen for an extended period of time, and a context menu appears. As a developer, you can create and manipulate context menus. You can allow users to use two fingers on an Android device instead of just one mouse cursor, for example. Keep in mind that fingers come in all sizes, however, and design your user interface accordingly. Make the buttons large enough, with enough spacing, so that even users with large fingers can interact with your apps easily.
Views and widgets What the heck is a view? A viewis a basic UI element a rectangular area on the screen that is responsible for drawing and event handling. I like to think of views as being basic controls, such as a label control in HTML. Here are a few examples of views: ContextMenu Menu View Surface view Widgetsare more-advanced UI elements, such as check boxes. Think of them as being the controls that your users interact with. Here are a few widgets: Button CheckBox
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 6
DatePicker DigitalClock Gallery FrameLayout ImageView RelativeLayout PopupWindow Many more widgets are ready for you to use. Check out the android. widgetpackage in the Android documentation at http://developer.
android.com/reference/android/widget/package-summary.html for complete details. Background services If youre a Windows user, you may already know what a serviceis: an application that runs in the background and doesnt necessarily have a UI. A classic example is an antivirus application that usually runs in the background as a service. Even though you dont see it, you know that its running. 2. Software for Development Developer Tools The Android Developer Tools (ADT) plugin for Eclipse provides a professional-grade development environment for building Android apps. It's a full Java IDE with advanced features to help you build, test, debug, and package your Android apps. Full Java IDE
Android-specific refactoring, quick fixes, integrated navigation between Java and XML resources.
Page 7
Build support for complex projects, command-line support for CI through Ant. Includes ProGuard and app-signing.
Graphical UI Builders
Build rich Android UI with drag and drop. Visualize your UI on tablets, phones, and other devices. Switch themes, locales, even platform versions instantly, without building.
Visual refactoring lets you extracts layout for inclusion, convert layouts, extract styles.
Enable debugging over USB. Quickly capture bug reports onto the device. Show CPU usage on screen. Draw debugging information on screen such as layout bounds, updates on GPU views and hardware layers, and other information.
Plus many more options to simulate app stresses or enable debugging options. To access these settings, open the Developer options in the system Settings. On Android 4.2 and higher, the Developer options screen is hidden by default. To make it available, go toSettings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
Page 8
Use any commercial Android hardware device or multiple devices. Deploy your app to connected devices directy from the IDE. Live, on-device debugging, testing, and profiling.
Emulate any device. Use custom screen sizes, keyboards, and other hardware components.
Powerful Debugging
Full Java debugger with on-device debugging and Android-specific tools. Built-in memory analysis, performance/CPU profiling, OpenGL ES tracing.
Page 9
Graphical tools for debugging and optimizing UI, runtime inspecton of UI structure and performance.
Testing
Fully instrumentated, scriptable test environment. Integrated reports using standard test UI. Create and run unit tests on hardware devices or emulator.
Native Development
Support for compiling and packaging existing code written in C or C++. Support for packaging multiple architectures in a single binary, for broad compatibility.
. C. Evaluation 1. What you must prepare for android development ? Operating System Android SDK JDK Bigger and Brighter Mobile Screen Much Money 2. What would motivate you to write programs for mobile devices ? the challenge of writing optimized applications new learning experience fun factor
Page 10
D. Practical Guide 1. Tools and Materials a. Laptop (Min Dual Core 1,8 GHz , Memory 2GB) b. Java SDK 1.7 c. ADT-Bundle d. Tablet (Min 512 RAM)
4) Type a name in the Name field. I recommend using Android ADT, but it can be anything you choose. 5) Type field. https://dl-ssl.google.com/android/eclipse/in the Location
6) Click the OK button. Android ADT is selected in the Work With drop-down menu, and the available options are displayed in the Name and Version window of the Install Details dialog box. 7) In the Install dialog box, select the check box next to Developer Tools, and click the Next button (see Figure Below).
The Install Details dialog box should list both the Android Dalvik Debug Monitor Server (DDMS; see Get physical with a real Android device, later in this chapter) and the ADT.
8) Click the Next button to review the software licenses. 9) Click the Finish button. 10) When youre prompted to do so, click the Restart Now button to restart Eclipse. The ADT plug-in is installed.
Page 13
b. Liner Layout A layout that arranges its children in a single row 1) Step 1 (Horizontal Layout) Run eclipse,choose File > New > Android Project.
Fig. 1. 6 LinearLayout1
Click Next.
Page 14
Click Next.
Click Next.
Page 15
Click Next.
Click Finish.
Page 16
4) Step 4 Type these codes. Although it is too long, for right now you just need to write one pattern, just copy-paste-Edit. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:layout_gravity="center_horizontal" android:background="#aa0000" android:text="Red" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:layout_gravity="center_horizontal" android:background="#0000aa"
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 17
android:text="Blue" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:layout_gravity="center_horizontal" android:background="#00aa00" android:text="Green" />
</LinearLayout>
</LinearLayout> 5) Step 5 Layout activity_linear_layout1.xml, if we see this from its hierarky from outline style. It will appear like this
Page 18
Fig. 1. 13 LinearLayout1.java
and Run Program with shortcut CTRL+F11 or right click and choose package > run as > android Project.
8) Step 1 (Vertical Layout) Run eclipse,choose File > New > Android Project.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 19
Click Finish.
11) Step 4 Type these codes. Although it is too long, for right now you just need to write one pattern, just copy-paste-Edit. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#aa0000" android:textSize="15pt" android:text="Line 1" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#0000aa" android:textSize="15pt" android:text="Line 2" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#00aa00" android:textSize="15pt" android:text="Line 2" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#aaaa00" android:textSize="15pt" android:text="Line 4" /> </LinearLayout> </LinearLayout>
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 22
12) Step 5 Layout activity_linear_layout2.xml, if we see this from its hierarky from outline style. It will appear like this
Fig. 1. 19 LinearLayout2.java
and Run Program with shortcut CTRL+F11 or right click and choose package > run as > android Project.
Page 23
symbol,text,etc) can be managed and placed in front of other components. For example OKbutton can be placed under Editext , the Cancel button can be placed on the left side of OK button and under Edittext. The main consept is that another. 1) Step 1 Run eclipse,choose File > New > Android Project. it has connection between one button and
Page 24
Click Finish.
Page 25
4) Step 4 Type these codes. Although it is too long, for right now you just need to write one pattern, just copy-paste-Edit. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >
Page 26
</RelativeLayout>
5) Step 5 Layout activity_relative_layout1.xml, if we see this from its hierarky from outline style. It will appear like this
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 27
Fig. 1. 25 RelativeLayout1.java
and Run Program with shortcut CTRL+F11 or right click and choose package > run as > android Project.
d. Table Layout A layout that arranges its children into rows and columns. 1) Step 1 Run eclipse,choose File > New > Android Project.
Click Finish.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 29
4) Step 4 Type these codes. Although it is too long, for right now you just need to write one pattern, just copy-paste-Edit. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
<TableRow> <TextView android:padding="3dp" android:text="Save..." /> <TextView android:text="Ctrl + S" android:gravity="right" android:padding="3dp"/> </TableRow>
<TableRow> <TextView android:padding="3dp" android:text="Save As..." /> <TextView android:text="Ctrl + Shift + S" android:gravity="right" android:padding="3dp"/> </TableRow>
<TableRow> <TextView android:padding="3dp" android:text="X Export..." /> <TextView android:text="Ctrl + E" android:gravity="right" android:padding="3dp"/> </TableRow>
5) Step 5 Layout activity_table_layout1.xml, if we see this from its hierarky from outline style. It will appear like this
Page 32
Fig. 1. 31 TableLayout1.java
and Run Program with shortcut CTRL+F11 or right click and choose package > run as > android Project.
Page 33
Page 34
e. Image In this step, you added the ImageViewinside your program. An ImageViewallows you to project an image to the devices screen. 1) Step 1 Run eclipse,choose File > New > Android Project.
Click Finish.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 35
4) Step 4 Create a folder with name drawable , in Image1/res/ folder. Like this picture.
5) Step 5 Prepare your image that you want to display. For example trilateral.png. And copy to folder drawable , so you can see like this
6) Step 6 Type these codes. Although it is too long, for right now you just need to write one pattern, just copy-paste-Edit.
<ImageView android:id="@+id/imageView1"
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 37
7) Step 5 Layout activity_image1.xml, if we see this from its hierarky from outline style. It will appear like this
Fig. 1. 39 Image1.java
and Run Program with shortcut CTRL+F11 or right click and choose package > run as > android Project. You will see the result like this .
Page 38
, You will see your program and the others program Like this
10) Step 8 Prepare an Image for your icon , for example icon.png.
Fig. 1. 43 Icon.png
Page 40
Fig. 1. 45 AndroidManifest.xml
Page 41
f. Text Auto Complete 1) Step 1 (Horizontal Layout) Run eclipse,choose File > New > Android Project.
Click Next.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 42
Click Finish.
4) Step 4 Type these codes. Although it is too long, for right now you just need to write one pattern, just copy-paste-Edit.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 43
5) Step 5 Layout activity_text_auto1.xml, if we see this from its hierarky from outline style. It will appear like this
6) Step 6 Open TextAuto1/res/values/string.xml , edit like this : <?xml version="1.0" encoding="utf-8"?> <resources>
<string name="app_name">Make Text Auto Complete Program</string> <string name="Command">Fill with minimal 3 character</string> <string name="hello_world">Hello world!</string>
</resources>
package com.example.textauto1;
import android.graphics.Color; import android.view.Menu; import android.text.Editable; import android.text.TextWatcher; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.TextView;
TextView result; AutoCompleteTextView edit; String[] item = { "Indonesia", "China", "Japan", "Qatar", "Germany","Singapura", "Filipina", "Kamboja", "Brunei Darussalam", "Timor Leste","Myanmar", "Thailand", "Malaysia","India" };
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.text_auto1, menu); return true; }
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub }
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub result.setText(edit.getText()); } }
and Run Program with shortcut CTRL+F11 or right click and choose package > run as > android Project.
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 47
Page 48
E. Assigment Implement any/all of the following projects using simple text boxes (EditText, TextView) and buttons : Create Common Calculator
Page 49