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

Commit 3abc5b00 authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Do not disturb."

parents e26092e2 2039e484
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.statusbar;

import android.app.StatusBarManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;

import com.android.systemui.statusbar.policy.Prefs;

public class DoNotDisturb implements SharedPreferences.OnSharedPreferenceChangeListener {
    private Context mContext;
    private StatusBarManager mStatusBar;
    SharedPreferences mPrefs;
    private boolean mDoNotDisturb;

    public DoNotDisturb(Context context) {
        mContext = context;
        mStatusBar = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
        mPrefs = Prefs.read(context);
        mPrefs.registerOnSharedPreferenceChangeListener(this);
        mDoNotDisturb = mPrefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);
        updateDisableRecord();
    }

    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        final boolean val = prefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF,
                Prefs.DO_NOT_DISTURB_DEFAULT);
        if (val != mDoNotDisturb) {
            mDoNotDisturb = val;
            updateDisableRecord();
        }
    }

    private void updateDisableRecord() {
        final int disabled = StatusBarManager.DISABLE_NOTIFICATION_ICONS
                | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
                | StatusBarManager.DISABLE_NOTIFICATION_TICKER;
        mStatusBar.disable(mDoNotDisturb ? disabled : 0);
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public abstract class StatusBar extends SystemUI implements CommandQueue.Callbac
    protected abstract View makeStatusBarView();
    protected abstract int getStatusBarGravity();

    private DoNotDisturb mDoNotDisturb;

    public void start() {
        // First set up our views and stuff.
        View sb = makeStatusBarView();
@@ -127,5 +129,7 @@ public abstract class StatusBar extends SystemUI implements CommandQueue.Callbac
                   + " imeButton=" + switches[3]
                   );
        }

        mDoNotDisturb = new DoNotDisturb(mContext);
    }
}
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.statusbar.policy;

import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Slog;
import android.view.IWindowManager;
import android.widget.CompoundButton;

public class DoNotDisturbController implements CompoundButton.OnCheckedChangeListener,
        SharedPreferences.OnSharedPreferenceChangeListener {
    private static final String TAG = "StatusBar.DoNotDisturbController";

    SharedPreferences mPrefs;
    private Context mContext;
    private CompoundButton mCheckBox;

    private boolean mDoNotDisturb;

    public DoNotDisturbController(Context context, CompoundButton checkbox) {
        mContext = context;

        mPrefs = Prefs.read(context);
        mPrefs.registerOnSharedPreferenceChangeListener(this);
        mDoNotDisturb = mPrefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);

        mCheckBox = checkbox;
        checkbox.setOnCheckedChangeListener(this);

        checkbox.setChecked(!mDoNotDisturb);
    }

    // The checkbox is ON for notifications coming in and OFF for Do not disturb, so we
    // don't have a double negative.
    public void onCheckedChanged(CompoundButton view, boolean checked) {
        //Slog.d(TAG, "onCheckedChanged checked=" + checked + " mDoNotDisturb=" + mDoNotDisturb);
        final boolean value = !checked;
        if (value != mDoNotDisturb) {
            SharedPreferences.Editor editor = Prefs.edit(mContext);
            editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, value);
            editor.apply();
        }
    }
    
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        final boolean val = prefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF,
                Prefs.DO_NOT_DISTURB_DEFAULT);
        if (val != mDoNotDisturb) {
            mDoNotDisturb = val;
            mCheckBox.setChecked(!val);
        }
    }

    public void release() {
        mPrefs.unregisterOnSharedPreferenceChangeListener(this);
    }
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.statusbar.policy;

import android.content.Context;
import android.content.SharedPreferences;

public class Prefs {
    private static final String SHARED_PREFS_NAME = "status_bar";

    // a boolean
    public static final String DO_NOT_DISTURB_PREF = "do_not_disturb";
    public static final boolean DO_NOT_DISTURB_DEFAULT = false;

    public static SharedPreferences read(Context context) {
        return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
    }

    public static SharedPreferences.Editor edit(Context context) {
        return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE).edit();
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -31,12 +31,14 @@ import android.widget.TextView;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.AirplaneModeController;
import com.android.systemui.statusbar.policy.AutoRotateController;
import com.android.systemui.statusbar.policy.DoNotDisturbController;

public class SettingsView extends LinearLayout implements View.OnClickListener {
    static final String TAG = "SettingsView";

    AirplaneModeController mAirplane;
    AutoRotateController mRotate;
    DoNotDisturbController mDoNotDisturb;

    public SettingsView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
@@ -57,6 +59,8 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
        findViewById(R.id.network).setOnClickListener(this);
        mRotate = new AutoRotateController(context,
                (CompoundButton)findViewById(R.id.rotate_checkbox));
        mDoNotDisturb = new DoNotDisturbController(context,
                (CompoundButton)findViewById(R.id.do_not_disturb_checkbox));
        findViewById(R.id.settings).setOnClickListener(this);
    }

@@ -64,6 +68,7 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mAirplane.release();
        mDoNotDisturb.release();
    }

    public void onClick(View v) {
Loading