diff --git a/.gitignore b/.gitignore
index 55e019e..8ccc4f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,3 @@
.externalNativeBuild
.cxx
local.properties
-/app/
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..42afabf
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..7a4b707
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,29 @@
+plugins {
+ alias(libs.plugins.android.application)
+}
+
+android {
+ namespace 'cfpi_fpsi.eu.titan_mini_mode'
+ compileSdk 34
+
+ defaultConfig {
+ applicationId "cfpi_fpsi.eu.titan_mini_mode"
+ minSdk 24
+ targetSdk 34
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+}
+
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..481bb43
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -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
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..8e1c434
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/cfpi_fpsi/eu/titan_mini_mode/TitanMiniModeQSTileService.java b/app/src/main/java/cfpi_fpsi/eu/titan_mini_mode/TitanMiniModeQSTileService.java
new file mode 100644
index 0000000..55de35b
--- /dev/null
+++ b/app/src/main/java/cfpi_fpsi/eu/titan_mini_mode/TitanMiniModeQSTileService.java
@@ -0,0 +1,107 @@
+package cfpi_fpsi.eu.titan_mini_mode;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.graphics.Point;
+import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.Display;
+import android.view.WindowManager;
+
+import java.io.IOException;
+
+public class TitanMiniModeQSTileService extends TileService {
+ SharedPreferences pref;
+ @Override
+ public void onTileAdded() {
+ super.onTileAdded();
+ pref = getBaseContext().getSharedPreferences(
+ "cfpi_fpsi.eu.titan_mini_mode.PREFERENCE_FILE_KEY", Context.MODE_PRIVATE);
+ // When the tile is first added, we save the original screen size into the preferences.
+ DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
+ SharedPreferences.Editor editor = pref.edit();
+ editor.putInt("original_screen_width", metrics.widthPixels);
+ editor.putInt("original_screen_height", metrics.heightPixels);
+ editor.commit();
+ }
+ @Override
+ public void onTileRemoved() {
+ super.onTileRemoved();
+ // When the tile is removed, we set the display size to the default.
+ Point originalScreenSize = getOriginalScreenSize();
+ setDisplaySize(originalScreenSize.x, originalScreenSize.y);
+ }
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+
+ pref = getBaseContext().getSharedPreferences(
+ "cfpi_fpsi.eu.titan_mini_mode.PREFERENCE_FILE_KEY", Context.MODE_PRIVATE);
+
+ Tile tile = getQsTile();
+ Point currentScreenSize = getCurrentScreenSize();
+ Point originalScreenSize = getOriginalScreenSize();
+
+ if (currentScreenSize.x == originalScreenSize.x
+ && currentScreenSize.y == originalScreenSize.y) {
+ tile.setState(Tile.STATE_INACTIVE);
+ } else {
+ tile.setState(Tile.STATE_ACTIVE);
+ }
+
+ tile.updateTile();
+ }
+
+ @Override
+ public void onClick() {
+ super.onClick();
+ Tile tile = getQsTile();
+ Point currentScreenSize = getCurrentScreenSize();
+ Point originalScreenSize = getOriginalScreenSize();
+
+ if (currentScreenSize.x == originalScreenSize.x &&
+ currentScreenSize.y == originalScreenSize.y) {
+ setDisplaySize(Math.round(originalScreenSize.x * 0.66), originalScreenSize.y);
+ tile.setState(Tile.STATE_ACTIVE);
+ } else {
+ setDisplaySize(originalScreenSize.x, originalScreenSize.y);
+ tile.setState(Tile.STATE_INACTIVE);
+ }
+
+ tile.updateTile();
+ }
+
+ static void setDisplaySize(long x, long y) {
+ runAsRoot("wm size " + x + "x" + y);
+ }
+
+ // https://github.com/rumplestilzken/gargoyleSettings/blob/main/app/src/main/java/com/rumplestilzken/gargoylesettings/provider/RootProvider.java
+ static void runAsRoot(String command) {
+ try {
+ Process root = Runtime.getRuntime().exec(new String[] { "su", "-c", command});
+
+ try {
+ root.waitFor();
+ } catch (InterruptedException e) {
+ Log.d("EXCEPTION", e.toString());
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Point getOriginalScreenSize() {
+ return new Point(pref.getInt("original_screen_width", 1440),
+ pref.getInt("original_screen_height", 1440));
+ }
+ private Point getCurrentScreenSize() {
+ WindowManager wm = (WindowManager) getBaseContext().getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ Point size = new Point();
+ display.getSize(size);
+ return size;
+ }
+}
diff --git a/app/src/main/res/drawable/qs_tile.xml b/app/src/main/res/drawable/qs_tile.xml
new file mode 100644
index 0000000..094bcfa
--- /dev/null
+++ b/app/src/main/res/drawable/qs_tile.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..527f390
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,4 @@
+
+ Titan Mini Mode
+ Mini mode
+
\ No newline at end of file