-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button
83 lines (76 loc) · 2.04 KB
/
Button
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import android.app.Activity;
import android.widget.FrameLayout;
import android.widget.Button;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.View.OnClickListener;
import android.view.Gravity;
import android.R;
import processing.android.CompatUtils;
Activity act;
FrameLayout fl;
Button btn1;
int btn1Id, tel;
boolean toggle;
void setup() {
fullScreen();
orientation(PORTRAIT);
background(255);
fill(0);
textAlign(CENTER);
textSize(35);
text("Click on screen to show button.", width/2, height/2);
}
void draw() {
}
@ Override
public void onStart() {
super.onStart();
act = this.getActivity();
btn1 = new Button(act);
btn1.setTextSize(30);
btn1.setText("Click");
//btn1.setHeight(55);
btn1.setWidth(280);
btn1.setX(width/2-140);
btn1.setY(200);
btn1.setTextColor(Color.WHITE);
btn1.setBackgroundColor(Color.rgb(0, 150, 150));
btn1Id = CompatUtils.getUniqueViewId();
//btn1Id = View.generateViewId();
btn1.setId(btn1Id);
btn1.setVisibility(View.GONE);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
background(255);
text("Click on button to count.", width/2, height/3);
tel++;
text("You clicked "+str(tel)+" times", width/2, height/3+100);
text("Click on screen to hide button.", width/2, height/3+200);
}
}
);
fl = (FrameLayout)act.findViewById(R.id.content);
fl.addView(btn1, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.LEFT));
}
void mousePressed() {
act.runOnUiThread(
new Runnable() {
public void run() {
Button bt = (Button)act.findViewById(btn1Id);
if (toggle) {
background(255);
text("Click on button to count.", width/2, height/3);
bt.setVisibility(View.VISIBLE);
} else {
background(255);
text("Click on screen to show button.", width/2, height/2);
bt.setVisibility(View.GONE);
tel = 0;
}
}
}
);
toggle =! toggle;
}