From 4ff96f59b1403b5949e706462d5e2e08b967dabf Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Tue, 1 Jul 2014 09:45:18 +0200 Subject: Clean up protected apps code (2/2) - Work with actual component names instead of converting them between ComponentName and String all the time - Some misc. coding style adaptions Change-Id: I7401ea471d618936e880e6d542744f80f89ce40f --- src/com/android/launcher3/Folder.java | 43 +++++++++++++---------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'src/com/android/launcher3/Folder.java') diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index 71183c342..b584b950d 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -34,6 +34,7 @@ import android.text.Selection; import android.text.Spannable; import android.util.AttributeSet; import android.util.Log; +import android.util.Pair; import android.view.ActionMode; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -57,6 +58,7 @@ import com.android.launcher3.settings.SettingsProvider; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.List; /** * Represents a set of icons chosen by the user or generated by the system. @@ -69,8 +71,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList private static final String PROTECTED_ACTION = "cyanogenmod.intent.action.PACKAGE_PROTECTED"; private static final String PROTECTED_STATE = "cyanogenmod.intent.action.PACKAGE_PROTECTED_STATE"; - private static final String PROTECTED_COMPONENT = - "cyanogenmod.intent.action.PACKAGE_PROTECTED_COMPONENT"; + private static final String PROTECTED_COMPONENTS = + "cyanogenmod.intent.action.PACKAGE_PROTECTED_COMPONENTS"; protected DragController mDragController; protected Launcher mLauncher; @@ -267,50 +269,37 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mLauncher.validateLockForHiddenFolders(bundle, mFolderIcon); } - public String[] getComponentTitles() { + public List> getComponents() { int size = mItemsInReadingOrder.size(); - String[] componentsTitles = new String[size]; + List> components = + new ArrayList>(); + for (int i = 0; i < size; i++) { View v = mItemsInReadingOrder.get(i); Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { - componentsTitles[i] = ((ShortcutInfo) tag).title.toString(); + ShortcutInfo shortcut = (ShortcutInfo) tag; + components.add(Pair.create(shortcut.getIntent().getComponent(), shortcut.title)); } } - return componentsTitles; - } - public String[] getComponents() { - String components = getComponentString(); - return components.split("\\|"); + return components; } public void modifyProtectedApps(boolean protect) { - String components = getComponentString(); + ArrayList components = new ArrayList(); + for (Pair item : getComponents()) { + components.add(item.first); + } Intent intent = new Intent(); intent.setAction(PROTECTED_ACTION); intent.putExtra(PROTECTED_STATE, protect); - intent.putExtra(PROTECTED_COMPONENT, components); + intent.putExtra(PROTECTED_COMPONENTS, components); mLauncher.sendBroadcast(intent); } - private String getComponentString() { - int size = mItemsInReadingOrder.size(); - String components = ""; - for (int i = 0; i < size; i++) { - View v = mItemsInReadingOrder.get(i); - Object tag = v.getTag(); - if (tag instanceof ShortcutInfo) { - ComponentName componentName = ((ShortcutInfo) tag).getIntent().getComponent(); - components += componentName.flattenToString() + "|"; - } - } - - return components; - } - public boolean onLongClick(View v) { // Return if global dragging is not enabled if (!mLauncher.isDraggingEnabled()) return true; -- cgit v1.2.3