The example ran just fine.
My code is
import android.app.Activity;
int textSize = 20;
int textSize2 = 20;
int textSize3 = 20;
int textSize4 = 20;
int textSize5 = 20;
int page = 1;
float speed = 0.1;
float x = -20;
boolean sucessful = false;
int numPings = 0;
boolean timedOut = false;
class sizeNText {
String text;
int size;
sizeNText(String text, int size) {
this.text = text;
this.size = size;
}
}
class ipBox {
int contents;
int x;
int y;
boolean open = false;
ipBox(int x, int y) {
this.x = x;
this.y = y;
this.contents = 1000;
}
void handlePress(int x, int y) {
textSize(height/16);
if (this.x < x && this.y < y) {
if (x < this.x+textWidth("100") && y < this.y+height/16) {
openKeyboard();
open = true;
} else {
closeKeyboard();
open = false;
}
} else {
closeKeyboard();
open = false;
}
}
void handleKey() {
if (open) {
println("Key is num "+str(int(key)));
if (key == '0' || key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9') {
if (contents < 26) {
if (contents == 25) {
if (int(str(key)) < 6) {
contents = int(str(contents)+key);
}
} else {
contents = int(str(contents)+key);
}
} else if (contents == 1000) {
contents = int(""+key);
}
} else if (key == char(65535)) {
if (str(contents).length() == 1 || contents == 1000) {
contents = 1000;
} else {
contents = int(str(contents).substring(0, str(contents).length()-1));
}
}
}
}
void render() {
stroke(0);
fill(255);
textSize(height/16);
if (open) {
strokeWeight(10);
} else {
strokeWeight(5);
}
rect(this.x, this.y, textWidth("100"), height/16);
fill(0);
if (contents != 1000) {
text(str(contents), this.x, this.y+height/16);
}
}
}
class changingText {
String Text = "";
int x = 0;
int y = 0;
int textSize = 0;
changingText() {
}
void setText(int textSize, int x, int y, String text) {
this.textSize = textSize;
this.x = x;
this.y = y;
this.Text = text;
}
void render() {
//println("Render was called");
textSize(this.textSize);
fill(255, 255, 255);
println("Height is "+height);
print("Rendering the text \""+this.Text+"\" at the text size of "+this.textSize+" at the x pos of"+this.x+" and a y pos of "+this.y);
text(this.Text, this.x, this.y);
}
}
ipBox text = new ipBox(0, 0);
ipBox text2 = new ipBox(0, 0);
changingText pings = new changingText();
void setup() {
fullScreen();
for (int i = 1; i < 1000; i++) {
textSize(i);
if (textWidth("SecurePythonPi") > width) {
i = i / 2;
textSize = i;
break;
}
}
for (int i = 1; i < 1000; i++) {
textSize(i);
if (textWidth("Search") > width) {
i = i / 2;
textSize2 = i;
break;
}
}
for (int i = 1; i < 1000; i++) {
textSize(i);
if (textWidth("Searching...") > width) {
i = i / 2;
textSize3 = i;
break;
}
}
for (int i = 1; i < 1000; i++) {
textSize(i);
if (textWidth("Found the device!") > width) {
i = i / 2;
textSize4 = i;
break;
}
}
for (int i = 1; i < 1000; i++) {
textSize(i);
if (textWidth("No devices found on that port, sorry. :~(") > width) {
i = i - 2;
textSize5 = i;
break;
}
}
speed = width/300;
textSize(height/16);
text = new ipBox(int((width/4)-(textWidth("100")/2)), height/2);
text2 = new ipBox(int((width/4*3)-(textWidth("100")/2)), height/2);
}
void draw() {
strokeWeight(5);
if (page == 1) {
stroke(0);
background(100);
textSize(textSize);
fill(255);
text("SecurePythonPi", (width/2)-textWidth("SecurePythonPi")/2, textSize);
textSize(textSize2);
fill(100);
strokeWeight(5);
rect(width/2-(textWidth("Search")/2), ((textSize2)*0.5)+textSize, textWidth("Search"), textSize2);
fill(255);
text("Search", (width/2)-textWidth("Search")/2, ((textSize2)*1.375)+textSize);
} else if (page == 2) {
background(100);
stroke(0);
line(0, height/10, width, height/10);
line(width/2-(((height/10)-(height/32))/2), height/64, width/2+(((height/10)-(height/32))/2), height/10-height/64);
line(width/2+(((height/10)-(height/32))/2), height/64, width/2-(((height/10)-(height/32))/2), height/10-height/64);
textSize(textSize3);
fill(255);
text("Searching...", (width/2)-textWidth("Searching...")/2, textSize3+height/10);
noStroke();
ellipse(x, textSize3+height/8, 20, 20);
x += speed;
if (x > width+20 || x < -20) {
speed *= -1;
}
if (sucessful) {
background(100);
stroke(0);
line(0, height/10, width, height/10);
line(width/2-(((height/10)-(height/32))/2), height/64, width/2+(((height/10)-(height/32))/2), height/10-height/64);
line(width/2+(((height/10)-(height/32))/2), height/64, width/2-(((height/10)-(height/32))/2), height/10-height/64);
textSize(textSize4);
fill(255);
text("Found the device!", (width/2)-textWidth("Found the device!")/2, textSize4+height/10);
} else if (timedOut) {
background(100);
stroke(0);
line(0, height/10, width, height/10);
line(width/2-(((height/10)-(height/32))/2), height/64, width/2+(((height/10)-(height/32))/2), height/10-height/64);
line(width/2+(((height/10)-(height/32))/2), height/64, width/2-(((height/10)-(height/32))/2), height/10-height/64);
textSize(textSize5);
fill(255);
text("No devices found on that port, sorry. :~(", (width/2)-textWidth("No devices found on that port, sorry. :~(")/2, textSize5+height/10);
} else {
sizeNText theData = formatPings();
println("The text is "+theData.text);
textSize(theData.size);
pings.setText(theData.size, int((width/2)-(textWidth(theData.text)/2)), height-theData.size, theData.text);
text.render();
text2.render();
pings.render();
}
}
}
void checkIP() {
String[] answer = null;
int startTime = millis();
while (answer == null && millis()-startTime<30000 && numPings <= 5) {
answer = loadStrings("https://192.168."+text.contents+"."+text2.contents+"/");
if (answer != null) {
sucessful = true;
println("Sucess!");
} else {
println("No sucess.");
numPings += 1;
int lastMillis = millis();
while (millis() - 2000 < lastMillis) {
int abc = 5;
}
}
}
timedOut = answer == null;
}
sizeNText formatPings() {
String returnVal;
boolean isOne = numPings == 1;
int theTextWidth = 20;
if (isOne) {
returnVal = "1 ping";
} else {
returnVal = str(numPings)+" pings";
}
for (int i = 1; i < 1000; i++) {
textSize(i);
if (textWidth(returnVal) > width) {
i = i / 2;
theTextWidth = i;
break;
}
}
return new sizeNText(returnVal, theTextWidth);
}
void mousePressed() {
if (page == 1) {
textSize(textSize2);
if (mouseX > width/2-(textWidth("Search")/2) && mouseX < width/2+(textWidth("Search")/2)) {
if (mouseY > ((textSize2)*0.5)+textSize && mouseY < ((textSize2)*1.5)+textSize) {
page = 2;
sucessful = false;
numPings = 0;
timedOut = false;
thread("checkIP");
println("Tap ocurred");
}
}
} else if (page == 2) {
text.handlePress(mouseX, mouseY);
text2.handlePress(mouseX, mouseY);
if (mouseY < height/10) {
page = 1;
x = -20;
}
}
}
void keyPressed() {
text.handleKey();
text2.handleKey();
}
public void onSaveInstanceState(Bundle savedInstanceState){
savedInstanceState.putInt("TheInt", page);
//the variable 'page' is a number that represents which page the app is in
super.onSaveInstanceState(savedInstanceState);
}```