OSDN Git Service

New Prefrence to Set Start Menu Icon to an Image URI
authorJoshua Spann <jspann128@gmail.com>
Wed, 10 Jul 2019 01:43:28 +0000 (20:43 -0500)
committerJoshua Spann <jspann128@gmail.com>
Wed, 10 Jul 2019 01:43:28 +0000 (20:43 -0500)
app/src/main/java/com/farmerbb/taskbar/fragment/AppearanceFragment.java
app/src/main/java/com/farmerbb/taskbar/ui/TaskbarController.java
app/src/main/res/values/strings.xml
app/src/main/res/xml/pref_appearance.xml

index a43892e..f34faa5 100644 (file)
 
 package com.farmerbb.taskbar.fragment;
 
+import android.Manifest;
 import android.annotation.SuppressLint;
 import android.app.Activity;
+import android.content.ActivityNotFoundException;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.graphics.Color;
 import android.os.Bundle;
 import android.preference.Preference;
+import android.provider.Settings;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AlertDialog;
 import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
 import android.view.View;
 import android.widget.ScrollView;
 import android.widget.SeekBar;
@@ -56,10 +60,15 @@ public class AppearanceFragment extends SettingsFragment implements Preference.O
         findPreference("reset_colors").setOnPreferenceClickListener(this);
         findPreference("background_tint_pref").setOnPreferenceClickListener(this);
         findPreference("accent_color_pref").setOnPreferenceClickListener(this);
+        findPreference("app_drawer_icon_custom").setOnPreferenceClickListener(this);
+        findPreference("app_drawer_icon_image").setOnPreferenceClickListener(this);
+
 
         bindPreferenceSummaryToValue(findPreference("theme"));
         bindPreferenceSummaryToValue(findPreference("invisible_button"));
         bindPreferenceSummaryToValue(findPreference("app_drawer_icon"));
+        bindPreferenceSummaryToValue(findPreference("app_drawer_icon_custom"));
+        bindPreferenceSummaryToValue(findPreference("app_drawer_icon_image"));
         bindPreferenceSummaryToValue(findPreference("icon_pack_use_mask"));
         bindPreferenceSummaryToValue(findPreference("visual_feedback"));
         bindPreferenceSummaryToValue(findPreference("shortcut_icon"));
@@ -157,17 +166,47 @@ public class AppearanceFragment extends SettingsFragment implements Preference.O
             case "accent_color_pref":
                 showColorPicker(ColorPickerType.ACCENT_COLOR);
                 break;
+            case "app_drawer_icon_custom":
+                //android.support.v4.app.ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 100);
+                break;
+            case "app_drawer_icon_image":
+                //android.support.v4.app.ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 100);
+                showFileChooser();
+                break;
         }
 
         return true;
     }
 
+    private void showFileChooser() {
+        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+        intent.setType("image/*");
+        intent.addCategory(Intent.CATEGORY_OPENABLE);
+
+        try {
+            startActivityForResult(Intent.createChooser(intent, "Select an Image File"), 1001);
+        } catch (android.content.ActivityNotFoundException ex) {
+            // Potentially direct the user to the Market with a Dialog
+            U.showToast(getActivity(), "Please install a File Manager.", 50);
+        }
+    }
+
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
         if(requestCode == 123 && resultCode == Activity.RESULT_OK) {
             U.refreshPinnedIcons(getActivity());
             U.restartTaskbar(getActivity());
         }
+
+        if (requestCode == 1001) {
+            android.net.Uri currFileURI = data.getData();
+            final SharedPreferences prefs = android.preference.PreferenceManager.getDefaultSharedPreferences(getActivity());
+            prefs.edit().putString("app_drawer_icon_image", currFileURI.toString()).commit();
+            if(prefs.getBoolean("app_drawer_icon_custom", true) == false) {
+                prefs.edit().putBoolean("app_drawer_icon_custom", true).commit();
+            }
+            U.restartTaskbar(getActivity());
+        }
     }
 
     @SuppressLint("SetTextI18n")
index e149b14..6aa731c 100644 (file)
@@ -33,6 +33,7 @@ import android.content.pm.LauncherActivityInfo;
 import android.content.pm.LauncherApps;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.BitmapFactory;
 import android.graphics.Color;
 import android.graphics.Point;
 import android.graphics.Typeface;
@@ -294,6 +295,19 @@ public class TaskbarController implements Controller {
             padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
         }
 
+        if(pref.getBoolean("app_drawer_icon_custom", true)) {
+            String strPath = "";
+            if (pref.getString("app_drawer_icon_image", "DEFAULT").isEmpty() == false) {
+                try {
+                    strPath = pref.getString("app_drawer_icon_image", "DEFAULT");
+                    startButton.setImageURI(android.net.Uri.parse(strPath));
+                    padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
+                } catch (Exception e) {
+                    U.showToast(this.context, "Error reading the custom image for the start menu. Try another file.", 500);
+                }
+            }
+        }
+
         startButton.setPadding(padding, padding, padding, padding);
         startButton.setOnClickListener(ocl);
         startButton.setOnLongClickListener(view -> {
index a772f5a..bd921af 100644 (file)
     <string name="pref_description_use_mask">May reduce performance when an icon pack is set</string>
 
     <string name="pref_title_app_drawer_icon">Use Taskbar logo as start menu icon</string>
+    <string name="pref_title_app_drawer_icon_custom">Use custom image as start menu icon</string>
+    <string name="pref_title_app_drawer_icon_image">Custom Image Path</string>
     <string name="pref_title_app_drawer_icon_bliss">Use Bliss logo as start menu icon</string>
 
     <string name="already_blacklisted">%1$s can\'t be selected because it is on the hidden apps list</string>
index e203aec..06d5f8c 100644 (file)
         android:title="@string/pref_title_app_drawer_icon"/>
 
     <CheckBoxPreference
+        android:defaultValue="false"
+        android:key="app_drawer_icon_custom"
+        android:title="@string/pref_title_app_drawer_icon_custom"/>
+
+    <Preference
+        android:key="app_drawer_icon_image"
+        android:title="@string/pref_title_app_drawer_icon_image"/>
+
+    <CheckBoxPreference
         android:defaultValue="true"
         android:key="shortcut_icon"
         android:title="@string/pref_title_shortcut_icon"/>