2/22/2012
Advanced Android
Wireless Communication EE 4683-001 Instructor: Dr. David Akopian
Presenter: Arsen Melkonyan
Electrical and Computer Engineering The University of Texas at San Antonio (UTSA) http://utsa.edu
Spring, 2012
1
Create Project
1. Start Eclipse 2. Select File > New > Project. 3. Select Android > Android Project, and click Next. 4. Enter Project name: Temperature Convertor 5. Select Target Android 2.2. 6. Application name: Temperature Convertor 7. Package name: utsa.itec.com 8. 8 Create Activity: TemperatureConvertorActivity 9. Min SDK Version: 8 10. Click Finish.
2/22/2012
Create Project (cont.)
Create Project (cont.)
Once you complete th N O l t the New Project Wizard, ADT creates the following folders and files in your new project:
2/22/2012
Create Project (cont.)
src - Includes your stub Activity Java file. All other Java files for your application go here. <Android Version> - (e.g., Android 1.6) Includes the android.jar file that your application will build against. gen - This contains the Java files generated by ADT, such as your R.java file and interfaces created from AIDL files. assets - This is empty. You can use it to store raw asset files. res - A folder for your application resources, such as drawable files, layout files, string values, etc. AndroidManifest.xml - The Android Manifest for your project. default.properties - This file contains project settings, such as the build target.
AndroidManifest.xml
2/22/2012
Main.xml - GUI View
ScreenSize
AndroidVersion ScreenLayout View
DesignedScreen View
GUIView
XMLView
7
Main.xml - XML View
2/22/2012
Add the EditText Block
EditText Block
Add the RadioGroup Block
RadioGroup Block
10
2/22/2012
Add the Button Block
ButtonBlock Button Block
11
XML View
12
2/22/2012
Modifying the RadioButton 1 - text
RadioButton 1 text
13
Modifying the RadioButton 1 - id
RadioButton 1 id
14
2/22/2012
Modifying the RadioButton 2 - text
RadioButton 2 text
15
Modifying the RadioButton 2 - id
RadioButton 2 id
16
2/22/2012
Modifying the Button - text
Button text
17
Modifying the Button - id
Button id
18
2/22/2012
Modified XML View
19
Test Application on Emulator
20
10
2/22/2012
Source Code- Phase 1
package utsa.itec.com;
import android.app.Activity;
public class TemperatureConverterActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
} }
21
Source Code- Phase 2
public class TemperatureConverterActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final EditText t = (EditText)findViewById(R.id.editText1); final RadioButton celsiusButton = (RadioButton) findViewById(R.id.radioCelsius); final RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radioFahrenheit); Button convert = (B tt ) fi dVi B Id(R id b tt C B tt t (Button) findViewById(R.id.buttonConvert); t)
} }
22
11
2/22/2012
Source Code- Phase 3
final EditText t = (EditText)findViewById(R.id.editText1); final RadioButton celsiusButton = (RadioButton) findViewById(R.id.radioCelsius); fi dVi B Id(R id di C l i ) final RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radioFahrenheit); Button convert = (Button) findViewById(R.id.buttonConvert); convert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } });
23
Source Code- Phase 3
convert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { float inputValue = Float.parseFloat(t.getText().toString()); if (celsiusButton.isChecked()) { celsiusButton.setChecked(false); fahrenheitButton.setChecked(true); } else { fahrenheitButton.setChecked(false); celsiusButton.setChecked(true); l i B tt tCh k d(t ) } } });
24
12
2/22/2012
Source Code- Phase 4
// Converts to Celsius private float convertFahrenheitToCelsius(float fahrenheit) { return ((fahrenheit - 32) * 5 / 9); } // Converts to Fahrenheit private float convertCelsiusToFahrenheit(float celsius) { return ((celsius * 9) / 5) + 32; }
25
Source Code- Phase 5
if (celsiusButton.isChecked()) { t.setText(String.valueOf(convertFahrenheitToCelsius(inputVal t tT t(St i l Of( tF h h itT C l i (i tV l ue))); celsiusButton.setChecked(false); fahrenheitButton.setChecked(true); } else t.setText(String.valueOf(convertCelsiusToFahrenheit(inputVal ue))); fahrenheitButton.setChecked(false); celsiusButton.setChecked(true); }
26
13
2/22/2012
Things to do With the Mobile Device
1. 2. 3. 4. 5. 6. 7. 8. 9. Press Menu button Tap on Settings button Tap on Applications in the menu Put a check for Unknown Sources (to allow installation of non-Market applications) Tap on Development (to set options for application development) Put a check on USB debugging (to enable the Debug Mode when USB is connected) Press Back button to go back to the Settings menu Plug your USB cable into the computer
27
Deploying Application Into the Phone
28
14
2/22/2012
Deploying Application Into the Phone Through Eclipse IDE
RunButton
29
Deploying Application Into the Phone Through Eclipse IDE(cont.)
ConnectedMobileDevice
30
15
2/22/2012
Deploying Application Into the Phone Through Astro
Plug in USB cable to PC and connect the mobile device. Get the APK file somewhere on SD card on the phone p Unplug the USB cable from PC. Use Astro File Manager or some similar app to browse to that file on the SD card and select it, which will prompt you if you want to install the app on your phone.
31
Improving GUI Changing Background Picture
Several images are loaded into the Project. They are located in following directory. Temperature Convertor>>> res >>> drawable p If you want to use a new image in the application do following steps: Load the image into the project: First, copy the image; right click on the < drawable > directory of the project and then paste the image into it. Hint: when adding new image into the application use the images with .png format.
32
16
2/22/2012
Improving GUI Changing Background Picture (Cont.)
ChosetheBackground Picture
33
Improving GUI Changing Background Picture (Cont.)
34
17
2/22/2012
Improving GUI Adding Toast Message
if (t.getText().length() == 0) { Toast.makeText(v.getContext(), "Please enter a valid number", Toast.LENGTH_LONG).show(); return; }else{ // Code }
35
Improving GUI Adding Toast Message (Cont.)
36
18
2/22/2012
Improving GUI Adding Vibration Effects
// Get instance of Vibrator from current Context final Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 300 milliseconds vib.vibrate(300);
37
Improving GUI Adding Vibration Effects / XML View
<uses-permission android:name="android.permission.VIBRATE"/>
38
19
2/22/2012
Testing Application in the Phone
ConnectedMobileDevice
39
Questions?
40
20