Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da6d30ab authored by Evan Severson's avatar Evan Severson Committed by Philip P. Moltmann
Browse files

Create camera toggle tile

Bug: 162549680
Test: None (tested with subsequent change)
Change-Id: I35c2528fa2bf5800c3329a7b5448addf476d12ff
parent 85bcae5e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@

    <!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
    <string name="quick_settings_tiles_stock" translatable="false">
        wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,dark,work,cast,night,screenrecord,reverse,reduce_brightness
        wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,dark,work,cast,night,screenrecord,reverse,reduce_brightness,cameratoggle
    </string>

    <!-- The tiles to display in QuickSettings -->
+4 −0
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@
            android:key="bluetooth"
            android:title="@string/quick_settings_bluetooth_label" />

        <com.android.systemui.tuner.StatusBarSwitch
            android:key="cameratoggle"
            android:title="Camera Toggle" />

        <!-- nfc -->
        <!-- tty -->
        <!-- speakerphone -->
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.tiles.AirplaneModeTile;
import com.android.systemui.qs.tiles.BatterySaverTile;
import com.android.systemui.qs.tiles.BluetoothTile;
import com.android.systemui.qs.tiles.CameraToggleTile;
import com.android.systemui.qs.tiles.CastTile;
import com.android.systemui.qs.tiles.CellularTile;
import com.android.systemui.qs.tiles.ColorInversionTile;
@@ -83,6 +84,7 @@ public class QSFactoryImpl implements QSFactory {
    private final Provider<UiModeNightTile> mUiModeNightTileProvider;
    private final Provider<ScreenRecordTile> mScreenRecordTileProvider;
    private final Provider<ReduceBrightColorsTile> mReduceBrightColorsTileProvider;
    private final Provider<CameraToggleTile> mCameraToggleTileProvider;

    private final Lazy<QSHost> mQsHostLazy;
    private final Provider<CustomTile.Builder> mCustomTileBuilderProvider;
@@ -115,7 +117,8 @@ public class QSFactoryImpl implements QSFactory {
            Provider<GarbageMonitor.MemoryTile> memoryTileProvider,
            Provider<UiModeNightTile> uiModeNightTileProvider,
            Provider<ScreenRecordTile> screenRecordTileProvider,
            Provider<ReduceBrightColorsTile> reduceBrightColorsTileProvider) {
            Provider<ReduceBrightColorsTile> reduceBrightColorsTileProvider,
            Provider<CameraToggleTile> cameraToggleTileProvider) {
        mQsHostLazy = qsHostLazy;
        mCustomTileBuilderProvider = customTileBuilderProvider;

@@ -143,6 +146,7 @@ public class QSFactoryImpl implements QSFactory {
        mUiModeNightTileProvider = uiModeNightTileProvider;
        mScreenRecordTileProvider = screenRecordTileProvider;
        mReduceBrightColorsTileProvider = reduceBrightColorsTileProvider;
        mCameraToggleTileProvider = cameraToggleTileProvider;
    }

    public QSTile createTile(String tileSpec) {
@@ -198,6 +202,8 @@ public class QSFactoryImpl implements QSFactory {
                return mScreenRecordTileProvider.get();
            case "reduce_brightness":
                return mReduceBrightColorsTileProvider.get();
            case "cameratoggle":
                return mCameraToggleTileProvider.get();
        }

        // Custom tiles
+109 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source 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.systemui.qs.tiles;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.service.quicksettings.Tile;
import android.widget.Switch;

import com.android.internal.logging.MetricsLogger;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.policy.CameraToggleController;

import javax.inject.Inject;

public class CameraToggleTile extends QSTileImpl<QSTile.BooleanState> {

    private CameraToggleController mCameraToggleController;

    @Inject
    protected CameraToggleTile(QSHost host,
            @Background Looper backgroundLooper,
            @Main Handler mainHandler,
            MetricsLogger metricsLogger,
            StatusBarStateController statusBarStateController,
            ActivityStarter activityStarter,
            QSLogger qsLogger,
            CameraToggleController cameraToggleController) {
        super(host, backgroundLooper, mainHandler, metricsLogger, statusBarStateController,
                activityStarter, qsLogger);
        mCameraToggleController = cameraToggleController;
        mCameraToggleController.addCallback((b) -> refreshState());
    }

    @Override
    public BooleanState newTileState() {
        return new BooleanState();
    }

    @Override
    protected void handleClick() {
        mCameraToggleController.setCameraEnabled(!mCameraToggleController.isCameraEnabled());
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.icon = new CameraToggleTileIcon();
        state.state = mCameraToggleController.isCameraEnabled()
                ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        state.value = mCameraToggleController.isCameraEnabled();
        state.label = "Camera";
        if (!mCameraToggleController.isCameraAvailable()) {
            state.secondaryLabel = "Currently in use";
        } else {
            state.secondaryLabel = null;
        }
        state.handlesLongClick = false;
        state.contentDescription = state.label;
        state.expandedAccessibilityClassName = Switch.class.getName();
    }

    @Override
    public int getMetricsCategory() {
        return 0;
    }

    @Override
    public Intent getLongClickIntent() {
        return null;
    }

    @Override
    public CharSequence getTileLabel() {
        return "Camera";
    }

    class CameraToggleTileIcon extends Icon {

        @Override
        public Drawable getDrawable(Context context) {
            return context.getDrawable(R.drawable.ic_camera);
        }
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source 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.systemui.statusbar.policy;

import com.android.systemui.Dumpable;

public interface CameraToggleController extends CallbackController<CameraToggleController.Callback>,
        Dumpable {

    boolean isCameraEnabled();
    void setCameraEnabled(boolean enabled);

    boolean isCameraAvailable();

    interface Callback {
        void onCameraEnabledChanged(boolean enable);
    }

}
Loading