help with onclickwidget
in
Android Processing
•
2 years ago
this is my first app prototype in processing im doing so im very new...i cant figure out whats missing in my code. when i press the ON button (APToggleButton) in the first screen the second screen shows up when its not suppose to. The second screen is only suppose to been shown when pressing the Settings button(appSettingsButton). I think it has something to do with the Void OnClickWidget but i just cant figure it out. help asap!
import apwidgets.*;
import android.text.InputType;
import android.view.inputmethod.EditorInfo;
APWidgetContainer startMenu;
APButton appSettingsButton;
APToggleButton knappA;
APToggleButton knappB;
APEditText numberField1;
APEditText numberField2;
APWidgetContainer appSettings;
APButton albumButton;
APButton websiteButton;
APToggleButton knappC;
APToggleButton knappD;
PFont font1;
PFont font2;
PFont font3;
PFont font4;
PFont font5;
PFont font6;
PFont font7;
int activeScreen;
void setup(){
startMenu = new APWidgetContainer(this);
knappA = new APToggleButton(66, 120, 80, 65, "ON");
knappB = new APToggleButton(170, 120, 80, 65, "OFF");
startMenu.addWidget(knappA);
startMenu.addWidget(knappB);
knappB.setChecked(true);
numberField1 = new APEditText(86, 260, 60, 50);
numberField2 = new APEditText(167, 260, 60, 50);
startMenu.addWidget(numberField1);
startMenu.addWidget(numberField2);
numberField1.setNextEditText(numberField2);till nästa
numberField1.setInputType(InputType.TYPE_CLASS_NUMBER);
numberField1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
numberField2.setInputType(InputType.TYPE_CLASS_NUMBER);
numberField2.setImeOptions(EditorInfo.IME_ACTION_DONE);
numberField2.setCloseImeOnDone(true);
appSettingsButton = new APButton(108, 340, 100, 55, "SETTINGS");
startMenu.addWidget(appSettingsButton);
r
appSettings = new APWidgetContainer(this);
albumButton = new APButton(185, 230, 80, 50, "ALBUM");
websiteButton = new APButton(58, 360, 175, 50, "www.androidapps.com");
appSettings.addWidget(albumButton);
appSettings.addWidget(websiteButton);
knappC = new APToggleButton(165, 150, 53, 55, "ON");
knappD = new APToggleButton(230, 150, 53, 55, "OFF");
appSettings.addWidget(knappC);
appSettings.addWidget(knappD);
knappD.setChecked(true);
appSettings.hide();
activeScreen = 1;
font1 = loadFont("Arial-BoldMT-48.vlw");
font2 = loadFont("Arial-BoldMT-36.vlw");
font3 = loadFont("Arial-BoldMT-36.vlw");
font4 = loadFont("Arial-BoldMT-36.vlw");
font5 = loadFont("Arial-BoldMT-28.vlw");
font6 = loadFont("Arial-BoldMT-28.vlw");
font7 = loadFont("Arial-BoldMT-28.vlw");
}
void draw(){
if(activeScreen == 1){
background(0);
textFont(font1);
text("NIGHT MODE", 6, 90);
textFont(font2);
text("TIME", 115, 250);
textFont(font3);
text("-", 149, 290);
}else if(activeScreen == 2){
background(0);
textFont(font4);
text("SETTINGS", 68, 80);
textFont(font5);
text("ALARM", 30, 180);
textFont(font6);
text("ALARM", 30, 240);
textFont(font7);
}
}
void onClickWidget(APWidget widget){ //när en widget blivit klickad på
if(widget == knappA){ //om det var knappA som klickades på
knappB.setChecked(false);
}else if(widget == knappB){
knappA.setChecked(false);
}
if(widget == knappC){
knappD.setChecked(false);
}else if(widget == knappD){
knappC.setChecked(false);
}
if(widget == appSettingsButton)
startMenu.hide();
appSettings.show();
activeScreen = 2;
}
void keyPressed(){
if(activeScreen != 1){
if(keyCode == BACK){
appSettings.hide();
startMenu.show();
activeScreen = 1;
keyCode = 0;
}
}
}
void onBackPressed(){
}
import apwidgets.*;
import android.text.InputType;
import android.view.inputmethod.EditorInfo;
APWidgetContainer startMenu;
APButton appSettingsButton;
APToggleButton knappA;
APToggleButton knappB;
APEditText numberField1;
APEditText numberField2;
APWidgetContainer appSettings;
APButton albumButton;
APButton websiteButton;
APToggleButton knappC;
APToggleButton knappD;
PFont font1;
PFont font2;
PFont font3;
PFont font4;
PFont font5;
PFont font6;
PFont font7;
int activeScreen;
void setup(){
startMenu = new APWidgetContainer(this);
knappA = new APToggleButton(66, 120, 80, 65, "ON");
knappB = new APToggleButton(170, 120, 80, 65, "OFF");
startMenu.addWidget(knappA);
startMenu.addWidget(knappB);
knappB.setChecked(true);
numberField1 = new APEditText(86, 260, 60, 50);
numberField2 = new APEditText(167, 260, 60, 50);
startMenu.addWidget(numberField1);
startMenu.addWidget(numberField2);
numberField1.setNextEditText(numberField2);till nästa
numberField1.setInputType(InputType.TYPE_CLASS_NUMBER);
numberField1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
numberField2.setInputType(InputType.TYPE_CLASS_NUMBER);
numberField2.setImeOptions(EditorInfo.IME_ACTION_DONE);
numberField2.setCloseImeOnDone(true);
appSettingsButton = new APButton(108, 340, 100, 55, "SETTINGS");
startMenu.addWidget(appSettingsButton);
r
appSettings = new APWidgetContainer(this);
albumButton = new APButton(185, 230, 80, 50, "ALBUM");
websiteButton = new APButton(58, 360, 175, 50, "www.androidapps.com");
appSettings.addWidget(albumButton);
appSettings.addWidget(websiteButton);
knappC = new APToggleButton(165, 150, 53, 55, "ON");
knappD = new APToggleButton(230, 150, 53, 55, "OFF");
appSettings.addWidget(knappC);
appSettings.addWidget(knappD);
knappD.setChecked(true);
appSettings.hide();
activeScreen = 1;
font1 = loadFont("Arial-BoldMT-48.vlw");
font2 = loadFont("Arial-BoldMT-36.vlw");
font3 = loadFont("Arial-BoldMT-36.vlw");
font4 = loadFont("Arial-BoldMT-36.vlw");
font5 = loadFont("Arial-BoldMT-28.vlw");
font6 = loadFont("Arial-BoldMT-28.vlw");
font7 = loadFont("Arial-BoldMT-28.vlw");
}
void draw(){
if(activeScreen == 1){
background(0);
textFont(font1);
text("NIGHT MODE", 6, 90);
textFont(font2);
text("TIME", 115, 250);
textFont(font3);
text("-", 149, 290);
}else if(activeScreen == 2){
background(0);
textFont(font4);
text("SETTINGS", 68, 80);
textFont(font5);
text("ALARM", 30, 180);
textFont(font6);
text("ALARM", 30, 240);
textFont(font7);
}
}
void onClickWidget(APWidget widget){ //när en widget blivit klickad på
if(widget == knappA){ //om det var knappA som klickades på
knappB.setChecked(false);
}else if(widget == knappB){
knappA.setChecked(false);
}
if(widget == knappC){
knappD.setChecked(false);
}else if(widget == knappD){
knappC.setChecked(false);
}
if(widget == appSettingsButton)
startMenu.hide();
appSettings.show();
activeScreen = 2;
}
void keyPressed(){
if(activeScreen != 1){
if(keyCode == BACK){
appSettings.hide();
startMenu.show();
activeScreen = 1;
keyCode = 0;
}
}
}
void onBackPressed(){
}
1