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

Commit d0e540f5 authored by Adnan Begovic's avatar Adnan Begovic Committed by Luca Stefani
Browse files

SystemUI: Add AmbientDisplay tile

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

Change-Id: Iea339685f523016876f059052e66e97fd5170a81
parent 2e7baed8
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
@@ -45,6 +45,13 @@
    <string name="quick_settings_network_adb_label">ADB over network</string>
    <string name="quick_settings_network_adb_no_network">no network</string>

    <!-- 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
@@ -117,7 +117,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,nfc,location,hotspot,inversion,saver,dark,work,cast,night,adb_network,caffeine,heads_up,sync,volume_panel
        wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,nfc,location,hotspot,inversion,saver,dark,work,cast,night,adb_network,ambient_display,caffeine,heads_up,sync,volume_panel
    </string>

    <!-- The tiles to display in QuickSettings -->
+6 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.qs.QSTileHost;
import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.tiles.AdbOverNetworkTile;
import com.android.systemui.qs.tiles.AirplaneModeTile;
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;
@@ -82,6 +83,7 @@ public class QSFactoryImpl implements QSFactory {
    private final Provider<GarbageMonitor.MemoryTile> mMemoryTileProvider;
    private final Provider<UiModeNightTile> mUiModeNightTileProvider;
    private final Provider<AdbOverNetworkTile> mAdbOverNetworkTileProvider;
    private final Provider<AmbientDisplayTile> mAmbientDisplayTileProvider;
    private final Provider<CaffeineTile> mCaffeineTileProvider;
    private final Provider<HeadsUpTile> mHeadsUpTileProvider;
    private final Provider<SyncTile> mSyncTileProvider;
@@ -110,6 +112,7 @@ public class QSFactoryImpl implements QSFactory {
            Provider<GarbageMonitor.MemoryTile> memoryTileProvider,
            Provider<UiModeNightTile> uiModeNightTileProvider,
            Provider<AdbOverNetworkTile> adbOverNetworkTileProvider,
            Provider<AmbientDisplayTile> ambientDisplayTileProvider,
            Provider<CaffeineTile> caffeineTileProvider,
            Provider<HeadsUpTile> headsUpTileProvider,
            Provider<SyncTile> syncTileProvider,
@@ -134,6 +137,7 @@ public class QSFactoryImpl implements QSFactory {
        mMemoryTileProvider = memoryTileProvider;
        mUiModeNightTileProvider = uiModeNightTileProvider;
        mAdbOverNetworkTileProvider = adbOverNetworkTileProvider;
        mAmbientDisplayTileProvider = ambientDisplayTileProvider;
        mCaffeineTileProvider = caffeineTileProvider;
        mHeadsUpTileProvider = headsUpTileProvider;
        mSyncTileProvider = syncTileProvider;
@@ -194,6 +198,8 @@ public class QSFactoryImpl implements QSFactory {
            // Custom tiles.
            case "adb_network":
                return mAdbOverNetworkTileProvider.get();
            case "ambient_display":
                return mAmbientDisplayTileProvider.get();
            case "caffeine":
                return mCaffeineTileProvider.get();
            case "heads_up":
+133 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The CyanogenMod Project
 * Copyright (C) 2017 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 android.content.Intent;
import android.os.Build;
import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.service.quicksettings.Tile;
import android.text.TextUtils;

import com.android.systemui.plugins.qs.QSTile.BooleanState;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.qs.SecureSetting;
import com.android.systemui.R;

import org.lineageos.internal.logging.LineageMetricsLogger;

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 static final Intent DISPLAY_SETTINGS = new Intent("android.settings.DISPLAY_SETTINGS");

    private final SecureSetting mSetting;

    @Inject
    public AmbientDisplayTile(QSHost host) {
        super(host);

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

    @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
    protected void handleClick() {
        setEnabled(!mState.value);
        refreshState();
    }

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

    private void setEnabled(boolean enabled) {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.DOZE_ENABLED,
                enabled ? 1 : 0);
    }

    @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 LineageMetricsLogger.TILE_AMBIENT_DISPLAY;
    }

    @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);
        }
    }

    @Override
    public void handleSetListening(boolean listening) {
        // Do nothing
    }
}