OSDN Git Service

Use display context when hiding navbar from desktop mode settings
authorBraden Farmer <farmerbb@gmail.com>
Sun, 31 May 2020 19:40:05 +0000 (13:40 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Sun, 31 May 2020 19:40:05 +0000 (13:40 -0600)
app/src/main/java/com/farmerbb/taskbar/fragment/SettingsFragment.java
app/src/main/java/com/farmerbb/taskbar/util/Lazy.java [new file with mode: 0644]
app/src/main/java/com/farmerbb/taskbar/util/U.java

index ebbbd12..6b95f14 100644 (file)
@@ -172,7 +172,7 @@ public abstract class SettingsFragment extends PreferenceFragment implements Pre
 
                             SharedPreferences pref2 = U.getSharedPreferences(getActivity());
                             if(pref2.getBoolean(PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE, false) && isOnHomeScreen)
-                                U.showHideNavigationBar(getActivity(), displayID, false, 250);
+                                U.showHideNavigationBar(U.getDisplayContext(getActivity()), displayID, false, 250);
                         } catch (Exception e) {
                             U.showToast(getActivity(), R.string.tb_unable_to_apply_density_change);
                         }
diff --git a/app/src/main/java/com/farmerbb/taskbar/util/Lazy.java b/app/src/main/java/com/farmerbb/taskbar/util/Lazy.java
new file mode 100644 (file)
index 0000000..577f421
--- /dev/null
@@ -0,0 +1,20 @@
+/* Copyright 2020 Braden Farmer
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.farmerbb.taskbar.util;
+
+interface Lazy<T> {
+   T get();
+}
index f37f048..4cb782a 100644 (file)
@@ -1217,12 +1217,12 @@ public class U {
             return;
         }
 
-        int value = show ? 0 : getSystemDimen(context, "navigation_bar_height") * -1;
+        Lazy<Integer> value = () -> show ? 0 : getSystemDimen(context, "navigation_bar_height") * -1;
 
         if(hasWriteSecureSettingsPermission(context)) {
             Runnable runnable = () -> {
                 try {
-                    setOverscan(displayID, value);
+                    setOverscan(displayID, value.get());
                 } catch (Exception e) { /* Gracefully fail */ }
             };
 
@@ -1239,7 +1239,7 @@ public class U {
             intent.setPackage(BuildConfig.SUPPORT_APPLICATION_ID);
 
             intent.putExtra("display_id", displayID);
-            intent.putExtra("value", value);
+            intent.putExtra("value", value.get());
 
             context.sendBroadcast(intent);
             return;