/
ActionButtonActivity.java
97 lines (83 loc) · 2.79 KB
/
ActionButtonActivity.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
/**
* RealWear Development Software, Source Code and Object Code
* (c) RealWear, Inc. All rights reserved.
* <p>
* Contact info@realwear.com for further information about the use of this code.
*/
package com.realwear.hmt1developerexamples;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.ImageView;
/**
* Activity that shows how to interact with the action button on a HMT-1 device
*/
public class ActionButtonActivity extends Activity {
private static final int ActionBtnKeyCode = 500;
private ImageView mActionButtonImageView;
/**
* Called when the activity is created
*
* @param savedInstanceState See Android docs
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.action_button_main);
mActionButtonImageView = (ImageView) findViewById(R.id.actionButtonImageView);
// Disable the action button default behaviour
mActionButtonImageView.setContentDescription("hf_no_ptt_home");
}
/**
* Called when activity is resumed - See Android docs
*/
@Override
protected void onResume() {
super.onResume();
mActionButtonImageView.setImageResource(R.drawable.radio_button_unchecked);
}
/**
* Called when activity is paused - See Android docs
*/
@Override
protected void onPause() {
super.onPause();
this.finish();
}
/**
* Called when a key is pressed - See Android docs
*
* @param keyCode The value in event.getKeyCode()
* @param event Description of the key event
* @return true if the action button was pressed, otherwise false
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case ActionBtnKeyCode:
mActionButtonImageView.setImageResource(R.drawable.radio_button_red);
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Called when a key is released - See Android docs
*
* @param keyCode The value in event.getKeyCode()
* @param event Description of the key event
* @return true if the action button was pressed, otherwise false
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case ActionBtnKeyCode:
mActionButtonImageView.setImageResource(R.drawable.radio_button_unchecked);
return true;
}
return super.onKeyUp(keyCode, event);
}
}