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 {
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);
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();
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;
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;
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;
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 {
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;
});
&& 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;
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);
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);
} else {
return false;
}
+*/
}
}
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
--- /dev/null
+<?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