Loading...
Logo
Processing Forum
Just curious if anyone out there is also spending their leisure time running Processing Android on a tablet.  I've got it going on a Xoom at the moment. . . am investigating if I can get it to take over the entire screen, as opposed to the little window (lovely as it may be) that I've got at the moment.

Would love to exchange tips, tricks, code, etc!


Replies(14)

While I don't have access to a tablet myself, a few users of one of my apps have reported it working well on a Galaxy Tab and Archos 32 Internet Tablet.

And as a general shout-out, you've been a great Processing resource Mr. Shiffman ;)  I've learned a lot from your examples.
Awesome. Next on my list... keep us posted! (pun intended)
As long as you leave out a size() command that asks for a tiny window, it should be taking over the whole screen.

If it's not, then I may need to add another setting to mark the app as "ready to use enormous screens", because it may be stuck in some sort of compatibility mode for phone-only apps. (If that's the case, and someone wants to track down this magic setting in the sprawling android dev docs, it'd be super helpful.)
leaving out size didn't work on the xoom.  I'll see if I can track down anything more!
Is there any news on this? I've just got a xoom and very keen to start getting my sketches on there.

Jim
Hmmm - this is worth investigating, Dan, as I think XOOM handles its screen resolution differently in order to accommodate HDMI output (which should also be really interesting). Probably the place to start would be to skip size and try manually passing in resolution, which could also mean a way to investigate how non-mirrored output would work...

Might have to drop by and try it out with you, especially as I'm pondering grabbing a XOOM myself. Querying resolution directly is possible - not desirable, but could be used to work backwards to what may be causing the app to fail.
Happy to report that with processing 1.5, if I just leave out size(), it runs in beautiful full screen on the motorola zoom!   Or if you need to, you can say size(1280,800) for full screen resolution.


Hooray!
Hey Dan, have you tried video output yet? Should just work with mirroring based on what I've heard from at least one other Xoom dev...
Hey folks, 

I've managed to get a 3D sketch running on my xoom!

The camera moves from left to right, and then back again. There are two grids, one above and one below, each made up of about 200 lines, so the sketch is rendering about 400 lines in total.  I'd say performance is ok, but it's not amazing, It doesn't feel like it's really using the hardware, it's probably running about 15-20FPS.

I've not seen any difference between using " size(1280, 800, A3D)" and " size(screenWidth, screenHeight, A3D)".  This is a bit of a shame, because I know that you can make apps run in a fullscreen mode where the status bar "virtual-softkeys" are reduced to dots, and the rest of the icons are removed.

However, I'm thrilled to have got this far and I'm going to carry on an see what sensor stuff I can do next.

Code is below, if anyone can see anything that would obviously speed things up, let me know :)

Jim




Copy code
  1. PVector campos, target_p; 
  2. Grid topGrid, bottomGrid;

  3. int direction = 0;
  4.   
  5. void setup() 
  6. {
  7.   size(screenWidth, screenHeight, A3D);

  8.   bottomGrid = new Grid(10,101,255,-50.0);
  9.   topGrid = new Grid(10,101,255,50.0);
  10.   
  11.   campos = new PVector(600,0,0);
  12.   target_p = new PVector(0, 0, 0);
  13.   
  14. }

  15. void draw() 
  16. {
  17.   background(0);
  18.   lights();
  19.   smooth();
  20.   
  21.   if (campos.y > 200) direction = 1;
  22.   if (campos.y < -200) direction = 0;

  23.   if (direction == 0) campos.y++; 
  24.   else campos.y--;

  25.      
  26.   camera(campos.x, campos.y, campos.z, campos.x-1, campos.y, campos.z, 0, 0, -1);

  27.   topGrid.display();
  28.   bottomGrid.display();
  29. }

  30. class Grid
  31. {
  32.   float    spacing;
  33.   int      gridSize;
  34.   int      gridStroke;
  35.   float    zpos;

  36.   Grid(float c_spacing, int c_gridSize, int c_gridStroke, float c_zpos)
  37.   {
  38.     spacing = c_spacing;
  39.     gridSize = c_gridSize;
  40.     gridStroke = c_gridStroke;
  41.     zpos = c_zpos;
  42.   }

  43.   void display()
  44.   {
  45.     for (int i = 0; i < gridSize; i++)
  46.     {
  47.       stroke(gridStroke-150);
  48.       if (i%5 == 0) stroke(gridStroke-100); 
  49.       if (i == 0) stroke(gridStroke); 
  50.       line(-(gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos, (gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos);
  51.       line((i*spacing)-((gridSize/2)*spacing),-(gridSize*(spacing/2)), zpos, (i*spacing)-((gridSize/2)*spacing),(gridSize*(spacing/2)), zpos);
  52.     }
  53.     stroke(0);
  54.   }

  55. }


Line drawing actually needs to be re-implemented on both A3D and OPENGL2. For the time being, I recommend using a PShape3D object in LINES mode for better performance.
... Actually, I take that back, the performance isn't that bad at all.  I've increased the speed at which the camera moves and added " println(frameRate);" into the draw loop. The emulator chugs along at 4fps, but the xoom is cruising at around 36fps.

Jim

Edit:  Thanks Andres, I'll go look at the PShape3D call now :)
Hi Andres

I've changed my grid drawing class to use (what I think is) Pshape3D, but it's not working for me.  It doesn't give any errors, but doesn't render anything on the screen.

I won't paste the whole sketch again, as it's largely unchanged from the version I have in my previous post, except that I'm declaring " PShape gridlines;" at the top of the sketch.  I understand that I don't need to load the openGL libs in android, but I don't know if this includes the openGL2 libs.  If I add " import processing.opengl2.*;" to the top, then the compiler complains that it can't find the package.  

the new grid.dispalyGL() method looks like this, can you see any problems with the Pshape calls?

thanks
Jim


Copy code
  1.   void displayGL()
  2.   {
  3.     //mergeShapes(true);
  4.     gridlines = beginRecord();
  5.     
  6.     for (int i = 0; i < gridSize; i++)
  7.     {
  8.       stroke(gridStroke-150);
  9.       if (i%5 == 0) stroke(gridStroke-100); 
  10.       if (i == 0) stroke(gridStroke); 
  11.  
  12.       beginShape(LINES); 
  13.         vertex(-(gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos);
  14.         vertex((gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos); 
  15.       endShape(); 
  16.   
  17.       beginShape(LINES); 
  18.         vertex((i*spacing)-((gridSize/2)*spacing),-(gridSize*(spacing/2)), zpos);
  19.         vertex((i*spacing)-((gridSize/2)*spacing),(gridSize*(spacing/2)), zpos); 
  20.       endShape();
  21.      }
  22.     endRecord();
  23.     stroke(0);
  24.   }
Hey Folks.
  
I don't want to take over this thread, but I've had a lot of fun today with processing and my Xoom, and I thought I'd share some more code.

I apologise right now, the code is a bit of a mess, I've been so excited that I've not been very tidy!  The code is based on the sketch I wrote and posted above, which displays two grids in 3D.

The camera in the 3D scene now moves in relation to the accelerometer, you tilt the device to move around the scene. it's not great, but it certainly works!  There is also debug code in there, which is commented out for now which will list all the sensors available on your device.

I've spent most of the time I've had today getting bluetooth working, and it does!  The sketch can now connect to another device (probably your Desktop or Laptop) and if it's already paired, it will open a SPP port and send the Accelerometer values along with the frame rate. I don't think it's very robust, and there is no GUI for the selection of the device you want to connect to.  The sketch will list all the paired devices, but you have to add the MAC address of the intended device into the 'BTserver' string.

ToDo... 
- I still can't get Andres suggestion for Pshape3D working...
- I want to try and get "lights-out" mode working for true full-screen
- I need to improve the BT implementation and robustness.
- I want to use the  TYPE_LINEAR_ACCELERATION sensor, but that seems to throw errors.

Copy code
  1. import android.content.Context;
  2. import android.hardware.Sensor;
  3. import android.hardware.SensorEvent;
  4. import android.hardware.SensorManager;
  5. import android.hardware.SensorEventListener;
  6. import android.bluetooth.BluetoothAdapter;
  7. import android.bluetooth.BluetoothDevice;
  8. import android.bluetooth.BluetoothSocket;
  9. import android.view.*;
  10. import java.util.List;


  11. //For Sensors
  12. SensorManager mSensorManager;
  13. MySensorEventListener accSensorEventListener;
  14. Sensor acc_sensor;
  15. float[] acc_values;

  16. //For Debug
  17. //Sensor mSensor;
  18. //List<Sensor> sensors;  

  19. //For Bluetooth
  20. String BTserver = "--------ADD YOUR MAC ADDRESS HERE!------------"; //desktop
  21. BluetoothAdapter mBluetoothAdapter;
  22. BluetoothDevice mBluetoothDevice;
  23. BluetoothSocket mBluetoothSocket;
  24. Set<BluetoothDevice> devices;
  25. String spp_buffer; 
  26.  
  27.  
  28. //For GUI
  29. String[] fontList;
  30. PFont androidFont;

  31. //For 3D Scene  
  32. PVector campos, target; 
  33. Grid topGrid, bottomGrid;
  34. int direction = 0;
  35. float speed = 3; 
  36. PShape gridlines;


  37.   
  38. void setup() 
  39. {
  40.   size(screenWidth, screenHeight, A3D);

  41.   bottomGrid = new Grid(10,101,255,-50.0);
  42.   topGrid = new Grid(10,101,255,50.0);
  43.   
  44.   campos = new PVector(600,0,0);
  45.   target = new PVector(0, 0, 0);

  46.   // Setup Fonts:
  47.   fontList = PFont.list();
  48.   androidFont = createFont(fontList[0], 8, true);
  49.   textFont(androidFont);

  50.   // Debug info
  51.   /*
  52.   println(fontList);  
  53.   sensors = new ArrayList<Sensor>();
  54.   sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
  55.   
  56.   println("Number of sensors found: " + sensors.size());

  57.   for (int i = 0; i < sensors.size(); i++)
  58.   {
  59.     println("----------------");  
  60.     mSensor = (Sensor) sensors.get(i);
  61.     println("Sensor Name:" + mSensor.getName());
  62.     println("Sensor Max Range:" + mSensor.getMaximumRange());
  63.     println("Sensor Type:" + mSensor.getType()); 
  64.   }
  65.   */
  66.    println("------------------------");
  67.   
  68. }


  69. void draw() 
  70. {
  71.   background(0);
  72.   lights();
  73.   smooth();
  74.   
  75.   text((round(frameRate)+"fps"),8,10);
  76.   text(("Accelerometer: " + round(acc_values[0]) + " " + round(acc_values[1]) + " " + round(acc_values[2])), 8, 20);

  77.   //move the camera accordinf to the values from the sensors
  78.   campos.y+=acc_values[0];
  79.   campos.z-=acc_values[1];

  80.   camera(campos.x, campos.y, campos.z, campos.x-1, campos.y, campos.z, 0, 0, -1);
  81.   //camera(campos.x, campos.y, campos.z, target.x, target.y, target.z, 0, 0, -1);
  82.   
  83.   //Draw the grids
  84.   topGrid.display();
  85.   bottomGrid.display();
  86.   
  87.   // populate the buffer with information (string) we want to send. terminate with a " " for a new line
  88.   spp_buffer = round(frameRate)+"fps "+"X:"+round(acc_values[0])+" Y:"+round(acc_values[1])+" Z:"+round(acc_values[2])+" ";
  89.   try 
  90.   {
  91.     //use a printStream to wrap the OutputStream so that we can easily send strings rather than just bytes
  92.     PrintStream printStream = new PrintStream(mBluetoothSocket.getOutputStream());
  93.     //print the buffer
  94.     printStream.print(spp_buffer);
  95.     //flush the buffer
  96.     mBluetoothSocket.getOutputStream().flush();
  97.     
  98.   } catch (IOException e) 
  99.   {
  100.     println("Writing failed: "+e);
  101.   }

  102.   
  103. }

  104. // sources
  105. // -------
  106. // http://www.akeric.com/blog/?p=1313
  107. // http://developer.android.com/reference/android/hardware/SensorEvent.html

  108. void onResume() {
  109.   super.onResume();
  110.   println("RESUMED! (Sketch Entered...)");
  111.   
  112.   // Build our SensorManager:
  113.   mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
  114.   // Build a SensorEventListener for each type of sensor:
  115.   accSensorEventListener = new MySensorEventListener();
  116.   
  117.   
  118.   // Get each of our Sensors:
  119.   acc_sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  120.   // Register the SensorEventListeners with their Sensor, and their SensorManager:
  121.   mSensorManager.registerListener(accSensorEventListener, acc_sensor, SensorManager.SENSOR_DELAY_GAME);


  122.   /////////////////////////////////////////////////
  123.   //bluetooth
  124.   /////////////////////////////////////////////////

  125.   //create a bluetooth adaptor from the default adaptor
  126.   mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  127.   //has that worked?
  128.   if (mBluetoothAdapter == null) 
  129.   {
  130.     println("--Bluetooth adaptor NOT found");
  131.   }
  132.   else
  133.   {
  134.     //get a some info about the adaptor
  135.     println("--Bluetooth adaptor found");
  136.     println("--bluetooth name: "+mBluetoothAdapter.getName());
  137.     println("--bluetooth address: "+mBluetoothAdapter.getAddress());
  138.     println("--bluetooth enanbled: "+mBluetoothAdapter.isEnabled());
  139.     
  140.     // find out how many devices are paired.  we put the returned data int a java 'set'
  141.     devices = mBluetoothAdapter.getBondedDevices();
  142.     println("--bluetooth found"+ devices.size() +" paired devices:"+ devices);


  143.     //just to proove we can find all the paired devices...
  144.     
  145.     //convert the devices 'set' into an array so that we can perform string functions on it
  146.     Object[] deviceArray = devices.toArray();
  147.     //step through it and assign each device in turn to mBluetoothDevice and then print it's name
  148.     for (int i = 0; i < devices.size(); i++)
  149.     {
  150.       mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(deviceArray[i].toString());
  151.       println("--bluetooth Paried device ["+i+"]: " + mBluetoothDevice.getName());
  152.     }
  153.     
  154.     //but now we use the BT device that we've hardcoded into the sketch becuase I don't have a GUI for choosing one.
  155.     mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(BTserver);
  156.     println("--bluetooth server hardcoded as: "+mBluetoothDevice.getName()+" ["+BTserver+"]");

  157.     //this is a specific UUID that is used for SPP 
  158.     UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  159.     
  160.     //create an RFCOMM BluetoothSocket - a socket through which we can pass serial data
  161.     try 
  162.     {
  163.       mBluetoothSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(SPP_UUID);

  164.     } catch (IOException e) 
  165.     {
  166.         println("createRfcommSocketToServiceRecord failed: "+e);
  167.     }
  168.     //and then try and connect() to remote device.
  169.     try 
  170.     {
  171.       mBluetoothSocket.connect();

  172.     } catch (IOException e) 
  173.     {
  174.         println("connect() failed: "+e);
  175.     }
  176.     
  177.   }
  178. }

  179. void onPause() {
  180.   // Unregister all of our SensorEventListeners upon exit:
  181.   mSensorManager.unregisterListener(accSensorEventListener);
  182.   println("PAUSED! (Sketch Exited...)");
  183.   super.onPause();
  184.   
  185.   // I should close a load of bluetooth stuff here.
  186.   

  187. // Setup our SensorEventListener
  188. class MySensorEventListener implements SensorEventListener {
  189.   void onSensorChanged(SensorEvent event) {
  190.     int eventType = event.sensor.getType();
  191.     if(eventType == Sensor.TYPE_ACCELEROMETER) {
  192.       acc_values = event.values;
  193.     }
  194.    }
  195.   void onAccuracyChanged(Sensor sensor, int accuracy) {
  196.     // do nuthin'...
  197.   }
  198. }
And the Grid class is:


Copy code
  1. class Grid
  2. {
  3.   float    spacing;
  4.   int      gridSize;
  5.   int      gridStroke;
  6.   float    zpos;

  7.   Grid(float c_spacing, int c_gridSize, int c_gridStroke, float c_zpos)
  8.   {
  9.     spacing = c_spacing;
  10.     gridSize = c_gridSize;
  11.     gridStroke = c_gridStroke;
  12.     zpos = c_zpos;
  13.   }

  14.   void display()
  15.   {
  16.     for (int i = 0; i < gridSize; i++)
  17.     {
  18.       stroke(gridStroke-150);
  19.       if (i%5 == 0) stroke(gridStroke-100); 
  20.       if (i == 0) stroke(gridStroke); 
  21.       line(-(gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos, (gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos);
  22.       line((i*spacing)-((gridSize/2)*spacing),-(gridSize*(spacing/2)), zpos, (i*spacing)-((gridSize/2)*spacing),(gridSize*(spacing/2)), zpos);
  23.     }
  24.     stroke(0);
  25.   }

  26.   void displayGL()
  27.   {
  28.     //mergeShapes(true);
  29.     gridlines = beginRecord();
  30.     
  31.     for (int i = 0; i < gridSize; i++)
  32.     {
  33.       stroke(gridStroke-150);
  34.       if (i%5 == 0) stroke(gridStroke-100); 
  35.       if (i == 0) stroke(gridStroke); 
  36.  
  37.       beginShape(LINES); 
  38.         vertex(-(gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos);
  39.         vertex((gridSize*(spacing/2)), (i*spacing)-((gridSize/2)*spacing), zpos); 
  40.       endShape(); 
  41.   
  42.       beginShape(LINES); 
  43.         vertex((i*spacing)-((gridSize/2)*spacing),-(gridSize*(spacing/2)), zpos);
  44.         vertex((i*spacing)-((gridSize/2)*spacing),(gridSize*(spacing/2)), zpos); 
  45.       endShape();
  46.      }
  47.     endRecord();
  48.     stroke(0);
  49.   }

I promise I'll post the code somewhere else and link to it next time!  I hope this helps people, but to be honest, there is nothing more fun than working it out for yourself!

Jim
Im using a Archos 101 running android 2.2 

and it works like a charm with processing - after some fiddling around with the udev-rules it even starts the
sketches with "run on machine"

I wrote a small android-monome clone yesterday to test the use of external libraries and sending
osc-events

http://www.local-guru.net/blog/2011/04/28/android-monome-clone-in-processing