-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
259 lines (220 loc) · 8.75 KB
/
MainActivity.java
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package onbon.bx05.mobiledemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
import java.awt.Color;
import java.awt.Font;
import onbon.bx05.Bx5GScreen;
import onbon.bx05.Bx5GScreenClient;
import onbon.bx05.Bx5GScreenProfile;
import onbon.bx05.area.TextCaptionBxArea;
import onbon.bx05.area.page.TextBxPage;
import onbon.bx05.file.ProgramBxFile;
import onbon.bx05.message.global.ACK;
import onbon.bx05.utils.DisplayStyleFactory;
import onbon.bx05.utils.TextBinary;
public class MainActivity extends AppCompatActivity {
private Bx5GScreenClient screen;
private EditText outputText;
private Button connButton;
private Button disconnButton;
private CheckBox screenBox;
private Button sendButton;
private Button brightnessButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.outputText = (EditText)findViewById(R.id.outputText);
this.connButton = (Button)findViewById(R.id.connButton);
this.connButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// testDeployOKorNot();
new Thread(new Runnable() {
public void run() {
connect();
}
}).start();
}
});
this.disconnButton = (Button)findViewById(R.id.disconnButton);
this.disconnButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
disconnect();
}
}).start();
}
});
this.screenBox = (CheckBox)findViewById(R.id.screenBox);
this.screenBox.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
turnOnOff();
}
}).start();
}
});
this.sendButton = (Button)findViewById(R.id.sendButton);
this.sendButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
writeProgram();
}
}).start();
}
});
this.brightnessButton = (Button)findViewById(R.id.brightnessButton);
this.brightnessButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
changeBrightness();
}
}).start();
}
});
this.screen = new Bx5GScreenClient("MyScreen");
}
private boolean testDeployOKorNot() {
try {
int size = onbon.bx05.db.Factory.getIstance().fineSeriesList().size();
this.outputText.setTextColor(Color.blue._color());
this.outputText.setText("OK. Series Size:" + size);
return true;
}
catch (Exception ex) {
this.outputText.setText("Failed");
this.outputText.setText(ex.getMessage());
return false;
}
}
private void connect() {
final TextView addrText = (TextView)findViewById(R.id.addrText);
final TextView portText = (TextView)findViewById(R.id.portText);
if (screen.connect("" + addrText.getText(), Integer.parseInt("" + portText.getText()))) {
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.connButton.setEnabled(false);
MainActivity.this.disconnButton.setEnabled(true);
MainActivity.this.sendButton.setEnabled(true);
MainActivity.this.screenBox.setEnabled(true);
MainActivity.this.brightnessButton.setEnabled(true);
MainActivity.this.outputText.setText("CONN success: " + MainActivity.this.screen.getControllerType());
}
});
}
else {
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.outputText.setText("CONN failure");
}
});
}
}
private void disconnect() {
this.screen.disconnect();
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.connButton.setEnabled(true);
MainActivity.this.disconnButton.setEnabled(false);
MainActivity.this.sendButton.setEnabled(false);
MainActivity.this.screenBox.setEnabled(false);
MainActivity.this.brightnessButton.setEnabled(false);
}
});
}
private void turnOnOff(){
if(this.screenBox.isChecked()) {
final Bx5GScreen.Result<ACK> r = MainActivity.this.screen.turnOn();
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.outputText.setText("Turn ON: " + r.isOK());
}
});
}
else {
final Bx5GScreen.Result<ACK> r = this.screen.turnOff();
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.outputText.setText("Turn OFF: " + r.isOK());
}
});
}
}
private void changeBrightness() {
EditText brightnessText = (EditText)findViewById(R.id.brightnessText);
final Bx5GScreen.Result<ACK> r = this.screen.manualBrightness(Byte.parseByte("" + brightnessText.getText()));
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.outputText.setText("BRIGHTNESS: " + r.isOK());
}
});
}
private void writeProgram() {
EditText msgText = (EditText)findViewById(R.id.msgText);
EditText fontNameText = (EditText)findViewById(R.id.fontNameText);
EditText fontSizeText = (EditText)findViewById(R.id.fontSizeText);
try {
Bx5GScreenProfile profile = screen.getProfile();
DisplayStyleFactory.DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyleFactory.DisplayStyle[0]);
ProgramBxFile p002 = new ProgramBxFile(2, profile);
p002.setFrameShow(true);
p002.setFrameSpeed(20);
p002.loadFrameImage(3);
TextCaptionBxArea textArea = new TextCaptionBxArea(4, 4, profile.getWidth() - 8, profile.getHeight() - 8, profile);
textArea.setFrameShow(false);
textArea.loadFrameImage(4);
TextBxPage page = new TextBxPage("" + msgText.getText());
// 对文本的处理是否自动换行
page.setLineBreak(true);
// 设置文本水平对齐方式
page.setHorizontalAlignment(TextBinary.Alignment.NEAR);
// 设置文本垂直居中方式
page.setVerticalAlignment(TextBinary.Alignment.CENTER);
// 设置文本字体
page.setFont(new Font(
"" + fontNameText.getText(),
Font.PLAIN,
Integer.parseInt("" + fontSizeText.getText())));
// 设置文本颜色
page.setForeground(Color.red);
// 设置区域背景色,默认为黑色
page.setBackground(Color.darkGray);
// 调整特技方式
page.setDisplayStyle(styles[4]);
// 调整特技速度
page.setSpeed(16);
// 调整停留时间, 单位 10ms
page.setStayTime(0);
textArea.addPage(page);
p002.addArea(textArea);
final boolean ok = screen.writeProgramQuickly(p002);
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.outputText.setText("WRITE P002: " + ok);
}
});
}
catch (final Exception ex) {
runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.outputText.setText("WRITE P002: failed, " + ex.getMessage());
}
});
}
}
}