OSDN Git Service

Dumb hack to work around faked display metrics causing Taskbar to glitch up on Androi...
authorBraden Farmer <farmerbb@gmail.com>
Sun, 12 Dec 2021 18:28:22 +0000 (11:28 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Sun, 12 Dec 2021 19:32:47 +0000 (12:32 -0700)
app/src/main/java/com/farmerbb/taskbar/activity/DummyActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/MainActivity.java
app/src/main/java/com/farmerbb/taskbar/util/U.java
app/src/main/res/values/styles.xml
app/src/nonlib/res/layout/tb_main.xml

index 4463b51..3a2b0d5 100644 (file)
@@ -46,6 +46,8 @@ public class DummyActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        if(U.relaunchActivityIfNeeded(this)) return;
+
         setContentView(new View(this));
 
         if(getIntent().hasExtra("finish_on_pause"))
index 3a90a9f..2b5f15e 100644 (file)
@@ -86,15 +86,20 @@ public class MainActivity extends AppCompatActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        if(U.relaunchActivityIfNeeded(this)) return;
 
         U.registerReceiver(this, switchReceiver, ACTION_UPDATE_SWITCH);
 
         final SharedPreferences pref = U.getSharedPreferences(this);
         SharedPreferences.Editor editor = pref.edit();
 
-        if(!U.isLibrary(this))
-            setTheme(U.isDarkTheme(this) ? R.style.Taskbar_Dark : R.style.Taskbar);
-        else {
+        if(!U.isLibrary(this)) {
+            boolean isRelaunched = getIntent().hasExtra("is_relaunched");
+            int lightTheme = isRelaunched ? R.style.Taskbar_Floating : R.style.Taskbar;
+            int darkTheme = isRelaunched ? R.style.Taskbar_Dark_Floating : R.style.Taskbar_Dark;
+
+            setTheme(U.isDarkTheme(this) ? darkTheme : lightTheme);
+        } else {
             int theme = getIntent().getIntExtra("theme", -1);
             if(theme != -1)
                 setTheme(theme);
index f5e1a2b..83e50d6 100644 (file)
@@ -836,9 +836,9 @@ public class U {
         return canEnableFreeform(context, true);
     }
 
-    public static boolean canEnableFreeform(Context context, boolean checkPref) {
+    public static boolean canEnableFreeform(Context context, boolean allowOverride) {
         if(getCurrentApiVersion() == 31.0f && !displayDefaultsToFreeform(context, getExternalDisplay(context))) {
-            if(!checkPref) return false;
+            if(!allowOverride) return false;
 
             SharedPreferences pref = getSharedPreferences(context);
             return pref.getBoolean(PREF_OVERRIDE_FREEFORM_UNSUPPORTED, false);
@@ -2187,4 +2187,21 @@ public class U {
 
         return configString;
     }
+
+    public static boolean relaunchActivityIfNeeded(Activity activity) {
+        if(isLibrary(activity)) return false;
+
+        Intent intent = activity.getIntent();
+        if(getCurrentApiVersion() != 30.0f
+                || !displayDefaultsToFreeform(activity, getExternalDisplay(activity))
+                || intent.hasExtra("is_relaunched")) {
+            return false;
+        }
+
+        intent.putExtra("is_relaunched", true);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+        newHandler().post(() -> startActivityMaximized(activity, intent));
+        activity.finish();
+        return true;
+    }
 }
index fafc1fe..e2df3b6 100644 (file)
 
     <style name="Taskbar.Dark" parent="TaskbarBase.Dark" />
 
+    <style name="Taskbar.Floating">
+        <item name="android:windowIsFloating">true</item>
+    </style>
+
+    <style name="Taskbar.Dark.Floating">
+        <item name="android:windowIsFloating">true</item>
+    </style>
+
     <style name="Taskbar.HomeActivity" parent="Theme.AppCompat.NoActionBar">
         <item name="android:windowBackground">@android:color/transparent</item>
         <item name="android:windowShowWallpaper">true</item>
index 0ec6eb5..a8d227f 100644 (file)
@@ -30,7 +30,7 @@
         android:layout_height="?attr/actionBarSize"
         android:background="?attr/colorPrimary"
         android:elevation="4dp"
-        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
+        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
         app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
 
         <include layout="@layout/tb_switch_layout" />