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

Commit ed090d17 authored by Jason Monk's avatar Jason Monk Committed by Android (Google) Code Review
Browse files

Merge "Add data saver tile"

parents fd7b9469 9a4ce137
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2016 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="24.0dp"
        android:height="24.0dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="
        M9.0,16.0l2.0,0.0L11.0,8.0L9.0,8.0l0.0,8.0z
        m3.0,-14.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0z
        m0.0,18.0c-4.41,0.0 -8.0,-3.59 -8.0,-8.0s3.59,-8.0 8.0,-8.0 8.0,3.59 8.0,8.0 -3.59,8.0 -8.0,8.0z
        m1.0,-4.0l2.0,0.0l0.0,-8.0l-2.0,0.0l0.0,8.0z"/>
</vector>
+28 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2016 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="24.0dp"
        android:height="24.0dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#4DFFFFFF"
        android:pathData="
        M9.0,16.0l2.0,0.0L11.0,8.0L9.0,8.0l0.0,8.0z
        m3.0,-14.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0z
        m0.0,18.0c-4.41,0.0 -8.0,-3.59 -8.0,-8.0s3.59,-8.0 8.0,-8.0 8.0,3.59 8.0,8.0 -3.59,8.0 -8.0,8.0z
        m1.0,-4.0l2.0,0.0l0.0,-8.0l-2.0,0.0l0.0,8.0z"/>
</vector>
+9 −0
Original line number Diff line number Diff line
@@ -1333,4 +1333,13 @@
    <!-- Explanation of the status bar section of the tuner [CHAR LIMIT=NONE] -->
    <string name="tuner_status_bar_explanation">Enable or disable icons from being shown in the status bar.</string>

    <!-- Label for quick settings tile for data saver [CHAR LIMIT=30] -->
    <string name="data_saver">Data Saver</string>

    <!-- Accessibility description for data saver being on [CHAR LIMIT=NONE] -->
    <string name="accessibility_data_saver_on">Data Saver is on</string>

    <!-- Accessibility description for data saver being off [CHAR LIMIT=NONE] -->
    <string name="accessibility_data_saver_off">Data Saver is off</string>

</resources>
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class TileAdapter extends BaseAdapter {
            mCurrentTiles = tileSpecs;
            final TileGroup group = new TileGroup("com.android.settings", mContext);
            String possible = mContext.getString(R.string.quick_settings_tiles_default)
                    + ",user,hotspot,inversion";
                    + ",user,hotspot,inversion,saver";
            String[] possibleTiles = possible.split(",");
            for (int i = 0; i < possibleTiles.length; i++) {
                final String spec = possibleTiles[i];
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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 com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.DataSaverController;

public class DataSaverTile extends QSTile<QSTile.BooleanState> implements
        DataSaverController.Listener{

    private final DataSaverController mDataSaverController;

    public DataSaverTile(Host host) {
        super(host);
        mDataSaverController = host.getNetworkController().getDataSaverController();
    }

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

    @Override
    public void setListening(boolean listening) {
        if (listening) {
            mDataSaverController.addListener(this);
        } else {
            mDataSaverController.remListener(this);
        }
    }

    @Override
    protected void handleClick() {
        mState.value = !mDataSaverController.isDataSaverEnabled();
        mDataSaverController.setDataSaverEnabled(mState.value);
        refreshState(mState.value);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.value = arg instanceof Boolean ? (Boolean) arg
                : mDataSaverController.isDataSaverEnabled();
        state.label = mContext.getString(R.string.data_saver);
        state.contentDescription = mContext.getString(state.value ?
                R.string.accessibility_data_saver_on : R.string.accessibility_data_saver_off);
        state.icon = ResourceIcon.get(state.value ? R.drawable.ic_data_saver
                : R.drawable.ic_data_saver_off);
    }

    @Override
    public int getMetricsCategory() {
        return MetricsEvent.QS_DATA_SAVER;
    }

    @Override
    public void onDataSaverChanged(boolean isDataSaving) {
        refreshState(isDataSaving);
    }
}
 No newline at end of file
Loading