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

Commit 2f74f16b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add alarm tile to QS."

parents 73f2270b 4bd8e05c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,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,location,hotspot,inversion,saver,work,cast,night
        wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,work,cast,night,alarm
    </string>

    <!-- The tiles to display in QuickSettings -->
+2 −0
Original line number Diff line number Diff line
@@ -739,6 +739,8 @@
    <string name="quick_settings_wifi_on_label">Wi-Fi On</string>
    <!-- QuickSettings: Wifi detail panel, text when there are no items [CHAR LIMIT=NONE] -->
    <string name="quick_settings_wifi_detail_empty_text">No Wi-Fi networks available</string>
    <!-- QuickSettings: Alarm title [CHAR LIMIT=NONE] -->
    <string name="quick_settings_alarm_title">Alarm</string>
    <!-- QuickSettings: Cast title [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cast_title">Cast</string>
    <!-- QuickSettings: Cast detail panel, status text when casting [CHAR LIMIT=NONE] -->
+2 −1
Original line number Diff line number Diff line
@@ -51,10 +51,11 @@ public class AutoAddTracker {
    public AutoAddTracker(Context context) {
        mContext = context;
        mAutoAdded = new ArraySet<>(getAdded());
        // TODO: remove migration code and shared preferences keys after P release
        for (String[] convertPref : CONVERT_PREFS) {
            if (Prefs.getBoolean(context, convertPref[0], false)) {
                setTileAdded(convertPref[1]);
                Prefs.putBoolean(context, convertPref[0], false);
                Prefs.remove(context, convertPref[0]);
            }
        }
        mContext.getContentResolver().registerContentObserver(
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.plugins.qs.*;
import com.android.systemui.plugins.qs.QSTileView;
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.BatterySaverTile;
import com.android.systemui.qs.tiles.BluetoothTile;
import com.android.systemui.qs.tiles.CastTile;
@@ -69,6 +70,7 @@ public class QSFactoryImpl implements QSFactory {
        else if (tileSpec.equals("saver")) return new DataSaverTile(mHost);
        else if (tileSpec.equals("night")) return new NightDisplayTile(mHost);
        else if (tileSpec.equals("nfc")) return new NfcTile(mHost);
        else if (tileSpec.equals("alarm")) return new AlarmTile(mHost);
        // Intent tiles.
        else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(mHost, tileSpec);
        else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(mHost, tileSpec);
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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 static android.service.quicksettings.Tile.STATE_ACTIVE;
import static android.service.quicksettings.Tile.STATE_UNAVAILABLE;

import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.QS_ALARM;
import static com.android.systemui.keyguard.KeyguardSliceProvider.formatNextAlarm;

import android.app.AlarmManager.AlarmClockInfo;
import android.app.PendingIntent;
import android.content.Intent;
import android.provider.AlarmClock;

import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.qs.QSTileHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.policy.NextAlarmController;
import com.android.systemui.statusbar.policy.NextAlarmController.NextAlarmChangeCallback;

public class AlarmTile extends QSTileImpl implements NextAlarmChangeCallback {
    private final NextAlarmController mController;
    private String mNextAlarm;
    private PendingIntent mIntent;

    public AlarmTile(QSTileHost host) {
        super(host);
        mController = Dependency.get(NextAlarmController.class);
    }

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

    @Override
    protected void handleClick() {
        if (mIntent != null) {
            Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(mIntent);
        }
    }

    @Override
    protected void handleUpdateState(State state, Object arg) {
        state.state = mNextAlarm != null ? STATE_ACTIVE : STATE_UNAVAILABLE;
        state.label = getTileLabel();
        state.secondaryLabel = mNextAlarm;
        state.icon = ResourceIcon.get(R.drawable.stat_sys_alarm);
        ((BooleanState) state).value = mNextAlarm != null;
    }

    @Override
    public void onNextAlarmChanged(AlarmClockInfo nextAlarm) {
        if (nextAlarm != null) {
            mNextAlarm = formatNextAlarm(mContext, nextAlarm);
            mIntent = nextAlarm.getShowIntent();
        } else {
            mNextAlarm = null;
            mIntent = null;
        }
        refreshState();
    }

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

    @Override
    public Intent getLongClickIntent() {
        return new Intent(AlarmClock.ACTION_SET_ALARM);
    }

    @Override
    protected void handleSetListening(boolean listening) {
        if (listening) {
            mController.addCallback(this);
        } else {
            mController.removeCallback(this);
        }
    }

    @Override
    public CharSequence getTileLabel() {
        return mContext.getString(R.string.status_bar_alarm);
    }
}
 No newline at end of file
Loading