-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecondpage.java
171 lines (100 loc) · 6.2 KB
/
secondpage.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
package com.example.phonergb;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class secondpage extends AppCompatActivity {
Object irdaService;
Method irWrite;
SparseArray<String> codemap;
public final String RED_CODE = "0000 006d 0022 0002 0155 00aa 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 003e 0016 003e 0016 0016 0016 003e 0016 0016 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 0612 0155 0055 0016 0e31";
public final String GREEN_CODE = "0000 006d 0022 0002 0155 00aa 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 0016 0016 003e 0016 003e 0016 0016 0016 003e 0016 0016 0016 0016 0016 003e 0016 003e 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 0612 0155 0055 0016 0e31";
public final String BLUE_CODE = "0000 006d 0022 0002 0155 00aa 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 003e 0016 003e 0016 0016 0016 003e 0016 0612 0155 0055 0016 0e31";
public final String WHITE_CODE = "0000 006d 0022 0002 0155 00aa 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 003e 0016 0016 0016 003e 0016 003e 0016 003e 0016 0016 0016 003e 0016 0612 0155 0055 0016 0e31";
public final String POWER_CODE = "0000 006d 0022 0002 0155 00aa 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 003e 0016 0612 0155 0055 0016 0e31";
public final String BRIGHTNESS_UP_CODE = "0000 006d 0022 0002 0155 00aa 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 003e 0016 003e 0016 003e 0016 0016 0016 003e 0016 0016 0016 003e 0016 003e 0016 0016 0016 0016 0016 0016 0016 003e 0016 0016 0016 003e 0016 0612 0155 0055 0016 0e31";
protected String hex2dec( String irData)
{
List<String> list = new ArrayList<String>(Arrays.asList(irData
.split(" ")));
list.remove(0);
int frequency = Integer.parseInt(list.remove(0), 16);
list.remove(0);
list.remove(0);
for (int i = 0; i < list.size(); i++) {
list.set(i, Integer.toString(Integer.parseInt(list.get(i), 16)));
}
frequency = (int) (1000000 / (frequency * 0.241246));
list.add(0, Integer.toString(frequency));
irData = "";
for (String s : list) {
irData += s + ",";
}
return irData;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Button buttonexit = (Button) findViewById(R.id.buttonexit);
buttonexit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final AlertDialog.Builder builder = new AlertDialog.Builder(secondpage.this);
builder.setTitle("Exit remote");
builder.setMessage("Do you want to exit ??");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondpage);
codemap = new SparseArray<String>();
codemap.put(R.id.buttonPower, hex2dec(POWER_CODE));
codemap.put(R.id.buttonRed, hex2dec(RED_CODE));
codemap.put(R.id.buttonGreen, hex2dec(GREEN_CODE));
codemap.put(R.id.buttonBlue, hex2dec(BLUE_CODE));
codemap.put(R.id.buttonWhite, hex2dec(WHITE_CODE));
codemap.put(R.id.buttonBrightnessUp, hex2dec(BRIGHTNESS_UP_CODE));
Class c = irdaService.getClass();
Class params[] = {String.class};
try {
irWrite = c.getMethod("write_irsend", params);
}
catch (NoSuchMethodException e){
e.printStackTrace();
}
}
public void sendIR(View v){
Log.i("button click", "pressed " + ((Button) v).getText() + " button");
try{
irWrite.invoke(irdaService, codemap.get(v.getId()));
}
catch (Exception e){
e.printStackTrace();
}
}
}