Java to Android !

edited June 2015 in Android Mode

**any body explain to me how can i change my java code to android i need to execute it on my mobile phone please i need help here **

import controlP5.*;

import saito.objloader.*; //<>//
import codeanticode.gsvideo.*;
import java.util.Calendar;     
import ddf.minim.*;

Minim minim;
AudioPlayer song;
OBJModel model;
GSCapture cam;
Button  b_Lancer;
float thetaX = 0.0;
float thetaY = 0.0;  
int offset=1 ;
int offst=1 ;
float scaler = 1;

String timestamp() {
  Calendar now = Calendar.getInstance();
  return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}

void setup() { 
  size(640, 480, P3D);
   
  smooth();
  noStroke();
  model = new OBJModel(this, "");
  cam = new GSCapture(this, 640, 480); // initialize the webcam capture at a specific resolution (correct and/or possible settings depend on YOUR webcam)
  cam.start(); // start capturing
}
void caricasuono() {
  minim = new Minim(this);
  song = minim.loadFile("THE SOUND OF SILENCE.mp3");
}

void keyPressed() {
  if (keyPressed) {
    if (key == 'a' ) { 
      model = new OBJModel(this, "tabletabletable.obj"); 
      model.scale(65);
      model.translateToCenter();

    }
    if (key == 'z' ) { 
      model = new OBJModel(this, "coujinahh.obj"); 
      model.scale(40);
      model.translateToCenter();
      noStroke();
    }
  }

     if (key == 's' ) { 
      model = new OBJModel(this, "tabletabletable1.obj"); 
      model.scale(40);
      model.translateToCenter();
      noStroke();
    }
    
     if (key == 'd' ) { 
      model = new OBJModel(this, "tabletabletable3.obj"); 
      model.scale(40);
      model.translateToCenter();
      noStroke();
    }
     
     if (key == 'x' ) { 
      model = new OBJModel(this, "canape.obj"); 
      model.scale(60);
      model.translateToCenter();
      noStroke();
    }




  if (key == 'q' ) { 
    // caricasuono();
    // song.play();
    model = new OBJModel(this, "bedbedbed5.obj"); 
    model.scale(60);
    model.translateToCenter(); 
    noStroke();
  } 
  if (key == 'w' ) { 
    model = new OBJModel(this, "bedbedbed2.obj"); 
    model.scale(60);
    model.translateToCenter(); 
    noStroke();
  } 
  if (key == 'e' ) { 
    model = new OBJModel(this, "bedbedbed6.obj"); 
    model.scale(60);
    model.translateToCenter(); 
    noStroke();
  } 
  if (keyCode==LEFT) offset--;
  if (keyCode==RIGHT) offset++;
  if ( keyCode==UP) {
    scaler -= 0.1; } // smaller
  if (keyCode==DOWN) {
    scaler += 0.1; } // bigger
  if (keyCode == ENTER) {    
    saveFrame("dot_images/"+timestamp()+".png");
  }
  // if (offset > 280){offset=285;}
  // if (offst < -280){offset=-285;}
  
}   

void draw() {
  if (cam.available()) {
    cam.read(); // read the cam image  
    rect(0,0,width, 30);
    background(cam); 
    translate(width/2 + offset, height/2);
    translate(0, 0, height/2); // use translate around scale
    scale(scaler);
    translate(0, 0, -height/2); // to scale from the center   
    rotateX(thetaX);
    rotateY(thetaY);    
    pointLight(190, 190, 190, width/2, height/2, -200);
    pointLight(170, 170, 170, -(width/2), -(height/2), 200);
    model.draw();
    
    if (mousePressed) {
      thetaY -= radians(pmouseX-mouseX);
      thetaX += radians(pmouseY-mouseY);
    }
    
    //Perpective 
    if (mousePressed) {
      float fov = PI/3.0; 
      float cameraZ = (height/1.0) / tan(fov/1.0); 
      perspective(fov, float(width)/float(height), cameraZ/5.0, cameraZ*5.0);
    } else {
      ortho(0, width, 0, height);
    }
  }
}

Answers

  • edited June 2015

    The easiest way is to use Android Mode for processing. It has some limitations however. You need to check if all of the libraries you use are Android compatible. Setting android mode to work is tricky as well, but there is a lot of information on this forum on how to do it.

    Besides, you'll need to change your code, because you can't use keyPressed in android.

  • @hafedh:: except Calendar non of your libs an be used for android then you cannot "translate" for android if you want to work with processing you install android mode and learn to work with it, which is not so easy...

  • but on eclipse there is a way and i can deploy my java projet into mobile ! is there the same think on processing ?

  • but on eclipse there is a way and i can deploy my java projet into mobile

    Not if you are using libraries incompatible with Android. The same is true in Processing.

    In Processing you have to develop the application in Android mode.

  • can you explain to me how can i change my code here on anroid (changing the librairie i used here )

  • @hafedh====

    as for libs:: sound & video (processing) == APWidgets library android genuine: videoView && MediaPlayer GUI: you have to code , there are a lot of solutions for that in android world... 3D: OPENGL ES but the problem is not only with libs!

Sign In or Register to comment.