| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The primary goal of this project is to make it foolishly easy to create Android apps using the Processing API. Once you have Processing on your machine (and the Android developer tools), you can simply write a line of code, hit Run (Ctrl-R or Cmd-R), and have your sketch show up in the emulator as a working Android app. Select Run on Device (Ctrl-Shift-R or Cmd-Shift-R) to have it run on an Android device that you have plugged into your machine. That's good stuff!
Note that this code is incomplete and contains bugs. It should be considered "beta" quality. Do not use this code while operating heavy equipment. Do not rely on this code for thesis or diploma work, as you will not graduate. Do not use this code if you're prone to whining about incomplete software that you download for free.
We currently have no plans to make a version of the development environment (the PDE) that runs on the phone, but the following unofficial apps are on Google Play:
After installing the mode through the Contribution Manager, you should be able to enable it through the mode selector in the PDE's toolbar. The first time you switch into the mode, if will ask to either automatically download and install the Android SDK, or select an already installed SDK.
To manually install the SDK, download the SDK from this link. After downloading, follow Google's instructions here and then for the Adding Platforms and Packages section, do the following:
Depending on your installation, you may need to update or create a .bash_profile file so the Android SDK can be found. Since this is a hidden file, open the Terminal and type the following command:
defaults write com.apple.Finder AppleShowAllFiles TRUE
Then restart the Finder to see hidden files:
killall Finder
You will now see all hidden files on your system; the .bash_profile file is likely in your user folder. Open it in a text editor, or create the file if it does not already exist. Add the following lines:
export ANDROID_HOME=/Developer/AndroidSDK export PATH=/Developer/AndroidSDK/platform-tools:/Developer/AndroidSDK/tools:$PATH
"/Developer/AndroidSDK" should be the path to your Android installation folder; the other path's on the second line are folders within the SDK folder. Save the .bash_profile file. To hide hidden files again, use the above commands with FALSE instead of TRUE.
64-bit Linux users should also install 32-bit compatibility libraries using something like the following on the command line (up to Ubuntu 12.04):
sudo apt-get install ia32-libs
In newer versions of Ubuntu, you can use the multiarch packages, as described here. More about platform-specific issues can be found in the links to Google's documentation (above).
The latest releases of Processing can be found on the main download page.
Please do not use earlier releases and older SDKs. Help us out by using the most current release and filing a bug if you run into a problem.
Read the revisions.txt document in the download to find out what's new and old in this release.
To build for Android, select “Android” from the drop-down box in the toolbar (by default it reads “Java”). This places the current editor window into Android mode. To show you that you've now entered a new world, the window will also get a lot more green.
The Run and Export features change a bit in Android mode:
Use this forum for questions about Processing for Android. Do not put questions in the general questions category, otherwise it's gonna be a confusing mess.
Do not use the forums to post bug reports, I cannot fix bugs if they only show up on the forum, and I cannot track bugs that are posted there.
If you find a bug, please file it here, clearly noting that it's an issue on the Android side. Please report issues: as much as I'd like to sit over the shoulders of you and the other 40-50,000 people who will do battle with Processing this week, current laws of physics disqualify me. If it's not in the bugs database, I don't know about it, and it probably won't be fixed. Second, it's much easier for me to mark a bug as duplicate rather than trying to separate a new issue that's been added to an existing bug, so please just file issues (however related they may seem) separately.
A list of known bugs can be found here.
If it's a known bug, just click the star at the top of the bug report. This gives it a “vote,” and lets me know that more people are having the problem. (Do not reply to the report and say "this is broken!" because we already know that.)
cd /Applications/Processing.app/Contents/PlugIns/jdk1.7.0_45.jdk/Contents/Home/jre/bin ln -s /Library/Java/Home/bin/javac javac
Be sure to change the JDK version to match your installation (you can go to this folder yourself by right-clicking on the Processing icon and selecting "Show Package Contents". You will need to restart Processing, but it should work! Fix via Ruairi.
Before testing your sketch on your device, you must:
A guide for the excited, hopeful, weary, and confused.
In a future release, we plan to include a proper API for touch and gesture events. Unfortunately, it looks like time is running out to bake this into the 2.0 release, so we're backing off a bit. In 2.0 beta 7, a number of changes have happened to make things more compatible with the desktop and JavaScript versions of Processing:
import android.view.MotionEvent;
void mouseDragged() {
MotionEvent me = (MotionEvent) mouseEvent.getNative();
// code here, like me.getHistorySize() and other Android-y things
}This may not work (did not for Processing 2.0b8 and a Nexus tablet); the following will allow access to the full selection of MotionEvent methods (full version here):
import android.view.MotionEvent;
String touchEvent = ""; // string for touch event type
float pressure = 0.0; // pressure and size variables
float pointerSize = 0.0;
// add the following to the bottom of your sketch; this code overrides the
// built-in method, then sends the data on after we capture it
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
x = event.getX(); // get x/y coords of touch event
y = event.getY();
int action = event.getActionMasked(); // get code for action
pressure = event.getPressure(); // get pressure and size
pointerSize = event.getSize();
switch (action) { // let us know which action code shows up
case MotionEvent.ACTION_DOWN:
touchEvent = "DOWN";
break;
case MotionEvent.ACTION_UP:
touchEvent = "UP";
pressure = pointerSize = 0.0; // when up, set pressure/size to 0
break;
case MotionEvent.ACTION_MOVE:
touchEvent = "MOVE";
break;
default:
touchEvent = "OTHER (CODE " + action + ")"; // default text on other event
}
return super.dispatchTouchEvent(event); // pass data along when done!
} void keyPressed() {
// doing other things here, and then:
if (key == CODED && keyCode == android.view.KeyEvent.KEYCODE_BACK) {
keyCode = 0; // don't quit by default
}
} void keyPressed() {
if (key == CODED) {
if (keyCode == DPAD) {
// user pressed the center button on the d-pad
} else if (keyCode == UP) {
// user triggered 'up' on the d-pad
} else if (keyCode == DOWN) {
// user triggered 'down' on the d-pad
} else if (keyCode == LEFT) {
// user triggered 'left' on the d-pad
} else if (keyCode == RIGHT) {
// user triggered 'right' on the d-pad
}
}
} void keyPressed() {
if (key == CODED) {
if (keyCode == BACK) {
// do something here for the back button behavior
// you'll need to set keyCode to 0 if you want to prevent quitting (see above)
} else if (keyCode == MENU) {
// user hit the menu key, take action
}
}
}Other key codes can be found in the Android documentation for KeyEvent. We're including what we feel are the essentials, so as not to pollute the namespace too much. To use one of those constants, you'd do something like the following, replacing KEYCODE_HOME with whatever other key code you wish. For instance, you might want KEYCODE_VOLUME_DOWN, KEYCODE_VOLUME_UP, KEYCODE_CAMERA, etc.
void keyPressed() {
// doing other things here, and then:
if (key == CODED && keyCode == android.view.KeyEvent.KEYCODE_HOME) {
// override the home key here
}
}<source lang="processing"> size(displayWidth, displayHeight, P3D); </source>
void setup() {
size(displayWidth, displayHeight, P3D);
} void setup() {
}
public void settings() {
size(displayWidth, displayHeight, P3D);
}Basically, we opted not to duplicate the (error-prone) dark magic used in the desktop version to change the sketch size mid-setup.
public String sketchRenderer() {
return P3D;
} orientation(PORTRAIT); // the hamburger way
orientation(LANDSCAPE); // the hot dog way // Place this at the top of your sketch
import android.util.DisplayMetrics;
// Place this inside your setup() method
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
float density = dm.density;
int densityDpi = dm.densityDpi;
println("density is " + density);
println("densityDpi is " + densityDpi);The Android documentation describes the 'density' value like so:
This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.The densityDpi value is simply 160 on a 160dpi screen, and you can guess what it is on a 240dpi screen. More can be found in the [http://developer.android.com/reference/android/util/DisplayMetrics.html DisplayMetrics] documentation.
If you want to load data from the internet, or otherwise connect to other servers, you'll need to enable INTERNET permission for your sketch. To do so, use Tools → Android Permissions to bring up the permissions editor. Check the box next to internet.
If you want to use methods like saveStrings() or createWriter, you'll need to enable WRITE_EXTERNAL_STORAGE so that you can save things to the built-in flash a plug-in card.
There are similar permissions for access to the phone, compass, etc. Look through the list in the permissions dialog, or check out other documentation that explains Android permissions in greater detail.
We hope to have simple examples or libraries for some of this. For multi-touch, I recommend this code that handles some of the awfulness. For other features, please help us out by writing examples and tutorials on how it works. Then we can include them on the site and with the Processing download.
Note, however, that any of these examples will come later—once the software and processing.core has been debugged. So don't hold your breath waiting for us. You'll be disappointed. And turn blue.
In release 0193, examples have been added for the Compass and Accelerometer. These are very basic (and need additional improvements and API tweaks), but should be helpful for getting started.
The Ketai library is designed for working with Android sensors and devices in Processing. It includes classes and examples for using device cameras, hardware sensors, multi-touch gestures, databases, and peer-to-peer networking via Bluetooth, WiFi, WiFi Direct, and NFC.
You should only use Eclipse/Android Studio for Android development if you've already spent time learning how to develop Android applications using Eclipse/Android Studio (separately from Processing), and want to make use of the Processing core library. Android development in Eclipse/Android Studio is significantly more difficult than desktop Processing/Java development with Eclipse. Take time to learn it if you're going this route: get a book, read some Android development tutorials, etc.
In case you already know how to develop Android apps using these advanced IDEs, it is not that difficult either. All our core code is bundled inside the **android-core.zip** file. You just need to rename this file to **android-core.jar** and add it as a dependency to your project. Step by step procedure for both the IDEs is as follows :
For nearly everything else, you're on your own. The point of the PDE is to not have to use something like Eclipse. When you shoot yourself in the foot, don't complain to us when it hurts. Don't take your guns to town, son. Leave your guns at home, Bill.
The following are basic Processing-based projects for Android Studio and Eclipse that include a minimal sketch. These can be used as the starting point for full apps.
Android Studio is the default IDE from Google to develop Processing apps, with the ADT plugin for Eclipse no longer supported. This sample project for AS was created using AS 1.5.1. As for the general steps to use Processing in AS:
Although the ADT plugin for Eclipse is no longer supported by Google, I kept this section for those of you who are still hanging to it :-) This sample project. was created with Mars.2 Release (4.5.2), using the latest available version of ADT. The basic steps to create this project were:
You can also help us make Processing for Android better! Either Android Studio and Eclipse+ADT allows you to debug an android app and step into the android-mode source code to understand how things work under the hood, and also find and fix bugs. In the case of Eclipse, this is actually fairly easy, all you need to do is to add the android-core project as a dependency to your main project (instead of the android-core.jar file as explained so far), and making sure that it is added to the Order and Export list in the Java Build Path. But as pointed out already, Android Studio is the only officially supported IDE for Android looking forward, so it is a better idea to use it instead.
It turns our that working with multi-project setups and depending libraries is a little bit more involved in Android Studio, at least that was my initial experience. All dependencies need to be added as subfolders alongside the main app project, and configured as Android library projects, as explained in this guide. The steps indicated in this post are also useful to understand how to work with libraries in Android Studio. Summarizing these guides, I put together another sample project where the main app depends on android-core, which is included as an Android library. A couple of important notes:
We definitely do not recommend incorporating Android GUI components into Processing sketches. The drawing model is incompatible, and like using AWT/Swing components can cause trouble with the desktop version of Processing, the same issues apply here: they might work in some cases, but will be inconsistent across other devices and/or Android OS versions.
Because a Processing sketch is an Android Fragment, it is possible to embed a Processing sketch within another application by doing some extra work, however, we don't offer embedding support neither in the Processing API nor the PDE. You would need to figure out the details on your own, and use a more advanced IDE such as Eclipse or Android Studio. Please refer to this section of the wiki on how to setup these IDEs to develop Processing-based apps.
It's a lot more fun to share your applications with other people. I'll build out this section as we clear up the features that make it easier to publish your apps on the market (or to make them available yourself from a web page). You might want to read Google's guidelines on Preparing to Publish.
To publish with the market, your application must be signed. You can use the "Export Signed Package" option in the File Menu to do it. The first time Processing will create a keystore for you, and the only required information you need to provide is the keystore password. Optionally, you can also enter first and last name, organization unit and name, city, state, and country code. The next time you use the export option, you would only need to enter the password, unless you choose to reset it, in which case you will be able to set a new password and all additional information if you want to. Once signed, the package will be available in the android/bin subfolder, inside the sketch folder, with the name <sketch></sketch>-release-signed.apk
You can also “Export” your code, and self-sign it by following these instructions from Google. A great, clear instruction on signing and deploying your app you can find here! (added by RvG)
Starting with revision 0190, it's possible to specify an icon that goes with your sketch. Actually Android wants lots of icons, which cover the varying screen resolutions where your app might show up, and the different contexts (launcher icons or a long list) where your app might be used.
All sketches use a default icon unless you specify otherwise. To create your own, save images as icon-36.png, icon-48.png, and icon-72.png. These should be 36x36, 48x48, and 72x72 pixel icons. Place them in the sketch folder (not the data folder or any other subfolder). The next time you build your app, these will be used instead of the defaults.
Your icons shouldn't just be images that use the full area of the icon. See the design guidelines for information on how to size, color, and shade your icons.
Starting with revision 0190, Android sketches have an AndroidManifest.xml file in their sketch folder. This is manipulated by the various options that control permissions, naming of the sketch, etc. You can also make edits yourself, but keep in mind that breaking the manifest file can cause a lot of trouble. If you start making changes, be sure to back up your previous file first.
Also, be sure to modify the copy in your sketch folder, not the file created by using Export or Export to Application. Those will be replaced next time you use the Export function. In some cases, you may want to make tweaks to the exported folder, but be sure to move it to a new location first so that you don't inadvertently lose changes when using the Export command again.
| Back | FazBrowse Home | New Git URL |