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

Unverified Commit 5f26f6e7 authored by Adnan Begovic's avatar Adnan Begovic Committed by Michael Bestas
Browse files

SystemUI: Add AmbientDisplay tile

Squashed with:

Author: Adnan Begovic <adnan@cyngn.com>
Date:   Fri Dec 11 16:16:02 2015 -0800

    SystemUI: Readd AmbientDisplayTile.

    Change-Id: Ie7b93ba0f87d505206b5d60f193c2234d83d7eac

Author: Michael Bestas <mkbestas@lineageos.org>
Date:   Sun Sep 17 22:51:15 2017 +0300

    SystemUI: Hide ambient display tile if device does not support it

    * Add a check similar to the Settings app

    Change-Id: I603cd28b8dd1fadff9ffcfb6953c7b72514b5857

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Wed Mar 17 22:34:17 2021 +0100

    SystemUI: AmbientTile: Don't hardcode display settings intent

    Change-Id: Ifaa69c2f235b85ae847524c81f0ba59e2a51cf01

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Wed Mar 17 22:37:04 2021 +0100

    SystemUI: AmbientTile: Use SecureSetting to change doze setting

    Change-Id: I7f004bcf45493130ad50faacb6e390cd640e53db

Author: LuK1337 <priv.luk@gmail.com>
Date:   Wed Mar 17 22:40:49 2021 +0100

    SystemUI: AmbientTile: Actually start using SecureSetting

    Change-Id: I5d94f6d2e596dbc6b44ae4f30f479d335a067661

Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date:   Thu Mar 18 10:51:54 2021 +0100

    SystemUI: AmbientTile: Default the setting to 1

    Change-Id: Idea9dda702fdbaa0e2836e7a2573aa57cf24449e

Change-Id: Iea339685f523016876f059052e66e97fd5170a81
parent d443c766
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2014 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="64dp"
        android:height="64dp"
        android:viewportWidth="64"
        android:viewportHeight="64">

    <group
            android:translateY="-988.583">
        <path
                android:fillColor="#FFFFFFFF"
                android:pathData="M15.0133
1051.24c-1.3615-0.2479-2.37425-1.2789-2.57968-2.6262-0.06554-0.4298-0.06571-55.8484-0.00018-56.28
0.09875-0.65024 0.367851-1.20544 0.812983-1.6773 0.402211-0.42637
0.920053-0.7356 1.49909-0.8952l0.299302-0.0825h16.845 16.845l0.291174
0.0804c1.24697 0.34447 2.13039 1.32473 2.32019 2.57456 0.06515 0.42898 0.06541
55.8484 0.0003 56.28-0.188067 1.2461-1.07608 2.2305-2.32306 2.5752l-0.288567
0.08h-16.755c-13.5267 0-16.7958
0-16.9665-0.034zm29.8065-31.1862v-19.23h-12.99-12.99v19.23 19.23h12.99
12.99v-19.23zm-13.459
11.687c-1.03547-0.2354-1.77837-1.1208-1.83292-2.1845l-0.01654-0.3225h1.87175c1.02946
0 2.10645 0.01 2.3933 0.02l0.521553 0.02-0.01945 0.253c-0.02847 0.3705-0.09559
0.6134-0.267159 0.9672-0.135477 0.2794-0.18522 0.3474-0.439626 0.6013-0.31197
0.3114-0.571617 0.4707-0.976866 0.5995-0.269196 0.085-0.949163 0.111-1.23404
0.046zm-9.04096-4.1842v-0.6872l1.10534-1.0831 1.10534-1.0831
0.02483-1.2072c0.01366-0.664 0.02781-2.213 0.03145-3.4422 0.007-2.3727
0.01776-2.5909 0.162279-3.3 0.234013-1.1483 0.861931-2.2993 1.7263-3.1643
0.762874-0.7634 1.91951-1.4813 3.00204-1.8633 0.262572-0.093 0.512691-0.1813
0.555819-0.1969l0.07842-0.029 0.01577-0.426c0.01284-0.3469 0.03018-0.4706
0.09332-0.666 0.197394-0.6109 0.642609-1.0525 1.21018-1.2004 0.365688-0.095
0.860153-0.043 1.2089 0.1282 0.234414 0.1149 0.589851 0.4783 0.725931 0.7422
0.171483 0.3325 0.207933 0.491 0.225975 0.9825 0.01148 0.3126 0.02671 0.4425
0.0519 0.4425 0.01961 0 0.2844 0.088 0.588423 0.1954 2.74734 0.9715 4.21726
2.7794 4.71985 5.805 0.171696 1.0336 0.211308 1.7926 0.259098 4.9646l0.03345
2.22 1.10911 1.095 1.1091 1.095-0.0014 0.6825-0.0014 0.6825h-9.57-9.57v-0.6872z" />
    </group>
</vector>
+7 −0
Original line number Diff line number Diff line
@@ -26,6 +26,13 @@
    <string name="clock">Clock</string>

    <!-- Custom QS tiles -->
    <!-- Ambient display QS tile -->
    <string name="quick_settings_ambient_display_label">Ambient display</string>
    <string name="accessibility_quick_settings_ambient_display_off">Ambient display off.</string>
    <string name="accessibility_quick_settings_ambient_display_on">Ambient display on.</string>
    <string name="accessibility_quick_settings_ambient_display_changed_off">Ambient display turned off.</string>
    <string name="accessibility_quick_settings_ambient_display_changed_on">Ambient display turned on.</string>

    <!-- Caffeine QS tile -->
    <string name="quick_settings_caffeine_label">Caffeine</string>
    <string name="accessibility_quick_settings_caffeine_off">Caffeine off.</string>
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@

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

    <!-- The tiles to display in QuickSettings -->
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.tiles.AirplaneModeTile;
import com.android.systemui.qs.tiles.AlarmTile;
import com.android.systemui.qs.tiles.AmbientDisplayTile;
import com.android.systemui.qs.tiles.BatterySaverTile;
import com.android.systemui.qs.tiles.BluetoothTile;
import com.android.systemui.qs.tiles.CaffeineTile;
@@ -94,6 +95,7 @@ public class QSFactoryImpl implements QSFactory {
    private final Provider<DeviceControlsTile> mDeviceControlsTileProvider;
    private final Provider<AlarmTile> mAlarmTileProvider;
    private final Provider<QuickAccessWalletTile> mQuickAccessWalletTileProvider;
    private final Provider<AmbientDisplayTile> mAmbientDisplayTileProvider;
    private final Provider<CaffeineTile> mCaffeineTileProvider;
    private final Provider<HeadsUpTile> mHeadsUpTileProvider;
    private final Provider<SyncTile> mSyncTileProvider;
@@ -132,6 +134,7 @@ public class QSFactoryImpl implements QSFactory {
            Provider<DeviceControlsTile> deviceControlsTileProvider,
            Provider<AlarmTile> alarmTileProvider,
            Provider<QuickAccessWalletTile> quickAccessWalletTileProvider,
            Provider<AmbientDisplayTile> ambientDisplayTileProvider,
            Provider<CaffeineTile> caffeineTileProvider,
            Provider<HeadsUpTile> headsUpTileProvider,
            Provider<SyncTile> syncTileProvider) {
@@ -165,6 +168,7 @@ public class QSFactoryImpl implements QSFactory {
        mDeviceControlsTileProvider = deviceControlsTileProvider;
        mAlarmTileProvider = alarmTileProvider;
        mQuickAccessWalletTileProvider = quickAccessWalletTileProvider;
        mAmbientDisplayTileProvider = ambientDisplayTileProvider;
        mCaffeineTileProvider = caffeineTileProvider;
        mHeadsUpTileProvider = headsUpTileProvider;
        mSyncTileProvider = syncTileProvider;
@@ -235,6 +239,8 @@ public class QSFactoryImpl implements QSFactory {
            case "wallet":
                return mQuickAccessWalletTileProvider.get();
            // Additional tiles.
            case "ambient_display":
                return mAmbientDisplayTileProvider.get();
            case "caffeine":
                return mCaffeineTileProvider.get();
            case "heads_up":
+164 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The CyanogenMod Project
 * Copyright (C) 2017-2021 The LineageOS 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 static com.android.internal.logging.MetricsLogger.VIEW_UNKNOWN;

import android.app.ActivityManager;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.service.quicksettings.Tile;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;

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.FalsingManager;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
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.qs.SecureSetting;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.util.settings.SecureSettings;

import javax.inject.Inject;

/** Quick settings tile: Ambient Display **/
public class AmbientDisplayTile extends QSTileImpl<BooleanState> {

    private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_ambient_display);
    private final SecureSetting mSetting;

    @Inject
    public AmbientDisplayTile(
            QSHost host,
            @Background Looper backgroundLooper,
            @Main Handler mainHandler,
            FalsingManager falsingManager,
            MetricsLogger metricsLogger,
            StatusBarStateController statusBarStateController,
            ActivityStarter activityStarter,
            QSLogger qsLogger,
            UserTracker userTracker,
            SecureSettings secureSettings
    ) {
        super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger,
                statusBarStateController, activityStarter, qsLogger);

        mSetting = new SecureSetting(secureSettings, mHandler, Secure.DOZE_ENABLED,
                userTracker.getUserId(), 1) {
            @Override
            protected void handleValueChanged(int value, boolean observedChange) {
                handleRefreshState(value);
            }
        };
    }

    @Override
    protected void handleDestroy() {
        super.handleDestroy();
        mSetting.setListening(false);
    }

    @Override
    public boolean isAvailable() {
        String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null;
        if (TextUtils.isEmpty(name)) {
            name = mContext.getString(com.android.internal.R.string.config_dozeComponent);
        }
        return !TextUtils.isEmpty(name);
    }

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

    @Override
    public void handleSetListening(boolean listening) {
        super.handleSetListening(listening);
        mSetting.setListening(listening);
    }

    @Override
    protected void handleUserSwitch(int newUserId) {
        mSetting.setUserId(newUserId);
        handleRefreshState(mSetting.getValue());
    }

    @Override
    protected void handleClick(@Nullable View view) {
        mSetting.setValue(mState.value ? 0 : 1);
    }

    @Override
    public Intent getLongClickIntent() {
        return new Intent(Settings.ACTION_DISPLAY_SETTINGS);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue();
        final boolean enable = value != 0;
        state.value = enable;
        state.label = mContext.getString(R.string.quick_settings_ambient_display_label);
        state.icon = mIcon;
        if (enable) {
            state.contentDescription =  mContext.getString(
                    R.string.accessibility_quick_settings_ambient_display_on);
            state.state = Tile.STATE_ACTIVE;
        } else {
            state.contentDescription =  mContext.getString(
                    R.string.accessibility_quick_settings_ambient_display_off);
            state.state = Tile.STATE_INACTIVE;
        }
    }

    @Override
    public CharSequence getTileLabel() {
        return mContext.getString(R.string.quick_settings_ambient_display_label);
    }

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

    @Override
    protected String composeChangeAnnouncement() {
        if (mState.value) {
            return mContext.getString(
                    R.string.accessibility_quick_settings_ambient_display_changed_on);
        } else {
            return mContext.getString(
                    R.string.accessibility_quick_settings_ambient_display_changed_off);
        }
    }
}