private PackageManager mPM;
private boolean mVoiceCapable;
private Vibrator mVibrator;
+ private AudioManager mAudioManager;
private VolumeSeekBarPreference mRingOrNotificationPreference;
private Preference mPhoneRingtonePreference;
private boolean mSecure;
private int mLockscreenSelectedValue;
private ComponentName mSuppressor;
- private int mRingOrNotificationProgress;
+ private int mRingerMode = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
mVoiceCapable = Utils.isVoiceCapable(mContext);
mSecure = new LockPatternUtils(getActivity()).isSecure();
+ mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (mVibrator != null && !mVibrator.hasVibrator()) {
mVibrator = null;
addPreferencesFromResource(R.xml.notification_settings);
final PreferenceCategory sound = (PreferenceCategory) findPreference(KEY_SOUND);
- initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC);
- initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM);
+ initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC,
+ com.android.internal.R.drawable.ic_audio_vol_mute);
+ initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM,
+ com.android.internal.R.drawable.ic_audio_alarm_mute);
if (mVoiceCapable) {
mRingOrNotificationPreference =
- initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING);
+ initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING,
+ com.android.internal.R.drawable.ic_audio_ring_notif_mute);
sound.removePreference(sound.findPreference(KEY_NOTIFICATION_VOLUME));
} else {
mRingOrNotificationPreference =
- initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION);
+ initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION,
+ com.android.internal.R.drawable.ic_audio_ring_notif_mute);
sound.removePreference(sound.findPreference(KEY_RING_VOLUME));
}
initRingtones(sound);
mNotificationAccess = findPreference(KEY_NOTIFICATION_ACCESS);
refreshNotificationListeners();
+ updateRingerMode();
updateEffectsSuppressor();
}
lookupRingtoneNames();
mSettingsObserver.register(true);
mReceiver.register(true);
+ updateRingOrNotificationPreference();
updateEffectsSuppressor();
for (VolumeSeekBarPreference volumePref : mVolumePrefs) {
volumePref.onActivityResume();
}
// === Volumes ===
- private VolumeSeekBarPreference initVolumePreference(String key, int stream) {
+
+ private VolumeSeekBarPreference initVolumePreference(String key, int stream, int muteIcon) {
final VolumeSeekBarPreference volumePref = (VolumeSeekBarPreference) findPreference(key);
volumePref.setCallback(mVolumeCallback);
volumePref.setStream(stream);
mVolumePrefs.add(volumePref);
+ volumePref.setMuteIcon(muteIcon);
return volumePref;
}
- private void updateRingOrNotificationIcon() {
+ private void updateRingOrNotificationPreference() {
mRingOrNotificationPreference.showIcon(mSuppressor != null
? com.android.internal.R.drawable.ic_audio_ring_notif_mute
- : mRingOrNotificationProgress > 0
- ? com.android.internal.R.drawable.ic_audio_ring_notif
- : (mVibrator == null
- ? com.android.internal.R.drawable.ic_audio_ring_notif_mute
- : com.android.internal.R.drawable.ic_audio_ring_notif_vibrate));
+ : mRingerMode == AudioManager.RINGER_MODE_VIBRATE
+ ? com.android.internal.R.drawable.ic_audio_ring_notif_vibrate
+ : com.android.internal.R.drawable.ic_audio_ring_notif);
+ }
+
+ private void updateRingerMode() {
+ final int ringerMode = mAudioManager.getRingerModeInternal();
+ if (mRingerMode == ringerMode) return;
+ mRingerMode = ringerMode;
+ updateRingOrNotificationPreference();
}
private void updateEffectsSuppressor() {
getSuppressorCaption(suppressor)) : null;
mRingOrNotificationPreference.setSuppressionText(text);
}
- updateRingOrNotificationIcon();
+ updateRingOrNotificationPreference();
}
private String getSuppressorCaption(ComponentName suppressor) {
@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();
- }
+ // noop
}
public void stopSample() {
private static final int UPDATE_PHONE_RINGTONE = 1;
private static final int UPDATE_NOTIFICATION_RINGTONE = 2;
private static final int STOP_SAMPLE = 3;
- private static final int UPDATE_RINGER_ICON = 4;
- private static final int UPDATE_EFFECTS_SUPPRESSOR = 5;
+ private static final int UPDATE_EFFECTS_SUPPRESSOR = 4;
+ private static final int UPDATE_RINGER_MODE = 5;
private H() {
super(Looper.getMainLooper());
case STOP_SAMPLE:
mVolumeCallback.stopSample();
break;
- case UPDATE_RINGER_ICON:
- mRingOrNotificationProgress = msg.arg1;
- updateRingOrNotificationIcon();
- break;
case UPDATE_EFFECTS_SUPPRESSOR:
updateEffectsSuppressor();
break;
+ case UPDATE_RINGER_MODE:
+ updateRingerMode();
+ break;
}
}
}
public void register(boolean register) {
if (mRegistered == register) return;
if (register) {
- mContext.registerReceiver(this,
- new IntentFilter(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED));
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
+ filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
+ mContext.registerReceiver(this, filter);
} else {
mContext.unregisterReceiver(this);
}
@Override
public void onReceive(Context context, Intent intent) {
- mHandler.sendEmptyMessage(H.UPDATE_EFFECTS_SUPPRESSOR);
+ final String action = intent.getAction();
+ if (NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED.equals(action)) {
+ mHandler.sendEmptyMessage(H.UPDATE_EFFECTS_SUPPRESSOR);
+ } else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
+ mHandler.sendEmptyMessage(H.UPDATE_RINGER_MODE);
+ }
}
}
private ImageView mIconView;
private TextView mSuppressionTextView;
private String mSuppressionText;
+ private boolean mMuted;
+ private int mIconResId;
+ private int mMuteIconResId;
public VolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
mCallback.onSampleStarting(sbv);
}
}
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
+ if (mCallback != null) {
+ mCallback.onStreamValueChanged(mStream, progress);
+ }
+ }
+ @Override
+ public void onMuted(boolean muted) {
+ if (mMuted == muted) return;
+ mMuted = muted;
+ updateIconView();
+ }
};
final Uri sampleUri = mStream == AudioManager.STREAM_MUSIC ? getMediaVolumeUri() : null;
if (mVolumizer == null) {
- 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 = new SeekBarVolumizer(getContext(), mStream, sampleUri, sbvc);
}
mVolumizer.start();
mVolumizer.setSeekBar(mSeekBar);
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
+ updateIconView();
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
mCallback.onStreamValueChanged(mStream, mSeekBar.getProgress());
updateSuppressionText();
mCallback.onStreamValueChanged(mStream, progress);
}
+ private void updateIconView() {
+ if (mIconView == null) return;
+ if (mIconResId != 0) {
+ mIconView.setImageResource(mIconResId);
+ } else if (mMuteIconResId != 0 && mMuted) {
+ mIconView.setImageResource(mMuteIconResId);
+ } else {
+ mIconView.setImageDrawable(getIcon());
+ }
+ }
+
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);
- }
+ if (mIconResId == resId) return;
+ mIconResId = resId;
+ updateIconView();
+ }
+
+ public void setMuteIcon(int resId) {
+ if (mMuteIconResId == resId) return;
+ mMuteIconResId = resId;
+ updateIconView();
}
private Uri getMediaVolumeUri() {