OSDN Git Service

Begin in-app documentation of desktop mode
authorBraden Farmer <farmerbb@gmail.com>
Sun, 24 May 2020 05:59:01 +0000 (23:59 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Sun, 24 May 2020 05:59:01 +0000 (23:59 -0600)
12 files changed:
app/src/main/java/com/farmerbb/taskbar/activity/EnableAdditionalSettingsActivity.java [new file with mode: 0644]
app/src/main/java/com/farmerbb/taskbar/activity/dark/EnableAdditionalSettingsActivityDark.java [new file with mode: 0644]
app/src/main/java/com/farmerbb/taskbar/fragment/DesktopModeFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/GeneralFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/RecentAppsFragment.java
app/src/main/java/com/farmerbb/taskbar/util/Constants.java
app/src/main/java/com/farmerbb/taskbar/util/U.java
app/src/main/res/layout/tb_enable_additional_settings.xml [new file with mode: 0644]
app/src/main/res/values/donottranslate.xml
app/src/main/res/values/strings.xml
app/src/main/res/values/styles.xml
app/src/playstore/AndroidManifest.xml

diff --git a/app/src/main/java/com/farmerbb/taskbar/activity/EnableAdditionalSettingsActivity.java b/app/src/main/java/com/farmerbb/taskbar/activity/EnableAdditionalSettingsActivity.java
new file mode 100644 (file)
index 0000000..6151d5b
--- /dev/null
@@ -0,0 +1,41 @@
+/* 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.activity;
+
+import android.Manifest;
+import android.os.Bundle;
+import androidx.appcompat.app.AppCompatActivity;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.farmerbb.taskbar.R;
+
+public class EnableAdditionalSettingsActivity extends AppCompatActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        setContentView(R.layout.tb_enable_additional_settings);
+        setTitle(R.string.tb_enable_additional_settings);
+
+        TextView adbShellCommand = findViewById(R.id.adb_shell_command);
+        adbShellCommand.setText(getString(R.string.tb_adb_shell_command, getPackageName(), Manifest.permission.WRITE_SECURE_SETTINGS));
+
+        Button button = findViewById(R.id.close_button);
+        button.setOnClickListener(v -> finish());
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/farmerbb/taskbar/activity/dark/EnableAdditionalSettingsActivityDark.java b/app/src/main/java/com/farmerbb/taskbar/activity/dark/EnableAdditionalSettingsActivityDark.java
new file mode 100644 (file)
index 0000000..c24b548
--- /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.activity.dark;
+
+import com.farmerbb.taskbar.activity.EnableAdditionalSettingsActivity;
+
+public class EnableAdditionalSettingsActivityDark extends EnableAdditionalSettingsActivity {}
\ No newline at end of file
index 320496b..f03e1b5 100644 (file)
@@ -28,9 +28,11 @@ import android.preference.Preference;
 import android.provider.Settings;
 
 import androidx.appcompat.app.ActionBar;
 import android.provider.Settings;
 
 import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatActivity;
 
 import com.farmerbb.taskbar.R;
 import androidx.appcompat.app.AppCompatActivity;
 
 import com.farmerbb.taskbar.R;
+import com.farmerbb.taskbar.activity.EnableAdditionalSettingsActivity;
 import com.farmerbb.taskbar.activity.HSLActivity;
 import com.farmerbb.taskbar.activity.HSLConfigActivity;
 import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
 import com.farmerbb.taskbar.activity.HSLActivity;
 import com.farmerbb.taskbar.activity.HSLConfigActivity;
 import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
@@ -44,6 +46,8 @@ public class DesktopModeFragment extends SettingsFragment {
 
     public static boolean isConfiguringHomeApp;
 
 
     public static boolean isConfiguringHomeApp;
 
+    private boolean updateAdditionalSettings;
+
     private DisplayManager.DisplayListener listener = new DisplayManager.DisplayListener() {
         @Override
         public void onDisplayAdded(int displayId) {
     private DisplayManager.DisplayListener listener = new DisplayManager.DisplayListener() {
         @Override
         public void onDisplayAdded(int displayId) {
@@ -71,6 +75,7 @@ public class DesktopModeFragment extends SettingsFragment {
         findPreference(PREF_SET_LAUNCHER_DEFAULT).setOnPreferenceClickListener(this);
         findPreference(PREF_PRIMARY_LAUNCHER).setOnPreferenceClickListener(this);
         findPreference(PREF_DIM_SCREEN).setOnPreferenceClickListener(this);
         findPreference(PREF_SET_LAUNCHER_DEFAULT).setOnPreferenceClickListener(this);
         findPreference(PREF_PRIMARY_LAUNCHER).setOnPreferenceClickListener(this);
         findPreference(PREF_DIM_SCREEN).setOnPreferenceClickListener(this);
+        findPreference(PREF_ENABLE_ADDITIONAL_SETTINGS).setOnPreferenceClickListener(this);
 
         SharedPreferences pref = U.getSharedPreferences(getActivity());
         if(pref.getBoolean(PREF_LAUNCHER, false)) {
 
         SharedPreferences pref = U.getSharedPreferences(getActivity());
         if(pref.getBoolean(PREF_LAUNCHER, false)) {
@@ -102,10 +107,20 @@ public class DesktopModeFragment extends SettingsFragment {
     public void onResume() {
         super.onResume();
 
     public void onResume() {
         super.onResume();
 
-        if(isConfiguringHomeApp)
-            startStopDesktopMode(true);
+        if(showReminderToast) {
+            showReminderToast = false;
+            desktopModeSetupComplete();
+        }
+
+        if(updateAdditionalSettings) {
+            updateAdditionalSettings = false;
+            updateAdditionalSettings();
+        }
 
 
-        isConfiguringHomeApp = false;
+        if(isConfiguringHomeApp) {
+            isConfiguringHomeApp = false;
+            startStopDesktopMode(true);
+        }
 
         Preference primaryLauncherPref = findPreference(PREF_PRIMARY_LAUNCHER);
         if(primaryLauncherPref != null) {
 
         Preference primaryLauncherPref = findPreference(PREF_PRIMARY_LAUNCHER);
         if(primaryLauncherPref != null) {
@@ -141,6 +156,40 @@ public class DesktopModeFragment extends SettingsFragment {
             case PREF_DESKTOP_MODE:
                 boolean isChecked = ((CheckBoxPreference) p).isChecked();
 
             case PREF_DESKTOP_MODE:
                 boolean isChecked = ((CheckBoxPreference) p).isChecked();
 
+                if(isChecked && !U.isDesktopModePrefEnabled(getActivity())) {
+                    try {
+                        Settings.Global.putInt(getActivity().getContentResolver(), "enable_freeform_support", 1);
+                        Settings.Global.putInt(getActivity().getContentResolver(), "force_desktop_mode_on_external_displays", 1);
+                        U.showToastLong(getActivity(), R.string.tb_reboot_required);
+                    } catch (Exception e) {
+                        ((CheckBoxPreference) p).setChecked(false);
+                        isChecked = false;
+
+                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+                        builder.setTitle(R.string.tb_desktop_mode_dialog_title)
+                                .setMessage(R.string.tb_freeform_dialog_message)
+                                .setPositiveButton(R.string.tb_action_developer_options, (dialogInterface, i) -> {
+                                    showReminderToast = true;
+
+                                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
+                                    try {
+                                        startActivity(intent);
+                                        U.showToastLong(getActivity(), R.string.tb_enable_desktop_mode);
+                                    } catch (ActivityNotFoundException e1) {
+                                        intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
+                                        try {
+                                            startActivity(intent);
+                                            U.showToastLong(getActivity(), R.string.tb_enable_developer_options);
+                                        } catch (ActivityNotFoundException e2) { /* Gracefully fail */ }
+                                    }
+                                });
+
+                        AlertDialog dialog = builder.create();
+                        dialog.show();
+                        dialog.setCancelable(false);
+                    }
+                }
+
                 U.setComponentEnabled(getActivity(), SecondaryHomeActivity.class, isChecked);
                 U.setComponentEnabled(getActivity(), HSLActivity.class, isChecked);
                 startStopDesktopMode(isChecked);
                 U.setComponentEnabled(getActivity(), SecondaryHomeActivity.class, isChecked);
                 U.setComponentEnabled(getActivity(), HSLActivity.class, isChecked);
                 startStopDesktopMode(isChecked);
@@ -173,6 +222,10 @@ public class DesktopModeFragment extends SettingsFragment {
                     U.sendBroadcast(getActivity(), ACTION_FINISH_DIM_SCREEN_ACTIVITY);
 
                 break;
                     U.sendBroadcast(getActivity(), ACTION_FINISH_DIM_SCREEN_ACTIVITY);
 
                 break;
+            case PREF_ENABLE_ADDITIONAL_SETTINGS:
+                updateAdditionalSettings = true;
+                startActivity(U.getThemedIntent(getActivity(), EnableAdditionalSettingsActivity.class));
+                break;
         }
 
         return super.onPreferenceClick(p);
         }
 
         return super.onPreferenceClick(p);
@@ -239,4 +292,14 @@ public class DesktopModeFragment extends SettingsFragment {
 
         finishedLoadingPrefs = true;
     }
 
         finishedLoadingPrefs = true;
     }
+
+    private void desktopModeSetupComplete() {
+        boolean desktopModeEnabled = U.isDesktopModePrefEnabled(getActivity());
+        ((CheckBoxPreference) findPreference(PREF_DESKTOP_MODE)).setChecked(desktopModeEnabled);
+
+        if(desktopModeEnabled)
+            U.showToastLong(getActivity(), R.string.tb_reboot_required_alt);
+
+        updateAdditionalSettings();
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file
index 23946d0..b077824 100644 (file)
@@ -43,14 +43,13 @@ public class GeneralFragment extends SettingsFragment {
         // Set OnClickListeners for certain preferences
         findPreference(PREF_BLACKLIST).setOnPreferenceClickListener(this);
 
         // Set OnClickListeners for certain preferences
         findPreference(PREF_BLACKLIST).setOnPreferenceClickListener(this);
 
-        if(!U.isLibrary(getActivity()) && !U.isAndroidTV(getActivity()))
-            findPreference(PREF_NOTIFICATION_SETTINGS).setOnPreferenceClickListener(this);
-        else {
+        if(U.isLibrary(getActivity()) || U.isAndroidTV(getActivity())) {
             getPreferenceScreen().removePreference(findPreference(PREF_NOTIFICATION_SETTINGS));
 
             if(!U.isAndroidTV(getActivity()))
                 getPreferenceScreen().removePreference(findPreference(PREF_START_ON_BOOT));
             getPreferenceScreen().removePreference(findPreference(PREF_NOTIFICATION_SETTINGS));
 
             if(!U.isAndroidTV(getActivity()))
                 getPreferenceScreen().removePreference(findPreference(PREF_START_ON_BOOT));
-        }
+        } else
+            findPreference(PREF_NOTIFICATION_SETTINGS).setOnPreferenceClickListener(this);
 
         if(U.canEnableFreeform()
                 && !U.isChromeOs(getActivity())
 
         if(U.canEnableFreeform()
                 && !U.isChromeOs(getActivity())
index 2f99df7..9940eb0 100644 (file)
@@ -77,10 +77,10 @@ public class RecentAppsFragment extends SettingsFragment implements SharedPrefer
         bindPreferenceSummaryToValue(findPreference(PREF_CENTERED_ICONS));
 
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
         bindPreferenceSummaryToValue(findPreference(PREF_CENTERED_ICONS));
 
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-            if(!U.isAndroidTV(getActivity()))
-                findPreference(PREF_NOTIFICATION_COUNT).setOnPreferenceClickListener(this);
-            else
+            if(U.isAndroidTV(getActivity()))
                 getPreferenceScreen().removePreference(findPreference(PREF_NOTIFICATION_COUNT));
                 getPreferenceScreen().removePreference(findPreference(PREF_NOTIFICATION_COUNT));
+            else
+                findPreference(PREF_NOTIFICATION_COUNT).setOnPreferenceClickListener(this);
 
             bindPreferenceSummaryToValue(findPreference(PREF_SYS_TRAY));
         } else {
 
             bindPreferenceSummaryToValue(findPreference(PREF_SYS_TRAY));
         } else {
index 0ae18a2..e71159e 100644 (file)
@@ -121,6 +121,7 @@ public class Constants {
     public static final String PREF_DONT_STOP_DASHBOARD = "dont_stop_dashboard";
     public static final String PREF_DOUBLE_TAP_DIALOG_SHOWN = "double_tap_dialog_shown";
     public static final String PREF_DOUBLE_TAP_TO_SLEEP = "double_tap_to_sleep";
     public static final String PREF_DONT_STOP_DASHBOARD = "dont_stop_dashboard";
     public static final String PREF_DOUBLE_TAP_DIALOG_SHOWN = "double_tap_dialog_shown";
     public static final String PREF_DOUBLE_TAP_TO_SLEEP = "double_tap_to_sleep";
+    public static final String PREF_ENABLE_ADDITIONAL_SETTINGS = "enable_additional_settings";
     public static final String PREF_ENABLE_RECENTS = "enable_recents";
     public static final String PREF_FILE_MANAGER = "file_manager";
     public static final String PREF_FIRST_RUN = "first_run";
     public static final String PREF_ENABLE_RECENTS = "enable_recents";
     public static final String PREF_FILE_MANAGER = "file_manager";
     public static final String PREF_FIRST_RUN = "first_run";
index 8888d22..f71c55c 100644 (file)
@@ -1785,7 +1785,7 @@ public class U {
                 && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS);
     }
 
                 && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS);
     }
 
-    public static boolean isDesktopModeActive(Context context) {
+    public static boolean isDesktopModePrefEnabled(Context context) {
         if(!isDesktopModeSupported(context) || !hasFreeformSupport(context))
             return false;
 
         if(!isDesktopModeSupported(context) || !hasFreeformSupport(context))
             return false;
 
@@ -1797,7 +1797,11 @@ public class U {
             desktopModePrefEnabled = false;
         }
 
             desktopModePrefEnabled = false;
         }
 
-        return desktopModePrefEnabled && getExternalDisplayID(context) != Display.DEFAULT_DISPLAY;
+        return desktopModePrefEnabled;
+    }
+
+    public static boolean isDesktopModeActive(Context context) {
+        return isDesktopModePrefEnabled(context) && getExternalDisplayID(context) != Display.DEFAULT_DISPLAY;
     }
 
     private static Display getExternalDisplay(Context context) {
     }
 
     private static Display getExternalDisplay(Context context) {
diff --git a/app/src/main/res/layout/tb_enable_additional_settings.xml b/app/src/main/res/layout/tb_enable_additional_settings.xml
new file mode 100644 (file)
index 0000000..c902be1
--- /dev/null
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="8dp" >
+
+    <ScrollView
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1" >
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:padding="16dp"
+                android:textColor="?tb_text_color"
+                android:textSize="16sp"
+                android:text="@string/tb_enable_additional_settings_message"/>
+
+            <TextView
+                android:id="@+id/adb_shell_command"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:paddingLeft="16dp"
+                android:paddingRight="16dp"
+                android:textColor="?tb_text_color"
+                android:textSize="12sp"
+                android:fontFamily="monospace"
+                android:textIsSelectable="true" />
+
+        </LinearLayout>
+
+    </ScrollView>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="bottom|end"
+        android:padding="16dp">
+
+        <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@android:color/transparent"
+            android:text="@string/tb_action_close"
+            android:gravity="bottom|end"
+            android:textColor="@color/tb_colorAccent"
+            android:id="@+id/close_button" />
+
+    </LinearLayout>
+
+</LinearLayout>
index 8e1769d..ea21ad1 100644 (file)
@@ -21,7 +21,8 @@
     <string name="tb_x" translatable="false">&#215;</string>
     <string name="tb_dashboard_grid_description" translatable="false">%1$d &#215; %2$d</string>
     <string name="tb_infinity" translatable="false">&#8734;</string>
     <string name="tb_x" translatable="false">&#215;</string>
     <string name="tb_dashboard_grid_description" translatable="false">%1$d &#215; %2$d</string>
     <string name="tb_infinity" translatable="false">&#8734;</string>
-    <string name="tb_systray_clock">%1$s\n%2$s</string>
+    <string name="tb_systray_clock" translatable="false">%1$s\n%2$s</string>
+    <string name="tb_adb_shell_command" translatable="false">adb shell pm grant %1$s %2$s</string>
 
     <string-array name="tb_pref_start_menu_list_values">
         <item>grid</item>
 
     <string-array name="tb_pref_start_menu_list_values">
         <item>grid</item>
index ac905d2..6463aaf 100644 (file)
     <string name="tb_pref_notification_count_title">Show notification count in status area</string>
     <string name="tb_pref_notification_count_description">Requires notification access</string>
 
     <string name="tb_pref_notification_count_title">Show notification count in status area</string>
     <string name="tb_pref_notification_count_description">Requires notification access</string>
 
+    <string name="tb_desktop_mode_dialog_title">Enable desktop mode support</string>
+    <string name="tb_desktop_mode_dialog_message">In order for Taskbar to support desktop mode, please follow these steps:\n\n&#8226; Go to Developer Options\n\n&#8226; Scroll to the bottom and turn on \"Enable freeform windows\" and \"Force desktop mode\"\n\n&#8226; Reboot your device</string>
+    <string name="tb_enable_desktop_mode">Scroll to the bottom and turn on \"Enable freeform support\" and \"Force desktop mode\"</string>
+    <string name="tb_reboot_required_alt">Reboot your device to complete desktop mode setup</string>
+    <string name="tb_enable_additional_settings_message">Taskbar can optionally use elevated permissions to improve your desktop mode experience. These permissions are granted by running an adb shell command.\n\nIf you wish to continue, connect your device to a computer with the Android SDK installed, and run the following command (one line):</string>
+
 </resources>
 </resources>
index 0b855e9..f908f27 100644 (file)
         <item name="tb_settings_icon_color">@color/tb_settings_icon_color_dark</item>
     </style>
 
         <item name="tb_settings_icon_color">@color/tb_settings_icon_color_dark</item>
     </style>
 
+    <style name="Taskbar.Dialog.FullWidth" parent="Theme.AppCompat.Light.Dialog">
+        <item name="colorPrimary">@color/tb_colorPrimary</item>
+        <item name="colorPrimaryDark">@color/tb_colorPrimaryDark</item>
+        <item name="colorAccent">@color/tb_colorAccent</item>
+        <item name="android:windowMinWidthMajor">95%</item>
+        <item name="android:windowMinWidthMinor">95%</item>
+    </style>
+
+    <style name="Taskbar.Dialog.FullWidth.Dark" parent="Theme.AppCompat.Dialog">
+        <item name="colorPrimary">@color/tb_colorPrimary</item>
+        <item name="colorPrimaryDark">@color/tb_colorPrimaryDark</item>
+        <item name="colorAccent">@color/tb_colorAccent</item>
+        <item name="android:windowMinWidthMajor">95%</item>
+        <item name="android:windowMinWidthMinor">95%</item>
+    </style>
+
 </resources>
\ No newline at end of file
 </resources>
\ No newline at end of file
index e9d29ac..87c6020 100644 (file)
             android:theme="@style/Taskbar.DimScreenActivity"
             android:screenOrientation="portrait"
             android:launchMode="singleTask"/>
             android:theme="@style/Taskbar.DimScreenActivity"
             android:screenOrientation="portrait"
             android:launchMode="singleTask"/>
+        <activity
+            android:name=".activity.EnableAdditionalSettingsActivity"
+            android:theme="@style/Taskbar.Dialog.FullWidth"/>
+        <activity
+            android:name=".activity.dark.EnableAdditionalSettingsActivityDark"
+            android:theme="@style/Taskbar.Dialog.FullWidth.Dark"/>
 
         <service android:name=".service.TaskbarService"/>
         <service android:name=".service.StartMenuService"/>
 
         <service android:name=".service.TaskbarService"/>
         <service android:name=".service.StartMenuService"/>