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

Commit 5960e54c authored by Arian's avatar Arian Committed by Łukasz Patron
Browse files

SystemUI: Add anti flicker tile

Change-Id: If2b23b509ff7f8c56abe427d8c35d27c453bd224
parent 21a64f30
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (c) 2020 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="64dp"
    android:width="64dp"
    android:viewportWidth="24"
    android:viewportHeight="24">

    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M23.5,17L18.5,22L15,18.5L16.5,17L18.5,19L22,15.5L23.5,17M12,9A3,3 0 0,1 15,12A3,3 0 0,1 12,15A3,3 0 0,1 9,12A3,3 0 0,1 12,9M12,4.5C17,4.5 21.27,7.61 23,12C22.75,12.65 22.44,13.26 22.08,13.85C21.5,13.5 20.86,13.25 20.18,13.12L20.82,12C19.17,8.64 15.76,6.5 12,6.5C8.24,6.5 4.83,8.64 3.18,12C4.83,15.36 8.24,17.5 12,17.5L13.21,17.43C13.07,17.93 13,18.46 13,19V19.46L12,19.5C7,19.5 2.73,16.39 1,12C2.73,7.61 7,4.5 12,4.5Z" />
</vector>
+3 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@
    <string name="vpn_credentials_password">Password</string>
    <string name="vpn_credentials_dialog_connect">Connect</string>

    <!-- Anti flicker QS tile -->
    <string name="quick_settings_anti_flicker">Anti flicker</string>

    <!-- Navigation bar dpad -->
    <string name="accessibility_dpad_left">Cursor left</string>
    <string name="accessibility_dpad_right">Cursor right</string>
+1 −1
Original line number Diff line number Diff line
@@ -114,7 +114,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,screenrecord,reverse,ambient_display,aod,caffeine,heads_up,livedisplay,powershare,profiles,reading_mode,sync,usb_tether,volume_panel,vpn
        wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,nfc,location,hotspot,inversion,saver,dark,work,cast,night,screenrecord,reverse,ambient_display,aod,caffeine,heads_up,livedisplay,powershare,profiles,reading_mode,sync,usb_tether,volume_panel,vpn,anti_flicker
    </string>

    <!-- The tiles to display in QuickSettings -->
+7 −1
Original line number Diff line number Diff line
@@ -29,6 +29,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.AmbientDisplayTile;
import com.android.systemui.qs.tiles.AntiFlickerTile;
import com.android.systemui.qs.tiles.AODTile;
import com.android.systemui.qs.tiles.BatterySaverTile;
import com.android.systemui.qs.tiles.BluetoothTile;
@@ -103,6 +104,7 @@ public class QSFactoryImpl implements QSFactory {
    private final Provider<UsbTetherTile> mUsbTetherTileProvider;
    private final Provider<VolumeTile> mVolumeTileProvider;
    private final Provider<VpnTile> mVpnTileProvider;
    private final Provider<AntiFlickerTile> mAntiFlickerTileProvider;

    private final Lazy<QSHost> mQsHostLazy;

@@ -139,7 +141,8 @@ public class QSFactoryImpl implements QSFactory {
            Provider<SyncTile> syncTileProvider,
            Provider<UsbTetherTile> usbTetherTileProvider,
            Provider<VolumeTile> volumeTileProvider,
            Provider<VpnTile> vpnTileProvider) {
            Provider<VpnTile> vpnTileProvider,
            Provider<AntiFlickerTile> antiFlickerTileProvider) {
        mQsHostLazy = qsHostLazy;
        mWifiTileProvider = wifiTileProvider;
        mBluetoothTileProvider = bluetoothTileProvider;
@@ -173,6 +176,7 @@ public class QSFactoryImpl implements QSFactory {
        mUsbTetherTileProvider = usbTetherTileProvider;
        mVolumeTileProvider = volumeTileProvider;
        mVpnTileProvider = vpnTileProvider;
        mAntiFlickerTileProvider = antiFlickerTileProvider;
    }

    public QSTile createTile(String tileSpec) {
@@ -249,6 +253,8 @@ public class QSFactoryImpl implements QSFactory {
                return mVolumeTileProvider.get();
            case "vpn":
                return mVpnTileProvider.get();
            case "anti_flicker":
                return mAntiFlickerTileProvider.get();
        }

        // Custom tiles
+139 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020-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 lineageos.hardware.LiveDisplayManager.FEATURE_ANTI_FLICKER;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.service.quicksettings.Tile;

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.R;

import org.lineageos.internal.logging.LineageMetricsLogger;

import lineageos.hardware.LiveDisplayManager;
import lineageos.providers.LineageSettings;

import javax.inject.Inject;

public class AntiFlickerTile extends QSTileImpl<BooleanState> {
    private boolean mAntiFlickerEnabled = true;
    private boolean mReceiverRegistered;

    private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_anti_flicker);

    private static final Intent DISPLAY_SETTINGS = new Intent("android.settings.DISPLAY_SETTINGS");

    private final LiveDisplayManager mLiveDisplay;

    @Inject
    public AntiFlickerTile(QSHost host) {
        super(host);
        mLiveDisplay = LiveDisplayManager.getInstance(mContext);
        if (!updateConfig()) {
            mContext.registerReceiver(mReceiver,
                    new IntentFilter(lineageos.content.Intent.ACTION_INITIALIZE_LIVEDISPLAY));
            mReceiverRegistered = true;
        }
    }

    @Override
    protected void handleDestroy() {
        super.handleDestroy();
        unregisterReceiver();
    }

    private void unregisterReceiver() {
        if (mReceiverRegistered) {
            mContext.unregisterReceiver(mReceiver);
            mReceiverRegistered = false;
        }
    }

    private boolean updateConfig() {
        if (mLiveDisplay.getConfig() != null) {
            mAntiFlickerEnabled = mLiveDisplay.getConfig().hasFeature(FEATURE_ANTI_FLICKER);
            if (!isAvailable()) {
                mHost.removeTile(getTileSpec());
            }
            return true;
        }
        return false;
    }

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

    @Override
    protected void handleClick() {
        setEnabled(!mLiveDisplay.isAntiFlickerEnabled());
        refreshState();
    }

    private void setEnabled(boolean enabled) {
        LineageSettings.System.putInt(mContext.getContentResolver(),
                LineageSettings.System.DISPLAY_ANTI_FLICKER, enabled ? 1 : 0);
    }

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

    @Override
    public boolean isAvailable() {
        return mAntiFlickerEnabled;
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.value = mLiveDisplay.isAntiFlickerEnabled();
        state.icon = mIcon;
        state.contentDescription = mContext.getString(R.string.quick_settings_anti_flicker);
        state.state = (state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
        state.label = getTileLabel();
    }

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

    @Override
    public int getMetricsCategory() {
        return LineageMetricsLogger.TILE_ANTI_FLICKER;
    }

    @Override
    public void handleSetListening(boolean listening) {}

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateConfig();
            unregisterReceiver();
        }
    };
}