├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── values-night │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── values-v21 │ │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ └── layout │ │ │ │ ├── activity_main.xml │ │ │ │ └── content_main.xml │ │ ├── java │ │ │ └── rikka │ │ │ │ └── daynight │ │ │ │ ├── MyApplication.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── rikka │ │ │ └── daynight │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── rikka │ │ └── daynight │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── daynightmode ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ └── strings.xml │ │ │ └── anim │ │ │ │ ├── fade_in.xml │ │ │ │ ├── fade_out.xml │ │ │ │ ├── accelerate_quart.xml │ │ │ │ └── activity_close_exit.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── moe │ │ │ └── xing │ │ │ └── daynightmode │ │ │ ├── DayNightMode.java │ │ │ └── BaseDayNightModeActivity.java │ ├── test │ │ └── java │ │ │ └── moe │ │ │ └── xing │ │ │ └── daynightmode │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── moe │ │ └── xing │ │ └── daynightmode │ │ └── ApplicationTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | DayNight -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .apk -------------------------------------------------------------------------------- /daynightmode/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':daynightmode' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaW/DayNight-Theme/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /daynightmode/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Day Night Mode 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaW/DayNight-Theme/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaW/DayNight-Theme/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaW/DayNight-Theme/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaW/DayNight-Theme/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RikkaW/DayNight-Theme/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DayNight 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ef5350 4 | #e53935 5 | #69f0ae 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 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.8-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /daynightmode/src/main/res/anim/fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /daynightmode/src/main/res/anim/fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /daynightmode/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/rikka/daynight/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package rikka.daynight; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /daynightmode/src/test/java/moe/xing/daynightmode/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package moe.xing.daynightmode; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/rikka/daynight/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package rikka.daynight; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /daynightmode/src/androidTest/java/moe/xing/daynightmode/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package moe.xing.daynightmode; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /daynightmode/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 11 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | testCompile 'junit:junit:4.12' 24 | compile 'com.android.support:appcompat-v7:23.2.1' 25 | } 26 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /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 C:\Users\Rikka\AppData\Local\Android\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 | -------------------------------------------------------------------------------- /daynightmode/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 C:\Users\Yulan\AppData\Local\Android\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 | -------------------------------------------------------------------------------- /app/src/main/java/rikka/daynight/MyApplication.java: -------------------------------------------------------------------------------- 1 | package rikka.daynight; 2 | 3 | import android.app.Application; 4 | import android.app.UiModeManager; 5 | import android.content.Context; 6 | import android.content.res.Configuration; 7 | import android.os.Build; 8 | import android.support.v7.app.AppCompatDelegate; 9 | 10 | import moe.xing.daynightmode.DayNightMode; 11 | 12 | /** 13 | * Created by Rikka on 2016/2/27. 14 | */ 15 | 16 | 17 | public class MyApplication extends Application { 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | 22 | DayNightMode.setDefaultNightMode(this, DayNightMode.MODE_NIGHT_FOLLOW_SYSTEM); 23 | //DayNightMode.setSystemNightMode(this, DayNightMode.MODE_NIGHT_NO); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "rikka.daynight" 9 | minSdkVersion 15 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 | testCompile 'junit:junit:4.12' 25 | compile project(':daynightmode') 26 | compile 'com.android.support:appcompat-v7:23.2.1' 27 | compile 'com.android.support:design:23.2.1' 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 21 | 22 | -------------------------------------------------------------------------------- /daynightmode/src/main/res/anim/accelerate_quart.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Sun Apr 03 12:51:21 CST 2016 16 | systemProp.http.proxyHost=127.0.0.1 17 | systemProp.http.nonProxyHosts=127.0.0.1 18 | systemProp.http.proxyPort=8123 19 | -------------------------------------------------------------------------------- /daynightmode/src/main/java/moe/xing/daynightmode/DayNightMode.java: -------------------------------------------------------------------------------- 1 | package moe.xing.daynightmode; 2 | 3 | import android.app.UiModeManager; 4 | import android.content.Context; 5 | import android.content.ContextWrapper; 6 | import android.os.Build; 7 | import android.support.v7.app.AppCompatDelegate; 8 | 9 | /** 10 | * Created by Rikka on 2016/3/2. 11 | */ 12 | public class DayNightMode { 13 | public static final int MODE_NIGHT_AUTO = AppCompatDelegate.MODE_NIGHT_AUTO; 14 | public static final int MODE_NIGHT_NO = AppCompatDelegate.MODE_NIGHT_NO; 15 | public static final int MODE_NIGHT_YES = AppCompatDelegate.MODE_NIGHT_YES; 16 | public static final int MODE_NIGHT_FOLLOW_SYSTEM = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; 17 | 18 | static public void setDefaultNightMode(int mode) { 19 | AppCompatDelegate.setDefaultNightMode( 20 | mode); 21 | } 22 | 23 | static public void setSystemNightMode(Context context, int mode) { 24 | ((UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE)) 25 | .setNightMode(mode); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DayNight-Theme 2 | =============== 3 | Google released Android Support Library 23.2 on February 24, 2016, it contains new DayNight Theme. 4 | However right now (March 2), it is not work on Marshmallow, so there is a temporary way. 5 | 6 | ###Usage: 7 | Add it in your root build.gradle at the end of repositories:
8 | `maven { url "https://jitpack.io" }`
9 | Add the dependency
10 | `compile 'com.github.RikkaW:DayNight-Theme:v1.0.6'` 11 | 12 | Use `BaseDayNightModeActivity.setNightMode()` to change night mode runtime (it will recreate activity)
13 | Use `DayNightMode.setDefaultNightMode` in `application` class to set default night mode
14 | 15 | If you are using `AppCompatActivity`, use `BaseDayNightModeActivity` as `AppCompatActivity`
16 | If not, see [`BaseDayNightModeActivity`](https://github.com/RikkaW/DayNight-Theme/blob/master/daynightmode/src/main/java/moe/xing/daynightmode/BaseDayNightModeActivity.java)
17 | 18 | ###Note: 19 | On Marshmallow, if you use `DayNightMode.setSystemNightMode` to change system setting, any app which contains `-night` resource will be affected. 20 | 21 | ###Sample app: 22 | [Download](https://github.com/RikkaW/DayNight-Theme/releases/download/v1.0.6/app-release.apk) 23 | -------------------------------------------------------------------------------- /daynightmode/src/main/res/anim/activity_close_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 28 | 32 | -------------------------------------------------------------------------------- /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 | Android Lint 39 | 40 | 41 | Control flow issuesJava 42 | 43 | 44 | Encapsulation issuesJava 45 | 46 | 47 | Java 48 | 49 | 50 | Naming conventionsJava 51 | 52 | 53 | XML 54 | 55 | 56 | 57 | 58 | Android 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 80 | -------------------------------------------------------------------------------- /daynightmode/src/main/java/moe/xing/daynightmode/BaseDayNightModeActivity.java: -------------------------------------------------------------------------------- 1 | package moe.xing.daynightmode; 2 | 3 | import android.content.Intent; 4 | import android.content.res.Configuration; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.app.AppCompatDelegate; 9 | 10 | public class BaseDayNightModeActivity extends AppCompatActivity { 11 | 12 | private int mCurrentNightMode; 13 | private Intent mIntent; 14 | 15 | public void setNightMode(int mode) { 16 | if (mode == mCurrentNightMode) { 17 | return; 18 | } 19 | 20 | mCurrentNightMode = mode; 21 | 22 | AppCompatDelegate.setDefaultNightMode(mode); 23 | 24 | fakeRecreate(); 25 | } 26 | 27 | protected Intent getNightModeChangedRestartActivityIntent() { 28 | if (mIntent.getAction() != null && mIntent.getAction().equals(Intent.ACTION_MAIN)) { 29 | return new Intent(this, this.getClass()); 30 | } 31 | return mIntent; 32 | } 33 | 34 | protected int getNightModeChangedEnterAnim() { 35 | return R.anim.fade_in; 36 | } 37 | 38 | protected int getNightModeChangedExitAnim() { 39 | return R.anim.fade_out; 40 | } 41 | 42 | private void fakeRecreate() { 43 | startActivity(getNightModeChangedRestartActivityIntent()); 44 | finish(); 45 | 46 | overridePendingTransition(getNightModeChangedEnterAnim(), 47 | getNightModeChangedExitAnim()); 48 | } 49 | 50 | @Override 51 | public void onBackPressed() { 52 | super.onBackPressed(); 53 | 54 | if (shouldOverrideBackTransition()) { 55 | overridePendingTransition(0, 56 | R.anim.activity_close_exit); 57 | } 58 | } 59 | 60 | public boolean shouldOverrideBackTransition() { 61 | return true; 62 | } 63 | 64 | @Override 65 | protected void onResume() { 66 | super.onResume(); 67 | 68 | // Let system do recreate 69 | if (mCurrentNightMode == DayNightMode.MODE_NIGHT_FOLLOW_SYSTEM) { 70 | return; 71 | } 72 | 73 | // If night mode changed start a new activity 74 | if (mCurrentNightMode != AppCompatDelegate.getDefaultNightMode()) { 75 | fakeRecreate(); 76 | return; 77 | } 78 | 79 | if (mCurrentNightMode == DayNightMode.MODE_NIGHT_AUTO) { 80 | if (getDelegate().applyDayNight()) { 81 | fakeRecreate(); 82 | } 83 | } 84 | } 85 | 86 | @Override 87 | protected void onCreate(@Nullable Bundle savedInstanceState) { 88 | mIntent = getIntent(); 89 | mCurrentNightMode = AppCompatDelegate.getDefaultNightMode(); 90 | 91 | // Bad way to really follow system 92 | if (mCurrentNightMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) { 93 | AppCompatDelegate.setDefaultNightMode(isNightMode() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); 94 | super.onCreate(savedInstanceState); 95 | AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); 96 | } 97 | else { 98 | super.onCreate(savedInstanceState); 99 | } 100 | 101 | } 102 | 103 | public boolean isNightMode() { 104 | return ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) > 0); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 19 | 20 | 26 | 27 |