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

Commit f15ce7a7 authored by Michael Bestas's avatar Michael Bestas Committed by Michael Bestas
Browse files

SystemUI: Add battery saver tile (1/2)

* To be displayed on devices without perf profiles

Change-Id: Iff6920a0bb78e36e44590c1db880afcdcc6f78b3
parent a7e5f923
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (c) 2015 The CyanogenMod 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="24"
    android:viewportHeight="24">

    <path
        android:fillColor="#4DFFFFFF"
        android:pathData="M16.67,4H15V2H9V4H7.33A1.33,1.33 0 0,0 6,5.33V20.67C6,21.4 6.6,22 7.33,22H16.67A1.33,1.33 0 0,0 18,20.67V5.33C18,4.6 17.4,4 16.67,4Z" />
</vector>
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (c) 2015 The CyanogenMod 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="24"
    android:viewportHeight="24">

    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M16.67,4C17.4,4 18,4.6 18,5.33V20.67A1.33,1.33 0 0,1 16.67,22H7.33C6.6,22 6,21.4 6,20.67V5.33A1.33,1.33 0 0,1 7.33,4H9V2H15V4H16.67M16,14V12H13V9H11V12H8V14H11V17H13V14H16Z" />
</vector>
+11 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@
    <string name="quick_settings_profiles">System profiles</string>
    <string name="quick_settings_profiles_off">Profiles disabled</string>
    <string name="quick_settings_heads_up_label">Heads up</string>
    <string name="quick_settings_battery_saver_label">Battery saver</string>

    <!-- Content description of the sync tile in quick settings when off (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_sync_off">Sync off.</string>
@@ -179,6 +180,16 @@
    <!-- Announcement made when heads up changes to on (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_heads_up_changed_on">Heads up turned on.</string>

    <!-- Content description of the battery saver tile in quick settings when off (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_battery_saver_off">Battery saver off.</string>
    <!-- Content description of the battery saver tile in quick settings when on (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_battery_saver_on">Battery saver on.</string>

    <!-- Announcement made when battery saver changes to off (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_battery_saver_changed_off">Battery saver turned off.</string>
    <!-- Announcement made when battery saver changes to on (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_battery_saver_changed_on">Battery saver turned on.</string>

    <!-- Dynamic tiles -->
    <string name="quick_settings_dynamic_tile_detail_title">Dynamic tile</string>
    <string name="dynamic_qs_tile_next_alarm_label">Next alarm</string>
+116 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The CyanogenMod 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.database.ContentObserver;
import android.net.Uri;
import android.os.PowerManager;
import android.provider.Settings;

import com.android.systemui.qs.QSTile;
import com.android.systemui.R;

import cyanogenmod.power.PerformanceManager;

import org.cyanogenmod.internal.logging.CMMetricsLogger;

/** Quick settings tile: Battery saver **/
public class BatterySaverTile extends QSTile<QSTile.BooleanState> {

    private static final Intent BATTERY_SETTINGS = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);

    private final PowerManager mPm;
    private final PerformanceManager mPerformanceManager;
    private boolean mListening;

    public BatterySaverTile(Host host) {
        super(host);
        mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mPerformanceManager = PerformanceManager.getInstance(mContext);
    }

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

    @Override
    public void handleClick() {
        mPm.setPowerSaveMode(!mState.value);
        refreshState();
    }

    @Override
    public void handleLongClick() {
        mHost.startActivityDismissingKeyguard(BATTERY_SETTINGS);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.value = mPm.isPowerSaveMode();
        state.visible = mPerformanceManager.getNumberOfProfiles() == 0;
        state.label = mContext.getString(R.string.quick_settings_battery_saver_label);
        if (state.value) {
            state.icon = ResourceIcon.get(R.drawable.ic_qs_battery_saver_on);
            state.contentDescription =  mContext.getString(
                    R.string.accessibility_quick_settings_battery_saver_on);
        } else {
            state.icon = ResourceIcon.get(R.drawable.ic_qs_battery_saver_off);
            state.contentDescription =  mContext.getString(
                    R.string.accessibility_quick_settings_battery_saver_off);
        }
    }

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

    @Override
    public int getMetricsCategory() {
        return CMMetricsLogger.TILE_BATTERY_SAVER;
    }

    private ContentObserver mObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            refreshState();
        }
    };

    @Override
    public void setListening(boolean listening) {
        if (mListening == listening) return;
        mListening = listening;

        if (listening) {
            mContext.getContentResolver().registerContentObserver(
                    Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE),
                    false, mObserver);
        } else {
            mContext.getContentResolver().unregisterContentObserver(mObserver);
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.systemui.qs.QSTile;
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.CastTile;
import com.android.systemui.qs.tiles.CellularTile;
@@ -361,6 +362,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
        else if (tileSpec.equals("ambient_display")) return new AmbientDisplayTile(this);
        else if (tileSpec.equals("live_display")) return new LiveDisplayTile(this);
        else if (tileSpec.equals("heads_up")) return new HeadsUpTile(this);
        else if (tileSpec.equals("battery_saver")) return new BatterySaverTile(this);
        else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
        else throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
    }
@@ -448,6 +450,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
        else if (spec.equals("ambient_display")) return R.string.quick_settings_ambient_display_label;
        else if (spec.equals("live_display")) return R.string.live_display_title;
        else if (spec.equals("heads_up")) return R.string.quick_settings_heads_up_label;
        else if (spec.equals("battery_saver")) return R.string.quick_settings_battery_saver_label;
        return 0;
    }

@@ -477,6 +480,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
        else if (spec.equals("ambient_display")) return R.drawable.ic_qs_ambientdisplay_on;
        else if (spec.equals("live_display")) return R.drawable.ic_livedisplay_auto;
        else if (spec.equals("heads_up")) return R.drawable.ic_qs_heads_up_on;
        else if (spec.equals("heads_up")) return R.drawable.ic_qs_battery_saver_on;
        return 0;
    }