From e2356b99a111a2cd4049d76d5326acaf8a050334 Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Thu, 2 Oct 2014 19:20:36 -0400 Subject: [PATCH] Settings: Update media & alarm stream icons. Update icon pointers and remove obsolete preference class. Bug: 17762712 Change-Id: Ia4b96c5b38f2a73a7a339b2ab3abfcd433f4403d --- res/drawable/ic_audio_alarm_24dp.xml | 20 + res/drawable/ic_audio_vol_24dp.xml | 20 + res/drawable/ring_notif.xml | 5 +- res/drawable/ring_notif_mute.xml | 5 +- res/drawable/ring_notif_vibrate.xml | 5 +- res/xml/notification_settings.xml | 4 +- .../settings/RingerVolumePreference.java | 391 ------------------ 7 files changed, 45 insertions(+), 405 deletions(-) create mode 100644 res/drawable/ic_audio_alarm_24dp.xml create mode 100644 res/drawable/ic_audio_vol_24dp.xml delete mode 100644 src/com/android/settings/RingerVolumePreference.java diff --git a/res/drawable/ic_audio_alarm_24dp.xml b/res/drawable/ic_audio_alarm_24dp.xml new file mode 100644 index 00000000000..ddfaa0136c9 --- /dev/null +++ b/res/drawable/ic_audio_alarm_24dp.xml @@ -0,0 +1,20 @@ + + + diff --git a/res/drawable/ic_audio_vol_24dp.xml b/res/drawable/ic_audio_vol_24dp.xml new file mode 100644 index 00000000000..ecb3a40793f --- /dev/null +++ b/res/drawable/ic_audio_vol_24dp.xml @@ -0,0 +1,20 @@ + + + diff --git a/res/drawable/ring_notif.xml b/res/drawable/ring_notif.xml index 414a83d0ba3..cc9da31e382 100644 --- a/res/drawable/ring_notif.xml +++ b/res/drawable/ring_notif.xml @@ -16,9 +16,6 @@ Copyright (C) 2014 The Android Open Source Project diff --git a/res/drawable/ring_notif_mute.xml b/res/drawable/ring_notif_mute.xml index afb835c3009..fe9417d594f 100644 --- a/res/drawable/ring_notif_mute.xml +++ b/res/drawable/ring_notif_mute.xml @@ -16,8 +16,5 @@ Copyright (C) 2014 The Android Open Source Project diff --git a/res/drawable/ring_notif_vibrate.xml b/res/drawable/ring_notif_vibrate.xml index 4f19e01f7f4..37113d7fa75 100644 --- a/res/drawable/ring_notif_vibrate.xml +++ b/res/drawable/ring_notif_vibrate.xml @@ -16,8 +16,5 @@ Copyright (C) 2014 The Android Open Source Project diff --git a/res/xml/notification_settings.xml b/res/xml/notification_settings.xml index e9a499260c5..3f9b40cbe2a 100644 --- a/res/xml/notification_settings.xml +++ b/res/xml/notification_settings.xml @@ -27,13 +27,13 @@ diff --git a/src/com/android/settings/RingerVolumePreference.java b/src/com/android/settings/RingerVolumePreference.java deleted file mode 100644 index 313c1c0ae61..00000000000 --- a/src/com/android/settings/RingerVolumePreference.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (C) 2008 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; - -import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; - -import com.android.internal.telephony.TelephonyIntents; - -import android.app.Dialog; -import android.content.BroadcastReceiver; -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.media.AudioManager; -import android.media.AudioSystem; -import android.net.Uri; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.os.Parcel; -import android.os.Parcelable; -import android.preference.SeekBarVolumizer; -import android.preference.VolumePreference; -import android.provider.Settings; -import android.provider.Settings.System; -import android.util.AttributeSet; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.SeekBar; -import android.widget.TextView; - -/** - * Special preference type that allows configuration of both the ring volume and - * notification volume. - */ -public class RingerVolumePreference extends VolumePreference { - private static final String TAG = "RingerVolumePreference"; - private static final int MSG_RINGER_MODE_CHANGED = 101; - - private SeekBarVolumizer [] mSeekBarVolumizer; - - // These arrays must all match in length and order - private static final int[] SEEKBAR_ID = new int[] { - R.id.media_volume_seekbar, - R.id.ringer_volume_seekbar, - R.id.notification_volume_seekbar, - R.id.alarm_volume_seekbar - }; - - private static final int[] SEEKBAR_TYPE = new int[] { - AudioManager.STREAM_MUSIC, - AudioManager.STREAM_RING, - AudioManager.STREAM_NOTIFICATION, - AudioManager.STREAM_ALARM - }; - - private static final int[] CHECKBOX_VIEW_ID = new int[] { - R.id.media_mute_button, - R.id.ringer_mute_button, - R.id.notification_mute_button, - R.id.alarm_mute_button - }; - - private static final int[] SEEKBAR_SECTION_ID = new int[] { - R.id.media_section, - R.id.ringer_section, - R.id.notification_section, - R.id.alarm_section - }; - - private static final int[] SEEKBAR_MUTED_RES_ID = new int[] { - com.android.internal.R.drawable.ic_audio_vol_mute, - com.android.internal.R.drawable.ic_audio_ring_notif_mute, - com.android.internal.R.drawable.ic_audio_notification_mute, - com.android.internal.R.drawable.ic_audio_alarm_mute - }; - - private static final int[] SEEKBAR_UNMUTED_RES_ID = new int[] { - com.android.internal.R.drawable.ic_audio_vol, - com.android.internal.R.drawable.ic_audio_ring_notif, - com.android.internal.R.drawable.ic_audio_notification, - com.android.internal.R.drawable.ic_audio_alarm - }; - - private ImageView[] mCheckBoxes = new ImageView[SEEKBAR_MUTED_RES_ID.length]; - private SeekBar[] mSeekBars = new SeekBar[SEEKBAR_ID.length]; - - private Handler mHandler = new Handler() { - public void handleMessage(Message msg) { - updateSlidersAndMutedStates(); - } - }; - - @Override - public void createActionButtons() { - setPositiveButtonText(android.R.string.ok); - setNegativeButtonText(null); - } - - private void updateSlidersAndMutedStates() { - for (int i = 0; i < SEEKBAR_TYPE.length; i++) { - int streamType = SEEKBAR_TYPE[i]; - boolean muted = mAudioManager.isStreamMute(streamType); - - if (mCheckBoxes[i] != null) { - if (((streamType == AudioManager.STREAM_RING) || - (streamType == AudioManager.STREAM_NOTIFICATION)) && - (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)) { - mCheckBoxes[i].setImageResource( - com.android.internal.R.drawable.ic_audio_ring_notif_vibrate); - } else { - mCheckBoxes[i].setImageResource( - muted ? SEEKBAR_MUTED_RES_ID[i] : SEEKBAR_UNMUTED_RES_ID[i]); - } - } - if (mSeekBars[i] != null) { - final int volume = mAudioManager.getStreamVolume(streamType); - mSeekBars[i].setProgress(volume); - if (streamType != mAudioManager.getMasterStreamType() && muted) { - mSeekBars[i].setEnabled(false); - } else { - mSeekBars[i].setEnabled(true); - } - } - } - } - - private BroadcastReceiver mRingModeChangedReceiver; - private AudioManager mAudioManager; - - //private SeekBarVolumizer mNotificationSeekBarVolumizer; - //private TextView mNotificationVolumeTitle; - - public RingerVolumePreference(Context context, AttributeSet attrs) { - super(context, attrs); - - // The always visible seekbar is for ring volume - setStreamType(AudioManager.STREAM_RING); - - setDialogLayoutResource(R.layout.preference_dialog_ringervolume); - //setDialogIcon(R.drawable.ic_settings_sound); - - mSeekBarVolumizer = new SeekBarVolumizer[SEEKBAR_ID.length]; - - mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - } - - @Override - protected void onBindDialogView(View view) { - super.onBindDialogView(view); - - for (int i = 0; i < SEEKBAR_ID.length; i++) { - SeekBar seekBar = (SeekBar) view.findViewById(SEEKBAR_ID[i]); - mSeekBars[i] = seekBar; - if (SEEKBAR_TYPE[i] == AudioManager.STREAM_MUSIC) { - mSeekBarVolumizer[i] = new SeekBarVolumizer(getContext(), - SEEKBAR_TYPE[i], getMediaVolumeUri(getContext()), this); - mSeekBarVolumizer[i].setSeekBar(seekBar); - } else { - mSeekBarVolumizer[i] = new SeekBarVolumizer(getContext(), - SEEKBAR_TYPE[i], null, this); - mSeekBarVolumizer[i].setSeekBar(seekBar); - } - } - - // Register callbacks for mute/unmute buttons - for (int i = 0; i < mCheckBoxes.length; i++) { - ImageView checkbox = (ImageView) view.findViewById(CHECKBOX_VIEW_ID[i]); - mCheckBoxes[i] = checkbox; - } - - // Load initial states from AudioManager - updateSlidersAndMutedStates(); - - // Listen for updates from AudioManager - if (mRingModeChangedReceiver == null) { - final IntentFilter filter = new IntentFilter(); - filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); - mRingModeChangedReceiver = new BroadcastReceiver() { - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { - mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED, intent - .getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0)); - } - } - }; - getContext().registerReceiver(mRingModeChangedReceiver, filter); - } - - boolean useMasterVolume = getContext().getResources(). - getBoolean(com.android.internal.R.bool.config_useMasterVolume); - if (useMasterVolume) { - // If config_useMasterVolume is true, all streams are treated as STREAM_MASTER. - // So hide all except a stream. - int id; - if (Utils.isVoiceCapable(getContext())) { - id = R.id.ringer_section; - } else { - id = R.id.media_section; - } - for (int i = 0; i < SEEKBAR_SECTION_ID.length; i++) { - if (SEEKBAR_SECTION_ID[i] != id) { - view.findViewById(SEEKBAR_SECTION_ID[i]).setVisibility(View.GONE); - } - } - } else { - // Disable either ringer+notifications or notifications - int id; - if (!Utils.isVoiceCapable(getContext())) { - id = R.id.ringer_section; - } else { - id = R.id.notification_section; - } - View hideSection = view.findViewById(id); - hideSection.setVisibility(View.GONE); - } - } - - private Uri getMediaVolumeUri(Context context) { - return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" - + context.getPackageName() - + "/" + R.raw.media_volume); - } - - @Override - protected void onDialogClosed(boolean positiveResult) { - super.onDialogClosed(positiveResult); - - if (!positiveResult) { - for (SeekBarVolumizer vol : mSeekBarVolumizer) { - if (vol != null) vol.revertVolume(); - } - } - cleanup(); - } - - @Override - public void onActivityStop() { - super.onActivityStop(); - - for (SeekBarVolumizer vol : mSeekBarVolumizer) { - if (vol != null) vol.stopSample(); - } - } - - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - boolean isdown = (event.getAction() == KeyEvent.ACTION_DOWN); - switch (keyCode) { - case KeyEvent.KEYCODE_VOLUME_DOWN: - case KeyEvent.KEYCODE_VOLUME_UP: - case KeyEvent.KEYCODE_VOLUME_MUTE: - return true; - default: - return false; - } - } - - @Override - public void onSampleStarting(SeekBarVolumizer volumizer) { - super.onSampleStarting(volumizer); - for (SeekBarVolumizer vol : mSeekBarVolumizer) { - if (vol != null && vol != volumizer) vol.stopSample(); - } - } - - private void cleanup() { - for (int i = 0; i < SEEKBAR_ID.length; i++) { - if (mSeekBarVolumizer[i] != null) { - Dialog dialog = getDialog(); - if (dialog != null && dialog.isShowing()) { - // Stopped while dialog was showing, revert changes - mSeekBarVolumizer[i].revertVolume(); - } - mSeekBarVolumizer[i].stop(); - mSeekBarVolumizer[i] = null; - } - } - if (mRingModeChangedReceiver != null) { - getContext().unregisterReceiver(mRingModeChangedReceiver); - mRingModeChangedReceiver = null; - } - } - - @Override - protected Parcelable onSaveInstanceState() { - final Parcelable superState = super.onSaveInstanceState(); - if (isPersistent()) { - // No need to save instance state since it's persistent - return superState; - } - - final SavedState myState = new SavedState(superState); - VolumeStore[] volumeStore = myState.getVolumeStore(SEEKBAR_ID.length); - for (int i = 0; i < SEEKBAR_ID.length; i++) { - SeekBarVolumizer vol = mSeekBarVolumizer[i]; - if (vol != null) { - vol.onSaveInstanceState(volumeStore[i]); - } - } - return myState; - } - - @Override - protected void onRestoreInstanceState(Parcelable state) { - if (state == null || !state.getClass().equals(SavedState.class)) { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } - - SavedState myState = (SavedState) state; - super.onRestoreInstanceState(myState.getSuperState()); - VolumeStore[] volumeStore = myState.getVolumeStore(SEEKBAR_ID.length); - for (int i = 0; i < SEEKBAR_ID.length; i++) { - SeekBarVolumizer vol = mSeekBarVolumizer[i]; - if (vol != null) { - vol.onRestoreInstanceState(volumeStore[i]); - } - } - } - - private static class SavedState extends BaseSavedState { - VolumeStore [] mVolumeStore; - - public SavedState(Parcel source) { - super(source); - mVolumeStore = new VolumeStore[SEEKBAR_ID.length]; - for (int i = 0; i < SEEKBAR_ID.length; i++) { - mVolumeStore[i] = new VolumeStore(); - mVolumeStore[i].volume = source.readInt(); - mVolumeStore[i].originalVolume = source.readInt(); - } - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - for (int i = 0; i < SEEKBAR_ID.length; i++) { - dest.writeInt(mVolumeStore[i].volume); - dest.writeInt(mVolumeStore[i].originalVolume); - } - } - - VolumeStore[] getVolumeStore(int count) { - if (mVolumeStore == null || mVolumeStore.length != count) { - mVolumeStore = new VolumeStore[count]; - for (int i = 0; i < count; i++) { - mVolumeStore[i] = new VolumeStore(); - } - } - return mVolumeStore; - } - - public SavedState(Parcelable superState) { - super(superState); - } - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - } -}