From e83576c5503596480d57ff9991df4ad99d26cfc4 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 26 Feb 2015 14:26:16 -0800 Subject: Convert GeneralSettings to SoundSettings. Rather than create a new fragment for "Sounds and vibration", reuse the existing general settings fragment. The other settings which used to reside general settings have been moved into their own top-level settings fragments. + Rename layout file and fragment. + Tweak string names. - Delete category heading; no longer necessary. Bug: 19372734 Change-Id: I5690df7ecbd49da5d5af94889e6b68e053ce25ba --- res/values/strings.xml | 9 +- res/xml/general_settings.xml | 47 ------ res/xml/sound_settings.xml | 40 +++++ .../dialer/settings/DialerSettingsActivity.java | 8 +- .../dialer/settings/GeneralSettingsFragment.java | 168 --------------------- .../dialer/settings/SoundSettingsFragment.java | 166 ++++++++++++++++++++ 6 files changed, 213 insertions(+), 225 deletions(-) delete mode 100644 res/xml/general_settings.xml create mode 100644 res/xml/sound_settings.xml delete mode 100644 src/com/android/dialer/settings/GeneralSettingsFragment.java create mode 100644 src/com/android/dialer/settings/SoundSettingsFragment.java diff --git a/res/values/strings.xml b/res/values/strings.xml index ab8fd2754..1e7a48b2d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -694,12 +694,9 @@ [CHAR LIMIT=40] --> Display options - - General - - - Sounds and vibrate + + Sounds and vibration Phone ringtone diff --git a/res/xml/general_settings.xml b/res/xml/general_settings.xml deleted file mode 100644 index c856e1a46..000000000 --- a/res/xml/general_settings.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml new file mode 100644 index 000000000..e933eedc0 --- /dev/null +++ b/res/xml/sound_settings.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index 935b6c7fd..08beffd9b 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -41,10 +41,10 @@ public class DialerSettingsActivity extends PreferenceActivity { displayOptionsHeader.fragment = DisplayOptionsFragment.class.getName(); target.add(displayOptionsHeader); - Header generalSettingsHeader = new Header(); - generalSettingsHeader.titleRes = R.string.general_settings_label; - generalSettingsHeader.fragment = GeneralSettingsFragment.class.getName(); - target.add(generalSettingsHeader); + Header soundSettingsHeader = new Header(); + soundSettingsHeader.titleRes = R.string.sounds_and_vibration_title; + soundSettingsHeader.fragment = SoundSettingsFragment.class.getName(); + target.add(soundSettingsHeader); Header quickResponseSettingsHeader = new Header(); Intent quickResponseSettingsIntent = diff --git a/src/com/android/dialer/settings/GeneralSettingsFragment.java b/src/com/android/dialer/settings/GeneralSettingsFragment.java deleted file mode 100644 index 7d8228642..000000000 --- a/src/com/android/dialer/settings/GeneralSettingsFragment.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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 - */ - -package com.android.dialer.settings; - -import android.content.Context; -import android.media.RingtoneManager; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.Vibrator; -import android.preference.CheckBoxPreference; -import android.preference.Preference; -import android.preference.PreferenceCategory; -import android.preference.PreferenceFragment; -import android.preference.PreferenceScreen; -import android.provider.Settings; - -import com.android.dialer.R; -import com.android.phone.common.util.SettingsUtil; - -import java.lang.Boolean; -import java.lang.CharSequence; -import java.lang.Object; -import java.lang.Override; -import java.lang.Runnable; -import java.lang.String; -import java.lang.Thread; - -public class GeneralSettingsFragment extends PreferenceFragment - implements Preference.OnPreferenceChangeListener { - private static final String CATEGORY_SOUNDS_KEY = "dialer_general_sounds_category_key"; - private static final String BUTTON_RINGTONE_KEY = "button_ringtone_key"; - private static final String BUTTON_VIBRATE_ON_RING = "button_vibrate_on_ring"; - private static final String BUTTON_PLAY_DTMF_TONE = "button_play_dtmf_tone"; - - private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1; - - private Context mContext; - - private Preference mRingtonePreference; - private CheckBoxPreference mVibrateWhenRinging; - private CheckBoxPreference mPlayDtmfTone; - - private Runnable mRingtoneLookupRunnable; - private final Handler mRingtoneLookupComplete = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_UPDATE_RINGTONE_SUMMARY: - mRingtonePreference.setSummary((CharSequence) msg.obj); - break; - } - } - }; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mContext = getActivity().getApplicationContext(); - - addPreferencesFromResource(R.xml.general_settings); - - mRingtonePreference = findPreference(BUTTON_RINGTONE_KEY); - mVibrateWhenRinging = (CheckBoxPreference) findPreference(BUTTON_VIBRATE_ON_RING); - mPlayDtmfTone = (CheckBoxPreference) findPreference(BUTTON_PLAY_DTMF_TONE); - - PreferenceCategory soundCategory = (PreferenceCategory) findPreference(CATEGORY_SOUNDS_KEY); - if (mVibrateWhenRinging != null) { - Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); - if (vibrator != null && vibrator.hasVibrator()) { - mVibrateWhenRinging.setOnPreferenceChangeListener(this); - } else { - soundCategory.removePreference(mVibrateWhenRinging); - mVibrateWhenRinging = null; - } - } - - if (mPlayDtmfTone != null) { - mPlayDtmfTone.setOnPreferenceChangeListener(this); - mPlayDtmfTone.setChecked(Settings.System.getInt(mContext.getContentResolver(), - Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0); - } - - mRingtoneLookupRunnable = new Runnable() { - @Override - public void run() { - if (mRingtonePreference != null) { - SettingsUtil.updateRingtoneName( - mContext, - mRingtoneLookupComplete, - RingtoneManager.TYPE_RINGTONE, - mRingtonePreference.getKey(), - MSG_UPDATE_RINGTONE_SUMMARY); - } - } - }; - } - - /** - * Supports onPreferenceChangeListener to look for preference changes. - * - * @param preference The preference to be changed - * @param objValue The value of the selection, NOT its localized display value. - */ - @Override - public boolean onPreferenceChange(Preference preference, Object objValue) { - if (preference == mVibrateWhenRinging) { - boolean doVibrate = (Boolean) objValue; - Settings.System.putInt(mContext.getContentResolver(), - Settings.System.VIBRATE_WHEN_RINGING, doVibrate ? 1 : 0); - } - return true; - } - - /** - * Click listener for toggle events. - */ - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { - if (preference == mPlayDtmfTone) { - Settings.System.putInt(mContext.getContentResolver(), - Settings.System.DTMF_TONE_WHEN_DIALING, mPlayDtmfTone.isChecked() ? 1 : 0); - } - return true; - } - - @Override - public void onResume() { - super.onResume(); - - if (mVibrateWhenRinging != null) { - mVibrateWhenRinging.setChecked(getVibrateWhenRingingSetting(mContext)); - } - - // Lookup the ringtone name asynchronously. - new Thread(mRingtoneLookupRunnable).start(); - } - - /** - * Obtain the setting for "vibrate when ringing" setting. - * - * Watch out: if the setting is missing in the device, this will try obtaining the old - * "vibrate on ring" setting from AudioManager, and save the previous setting to the new one. - */ - public static boolean getVibrateWhenRingingSetting(Context context) { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - if (vibrator == null || !vibrator.hasVibrator()) { - return false; - } - return Settings.System.getInt(context.getContentResolver(), - Settings.System.VIBRATE_WHEN_RINGING, 0) != 0; - } -} diff --git a/src/com/android/dialer/settings/SoundSettingsFragment.java b/src/com/android/dialer/settings/SoundSettingsFragment.java new file mode 100644 index 000000000..6a9bc1e36 --- /dev/null +++ b/src/com/android/dialer/settings/SoundSettingsFragment.java @@ -0,0 +1,166 @@ +/* + * 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 + */ + +package com.android.dialer.settings; + +import android.content.Context; +import android.media.RingtoneManager; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.Vibrator; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.PreferenceScreen; +import android.provider.Settings; + +import com.android.dialer.R; +import com.android.phone.common.util.SettingsUtil; + +import java.lang.Boolean; +import java.lang.CharSequence; +import java.lang.Object; +import java.lang.Override; +import java.lang.Runnable; +import java.lang.String; +import java.lang.Thread; + +public class SoundSettingsFragment extends PreferenceFragment + implements Preference.OnPreferenceChangeListener { + private static final String BUTTON_RINGTONE_KEY = "button_ringtone_key"; + private static final String BUTTON_VIBRATE_ON_RING = "button_vibrate_on_ring"; + private static final String BUTTON_PLAY_DTMF_TONE = "button_play_dtmf_tone"; + + private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1; + + private Context mContext; + + private Preference mRingtonePreference; + private CheckBoxPreference mVibrateWhenRinging; + private CheckBoxPreference mPlayDtmfTone; + + private Runnable mRingtoneLookupRunnable; + private final Handler mRingtoneLookupComplete = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_UPDATE_RINGTONE_SUMMARY: + mRingtonePreference.setSummary((CharSequence) msg.obj); + break; + } + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mContext = getActivity().getApplicationContext(); + + addPreferencesFromResource(R.xml.sound_settings); + + mRingtonePreference = findPreference(BUTTON_RINGTONE_KEY); + mVibrateWhenRinging = (CheckBoxPreference) findPreference(BUTTON_VIBRATE_ON_RING); + mPlayDtmfTone = (CheckBoxPreference) findPreference(BUTTON_PLAY_DTMF_TONE); + + if (mVibrateWhenRinging != null) { + Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator != null && vibrator.hasVibrator()) { + mVibrateWhenRinging.setOnPreferenceChangeListener(this); + } else { + getPreferenceScreen().removePreference(mVibrateWhenRinging); + mVibrateWhenRinging = null; + } + } + + if (mPlayDtmfTone != null) { + mPlayDtmfTone.setOnPreferenceChangeListener(this); + mPlayDtmfTone.setChecked(Settings.System.getInt(mContext.getContentResolver(), + Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0); + } + + mRingtoneLookupRunnable = new Runnable() { + @Override + public void run() { + if (mRingtonePreference != null) { + SettingsUtil.updateRingtoneName( + mContext, + mRingtoneLookupComplete, + RingtoneManager.TYPE_RINGTONE, + mRingtonePreference.getKey(), + MSG_UPDATE_RINGTONE_SUMMARY); + } + } + }; + } + + @Override + public void onResume() { + super.onResume(); + + if (mVibrateWhenRinging != null) { + mVibrateWhenRinging.setChecked(getVibrateWhenRingingSetting(mContext)); + } + + // Lookup the ringtone name asynchronously. + new Thread(mRingtoneLookupRunnable).start(); + } + + /** + * Supports onPreferenceChangeListener to look for preference changes. + * + * @param preference The preference to be changed + * @param objValue The value of the selection, NOT its localized display value. + */ + @Override + public boolean onPreferenceChange(Preference preference, Object objValue) { + if (preference == mVibrateWhenRinging) { + boolean doVibrate = (Boolean) objValue; + Settings.System.putInt(mContext.getContentResolver(), + Settings.System.VIBRATE_WHEN_RINGING, doVibrate ? 1 : 0); + } + return true; + } + + /** + * Click listener for toggle events. + */ + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + if (preference == mPlayDtmfTone) { + Settings.System.putInt(mContext.getContentResolver(), + Settings.System.DTMF_TONE_WHEN_DIALING, mPlayDtmfTone.isChecked() ? 1 : 0); + } + return true; + } + + + /** + * Obtain the setting for "vibrate when ringing" setting. + * + * Watch out: if the setting is missing in the device, this will try obtaining the old + * "vibrate on ring" setting from AudioManager, and save the previous setting to the new one. + */ + public static boolean getVibrateWhenRingingSetting(Context context) { + Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator == null || !vibrator.hasVibrator()) { + return false; + } + return Settings.System.getInt(context.getContentResolver(), + Settings.System.VIBRATE_WHEN_RINGING, 0) != 0; + } +} -- cgit v1.2.3