-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "dev.tylerolson.snapchatdarkmode" | ||
minSdkVersion 15 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
repositories { | ||
maven { url 'https://jitpack.io' } | ||
} | ||
|
||
dependencies { | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.3.1' | ||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.2.1' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
|
||
//libsu | ||
def libsuVersion = '3.1.2' | ||
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}" | ||
implementation "com.github.topjohnwu.libsu:io:${libsuVersion}" | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.tylerolson.snapchatdarkmode | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("dev.tylerolson.snapchatdarkmodeenabler", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dev.tylerolson.snapchatdarkmode"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.SnapchatDarkMode"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package dev.tylerolson.snapchatdarkmode | ||
|
||
import android.app.AlertDialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.topjohnwu.superuser.Shell | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
private val appTag: String = "SNAPCHAT DARK MODE" | ||
private val xmlFile: String = "/data/data/com.snapchat.android/shared_prefs/APP_START_EXPERIMENT_PREFS.xml" | ||
private var isDarkModeEnabled: Boolean = false | ||
private var isRoot: Boolean = false | ||
|
||
init { | ||
// Set settings before the main shell can be created | ||
Shell.enableVerboseLogging = BuildConfig.DEBUG | ||
Shell.setDefaultBuilder( | ||
Shell.Builder.create() | ||
.setFlags(Shell.FLAG_REDIRECT_STDERR) | ||
.setTimeout(10) | ||
) | ||
} | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
hasRootAccess() | ||
|
||
val darkModeStatus: TextView = findViewById(R.id.darkModeStatus) | ||
checkDarkMode(darkModeStatus) | ||
|
||
val toggleButton: Button = findViewById(R.id.toggleButton) | ||
toggleButton.setOnClickListener { | ||
if (hasRootAccess()) { | ||
if (isDarkModeEnabled) { | ||
disableDarkMode(checkDarkMode(darkModeStatus)) | ||
} else { | ||
enableDarkMode(checkDarkMode(darkModeStatus)) | ||
} | ||
checkDarkMode(darkModeStatus) | ||
} | ||
} | ||
} | ||
|
||
private fun hasRootAccess(): Boolean { | ||
return if (!Shell.rootAccess()) { | ||
showDialog( | ||
"No Root Access", | ||
"Root access could not be given on your device. This app will not work." | ||
) | ||
false | ||
} else { | ||
if (!isRoot) { | ||
showDialog("Root Access", "Root access has been given on your device. Enjoy!") | ||
isRoot = true | ||
} | ||
true | ||
} | ||
} | ||
|
||
private fun showDialog(title: String, message: String) { | ||
val builder = AlertDialog.Builder(this) | ||
builder.setTitle(title) | ||
.setMessage(message) | ||
.setPositiveButton("Ok") { _: DialogInterface, _: Int -> } | ||
builder.show() | ||
} | ||
|
||
private fun checkDarkMode(darkModeStatus: TextView): MutableList<String> { | ||
val result: Shell.Result = Shell.su("cat $xmlFile").exec() | ||
|
||
Log.e(appTag, "Checking") | ||
|
||
isDarkModeEnabled = false | ||
result.out.forEachIndexed { _, it -> | ||
Log.e(appTag, it) | ||
if (it.contains("<string name=\"DARK_MODE\">ENABLED</string>")) { | ||
isDarkModeEnabled = true | ||
} | ||
} | ||
|
||
if (isDarkModeEnabled) { | ||
darkModeStatus.text = "Dark mode is ON" | ||
} else { | ||
darkModeStatus.text = "Dark mode is OFF" | ||
} | ||
|
||
return result.out | ||
} | ||
|
||
private fun enableDarkMode(out: MutableList<String>) { | ||
Shell.su("sed -i '" + out.size + "d' " + xmlFile).exec() | ||
Shell.sh("echo '<string name=\"DARK_MODE\">ENABLED</string>' >> $xmlFile").exec() | ||
Shell.sh("echo \"</map>\" >> $xmlFile").exec() | ||
|
||
isDarkModeEnabled = true | ||
showDialog("Dark Mode", "Enabled dark mode!") | ||
} | ||
|
||
private fun disableDarkMode(out: MutableList<String>) { | ||
Shell.su("sed -i '" + (out.size - 1) + "d' " + xmlFile).exec() | ||
|
||
isDarkModeEnabled = false | ||
showDialog("Dark Mode", "Disabled dark mode!") | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:id="@+id/darkModeStatus" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="dark_mode_status" | ||
android:textSize="24sp" | ||
app:layout_constraintBottom_toTopOf="@+id/toggleButton" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.599" /> | ||
|
||
<Button | ||
android:id="@+id/toggleButton" | ||
android:layout_width="202dp" | ||
android:layout_height="62dp" | ||
android:text="@string/toggle_button" | ||
android:textSize="14sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.499" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@mipmap/ic_launcher_background"/> | ||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> | ||
</adaptive-icon> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@mipmap/ic_launcher_background"/> | ||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> | ||
</adaptive-icon> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<resources xmlns:tools="http://schemas.android.com/tools"> | ||
<!-- Base application theme. --> | ||
<style name="Theme.SnapchatDarkMode" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> | ||
<!-- Primary brand color. --> | ||
<item name="colorPrimary">@color/yellow</item> | ||
<item name="colorPrimaryVariant">@color/black</item> | ||
<item name="colorOnPrimary">@color/black</item> | ||
<!-- Secondary brand color. --> | ||
<item name="colorSecondary">@color/teal_200</item> | ||
<item name="colorSecondaryVariant">@color/teal_200</item> | ||
<item name="colorOnSecondary">@color/black</item> | ||
<!-- Status bar color. --> | ||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> | ||
<!-- Customize your theme here. --> | ||
</style> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="yellow">#FFFFFC00</color> | ||
<color name="teal_200">#FF03DAC5</color> | ||
<color name="teal_700">#FF018786</color> | ||
<color name="black">#FF111111</color> | ||
<color name="white">#FFFFFFFF</color> | ||
</resources> |