Merge changes Ib8e1b852,I7e848e97,I7d620721 am: 66098afb42
am: dcfedabfad

Change-Id: Ifead62cf031d59f37775b8f2000af0fac8301734
diff --git a/java/com/android/dialer/app/settings/DialerSettingsActivity.java b/java/com/android/dialer/app/settings/DialerSettingsActivity.java
index cbd9e79..24e5fe8 100644
--- a/java/com/android/dialer/app/settings/DialerSettingsActivity.java
+++ b/java/com/android/dialer/app/settings/DialerSettingsActivity.java
@@ -102,7 +102,6 @@
 
     Header soundSettingsHeader = new Header();
     soundSettingsHeader.titleRes = R.string.sounds_and_vibration_title;
-    soundSettingsHeader.fragment = SoundSettingsFragment.class.getName();
     soundSettingsHeader.id = R.id.settings_header_sounds_and_vibration;
     target.add(soundSettingsHeader);
 
@@ -271,22 +270,32 @@
         && getResources().getBoolean(R.bool.config_sort_order_user_changeable);
   }
 
+  /**
+   * For the "sounds and vibration" setting, we go directly to the system sound settings fragment.
+   * This helps since:
+   * <li>We don't need a separate Dialer sounds and vibrations fragment, as everything we need is
+   *     present in the system sounds fragment.
+   * <li>OEM's e.g Moto that support dual sim ring-tones no longer need to update the dialer sound
+   *     and settings fragment.
+   *
+   *     <p>For all other settings, we launch our our preferences fragment.
+   */
   @Override
   public void onHeaderClick(Header header, int position) {
     if (header.id == R.id.settings_header_sounds_and_vibration) {
-      // If we don't have the permission to write to system settings, go to system sound
-      // settings instead. Otherwise, perform the super implementation (which launches our
-      // own preference fragment.
+
       if (!Settings.System.canWrite(this)) {
         Toast.makeText(
                 this,
                 getResources().getString(R.string.toast_cannot_write_system_settings),
                 Toast.LENGTH_SHORT)
             .show();
-        startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
-        return;
       }
+
+      startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
+      return;
     }
+
     super.onHeaderClick(header, position);
   }
 
diff --git a/java/com/android/dialer/app/settings/SoundSettingsFragment.java b/java/com/android/dialer/app/settings/SoundSettingsFragment.java
deleted file mode 100644
index 19cddbc..0000000
--- a/java/com/android/dialer/app/settings/SoundSettingsFragment.java
+++ /dev/null
@@ -1,242 +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.app.settings;
-
-import android.content.Context;
-import android.media.RingtoneManager;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Vibrator;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.PreferenceFragment;
-import android.preference.PreferenceScreen;
-import android.preference.SwitchPreference;
-import android.provider.Settings;
-import android.telephony.CarrierConfigManager;
-import android.telephony.TelephonyManager;
-import android.widget.Toast;
-import com.android.dialer.app.R;
-import com.android.dialer.compat.SdkVersionOverride;
-import com.android.dialer.util.SettingsUtil;
-
-public class SoundSettingsFragment extends PreferenceFragment
-    implements Preference.OnPreferenceChangeListener {
-
-  private static final int NO_DTMF_TONE = 0;
-  private static final int PLAY_DTMF_TONE = 1;
-
-  private static final int NO_VIBRATION_FOR_CALLS = 0;
-  private static final int DO_VIBRATION_FOR_CALLS = 1;
-
-  private static final int DTMF_TONE_TYPE_NORMAL = 0;
-
-  private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1;
-
-  private Preference ringtonePreference;
-  private final Handler ringtoneLookupComplete =
-      new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-          switch (msg.what) {
-            case MSG_UPDATE_RINGTONE_SUMMARY:
-              ringtonePreference.setSummary((CharSequence) msg.obj);
-              break;
-          }
-        }
-      };
-  private final Runnable ringtoneLookupRunnable =
-      new Runnable() {
-        @Override
-        public void run() {
-          updateRingtonePreferenceSummary();
-        }
-      };
-  private SwitchPreference vibrateWhenRinging;
-  private SwitchPreference playDtmfTone;
-  private ListPreference dtmfToneLength;
-
-  @Override
-  public Context getContext() {
-    return getActivity();
-  }
-
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    addPreferencesFromResource(R.xml.sound_settings);
-
-    Context context = getActivity();
-
-    ringtonePreference = findPreference(context.getString(R.string.ringtone_preference_key));
-    vibrateWhenRinging =
-        (SwitchPreference) findPreference(context.getString(R.string.vibrate_on_preference_key));
-    playDtmfTone =
-        (SwitchPreference) findPreference(context.getString(R.string.play_dtmf_preference_key));
-    dtmfToneLength =
-        (ListPreference)
-            findPreference(context.getString(R.string.dtmf_tone_length_preference_key));
-
-    if (hasVibrator()) {
-      vibrateWhenRinging.setOnPreferenceChangeListener(this);
-    } else {
-      getPreferenceScreen().removePreference(vibrateWhenRinging);
-      vibrateWhenRinging = null;
-    }
-
-    playDtmfTone.setOnPreferenceChangeListener(this);
-    playDtmfTone.setChecked(shouldPlayDtmfTone());
-
-    TelephonyManager telephonyManager =
-        (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
-    if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M
-        && telephonyManager.canChangeDtmfToneLength()
-        && (telephonyManager.isWorldPhone() || !shouldHideCarrierSettings())) {
-      dtmfToneLength.setOnPreferenceChangeListener(this);
-      dtmfToneLength.setValueIndex(
-          Settings.System.getInt(
-              context.getContentResolver(),
-              Settings.System.DTMF_TONE_TYPE_WHEN_DIALING,
-              DTMF_TONE_TYPE_NORMAL));
-    } else {
-      getPreferenceScreen().removePreference(dtmfToneLength);
-      dtmfToneLength = null;
-    }
-  }
-
-  @Override
-  public void onResume() {
-    super.onResume();
-
-    if (!Settings.System.canWrite(getContext())) {
-      // If the user launches this setting fragment, then toggles the WRITE_SYSTEM_SETTINGS
-      // AppOp, then close the fragment since there is nothing useful to do.
-      getActivity().onBackPressed();
-      return;
-    }
-
-    if (vibrateWhenRinging != null) {
-      vibrateWhenRinging.setChecked(shouldVibrateWhenRinging());
-    }
-
-    // Lookup the ringtone name asynchronously.
-    new Thread(ringtoneLookupRunnable).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 (!Settings.System.canWrite(getContext())) {
-      // A user shouldn't be able to get here, but this protects against monkey crashes.
-      Toast.makeText(
-              getContext(),
-              getResources().getString(R.string.toast_cannot_write_system_settings),
-              Toast.LENGTH_SHORT)
-          .show();
-      return true;
-    }
-    if (preference == vibrateWhenRinging) {
-      boolean doVibrate = (Boolean) objValue;
-      Settings.System.putInt(
-          getActivity().getContentResolver(),
-          Settings.System.VIBRATE_WHEN_RINGING,
-          doVibrate ? DO_VIBRATION_FOR_CALLS : NO_VIBRATION_FOR_CALLS);
-    } else if (preference == dtmfToneLength) {
-      int index = dtmfToneLength.findIndexOfValue((String) objValue);
-      Settings.System.putInt(
-          getActivity().getContentResolver(), Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index);
-    }
-    return true;
-  }
-
-  /** Click listener for toggle events. */
-  @Override
-  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-    if (!Settings.System.canWrite(getContext())) {
-      Toast.makeText(
-              getContext(),
-              getResources().getString(R.string.toast_cannot_write_system_settings),
-              Toast.LENGTH_SHORT)
-          .show();
-      return true;
-    }
-    if (preference == playDtmfTone) {
-      Settings.System.putInt(
-          getActivity().getContentResolver(),
-          Settings.System.DTMF_TONE_WHEN_DIALING,
-          playDtmfTone.isChecked() ? PLAY_DTMF_TONE : NO_DTMF_TONE);
-    }
-    return true;
-  }
-
-  /** Updates the summary text on the ringtone preference with the name of the ringtone. */
-  private void updateRingtonePreferenceSummary() {
-    SettingsUtil.updateRingtoneName(
-        getActivity(),
-        ringtoneLookupComplete,
-        RingtoneManager.TYPE_RINGTONE,
-        ringtonePreference.getKey(),
-        MSG_UPDATE_RINGTONE_SUMMARY);
-  }
-
-  /**
-   * Obtain the value for "vibrate when ringing" setting. The default value is false.
-   *
-   * <p>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.
-   */
-  private boolean shouldVibrateWhenRinging() {
-    int vibrateWhenRingingSetting =
-        Settings.System.getInt(
-            getActivity().getContentResolver(),
-            Settings.System.VIBRATE_WHEN_RINGING,
-            NO_VIBRATION_FOR_CALLS);
-    return hasVibrator() && (vibrateWhenRingingSetting == DO_VIBRATION_FOR_CALLS);
-  }
-
-  /** Obtains the value for dialpad/DTMF tones. The default value is true. */
-  private boolean shouldPlayDtmfTone() {
-    int dtmfToneSetting =
-        Settings.System.getInt(
-            getActivity().getContentResolver(),
-            Settings.System.DTMF_TONE_WHEN_DIALING,
-            PLAY_DTMF_TONE);
-    return dtmfToneSetting == PLAY_DTMF_TONE;
-  }
-
-  /** Whether the device hardware has a vibrator. */
-  private boolean hasVibrator() {
-    Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
-    return vibrator != null && vibrator.hasVibrator();
-  }
-
-  private boolean shouldHideCarrierSettings() {
-    CarrierConfigManager configManager =
-        (CarrierConfigManager) getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
-    return configManager
-        .getConfig()
-        .getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL);
-  }
-}
diff --git a/java/com/android/incallui/rtt/impl/RttCheckableButton.java b/java/com/android/incallui/rtt/impl/RttCheckableButton.java
index ba15ca9..c0c8599 100644
--- a/java/com/android/incallui/rtt/impl/RttCheckableButton.java
+++ b/java/com/android/incallui/rtt/impl/RttCheckableButton.java
@@ -22,11 +22,11 @@
 import android.os.Parcelable;
 import android.util.AttributeSet;
 import android.view.SoundEffectConstants;
+import android.widget.Button;
 import android.widget.Checkable;
-import android.widget.TextView;
 
 /** Image button that maintains a checked state. */
-public class RttCheckableButton extends TextView implements Checkable {
+public class RttCheckableButton extends Button implements Checkable {
 
   private static final int[] CHECKED_STATE_SET = {android.R.attr.state_checked};
 
@@ -47,11 +47,16 @@
   }
 
   public RttCheckableButton(Context context, AttributeSet attrs) {
-    this(context, attrs, 0);
+    this(context, attrs, android.R.attr.imageButtonStyle);
   }
 
   public RttCheckableButton(Context context, AttributeSet attrs, int defStyleAttr) {
-    super(context, attrs, defStyleAttr);
+    this(context, attrs, defStyleAttr, 0);
+  }
+
+  public RttCheckableButton(
+      Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+    super(context, attrs, defStyleAttr, defStyleRes);
     init(context, attrs);
   }
 
diff --git a/java/com/android/incallui/rtt/impl/res/values/styles.xml b/java/com/android/incallui/rtt/impl/res/values/styles.xml
index 515e0df..bbacde8 100644
--- a/java/com/android/incallui/rtt/impl/res/values/styles.xml
+++ b/java/com/android/incallui/rtt/impl/res/values/styles.xml
@@ -22,6 +22,10 @@
     <item name="android:textSize">16sp</item>
   </style>
 
+  <style name="ButtonTheme">
+    <item name="android:colorControlHighlight">#33000000</item>
+  </style>
+
   <style name="RttButton">
     <item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">wrap_content</item>
@@ -33,6 +37,7 @@
     <item name="android:drawableTint">@color/rtt_checkable_button_color</item>
     <item name="android:textSize">16sp</item>
     <item name="android:textColor">@color/rtt_checkable_button_color</item>
-    <item name="android:colorControlHighlight">#33000000</item>
+    <item name="android:theme">@style/ButtonTheme</item>
+    <item name="android:background">?attr/selectableItemBackground</item>
   </style>
 </resources>
\ No newline at end of file
diff --git a/java/com/android/incallui/speakeasy/SpeakEasyCallManager.java b/java/com/android/incallui/speakeasy/SpeakEasyCallManager.java
index 4fe894a..f2721da 100644
--- a/java/com/android/incallui/speakeasy/SpeakEasyCallManager.java
+++ b/java/com/android/incallui/speakeasy/SpeakEasyCallManager.java
@@ -16,8 +16,8 @@
 
 package com.android.incallui.speakeasy;
 
-import android.app.Fragment;
 import android.support.annotation.NonNull;
+import android.support.v4.app.Fragment;
 import com.android.incallui.call.DialerCall;
 import com.google.common.base.Optional;
 
diff --git a/java/com/android/incallui/speakeasy/SpeakEasyCallManagerStub.java b/java/com/android/incallui/speakeasy/SpeakEasyCallManagerStub.java
index e84766c..9e58ce1 100644
--- a/java/com/android/incallui/speakeasy/SpeakEasyCallManagerStub.java
+++ b/java/com/android/incallui/speakeasy/SpeakEasyCallManagerStub.java
@@ -16,8 +16,8 @@
 
 package com.android.incallui.speakeasy;
 
-import android.app.Fragment;
 import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
 import com.android.incallui.call.DialerCall;
 import com.google.common.base.Optional;
 import javax.inject.Inject;