Experiment 1: Your first app.
Create a new project with using this source in eclipse, try to troubleshoot and debug yourself when you find any package which is missing or method which cannot use.
- 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);
- }
- }
Some Importance Android API:
- android.app
- android.content
- android.database
- android.database.sqlite
- android.graphics
- android.graphics.drawable
- android.graphics.glutils
- android.hardware
- android.location
- android.media
- android.net
- android.opengl
- android.os
- android.provider
- android.sax
- android.speech.recognition android.telephony
- android.telephony.gsm
- android.text
- android.text.method
- android.text.style
- android.util
- android.view
- android.view.animation
- android.webkit
- android.widget
Android related file types:
Java --- application source files
Android itself is written in part by java, but applications must be java development
class --- java compiled object file:
Compiled by the java virtual machine from a byte code file, before we learned in the j2ee and j2se it is an executable file, but Android is just a transition file
dex --- Android platform, executable files:
Android provides a virtual machine (Dalvik), this is not the byte code java virtual machine execution, but another byte code: dex bytecode format, the JVM will compile java file Class file, again through the Android platform tools into this Class file dex.
APK file ,the installation file --- Android
APK package is the package file for Android, an Android installation package includes an Android application with all documents related to, all the necessary files , apk file androidManifest.xml file, application code (dex files), resource files and other files into a compressed package, a project can only execute an apk file once (similar to the exe file).
Experiment 2: Interface Design: Control and Layout
【Objective】
Android based programming, UI design.
Android based programming, UI design.
【Requirements】
1, Understanding the principles of Android programming
2, Master the interface controls designed
3, Master the control program event handling
【Principle】
UI Design Principles
【Process】
1. understanding the basic functions of various controls
Various controls:
Menu
TextView、EditText、
Button
Radio button
List
Progress Bar
2. to understand the application layout
By various controls layout, we can determine how the object to be displayed on the screen, and also the mutual position relationship. To have a good machine interface, we must have some knowledge of the layout, select the appropriate layout of the arrangements for the various controls.
By various controls layout, we can determine how the object to be displayed on the screen, and also the mutual position relationship. To have a good machine interface, we must have some knowledge of the layout, select the appropriate layout of the arrangements for the various controls.
A variety of Layout:
AbsoluteLayout
FrameLayout
GridView
LinearLayout
ListLayout
RadioGroup
TableLayout
3. Arranged the layout of various controls by the XML, designe a well-designed user interface.
Insert these code into your example:
<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:id="@+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText android:id="@+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/adr"
/>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_name"
/>
<Button android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stp_name"
/>
</LinearLayout>
<ProgressBar android:id="@+id/progressbar01"
android:layout_width="fill_parent"
android:layout_height="20px"
style="?android:attr/progressBarStyleHorizontal"
/>
<SeekBar android:id="@+id/seekbar01"
android:layout_width="fill_parent"
android:layout_height="20px"
style="?android:attr/progressBarStyleHorizontal"
/>
</LinearLayout>Experiment 3: Drawing with OpenGL ES graphics
【Objective】
Draw various graphics on the screen, understanding OpenGL
【Requirements】
1, understand the screen drawing methods
2, understand OpenGL
【Process】
1, draw a straight line, Park, curves and other graphical
2, display a character
3, OpenGL ES Programming
Android's graphics system using Client / Server architecture. Server (ie SurfaceFlinger) mainly written in c + + code. Client-side code is divided into two parts, provided by the Java application using the api, the other part is written in c + + by the underlying implementation.
Android graphics system draw the screen, using “view” to develop a “Canvas” by a “surface”, which management the “view” in the drawing operations on the “surface”. “View” provides a method, its subclasses (e.g. TextView, Button) on the surface to be painted.
OpenGL ES (OpenGL for Embedded Systems) is an embedded application, free of charge, to support full-featured 2D, 3D cross-platform API (OpenGL ® ES is a royalty-free, cross-platform API for full-function 2D and 3D graphics on embedded systems - including consoles, phones, appliances and vehicles). At present, there are three versions, 1.0,1.1,2.0.
OpenGL ES 1.0 specification is based on OpenGL 1.3, OpenGL ES 1.1 is based on OpenGL 1.5 specification, 1.1 is fully compatible with 1.0. OpenGL ES 2.0 is refer to the definition of OpenGL 2.0 specification. To put it simply, OpenGL ES is a simplified version of OpenGL for embedded applications, for standard used android. Api OpenGL ES 1.1 emphasizes hardware acceleration, OpenGL ES 2.0 more emphasis on 3D acceleration.
OpenGL ES 1.1 and OpenGL ES 2.0 has no relationship between the old and new versions, but a relatively, for low-end applications, and the other one for advanced applications, 2.X is not hundred percent compatible with 1.X.
Android now supports the 1.X and 2.X. OpenGL ES is designed for embedded and mobile devices, lightweight design of a 2D/3D graphics library, which is based on OpenGL API design, has a subset of three-dimensional OpenGL graphics API. There are three Android OpenGL-related packages:
android.opengl
javax.microedition.khronos.egl
javax.microedition.khronos.opengles
Unzipped OpenGL and import to your workspace:
Folder Name: hello
Main Class: HelloActivity
Package: com.android.test
Experiment 4 : Network Access and Services
【Objective】
Network access control method for Android
【Requirements】
1, to access a web site from mobile phone
2, data access through the network
3, learn to use the database
【Principle】
Network access protocol using Android
【Process】
1, access WEB sites, through the HttpResponse class, read the network data.
Android SDK network packets/API:
API
|
Description
|
android.net
|
Android network access socket. The package includes the URI class, not just the traditional networking
|
android.net.http
|
Process an Android http protocol。
|
android.net.wifi
|
Android Wi-Fi related method。
|
android.telephony.gsm
|
Android telephony class contains SMS and telephony method。
|
Some other packages may needed, refer to J2ME and google:
Try to print web resource into your screen:
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();
InputStream is = entity.getContent();
String s = null;
if (is != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[512];
int ch = -1;
int count = 0;
while ((ch = is.read(buf)) != -1) {
baos.write(buf, 0, ch);
count += ch;
if (length > 0) {
listener.taskProgress(this, count, length);
}
Thread.sleep(100);
}
Log.e("HttpTask", "length=" + baos.toByteArray().length);
s = new String(baos.toByteArray());
}
return s;