Android Simple Development Tutorial eight explains the program needs to implement the functionality, you can create an Android project. See Android Simple development tutorial Three: The first application Hello World, create a new project androidgraphics2dtutorial. Today, we'll start by introducing the framework of the program you created. Then add the following class definition to the project:
Add third party library files
Androidgraphics2dtutorial called the Guide Bee two-dimensional graphics library, so you need to add a Third-party library Reference (Libgisengine.jar) to the project, open the Android Properties window, and add external JARs. To add Libgisengine.jar to the project, the Guide Bee two-dimensional graphics library is part of the Guide Bee map development package. Add library references see Android Guide Bee Map Development Example: basic knowledge.
Class description, the following table lists a brief description of the classes defined in the project:
Class |
Description |
Androidgraphics2dapplication |
Application classes, for application subclasses |
Androidgraphics2dtutorial |
The main activity, a listactivity subclass, for listing other examples. |
Guidebeegraphics2dsurfaceview |
Surfaceview class for displaying graphics |
Guidebeegraphics2dview |
The view subclass is used to display graphics, which, like Guidebeegraphics2dsurfaceview functionality, can be interchanged in a program. |
Sharedgraphics2dinstance |
A shared class object is defined, consisting mainly of graphics2d |
Graphics2dactivity |
Activity subclass, for all sample base classes, defines some of the class variables and functions that all sample shares. |
Bezier,brush,colors,font,image,path,pen,shape,transform |
A subclass of graphics2dactivity that demonstrates each function for a two-dimensional graphic |
Androidgraphics2dapplication, in fact, in general Android applications, no need to define application derived classes, such as in the Hello World is not defined, when it is if you want to share variables in multiple activity , or you want to initialize some global variables, you can define application derived classes, and then call Getapplication () or Getapplicationcontext () in the activity or service. To get the Application object, you can access some of the shared variables defined in application. In this case, the androidgraphics2dapplication is either strictly or undefined, to illustrate the problem, or to initialize the Graphics2D instance, graphics2d instances can be all sample activity, such as colors, Font access. If you define a application derived class, you need to describe the location of the application derived class in Androidmanifest.xml.
<manifest xmlns:android=”http://schemas.android.com/apk/res/android ”
package=”com.pstreets.graphics2d ”
android:versionCode=”1″
android:versionName=”1.0″>
<application android:name=”AndroidGraphics2DApplication ”
android:icon=”@drawable/icon” android:label=”@string/app_name”>
<activity android:name=”.AndroidGraphics2DTutorial”
android:label=”@string/app_name”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
…
</application>
<uses-sdk android:minSdkVersion=”4″ />
</manifest>
Application can overload onCreate () and Onterminate (), OnCreate () at the start of the application, and Onterminate () execute once in the application launch. Initializes the graphics2d instance in the OnCreate () of androidgraphics2dapplication:
public void onCreate() {
SharedGraphics2DInstance.graphics2d=
new Graphics2D(SharedGraphics2DInstance.CANVAS_WIDTH,
SharedGraphics2DInstance.CANVAS_HEIGHT);
}
Androidgraphics2dtutorial is a listactivity subclass, read directly from the Androidmanifest.xml Intent-filter catetory is All activity of the Com.pstreets.graphics2d.SAMPLE_CODE.
private static final String SAMPLE_CATEGORY= "com.pstreets.graphics2d.SAMPLE_CODE" ;
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null );
mainIntent.addCategory(SAMPLE_CATEGORY);
...