|
@@ -2,7 +2,6 @@ package com.afollestad.materialdialogs.prefs;
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Context;
|
|
|
-import android.content.DialogInterface;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Parcel;
|
|
@@ -49,6 +48,8 @@ public class MaterialEditTextPreference extends EditTextPreference {
|
|
|
mColor = DialogUtils.resolveColor(context, R.attr.colorAccent, fallback);
|
|
|
|
|
|
mEditText = new AppCompatEditText(context, attrs);
|
|
|
+ // Give it an ID so it can be saved/restored
|
|
|
+ mEditText.setId(android.R.id.edit);
|
|
|
mEditText.setEnabled(true);
|
|
|
}
|
|
|
|
|
@@ -58,22 +59,26 @@ public class MaterialEditTextPreference extends EditTextPreference {
|
|
|
|
|
|
@Override
|
|
|
protected void onAddEditTextToDialogView(@NonNull View dialogView, @NonNull EditText editText) {
|
|
|
- if (editText.getParent() != null)
|
|
|
- ((ViewGroup) mEditText.getParent()).removeView(editText);
|
|
|
((ViewGroup) dialogView).addView(editText, new LinearLayout.LayoutParams(
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onBindDialogView(@NonNull View view) {
|
|
|
- mEditText.setText("");
|
|
|
- if (getText() != null)
|
|
|
- mEditText.setText(getText());
|
|
|
- ViewParent oldParent = mEditText.getParent();
|
|
|
+ EditText editText = mEditText;
|
|
|
+ editText.setText(getText());
|
|
|
+
|
|
|
+ // Initialize cursor to end of text
|
|
|
+ if (editText.getText().length() > 0) {
|
|
|
+ editText.setSelection(editText.length());
|
|
|
+ }
|
|
|
+
|
|
|
+ ViewParent oldParent = editText.getParent();
|
|
|
if (oldParent != view) {
|
|
|
- if (oldParent != null)
|
|
|
- ((ViewGroup) oldParent).removeView(mEditText);
|
|
|
- onAddEditTextToDialogView(view, mEditText);
|
|
|
+ if (oldParent != null) {
|
|
|
+ ((ViewGroup) oldParent).removeView(editText);
|
|
|
+ }
|
|
|
+ onAddEditTextToDialogView(view, editText);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -105,14 +110,7 @@ public class MaterialEditTextPreference extends EditTextPreference {
|
|
|
.positiveText(getPositiveButtonText())
|
|
|
.negativeText(getNegativeButtonText())
|
|
|
.callback(callback)
|
|
|
- .dismissListener(this)
|
|
|
- .showListener(new DialogInterface.OnShowListener() {
|
|
|
- @Override
|
|
|
- public void onShow(DialogInterface dialog) {
|
|
|
- if (mEditText.getText().length() > 0)
|
|
|
- mEditText.setSelection(mEditText.length());
|
|
|
- }
|
|
|
- });
|
|
|
+ .dismissListener(this);
|
|
|
|
|
|
View layout = LayoutInflater.from(getContext()).inflate(R.layout.md_stub_inputpref, null);
|
|
|
onBindDialogView(layout);
|