summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-07-01 07:45:18 (GMT)
committerAbhisek Devkota <ciwrl@cyanogenmod.com>2014-12-02 01:17:02 (GMT)
commitc398b8b621f284295b8eafb9c729743a53f40ad2 (patch)
treeaebfcfa32ce00caad80325370625b9154b5c1e34
parentb96792dcc654626cf1a57bd1b23efbb330de4664 (diff)
downloadandroid_packages_apps_Trebuchet-c398b8b621f284295b8eafb9c729743a53f40ad2.zip
android_packages_apps_Trebuchet-c398b8b621f284295b8eafb9c729743a53f40ad2.tar.gz
android_packages_apps_Trebuchet-c398b8b621f284295b8eafb9c729743a53f40ad2.tar.bz2
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
-rw-r--r--src/com/android/launcher3/Folder.java43
-rw-r--r--src/com/android/launcher3/HiddenFolderFragment.java57
2 files changed, 40 insertions, 60 deletions
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 89785fe..3a43ec1 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -35,6 +35,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;
@@ -59,6 +60,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.
@@ -71,8 +73,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;
@@ -277,50 +279,37 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mLauncher.validateLockForHiddenFolders(bundle, mFolderIcon);
}
- public String[] getComponentTitles() {
+ public List<Pair<ComponentName, CharSequence>> getComponents() {
int size = mItemsInReadingOrder.size();
- String[] componentsTitles = new String[size];
+ List<Pair<ComponentName, CharSequence>> components =
+ new ArrayList<Pair<ComponentName, CharSequence>>();
+
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<ComponentName> components = new ArrayList<ComponentName>();
+ for (Pair<ComponentName, CharSequence> 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;
diff --git a/src/com/android/launcher3/HiddenFolderFragment.java b/src/com/android/launcher3/HiddenFolderFragment.java
index 07b0e4a..de37671 100644
--- a/src/com/android/launcher3/HiddenFolderFragment.java
+++ b/src/com/android/launcher3/HiddenFolderFragment.java
@@ -1,33 +1,32 @@
package com.android.launcher3;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-
import android.app.Fragment;
import android.app.FragmentTransaction;
-import android.media.Image;
-import android.text.InputType;
-import android.view.KeyEvent;
-import android.view.MenuItem;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.*;
-import com.android.launcher3.settings.SettingsProvider;
-
-import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
+import android.media.Image;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.util.Log;
+import android.text.InputType;
+import android.util.Pair;
+import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
public class HiddenFolderFragment extends Fragment {
public static final String HIDDEN_FOLDER_FRAGMENT = "hiddenFolderFragment";
@@ -39,8 +38,6 @@ public class HiddenFolderFragment extends Fragment {
private static final int REQ_LOCK_PATTERN = 1;
- private String[] mComponentInfo;
- private String[] mComponentTitles;
private boolean mHidden;
private PackageManager mPackageManager;
private AppsAdapter mAppsAdapter;
@@ -76,8 +73,6 @@ public class HiddenFolderFragment extends Fragment {
mHidden = getArguments().getBoolean(HIDDEN_FOLDER_STATUS);
Folder folder = mLauncher.mHiddenFolderIcon.getFolder();
- mComponentInfo = folder.getComponents();
- mComponentTitles = folder.getComponentTitles();
String title = mLauncher.mHiddenFolderIcon.getFolderInfo().title.toString();
mFolderName = (EditText) v.findViewById(R.id.folder_name);
@@ -113,7 +108,7 @@ public class HiddenFolderFragment extends Fragment {
mAppsAdapter = new AppsAdapter(mLauncher, R.layout.hidden_apps_list_item);
mAppsAdapter.setNotifyOnChange(true);
- mAppEntries = loadApps();
+ mAppEntries = loadApps(folder.getComponents());
mAppsAdapter.clear();
mAppsAdapter.addAll(mAppEntries);
@@ -131,11 +126,10 @@ public class HiddenFolderFragment extends Fragment {
mListView.requestFocus();
}
- private ArrayList<AppEntry> loadApps() {
+ private ArrayList<AppEntry> loadApps(List<Pair<ComponentName, CharSequence>> items) {
ArrayList<AppEntry> apps = new ArrayList<AppEntry>();
- int size = mComponentInfo.length;
- for (int i = 0; i < size; i++) {
- apps.add(new AppEntry(mComponentInfo[i], mComponentTitles[i]));
+ for (Pair<ComponentName, CharSequence> item : items) {
+ apps.add(new AppEntry(item.first, item.second));
}
return apps;
}
@@ -158,10 +152,8 @@ public class HiddenFolderFragment extends Fragment {
View v = folder.getViewFromPosition(position);
Object tag = v.getTag();
if (tag instanceof ShortcutInfo) {
- mLauncher.startActivitySafely(v,
- ((ShortcutInfo) tag).getIntent(),
- v.getTag());
-
+ ShortcutInfo shortcut = (ShortcutInfo) tag;
+ mLauncher.startActivitySafely(v, shortcut.getIntent(), v.getTag());
return;
}
}
@@ -317,12 +309,11 @@ public class HiddenFolderFragment extends Fragment {
}
private final class AppEntry {
-
public final ComponentName componentName;
- public final String title;
+ public final CharSequence title;
- public AppEntry(String component, String title) {
- componentName = ComponentName.unflattenFromString(component);
+ public AppEntry(ComponentName component, CharSequence title) {
+ this.componentName = component;
this.title = title;
}
}