1
0
Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

Aidan Follestad 10 жил өмнө
parent
commit
8f9ec911a2

+ 3 - 3
README.md

@@ -327,8 +327,8 @@ using the `Builder`. This will result in the library not applying Roboto and Rob
 and everything will use the regular system font.
 and everything will use the regular system font.
 
 
 If you want to explicitly use custom fonts, you can make a call to `typeface(String, String)` when
 If you want to explicitly use custom fonts, you can make a call to `typeface(String, String)` when
-using the `Builder`. This will pull fonts from TTF files in your project's `assets` folder. For an example,
-if you had `Roboto.ttf` and `Roboto-Light.ttf` in `/src/main/assets`, you would call `typeface("Roboto", "Roboto-Light")`.
+using the `Builder`. This will pull fonts from TTF files in your project's `assets` folder. For example,
+if you had `Roboto.ttf` and `Roboto-Light.ttf` in `/src/main/assets/fonts`, you would call `typeface("Roboto", "Roboto-Light")`.
 Note that no extension is used in the name. This method will also handle recycling Typefaces via the `TypefaceHelper` which
 Note that no extension is used in the name. This method will also handle recycling Typefaces via the `TypefaceHelper` which
 you can use in your own project to avoid duplicate allocations.
 you can use in your own project to avoid duplicate allocations.
 
 
@@ -612,4 +612,4 @@ MaterialDialog dialog new MaterialDialog.Builder(this)
         // ... other initialization
         // ... other initialization
         .autoDismiss(false)
         .autoDismiss(false)
         .show();
         .show();
-```
+```

+ 23 - 1
library/src/main/java/com/afollestad/materialdialogs/prefs/MaterialEditTextPreference.java

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

+ 1 - 0
sample/src/main/res/values/strings.xml

@@ -131,6 +131,7 @@
     <string name="edittext_pref_title">Material EditText Preference</string>
     <string name="edittext_pref_title">Material EditText Preference</string>
     <string name="edittext_pref_desc">This is an example of an EditText preference that automatically uses Material Dialogs to show the input dialog.</string>
     <string name="edittext_pref_desc">This is an example of an EditText preference that automatically uses Material Dialogs to show the input dialog.</string>
     <string name="edittext_pref_dialogtitle">Enter a Name</string>
     <string name="edittext_pref_dialogtitle">Enter a Name</string>
+    <string name="edittext_pref_optionalvalue">Default value</string>
     <string name="progress_dialog_indeterminate">Progress Dialog (Indeterminate)</string>
     <string name="progress_dialog_indeterminate">Progress Dialog (Indeterminate)</string>
     <string name="progress_dialog">Progress Dialog</string>
     <string name="progress_dialog">Progress Dialog</string>
     <string name="please_wait">Please wait…</string>
     <string name="please_wait">Please wait…</string>

+ 1 - 0
sample/src/main/res/xml/preferences.xml

@@ -18,6 +18,7 @@
         android:dialogTitle="@string/edittext_pref_dialogtitle"
         android:dialogTitle="@string/edittext_pref_dialogtitle"
         android:dialogMessage="@string/optional_dialog_message"
         android:dialogMessage="@string/optional_dialog_message"
         android:persistent="true"
         android:persistent="true"
+        android:defaultValue="@string/edittext_pref_optionalvalue"
         android:layout="@layout/preference_custom" />
         android:layout="@layout/preference_custom" />
 
 
 </PreferenceScreen>
 </PreferenceScreen>