├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── scopes │ └── scope_settings.xml └── vcs.xml ├── LICENSE ├── MaterialDialog.iml ├── MaterialPreferenceCompat.iml ├── README.md ├── art ├── kitkat-1.png ├── kitkat.png ├── lollipop-1.png └── lollipop.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── library.iml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── moe │ │ └── feng │ │ └── materialcompat │ │ └── preference │ │ ├── EditTextPreferenceCompat.java │ │ ├── ListPreferenceCompat.java │ │ ├── MultiSelectListPreferenceCompat.java │ │ └── SwitchPreferenceCompat.java │ └── res │ ├── layout │ ├── pref_layout_edittext.xml │ └── pref_widget_switch.xml │ └── values │ └── dimens.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── sample.iml └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── moe │ │ └── feng │ │ └── materialcompat │ │ └── sample │ │ ├── HomeFragment.java │ │ └── SettingsActivity.java │ └── res │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_settings.xml │ ├── values-zh-rCN │ └── strings.xml │ ├── values-zh-rTW │ └── strings.xml │ ├── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── pref_home.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MaterialPreferenceCompat -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/LICENSE -------------------------------------------------------------------------------- /MaterialDialog.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /MaterialPreferenceCompat.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/README.md -------------------------------------------------------------------------------- /art/kitkat-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/art/kitkat-1.png -------------------------------------------------------------------------------- /art/kitkat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/art/kitkat.png -------------------------------------------------------------------------------- /art/lollipop-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/art/lollipop-1.png -------------------------------------------------------------------------------- /art/lollipop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/art/lollipop.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.1.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed May 20 13:59:06 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'maven' 3 | 4 | android { 5 | compileSdkVersion 22 6 | buildToolsVersion "22.0.1" 7 | 8 | defaultConfig { 9 | // applicationId "moe.feng.materialcompat" 10 | minSdkVersion 15 11 | targetSdkVersion 22 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | 16 | compileOptions { 17 | sourceCompatibility JavaVersion.VERSION_1_7 18 | targetCompatibility JavaVersion.VERSION_1_7 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | group = 'moe.feng.materialcompat' 29 | version = '1.0.0' 30 | def artifactId = 'library' 31 | 32 | def repositoryUrl 33 | if (has('repoDir')) { 34 | repositoryUrl = "file://$repoDir" 35 | } else { 36 | repositoryUrl = "file://$buildDir/repo/" 37 | } 38 | 39 | afterEvaluate { project -> 40 | uploadArchives { 41 | repositories { 42 | mavenDeployer { 43 | repository(url: repositoryUrl) 44 | pom.artifactId = artifactId 45 | } 46 | } 47 | } 48 | 49 | task androidJavadocs(type: Javadoc) { 50 | source = android.sourceSets.main.java.srcDirs.toString() 51 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 52 | options.links("http://docs.oracle.com/javase/7/docs/api/"); 53 | options.linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference" 54 | exclude '**/BuildConfig.java' 55 | exclude '**/R.java' 56 | failOnError = false 57 | } 58 | 59 | task androidJavadocsJar(type: Jar) { 60 | classifier = 'javadoc' 61 | from androidJavadocs.destinationDir.toString() 62 | } 63 | task androidSourcesJar(type: Jar) { 64 | classifier = 'sources' 65 | from android.sourceSets.main.java.toString() 66 | } 67 | 68 | artifacts { 69 | archives androidSourcesJar 70 | archives androidJavadocsJar 71 | } 72 | } 73 | 74 | 75 | dependencies { 76 | compile fileTree(dir: 'libs', include: ['*.jar']) 77 | compile 'com.android.support:appcompat-v7:22.1.0' 78 | } 79 | -------------------------------------------------------------------------------- /library/library.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:/Feng/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /library/src/main/java/moe/feng/materialcompat/preference/EditTextPreferenceCompat.java: -------------------------------------------------------------------------------- 1 | package moe.feng.materialcompat.preference; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.content.res.ColorStateList; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | import android.preference.EditTextPreference; 10 | import android.preference.PreferenceManager; 11 | import android.support.annotation.NonNull; 12 | import android.support.v7.app.AlertDialog; 13 | import android.support.v7.widget.AppCompatEditText; 14 | import android.util.AttributeSet; 15 | import android.view.LayoutInflater; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import android.view.ViewParent; 19 | import android.view.Window; 20 | import android.view.WindowManager; 21 | import android.widget.EditText; 22 | import android.widget.LinearLayout; 23 | import android.widget.TextView; 24 | 25 | import java.lang.reflect.Method; 26 | 27 | import moe.feng.materialcompat.R; 28 | 29 | /** 30 | * @author Fung Jichun 某烧饼 (fython@163.com) 31 | */ 32 | public class EditTextPreferenceCompat extends EditTextPreference { 33 | 34 | private int mColor = 0; 35 | private AlertDialog mDialog; 36 | private EditText mEditText; 37 | 38 | public EditTextPreferenceCompat(Context context, AttributeSet attrs) { 39 | super(context, attrs); 40 | int fallback = 0; 41 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 42 | fallback = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorAccent}).getColor(0, 0); 43 | } 44 | mColor = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorAccent}).getColor(0, fallback); 45 | 46 | mEditText = new AppCompatEditText(context, attrs); 47 | mEditText.setEnabled(true); 48 | } 49 | 50 | public EditTextPreferenceCompat(Context context) { 51 | this(context, null); 52 | } 53 | 54 | @Override 55 | protected void onAddEditTextToDialogView(@NonNull View view, @NonNull EditText editText) { 56 | if (editText.getParent() != null) { 57 | ((ViewGroup) mEditText.getParent()).removeView(editText); 58 | } 59 | ((ViewGroup) view).addView( 60 | editText, 61 | new LinearLayout.LayoutParams( 62 | ViewGroup.LayoutParams.MATCH_PARENT, 63 | ViewGroup.LayoutParams.WRAP_CONTENT 64 | ) 65 | ); 66 | } 67 | 68 | @Override 69 | protected void onBindDialogView(@NonNull View view) { 70 | mEditText.setText(""); 71 | if (getText() != null) { 72 | mEditText.setText(getText()); 73 | } 74 | ViewParent oldParent = mEditText.getParent(); 75 | if (oldParent != view) { 76 | if (oldParent != null) { 77 | ((ViewGroup) oldParent).removeView(mEditText); 78 | } 79 | onAddEditTextToDialogView(view, mEditText); 80 | } 81 | } 82 | 83 | @Override 84 | protected void onDialogClosed(boolean positiveResult) { 85 | if (positiveResult) { 86 | String value = mEditText.getText().toString(); 87 | if (callChangeListener(value)) { 88 | setText(value); 89 | } 90 | } 91 | } 92 | 93 | @Override 94 | public EditText getEditText() { 95 | return mEditText; 96 | } 97 | 98 | @Override 99 | public Dialog getDialog() { 100 | return mDialog; 101 | } 102 | 103 | @Override 104 | protected void showDialog(Bundle state) { 105 | AlertDialog.Builder mBuilder = new AlertDialog.Builder(getContext()) 106 | .setTitle(getDialogTitle()) 107 | .setIcon(getDialogIcon()) 108 | .setPositiveButton(getPositiveButtonText(), callback) 109 | .setNegativeButton(getNegativeButtonText(), null) 110 | .setOnDismissListener(this); 111 | 112 | View layout = LayoutInflater.from(getContext()).inflate(R.layout.pref_layout_edittext, null); 113 | onBindDialogView(layout); 114 | 115 | ColorStateList editTextColorStateList = createEditTextColorStateList(mEditText.getContext(), mColor); 116 | if (mEditText instanceof AppCompatEditText) { 117 | ((AppCompatEditText) mEditText).setSupportBackgroundTintList(editTextColorStateList); 118 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 119 | mEditText.setBackgroundTintList(editTextColorStateList); 120 | } 121 | 122 | TextView message = (TextView) layout.findViewById(android.R.id.message); 123 | if (getDialogMessage() != null && getDialogMessage().toString().length() > 0) { 124 | message.setVisibility(View.VISIBLE); 125 | message.setText(getDialogMessage()); 126 | } else { 127 | message.setVisibility(View.GONE); 128 | } 129 | mBuilder.setView(layout); 130 | 131 | PreferenceManager pm = getPreferenceManager(); 132 | try { 133 | Method method = pm.getClass().getDeclaredMethod( 134 | "registerOnActivityDestroyListener", 135 | PreferenceManager.OnActivityDestroyListener.class); 136 | method.setAccessible(true); 137 | method.invoke(pm, this); 138 | } catch (Exception e) { 139 | e.printStackTrace(); 140 | } 141 | 142 | mDialog = mBuilder.create(); 143 | if (state != null) { 144 | mDialog.onRestoreInstanceState(state); 145 | } 146 | requestInputMethod(mDialog); 147 | 148 | mDialog.show(); 149 | } 150 | 151 | private final AlertDialog.OnClickListener callback = new DialogInterface.OnClickListener() { 152 | @Override 153 | public void onClick(DialogInterface dialogInterface, int i) { 154 | String value = mEditText.getText().toString(); 155 | if (callChangeListener(value) && isPersistent()) { 156 | setText(value); 157 | } 158 | } 159 | }; 160 | 161 | private void requestInputMethod(Dialog dialog) { 162 | Window window = dialog.getWindow(); 163 | window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 164 | } 165 | 166 | @Override 167 | public void onActivityDestroy() { 168 | super.onActivityDestroy(); 169 | if (mDialog != null && mDialog.isShowing()) { 170 | mDialog.dismiss(); 171 | } 172 | } 173 | 174 | private static ColorStateList createEditTextColorStateList(Context context, int color) { 175 | int[][] states = new int[3][]; 176 | int[] colors = new int[3]; 177 | states[0] = new int[]{-android.R.attr.state_enabled}; 178 | colors[0] = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorControlNormal}).getColor(0, 0); 179 | states[1] = new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused}; 180 | colors[1] = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorControlNormal}).getColor(0, 0); 181 | states[2] = new int[]{}; 182 | colors[2] = color; 183 | return new ColorStateList(states, colors); 184 | } 185 | 186 | } -------------------------------------------------------------------------------- /library/src/main/java/moe/feng/materialcompat/preference/ListPreferenceCompat.java: -------------------------------------------------------------------------------- 1 | package moe.feng.materialcompat.preference; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.preference.ListPreference; 9 | import android.preference.PreferenceManager; 10 | import android.support.v7.app.AlertDialog; 11 | import android.text.TextUtils; 12 | import android.util.AttributeSet; 13 | import android.view.View; 14 | import android.widget.SimpleAdapter; 15 | 16 | import java.lang.reflect.Method; 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | 20 | import moe.feng.materialcompat.R; 21 | 22 | /** 23 | * @author Fung Jichun 某烧饼 (fython@163.com) 24 | */ 25 | public class ListPreferenceCompat extends ListPreference { 26 | 27 | private Context mContext; 28 | private AlertDialog mDialog; 29 | 30 | public ListPreferenceCompat(Context context) { 31 | super(context); 32 | mContext = context; 33 | } 34 | 35 | public ListPreferenceCompat(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | mContext = context; 38 | } 39 | 40 | @Override 41 | public void setEntries(CharSequence[] entries) { 42 | super.setEntries(entries); 43 | if (mDialog != null) { 44 | ArrayList> listItems = new ArrayList<>(); 45 | for (CharSequence entry : entries) { 46 | HashMap map = new HashMap<>(); 47 | map.put("item", entry); 48 | listItems.add(map); 49 | } 50 | mDialog.getListView().setAdapter(new SimpleAdapter( 51 | mContext, 52 | listItems, 53 | R.layout.select_dialog_singlechoice_material, 54 | new String[] {"item"}, 55 | new int[]{android.R.id.text1} 56 | )); 57 | } 58 | } 59 | 60 | @Override 61 | public Dialog getDialog() { 62 | return mDialog; 63 | } 64 | 65 | @Override 66 | protected void showDialog(Bundle state) { 67 | if (getEntries() == null || getEntryValues() == null) { 68 | throw new IllegalStateException("ListPreferenceCompat requires an entries array and an entryValues array."); 69 | } 70 | 71 | int preselect = findIndexOfValue(getValue()); 72 | AlertDialog.Builder builder = new AlertDialog.Builder(mContext) 73 | .setTitle(getDialogTitle()) 74 | .setMessage(getDialogMessage()) 75 | .setIcon(getDialogIcon()) 76 | .setNegativeButton(getNegativeButtonText(), null) 77 | .setSingleChoiceItems(getEntries(), preselect, new DialogInterface.OnClickListener() { 78 | @Override 79 | public void onClick(DialogInterface dialogInterface, int i) { 80 | if (i >= 0 && getEntryValues() != null) { 81 | String value = getEntryValues()[i].toString(); 82 | if (callChangeListener(value) && isPersistent()) { 83 | setValue(value); 84 | } 85 | } 86 | dialogInterface.dismiss(); 87 | } 88 | }); 89 | 90 | final View contentView = onCreateDialogView(); 91 | if (contentView != null) { 92 | onBindDialogView(contentView); 93 | builder.setView(contentView); 94 | } else { 95 | builder.setMessage(getDialogMessage()); 96 | } 97 | 98 | PreferenceManager pm = getPreferenceManager(); 99 | try { 100 | Method method = pm.getClass().getDeclaredMethod( 101 | "registerOnActivityDestroyListener", 102 | PreferenceManager.OnActivityDestroyListener.class); 103 | method.setAccessible(true); 104 | method.invoke(pm, this); 105 | } catch (Exception e) { 106 | e.printStackTrace(); 107 | } 108 | 109 | mDialog = builder.create(); 110 | if (state != null) { 111 | mDialog.onRestoreInstanceState(state); 112 | } 113 | mDialog.show(); 114 | } 115 | 116 | @Override 117 | public void onActivityDestroy() { 118 | super.onActivityDestroy(); 119 | if (mDialog != null && mDialog.isShowing()) { 120 | mDialog.dismiss(); 121 | } 122 | } 123 | 124 | @Override 125 | public void setValue(String value) { 126 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 127 | super.setValue(value); 128 | } else { 129 | String oldValue = getValue(); 130 | super.setValue(value); 131 | if (!TextUtils.equals(value, oldValue)) { 132 | notifyChanged(); 133 | } 134 | } 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /library/src/main/java/moe/feng/materialcompat/preference/MultiSelectListPreferenceCompat.java: -------------------------------------------------------------------------------- 1 | package moe.feng.materialcompat.preference; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.os.Bundle; 7 | import android.preference.MultiSelectListPreference; 8 | import android.preference.PreferenceManager; 9 | import android.support.v7.app.AlertDialog; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.widget.SimpleAdapter; 13 | 14 | import java.lang.reflect.Method; 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.Set; 18 | 19 | import moe.feng.materialcompat.R; 20 | 21 | /** 22 | * @author Fung Jichun 某烧饼 (fython@163.com) 23 | */ 24 | public class MultiSelectListPreferenceCompat extends MultiSelectListPreference { 25 | 26 | private Context mContext; 27 | private AlertDialog mDialog; 28 | 29 | public MultiSelectListPreferenceCompat(Context context) { 30 | this(context, null); 31 | this.mContext = context; 32 | } 33 | 34 | public MultiSelectListPreferenceCompat(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | this.mContext = context; 37 | } 38 | 39 | @Override 40 | public void setEntries(CharSequence[] entries) { 41 | super.setEntries(entries); 42 | if (mDialog != null) { 43 | ArrayList> listItems = new ArrayList<>(); 44 | for (CharSequence entry : entries) { 45 | HashMap map = new HashMap<>(); 46 | map.put("item", entry); 47 | listItems.add(map); 48 | } 49 | mDialog.getListView().setAdapter(new SimpleAdapter( 50 | mContext, 51 | listItems, 52 | R.layout.select_dialog_singlechoice_material, 53 | new String[] {"item"}, 54 | new int[]{android.R.id.text1} 55 | )); 56 | } 57 | } 58 | 59 | @Override 60 | public Dialog getDialog() { 61 | return mDialog; 62 | } 63 | 64 | @Override 65 | protected void showDialog(Bundle state) { 66 | boolean[] b = new boolean[getEntryValues().length]; 67 | for (String s : getValues()) { 68 | b [findIndexOfValue(s)] = findIndexOfValue(s) >= 0; 69 | } 70 | 71 | AlertDialog.Builder builder = new AlertDialog.Builder(mContext) 72 | .setTitle(getDialogTitle()) 73 | .setMessage(getDialogMessage()) 74 | .setIcon(getDialogIcon()) 75 | .setNegativeButton(getNegativeButtonText(), null) 76 | .setPositiveButton(getPositiveButtonText(), null) 77 | .setMultiChoiceItems(getEntries(), b, new DialogInterface.OnMultiChoiceClickListener() { 78 | @Override 79 | public void onClick(DialogInterface dialogInterface, int i, boolean b) { 80 | final Set values = getValues(); 81 | if (b) { 82 | values.add(getEntryValues()[i].toString()); 83 | } else { 84 | values.remove(getEntryValues()[i].toString()); 85 | } 86 | if (callChangeListener(values)) { 87 | setValues(values); 88 | } 89 | } 90 | }) 91 | .setOnDismissListener(this); 92 | 93 | final View contentView = onCreateDialogView(); 94 | if (contentView != null) { 95 | onBindDialogView(contentView); 96 | builder.setView(contentView); 97 | } else { 98 | builder.setMessage(getDialogMessage()); 99 | } 100 | 101 | PreferenceManager pm = getPreferenceManager(); 102 | try { 103 | Method method = pm.getClass().getDeclaredMethod( 104 | "registerOnActivityDestroyListener", 105 | PreferenceManager.OnActivityDestroyListener.class); 106 | method.setAccessible(true); 107 | method.invoke(pm, this); 108 | } catch (Exception e) { 109 | e.printStackTrace(); 110 | } 111 | 112 | mDialog = builder.create(); 113 | if (state != null) 114 | mDialog.onRestoreInstanceState(state); 115 | mDialog.show(); 116 | } 117 | 118 | @Override 119 | public void onActivityDestroy() { 120 | super.onActivityDestroy(); 121 | if (mDialog != null && mDialog.isShowing()) { 122 | mDialog.dismiss(); 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /library/src/main/java/moe/feng/materialcompat/preference/SwitchPreferenceCompat.java: -------------------------------------------------------------------------------- 1 | package moe.feng.materialcompat.preference; 2 | 3 | import android.content.Context; 4 | import android.preference.CheckBoxPreference; 5 | import android.util.AttributeSet; 6 | 7 | import moe.feng.materialcompat.R; 8 | 9 | /** 10 | * @author Fung Jichun 某烧饼 (fython@163.com) 11 | */ 12 | public class SwitchPreferenceCompat extends CheckBoxPreference { 13 | 14 | public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr) { 15 | super(context, attrs, defStyleAttr); 16 | init(); 17 | } 18 | 19 | public SwitchPreferenceCompat(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | init(); 22 | } 23 | 24 | public SwitchPreferenceCompat(Context context) { 25 | super(context); 26 | init(); 27 | } 28 | 29 | private void init() { 30 | setWidgetLayoutResource(R.layout.pref_widget_switch); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /library/src/main/res/layout/pref_layout_edittext.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 24 | 25 | -------------------------------------------------------------------------------- /library/src/main/res/layout/pref_widget_switch.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /library/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24dp 5 | 8dp 6 | 8dp 7 | 8 | 16sp 9 | 10 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "moe.feng.materialcompat.sample" 9 | minSdkVersion 15 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_7 17 | targetCompatibility JavaVersion.VERSION_1_7 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | compile 'com.android.support:appcompat-v7:22.1.0' 30 | compile 'com.android.support:support-v4:22.1.0' 31 | compile project(':library') 32 | } 33 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in G:/adt/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/src/main/java/moe/feng/materialcompat/sample/HomeFragment.java: -------------------------------------------------------------------------------- 1 | package moe.feng.materialcompat.sample; 2 | 3 | import android.os.Bundle; 4 | import android.preference.Preference; 5 | import android.preference.PreferenceFragment; 6 | import android.widget.Toast; 7 | 8 | import moe.feng.materialcompat.preference.ListPreferenceCompat; 9 | import moe.feng.materialcompat.preference.MultiSelectListPreferenceCompat; 10 | import moe.feng.materialcompat.preference.SwitchPreferenceCompat; 11 | 12 | public class HomeFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener { 13 | 14 | SwitchPreferenceCompat mSwitchPref; 15 | ListPreferenceCompat mListPref; 16 | MultiSelectListPreferenceCompat mMultiSelectListPref; 17 | 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | addPreferencesFromResource(R.xml.pref_home); 22 | 23 | mSwitchPref = (SwitchPreferenceCompat) findPreference("loli_is_justice"); 24 | mListPref = (ListPreferenceCompat) findPreference("loli_choice"); 25 | mMultiSelectListPref = (MultiSelectListPreferenceCompat) findPreference("type_choice"); 26 | 27 | mSwitchPref.setOnPreferenceChangeListener(this); 28 | mListPref.setOnPreferenceChangeListener(this); 29 | mMultiSelectListPref.setOnPreferenceChangeListener(this); 30 | 31 | mListPref.setSummary(mListPref.getEntry()); 32 | } 33 | 34 | @Override 35 | public boolean onPreferenceChange(Preference preference, Object o) { 36 | if (preference == mSwitchPref) { 37 | Boolean b = (Boolean) o; 38 | mSwitchPref.setSummary(b ? R.string.pref_loli_is_justice_summary_on 39 | : R.string.pref_loli_is_justice_summary_off); 40 | return true; 41 | } 42 | if (preference == mListPref) { 43 | Toast.makeText( 44 | getActivity().getApplicationContext(), 45 | "You selected No." + mListPref.findIndexOfValue(mListPref.getValue()) + " LORI" + 46 | ", value: " + mListPref.getValue() + ", entry of value: " + mListPref.getEntry(), 47 | Toast.LENGTH_SHORT 48 | ).show(); 49 | mListPref.setSummary(mListPref.getEntry()); 50 | return true; 51 | } 52 | if (preference == mMultiSelectListPref) { 53 | String showValues = listArray(mMultiSelectListPref.getValues().toArray()); 54 | String showEntries = ""; 55 | for (int i = 0; i < mMultiSelectListPref.getEntryValues().length; i++) { 56 | if (mMultiSelectListPref.getValues().contains(mMultiSelectListPref.getEntryValues()[i])) { 57 | showEntries += mMultiSelectListPref.getEntries() [i] + ","; 58 | } 59 | } 60 | if (showEntries.lastIndexOf(",") != -1) { 61 | showEntries = showEntries.substring(0, showEntries.lastIndexOf(",")); 62 | } 63 | Toast.makeText( 64 | getActivity().getApplicationContext(), 65 | "You selected values: " + showValues + 66 | ", selected entries: " + showEntries, 67 | Toast.LENGTH_SHORT 68 | ).show(); 69 | mMultiSelectListPref.setSummary(showEntries); 70 | return true; 71 | } 72 | return false; 73 | } 74 | 75 | private String listArray(Object[] array) { 76 | StringBuffer sb = new StringBuffer(); 77 | for (Object obj : array) { 78 | sb.append(obj); 79 | sb.append(","); 80 | } 81 | if (sb.lastIndexOf(",") != -1) { 82 | sb.deleteCharAt(sb.length() - 1); 83 | } 84 | return sb.toString(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /sample/src/main/java/moe/feng/materialcompat/sample/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | package moe.feng.materialcompat.sample; 2 | 3 | import android.app.Fragment; 4 | import android.content.Intent; 5 | import android.os.Build; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.Toolbar; 9 | import android.view.MenuItem; 10 | 11 | public class SettingsActivity extends AppCompatActivity { 12 | 13 | private int flag; 14 | 15 | public static final int FLAG_HOME = 0; 16 | public static final String EXTRA_FLAG = "flag"; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_settings); 22 | 23 | Intent intent = getIntent(); 24 | flag = intent.getIntExtra(EXTRA_FLAG, FLAG_HOME); 25 | 26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 28 | toolbar.setElevation(getResources().getDimension(R.dimen.toolbar_elevation)); 29 | } 30 | setSupportActionBar(toolbar); 31 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 32 | 33 | Fragment fragment; 34 | switch (flag) { 35 | case FLAG_HOME: 36 | default: 37 | fragment = new HomeFragment(); 38 | break; 39 | } 40 | getFragmentManager().beginTransaction() 41 | .replace(R.id.content, fragment) 42 | .commit(); 43 | } 44 | 45 | @Override 46 | public boolean onOptionsItemSelected(MenuItem item) { 47 | if (item.getItemId() == android.R.id.home) { 48 | super.onBackPressed(); 49 | return true; 50 | } 51 | return super.onOptionsItemSelected(item); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/MaterialPreferenceCompat/65dedd2acfc223a6708686b1dc52013d76e17aef/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /sample/src/main/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MPC 范例 4 | 5 | 你好,世界! 6 | 萝莉即是正义 7 | 是的!萝莉赛高! 8 | 不!我不属于这个世界。 9 | 10 | 哪个萝莉你最喜欢? 11 | 12 | 宫内莲华 (喵帕斯!) 13 | 神崎·H·亚里亚 14 | 琴石奈瑠 15 | 逢坂大河 16 | 17 | 18 | 0 19 | 1 20 | 2 21 | 3 22 | 23 | 24 | 你喜欢哪种萝莉? 25 | 26 | 双马尾 27 | 28 | 幼女体形 29 | 傲娇 30 | 兽耳 31 | 32 | 33 | 0 34 | 1 35 | 2 36 | 3 37 | 4 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sample/src/main/res/values-zh-rTW/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MPC 範例 4 | 5 | 你好,世界! 6 | 蘿莉即是正義 7 | 是的!蘿莉最棒! 8 | 不!我不歸屬于這個世界。 9 | 10 | 哪個蘿莉你最喜歡? 11 | 12 | 宮內蓮華 (喵帕斯!) 13 | 神崎·H·亞利亞 14 | 琴石奈瑠 15 | 逢阪大河 16 | 17 | 18 | 0 19 | 1 20 | 2 21 | 3 22 | 23 | 24 | 你喜歡哪種蘿莉? 25 | 26 | 雙馬辮 27 | 28 | 幼女體型 29 | 傲嬌 30 | 獸耳 31 | 32 | 33 | 0 34 | 1 35 | 2 36 | 3 37 | 4 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MPC Sample 4 | 5 | Hello, world! 6 | LORI is justice! 7 | Yes! LORI is best! 8 | No! I am not the human in this world. 9 | 10 | Which lori do you like best? 11 | 12 | Miyauchi Renge (Miao pa su!) 13 | Kanzaki H Aria 14 | Kotoishi Naru 15 | Aisaka Taiga 16 | 17 | 18 | 0 19 | 1 20 | 2 21 | 3 22 | 23 | 24 | Which types of lori do you like? 25 | 26 | Double tail 27 | Moe 28 | Young girls body 29 | Playfully 30 | Animal ears 31 | 32 | 33 | 0 34 | 1 35 | 2 36 | 3 37 | 4 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample/src/main/res/xml/pref_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 19 | 20 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' 2 | --------------------------------------------------------------------------------