-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControllerExample.java
146 lines (107 loc) · 4.47 KB
/
ControllerExample.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
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class ControllerExample extends AppCompatActivity {
//A simple example on how to implement DMD Remote Controller Support
//Our Remotes always send out a broadcast on key press and key release
//You should register the broadcast listener on Resume of your activity and unregister on Pause
//You can further improve the example by adding logic for long press / repeat
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
//Register the Remote Listener
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(remoteListener, new IntentFilter("com.thorkracing.wireddevices.keypress"),
Context.RECEIVER_EXPORTED);
}
else{
registerReceiver(remoteListener, new IntentFilter("com.thorkracing.wireddevices.keypress"));
}
}
@Override
protected void onPause() {
super.onPause();
//Unregister the remote listener
if (remoteListener != null) {
try {
unregisterReceiver(remoteListener);
} catch (Exception ignore) {}
}
}
private final BroadcastReceiver remoteListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null &&
intent.getAction().equals("com.thorkracing.wireddevices.keypress")) {
//When the key is pressed
if (intent.hasExtra("key_press")){
int keyCode = intent.getIntExtra("key_press",0);
switch (keyCode){
//UP (Usually Map Pan or Menus Select Up)
case 19:
break;
//DOWN (Usually Map Pan or Menus Select Down)
case 20:
break;
//LEFT (Usually Map Pan or Menus Select Left)
case 21:
break;
//RIGHT (Usually Map Pan or Menus Select Right)
case 22:
break;
//ROUND BUTTON 1 (Usually Follow Location Toggle / Center Map)
case 66:
break;
//ROUND BUTTON 2 (Usually Cancel / Back / 3D Mode / Tilt)
case 111:
break;
//SWITCH IN (Usually Zoom In)
case 136:
break;
//SWITCH OUT (Usually Zoom out)
case 137:
break;
}
}
//When the key is released
else if (intent.hasExtra("key_release")){
int keyCode = intent.getIntExtra("key_release",0);
switch (keyCode){
//UP (Usually Map Pan or Menus Select Up)
case 19:
break;
//DOWN (Usually Map Pan or Menus Select Down)
case 20:
break;
//LEFT (Usually Map Pan or Menus Select Left)
case 21:
break;
//RIGHT (Usually Map Pan or Menus Select Right)
case 22:
break;
//ROUND BUTTON 1 (Usually Follow Location Toggle / Center Map)
case 66:
break;
//ROUND BUTTON 2 (Usually Cancel / Back / 3D Mode / Tilt)
case 111:
break;
//SWITCH IN (Usually Zoom In)
case 136:
break;
//SWITCH OUT (Usually Zoom out)
case 137:
break;
}
}
}
}
};
}