Make a second page on android app
in
Android Processing
•
1 year ago
I have an android app made many thanks to calsign and
his great assistance.
My app is to control my television. What i want now is to be able to swipe my finger to the side and have the page slide over and show me another set of buttons. I don't think i will have an issue making the second page itself... my questions is more so about the process of create the actual transition and base of the second page.
my current program:
- ArrayList buttons; // define ArrayList that will hold instance of ImageButton Class
- import hypermedia.net.*; // UDP Library Name
- UDP udp; // define the UDP object
- String ip = "192.168.5.200"; // the remote IP address
- int port = 8888; // the destination port
- String message;
- int RVal = 0;
- int GVal = 0;
- long timer;
- int difference;
- void setup() {
- size(800, 1280); //resolution of Galaxy Note
- background(0, 0, 0); //Black Background
- orientation(PORTRAIT); //Haven't set up the icons for screen rotating so fix it to portrait
- udp = new UDP ( this, 6000 ); // initialize UDP Object
- // udp.listen( true );
- buttons = new ArrayList(); //create empty buttons ArrayList
- //Creates a new ImageButton
- buttons.add(new ImageButton(this, "ae.jpg", "ae", 113, 342, "DCCH039 "));
- buttons.add(new ImageButton(this, "discovery.jpg", "discovery", 576, 521, "DCCH046 "));
- buttons.add(new ImageButton(this, "nick.jpg", "nick", 30, 548, "DCCH030 "));
- buttons.add(new ImageButton(this, "cartoonnetwork.jpg", "cartoonnetwork", 64, 681, "DCCH033 "));
- buttons.add(new ImageButton(this, "disney.jpg", "disney", 571, 696, "DCCH024 "));
- buttons.add(new ImageButton(this, "history.jpg", "history", 339, 364, "DCCH047 "));
- buttons.add(new ImageButton(this, "pbs.jpg", "pbs", 311, 533, "DCCH012 "));
- buttons.add(new ImageButton(this, "spike.jpg", "spike", 581, 215, "DCCH041 "));
- buttons.add(new ImageButton(this, "usa.jpg", "usa", 330, 224, "DCCH027 "));
- buttons.add(new ImageButton(this, "tnt.jpg", "tnt", 535, 372, "DCCH028 "));
- buttons.add(new ImageButton(this, "trutv.jpg", "trutv", 52, 222, "DCCH051 "));
- buttons.add(new ImageButton(this, "xbox.jpg", "xbox", 332, 21, "IAVD1 "));
- buttons.add(new ImageButton(this, "poweron.jpg", "poweron", 595, 16, "POWR1 "));
- buttons.add(new ImageButton(this, "poweroff.jpg", "poweroff", 81, 15, "POWR0 "));
- buttons.add(new ImageButton(this, "downarrow.jpg", "downarrow", 308, 1116, "CHDW1 "));
- buttons.add(new ImageButton(this, "uparrow.jpg", "uparrow", 308, 787, "CHUP1 "));
- buttons.add(new ImageButton(this, "leftarrow.jpg", "leftarrow", 180, 917, "RCKY32 "));
- buttons.add(new ImageButton(this, "rightarrow.jpg", "rightarrow", 509, 918, "RCKY33 "));
- buttons.add(new ImageButton(this, "mutebutton.jpg", "mutebutton", 370, 971, "MUTE0 "));
- }
- void draw() {
- for (int i = buttons.size()-1; i >=0 ; i--) { //Calls each image button to draw
- ImageButton button = (ImageButton) buttons.get(i); // Use casting to pull name out of class and call
- button.draw(); //the actual draw
- }
- udp.listen(true); //udp.listen calls the receive() function
- ClearStatus(); // clears the green indicator dot out after 100ms
- fill(RVal, GVal, 0); //lcolor of indicator dot, it's black and turns green when tv accepts command
- ellipse(10, 1270, 20, 20); //location and size of inidicator dot
- }
- void receive( byte[] data ) { //handle received UDP packet
- message = new String( data ); //turn data into a string using String class
- // print the result to console
- println( "receive: \""+message+"\" from "+ip+" on port "+port );
- if (message.equals("O")) { //if UDP return is O turn dot green
- GVal = 255;
- timer = millis();
- }
- if (message.equals("E")) { //if UDP dot is E turn dot red
- RVal = 255;
- timer = millis();
- }
- }
- void ClearStatus() {
- if (millis()-timer>100) { // if the dot had been red or green for 100ms or more turn it black again
- GVal = 0;
- RVal = 0;
- }
- }
- class ImageButton {
- PApplet parent; //The parent PApplet
- PImage image; //The image source
- PVector loc; //The location and dimensions
- PVector dim;
- String id; //The identifier of this ImageButton
- String command; //The command to send to the Television
- boolean pressed; //Whether or not the ImageButton is pressed
- /*
- Creates an new ImageButton
- PApplet parent - use "this"
- String path - the path to the image file
- String id - the identifier of this image, used for firing press events
- float x - the x position of the ImageButton
- float y - the y position of the ImageButton
- */
- ImageButton(PApplet parent, String path, String id, float x, float y, String command) {
- this.id = id; //initializing vairables for use in other functions,
- this.command = command; //ID is unused but left for possible future needs when expanding code
- this.parent = parent;
- image = loadImage(path); //load image from data folder
- loc = new PVector(x, y);
- dim = new PVector(image.width, image.height);
- }
- void draw() {
- update();
- display();
- }
- void update() {
- if (mousePressed && mouseOver()) { //If pressed and over object
- if (!pressed) { //and the button wasnt already pressed (each time you press the button the command is sent once)
- udp.send(command, ip, port); //send udp packet of serial command to TV
- pressed = true;
- }
- }
- else pressed = false;
- }
- void display() {
- pushStyle();
- if (pressed) tint(50); //Tint the image if it is pressed
- image(image, loc.x, loc.y); //Display the image
- popStyle();
- }
- boolean mouseOver() { //This is the magic mouse detection part
- return alpha(image.get((int) (mouseX - loc.x), (int) (mouseY - loc.y))) > 0;
- }
- }
1