FileDocCategorySizeDatePackage
FlashlightTile.javaAPI DocAndroid 5.1 API4704Thu Mar 12 22:22:42 GMT 2015com.android.systemui.qs.tiles

FlashlightTile

public class FlashlightTile extends com.android.systemui.qs.QSTile implements FlashlightController.FlashlightListener
Quick settings tile: Control flashlight

Fields Summary
private static final long
RECENTLY_ON_DURATION_MILLIS
Grace period for which we consider the flashlight still available because it was recently on.
private final AnimationIcon
mEnable
private final AnimationIcon
mDisable
private final com.android.systemui.statusbar.policy.FlashlightController
mFlashlightController
private long
mWasLastOn
private Runnable
mRecentlyOnTimeout
Constructors Summary
public FlashlightTile(Host host)


       
        super(host);
        mFlashlightController = host.getFlashlightController();
        mFlashlightController.addListener(this);
    
Methods Summary
protected java.lang.StringcomposeChangeAnnouncement()

        if (mState.value) {
            return mContext.getString(R.string.accessibility_quick_settings_flashlight_changed_on);
        } else {
            return mContext.getString(R.string.accessibility_quick_settings_flashlight_changed_off);
        }
    
protected voidhandleClick()

        if (ActivityManager.isUserAMonkey()) {
            return;
        }
        boolean newState = !mState.value;
        mFlashlightController.setFlashlight(newState);
        refreshState(newState ? UserBoolean.USER_TRUE : UserBoolean.USER_FALSE);
    
protected voidhandleDestroy()

        super.handleDestroy();
        mFlashlightController.removeListener(this);
    
protected voidhandleUpdateState(BooleanState state, java.lang.Object arg)

        if (state.value) {
            mWasLastOn = SystemClock.uptimeMillis();
        }

        if (arg instanceof UserBoolean) {
            state.value = ((UserBoolean) arg).value;
        }

        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 = mWasLastOn != 0 || mFlashlightController.isAvailable();
        state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label);
        final AnimationIcon icon = state.value ? mEnable : mDisable;
        icon.setAllowAnimation(arg instanceof UserBoolean && ((UserBoolean) arg).userInitiated);
        state.icon = icon;
        int onOrOffId = state.value
                ? R.string.accessibility_quick_settings_flashlight_on
                : R.string.accessibility_quick_settings_flashlight_off;
        state.contentDescription = mContext.getString(onOrOffId);
    
protected voidhandleUserSwitch(int newUserId)

    
protected BooleanStatenewTileState()

        return new BooleanState();
    
public voidonFlashlightAvailabilityChanged(boolean available)

        refreshState();
    
public voidonFlashlightError()

        refreshState(UserBoolean.BACKGROUND_FALSE);
    
public voidonFlashlightOff()

        refreshState(UserBoolean.BACKGROUND_FALSE);
    
public voidsetListening(boolean listening)