summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2013-06-21 08:57:11 +0200
committerDanny Baumann <dannybaumann@web.de>2013-06-26 08:45:04 +0200
commit1621c284856753f674a0f54ec6f0f7c71a3a98ba (patch)
treebe6376a62b55208e19129362537938a157f6622f /core/java
parent3754b94205e9f22b38337a099376e406c390d372 (diff)
downloadframeworks_base-1621c284856753f674a0f54ec6f0f7c71a3a98ba.zip
frameworks_base-1621c284856753f674a0f54ec6f0f7c71a3a98ba.tar.gz
frameworks_base-1621c284856753f674a0f54ec6f0f7c71a3a98ba.tar.bz2
Use sticky broadcast to convey torch state (1/2).
It doesn't really make sense to store the (non-persistent) state of the torch in a (persistent) setting. As the torch is sending a broadcast anyway, make that broadcast sticky and use it to convey the state. Also unify the torch constants (actions, extras, activity names) at a common place. Change-Id: If845bef27cc79990794aa748dce18cfea3bac1f5
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/provider/Settings.java6
-rw-r--r--core/java/com/android/internal/util/cm/NavigationRingHelpers.java12
-rw-r--r--core/java/com/android/internal/util/cm/TorchConstants.java56
3 files changed, 65 insertions, 9 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 2f05dfe..9e1177f 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2505,12 +2505,6 @@ public final class Settings {
public static final String SIP_ASK_ME_EACH_TIME = "SIP_ASK_ME_EACH_TIME";
/**
- * Torch state (flashlight)
- * FIXME: move me to global state
- * @hide
- */
- public static final String TORCH_STATE = "torch_state";
- /**
* Pointer speed setting.
* This is an integer value in a range between -7 and +7, so there are 15 possible values.
* -7 = slowest
diff --git a/core/java/com/android/internal/util/cm/NavigationRingHelpers.java b/core/java/com/android/internal/util/cm/NavigationRingHelpers.java
index 3d73071..e081de6 100644
--- a/core/java/com/android/internal/util/cm/NavigationRingHelpers.java
+++ b/core/java/com/android/internal/util/cm/NavigationRingHelpers.java
@@ -21,6 +21,7 @@ import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
@@ -33,6 +34,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import static com.android.internal.util.cm.NavigationRingConstants.*;
+import com.android.internal.util.cm.TorchConstants;
import com.android.internal.widget.multiwaveview.GlowPadView;
import com.android.internal.widget.multiwaveview.TargetDrawable;
@@ -43,6 +45,9 @@ public class NavigationRingHelpers {
private static final String ASSIST_ICON_METADATA_NAME = "com.android.systemui.action_assist_icon";
+ private static final IntentFilter TORCH_STATE_FILTER =
+ new IntentFilter(TorchConstants.ACTION_STATE_CHANGED);
+
private NavigationRingHelpers() {
}
@@ -94,7 +99,7 @@ public class NavigationRingHelpers {
public static boolean isTorchAvailable(Context context) {
PackageManager pm = context.getPackageManager();
try {
- return pm.getPackageInfo("net.cactii.flash2", 0) != null;
+ return pm.getPackageInfo(TorchConstants.APP_PACKAGE_NAME, 0) != null;
} catch (PackageManager.NameNotFoundException e) {
// ignored, just catched so we can return false below
}
@@ -204,8 +209,9 @@ public class NavigationRingHelpers {
}
private static int getTorchDrawableResId(Context context) {
- boolean active = Settings.System.getInt(context.getContentResolver(),
- Settings.System.TORCH_STATE, 0) != 0;
+ Intent stateIntent = context.registerReceiver(null, TORCH_STATE_FILTER);
+ boolean active = stateIntent != null
+ && stateIntent.getIntExtra(TorchConstants.EXTRA_CURRENT_STATE, 0) != 0;
if (active) {
return com.android.internal.R.drawable.ic_navigation_ring_torch_on;
diff --git a/core/java/com/android/internal/util/cm/TorchConstants.java b/core/java/com/android/internal/util/cm/TorchConstants.java
new file mode 100644
index 0000000..eea8eea
--- /dev/null
+++ b/core/java/com/android/internal/util/cm/TorchConstants.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.util.cm;
+
+import android.content.Intent;
+
+public class TorchConstants {
+ /**
+ * Package name of the torch app
+ */
+ public static final String APP_PACKAGE_NAME = "net.cactii.flash2";
+
+ /**
+ * Intent broadcast action for toggling the torch state
+ */
+ public static final String ACTION_TOGGLE_STATE = APP_PACKAGE_NAME + ".TOGGLE_FLASHLIGHT";
+
+ /**
+ * Extra for {@link ACTION_TOGGLE_STATE}:
+ * When toggling to on, use the bright brightness setting
+ * Type: boolean
+ */
+ public static final String EXTRA_BRIGHT_MODE = "bright";
+
+ /**
+ * Intent action for 'torch state changed' broadcast
+ */
+ public static final String ACTION_STATE_CHANGED = APP_PACKAGE_NAME + ".TORCH_STATE_CHANGED";
+
+ /**
+ * Extra for {@link ACTION_STATE_CHANGED}:
+ * Current torch state
+ * Type: integer (0/1)
+ */
+ public static final String EXTRA_CURRENT_STATE = "state";
+
+ /**
+ * Intent for launching the torch application
+ */
+ public static Intent INTENT_LAUNCH_APP = new Intent(Intent.ACTION_MAIN)
+ .setClassName(APP_PACKAGE_NAME, APP_PACKAGE_NAME + ".MainActivity");
+}