|
@@ -2,6 +2,7 @@ package com.afollestad.materialdialogs.prefs;
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Context;
|
|
|
+import android.content.res.TypedArray;
|
|
|
import android.graphics.PorterDuff;
|
|
|
import android.os.Build.VERSION;
|
|
|
import android.os.Build.VERSION_CODES;
|
|
@@ -29,11 +30,16 @@ public class MaterialEditTextPreference extends DialogPreference {
|
|
|
|
|
|
private int mColor = 0;
|
|
|
private EditText mEditText;
|
|
|
+ private String mValue;
|
|
|
|
|
|
public EditText getEditText() {
|
|
|
return mEditText;
|
|
|
}
|
|
|
|
|
|
+ public void setValue(String value){
|
|
|
+ mValue = value;
|
|
|
+ }
|
|
|
+
|
|
|
public void setText(String text) {
|
|
|
final boolean wasBlocking = shouldDisableDependents();
|
|
|
persistString(text);
|
|
@@ -69,12 +75,12 @@ public class MaterialEditTextPreference extends DialogPreference {
|
|
|
// Create our layout, put the EditText inside, then add to dialog
|
|
|
ViewGroup layout = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.md_input_dialog, null);
|
|
|
mEditText = (EditText) layout.findViewById(android.R.id.edit);
|
|
|
+ mEditText.setText(mValue);
|
|
|
|
|
|
// Color our EditText if need be. Lollipop does it by default
|
|
|
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP)
|
|
|
mEditText.getBackground().setColorFilter(mColor, PorterDuff.Mode.SRC_ATOP);
|
|
|
|
|
|
-
|
|
|
TextView message = (TextView) layout.findViewById(android.R.id.message);
|
|
|
if (getDialogMessage() != null && getDialogMessage().toString().length() > 0) {
|
|
|
message.setVisibility(View.VISIBLE);
|
|
@@ -116,4 +122,20 @@ public class MaterialEditTextPreference extends DialogPreference {
|
|
|
Window window = dialog.getWindow();
|
|
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Called when the default value attribute needs to be read
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected Object onGetDefaultValue(TypedArray a, int index) {
|
|
|
+ return a.getString(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Called on initialization, defaultValue populated only if onGetDefaultValue is overriden
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
|
|
|
+ setValue(restorePersistedValue ? getPersistedString("") : defaultValue.toString());
|
|
|
+ }
|
|
|
}
|