Switch to vibrate (or slash-bell) icon at ringer volume 0.

Bug: 16900054
Change-Id: If94a18a7cac596c0f4c33421b642f96dcf0280fd
This commit is contained in:
Dan Sandler
2014-09-02 01:05:27 +02:00
parent 8007caa43e
commit cb9f35171d
6 changed files with 139 additions and 7 deletions

View File

@@ -0,0 +1,24 @@
<!--
Copyright (C) 2014 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.
-->
<!-- shrink ic_audio_ring_notif from 32dp to 24dp using insets -->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_audio_ring_notif"
android:insetLeft="4dp"
android:insetRight="4dp"
android:insetTop="4dp"
android:insetBottom="4dp"
/>

View File

@@ -0,0 +1,23 @@
<!--
Copyright (C) 2014 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.
-->
<!-- shrink ic_audio_ring_notif_mute from 32dp to 24dp using insets -->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_audio_ring_notif_mute"
android:insetLeft="4dp"
android:insetRight="4dp"
android:insetTop="4dp"
android:insetBottom="4dp"
/>

View File

@@ -0,0 +1,23 @@
<!--
Copyright (C) 2014 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.
-->
<!-- shrink ic_audio_ring_notif_vibrate from 32dp to 24dp using insets -->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_audio_ring_notif_vibrate"
android:insetLeft="4dp"
android:insetRight="4dp"
android:insetTop="4dp"
android:insetBottom="4dp"
/>

View File

@@ -39,13 +39,13 @@
<!-- Ring volume --> <!-- Ring volume -->
<com.android.settings.notification.VolumeSeekBarPreference <com.android.settings.notification.VolumeSeekBarPreference
android:key="ring_volume" android:key="ring_volume"
android:icon="@*android:drawable/ic_audio_ring_notif" android:icon="@drawable/ring_notif"
android:title="@string/ring_volume_option_title" /> android:title="@string/ring_volume_option_title" />
<!-- Notification volume --> <!-- Notification volume -->
<com.android.settings.notification.VolumeSeekBarPreference <com.android.settings.notification.VolumeSeekBarPreference
android:key="notification_volume" android:key="notification_volume"
android:icon="@*android:drawable/ic_audio_ring_notif" android:icon="@drawable/ring_notif"
android:title="@string/notification_volume_option_title" /> android:title="@string/notification_volume_option_title" />
<!-- Also vibrate for calls --> <!-- Also vibrate for calls -->

View File

@@ -30,6 +30,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.Vibrator;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
@@ -40,6 +41,7 @@ import android.provider.SearchIndexableResource;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.widget.SeekBar;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
@@ -76,6 +78,8 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
private Context mContext; private Context mContext;
private PackageManager mPM; private PackageManager mPM;
private boolean mVoiceCapable; private boolean mVoiceCapable;
private Vibrator mVibrator;
private VolumeSeekBarPreference mRingOrNotificationPreference;
private Preference mPhoneRingtonePreference; private Preference mPhoneRingtonePreference;
private Preference mNotificationRingtonePreference; private Preference mNotificationRingtonePreference;
@@ -93,15 +97,23 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
mPM = mContext.getPackageManager(); mPM = mContext.getPackageManager();
mVoiceCapable = Utils.isVoiceCapable(mContext); mVoiceCapable = Utils.isVoiceCapable(mContext);
mSecure = new LockPatternUtils(getActivity()).isSecure(); mSecure = new LockPatternUtils(getActivity()).isSecure();
mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (mVibrator != null && !mVibrator.hasVibrator()) {
mVibrator = null;
}
addPreferencesFromResource(R.xml.notification_settings); addPreferencesFromResource(R.xml.notification_settings);
final PreferenceCategory sound = (PreferenceCategory) findPreference(KEY_SOUND); final PreferenceCategory sound = (PreferenceCategory) findPreference(KEY_SOUND);
initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC); initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC);
initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM); initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM);
if (mVoiceCapable) { if (mVoiceCapable) {
mRingOrNotificationPreference =
initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING); initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING);
sound.removePreference(sound.findPreference(KEY_NOTIFICATION_VOLUME)); sound.removePreference(sound.findPreference(KEY_NOTIFICATION_VOLUME));
} else { } else {
mRingOrNotificationPreference =
initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION); initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION);
sound.removePreference(sound.findPreference(KEY_RING_VOLUME)); sound.removePreference(sound.findPreference(KEY_RING_VOLUME));
} }
@@ -134,10 +146,19 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
// === Volumes === // === Volumes ===
private void initVolumePreference(String key, int stream) { private VolumeSeekBarPreference initVolumePreference(String key, int stream) {
final VolumeSeekBarPreference volumePref = (VolumeSeekBarPreference) findPreference(key); final VolumeSeekBarPreference volumePref = (VolumeSeekBarPreference) findPreference(key);
volumePref.setStream(stream);
volumePref.setCallback(mVolumeCallback); volumePref.setCallback(mVolumeCallback);
volumePref.setStream(stream);
return volumePref;
}
private void updateRingOrNotificationIcon(int progress) {
mRingOrNotificationPreference.showIcon(progress > 0
? R.drawable.ring_notif
: (mVibrator == null
? R.drawable.ring_notif_mute
: R.drawable.ring_notif_vibrate));
} }
private final class VolumePreferenceCallback implements VolumeSeekBarPreference.Callback { private final class VolumePreferenceCallback implements VolumeSeekBarPreference.Callback {
@@ -155,6 +176,14 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
} }
} }
@Override
public void onStreamValueChanged(int stream, int progress) {
if (stream == AudioManager.STREAM_RING) {
mHandler.removeMessages(H.UPDATE_RINGER_ICON);
mHandler.obtainMessage(H.UPDATE_RINGER_ICON, progress, 0).sendToTarget();
}
}
public void stopSample() { public void stopSample() {
if (mCurrent != null) { if (mCurrent != null) {
mCurrent.stopSample(); mCurrent.stopSample();
@@ -426,6 +455,7 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
private static final int UPDATE_PHONE_RINGTONE = 1; private static final int UPDATE_PHONE_RINGTONE = 1;
private static final int UPDATE_NOTIFICATION_RINGTONE = 2; private static final int UPDATE_NOTIFICATION_RINGTONE = 2;
private static final int STOP_SAMPLE = 3; private static final int STOP_SAMPLE = 3;
private static final int UPDATE_RINGER_ICON = 4;
private H() { private H() {
super(Looper.getMainLooper()); super(Looper.getMainLooper());
@@ -443,6 +473,9 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
case STOP_SAMPLE: case STOP_SAMPLE:
mVolumeCallback.stopSample(); mVolumeCallback.stopSample();
break; break;
case UPDATE_RINGER_ICON:
updateRingOrNotificationIcon(msg.arg1);
break;
} }
} }
} }

View File

@@ -26,6 +26,7 @@ import android.preference.SeekBarVolumizer;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar; import android.widget.SeekBar;
import com.android.settings.R; import com.android.settings.R;
@@ -39,6 +40,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference
private SeekBar mSeekBar; private SeekBar mSeekBar;
private SeekBarVolumizer mVolumizer; private SeekBarVolumizer mVolumizer;
private Callback mCallback; private Callback mCallback;
private ImageView mIconView;
public VolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, public VolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) { int defStyleRes) {
@@ -93,9 +95,35 @@ public class VolumeSeekBarPreference extends SeekBarPreference
}; };
final Uri sampleUri = mStream == AudioManager.STREAM_MUSIC ? getMediaVolumeUri() : null; final Uri sampleUri = mStream == AudioManager.STREAM_MUSIC ? getMediaVolumeUri() : null;
if (mVolumizer == null) { if (mVolumizer == null) {
mVolumizer = new SeekBarVolumizer(getContext(), mStream, sampleUri, sbvc); mVolumizer = new SeekBarVolumizer(getContext(), mStream, sampleUri, sbvc) {
// we need to piggyback on SBV's SeekBar listener to update our icon
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromTouch) {
super.onProgressChanged(seekBar, progress, fromTouch);
mCallback.onStreamValueChanged(mStream, progress);
}
};
} }
mVolumizer.setSeekBar(mSeekBar); mVolumizer.setSeekBar(mSeekBar);
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
mCallback.onStreamValueChanged(mStream, mSeekBar.getProgress());
}
// during initialization, this preference is the SeekBar listener
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromTouch) {
super.onProgressChanged(seekBar, progress, fromTouch);
mCallback.onStreamValueChanged(mStream, progress);
}
public void showIcon(int resId) {
// Instead of using setIcon, which will trigger listeners, this just decorates the
// preference temporarily with a new icon.
if (mIconView != null) {
mIconView.setImageResource(resId);
}
} }
private Uri getMediaVolumeUri() { private Uri getMediaVolumeUri() {
@@ -106,5 +134,6 @@ public class VolumeSeekBarPreference extends SeekBarPreference
public interface Callback { public interface Callback {
void onSampleStarting(SeekBarVolumizer sbv); void onSampleStarting(SeekBarVolumizer sbv);
void onStreamValueChanged(int stream, int progress);
} }
} }