Recently recommended by apprentices, interested in visual data. A language called Processing is used.
Processing is a relatively new language. It has been widely used as an alternative language for Java. The principle is that Java is used as the interpreter of the overall language, and some technical means can be used to make the code of Processing language go through some brief modifications and become the Java source code, then compile the program in Java.
Because the syntax structure is very concise, Processing is widely used in art and interaction applications. Processing has two common functions: setup () and draw (). The setup () function is similar to the main function in other languages. It is the program entry and will be executed once after the program initialization. The draw () function is a scheduled callback function (executed 60 times per second ). With these two functions, you can easily create programs that include iteration, interaction, animation, and so on.
Since Processing and Java are almost identical, Processing code is also very useful in Java. After all, a modification process is required from Processing to Java. Therefore, there are still some issues to note when using Processing in Android projects.
First, as a professional developer on the Android platform, we use the Processing architecture, rich functions, and the idea of setup and draw functions, instead of all the syntaxes of Processing.
The second point is that some native functions in Processing need to be converted by programmers. The specific conversion method can be queried in these two places:
1: http://wiki.processing.org/w/Android
2: http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/index.html
(Note: Javadoc in article 2 is written for a pure Java environment instead of an Android environment. Therefore, the inheritance relationship may have some problems. So we recommend that you directly check the source code)
Having said so much, what are the advantages of Processing on Android? Then I will use an example to show you how to use Processing for development in Android. I believe you will understand it with patience!
Step 1: Download Processing
: Http://www.processing.org/
I use Mac OS Lion with Android SDK r16, and the operations on other systems are similar.
Step 2: Create a project in Eclipse.
As you can see, I didn't use the Wizard to create an Activity. The specific reason can be seen later.
Note: Processing currently only supports Versions later than 2.2 (API Level 8.
Step 3: import the Processing-core package to the project.
Change android-core.zip in the figure to A. jar file, and the Processing-core package is obtained.
Step 4: Compile "PApplet"
PApplet is the entry program for all Processing. The program compiled by the user must inherit from the PApplet class. You also need to write the setup () and draw () functions to call back them together.
The program content is as follows:
package cn.Friskit;import processing.core.*;public class ProcessingRun extends PApplet{public void setup(){strokeWeight(5);} public void draw(){line(mouseX,mouseY,pmouseX,pmouseY);}}
The functions of the above program are similar to those of an electronic whiteboard. Draw by dragging your finger on the device.
It is very troublesome to implement similar functions on the traditional Android platform! However, in the Processing framework, only a few lines of actual code can achieve the same effect. We can see that Processing has inherent advantages in interaction and animation...
Step 5: register the Activity
Obviously, to let the system run this program, you also need to register this ProcessingRun in AndroidManifest. xml. Add the following content to the <Application> node:
<activity android:name=".ProcessingTest"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>
Careful readers will certainly add an Activity here. However, our ProcessingRun is just a class inherited from PApplet.
Here we need to analyze the following PApplet structure.
We can find these codes from Processing of Android:
By analyzing the source code of PApplet, we can easily find that PApplet is an Activity that encapsulates many functions. Processing also implements functions such as OnCreate to build a good framework for subsequent use.
Therefore, it is no problem to register a class inherited from PApplet to AndroidManifest. xml as an Activity.
The final execution is similar to what we imagined.
Well, this Processing on Android development tour will be written here first.
Processing does not support Android as well as native Java. No documents have been written. However, we can read the source code to see how Processing works. Now, let's talk about this much. We are looking forward to the next study!