summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornebkat <nebkat@teamhacksung.org>2012-12-22 10:46:58 +0000
committernebkat <nebkat@teamhacksung.org>2012-12-22 20:10:14 +0000
commit1a9d397e9d8f432d6a8acfc96a6378cff57e753a (patch)
tree7581c076b96e3265592a209c8072b90e79005394
parent229ac203294898445ce64e2f9ccd2163d681c276 (diff)
downloadandroid_packages_apps_Trebuchet-1a9d397e9d8f432d6a8acfc96a6378cff57e753a.tar.gz
android_packages_apps_Trebuchet-1a9d397e9d8f432d6a8acfc96a6378cff57e753a.tar.bz2
android_packages_apps_Trebuchet-1a9d397e9d8f432d6a8acfc96a6378cff57e753a.zip
AppsCustomizePagedView: Filtering
Change-Id: I829fc4b1a54e348d3c13da602d133dc20d315cca
-rw-r--r--AndroidManifest.xml4
-rw-r--r--res/layout/hidden_apps_list.xml8
-rw-r--r--res/layout/hidden_apps_list_item.xml34
-rw-r--r--res/menu/apps_tab.xml9
-rw-r--r--res/values/strings.xml12
-rw-r--r--res/xml/preferences_drawer.xml7
-rw-r--r--src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java103
-rw-r--r--src/com/cyanogenmod/trebuchet/Launcher.java10
-rw-r--r--src/com/cyanogenmod/trebuchet/preference/HiddenAppsActivity.java231
-rw-r--r--src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java3
-rw-r--r--src/com/cyanogenmod/trebuchet/widget/CheckableLinearLayout.java50
-rw-r--r--src/com/cyanogenmod/trebuchet/widget/InertCheckBox.java69
12 files changed, 507 insertions, 33 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1a1f6bd94..79b539916 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -115,6 +115,10 @@
<category android:name="com.cyanogenmod.category.LAUNCHER_PREFERENCES" />
</intent-filter>
</activity>
+
+ <activity android:name="com.cyanogenmod.trebuchet.preference.HiddenAppsActivity"
+ android:label="@string/hidden_apps_title"/>
+
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name="com.cyanogenmod.trebuchet.InstallShortcutReceiver"
diff --git a/res/layout/hidden_apps_list.xml b/res/layout/hidden_apps_list.xml
new file mode 100644
index 000000000..cc9447210
--- /dev/null
+++ b/res/layout/hidden_apps_list.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ListView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="5dp"
+ android:choiceMode="multipleChoice"
+ android:layout_alignParentTop="true"/> \ No newline at end of file
diff --git a/res/layout/hidden_apps_list_item.xml b/res/layout/hidden_apps_list_item.xml
new file mode 100644
index 000000000..88fa8b034
--- /dev/null
+++ b/res/layout/hidden_apps_list_item.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.cyanogenmod.trebuchet.widget.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="48dp"
+ android:gravity="center_vertical"
+ android:paddingRight="?android:attr/scrollbarSize"
+ android:background="?android:attr/actionBarItemBackground">
+
+ <ImageView android:id="@+id/icon"
+ android:layout_width="40dp"
+ android:layout_height="40dp"
+ android:layout_gravity="center"/>
+
+ <TextView android:id="@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="15dip"
+ android:layout_marginRight="6dip"
+ android:layout_marginTop="6dip"
+ android:layout_marginBottom="6dip"
+ android:layout_weight="1"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"/>
+
+ <com.cyanogenmod.trebuchet.widget.InertCheckBox android:id="@+id/checkbox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center_vertical"/>
+
+</com.cyanogenmod.trebuchet.widget.CheckableLinearLayout> \ No newline at end of file
diff --git a/res/menu/apps_tab.xml b/res/menu/apps_tab.xml
index 8e95139d1..05573d9db 100644
--- a/res/menu/apps_tab.xml
+++ b/res/menu/apps_tab.xml
@@ -2,9 +2,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="@+id/apps_sort_title"
- android:title="@string/menu_apps_sort_title"
- android:checked="true" />
+ android:title="@string/menu_apps_sort_title" />
<item android:id="@+id/apps_sort_install_date"
android:title="@string/menu_apps_sort_install_date" />
</group>
+ <group android:checkableBehavior="all">
+ <item android:id="@+id/apps_filter_system"
+ android:title="@string/menu_apps_filter_system" />
+ <item android:id="@+id/apps_filter_downloaded"
+ android:title="@string/menu_apps_filter_downloaded" />
+ </group>
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 293d73edb..30d410716 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -164,6 +164,13 @@ s -->
<string name="menu_apps_sort_title">Name</string>
<!-- Noun, menu item used to sort apps by install date -->
<string name="menu_apps_sort_install_date">Install Date</string>
+ <!-- Noun, menu item used to show system apps -->
+ <string name="menu_apps_filter_system">System</string>
+ <!-- Noun, menu item used to show downloaded apps -->
+ <string name="menu_apps_filter_downloaded">Downloaded</string>
+
+ <!-- Noun, menu item used to reset hidden apps list -->
+ <string name="menu_hidden_apps_delete">Reset</string>
<!-- URL pointing to help text. If empty, no link to help will be created [DO NOT TRANSLATE] -->
<string name="help_url" translatable="false"></string>
@@ -291,6 +298,9 @@ s -->
<!-- Dummy string [CHAR_LIMIT=60] -->
<string name="custom_workspace_cling_description_2"></string>
+ <!-- Hidden apps -->
+ <string name="hidden_apps_title">Hidden Apps</string>
+
<skip />
<!-- -->
<!-- Preferences -->
@@ -348,6 +358,8 @@ s -->
<string name="preferences_interface_drawer_summary">Apps and widgets drawer</string>
<string name="preferences_interface_drawer_orientation_title">Orientation</string>
<string name="preferences_interface_drawer_orientation_summary">Choose which way the drawer scrolls</string>
+ <string name="preferences_interface_drawer_hidden_apps_title">Hidden apps</string>
+ <string name="preferences_interface_drawer_hidden_apps_summary">Hide apps from the drawer</string>
<string name="preferences_interface_drawer_widgets_category">Widgets</string>
<string name="preferences_interface_drawer_widgets_join_apps_title">Join with apps</string>
<string name="preferences_interface_drawer_widgets_join_apps_summary">Swipe from apps drawer to widgets drawer without changing tabs</string>
diff --git a/res/xml/preferences_drawer.xml b/res/xml/preferences_drawer.xml
index 3c57d3ed9..3b4a3ef21 100644
--- a/res/xml/preferences_drawer.xml
+++ b/res/xml/preferences_drawer.xml
@@ -24,6 +24,13 @@
android:entries="@array/preferences_interface_drawer_orientation_entries"
android:entryValues="@array/preferences_interface_drawer_orientation_values"
android:defaultValue="horizontal" />
+ <Preference android:key="ui_drawer_hidden_apps"
+ android:title="@string/preferences_interface_drawer_hidden_apps_title"
+ android:summary="@string/preferences_interface_drawer_hidden_apps_summary">
+ <intent
+ android:targetPackage="com.cyanogenmod.trebuchet"
+ android:targetClass="com.cyanogenmod.trebuchet.preference.HiddenAppsActivity"/>
+ </Preference>
<PreferenceCategory android:title="@string/preferences_interface_drawer_widgets_category">
<CheckBoxPreference android:key="ui_drawer_widgets_join_apps"
android:title="@string/preferences_interface_drawer_widgets_join_apps_title"
diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java
index 535338a83..070bfed0a 100644
--- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java
+++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java
@@ -255,6 +255,11 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
InstallDate
}
+ private int mFilterApps = FILTER_APPS_SYSTEM_FLAG | FILTER_APPS_DOWNLOADED_FLAG;
+
+ private static final int FILTER_APPS_SYSTEM_FLAG = 1;
+ private static final int FILTER_APPS_DOWNLOADED_FLAG = 2;
+
// Refs
private Launcher mLauncher;
private DragController mDragController;
@@ -270,6 +275,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
private ContentType mContentType;
private SortMode mSortMode = SortMode.Title;
private ArrayList<ApplicationInfo> mApps;
+ private ArrayList<ApplicationInfo> mFilteredApps;
+ private ArrayList<ComponentName> mHiddenApps;
private ArrayList<Object> mWidgets;
// Cling
@@ -376,6 +383,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mPackageManager = context.getPackageManager();
mContentType = ContentType.Applications;
mApps = new ArrayList<ApplicationInfo>();
+ mFilteredApps = new ArrayList<ApplicationInfo>();
+ mHiddenApps = new ArrayList<ComponentName>();
mWidgets = new ArrayList<Object>();
mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache();
mCanvas = new Canvas();
@@ -397,6 +406,11 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mFadeScrollingIndicator = PreferencesProvider.Interface.Drawer.Indicator.getFadeScrollingIndicator();
mScrollingIndicatorPosition = PreferencesProvider.Interface.Drawer.Indicator.getScrollingIndicatorPosition();
+ String[] flattened = PreferencesProvider.Interface.Drawer.getHiddenApps().split("\\|");
+ for (String flat : flattened) {
+ mHiddenApps.add(ComponentName.unflattenFromString(flat));
+ }
+
if (!mShowScrollingIndicator) {
disableScrollingIndicator();
@@ -451,7 +465,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
i = (currentPage * numItemsPerPage) + (childCount / 2);
}
} else {
- int numApps = mApps.size();
+ int numApps = mFilteredApps.size();
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage);
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
int childCount = layout.getChildCount();
@@ -499,12 +513,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
if (mJoinWidgetsApps) {
if (index < 0) return 0;
- if (index < mApps.size()) {
+ if (index < mFilteredApps.size()) {
int numItemsPerPage = mCellCountX * mCellCountY;
return (index / numItemsPerPage);
} else {
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
- return mNumAppsPages + ((index - mApps.size()) / numItemsPerPage);
+ return mNumAppsPages + ((index - mFilteredApps.size()) / numItemsPerPage);
}
} else {
switch (mContentType) {
@@ -530,7 +544,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
if (mJoinWidgetsApps) {
mNumWidgetPages = (int) Math.ceil(mWidgets.size() /
(float) (mWidgetCountX * mWidgetCountY));
- mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
+ mNumAppsPages = (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY));
}
}
@@ -1202,7 +1216,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
public void syncAppsPages() {
// Ensure that we have the right number of pages
Context context = getContext();
- int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
+ int numPages = (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY));
for (int i = 0; i < numPages; ++i) {
PagedViewCellLayout layout = new PagedViewCellLayout(context);
setupPage(layout);
@@ -1213,14 +1227,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// ensure that we have the right number of items on the pages
int numCells = mCellCountX * mCellCountY;
int startIndex = page * numCells;
- int endIndex = Math.min(startIndex + numCells, mApps.size());
+ int endIndex = Math.min(startIndex + numCells, mFilteredApps.size());
PagedViewCellLayout layout = (PagedViewCellLayout) getPageAt(page);
layout.removeAllViewsOnPage();
ArrayList<Object> items = new ArrayList<Object>();
ArrayList<Bitmap> images = new ArrayList<Bitmap>();
for (int i = startIndex; i < endIndex; ++i) {
- ApplicationInfo info = mApps.get(i);
+ ApplicationInfo info = mFilteredApps.get(i);
PagedViewIcon icon = (PagedViewIcon) mLayoutInflater.inflate(
R.layout.apps_customize_application, layout, false);
icon.applyFromApplicationInfo(info, true, this);
@@ -2256,32 +2270,38 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mSortMode = sortMode;
- if (mSortMode == SortMode.Title) {
- Collections.sort(mApps, LauncherModel.getAppNameComparator());
- } else if (mSortMode == SortMode.InstallDate) {
- Collections.sort(mApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
+ filterApps();
+ }
+
+ public void setShowSystemApps(boolean show) {
+ if (show) {
+ mFilterApps |= FILTER_APPS_SYSTEM_FLAG;
+ } else {
+ mFilterApps &= ~FILTER_APPS_SYSTEM_FLAG;
}
+ filterApps();
+ }
- if (mJoinWidgetsApps) {
- for (int i = 0; i < mNumAppsPages; i++) {
- syncAppsPageItems(i, true);
- }
+ public void setShowDownloadedApps(boolean show) {
+ if (show) {
+ mFilterApps |= FILTER_APPS_DOWNLOADED_FLAG;
} else {
- if (mContentType == ContentType.Applications) {
- for (int i = 0; i < getChildCount(); i++) {
- syncAppsPageItems(i, true);
- }
- }
+ mFilterApps &= ~FILTER_APPS_DOWNLOADED_FLAG;
}
+ filterApps();
+ }
+
+ public boolean getShowSystemApps() {
+ return (mFilterApps & FILTER_APPS_SYSTEM_FLAG) != 0;
+ }
+
+ public boolean getShowDownloadedApps() {
+ return (mFilterApps & FILTER_APPS_DOWNLOADED_FLAG) != 0;
}
public void setApps(ArrayList<ApplicationInfo> list) {
mApps = list;
- if (mSortMode == SortMode.Title) {
- Collections.sort(mApps, LauncherModel.getAppNameComparator());
- } else if (mSortMode == SortMode.InstallDate) {
- Collections.sort(mApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
- }
+ filterAppsWithoutInvalidate();
updatePageCounts();
invalidateOnDataChange();
}
@@ -2290,12 +2310,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
int count = list.size();
for (int i = 0; i < count; ++i) {
ApplicationInfo info = list.get(i);
- int index = 0;
- if (mSortMode == SortMode.Title) {
- index = Collections.binarySearch(mApps, info, LauncherModel.getAppNameComparator());
- } else if (mSortMode == SortMode.InstallDate) {
- index = Collections.binarySearch(mApps, info, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
- }
+ int index = Collections.binarySearch(mApps, info, LauncherModel.getAppNameComparator());
if (index < 0) {
mApps.add(-(index + 1), info);
}
@@ -2303,6 +2318,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
public void addApps(ArrayList<ApplicationInfo> list) {
addAppsWithoutInvalidate(list);
+ filterAppsWithoutInvalidate();
updatePageCounts();
invalidateOnDataChange();
}
@@ -2350,6 +2366,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
public void removeApps(ArrayList<String> packageNames) {
removeAppsWithPackageNameWithoutInvalidate(packageNames);
+ filterAppsWithoutInvalidate();
updatePageCounts();
invalidateOnDataChange();
}
@@ -2359,6 +2376,30 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// place in the list.
removeAppsWithoutInvalidate(list);
addAppsWithoutInvalidate(list);
+ filterAppsWithoutInvalidate();
+ updatePageCounts();
+ invalidateOnDataChange();
+ }
+ public void filterAppsWithoutInvalidate() {
+ mFilteredApps = new ArrayList<ApplicationInfo>(mApps);
+ Iterator<ApplicationInfo> iterator = mFilteredApps.iterator();
+ while (iterator.hasNext()) {
+ ApplicationInfo appInfo = iterator.next();
+ boolean system = (appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0;
+ if (mHiddenApps.contains(appInfo.componentName) ||
+ (system && !getShowSystemApps()) ||
+ (!system && !getShowDownloadedApps())) {
+ iterator.remove();
+ }
+ }
+ if (mSortMode == SortMode.Title) {
+ Collections.sort(mFilteredApps, LauncherModel.getAppNameComparator());
+ } else if (mSortMode == SortMode.InstallDate) {
+ Collections.sort(mFilteredApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
+ }
+ }
+ public void filterApps() {
+ filterAppsWithoutInvalidate();
updatePageCounts();
invalidateOnDataChange();
}
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java
index 28e4f0e5b..3450db6bf 100644
--- a/src/com/cyanogenmod/trebuchet/Launcher.java
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java
@@ -2064,6 +2064,10 @@ public final class Launcher extends Activity
} else if (sortMode == AppsCustomizePagedView.SortMode.InstallDate) {
menu.findItem(R.id.apps_sort_install_date).setChecked(true);
}
+ boolean showSystemApps = mAppsCustomizeContent.getShowSystemApps();
+ boolean showDownloadedApps = mAppsCustomizeContent.getShowDownloadedApps();
+ menu.findItem(R.id.apps_filter_system).setChecked(showSystemApps).setEnabled(showDownloadedApps);
+ menu.findItem(R.id.apps_filter_downloaded).setChecked(showDownloadedApps).setEnabled(showSystemApps);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
@@ -2073,6 +2077,12 @@ public final class Launcher extends Activity
case R.id.apps_sort_install_date:
mAppsCustomizeContent.setSortMode(AppsCustomizePagedView.SortMode.InstallDate);
break;
+ case R.id.apps_filter_system:
+ mAppsCustomizeContent.setShowSystemApps(!item.isChecked());
+ break;
+ case R.id.apps_filter_downloaded:
+ mAppsCustomizeContent.setShowDownloadedApps(!item.isChecked());
+ break;
}
return true;
}
diff --git a/src/com/cyanogenmod/trebuchet/preference/HiddenAppsActivity.java b/src/com/cyanogenmod/trebuchet/preference/HiddenAppsActivity.java
new file mode 100644
index 000000000..3eb6170d5
--- /dev/null
+++ b/src/com/cyanogenmod/trebuchet/preference/HiddenAppsActivity.java
@@ -0,0 +1,231 @@
+package com.cyanogenmod.trebuchet.preference;
+
+import android.app.AlertDialog;
+import android.app.ListActivity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.ResolveInfo;
+import android.content.pm.PackageManager;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.SparseBooleanArray;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.ArrayAdapter;
+import android.widget.Checkable;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.cyanogenmod.trebuchet.R;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class HiddenAppsActivity extends ListActivity implements MenuItem.OnMenuItemClickListener {
+
+ private boolean mSaved;
+
+ private static final int MENU_DELETE = 0;
+
+ private PackageManager mPackageManager;
+
+ private AppsAdapter mAppsAdapter;
+
+ protected void onCreate(Bundle savedInstanceState) {
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+ super.onCreate(savedInstanceState);
+
+ setTitle(R.string.hidden_apps_title);
+ setContentView(R.layout.hidden_apps_list);
+
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ setProgressBarIndeterminateVisibility(true);
+ setProgressBarIndeterminate(true);
+
+ mPackageManager = getPackageManager();
+ mAppsAdapter = new AppsAdapter(this, R.layout.hidden_apps_list_item);
+ mAppsAdapter.setNotifyOnChange(true);
+
+ setListAdapter(mAppsAdapter);
+
+ AsyncTask<Void, Void, Void> refreshAppsTask = new AsyncTask<Void, Void, Void>(){
+
+ @Override
+ protected void onPostExecute(Void result) {
+ restore();
+ setProgressBarIndeterminateVisibility(false);
+ setProgressBarIndeterminate(false);
+ super.onPostExecute(result);
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ refreshApps();
+ return null;
+ }
+ };
+ refreshAppsTask.execute(null, null, null);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ save();
+ }
+
+ private void save() {
+ StringBuilder string = new StringBuilder("");
+
+ SparseBooleanArray checked = getListView().getCheckedItemPositions();
+
+ for (int i = 0; i < checked.size(); i++) {
+ if (checked.valueAt(i)) {
+ ResolveInfo app = (ResolveInfo) getListView().getItemAtPosition(checked.keyAt(i));
+ if (string.length() > 0) string.append("|");
+ string.append(new ComponentName(app.activityInfo.packageName, app.activityInfo.name).flattenToString());
+
+ }
+ }
+
+ SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
+ editor.putString("ui_drawer_hidden_apps", string.toString());
+ editor.commit();
+
+ mSaved = true;
+ }
+
+ private void restore() {
+ List<ComponentName> apps = new ArrayList();
+ String[] flattened = PreferenceManager.getDefaultSharedPreferences(this)
+ .getString("ui_drawer_hidden_apps", "").split("\\|");
+ for (String flat : flattened) {
+ apps.add(ComponentName.unflattenFromString(flat));
+ }
+
+ for (int i = 0; i < getListAdapter().getCount(); i++) {
+ ResolveInfo info = (ResolveInfo) getListAdapter().getItem(i);
+ if (apps.contains(new ComponentName(info.activityInfo.packageName, info.activityInfo.name))) {
+ getListView().setItemChecked(i, true);
+ }
+ }
+
+ mSaved = true;
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+
+ menu.add(0, MENU_DELETE, 0, R.string.menu_hidden_apps_delete)
+ .setOnMenuItemClickListener(this)
+ .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+
+ return true;
+ }
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ switch (item.getItemId()) {
+ case MENU_DELETE:
+ delete();
+ return true;
+ }
+ return false;
+ }
+
+ private void delete() {
+ for (int i = 0; i < getListView().getCount(); i++) {
+ getListView().setItemChecked(i, false);
+ }
+
+ mSaved = false;
+ }
+
+ private void refreshApps() {
+ final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+ final List<ResolveInfo> apps = mPackageManager.queryIntentActivities(mainIntent, 0);
+ Collections.sort(apps, new ResolveInfo.DisplayNameComparator(mPackageManager));
+
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mAppsAdapter.clear();
+ mAppsAdapter.addAll(apps);
+ }
+ });
+ }
+
+ @Override
+ public boolean onMenuItemSelected(int featureId, MenuItem item) {
+ boolean result = super.onMenuItemSelected(featureId, item);
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ return result;
+ }
+
+ private class AppsAdapter extends ArrayAdapter<ResolveInfo> {
+
+ private final LayoutInflater mInfaltor;
+
+ public AppsAdapter(Context context, int textViewResourceId) {
+ super(context, textViewResourceId);
+
+ mInfaltor = LayoutInflater.from(context);
+
+ }
+
+ @Override
+ public long getItemId(int id) {
+ return id;
+ }
+
+ @Override
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ final ResolveInfo info = getItem(position);
+
+ if(convertView == null) {
+ convertView = mInfaltor.inflate(R.layout.hidden_apps_list_item, parent, false);
+ }
+
+ final View item = convertView;
+
+ ImageView icon = (ImageView) item.findViewById(R.id.icon);
+ TextView title = (TextView) item.findViewById(R.id.title);
+
+ icon.setImageDrawable(info.loadIcon(mPackageManager));
+ title.setText(info.loadLabel(mPackageManager));
+
+ item.setTag(info.activityInfo.packageName);
+
+ item.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ getListView().setItemChecked(position, !((Checkable) item).isChecked());
+ mSaved = false;
+ }
+ });
+
+ return convertView;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return true;
+ }
+ }
+}
diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java
index 7866345be..623a2976e 100644
--- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java
+++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java
@@ -141,6 +141,9 @@ public final class PreferencesProvider {
public static boolean getJoinWidgetsApps() {
return getBoolean("ui_drawer_widgets_join_apps", true);
}
+ public static String getHiddenApps() {
+ return getString("ui_drawer_hidden_apps", "");
+ }
public static class Scrolling {
public static AppsCustomizePagedView.TransitionEffect getTransitionEffect(String def) {
try {
diff --git a/src/com/cyanogenmod/trebuchet/widget/CheckableLinearLayout.java b/src/com/cyanogenmod/trebuchet/widget/CheckableLinearLayout.java
new file mode 100644
index 000000000..0e87f801f
--- /dev/null
+++ b/src/com/cyanogenmod/trebuchet/widget/CheckableLinearLayout.java
@@ -0,0 +1,50 @@
+package com.cyanogenmod.trebuchet.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.CheckBox;
+import android.widget.Checkable;
+import android.widget.LinearLayout;
+
+import com.cyanogenmod.trebuchet.R;
+
+/*
+ * This class is useful for using inside of ListView that needs to have checkable items.
+ */
+public class CheckableLinearLayout extends LinearLayout implements Checkable {
+ private CheckBox mCheckBox;
+
+ public CheckableLinearLayout(Context context) {
+ super(context);
+ }
+
+ public CheckableLinearLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public CheckableLinearLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mCheckBox = (CheckBox) findViewById(R.id.checkbox);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mCheckBox.isChecked();
+ }
+
+ @Override
+ public void setChecked(boolean checked) {
+ mCheckBox.setChecked(checked);
+ }
+
+ @Override
+ public void toggle() {
+ mCheckBox.toggle();
+ }
+} \ No newline at end of file
diff --git a/src/com/cyanogenmod/trebuchet/widget/InertCheckBox.java b/src/com/cyanogenmod/trebuchet/widget/InertCheckBox.java
new file mode 100644
index 000000000..bab357b15
--- /dev/null
+++ b/src/com/cyanogenmod/trebuchet/widget/InertCheckBox.java
@@ -0,0 +1,69 @@
+package com.cyanogenmod.trebuchet.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.widget.CheckBox;
+
+
+// CheckBox that does not react to any user event in order to let the container handle them.
+public class InertCheckBox extends CheckBox {
+
+ @SuppressWarnings("unused")
+ public InertCheckBox(Context context) {
+ super(context);
+ }
+
+ @SuppressWarnings("unused")
+ public InertCheckBox(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @SuppressWarnings("unused")
+ public InertCheckBox(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+
+ @Override
+ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+
+ @Override
+ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+
+ @Override
+ public boolean onKeyShortcut(int keyCode, KeyEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+
+ @Override
+ public boolean onTrackballEvent(MotionEvent event) {
+ // Make the checkbox not respond to any user event
+ return false;
+ }
+} \ No newline at end of file