Merge "Hide password for wifi tether" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9bb2efa0ff
@@ -19,6 +19,7 @@ package com.android.settings.widget;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
@@ -27,6 +28,7 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settingslib.CustomEditTextPreference;
|
||||
|
||||
@@ -42,6 +44,7 @@ public class ValidatedEditTextPreference extends CustomEditTextPreference {
|
||||
private final EditTextWatcher mTextWatcher = new EditTextWatcher();
|
||||
private Validator mValidator;
|
||||
private boolean mIsPassword;
|
||||
private boolean mIsSummaryPassword;
|
||||
|
||||
public ValidatedEditTextPreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
@@ -78,10 +81,25 @@ public class ValidatedEditTextPreference extends CustomEditTextPreference {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
final TextView textView = (TextView) holder.findViewById(android.R.id.summary);
|
||||
if (textView != null && mIsSummaryPassword) {
|
||||
textView.setInputType(
|
||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsPassword(boolean isPassword) {
|
||||
mIsPassword = isPassword;
|
||||
}
|
||||
|
||||
public void setIsSummaryPassword(boolean isPassword) {
|
||||
mIsSummaryPassword = isPassword;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
public boolean isPassword() {
|
||||
return mIsPassword;
|
||||
|
@@ -51,6 +51,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
Log.d(TAG, "Updating password in Preference, " + mPassword);
|
||||
}
|
||||
((ValidatedEditTextPreference) mPreference).setValidator(this);
|
||||
((ValidatedEditTextPreference) mPreference).setIsSummaryPassword(true);
|
||||
updatePasswordDisplay((EditTextPreference) mPreference);
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -24,10 +25,12 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -37,6 +40,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ValidatedEditTextPreferenceTest {
|
||||
@@ -46,11 +50,15 @@ public class ValidatedEditTextPreferenceTest {
|
||||
@Mock
|
||||
private ValidatedEditTextPreference.Validator mValidator;
|
||||
|
||||
private PreferenceViewHolder mViewHolder;
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mViewHolder = spy(PreferenceViewHolder.createInstanceForTests(
|
||||
new View(RuntimeEnvironment.application)));
|
||||
mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@@ -111,4 +119,17 @@ public class ValidatedEditTextPreferenceTest {
|
||||
& (InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT))
|
||||
.isNotEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindViewHolder_isPassword_shouldSetInputType() {
|
||||
final TextView textView = spy(new TextView(RuntimeEnvironment.application));
|
||||
when(mViewHolder.findViewById(android.R.id.summary)).thenReturn(textView);
|
||||
|
||||
mPreference.setIsSummaryPassword(true);
|
||||
mPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
assertThat(textView.getInputType()
|
||||
& (InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT))
|
||||
.isNotEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user