Loading packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java +30 −2 Original line number Diff line number Diff line Loading @@ -24,13 +24,20 @@ import com.android.systemui.statusbar.policy.FlashlightController; import android.app.ActivityManager; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.provider.Settings.Secure; import android.util.Log; /** Quick settings tile: Control flashlight **/ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements FlashlightController.FlashlightListener { /** Grace period for which we consider the flashlight * still available because it was recently on. */ private static final long RECENTLY_ON_DURATION_MILLIS = 500; private final FlashlightController mFlashlightController; private long mWasLastOn; public FlashlightTile(Host host) { super(host); Loading Loading @@ -63,12 +70,26 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements @Override protected void handleUpdateState(BooleanState state, Object arg) { if (state.value) { mWasLastOn = SystemClock.uptimeMillis(); } if (arg instanceof Boolean) { state.value = (Boolean) arg; } // Always show the tile when the flashlight is on. This is needed because if (!state.value && mWasLastOn != 0) { if (SystemClock.uptimeMillis() > mWasLastOn + RECENTLY_ON_DURATION_MILLIS) { mWasLastOn = 0; } else { mHandler.removeCallbacks(mRecentlyOnTimeout); mHandler.postAtTime(mRecentlyOnTimeout, mWasLastOn + RECENTLY_ON_DURATION_MILLIS); } } // Always show the tile when the flashlight is or was recently on. This is needed because // the camera is not available while it is being used for the flashlight. state.visible = state.value || mFlashlightController.isAvailable(); state.visible = mWasLastOn != 0 || mFlashlightController.isAvailable(); state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label); state.iconId = state.value ? R.drawable.ic_qs_flashlight_on : R.drawable.ic_qs_flashlight_off; Loading @@ -88,4 +109,11 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements public void onFlashlightAvailabilityChanged(boolean available) { refreshState(); } private Runnable mRecentlyOnTimeout = new Runnable() { @Override public void run() { refreshState(); } }; } packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightController.java +5 −7 Original line number Diff line number Diff line Loading @@ -44,9 +44,6 @@ public class FlashlightController { private static final String TAG = "FlashlightController"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final boolean ENFORCE_AVAILABILITY_LISTENER = SystemProperties.getBoolean("persist.sysui.flash.listener", false); private static final int DISPATCH_ERROR = 0; private static final int DISPATCH_OFF = 1; private static final int DISPATCH_AVAILABILITY_CHANGED = 2; Loading Loading @@ -82,10 +79,11 @@ public class FlashlightController { return; } if (mCameraId != null) { ensureHandler(); mCameraAvailable = true; mCameraManager.addAvailabilityListener(mAvailabilityListener, mHandler); } } public synchronized void setFlashlight(boolean enabled) { if (mFlashlightEnabled != enabled) { Loading @@ -105,7 +103,7 @@ public class FlashlightController { } public synchronized boolean isAvailable() { return ENFORCE_AVAILABILITY_LISTENER ? mCameraAvailable : (mCameraId != null); return mCameraAvailable; } public void addListener(FlashlightListener l) { Loading Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java +30 −2 Original line number Diff line number Diff line Loading @@ -24,13 +24,20 @@ import com.android.systemui.statusbar.policy.FlashlightController; import android.app.ActivityManager; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.provider.Settings.Secure; import android.util.Log; /** Quick settings tile: Control flashlight **/ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements FlashlightController.FlashlightListener { /** Grace period for which we consider the flashlight * still available because it was recently on. */ private static final long RECENTLY_ON_DURATION_MILLIS = 500; private final FlashlightController mFlashlightController; private long mWasLastOn; public FlashlightTile(Host host) { super(host); Loading Loading @@ -63,12 +70,26 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements @Override protected void handleUpdateState(BooleanState state, Object arg) { if (state.value) { mWasLastOn = SystemClock.uptimeMillis(); } if (arg instanceof Boolean) { state.value = (Boolean) arg; } // Always show the tile when the flashlight is on. This is needed because if (!state.value && mWasLastOn != 0) { if (SystemClock.uptimeMillis() > mWasLastOn + RECENTLY_ON_DURATION_MILLIS) { mWasLastOn = 0; } else { mHandler.removeCallbacks(mRecentlyOnTimeout); mHandler.postAtTime(mRecentlyOnTimeout, mWasLastOn + RECENTLY_ON_DURATION_MILLIS); } } // Always show the tile when the flashlight is or was recently on. This is needed because // the camera is not available while it is being used for the flashlight. state.visible = state.value || mFlashlightController.isAvailable(); state.visible = mWasLastOn != 0 || mFlashlightController.isAvailable(); state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label); state.iconId = state.value ? R.drawable.ic_qs_flashlight_on : R.drawable.ic_qs_flashlight_off; Loading @@ -88,4 +109,11 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements public void onFlashlightAvailabilityChanged(boolean available) { refreshState(); } private Runnable mRecentlyOnTimeout = new Runnable() { @Override public void run() { refreshState(); } }; }
packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightController.java +5 −7 Original line number Diff line number Diff line Loading @@ -44,9 +44,6 @@ public class FlashlightController { private static final String TAG = "FlashlightController"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final boolean ENFORCE_AVAILABILITY_LISTENER = SystemProperties.getBoolean("persist.sysui.flash.listener", false); private static final int DISPATCH_ERROR = 0; private static final int DISPATCH_OFF = 1; private static final int DISPATCH_AVAILABILITY_CHANGED = 2; Loading Loading @@ -82,10 +79,11 @@ public class FlashlightController { return; } if (mCameraId != null) { ensureHandler(); mCameraAvailable = true; mCameraManager.addAvailabilityListener(mAvailabilityListener, mHandler); } } public synchronized void setFlashlight(boolean enabled) { if (mFlashlightEnabled != enabled) { Loading @@ -105,7 +103,7 @@ public class FlashlightController { } public synchronized boolean isAvailable() { return ENFORCE_AVAILABILITY_LISTENER ? mCameraAvailable : (mCameraId != null); return mCameraAvailable; } public void addListener(FlashlightListener l) { Loading