Merge "Tweak change voicemail PIN UI" into nyc-mr1-dev
diff --git a/res/layout/voicemail_change_pin.xml b/res/layout/voicemail_change_pin.xml
index ba0d823..b0db64b 100644
--- a/res/layout/voicemail_change_pin.xml
+++ b/res/layout/voicemail_change_pin.xml
@@ -28,7 +28,9 @@
     android:layout_height="0dp"
     android:layout_weight="1"
     android:orientation="vertical"
-    android:padding="48dp">
+    android:paddingTop="48dp"
+    android:paddingStart="48dp"
+    android:paddingEnd="48dp">
     <TextView
       android:id="@+id/headerText"
       android:layout_width="match_parent"
diff --git a/res/layout/voicemail_dialog_change_pin.xml b/res/layout/voicemail_dialog_change_pin.xml
deleted file mode 100644
index a5cfa80..0000000
--- a/res/layout/voicemail_dialog_change_pin.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-  android:layout_width="match_parent"
-  android:layout_height="match_parent"
-  android:orientation="vertical"
-  android:padding="?android:attr/dialogPreferredPadding">
-
-    <TextView
-      android:id="@+id/vm_old_pin_label"
-      android:layout_width="match_parent"
-      android:layout_height="wrap_content"
-      android:text="@string/vm_change_pin_old_pin"
-      android:labelFor="@+id/vm_old_pin"/>
-
-    <EditText android:id="@id/vm_old_pin"
-      android:layout_width="match_parent"
-      android:layout_height="wrap_content"
-      android:textColor="?android:attr/textColorSecondary"
-      android:inputType="numberPassword"/>
-
-    <TextView
-      android:layout_width="match_parent"
-      android:layout_height="wrap_content"
-      android:text="@string/vm_change_pin_new_pin"
-      android:labelFor="@+id/vm_new_pin"/>
-
-    <EditText android:id="@id/vm_new_pin"
-      android:layout_width="match_parent"
-      android:layout_height="wrap_content"
-      android:textColor="?android:attr/textColorSecondary"
-      android:inputType="numberPassword"/>
-
-</LinearLayout>
\ No newline at end of file
diff --git a/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java b/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
index b556aa1..22fb70e 100644
--- a/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
+++ b/src/com/android/phone/settings/VisualVoicemailSettingsUtil.java
@@ -17,8 +17,6 @@
 
 import android.content.Context;
 import android.telecom.PhoneAccountHandle;
-import com.android.internal.telephony.Phone;
-import com.android.phone.PhoneUtils;
 import com.android.phone.R;
 import com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper;
 import com.android.phone.vvm.omtp.VisualVoicemailPreferences;
@@ -67,11 +65,6 @@
                 PhoneAccountHandleConverter.toSubId(phoneAccount)).isEnabledByDefault();
     }
 
-    public static boolean isEnabled(Phone phone) {
-        return isEnabled(phone.getContext(),
-                PhoneUtils.makePstnPhoneAccountHandle(phone));
-    }
-
     /**
      * Whether the client enabled status is explicitly set by user or by default(Whether carrier VVM
      * app is installed). This is used to determine whether to disable the client when the carrier
diff --git a/src/com/android/phone/settings/VoicemailChangePinActivity.java b/src/com/android/phone/settings/VoicemailChangePinActivity.java
index 8027dc1..52c97a7 100644
--- a/src/com/android/phone/settings/VoicemailChangePinActivity.java
+++ b/src/com/android/phone/settings/VoicemailChangePinActivity.java
@@ -437,6 +437,9 @@
     }
 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+      if (!mNextButton.isEnabled()) {
+        return true;
+      }
         // Check if this was the result of hitting the enter or "done" key
         if (actionId == EditorInfo.IME_NULL
                 || actionId == EditorInfo.IME_ACTION_DONE
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
index 92e1b5f..35d9a1c 100644
--- a/src/com/android/phone/settings/VoicemailSettingsActivity.java
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -45,7 +45,9 @@
 import com.android.phone.PhoneUtils;
 import com.android.phone.R;
 import com.android.phone.SubscriptionInfoHelper;
+import com.android.phone.vvm.omtp.OmtpConstants;
 import com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper;
+import com.android.phone.vvm.omtp.VisualVoicemailPreferences;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -193,6 +195,7 @@
 
     private boolean mForeground;
     private Phone mPhone;
+    private PhoneAccountHandle mPhoneAccountHandle;
     private SubscriptionInfoHelper mSubscriptionInfoHelper;
     private OmtpVvmCarrierConfigHelper mOmtpVvmCarrierConfigHelper;
 
@@ -221,6 +224,7 @@
         mSubscriptionInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.voicemail_settings_with_label);
         mPhone = mSubscriptionInfoHelper.getPhone();
+        mPhoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(mPhone);
         mOmtpVvmCarrierConfigHelper = new OmtpVvmCarrierConfigHelper(
                 mPhone.getContext(), mPhone.getSubId());
     }
@@ -265,13 +269,12 @@
 
         mVoicemailChangePinPreference = findPreference(
                 getResources().getString(R.string.voicemail_change_pin_key));
-        PhoneAccountHandle phoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(mPhone);
         Intent changePinIntent = new Intent(new Intent(this, VoicemailChangePinActivity.class));
         changePinIntent.putExtra(VoicemailChangePinActivity.EXTRA_PHONE_ACCOUNT_HANDLE,
-                phoneAccountHandle);
+                mPhoneAccountHandle);
 
         mVoicemailChangePinPreference.setIntent(changePinIntent);
-        if (VoicemailChangePinActivity.isDefaultOldPinSet(this, phoneAccountHandle)) {
+        if (VoicemailChangePinActivity.isDefaultOldPinSet(this, mPhoneAccountHandle)) {
             mVoicemailChangePinPreference.setTitle(R.string.voicemail_set_pin_dialog_title);
         } else {
             mVoicemailChangePinPreference.setTitle(R.string.voicemail_change_pin_dialog_title);
@@ -280,7 +283,10 @@
         if (mOmtpVvmCarrierConfigHelper.isValid()) {
             mVoicemailVisualVoicemail.setOnPreferenceChangeListener(this);
             mVoicemailVisualVoicemail.setChecked(
-                    VisualVoicemailSettingsUtil.isEnabled(mPhone));
+                    VisualVoicemailSettingsUtil.isEnabled(this, mPhoneAccountHandle));
+            if (!isVisualVoicemailActivated()) {
+                prefSet.removePreference(mVoicemailChangePinPreference);
+            }
         } else {
             prefSet.removePreference(mVoicemailVisualVoicemail);
             prefSet.removePreference(mVoicemailChangePinPreference);
@@ -406,11 +412,10 @@
                     mPhone, Boolean.TRUE.equals(objValue));
         } else if (preference.getKey().equals(mVoicemailVisualVoicemail.getKey())) {
             boolean isEnabled = (boolean) objValue;
-            PhoneAccountHandle handle = PhoneUtils.makePstnPhoneAccountHandle(mPhone);
             VisualVoicemailSettingsUtil
-                    .setEnabled(mPhone.getContext(), handle, isEnabled);
+                    .setEnabled(mPhone.getContext(), mPhoneAccountHandle, isEnabled);
             PreferenceScreen prefSet = getPreferenceScreen();
-            if (isEnabled) {
+            if (isVisualVoicemailActivated()) {
                 prefSet.addPreference(mVoicemailChangePinPreference);
             } else {
                 prefSet.removePreference(mVoicemailChangePinPreference);
@@ -1150,6 +1155,16 @@
         return true;
     }
 
+    private boolean isVisualVoicemailActivated() {
+        if (!VisualVoicemailSettingsUtil.isEnabled(this, mPhoneAccountHandle)) {
+            return false;
+        }
+        VisualVoicemailPreferences preferences = new VisualVoicemailPreferences(this,
+                mPhoneAccountHandle);
+        return preferences.getString(OmtpConstants.SERVER_ADDRESS, null) != null;
+
+    }
+
     private static void log(String msg) {
         Log.d(LOG_TAG, msg);
     }