/
AbstractMythmoteDialogFragment.java
67 lines (49 loc) · 1.77 KB
/
AbstractMythmoteDialogFragment.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
package tkj.android.homecontrol.mythmote;
import tkj.android.homecontrol.mythmote.keymanager.KeyBindingEntry;
import tkj.android.homecontrol.mythmote.keymanager.KeyBindingManager;
import tkj.android.homecontrol.mythmote.keymanager.KeyMapBinder;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.Button;
public class AbstractMythmoteDialogFragment extends DialogFragment implements KeyMapBinder {
protected KeyBindingManager mKeyManager;
protected MythCom mythCom;
@Override
public void onCreate(Bundle savedInstanceState) {
mythCom = MythCom.GetMythCom(this.getActivity());
mKeyManager = new KeyBindingManager(this.getActivity(), this, mythCom);
super.onCreate(savedInstanceState);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mKeyManager.loadKeys();
}
@Override
public void onDestroy() {
super.onDestroy();
mythCom = null;
mKeyManager = null;
}
/**
* Enable the long click and normal click actions where a long click will
* configure the button, and a normal tap will perform the command
*
* This is the callback from the {@link KeyBindingManager}
*/
public View bind(KeyBindingEntry entry) {
int buttonId = entry.getMythKey().getButtonId();
View v = this.getActivity().findViewById(buttonId);
if (null == v)
return null;
v.setOnLongClickListener(mKeyManager);
v.setOnClickListener(mKeyManager);
if(buttonId == R.id.ButtonJump1 || buttonId == R.id.ButtonJump2 ||
buttonId == R.id.ButtonJump3 || buttonId == R.id.ButtonJump4 ||
buttonId == R.id.ButtonJump5 || buttonId == R.id.ButtonJump6){
((Button)v).setText(entry.getFriendlyName());
}
return v;
}
}