Merge "Add "device is muted/vibrate, click to turn on" conditions" into pi-dev am: 0a5367c0c4
am: 543bd80a90
Change-Id: Ia404aa2faf697ffc42e29d55600d75f680598508
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.settings.dashboard.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public abstract class AbnormalRingerConditionBase extends Condition {
|
||||
|
||||
private final IntentFilter mFilter;
|
||||
|
||||
protected final AudioManager mAudioManager;
|
||||
|
||||
private final RingerModeChangeReceiver mReceiver;
|
||||
|
||||
AbnormalRingerConditionBase(ConditionManager manager) {
|
||||
super(manager);
|
||||
mAudioManager =
|
||||
(AudioManager) mManager.getContext().getSystemService(Context.AUDIO_SERVICE);
|
||||
mReceiver = new RingerModeChangeReceiver(this);
|
||||
|
||||
mFilter = new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
||||
manager.getContext().registerReceiver(mReceiver, mFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {
|
||||
mManager.getContext().getText(R.string.condition_device_muted_action_turn_on_sound)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
mManager.getContext().startActivity(
|
||||
new Intent(Settings.ACTION_SOUND_SETTINGS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 1, 0 /* flags */);
|
||||
refreshState();
|
||||
}
|
||||
|
||||
static class RingerModeChangeReceiver extends BroadcastReceiver {
|
||||
|
||||
private final AbnormalRingerConditionBase mCondition;
|
||||
|
||||
public RingerModeChangeReceiver(AbnormalRingerConditionBase condition) {
|
||||
mCondition = condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
||||
mCondition.refreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,7 +20,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
@@ -24,6 +24,7 @@ import android.util.Xml;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
@@ -153,6 +154,8 @@ public class ConditionManager implements LifecycleObserver, OnResume, OnPause {
|
||||
addIfMissing(BackgroundDataCondition.class, conditions);
|
||||
addIfMissing(WorkModeCondition.class, conditions);
|
||||
addIfMissing(NightDisplayCondition.class, conditions);
|
||||
addIfMissing(RingerMutedCondition.class, conditions);
|
||||
addIfMissing(RingerVibrateCondition.class, conditions);
|
||||
Collections.sort(conditions, CONDITION_COMPARATOR);
|
||||
}
|
||||
|
||||
@@ -183,6 +186,10 @@ public class ConditionManager implements LifecycleObserver, OnResume, OnPause {
|
||||
return new WorkModeCondition(this);
|
||||
} else if (NightDisplayCondition.class == clz) {
|
||||
return new NightDisplayCondition(this);
|
||||
} else if (RingerMutedCondition.class == clz) {
|
||||
return new RingerMutedCondition(this);
|
||||
} else if (RingerVibrateCondition.class == clz) {
|
||||
return new RingerVibrateCondition(this);
|
||||
}
|
||||
Log.e(TAG, "unknown condition class: " + clz.getSimpleName());
|
||||
return null;
|
||||
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.settings.dashboard.conditional;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RingerMutedCondition extends AbnormalRingerConditionBase {
|
||||
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
RingerMutedCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mNotificationManager = mManager.getContext().getSystemService(NotificationManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
int zen = mNotificationManager.getZenMode();
|
||||
boolean zenModeEnabled = zen != Settings.Global.ZEN_MODE_OFF;
|
||||
boolean isSilent = mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
|
||||
setActive(isSilent && !zenModeEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_MUTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_volume_ringer_mute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getText(R.string.condition_device_muted_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getText(R.string.condition_device_muted_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.settings.dashboard.conditional;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RingerVibrateCondition extends AbnormalRingerConditionBase {
|
||||
|
||||
RingerVibrateCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
setActive(mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_VIBRATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_volume_ringer_vibrate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getText(R.string.condition_device_vibrate_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getText(R.string.condition_device_vibrate_summary);
|
||||
}
|
||||
}
|
@@ -22,16 +22,14 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Vibrator;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -99,7 +97,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
|
||||
@Override
|
||||
public int getMuteIcon() {
|
||||
return com.android.internal.R.drawable.ic_audio_ring_notif_mute;
|
||||
return R.drawable.ic_volume_ringer_vibrate;
|
||||
}
|
||||
|
||||
private void updateRingerMode() {
|
||||
|
Reference in New Issue
Block a user