OSDN Git Service

Implement automatic hiding of navigation bar
authorBraden Farmer <farmerbb@gmail.com>
Thu, 25 May 2017 02:29:21 +0000 (20:29 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Thu, 25 May 2017 02:29:21 +0000 (20:29 -0600)
app/src/main/AndroidManifest.xml
app/src/main/java/com/farmerbb/taskbar/activity/NavigationBarButtonsActivity.java
app/src/main/java/com/farmerbb/taskbar/receiver/EnableHomeReceiver.java
app/src/main/java/com/farmerbb/taskbar/service/TaskbarService.java
app/src/main/java/com/farmerbb/taskbar/util/U.java
app/src/main/res/values-de/strings.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/pref_navigation_bar_buttons.xml

index 2dd49c6..5523eff 100644 (file)
@@ -35,6 +35,7 @@
 
     <uses-permission-sdk-23 android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
     <uses-permission-sdk-23 android:name="android.permission.GET_TASKS" />
+    <uses-permission-sdk-23 android:name="android.permission.WRITE_SETTINGS" />
 
     <uses-feature
         android:name="android.hardware.touchscreen"
index c4b99b1..4aef319 100644 (file)
 package com.farmerbb.taskbar.activity;
 
 import android.os.Bundle;
+import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
+import android.provider.Settings;
 
 import com.farmerbb.taskbar.R;
+import com.farmerbb.taskbar.service.TaskbarService;
 import com.farmerbb.taskbar.util.U;
 
 public class NavigationBarButtonsActivity extends PreferenceActivity implements Preference.OnPreferenceClickListener {
@@ -35,11 +38,29 @@ public class NavigationBarButtonsActivity extends PreferenceActivity implements
         findPreference("button_back").setOnPreferenceClickListener(this);
         findPreference("button_home").setOnPreferenceClickListener(this);
         findPreference("button_recents").setOnPreferenceClickListener(this);
+
+        if(U.hasSupportLibrary(this))
+            findPreference("auto_hide_navbar").setOnPreferenceClickListener(this);
+        else
+            getPreferenceScreen().removePreference(findPreference("auto_hide_navbar_category"));
     }
 
     @Override
     public boolean onPreferenceClick(Preference preference) {
-        U.restartTaskbar(this);
+        switch(preference.getKey()) {
+            case "auto_hide_navbar":
+                if(U.isServiceRunning(this, TaskbarService.class)) {
+                    boolean isChecked = ((CheckBoxPreference) preference).isChecked();
+
+                    try {
+                        Settings.System.putInt(getContentResolver(), "navigation_bar_show", isChecked ? 0 : 1);
+                    } catch (Exception e) { /* Gracefully fail */ }
+                }
+                break;
+            default:
+                U.restartTaskbar(this);
+                break;
+        }
         return true;
     }
 }
\ No newline at end of file
index cea1ba5..faf02a8 100644 (file)
@@ -45,11 +45,12 @@ public class EnableHomeReceiver extends BroadcastReceiver {
                 editor.putBoolean("full_length", true);
             }
 
-            if(intent.hasExtra("enable_navigation_bar_buttons")) {
+            if(intent.hasExtra("enable_navigation_bar_buttons") && U.isSystemApp(context)) {
                 editor.putBoolean("dashboard", true);
                 editor.putBoolean("button_back", true);
                 editor.putBoolean("button_home", true);
                 editor.putBoolean("button_recents", true);
+                editor.putBoolean("auto_hide_navbar", true);
             }
 
             editor.apply();
index 6f188ba..5f588c1 100644 (file)
@@ -488,6 +488,11 @@ public class TaskbarService extends Service {
         else if(!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false))
             toggleTaskbar();
 
+        if(pref.getBoolean("auto_hide_navbar", false))
+            try {
+                Settings.System.putInt(getContentResolver(), "navigation_bar_show", 0);
+            } catch (Exception e) { /* Gracefully fail */ }
+
         LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
         
         lbm.unregisterReceiver(showReceiver);
@@ -1072,6 +1077,14 @@ public class TaskbarService extends Service {
                 windowManager.removeView(layout);
             } catch (IllegalArgumentException e) { /* Gracefully fail */ }
 
+        SharedPreferences pref = U.getSharedPreferences(this);
+        if(pref.getBoolean("skip_auto_hide_navbar", false)) {
+            pref.edit().remove("skip_auto_hide_navbar").apply();
+        } else if(pref.getBoolean("auto_hide_navbar", false))
+            try {
+                Settings.System.putInt(getContentResolver(), "navigation_bar_show", 1);
+            } catch (Exception e) { /* Gracefully fail */ }
+
         LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
 
         lbm.unregisterReceiver(showReceiver);
index 57a8147..9b24ed6 100644 (file)
@@ -987,11 +987,16 @@ public class U {
     public static void restartTaskbar(Context context) {
         SharedPreferences pref = getSharedPreferences(context);
         if(pref.getBoolean("taskbar_active", false) && !pref.getBoolean("is_hidden", false)) {
-            pref.edit().putBoolean("is_restarting", true).apply();
+            pref.edit()
+                    .putBoolean("is_restarting", true)
+                    .putBoolean("skip_auto_hide_navbar", true)
+                    .apply();
 
             stopTaskbarService(context, true);
             startTaskbarService(context, true);
         } else if(isServiceRunning(context, StartMenuService.class)) {
+            pref.edit().putBoolean("skip_auto_hide_navbar", true).apply();
+
             stopTaskbarService(context, false);
             startTaskbarService(context, false);
         }
index 757d7c3..6e12f73 100644 (file)
     <string name="freeform_on">Freeform on</string>
     <string name="freeform_off">Freeform off</string>
 
+    <string name="auto_hide_navbar">Automatically control the system navigation bar</string>
+    <string name="auto_hide_navbar_description">Hide the navigation bar when Taskbar is active, and show it when Taskbar is inactive</string>
+
 </resources>
index 2a976a8..c07aaf6 100644 (file)
     <string name="freeform_on">Freeform on</string>
     <string name="freeform_off">Freeform off</string>
 
+    <string name="auto_hide_navbar">Automatically control the system navigation bar</string>
+    <string name="auto_hide_navbar_description">Hide the navigation bar when Taskbar is active, and show it when Taskbar is inactive</string>
+
 </resources>
index 9322c41..d0869cf 100644 (file)
     <string name="freeform_on">Freeform on</string>
     <string name="freeform_off">Freeform off</string>
 
+    <string name="auto_hide_navbar">Automatically control the system navigation bar</string>
+    <string name="auto_hide_navbar_description">Hide the navigation bar when Taskbar is active, and show it when Taskbar is inactive</string>
+
 </resources>
index dff6952..c367372 100644 (file)
     <string name="freeform_on">Freeform on</string>
     <string name="freeform_off">Freeform off</string>
 
+    <string name="auto_hide_navbar">Automatically control the system navigation bar</string>
+    <string name="auto_hide_navbar_description">Hide the navigation bar when Taskbar is active, and show it when Taskbar is inactive</string>
+
 </resources>
index d6272fa..7168c20 100644 (file)
         android:key="button_recents"
         android:title="@string/button_recents" />
 
+    <PreferenceCategory android:key="auto_hide_navbar_category" >
+
+        <CheckBoxPreference
+            android:defaultValue="false"
+            android:key="auto_hide_navbar"
+            android:title="@string/auto_hide_navbar"
+            android:summary="@string/auto_hide_navbar_description" />
+
+    </PreferenceCategory>
+
 </PreferenceScreen>