├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── app ├── .gitignore ├── libs │ └── nineoldandroids-2.4.0.jar ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── attrs.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ └── colors.xml │ │ │ ├── drawable-nodpi │ │ │ │ ├── skin_main_bg.jpg │ │ │ │ ├── skin_main_bg_red.jpg │ │ │ │ ├── skin_left_menu_icon.png │ │ │ │ ├── skin_main_bg_green.jpg │ │ │ │ ├── skin_left_menu_icon_red.png │ │ │ │ └── skin_left_menu_icon_green.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ └── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── item.xml │ │ │ │ └── layout_menu.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── zhy │ │ │ │ └── skinchangenow │ │ │ │ ├── sample │ │ │ │ └── MyApplication.java │ │ │ │ ├── MenuLeftFragment.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── zhy │ │ └── skinchangenow │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── build.gradle └── app.iml ├── plugin ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ └── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── zhy │ │ └── plugin │ │ └── ApplicationTest.java ├── build.gradle ├── proguard-rules.pro └── plugin.iml ├── changeskin ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── zhy │ │ │ │ └── changeskin │ │ │ │ ├── callback │ │ │ │ ├── ISkinChangedListener.java │ │ │ │ └── ISkinChangingCallback.java │ │ │ │ ├── utils │ │ │ │ ├── L.java │ │ │ │ └── PrefUtils.java │ │ │ │ ├── constant │ │ │ │ └── SkinConfig.java │ │ │ │ ├── attr │ │ │ │ ├── SkinAttr.java │ │ │ │ ├── SkinView.java │ │ │ │ ├── SkinAttrSupport.java │ │ │ │ └── SkinAttrType.java │ │ │ │ ├── ResourceManager.java │ │ │ │ ├── base │ │ │ │ └── BaseSkinActivity.java │ │ │ │ └── SkinManager.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── zhy │ │ └── changeskin │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── build.gradle └── changeskin.iml ├── settings.gradle ├── lalala.gif ├── skin1.gif ├── skin_2.png ├── skin_sc.gif ├── night_plugin.apk ├── skin_usage_02.png ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── .gitignore ├── .gitignore ├── gradle.properties ├── SkinChangeNow.iml ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /.idea/.name: -------------------------------------------------------------------------------- 1 | SkinChangeNow -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /changeskin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':changeskin' 2 | -------------------------------------------------------------------------------- /lalala.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/lalala.gif -------------------------------------------------------------------------------- /skin1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/skin1.gif -------------------------------------------------------------------------------- /skin_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/skin_2.png -------------------------------------------------------------------------------- /skin_sc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/skin_sc.gif -------------------------------------------------------------------------------- /night_plugin.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/night_plugin.apk -------------------------------------------------------------------------------- /skin_usage_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/skin_usage_02.png -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /plugin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | plugin 3 | 4 | -------------------------------------------------------------------------------- /changeskin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | changeSkin 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/libs/nineoldandroids-2.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/libs/nineoldandroids-2.4.0.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/skin_main_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/drawable-nodpi/skin_main_bg.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /plugin/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/plugin/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /plugin/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/plugin/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /plugin/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/plugin/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /plugin/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/plugin/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/skin_main_bg_red.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/drawable-nodpi/skin_main_bg_red.jpg -------------------------------------------------------------------------------- /gradle/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | *Bak 6 | *BAK 7 | .DS_Store 8 | /build 9 | /captures 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/skin_left_menu_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/drawable-nodpi/skin_left_menu_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/skin_main_bg_green.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/drawable-nodpi/skin_main_bg_green.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/skin_left_menu_icon_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/drawable-nodpi/skin_left_menu_icon_red.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/skin_left_menu_icon_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/ChangeSkin/HEAD/app/src/main/res/drawable-nodpi/skin_left_menu_icon_green.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | *Bak 6 | *BAK 7 | .DS_Store 8 | /build 9 | /captures 10 | /imooc_changeskin 11 | /imooc_changeskin/* 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SkinChangeNow 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /plugin/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/callback/ISkinChangedListener.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.callback; 2 | 3 | /** 4 | * Created by zhy on 15/9/22. 5 | */ 6 | public interface ISkinChangedListener 7 | { 8 | void onSkinChanged(); 9 | } 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 29 00:03:44 GMT+08:00 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /changeskin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /plugin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/utils/L.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.utils; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by zhy on 15/9/23. 7 | */ 8 | public class L 9 | { 10 | private static final String TAG = "Skin"; 11 | private static boolean debug = false; 12 | 13 | public static void e(String msg) 14 | { 15 | if (debug) 16 | Log.e(TAG, msg); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /plugin/src/androidTest/java/com/zhy/plugin/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhy.plugin; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/com/zhy/skinchangenow/sample/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhy.skinchangenow.sample; 2 | 3 | import android.app.Application; 4 | 5 | import com.zhy.changeskin.SkinManager; 6 | 7 | 8 | /** 9 | * Created by zhy on 15/9/22. 10 | */ 11 | public class MyApplication extends Application 12 | { 13 | @Override 14 | public void onCreate() 15 | { 16 | super.onCreate(); 17 | SkinManager.getInstance().init(this); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zhy/skinchangenow/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhy.skinchangenow; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /changeskin/src/androidTest/java/com/zhy/changeskin/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase 10 | { 11 | public ApplicationTest() 12 | { 13 | super(Application.class); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ffffffff 4 | #ff000000 5 | 6 | 7 | 8 | #ff0000 9 | #ff0000 10 | 11 | 12 | #ff00ff00 13 | #ff00ff00 14 | 15 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/constant/SkinConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.constant; 2 | 3 | /** 4 | * Created by zhy on 15/9/22. 5 | */ 6 | public class SkinConfig 7 | { 8 | public static final String PREF_NAME = "skin_plugin_pref"; 9 | public static final String KEY_PLUGIN_PATH = "key_plugin_path"; 10 | public static final String KEY_PLUGIN_PKG = "key_plugin_pkg"; 11 | public static final String KEY_PLUGIN_SUFFIX = "key_plugin_suffix"; 12 | 13 | public static final String ATTR_PREFIX="skin"; 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/attr/SkinAttr.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/9/22. 7 | */ 8 | public class SkinAttr 9 | { 10 | String resName; 11 | SkinAttrType attrType; 12 | 13 | 14 | public SkinAttr(SkinAttrType attrType, String resName) 15 | { 16 | this.resName = resName; 17 | this.attrType = attrType; 18 | } 19 | 20 | public void apply(View view) 21 | { 22 | attrType.apply(view, resName); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.0 rc3" 6 | 7 | defaultConfig { 8 | applicationId "com.zhy.plugin" 9 | minSdkVersion 10 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:23.0.1' 25 | } 26 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/attr/SkinView.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by zhy on 15/9/22. 9 | */ 10 | public class SkinView 11 | { 12 | // SoftReference viewRef; 13 | View view ; 14 | List attrs; 15 | 16 | public SkinView(View view, List skinAttrs) 17 | { 18 | this.view = view; 19 | this.attrs = skinAttrs; 20 | } 21 | 22 | public void apply() 23 | { 24 | // View view = viewRef.get(); 25 | if (view == null) return; 26 | 27 | for (SkinAttr attr : attrs) 28 | { 29 | attr.apply(view); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/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 /Users/zhy/android/sdk/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /plugin/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 /Users/zhy/android/sdk/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /changeskin/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 /Users/zhy/android/sdk/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 14 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.zhy.skinchangenow" 9 | minSdkVersion 10 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile files('libs/nineoldandroids-2.4.0.jar') 25 | compile project(':changeskin') 26 | compile 'com.android.support:support-v4:23.0.1' 27 | compile 'com.android.support:appcompat-v7:23.0.1' 28 | } 29 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/callback/ISkinChangingCallback.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.callback; 2 | 3 | /** 4 | * Created by zhy on 15/9/22. 5 | */ 6 | public interface ISkinChangingCallback 7 | { 8 | void onStart(); 9 | 10 | void onError(Exception e); 11 | 12 | void onComplete(); 13 | 14 | public static DefaultSkinChangingCallback DEFAULT_SKIN_CHANGING_CALLBACK = new DefaultSkinChangingCallback(); 15 | 16 | public class DefaultSkinChangingCallback implements ISkinChangingCallback 17 | { 18 | @Override 19 | public void onStart() 20 | { 21 | 22 | } 23 | 24 | @Override 25 | public void onError(Exception e) 26 | { 27 | 28 | } 29 | 30 | @Override 31 | public void onComplete() 32 | { 33 | 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /SkinChangeNow.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 15 | 16 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 24 | 25 | 33 | 34 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/attr/SkinAttrSupport.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.attr; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.zhy.changeskin.constant.SkinConfig; 7 | import com.zhy.changeskin.utils.L; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by zhy on 15/9/23. 14 | */ 15 | public class SkinAttrSupport 16 | { 17 | public static List getSkinAttrs(AttributeSet attrs, Context context) 18 | { 19 | List skinAttrs = new ArrayList(); 20 | SkinAttr skinAttr = null; 21 | for (int i = 0; i < attrs.getAttributeCount(); i++) 22 | { 23 | String attrName = attrs.getAttributeName(i); 24 | String attrValue = attrs.getAttributeValue(i); 25 | 26 | SkinAttrType attrType = getSupprotAttrType(attrName); 27 | if (attrType == null) continue; 28 | 29 | if (attrValue.startsWith("@")) 30 | { 31 | int id = Integer.parseInt(attrValue.substring(1)); 32 | String entryName = context.getResources().getResourceEntryName(id); 33 | 34 | L.e("entryName = " + entryName); 35 | if (entryName.startsWith(SkinConfig.ATTR_PREFIX)) 36 | { 37 | skinAttr = new SkinAttr(attrType, entryName); 38 | skinAttrs.add(skinAttr); 39 | } 40 | } 41 | } 42 | return skinAttrs; 43 | 44 | } 45 | 46 | private static SkinAttrType getSupprotAttrType(String attrName) 47 | { 48 | for (SkinAttrType attrType : SkinAttrType.values()) 49 | { 50 | if (attrType.getAttrType().equals(attrName)) 51 | return attrType; 52 | } 53 | return null; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/utils/PrefUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.utils; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import com.zhy.changeskin.constant.SkinConfig; 7 | 8 | 9 | /** 10 | * Created by zhy on 15/9/22. 11 | */ 12 | public class PrefUtils 13 | { 14 | private Context mContext; 15 | 16 | public PrefUtils(Context context) 17 | { 18 | this.mContext = context; 19 | } 20 | 21 | public String getPluginPath() 22 | { 23 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 24 | return sp.getString(SkinConfig.KEY_PLUGIN_PATH, ""); 25 | } 26 | 27 | public String getSuffix() 28 | { 29 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 30 | return sp.getString(SkinConfig.KEY_PLUGIN_SUFFIX, ""); 31 | } 32 | 33 | public boolean clear() 34 | { 35 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 36 | return sp.edit().clear().commit(); 37 | } 38 | 39 | public void putPluginPath(String path) 40 | { 41 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 42 | sp.edit().putString(SkinConfig.KEY_PLUGIN_PATH, path).apply(); 43 | } 44 | 45 | public void putPluginPkg(String pkgName) 46 | { 47 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 48 | sp.edit().putString(SkinConfig.KEY_PLUGIN_PKG, pkgName).apply(); 49 | } 50 | 51 | public String getPluginPkgName() 52 | { 53 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 54 | return sp.getString(SkinConfig.KEY_PLUGIN_PKG, ""); 55 | } 56 | 57 | public void putPluginSuffix(String suffix) 58 | { 59 | SharedPreferences sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE); 60 | sp.edit().putString(SkinConfig.KEY_PLUGIN_SUFFIX, suffix).apply(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/attr/SkinAttrType.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.attr; 2 | 3 | import android.content.res.ColorStateList; 4 | import android.graphics.drawable.Drawable; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import com.zhy.changeskin.ResourceManager; 10 | import com.zhy.changeskin.SkinManager; 11 | 12 | 13 | /** 14 | * Created by zhy on 15/9/28. 15 | */ 16 | public enum SkinAttrType 17 | { 18 | BACKGROUD("background") 19 | { 20 | @Override 21 | public void apply(View view, String resName) 22 | { 23 | Drawable drawable = getResourceManager().getDrawableByName(resName); 24 | if (drawable == null) return; 25 | view.setBackgroundDrawable(drawable); 26 | } 27 | }, COLOR("textColor") 28 | { 29 | @Override 30 | public void apply(View view, String resName) 31 | { 32 | ColorStateList colorlist = getResourceManager().getColorStateList(resName); 33 | if (colorlist == null) return; 34 | ((TextView) view).setTextColor(colorlist); 35 | } 36 | }, SRC("src") 37 | { 38 | @Override 39 | public void apply(View view, String resName) 40 | { 41 | if (view instanceof ImageView) 42 | { 43 | Drawable drawable = getResourceManager().getDrawableByName(resName); 44 | if (drawable == null) return; 45 | ((ImageView) view).setImageDrawable(drawable); 46 | } 47 | 48 | } 49 | }; 50 | 51 | String attrType; 52 | 53 | SkinAttrType(String attrType) 54 | { 55 | this.attrType = attrType; 56 | } 57 | 58 | public String getAttrType() 59 | { 60 | return attrType; 61 | } 62 | 63 | 64 | public abstract void apply(View view, String resName); 65 | 66 | public ResourceManager getResourceManager() 67 | { 68 | return SkinManager.getInstance().getResourceManager(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/ResourceManager.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin; 2 | 3 | import android.content.res.ColorStateList; 4 | import android.content.res.Resources; 5 | import android.graphics.drawable.Drawable; 6 | import android.text.TextUtils; 7 | 8 | import com.zhy.changeskin.utils.L; 9 | 10 | /** 11 | * Created by zhy on 15/9/22. 12 | */ 13 | public class ResourceManager 14 | { 15 | private static final String DEFTYPE_DRAWABLE = "drawable"; 16 | private static final String DEFTYPE_COLOR = "color"; 17 | private Resources mResources; 18 | private String mPluginPackageName; 19 | private String mSuffix; 20 | 21 | 22 | public ResourceManager(Resources res, String pluginPackageName, String suffix) 23 | { 24 | mResources = res; 25 | mPluginPackageName = pluginPackageName; 26 | 27 | if (suffix == null) 28 | { 29 | suffix = ""; 30 | } 31 | mSuffix = suffix; 32 | 33 | } 34 | 35 | public Drawable getDrawableByName(String name) 36 | { 37 | try { 38 | name = appendSuffix(name); 39 | L.e("name = " + name); 40 | return mResources.getDrawable(mResources.getIdentifier(name, DEFTYPE_DRAWABLE, mPluginPackageName)); 41 | } catch (Resources.NotFoundException e) { 42 | try { 43 | return mResources.getDrawable(mResources.getIdentifier(name, DEFTYPE_COLOR, mPluginPackageName)); 44 | } catch (Resources.NotFoundException e2) { 45 | e.printStackTrace(); 46 | return null; 47 | } 48 | } 49 | } 50 | 51 | public int getColor(String name) 52 | { 53 | try 54 | { 55 | name = appendSuffix(name); 56 | L.e("name = " + name); 57 | return mResources.getColor(mResources.getIdentifier(name, DEFTYPE_COLOR, mPluginPackageName)); 58 | 59 | } catch (Resources.NotFoundException e) 60 | { 61 | e.printStackTrace(); 62 | return -1; 63 | } 64 | 65 | } 66 | 67 | public ColorStateList getColorStateList(String name) { 68 | try 69 | { 70 | name = appendSuffix(name); 71 | L.e("name = " + name); 72 | return mResources.getColorStateList(mResources.getIdentifier(name, DEFTYPE_COLOR, mPluginPackageName)); 73 | 74 | } catch (Resources.NotFoundException e) 75 | { 76 | e.printStackTrace(); 77 | return null; 78 | } 79 | 80 | } 81 | 82 | private String appendSuffix(String name) 83 | { 84 | if (!TextUtils.isEmpty(mSuffix)) 85 | return name += "_" + mSuffix; 86 | return name ; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.7 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhy/skinchangenow/MenuLeftFragment.java: -------------------------------------------------------------------------------- 1 | package com.zhy.skinchangenow; 2 | 3 | import android.os.Bundle; 4 | import android.os.Environment; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Toast; 10 | 11 | import com.zhy.changeskin.SkinManager; 12 | 13 | import java.io.File; 14 | 15 | public class MenuLeftFragment extends Fragment implements View.OnClickListener 16 | { 17 | private String mSkinPkgPath = Environment.getExternalStorageDirectory() + File.separator + "night_plugin.apk"; 18 | private View mInnerChange01; 19 | private View mInnerChange02; 20 | 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 23 | Bundle savedInstanceState) 24 | { 25 | return inflater.inflate(R.layout.layout_menu, container, false); 26 | } 27 | 28 | @Override 29 | public void onViewCreated(View view, Bundle savedInstanceState) 30 | { 31 | super.onViewCreated(view, savedInstanceState); 32 | 33 | mInnerChange01 = view.findViewById(R.id.id_rl_innerchange01); 34 | mInnerChange01.setOnClickListener(this); 35 | 36 | mInnerChange02 = view.findViewById(R.id.id_rl_innerchange02); 37 | mInnerChange02.setOnClickListener(this); 38 | 39 | view.findViewById(R.id.id_restore).setOnClickListener(new View.OnClickListener() 40 | { 41 | @Override 42 | public void onClick(View v) 43 | { 44 | com.zhy.changeskin.SkinManager.getInstance().removeAnySkin(); 45 | } 46 | }); 47 | 48 | view.findViewById(R.id.id_changeskin).setOnClickListener(new View.OnClickListener() 49 | { 50 | @Override 51 | public void onClick(View v) 52 | { 53 | com.zhy.changeskin.SkinManager.getInstance().changeSkin(mSkinPkgPath, "com.zhy.plugin", new com.zhy.changeskin.callback.ISkinChangingCallback() 54 | { 55 | @Override 56 | public void onStart() 57 | { 58 | } 59 | 60 | @Override 61 | public void onError(Exception e) 62 | { 63 | Toast.makeText(getActivity(), "换肤失败", Toast.LENGTH_SHORT).show(); 64 | } 65 | 66 | @Override 67 | public void onComplete() 68 | { 69 | Toast.makeText(getActivity(), "换肤成功", Toast.LENGTH_SHORT).show(); 70 | } 71 | }); 72 | } 73 | }); 74 | 75 | } 76 | 77 | /** 78 | * Called when a view has been clicked. 79 | * 80 | * @param v The view that was clicked. 81 | */ 82 | @Override 83 | public void onClick(View v) 84 | { 85 | switch (v.getId()) 86 | { 87 | case R.id.id_rl_innerchange01: 88 | SkinManager.getInstance().changeSkin("red"); 89 | break; 90 | case R.id.id_rl_innerchange02: 91 | SkinManager.getInstance().changeSkin("green"); 92 | break; 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /changeskin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | version = "3.0.0" 6 | 7 | android { 8 | compileSdkVersion 23 9 | buildToolsVersion "23.0.1" 10 | 11 | defaultConfig { 12 | minSdkVersion 10 13 | targetSdkVersion 23 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | compile 'com.android.support:appcompat-v7:23.0.1' 28 | compile 'com.android.support:support-v4:23.0.1' 29 | } 30 | 31 | def siteUrl = 'https://github.com/hongyangAndroid/ChangeSkin' // #CONFIG# // project homepage 32 | def gitUrl = 'https://github.com/hongyangAndroid/ChangeSkin.git' // #CONFIG# // project git 33 | group = "com.zhy" 34 | 35 | install { 36 | repositories.mavenInstaller { 37 | // This generates POM.xml with proper parameters 38 | pom { 39 | project { 40 | packaging 'aar' 41 | name 'changeSkin' // #CONFIG# // project title 42 | url siteUrl 43 | // Set your license 44 | licenses { 45 | license { 46 | name 'The Apache Software License, Version 2.0' 47 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 48 | } 49 | } 50 | developers { 51 | developer { 52 | id 'hongyangAndroid' // #CONFIG# // your user id (you can write your nickname) 53 | name 'ZhangHongyang' // #CONFIG# // your user name 54 | email '623565791@qq.com' // #CONFIG# // your email 55 | } 56 | } 57 | scm { 58 | connection gitUrl 59 | developerConnection gitUrl 60 | url siteUrl 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | task sourcesJar(type: Jar) { 68 | from android.sourceSets.main.java.srcDirs 69 | classifier = 'sources' 70 | } 71 | 72 | task javadoc(type: Javadoc) { 73 | source = android.sourceSets.main.java.srcDirs 74 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 75 | } 76 | 77 | task javadocJar(type: Jar, dependsOn: javadoc) { 78 | classifier = 'javadoc' 79 | from javadoc.destinationDir 80 | } 81 | 82 | artifacts { 83 | archives javadocJar 84 | archives sourcesJar 85 | } 86 | Properties properties = new Properties() 87 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 88 | bintray { 89 | user = properties.getProperty("bintray.user") 90 | key = properties.getProperty("bintray.apikey") 91 | configurations = ['archives'] 92 | pkg { 93 | repo = "maven" 94 | name = "changeSkin" // #CONFIG# project name in jcenter 95 | websiteUrl = siteUrl 96 | vcsUrl = gitUrl 97 | licenses = ["Apache-2.0"] 98 | publish = true 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChangeSkin 2 | 基于插件式的Android换肤框架,支持app内和或者外部插件式提供资源的换肤方案,无需重启Activity。 3 | 4 | 5 | - [致谢](#致谢) 6 | - [支持](#支持) 7 | - [Demo运行](#Demo运行) 8 | - [使用](#使用) 9 | - [声明](#声明) 10 | 11 | 12 | 13 | ## 致谢 14 | * [Android换肤技术总结](http://blog.zhaiyifan.cn/2015/09/10/Android%E6%8D%A2%E8%82%A4%E6%8A%80%E6%9C%AF%E6%80%BB%E7%BB%93/) 15 | * [github.com/fengjundev/Android-Skin-Loader](https://github.com/fengjundev/Android-Skin-Loader) 16 | * [App Development: How to Get the Right LayoutInflater](http://willowtreeapps.com/blog/app-development-how-to-get-the-right-layoutinflater/) 17 | * [LayoutInflater Factories](http://blog.bradcampbell.nz/layoutinflater-factories/) 18 | * [Optimizing CustomViews](https://sriramramani.wordpress.com/2012/07/22/optimizing-customviews/) 19 | * [https://github.com/bboyfeiyu/Colorful](https://github.com/bboyfeiyu/Colorful) 20 | 21 | ## 支持 22 | 23 | * 插件的方式提供资源 24 | * 应用内直接提供资源 25 | * 一个插件包提供一套或者多套皮肤 26 | * 应用内直接提供一套或者多套皮肤 27 | 28 | ## Demo运行 29 | 30 | 31 | 目前的demo,已经包含上述功能的测试。 32 | 33 | 下载[night_plugin.apk](night_plugin.apk)里面包含资源文件,放到手机或者模拟器SdCard的根目录。 34 | 35 | 然后import project,运行app。 36 | 37 | 运行效果图: 38 | 39 | 40 | 41 | 无需重启Activity,无缝换肤,资源均来自插件apk中。 42 | 43 | 44 | ## 使用 45 | 46 | 下载[changeskin](changeskin),作为module依赖至主项目,例如: 47 | 48 | ```xml 49 | dependencies { 50 | compile project(':changeskin') 51 | } 52 | ``` 53 | 54 | 或者直接添加依赖: 55 | 56 | ```xml 57 | dependencies { 58 | compile 'com.zhy:changeskin:3.0.0' 59 | } 60 | ``` 61 | ### (1)初始化 62 | 63 | #### 1、Application中初始化 64 | 在你的Application中,去初始化SkinManager,例如: 65 | 66 | ```java 67 | public class MyApplication extends Application 68 | { 69 | @Override 70 | public void onCreate() 71 | { 72 | super.onCreate(); 73 | SkinManager.getInstance().init(this); 74 | } 75 | } 76 | 77 | ``` 78 | 别忘了注册。 79 | 80 | ####2、继承BaseSkinActivity 81 | 让所有的需要换肤的界面的Activity,继承自`com.zhy.changeskin.base.BaseSkinActivity`。 82 | 83 | ####3、对于需要换肤的资源命名使用skin开头 84 | 85 | 比如你的某个控件的背景需要换肤: 86 | 87 | ```xml 88 | 92 | ``` 93 | 94 | 字体颜色: 95 | 96 | ```xml 97 | 100 | ``` 101 | 其他的类似。 102 | 103 | 接下来,针对插件式或者应用内准备皮肤资源即可。 104 | 105 | ### (2)插件式换肤 106 | 107 | #### 1、准备资源apk 108 | 109 | >只需要按规则定义下资源名称,然后几行代码就完成了换肤。 110 | 111 | 然后,单独准备一份插件apk,其实就是普通的项目,仅仅准备需要包含用到的资源即可。 112 | 113 | 例如: 114 | 115 | 116 | 117 | 搞成apk就不用说了吧。 118 | 119 | #### 2、调用API 120 | 121 | 准备完成资源后,调用: 122 | 123 | ```java 124 | SkinManager.getInstance().changeSkin( 125 | mSkinPkgPath, 126 | "com.zhy.plugin", 127 | new ISkinChangingCallback() 128 | { 129 | @Override 130 | public void onStart() 131 | { 132 | } 133 | 134 | @Override 135 | public void onError(Exception e) 136 | { 137 | Toast.makeText(MainActivity.this, "换肤失败", Toast.LENGTH_SHORT).show(); 138 | } 139 | 140 | @Override 141 | public void onComplete() 142 | { 143 | Toast.makeText(MainActivity.this, "换肤成功", Toast.LENGTH_SHORT).show(); 144 | } 145 | }); 146 | ``` 147 | 即可完成换肤。第一个参数为插件apk的路径,第二个参数为插件apk的packageName. 148 | 149 | 记得设置读取存储卡权限。 150 | 151 | 152 | 当然你也可以调用 153 | 154 | ```java 155 | SkinManager.getInstance().removeAnySkin(); 156 | ``` 157 | 重置为初始状态。 158 | 159 | ###(3)应用内换肤 160 | 161 | #### 1、准备资源apk 162 | 163 | 这个就简单了,因为应用内换肤那么你肯定有多套资源,比如有一个背景图叫做: 164 | 165 | skin\_main\_bg 166 | 167 | 那么你可以准备一套皮肤资源,命名为: 168 | 169 | skin\_main\_bg\_后缀 170 | 171 | 这二个后缀你自己决定,例如: 172 | 173 | 174 | 175 | 上图,我准备了两套应用内的皮肤。 176 | 177 | #### 2、调用换肤API 178 | 179 | ```java 180 | SkinManager.getInstance().changeSkin("red"); 181 | ``` 182 | 183 | 参数传入你的后缀名即可。 184 | 185 | 详情参考demo. 186 | 187 | 188 | 189 | 190 | 191 | 192 | ## 声明 193 | 感谢:[drakeet](https://github.com/drakeet)的提醒. 194 | 195 | 恩,看来得说明下,首先对于换肤,从Simple发布的Colorful项目开始关注,搜索了大量的资料,因为希望是可以支持插件式,一直寻找合适的资源替换方案,后来搜索到这篇博文[Android换肤技术总结](http://blog.zhaiyifan.cn/2015/09/10/Android%E6%8D%A2%E8%82%A4%E6%8A%80%E6%9C%AF%E6%80%BB%E7%BB%93/),里面提到了一些方案。很开心的是,发现了这个库:[https://github.com/fengjundev/Android-Skin-Loader](https://github.com/fengjundev/Android-Skin-Loader)有极大的参考价值。该库通过为LayoutInfalter去设置自定义Factory,对加载的View进行分析和提取,方案还是不错的。 196 | 197 | 该库也就成为本库的一个资源替换原理的一个核心的突破点。 198 | 199 | 当然,后来对于LayoutInflater.Factory又做了一些的分析,感觉侵入性有点大,主要担心对于AppCompat一些support的影响。 200 | 于是选择,直接重写Activity的onCreateView等方法。(由于v7 23.0.1的变动,onCreateView只能作为private factory参与创建View了,时机太晚,该库方案也改为setFactory) 201 | 因为本库的预期准备支持app内和或者外部插件式提供资源的换肤方案,为了方便变采用了资源名称的约束,所以修改幅度较大,也就没准备针对Android-Skin-Loader库提交PR。 202 | 203 | 后面会编写博客叙述该库的原理等。 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 18 | 19 | 27 | 28 | 37 | 38 | 39 | 43 | 44 | 52 | 53 | 62 | 63 | 64 | 67 | 68 | 76 | 77 | 86 | 87 | 88 | 89 | 93 | 94 | 102 | 103 | 112 | 113 | 114 | 118 | 119 | 127 | 128 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /plugin/plugin.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 94 | 95 | -------------------------------------------------------------------------------- /changeskin/changeskin.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhy/skinchangenow/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.skinchangenow; 2 | 3 | import android.content.res.AssetManager; 4 | import android.content.res.Resources; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.app.FragmentManager; 9 | import android.support.v4.widget.DrawerLayout; 10 | import android.support.v4.widget.DrawerLayout.DrawerListener; 11 | import android.view.LayoutInflater; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.widget.ArrayAdapter; 17 | import android.widget.ListView; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.nineoldandroids.view.ViewHelper; 22 | import com.zhy.changeskin.utils.L; 23 | 24 | import java.io.File; 25 | import java.lang.reflect.Method; 26 | 27 | /** 28 | * http://blog.csdn.net/lmj623565791/article/details/41531475 29 | * 30 | * @author zhy 31 | */ 32 | public class MainActivity extends com.zhy.changeskin.base.BaseSkinActivity 33 | { 34 | 35 | private DrawerLayout mDrawerLayout; 36 | private ListView mListView; 37 | private String mSkinPkgPath = Environment.getExternalStorageDirectory() + File.separator + "night_plugin.apk"; 38 | private String[] mDatas = new String[]{"Activity", "Service", "Activity", "Service", "Activity", "Service", "Activity", "Service"}; 39 | 40 | 41 | @Override 42 | public void onCreate(Bundle savedInstanceState) 43 | { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_main); 46 | initView(); 47 | initEvents(); 48 | 49 | } 50 | 51 | 52 | private void initEvents() 53 | { 54 | 55 | mListView = (ListView) findViewById(R.id.id_listview); 56 | mListView.setAdapter(new ArrayAdapter(this, -1, mDatas) 57 | { 58 | @Override 59 | public View getView(int position, View convertView, ViewGroup parent) 60 | { 61 | if (convertView == null) 62 | { 63 | convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item, parent 64 | , false); 65 | } 66 | 67 | TextView tv = (TextView) convertView.findViewById(R.id.id_tv_title); 68 | tv.setText(getItem(position)); 69 | return convertView; 70 | } 71 | }); 72 | 73 | 74 | mDrawerLayout.setDrawerListener(new DrawerListener() 75 | { 76 | @Override 77 | public void onDrawerStateChanged(int newState) 78 | { 79 | } 80 | 81 | @Override 82 | public void onDrawerSlide(View drawerView, float slideOffset) 83 | { 84 | View mContent = mDrawerLayout.getChildAt(0); 85 | View mMenu = drawerView; 86 | float scale = 1 - slideOffset; 87 | float rightScale = 0.8f + scale * 0.2f; 88 | 89 | if (drawerView.getTag().equals("LEFT")) 90 | { 91 | 92 | float leftScale = 1 - 0.3f * scale; 93 | 94 | ViewHelper.setScaleX(mMenu, leftScale); 95 | ViewHelper.setScaleY(mMenu, leftScale); 96 | ViewHelper.setAlpha(mMenu, 0.6f + 0.4f * (1 - scale)); 97 | ViewHelper.setTranslationX(mContent, 98 | mMenu.getMeasuredWidth() * (1 - scale)); 99 | ViewHelper.setPivotX(mContent, 0); 100 | ViewHelper.setPivotY(mContent, 101 | mContent.getMeasuredHeight() / 2); 102 | mContent.invalidate(); 103 | ViewHelper.setScaleX(mContent, rightScale); 104 | ViewHelper.setScaleY(mContent, rightScale); 105 | } 106 | } 107 | 108 | @Override 109 | public void onDrawerOpened(View drawerView) 110 | { 111 | } 112 | 113 | @Override 114 | public void onDrawerClosed(View drawerView) 115 | { 116 | } 117 | }); 118 | } 119 | 120 | private void initView() 121 | { 122 | mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawerLayout); 123 | 124 | FragmentManager fm = getSupportFragmentManager(); 125 | Fragment fragment = fm.findFragmentById(R.id.id_left_menu_container); 126 | if (fragment == null) 127 | { 128 | fm.beginTransaction().add(R.id.id_left_menu_container, new MenuLeftFragment()).commit(); 129 | } 130 | } 131 | 132 | @Override 133 | public boolean onCreateOptionsMenu(Menu menu) 134 | { 135 | getMenuInflater().inflate(R.menu.menu_main, menu); 136 | return true; 137 | } 138 | 139 | @Override 140 | public boolean onOptionsItemSelected(MenuItem item) 141 | { 142 | int id = item.getItemId(); 143 | 144 | switch (id) 145 | { 146 | case R.id.id_action_plugin_skinchange: 147 | com.zhy.changeskin.SkinManager.getInstance().changeSkin(mSkinPkgPath, "com.zhy.plugin", new com.zhy.changeskin.callback.ISkinChangingCallback() 148 | { 149 | @Override 150 | public void onStart() 151 | { 152 | } 153 | 154 | @Override 155 | public void onError(Exception e) 156 | { 157 | Toast.makeText(MainActivity.this, "换肤失败", Toast.LENGTH_SHORT).show(); 158 | } 159 | 160 | @Override 161 | public void onComplete() 162 | { 163 | Toast.makeText(MainActivity.this, "换肤成功", Toast.LENGTH_SHORT).show(); 164 | } 165 | }); 166 | break; 167 | case R.id.id_action_remove_any_skin: 168 | com.zhy.changeskin.SkinManager.getInstance().removeAnySkin(); 169 | break; 170 | case R.id.id_action_test_res: 171 | AssetManager assetManager = null; 172 | try 173 | { 174 | assetManager = AssetManager.class.newInstance(); 175 | Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class); 176 | addAssetPath.invoke(assetManager, mSkinPkgPath); 177 | 178 | File file = new File(mSkinPkgPath); 179 | L.e(file.exists()+""); 180 | Resources superRes = getResources(); 181 | Resources mResources = new Resources(assetManager, superRes.getDisplayMetrics(), superRes.getConfiguration()); 182 | 183 | int mainBgId = mResources.getIdentifier("skin_main_bg", "drawable", "com.zhy.plugin"); 184 | findViewById(R.id.id_drawerLayout).setBackgroundDrawable(mResources.getDrawable(mainBgId)); 185 | 186 | 187 | } catch (Exception e) 188 | { 189 | e.printStackTrace(); 190 | } 191 | 192 | break; 193 | } 194 | 195 | 196 | return super.onOptionsItemSelected(item); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/base/BaseSkinActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin.base; 2 | 3 | import android.content.Context; 4 | import android.os.Build; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.Nullable; 8 | import android.support.v4.app.FragmentActivity; 9 | import android.support.v4.util.ArrayMap; 10 | import android.support.v4.view.LayoutInflaterCompat; 11 | import android.support.v4.view.LayoutInflaterFactory; 12 | import android.support.v4.view.ViewCompat; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.support.v7.app.AppCompatDelegate; 15 | import android.support.v7.internal.app.AppCompatViewInflater; 16 | import android.support.v7.widget.AppCompatAutoCompleteTextView; 17 | import android.support.v7.widget.AppCompatButton; 18 | import android.support.v7.widget.AppCompatCheckBox; 19 | import android.support.v7.widget.AppCompatCheckedTextView; 20 | import android.support.v7.widget.AppCompatEditText; 21 | import android.support.v7.widget.AppCompatMultiAutoCompleteTextView; 22 | import android.support.v7.widget.AppCompatRadioButton; 23 | import android.support.v7.widget.AppCompatRatingBar; 24 | import android.support.v7.widget.AppCompatSpinner; 25 | import android.support.v7.widget.AppCompatTextView; 26 | import android.util.AttributeSet; 27 | import android.view.InflateException; 28 | import android.view.LayoutInflater; 29 | import android.view.View; 30 | 31 | import com.zhy.changeskin.SkinManager; 32 | import com.zhy.changeskin.attr.SkinAttr; 33 | import com.zhy.changeskin.attr.SkinAttrSupport; 34 | import com.zhy.changeskin.attr.SkinView; 35 | import com.zhy.changeskin.callback.ISkinChangedListener; 36 | import com.zhy.changeskin.utils.L; 37 | 38 | import java.lang.reflect.Constructor; 39 | import java.lang.reflect.InvocationTargetException; 40 | import java.lang.reflect.Method; 41 | import java.util.ArrayList; 42 | import java.util.List; 43 | import java.util.Map; 44 | 45 | /** 46 | * Created by zhy on 15/9/22. 47 | */ 48 | public class BaseSkinActivity extends AppCompatActivity implements ISkinChangedListener, LayoutInflaterFactory 49 | { 50 | static final Class[] sConstructorSignature = new Class[]{ 51 | Context.class, AttributeSet.class}; 52 | private static final Map> sConstructorMap 53 | = new ArrayMap<>(); 54 | private final Object[] mConstructorArgs = new Object[2]; 55 | private static Method sCreateViewMethod; 56 | static final Class[] sCreateViewSignature = new Class[]{View.class, String.class, Context.class, AttributeSet.class}; 57 | 58 | @Override 59 | public View onCreateView(View parent, String name, Context context, AttributeSet attrs) 60 | { 61 | 62 | LayoutInflater layoutInflater = getLayoutInflater(); 63 | AppCompatDelegate delegate = getDelegate(); 64 | View view = null; 65 | try 66 | { 67 | //public View createView 68 | // (View parent, final String name, @NonNull Context context, @NonNull AttributeSet attrs) 69 | if (sCreateViewMethod == null) 70 | { 71 | Method methodOnCreateView = delegate.getClass().getMethod("createView", sCreateViewSignature); 72 | sCreateViewMethod = methodOnCreateView; 73 | } 74 | Object object = sCreateViewMethod.invoke(delegate, parent, name, context, attrs); 75 | view = (View) object; 76 | } catch (NoSuchMethodException e) 77 | { 78 | e.printStackTrace(); 79 | } catch (InvocationTargetException e) 80 | { 81 | e.printStackTrace(); 82 | } catch (IllegalAccessException e) 83 | { 84 | e.printStackTrace(); 85 | } 86 | 87 | // if ("fragment".equals(name)) 88 | // { 89 | // view = super.onCreateView(name, context, attrs); 90 | // } 91 | // final boolean isPre21 = Build.VERSION.SDK_INT < 21; 92 | // 93 | // if (mAppCompatViewInflater == null) 94 | // { 95 | // mAppCompatViewInflater = new AppCompatViewInflater(); 96 | // } 97 | // 98 | // boolean subDecorInstalled = true; 99 | // final boolean inheritContext = isPre21 && subDecorInstalled && parent != null 100 | // && parent.getId() != android.R.id.content 101 | // && !ViewCompat.isAttachedToWindow(parent); 102 | // 103 | // view = mAppCompatViewInflater.createView(parent, name, context, attrs, inheritContext, 104 | // isPre21, 105 | // true); 106 | // 107 | List skinAttrList = SkinAttrSupport.getSkinAttrs(attrs, context); 108 | if (skinAttrList.isEmpty()) 109 | { 110 | return view; 111 | } 112 | if (view == null) 113 | { 114 | view = createViewFromTag(context, name, attrs); 115 | } 116 | injectSkin(view, skinAttrList); 117 | return view; 118 | 119 | } 120 | 121 | private void injectSkin(View view, List skinAttrList) 122 | { 123 | //do some skin inject 124 | if (skinAttrList.size() != 0) 125 | { 126 | List skinViews = SkinManager.getInstance().getSkinViews(this); 127 | if (skinViews == null) 128 | { 129 | skinViews = new ArrayList(); 130 | } 131 | SkinManager.getInstance().addSkinView(this, skinViews); 132 | skinViews.add(new SkinView(view, skinAttrList)); 133 | 134 | if (SkinManager.getInstance().needChangeSkin()) 135 | { 136 | SkinManager.getInstance().apply(this); 137 | } 138 | } 139 | } 140 | 141 | 142 | private View createViewFromTag(Context context, String name, AttributeSet attrs) 143 | { 144 | if (name.equals("view")) 145 | { 146 | name = attrs.getAttributeValue(null, "class"); 147 | } 148 | 149 | try 150 | { 151 | mConstructorArgs[0] = context; 152 | mConstructorArgs[1] = attrs; 153 | 154 | if (-1 == name.indexOf('.')) 155 | { 156 | // try the android.widget prefix first... 157 | return createView(context, name, "android.widget."); 158 | } else 159 | { 160 | return createView(context, name, null); 161 | } 162 | } catch (Exception e) 163 | { 164 | // We do not want to catch these, lets return null and let the actual LayoutInflater 165 | // try 166 | return null; 167 | } finally 168 | { 169 | // Don't retain references on context. 170 | mConstructorArgs[0] = null; 171 | mConstructorArgs[1] = null; 172 | } 173 | } 174 | 175 | private View createView(Context context, String name, String prefix) 176 | throws ClassNotFoundException, InflateException 177 | { 178 | Constructor constructor = sConstructorMap.get(name); 179 | 180 | try 181 | { 182 | if (constructor == null) 183 | { 184 | // Class not found in the cache, see if it's real, and try to add it 185 | Class clazz = context.getClassLoader().loadClass( 186 | prefix != null ? (prefix + name) : name).asSubclass(View.class); 187 | 188 | constructor = clazz.getConstructor(sConstructorSignature); 189 | sConstructorMap.put(name, constructor); 190 | } 191 | constructor.setAccessible(true); 192 | return constructor.newInstance(mConstructorArgs); 193 | } catch (Exception e) 194 | { 195 | // We do not want to catch these, lets return null and let the actual LayoutInflater 196 | // try 197 | return null; 198 | } 199 | } 200 | 201 | 202 | protected void onCreate(@Nullable Bundle savedInstanceState) 203 | { 204 | LayoutInflater layoutInflater = LayoutInflater.from(this); 205 | LayoutInflaterCompat.setFactory(layoutInflater, this); 206 | super.onCreate(savedInstanceState); 207 | SkinManager.getInstance().addChangedListener(this); 208 | } 209 | 210 | @Override 211 | protected void onDestroy() 212 | { 213 | super.onDestroy(); 214 | SkinManager.getInstance().removeChangedListener(this); 215 | } 216 | 217 | 218 | @Override 219 | public void onSkinChanged() 220 | { 221 | SkinManager.getInstance().apply(this); 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /changeskin/src/main/java/com/zhy/changeskin/SkinManager.java: -------------------------------------------------------------------------------- 1 | package com.zhy.changeskin; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | import android.content.res.Resources; 6 | import android.os.AsyncTask; 7 | import android.text.TextUtils; 8 | 9 | import com.zhy.changeskin.attr.SkinView; 10 | import com.zhy.changeskin.callback.ISkinChangedListener; 11 | import com.zhy.changeskin.callback.ISkinChangingCallback; 12 | import com.zhy.changeskin.utils.PrefUtils; 13 | 14 | import java.io.File; 15 | import java.lang.reflect.Method; 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * Created by zhy on 15/9/22. 23 | */ 24 | public class SkinManager 25 | { 26 | private Context mContext; 27 | private Resources mResources; 28 | private ResourceManager mResourceManager; 29 | private PrefUtils mPrefUtils; 30 | 31 | private boolean usePlugin; 32 | /** 33 | * 换肤资源后缀 34 | */ 35 | private String mSuffix = ""; 36 | private String mCurPluginPath; 37 | private String mCurPluginPkg; 38 | 39 | 40 | private Map> mSkinViewMaps = new HashMap>(); 41 | private List mSkinChangedListeners = new ArrayList(); 42 | 43 | private SkinManager() 44 | { 45 | } 46 | 47 | private static class SingletonHolder 48 | { 49 | static SkinManager sInstance = new SkinManager(); 50 | } 51 | 52 | public static SkinManager getInstance() 53 | { 54 | return SingletonHolder.sInstance; 55 | } 56 | 57 | 58 | public void init(Context context) 59 | { 60 | mContext = context.getApplicationContext(); 61 | mPrefUtils = new PrefUtils(mContext); 62 | 63 | String skinPluginPath = mPrefUtils.getPluginPath(); 64 | String skinPluginPkg = mPrefUtils.getPluginPkgName(); 65 | mSuffix = mPrefUtils.getSuffix(); 66 | if (TextUtils.isEmpty(skinPluginPath)) 67 | return; 68 | File file = new File(skinPluginPath); 69 | if (!file.exists()) return; 70 | try 71 | { 72 | loadPlugin(skinPluginPath, skinPluginPkg, mSuffix); 73 | mCurPluginPath = skinPluginPath; 74 | mCurPluginPkg = skinPluginPkg; 75 | } catch (Exception e) 76 | { 77 | mPrefUtils.clear(); 78 | e.printStackTrace(); 79 | } 80 | } 81 | 82 | 83 | private void loadPlugin(String skinPath, String skinPkgName, String suffix) throws Exception 84 | { 85 | //checkPluginParams(skinPath, skinPkgName); 86 | AssetManager assetManager = AssetManager.class.newInstance(); 87 | Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class); 88 | addAssetPath.invoke(assetManager, skinPath); 89 | 90 | Resources superRes = mContext.getResources(); 91 | mResources = new Resources(assetManager, superRes.getDisplayMetrics(), superRes.getConfiguration()); 92 | mResourceManager = new ResourceManager(mResources, skinPkgName, suffix); 93 | usePlugin = true; 94 | } 95 | 96 | private boolean checkPluginParams(String skinPath, String skinPkgName) 97 | { 98 | if (TextUtils.isEmpty(skinPath) || TextUtils.isEmpty(skinPkgName)) 99 | { 100 | return false; 101 | } 102 | return true; 103 | } 104 | 105 | private void checkPluginParamsThrow(String skinPath, String skinPkgName) 106 | { 107 | if (!checkPluginParams(skinPath, skinPkgName)) 108 | { 109 | throw new IllegalArgumentException("skinPluginPath or skinPkgName can not be empty ! "); 110 | } 111 | } 112 | 113 | 114 | public void removeAnySkin() 115 | { 116 | clearPluginInfo(); 117 | notifyChangedListeners(); 118 | } 119 | 120 | 121 | 122 | 123 | public boolean needChangeSkin() 124 | { 125 | return usePlugin || !TextUtils.isEmpty(mSuffix); 126 | } 127 | 128 | 129 | public ResourceManager getResourceManager() 130 | { 131 | if (!usePlugin) 132 | { 133 | mResourceManager = new ResourceManager(mContext.getResources(), mContext.getPackageName(), mSuffix); 134 | } 135 | return mResourceManager; 136 | } 137 | 138 | 139 | /** 140 | * 应用内换肤,传入资源区别的后缀 141 | * 142 | * @param suffix 143 | */ 144 | public void changeSkin(String suffix) 145 | { 146 | clearPluginInfo();//clear before 147 | mSuffix = suffix; 148 | mPrefUtils.putPluginSuffix(suffix); 149 | notifyChangedListeners(); 150 | } 151 | 152 | private void clearPluginInfo() 153 | { 154 | mCurPluginPath = null; 155 | mCurPluginPkg = null; 156 | usePlugin = false; 157 | mSuffix = null; 158 | mPrefUtils.clear(); 159 | } 160 | 161 | private void updatePluginInfo(String skinPluginPath, String pkgName, String suffix) 162 | { 163 | mPrefUtils.putPluginPath(skinPluginPath); 164 | mPrefUtils.putPluginPkg(pkgName); 165 | mPrefUtils.putPluginSuffix(suffix); 166 | mCurPluginPkg = pkgName; 167 | mCurPluginPath = skinPluginPath; 168 | mSuffix = suffix; 169 | } 170 | 171 | 172 | public void changeSkin(final String skinPluginPath, final String pkgName, ISkinChangingCallback callback) 173 | { 174 | changeSkin(skinPluginPath, pkgName, "", callback); 175 | } 176 | 177 | 178 | /** 179 | * 根据suffix选择插件内某套皮肤,默认为"" 180 | * 181 | * @param skinPluginPath 182 | * @param pkgName 183 | * @param suffix 184 | * @param callback 185 | */ 186 | public void changeSkin(final String skinPluginPath, final String pkgName, final String suffix, ISkinChangingCallback callback) 187 | { 188 | if (callback == null) 189 | callback = ISkinChangingCallback.DEFAULT_SKIN_CHANGING_CALLBACK; 190 | final ISkinChangingCallback skinChangingCallback = callback; 191 | 192 | skinChangingCallback.onStart(); 193 | checkPluginParamsThrow(skinPluginPath, pkgName); 194 | 195 | if (skinPluginPath.equals(mCurPluginPath) && pkgName.equals(mCurPluginPkg)) 196 | { 197 | return; 198 | } 199 | 200 | new AsyncTask() 201 | { 202 | @Override 203 | protected Void doInBackground(Void... params) 204 | { 205 | try 206 | { 207 | loadPlugin(skinPluginPath, pkgName, suffix); 208 | } catch (Exception e) 209 | { 210 | e.printStackTrace(); 211 | skinChangingCallback.onError(e); 212 | } 213 | 214 | return null; 215 | } 216 | 217 | @Override 218 | protected void onPostExecute(Void aVoid) 219 | { 220 | try 221 | { 222 | updatePluginInfo(skinPluginPath, pkgName, suffix); 223 | notifyChangedListeners(); 224 | skinChangingCallback.onComplete(); 225 | } catch (Exception e) 226 | { 227 | e.printStackTrace(); 228 | skinChangingCallback.onError(e); 229 | } 230 | 231 | } 232 | }.execute(); 233 | } 234 | 235 | 236 | public void addSkinView(ISkinChangedListener listener, List skinViews) 237 | { 238 | mSkinViewMaps.put(listener, skinViews); 239 | } 240 | 241 | public List getSkinViews(ISkinChangedListener listener) 242 | { 243 | return mSkinViewMaps.get(listener); 244 | } 245 | 246 | 247 | public void apply(ISkinChangedListener listener) 248 | { 249 | List skinViews = getSkinViews(listener); 250 | 251 | if (skinViews == null) return; 252 | for (SkinView skinView : skinViews) 253 | { 254 | skinView.apply(); 255 | } 256 | } 257 | 258 | public void addChangedListener(ISkinChangedListener listener) 259 | { 260 | mSkinChangedListeners.add(listener); 261 | } 262 | 263 | 264 | public void removeChangedListener(ISkinChangedListener listener) 265 | { 266 | mSkinChangedListeners.remove(listener); 267 | mSkinViewMaps.remove(listener); 268 | } 269 | 270 | 271 | public void notifyChangedListeners() 272 | { 273 | for (ISkinChangedListener listener : mSkinChangedListeners) 274 | { 275 | listener.onSkinChanged(); 276 | } 277 | } 278 | 279 | } 280 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------