-
Notifications
You must be signed in to change notification settings - Fork 3
/
PluginActivity.java
584 lines (520 loc) · 17.7 KB
/
PluginActivity.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/**
* Copyright 2018 Ricoh Company, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.theta360.pluginlibrary.activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.theta360.pluginlibrary.callback.KeyCallback;
import com.theta360.pluginlibrary.values.ExitStatus;
import com.theta360.pluginlibrary.values.LedColor;
import com.theta360.pluginlibrary.values.LedTarget;
import com.theta360.pluginlibrary.values.OledDisplay;
import com.theta360.pluginlibrary.UncaughtException;
import com.theta360.pluginlibrary.receiver.KeyReceiver;
import com.theta360.pluginlibrary.values.TextArea;
import com.theta360.pluginlibrary.values.ThetaModel;
import java.util.Map;
/**
* PluginActivity
*/
public abstract class PluginActivity extends AppCompatActivity {
private boolean isCamera = false;
private boolean isAutoClose = true;
private boolean isClosed = false;
private String mUserOption;
private boolean isApConnected = false;
private KeyCallback mKeyCallback;
private KeyReceiver mKeyReceiver;
private KeyReceiver.Callback onKeyReceiver = new KeyReceiver.Callback() {
@Override
public void onKeyDownCallback(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyReceiver.KEYCODE_MEDIA_RECORD
&& event.isLongPress()) {
if (mKeyCallback != null) {
mKeyCallback.onKeyLongPress(keyCode, event);
}
if (isAutoClose) {
close();
}
} else {
if (mKeyCallback != null) {
if (event.getRepeatCount() == 0) {
mKeyCallback.onKeyDown(keyCode, event);
} else if (event.isLongPress()) {
mKeyCallback.onKeyLongPress(keyCode, event);
}
}
}
}
@Override
public void onKeyUpCallback(int keyCode, KeyEvent event) {
if (mKeyCallback != null) {
mKeyCallback.onKeyUp(keyCode, event);
}
}
};
// For THETA X
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
switch(event.getAction()) {
case KeyEvent.ACTION_DOWN:
if (event.getKeyCode() == KeyReceiver.KEYCODE_MEDIA_RECORD
&& event.isLongPress()) {
if (mKeyCallback != null) {
mKeyCallback.onKeyLongPress(keyCode, event);
}
if (isAutoClose) {
close();
}
} else {
if (mKeyCallback != null) {
if (event.getRepeatCount() == 0) {
mKeyCallback.onKeyDown(keyCode, event);
} else if (event.isLongPress()) {
mKeyCallback.onKeyLongPress(keyCode, event);
}
}
}
break;
case KeyEvent.ACTION_UP:
if (mKeyCallback != null) {
mKeyCallback.onKeyUp(keyCode, event);
}
break;
}
return super.dispatchKeyEvent(event);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Fix to be portrait
UncaughtException uncaughtException = new UncaughtException(getApplicationContext(),
new UncaughtException.Callback() {
@Override
public void onException(String message) {
notificationError(message);
}
});
Thread.setDefaultUncaughtExceptionHandler(uncaughtException);
}
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null) {
mUserOption = intent.getStringExtra(Constants.USER_OPTION);
isApConnected = intent.getBooleanExtra(Constants.IS_AP_CONNECTED, false);
}
mKeyReceiver = new KeyReceiver(onKeyReceiver);
IntentFilter keyFilter = new IntentFilter();
keyFilter.addAction(KeyReceiver.ACTION_KEY_DOWN);
keyFilter.addAction(KeyReceiver.ACTION_KEY_UP);
registerReceiver(mKeyReceiver, keyFilter);
}
@Override
protected void onPause() {
if (!isClosed && isAutoClose) {
close();
}
unregisterReceiver(mKeyReceiver);
super.onPause();
}
public void setKeyCallback(KeyCallback keyCallback) {
mKeyCallback = keyCallback;
}
/**
* Auto close setting
*
* @param autoClose true : auto close / false : not auto close
*/
public void setAutoClose(boolean autoClose) {
isAutoClose = autoClose;
}
/**
* End processing
*/
public void close() {
isClosed = true;
if (isCamera) {
notificationCameraOpen();
}
notificationSuccess();
}
public String getUserOption() {
return mUserOption;
}
public boolean isApConnected() {
return isApConnected;
}
public void notificationCameraOpen() {
isCamera = false;
sendBroadcast(new Intent(Constants.ACTION_MAIN_CAMERA_OPEN));
}
public void notificationCameraClose() {
isCamera = true;
sendBroadcast(new Intent(Constants.ACTION_MAIN_CAMERA_CLOSE));
}
/**
* Sound of normal capture
*/
public void notificationAudioShutter() {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_SHUTTER));
}
/**
* Sound of starting long exposure capture
*/
public void notificationAudioOpen() {
if (ThetaModel.isVCameraModel()) {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_SH_OPEN));
} else {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_SHUTTER_OPEN));
}
}
/**
* Sound of ending long exposure capture
*/
public void notificationAudioClose() {
if (ThetaModel.isVCameraModel()) {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_SH_CLOSE));
} else {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_SHUTTER_CLOSE));
}
}
/**
* Sound of starting movie recording
*/
public void notificationAudioMovStart() {
if (ThetaModel.isVCameraModel()) {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_MOVSTART));
} else {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_MOVIE_START));
}
}
/**
* Sound of stopping movie recording
*/
public void notificationAudioMovStop() {
if (ThetaModel.isVCameraModel()) {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_MOVSTOP));
} else {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_MOVIE_STOP));
}
}
/**
* Sound of working self-timer
*/
public void notificationAudioSelf() {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_SELF));
}
/**
* Sound of warning
*/
public void notificationAudioWarning() {
sendBroadcast(new Intent(Constants.ACTION_AUDIO_WARNING));
}
/**
* Brightness of display
*
* @param brightness brightness 0-100(percent)
*/
public void notificationScreenBrightnessSet(@NonNull int brightness) {
if (brightness < 0) {
brightness = 0;
}
if (brightness > 100) {
brightness = 100;
}
Intent intent = new Intent(Constants.ACTION_SCREEN_BRIGHTNESS_SET);
if (ThetaModel.isXModel() && (
ThetaInfo.getThetaFirmwareVersion().equals("1.00.2") ||
ThetaInfo.getThetaFirmwareVersion().equals("1.10.1"))
){
intent.putExtra(Constants.BRIGHTNESS, Integer.valueOf(brightness).toString());
}
else {
intent.putExtra(Constants.BRIGHTNESS, brightness);
}
sendBroadcast(intent);
}
/**
* Turn on LED3 with color
*
* @param ledColor target LED
*/
public void notificationLed3Show(@NonNull LedColor ledColor) {
Intent intent = new Intent(Constants.ACTION_LED_SHOW);
intent.putExtra(Constants.TARGET, LedTarget.LED3.toString());
intent.putExtra(Constants.COLOR, ledColor.toString());
sendBroadcast(intent);
}
/**
* Turn on LED
*
* @param ledTarget target LED
*/
public void notificationLedShow(@NonNull LedTarget ledTarget) {
if (ledTarget == LedTarget.LED3) {
notificationLed3Show(LedColor.BLUE);
} else {
Intent intent = new Intent(Constants.ACTION_LED_SHOW);
intent.putExtra(Constants.TARGET, ledTarget.toString());
sendBroadcast(intent);
}
}
/**
* Blink LED
*
* @param ledTarget target LED
* @param ledColor color
* @param period period 250-2000 (msec)
*/
public void notificationLedBlink(@NonNull LedTarget ledTarget, LedColor ledColor, int period) {
if (ledColor == null) {
ledColor = LedColor.BLUE;
}
if (period < 250) {
period = 250;
}
if (period > 2000) {
period = 2000;
}
Intent intent = new Intent(Constants.ACTION_LED_BLINK);
intent.putExtra(Constants.TARGET, ledTarget.toString());
intent.putExtra(Constants.COLOR, ledColor.toString());
intent.putExtra(Constants.PERIOD, period);
sendBroadcast(intent);
}
/**
* Turn off LED
*
* @param ledTarget target LED
*/
public void notificationLedHide(@NonNull LedTarget ledTarget) {
Intent intent = new Intent(Constants.ACTION_LED_HIDE);
intent.putExtra(Constants.TARGET, ledTarget.toString());
sendBroadcast(intent);
}
/**
* Set LED or OLED brightness
*
* @param ledTarget target LED or OLED
* @param brightness brightness 0-100 (percent)
*/
public void notificationLedBrightnessSet(@NonNull LedTarget ledTarget, int brightness) {
if (brightness < 0) {
brightness = 0;
}
if (brightness > 100) {
brightness = 100;
}
Intent intent = new Intent(Constants.ACTION_LED_BRIGHTNESS_SET);
intent.putExtra(Constants.TARGET, ledTarget.toString());
if (ThetaModel.isXModel() && (
ThetaInfo.getThetaFirmwareVersion().equals("1.00.2") ||
ThetaInfo.getThetaFirmwareVersion().equals("1.10.1"))
){
intent.putExtra(Constants.BRIGHTNESS, Integer.valueOf(brightness).toString());
}
else {
intent.putExtra(Constants.BRIGHTNESS, brightness);
}
sendBroadcast(intent);
}
/**
* Display bitmap on OLED
*
* @param bitmap Bitmap displayed on OLED (Bitmap size is height 24 or 36 and width 128)
*/
public void notificationOledImageShow(@NonNull Bitmap bitmap) {
if ((bitmap.getHeight() == 24 || bitmap.getHeight() == 36)
&& bitmap.getWidth() == 128) {
Intent intent = new Intent(Constants.ACTION_OLED_IMAGE_SHOW);
intent.putExtra(Constants.BITMAP, bitmap);
sendBroadcast(intent);
}
}
/**
* Blink bitmap on OLED
*
* @param bitmap Bitmap displayed on OLED (Bitmap size is height 24 or 36 and width 128)
* @param period period 250-2000 (msec)
*/
public void notificationOledImageBlink(@NonNull Bitmap bitmap, int period) {
if ((bitmap.getHeight() == 24 || bitmap.getHeight() == 36)
&& bitmap.getWidth() == 128) {
if (period < 250) {
period = 250;
}
if (period > 2000) {
period = 2000;
}
Intent intent = new Intent(Constants.ACTION_OLED_IMAGE_BLINK);
intent.putExtra(Constants.BITMAP, bitmap);
intent.putExtra(Constants.PERIOD, period);
sendBroadcast(intent);
}
}
/**
* Displays a string in the specified area
*
* @param textMap Specify TextArea for Key and string to be displayed for Value
*/
public void notificationOledTextShow(@NonNull Map<TextArea, String> textMap) {
Intent intent = new Intent(Constants.ACTION_OLED_TEXT_SHOW);
for (Map.Entry<TextArea, String> map : textMap.entrySet()) {
intent.putExtra(map.getKey().toString(), map.getValue());
}
sendBroadcast(intent);
}
/**
* Turn off OLED
*/
public void notificationOledHide() {
sendBroadcast(new Intent(Constants.ACTION_OLED_HIDE));
}
/**
* Setting the OLED display during plug-in mode
*
* @param oledDisplay Plug-in display or basic display
*/
public void notificationOledDisplaySet(@NonNull OledDisplay oledDisplay) {
Intent intent = new Intent(Constants.ACTION_OLED_DISPLAY_SET);
intent.putExtra(Constants.DISPLAY, oledDisplay.toString());
sendBroadcast(intent);
}
public void notificationWlanOff() {
sendBroadcast(new Intent(Constants.ACTION_WLAN_OFF));
}
public void notificationWlanAp() {
sendBroadcast(new Intent(Constants.ACTION_WLAN_AP));
}
public void notificationWlanCl() {
sendBroadcast(new Intent(Constants.ACTION_WLAN_CL));
}
/**
* Turn off/on Bluetooth
*/
public void notificationBluetoothOff() {
sendBroadcast(new Intent(Constants.ACTION_BLUETOOTH_OFF));
}
public void notificationBluetoothOn() {
sendBroadcast(new Intent(Constants.ACTION_BLUETOOTH_ON));
}
/**
* Turn off/on GNSS
*/
public void notificationGpsOff() {
sendBroadcast(new Intent(Constants.ACTION_GPS_OFF));
}
public void notificationGpsOn() {
sendBroadcast(new Intent(Constants.ACTION_GPS_ON));
}
/**
* Updating the Database in X Models
*/
public void notificationDatabaseUpdate(@NonNull String target) {
Intent intent = new Intent(Constants.ACTION_DATABASE_UPDATE);
intent.putExtra(Constants.TARGET, target);
sendBroadcast(intent);
}
/**
* Updating the Database in V/Z1 Models
*/
public void notificationDatabaseUpdate(@NonNull String[] targets) {
Intent intent = new Intent(Constants.ACTION_DATABASE_UPDATE);
intent.putExtra(Constants.TARGETS, targets);
sendBroadcast(intent);
}
/**
* Start camera attitude control sensor
*/
public void notificationSensorStart() {
sendBroadcast(new Intent(Constants.ACTION_MOTION_SENSOR_START));
}
/**
* Stop the camera attitude control sensor
*/
public void notificationSensorStop() {
sendBroadcast(new Intent(Constants.ACTION_MOTION_SENSOR_STOP));
}
/**
* Suspend battery charging
*/
public void notificationBatteryChargingSuspend() {
sendBroadcast(new Intent(Constants.ACTION_BATTERY_CHARGING_SUSPEND));
}
/**
* Resume battery charging
*/
public void notificationBatteryChargingResume() {
sendBroadcast(new Intent(Constants.ACTION_BATTERY_CHARGING_RESUME));
}
/**
* Power Off
*/
public void notificationPowerOff() {
sendBroadcast(new Intent(Constants.ACTION_POWER_OFF));
}
/**
* Start of camera control by WebApi
*/
public void notificationWebApiCameraOpen() {
sendBroadcast(new Intent(Constants.ACTION_PLUGIN_WEBAPI_CAMERA_OPEN));
try { Thread.sleep(500); }
catch (InterruptedException e) { e.printStackTrace(); }
}
/**
* Stop of camera control by WebApi
*/
public void notificationWebApiCameraClose() {
sendBroadcast(new Intent(Constants.ACTION_PLUGIN_WEBAPI_CAMERA_CLOSE));
}
/**
* Notifying Completion of Plug-in when the plug-in ends normally
*/
public void notificationSuccess() {
Intent intent = new Intent(Constants.ACTION_FINISH_PLUGIN);
intent.putExtra(Constants.PACKAGE_NAME, getPackageName());
intent.putExtra(Constants.EXIT_STATUS, ExitStatus.SUCCESS.toString());
sendBroadcast(intent);
finishAndRemoveTask();
}
/**
* Notifying Completion of Plug-in when the plug-in ends with error
*
* @param message error message
*/
public void notificationError(String message) {
Intent intent = new Intent(Constants.ACTION_FINISH_PLUGIN);
intent.putExtra(Constants.PACKAGE_NAME, getPackageName());
intent.putExtra(Constants.EXIT_STATUS, ExitStatus.FAILURE.toString());
intent.putExtra(Constants.MESSAGE, message);
sendBroadcast(intent);
finishAndRemoveTask();
}
/**
* Notifying Occurrences of Errors
*/
public void notificationErrorOccured() {
sendBroadcast(new Intent(Constants.ACTION_ERROR_OCCURED));
}
}