Bug 1227325 - Part 3: Upgrade GeckoPreferences to use TextInputLayout r=mcomella draft
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 22 Jan 2016 16:46:26 -0800
changeset 325484 4a8ca2558940ad2828695ef07ee2447c83dae6d1
parent 325483 f4c964a0b99cc8b9f09192091d3d38466fde9b6b
child 325485 115229d46fcc07b8327dbfc33f6ff743c24a440e
push id9978
push userahunt@mozilla.com
push dateMon, 25 Jan 2016 16:58:05 +0000
reviewersmcomella
bugs1227325
milestone46.0a1
Bug 1227325 - Part 3: Upgrade GeckoPreferences to use TextInputLayout r=mcomella
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -1,17 +1,15 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.preferences;
 
-import android.Manifest;
-import android.annotation.TargetApi;
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.AdjustConstants;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.BrowserLocaleManager;
 import org.mozilla.gecko.DataReportingNotification;
 import org.mozilla.gecko.EventDispatcher;
@@ -40,58 +38,61 @@ import org.mozilla.gecko.updater.UpdateS
 import org.mozilla.gecko.updater.UpdateServiceHelper;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.InputOptionsUtils;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
-import org.mozilla.gecko.widget.FloatingHintEditText;
 
+import android.annotation.TargetApi;
 import android.app.ActionBar;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.NotificationManager;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.content.res.Configuration;
+import android.Manifest;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.EditTextPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceChangeListener;
 import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
 import android.preference.TwoStatePreference;
 import android.support.design.widget.Snackbar;
+import android.support.design.widget.TextInputLayout;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.EditText;
 import android.widget.LinearLayout;
 import android.widget.ListAdapter;
 import android.widget.ListView;
 
 import org.json.JSONObject;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
 public class GeckoPreferences
@@ -1284,24 +1285,28 @@ OnSharedPreferenceChangeListener
                     @Override
                     public void run() {
                         preference.setChecked(true);
                         broadcastStumblerPref(GeckoPreferences.this, true);
                     }
                 });
     }
 
-    private EditText getTextBox(int aHintText) {
-        EditText input = new FloatingHintEditText(this);
+    private TextInputLayout getTextBox(int aHintText) {
+        final EditText input = new EditText(this);
         int inputtype = InputType.TYPE_CLASS_TEXT;
         inputtype |= InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
         input.setInputType(inputtype);
 
         input.setHint(aHintText);
-        return input;
+
+        final TextInputLayout layout = new TextInputLayout(this);
+        layout.addView(input);
+
+        return layout;
     }
 
     private class PasswordTextWatcher implements TextWatcher {
         EditText input1;
         EditText input2;
         AlertDialog dialog;
 
         PasswordTextWatcher(EditText aInput1, EditText aInput2, AlertDialog aDialog) {
@@ -1355,20 +1360,23 @@ OnSharedPreferenceChangeListener
     @Override
     protected Dialog onCreateDialog(int id) {
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         LinearLayout linearLayout = new LinearLayout(this);
         linearLayout.setOrientation(LinearLayout.VERTICAL);
         AlertDialog dialog;
         switch(id) {
             case DIALOG_CREATE_MASTER_PASSWORD:
-                final EditText input1 = getTextBox(R.string.masterpassword_password);
-                final EditText input2 = getTextBox(R.string.masterpassword_confirm);
-                linearLayout.addView(input1);
-                linearLayout.addView(input2);
+                final TextInputLayout inputLayout1 = getTextBox(R.string.masterpassword_password);
+                final TextInputLayout inputLayout2 = getTextBox(R.string.masterpassword_confirm);
+                linearLayout.addView(inputLayout1);
+                linearLayout.addView(inputLayout2);
+
+                final EditText input1 = inputLayout1.getEditText();
+                final EditText input2 = inputLayout2.getEditText();
 
                 builder.setTitle(R.string.masterpassword_create_title)
                        .setView((View) linearLayout)
                        .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                             @Override
                             public void onClick(DialogInterface dialog, int which) {
                                 JSONObject jsonPref = new JSONObject();
                                 try {
@@ -1402,18 +1410,19 @@ OnSharedPreferenceChangeListener
                         });
 
                         PasswordTextWatcher watcher = new PasswordTextWatcher(input1, input2, dialog);
                         input1.addTextChangedListener((TextWatcher) watcher);
                         input2.addTextChangedListener((TextWatcher) watcher);
 
                 break;
             case DIALOG_REMOVE_MASTER_PASSWORD:
-                final EditText input = getTextBox(R.string.masterpassword_password);
-                linearLayout.addView(input);
+                final TextInputLayout inputLayout = getTextBox(R.string.masterpassword_password);
+                linearLayout.addView(inputLayout);
+                final EditText input = inputLayout.getEditText();
 
                 builder.setTitle(R.string.masterpassword_remove_title)
                        .setView((View) linearLayout)
                        .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                             @Override
                             public void onClick(DialogInterface dialog, int which) {
                                 PrefsHelper.setPref(PREFS_MP_ENABLED, input.getText().toString());
                             }