summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Webster <miketwebster@gmail.com>2010-12-03 20:49:04 -0500
committerMichael Webster <miketwebster@gmail.com>2010-12-03 21:01:22 -0500
commit4acab88fbc9c97b5088e5a358c58cb9282dd717a (patch)
tree649836d4c59f0979703d5b20a56e07de21c63e70
parent25eee5c4ef1f3e3126363f2a101af4f9237170bc (diff)
downloadframeworks_base-4acab88fbc9c97b5088e5a358c58cb9282dd717a.zip
frameworks_base-4acab88fbc9c97b5088e5a358c58cb9282dd717a.tar.gz
frameworks_base-4acab88fbc9c97b5088e5a358c58cb9282dd717a.tar.bz2
Cleanup notification bar flashlight widget to use Torch app,
and add state storage for flashlight. Change-Id: I6d4ad46318a7593809e7ff63601f8bd70db64a0c
-rw-r--r--core/java/android/provider/Settings.java6
-rw-r--r--services/java/com/android/server/status/StatusBarService.java4
-rw-r--r--services/java/com/android/server/status/widget/FlashlightButton.java99
3 files changed, 13 insertions, 96 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index b0e0b1e..0bc241e 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2396,6 +2396,12 @@ public final class Settings {
public static final String LOCKSCREEN_GESTURES_COLOR = "lockscreen_gestures_color";
/**
+ * Torch state (flashlight)
+ * @hide
+ */
+ public static final String TORCH_STATE = "torch_state";
+
+ /**
* Settings to backup. This is here so that it's in the same place as the settings
* keys and easy to update.
* @hide
diff --git a/services/java/com/android/server/status/StatusBarService.java b/services/java/com/android/server/status/StatusBarService.java
index 683e634..18154a5 100644
--- a/services/java/com/android/server/status/StatusBarService.java
+++ b/services/java/com/android/server/status/StatusBarService.java
@@ -2330,6 +2330,10 @@ public class StatusBarService extends IStatusBar.Stub
resolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.WIDGET_BUTTONS),
false, this);
+
+ resolver.registerContentObserver(
+ Settings.System.getUriFor(Settings.System.TORCH_STATE),
+ false, this);
}
@Override
diff --git a/services/java/com/android/server/status/widget/FlashlightButton.java b/services/java/com/android/server/status/widget/FlashlightButton.java
index eb25cf0..d4a9b10 100644
--- a/services/java/com/android/server/status/widget/FlashlightButton.java
+++ b/services/java/com/android/server/status/widget/FlashlightButton.java
@@ -5,46 +5,14 @@ import com.android.server.status.widget.PowerButton;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
import android.provider.Settings;
-import android.util.Log;
-import android.os.Build;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ExecutorService;
-import java.lang.Thread;
-import java.lang.Runnable;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
public class FlashlightButton extends PowerButton {
Context mContext;
-
static FlashlightButton ownButton;
private static final String TAG = "FlashlightButton";
- private static int currentMode;
-
- private static FileWriter mWriter;
-
- private static ExecutorService threadExecutor;
- private static boolean runTimer = false;
-
- private static final int MODE_DEFAULT = 0;
- private static final int MODE_HIGH = 1;
- private static boolean useDeathRay = !Build.DEVICE.equals("supersonic");;
-
- private static final String FLASHLIGHT_FILE;
- private static final String FLASHLIGHT_FILE_SPOTLIGHT = "/sys/class/leds/spotlight/brightness";
- static {
- File ff = new File(FLASHLIGHT_FILE_SPOTLIGHT);
- if (ff.exists()) {
- FLASHLIGHT_FILE = FLASHLIGHT_FILE_SPOTLIGHT;
- } else {
- FLASHLIGHT_FILE = "/sys/class/leds/flashlight/brightness";
- }
- }
public void updateState(Context context) {
mContext = context;
@@ -69,80 +37,19 @@ public class FlashlightButton extends PowerButton {
}
public void toggleState(Context context) {
- currentMode = Settings.System.getInt(context.getContentResolver(), Settings.System.EXPANDED_FLASH_MODE,
- MODE_DEFAULT);
- boolean enabled = getFlashlightEnabled();
- runTimer = !enabled;
- setFlashlightEnabled(!enabled);
+ mContext.sendBroadcast(new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"));
}
public static FlashlightButton getInstance() {
if (ownButton==null) ownButton = new FlashlightButton();
-
return ownButton;
}
public boolean getFlashlightEnabled() {
- try {
- FileInputStream fis = new FileInputStream(FLASHLIGHT_FILE);
- int result = fis.read();
- fis.close();
- return (result != '0');
- } catch (Exception e) {
- return false;
- }
- }
-
- public void setFlashlightEnabled(boolean on) {
- try {
- if (mWriter == null) {
- mWriter = new FileWriter(FLASHLIGHT_FILE);
- }
- int value = 0;
- if (on) {
- switch (currentMode) {
- case MODE_HIGH:
- value = useDeathRay ? 3 : 128;
- break;
- default:
- value = 1;
- break;
- }
- }
- mWriter.write(String.valueOf(value));
- mWriter.flush();
- if (!on) {
- mWriter.close();
- mWriter = null;
- }
- } catch (Exception e) {
- Log.e(TAG, "setFlashlightEnabled failed", e);
- }
- startTimer(on);
- }
-
- private void startTimer(boolean on) {
- if (!on) return;
- if (threadExecutor == null) threadExecutor = Executors.newSingleThreadExecutor();
-
- flashTimer timerRun = new flashTimer();
- threadExecutor.execute(timerRun);
+ return Settings.System.getInt(mContext.getContentResolver(), Settings.System.TORCH_STATE, 0) == 1;
}
- public class flashTimer implements Runnable {
- public flashTimer() {
- }
- public void run() {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- }
- setFlashlightEnabled(runTimer);
- }
- }
-
-
@Override
void initButton(int position) {
}