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

Commit 7340a772 authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Merge "Clean up, simplify and fix AlarmTile class and logic" into cm-10.1

parents a7821dff 54639e2e
Loading
Loading
Loading
Loading
+15 −29
Original line number Diff line number Diff line
package com.android.systemui.quicksettings;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

@@ -18,21 +17,14 @@ import com.android.systemui.statusbar.phone.QuickSettingsContainerView;

public class AlarmTile extends QuickSettingsTile {

    private boolean enabled = false;

    public AlarmTile(Context context, LayoutInflater inflater,
            QuickSettingsContainerView container,
            QuickSettingsController qsc, Handler handler) {
        super(context, inflater, container, qsc);

        mDrawable = R.drawable.ic_qs_alarm_on;
        String nextAlarmTime = Settings.System.getString(mContext.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED);
        if(nextAlarmTime != null){
            mLabel = nextAlarmTime;
        }

        mOnClick = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
@@ -42,36 +34,30 @@ public class AlarmTile extends QuickSettingsTile{
                startSettingsActivity(intent);
            }
        };
        qsc.registerAction(Intent.ACTION_ALARM_CHANGED, this);

        qsc.registerObservedContent(Settings.System.getUriFor(
                Settings.System.NEXT_ALARM_FORMATTED), this);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        onAlarmChanged(intent);
        updateStatus();
    }

    @Override
    public void onChangeUri(ContentResolver resolver, Uri uri) {
        onNextAlarmChanged();
        updateStatus();
        updateQuickSettings();
    }

    void onAlarmChanged(Intent intent) {
        enabled = intent.getBooleanExtra("alarmSet", false);
        updateQuickSettings();
    @Override
    public void updateQuickSettings() {
        mTile.setVisibility(!TextUtils.isEmpty(mLabel) ? View.VISIBLE : View.GONE);
        super.updateQuickSettings();
    }

    void onNextAlarmChanged() {
    /**
     * Updates the alarm status shown on the tile.
     */
    private void updateStatus() {
        mLabel = Settings.System.getString(mContext.getContentResolver(),
            Settings.System.NEXT_ALARM_FORMATTED);
        updateQuickSettings();
    }

    @Override
    void updateQuickSettings() {
        mTile.setVisibility(enabled ? View.VISIBLE : View.GONE);
        super.updateQuickSettings();
    }

}