OSDN Git Service

Continue work on desktop icons
authorBraden Farmer <farmerbb@gmail.com>
Tue, 30 Jul 2019 05:55:42 +0000 (23:55 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Tue, 30 Jul 2019 05:55:42 +0000 (23:55 -0600)
app/src/main/java/com/farmerbb/taskbar/activity/ContextMenuActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/HomeActivityDelegate.java
app/src/main/res/values-de/strings.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values-nl/strings.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values-tr/strings.xml
app/src/main/res/values-zh-rCN/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/pref_context_menu_remove_desktop_icon.xml [new file with mode: 0644]

index c13e0cf..693a117 100644 (file)
@@ -60,6 +60,9 @@ import com.farmerbb.taskbar.util.PinnedBlockedApps;
 import com.farmerbb.taskbar.util.SavedWindowSizes;
 import com.farmerbb.taskbar.util.U;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+
 import java.util.List;
 
 public class ContextMenuActivity extends PreferenceActivity implements Preference.OnPreferenceClickListener {
@@ -324,7 +327,10 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
             homeIntent.addCategory(Intent.CATEGORY_HOME);
             ResolveInfo defaultLauncher = pm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);
 
-            if(!packageName.contains(BuildConfig.BASE_APPLICATION_ID)
+            if(desktopIcon != null) {
+                addPreferencesFromResource(R.xml.pref_context_menu_remove_desktop_icon);
+                findPreference("remove_desktop_icon").setOnPreferenceClickListener(this);
+            } else if(!packageName.contains(BuildConfig.BASE_APPLICATION_ID)
                     && !packageName.equals(defaultLauncher.activityInfo.packageName)) {
                 PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
 
@@ -704,6 +710,28 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
                 shouldHideTaskbar = true;
                 contextMenuFix = false;
                 break;
+            case "remove_desktop_icon":
+                try {
+                    SharedPreferences pref5 = U.getSharedPreferences(this);
+                    JSONArray jsonIcons = new JSONArray(pref5.getString("desktop_icons", "[]"));
+                    int iconToRemove = -1;
+
+                    for(int i = 0; i < jsonIcons.length(); i++) {
+                        DesktopIconInfo info = DesktopIconInfo.fromJson(jsonIcons.getJSONObject(i));
+                        if(info != null && info.column == desktopIcon.column && info.row == desktopIcon.row) {
+                            iconToRemove = i;
+                            break;
+                        }
+                    }
+
+                    if(iconToRemove > -1) {
+                        jsonIcons.remove(iconToRemove);
+
+                        pref5.edit().putString("desktop_icons", jsonIcons.toString()).apply();
+                        LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.REFRESH_DESKTOP_ICONS"));
+                    }
+                } catch (JSONException e) { /* Gracefully fail */ }
+                break;
         }
 
         if(!secondaryMenu) finish();
index 263b7e9..49d1e37 100644 (file)
@@ -27,7 +27,6 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
-import android.content.pm.LauncherActivityInfo;
 import android.graphics.PorterDuff;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
@@ -45,7 +44,6 @@ import android.view.WindowManager;
 import android.widget.FrameLayout;
 import android.widget.GridLayout;
 import android.widget.ImageView;
-import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.farmerbb.taskbar.R;
@@ -66,6 +64,7 @@ import com.farmerbb.taskbar.util.FeatureFlags;
 import com.farmerbb.taskbar.util.FreeformHackHelper;
 import com.farmerbb.taskbar.util.IconCache;
 import com.farmerbb.taskbar.util.LauncherHelper;
+import com.farmerbb.taskbar.util.MenuHelper;
 import com.farmerbb.taskbar.util.U;
 
 import org.json.JSONArray;
@@ -74,7 +73,6 @@ import org.json.JSONException;
 import java.text.Collator;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 public class HomeActivityDelegate extends Activity implements UIHost {
@@ -518,10 +516,32 @@ public class HomeActivityDelegate extends Activity implements UIHost {
 
             int index = i;
 
+            iconContainer.setOnClickListener(view -> {
+                boolean isStartMenuOpen = MenuHelper.getInstance().isStartMenuOpen();
+                LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
+
+                DesktopIconInfo info = icons.get(index);
+                if(!isStartMenuOpen && info != null && info.entry != null) {
+                    U.launchApp(
+                            this,
+                            info.entry.getPackageName(),
+                            info.entry.getComponentName(),
+                            info.entry.getUserId(this),
+                            null,
+                            false,
+                            false
+                    );
+                }
+            });
+
             iconContainer.setOnLongClickListener(view -> {
                 int[] location = new int[2];
                 view.getLocationOnScreen(location);
-                openContextMenu(null, location, getDesktopIconInfo(index));
+
+                DesktopIconInfo info = icons.get(index);
+                if(info == null) info = getDesktopIconInfo(index);
+
+                openContextMenu(info, location);
                 return true;
             });
 
@@ -532,7 +552,11 @@ public class HomeActivityDelegate extends Activity implements UIHost {
                         && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                     int[] location = new int[2];
                     view.getLocationOnScreen(location);
-                    openContextMenu(null, location, getDesktopIconInfo(index));
+
+                    DesktopIconInfo info = icons.get(index);
+                    if(info == null) info = getDesktopIconInfo(index);
+
+                    openContextMenu(info, location);
                 }
 
                 return false;
@@ -606,29 +630,18 @@ public class HomeActivityDelegate extends Activity implements UIHost {
         ImageView imageView = icon.findViewById(R.id.icon);
         imageView.setImageDrawable(entry.getIcon(this));
 
-        LinearLayout layout = icon.findViewById(R.id.entry);
-        layout.setOnClickListener(view -> U.launchApp(
-                this,
-                entry.getPackageName(),
-                entry.getComponentName(),
-                entry.getUserId(this),
-                null,
-                false,
-                false
-        ));
-
         icon.setOnTouchListener(new DesktopIconTouchListener());
         return icon;
     }
 
-    private void openContextMenu(final AppEntry entry, final int[] location, DesktopIconInfo info) {
+    private void openContextMenu(final DesktopIconInfo info, final int[] location) {
         Bundle args = new Bundle();
 
-        if(entry != null) {
-            args.putString("package_name", entry.getPackageName());
-            args.putString("app_name", entry.getLabel());
-            args.putString("component_name", entry.getComponentName());
-            args.putLong("user_id", entry.getUserId(this));
+        if(info.entry != null) {
+            args.putString("package_name", info.entry.getPackageName());
+            args.putString("app_name", info.entry.getLabel());
+            args.putString("component_name", info.entry.getComponentName());
+            args.putLong("user_id", info.entry.getUserId(this));
         }
 
         args.putSerializable("desktop_icon", info);
@@ -640,6 +653,9 @@ public class HomeActivityDelegate extends Activity implements UIHost {
 
     private final class DesktopIconTouchListener implements View.OnTouchListener {
         public boolean onTouch(View view, MotionEvent motionEvent) {
+            view.setAlpha(motionEvent.getAction() == MotionEvent.ACTION_DOWN ? 0.5f : 1);
+            return false;
+/*
             if(motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                 ClipData data = ClipData.newPlainText("", "");
                 View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
@@ -649,6 +665,7 @@ public class HomeActivityDelegate extends Activity implements UIHost {
             } else {
                 return false;
             }
+*/
         }
     }
 
@@ -670,6 +687,7 @@ public class HomeActivityDelegate extends Activity implements UIHost {
                 case DragEvent.ACTION_DRAG_EXITED:
                 case DragEvent.ACTION_DRAG_ENDED:
                     v.setBackground(null);
+                    v.setVisibility(View.VISIBLE);
                     break;
                 case DragEvent.ACTION_DROP:
                     // Dropped, reassign View to ViewGroup
index a092ce6..3e73454 100644 (file)
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
index 4f88a8d..6ded948 100644 (file)
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
\ No newline at end of file
index 816d590..1ff150f 100644 (file)
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
index ac9d1c0..02423c9 100644 (file)
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
\ No newline at end of file
index d2ec32f..62ba5ac 100644 (file)
@@ -364,5 +364,6 @@ Bu durumda, bu cihazdaki serbest biçimli modu kullanmak için özel bir ROM fla
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
\ No newline at end of file
index 2d7c57f..26e3fc5 100644 (file)
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
\ No newline at end of file
index 6774b23..b8bd6cc 100644 (file)
     <string name="add_icon_to_desktop">Add icon to desktop</string>
     <string name="arrange_icons">Arrange icons</string>
     <string name="select_an_app">Select an app</string>
+    <string name="remove_desktop_icon">Remove desktop icon</string>
 
 </resources>
diff --git a/app/src/main/res/xml/pref_context_menu_remove_desktop_icon.xml b/app/src/main/res/xml/pref_context_menu_remove_desktop_icon.xml
new file mode 100644 (file)
index 0000000..c62b216
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <Preference
+        android:key="remove_desktop_icon"
+        android:title="@string/remove_desktop_icon" />
+
+</PreferenceScreen>
\ No newline at end of file