From c65acdff581a103b6baabd25be6fcc8be88215f0 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 2 Mar 2015 22:43:41 -0800 Subject: Move DTMF length setting to Sound settings. Bug: 19372734 Change-Id: I59742a36333b1923459b89c4f11f741feb4d3e78 --- res/values/strings.xml | 14 ++++++ res/xml/sound_settings.xml | 16 +++++-- .../dialer/settings/SoundSettingsFragment.java | 55 +++++++++++++++++----- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index db134430e..e924c3afc 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -707,6 +707,18 @@ Dialpad tones + + Dialpad tone length + + + Normal + Long + + + + 0 + 1 + Quick responses @@ -723,4 +735,6 @@ button_vibrate_on_ring button_play_dtmf_tone + + button_dtmf_settings diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml index ebe0f51f1..80fad626a 100644 --- a/res/xml/sound_settings.xml +++ b/res/xml/sound_settings.xml @@ -25,16 +25,22 @@ android:persistent="false" android:ringtoneType="ringtone" /> + + - + diff --git a/src/com/android/dialer/settings/SoundSettingsFragment.java b/src/com/android/dialer/settings/SoundSettingsFragment.java index 83d5d7de4..43297b5e5 100644 --- a/src/com/android/dialer/settings/SoundSettingsFragment.java +++ b/src/com/android/dialer/settings/SoundSettingsFragment.java @@ -23,10 +23,12 @@ import android.os.Handler; import android.os.Message; import android.os.Vibrator; import android.preference.CheckBoxPreference; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.provider.Settings; +import android.telephony.TelephonyManager; import com.android.dialer.R; import com.android.phone.common.util.SettingsUtil; @@ -48,13 +50,15 @@ public class SoundSettingsFragment extends PreferenceFragment private static final int NO_VIBRATION_FOR_CALLS = 0; private static final int DO_VIBRATION_FOR_CALLS = 1; - private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1; + private static final int SHOW_CARRIER_SETTINGS = 0; + private static final int HIDE_CARRIER_SETTINGS = 1; - private Context mContext; + private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1; private Preference mRingtonePreference; private CheckBoxPreference mVibrateWhenRinging; private CheckBoxPreference mPlayDtmfTone; + private ListPreference mDtmfToneLength; private final Runnable mRingtoneLookupRunnable = new Runnable() { @Override @@ -78,15 +82,17 @@ public class SoundSettingsFragment extends PreferenceFragment public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mContext = getActivity().getApplicationContext(); - addPreferencesFromResource(R.xml.sound_settings); - mRingtonePreference = findPreference(mContext.getString(R.string.ringtone_preference_key)); + Context context = getActivity(); + + mRingtonePreference = findPreference(context.getString(R.string.ringtone_preference_key)); mVibrateWhenRinging = (CheckBoxPreference) findPreference( - mContext.getString(R.string.vibrate_on_preference_key)); + context.getString(R.string.vibrate_on_preference_key)); mPlayDtmfTone = (CheckBoxPreference) findPreference( - mContext.getString(R.string.play_dtmf_preference_key)); + context.getString(R.string.play_dtmf_preference_key)); + mDtmfToneLength = (ListPreference) findPreference( + context.getString(R.string.dtmf_tone_length_preference_key)); if (hasVibrator()) { mVibrateWhenRinging.setOnPreferenceChangeListener(this); @@ -97,6 +103,19 @@ public class SoundSettingsFragment extends PreferenceFragment mPlayDtmfTone.setOnPreferenceChangeListener(this); mPlayDtmfTone.setChecked(shouldPlayDtmfTone()); + + TelephonyManager telephonyManager = + (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); + if (telephonyManager.canChangeDtmfToneLength() + && (telephonyManager.isWorldPhone() || !shouldHideCarrierSettings())) { + mDtmfToneLength.setOnPreferenceChangeListener(this); + mDtmfToneLength.setValueIndex( + Settings.System.getInt(context.getContentResolver(), + Settings.System.DTMF_TONE_WHEN_DIALING, PLAY_DTMF_TONE)); + } else { + getPreferenceScreen().removePreference(mDtmfToneLength); + mDtmfToneLength = null; + } } @Override @@ -121,9 +140,13 @@ public class SoundSettingsFragment extends PreferenceFragment public boolean onPreferenceChange(Preference preference, Object objValue) { if (preference == mVibrateWhenRinging) { boolean doVibrate = (Boolean) objValue; - Settings.System.putInt(mContext.getContentResolver(), + Settings.System.putInt(getActivity().getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, doVibrate ? DO_VIBRATION_FOR_CALLS : NO_VIBRATION_FOR_CALLS); + } else if (preference == mDtmfToneLength) { + int index = mDtmfToneLength.findIndexOfValue((String) objValue); + Settings.System.putInt(getActivity().getContentResolver(), + Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index); } return true; } @@ -134,7 +157,7 @@ public class SoundSettingsFragment extends PreferenceFragment @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference == mPlayDtmfTone) { - Settings.System.putInt(mContext.getContentResolver(), + Settings.System.putInt(getActivity().getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, mPlayDtmfTone.isChecked() ? PLAY_DTMF_TONE : NO_DTMF_TONE); } @@ -146,7 +169,7 @@ public class SoundSettingsFragment extends PreferenceFragment */ private void updateRingtonePreferenceSummary() { SettingsUtil.updateRingtoneName( - mContext, + getActivity(), mRingtoneLookupComplete, RingtoneManager.TYPE_RINGTONE, mRingtonePreference.getKey(), @@ -160,7 +183,7 @@ public class SoundSettingsFragment extends PreferenceFragment * "vibrate on ring" setting from AudioManager, and save the previous setting to the new one. */ private boolean shouldVibrateWhenRinging() { - int vibrateWhenRingingSetting = Settings.System.getInt(mContext.getContentResolver(), + int vibrateWhenRingingSetting = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, NO_VIBRATION_FOR_CALLS); return hasVibrator() && (vibrateWhenRingingSetting == DO_VIBRATION_FOR_CALLS); @@ -170,7 +193,7 @@ public class SoundSettingsFragment extends PreferenceFragment * Obtains the value for dialpad/DTMF tones. The default value is true. */ private boolean shouldPlayDtmfTone() { - int dtmfToneSetting = Settings.System.getInt(mContext.getContentResolver(), + int dtmfToneSetting = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, PLAY_DTMF_TONE); return dtmfToneSetting == PLAY_DTMF_TONE; @@ -180,7 +203,13 @@ public class SoundSettingsFragment extends PreferenceFragment * Whether the device hardware has a vibrator. */ private boolean hasVibrator() { - Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); + Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); return vibrator != null && vibrator.hasVibrator(); } + + private boolean shouldHideCarrierSettings() { + int hideCarrierNetworkSetting = Settings.Global.getInt(getActivity().getContentResolver(), + Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, SHOW_CARRIER_SETTINGS); + return hideCarrierNetworkSetting == HIDE_CARRIER_SETTINGS; + } } -- cgit v1.2.3