2 LED tester for Android platform
3 Copyright (C) 2009-2010 RafaĆ Rzepecki
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package pl
.blip
.divide
.ledtester
;
21 import android
.app
.Activity
;
22 import android
.app
.AlertDialog
;
23 import android
.app
.Dialog
;
24 import android
.app
.Notification
;
25 import android
.app
.NotificationManager
;
26 import android
.content
.DialogInterface
;
27 import android
.content
.DialogInterface
.OnClickListener
;
28 import android
.os
.Build
;
29 import android
.os
.Bundle
;
30 import android
.util
.Log
;
31 import android
.view
.KeyEvent
;
32 import android
.view
.View
;
33 import android
.view
.View
.OnFocusChangeListener
;
34 import android
.widget
.EditText
;
35 import android
.widget
.SeekBar
;
36 import android
.widget
.TextView
;
37 import android
.widget
.SeekBar
.OnSeekBarChangeListener
;
38 import android
.widget
.TextView
.OnEditorActionListener
;
40 public class LedTester
extends Activity
{
41 public class TextEditListener
implements OnEditorActionListener
, OnFocusChangeListener
{
42 private SeekBar seekBar
;
44 public TextEditListener(SeekBar seekBar
) {
45 this.seekBar
= seekBar
;
49 public boolean onEditorAction(TextView v
, int actionId
, KeyEvent event
) {
54 private void updateFrom(TextView v
) {
58 final int value
= Integer
.parseInt(v
.getText().toString());
59 if (value
== seekBar
.getProgress())
61 seekBar
.setProgress(value
);
62 v
.setText(String
.valueOf(seekBar
.getProgress()));
67 public void onFocusChange(View v
, boolean hasFocus
) {
69 updateFrom((TextView
) v
);
74 public class LabelUpdatingOnSeekBarChangeListener
implements
75 OnSeekBarChangeListener
{
76 private TextView myLabel
;
77 public LabelUpdatingOnSeekBarChangeListener(TextView label
) {
82 public void onProgressChanged(SeekBar seekBar
, int progress
,
84 final String text
= Integer
.toString(progress
);
85 if (myLabel
.getText().toString().equals(text
))
87 myLabel
.setText(text
);
91 public void onStartTrackingTouch(SeekBar seekBar
) {
95 public void onStopTrackingTouch(SeekBar seekBar
) {
99 private SeekBar redBar
;
100 private SeekBar greenBar
;
101 private SeekBar blueBar
;
102 private EditText redText
;
103 private EditText greenText
;
104 private EditText blueText
;
105 private NotificationManager notificationManager
;
106 private Notification notification
;
107 private SeekBar onBar
;
108 private EditText onText
;
109 private EditText offText
;
110 private SeekBar offBar
;
112 /** Called when the activity is first created. */
114 public void onCreate(Bundle savedInstanceState
) {
115 super.onCreate(savedInstanceState
);
116 setContentView(R
.layout
.main
);
118 redBar
= (SeekBar
) findViewById(R
.id
.red
);
119 greenBar
= (SeekBar
) findViewById(R
.id
.green
);
120 blueBar
= (SeekBar
) findViewById(R
.id
.blue
);
121 onBar
= (SeekBar
) findViewById(R
.id
.on_ms
);
122 offBar
= (SeekBar
) findViewById(R
.id
.off_ms
);
124 redText
= (EditText
) findViewById(R
.id
.red_text
);
125 greenText
= (EditText
) findViewById(R
.id
.green_text
);
126 blueText
= (EditText
) findViewById(R
.id
.blue_text
);
127 onText
= (EditText
) findViewById(R
.id
.on_ms_text
);
128 offText
= (EditText
) findViewById(R
.id
.off_ms_text
);
130 redBar
.setOnSeekBarChangeListener(new LabelUpdatingOnSeekBarChangeListener(redText
));
131 greenBar
.setOnSeekBarChangeListener(new LabelUpdatingOnSeekBarChangeListener(greenText
));
132 blueBar
.setOnSeekBarChangeListener(new LabelUpdatingOnSeekBarChangeListener(blueText
));
133 onBar
.setOnSeekBarChangeListener(new LabelUpdatingOnSeekBarChangeListener(onText
));
134 offBar
.setOnSeekBarChangeListener(new LabelUpdatingOnSeekBarChangeListener(offText
));
136 TextEditListener tel
;
137 tel
= new TextEditListener(redBar
);
138 redText
.setOnEditorActionListener(tel
);
139 redText
.setOnFocusChangeListener(tel
);
140 tel
= new TextEditListener(greenBar
);
141 greenText
.setOnEditorActionListener(tel
);
142 greenText
.setOnFocusChangeListener(tel
);
143 tel
= new TextEditListener(blueBar
);
144 blueText
.setOnEditorActionListener(tel
);
145 blueText
.setOnFocusChangeListener(tel
);
146 tel
= new TextEditListener(onBar
);
147 onText
.setOnEditorActionListener(tel
);
148 onText
.setOnFocusChangeListener(tel
);
149 tel
= new TextEditListener(offBar
);
150 offText
.setOnEditorActionListener(tel
);
151 offText
.setOnFocusChangeListener(tel
);
153 notificationManager
= (NotificationManager
) getSystemService(NOTIFICATION_SERVICE
);
154 notification
= new Notification();
155 notification
.ledOffMS
= 0;
156 notification
.ledOnMS
= 5000;
157 notification
.flags
= Notification
.FLAG_SHOW_LIGHTS
;
165 protected Dialog
onCreateDialog(int id
) {
166 return new AlertDialog
.Builder(this)
167 .setMessage(R
.string
.welcome_text
)
168 .setPositiveButton(android
.R
.string
.ok
, new OnClickListener() {
170 public void onClick(DialogInterface dialog
, int which
) {
176 private void printSystemInfo() {
177 Log
.i("LedTester", "System info:\n" +
178 "\tBoard: " + Build
.BOARD
+
179 "\n\tBrand: " + Build
.BRAND
+
180 "\n\tDevice: " + Build
.DEVICE
+
181 "\n\tDisplay: " + Build
.DISPLAY
+
182 "\n\tFingerprint: " + Build
.FINGERPRINT
+
183 "\n\tHost: " + Build
.HOST
+
184 "\n\tID: " + Build
.ID
+
185 "\n\tModel: " + Build
.MODEL
+
186 "\n\tProduct: " + Build
.PRODUCT
+
187 "\n\tTags: " + Build
.TAGS
+
188 "\n\tType: " + Build
.TYPE
+
189 "\n\tUser: " + Build
.USER
193 public void updateLedColor() {
194 int red
= redBar
.getProgress();
195 int green
= greenBar
.getProgress();
196 int blue
= blueBar
.getProgress();
198 int color
= 0xff000000 | (red
<< 16) | (green
<< 8) | blue
;
200 notification
.ledARGB
= color
;
202 notification
.ledOffMS
= offBar
.getProgress();
203 notification
.ledOnMS
= onBar
.getProgress();
205 notificationManager
.notify(0, notification
);
209 protected void onPause() {
211 notificationManager
.cancel(0);
215 protected void onResume() {