|
13 | 13 | import android.support.customtabs.CustomTabsIntent;
|
14 | 14 | import android.support.v7.app.AlertDialog;
|
15 | 15 | import android.support.v7.widget.Toolbar;
|
| 16 | +import android.text.Editable; |
| 17 | +import android.text.InputType; |
| 18 | +import android.text.TextWatcher; |
16 | 19 | import android.util.Log;
|
17 | 20 | import android.util.Patterns;
|
18 | 21 | import android.view.View;
|
19 | 22 | import android.view.inputmethod.InputMethodManager;
|
20 | 23 | import android.webkit.URLUtil;
|
21 | 24 | import android.widget.Button;
|
22 | 25 | import android.widget.EditText;
|
| 26 | +import android.widget.ImageView; |
23 | 27 | import android.widget.Toast;
|
24 | 28 |
|
25 | 29 | import com.google.android.gms.auth.api.Auth;
|
@@ -62,6 +66,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener,
|
62 | 66 | private EditText mServerEditText;
|
63 | 67 | private EditText mUserName;
|
64 | 68 | private EditText mPassword;
|
| 69 | + private ImageView mShowPassword; |
65 | 70 | private EditText serverIn;
|
66 | 71 | //region state-restoration
|
67 | 72 | static final String USERNAME = "username";
|
@@ -92,6 +97,7 @@ protected void onCreate(Bundle savedInstanceState) {
|
92 | 97 | findViewById(R.id.zulip_login).setOnClickListener(this);
|
93 | 98 | mUserName = (EditText) findViewById(R.id.username);
|
94 | 99 | mPassword = (EditText) findViewById(R.id.password);
|
| 100 | + mShowPassword = (ImageView) findViewById(R.id.showPassword); |
95 | 101 | serverIn = (EditText) findViewById(R.id.server_url_in);
|
96 | 102 | findViewById(R.id.server_btn).setOnClickListener(new View.OnClickListener() {
|
97 | 103 | @Override
|
@@ -120,6 +126,56 @@ public void onClick(View view) {
|
120 | 126 | mUserName.setText(savedInstanceState.getString(USERNAME));
|
121 | 127 | mPassword.setText(savedInstanceState.getString(PASSWORD));
|
122 | 128 | }
|
| 129 | + |
| 130 | + mShowPassword.setVisibility(View.GONE); |
| 131 | + mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); |
| 132 | + mPassword.addTextChangedListener(new TextWatcher() { |
| 133 | + @Override |
| 134 | + public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 135 | + |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 140 | + |
| 141 | + if (mPassword.getText().length() > 0) |
| 142 | + { |
| 143 | + mShowPassword.setVisibility(View.VISIBLE); |
| 144 | + } |
| 145 | + else |
| 146 | + { |
| 147 | + mShowPassword.setVisibility(View.GONE); |
| 148 | + } |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | + @Override |
| 153 | + public void afterTextChanged(Editable s) { |
| 154 | + |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + |
| 159 | + mShowPassword.setOnClickListener(new View.OnClickListener() { |
| 160 | + @Override |
| 161 | + public void onClick(View v) { |
| 162 | + |
| 163 | + if (mShowPassword.getTag().toString().equals("visible")) |
| 164 | + { |
| 165 | + mShowPassword.setTag("hide"); |
| 166 | + mShowPassword.setImageResource(R.drawable.ic_visibility_off_black_24dp); |
| 167 | + mPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); |
| 168 | + mPassword.setSelection(mPassword.length()); |
| 169 | + } |
| 170 | + else |
| 171 | + { |
| 172 | + mShowPassword.setTag("visible"); |
| 173 | + mShowPassword.setImageResource(R.drawable.ic_visibility_black_24dp); |
| 174 | + mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); |
| 175 | + mPassword.setSelection(mPassword.length()); |
| 176 | + } |
| 177 | + } |
| 178 | + }); |
123 | 179 | }
|
124 | 180 |
|
125 | 181 | private void showLoginFields() {
|
|
0 commit comments