blob: cf8ed2d470a7c442a9226746820ec0d2573f0581 (
plain)
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
|
package com.android.systemui.statusbar.powerwidget;
import com.android.systemui.R;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import java.util.ArrayList;
import java.util.List;
public class FlashlightButton extends PowerButton {
private static final List<Uri> OBSERVED_URIS = new ArrayList<Uri>();
static {
OBSERVED_URIS.add(Settings.System.getUriFor(Settings.System.TORCH_STATE));
}
public FlashlightButton() { mType = BUTTON_FLASHLIGHT; }
@Override
protected void updateState(Context context) {
boolean enabled = Settings.System.getInt(context.getContentResolver(), Settings.System.TORCH_STATE, 0) == 1;
if(enabled) {
mIcon = R.drawable.stat_flashlight_on;
mState = STATE_ENABLED;
} else {
mIcon = R.drawable.stat_flashlight_off;
mState = STATE_DISABLED;
}
}
@Override
protected void toggleState(Context context) {
boolean bright = Settings.System.getInt(context.getContentResolver(),
Settings.System.EXPANDED_FLASH_MODE, 0) == 1;
Intent i = new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT");
i.putExtra("bright", bright);
context.sendBroadcast(i);
}
@Override
protected boolean handleLongClick(Context context) {
// it may be better to make an Intent action for the Torch
// we may want to look at that option later
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("net.cactii.flash2", "net.cactii.flash2.MainActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return true;
}
@Override
protected List<Uri> getObservedUris() {
return OBSERVED_URIS;
}
}
|