summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornebkat <nebkat@gmail.com>2011-12-26 12:36:32 +0000
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2012-11-19 01:19:40 +0000
commite78f8ad769c5cbe688f54904c7870a19c0b9e1de (patch)
tree629b542529f428d5cb021bcfe9914abb578e20b1
parent5abfd39cdafb0d960bae913f345d31a91b7e05ca (diff)
downloadpackages_apps_trebuchet-e78f8ad769c5cbe688f54904c7870a19c0b9e1de.zip
packages_apps_trebuchet-e78f8ad769c5cbe688f54904c7870a19c0b9e1de.tar.gz
packages_apps_trebuchet-e78f8ad769c5cbe688f54904c7870a19c0b9e1de.tar.bz2
AppsCustomize: Apps Sorting Mode
Change-Id: I9b376c39da3039b7c9a37f0748a1d6b5dc67a471
-rw-r--r--res/menu/apps_tab.xml10
-rw-r--r--res/values/strings.xml5
-rw-r--r--src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java52
-rw-r--r--src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java9
-rw-r--r--src/com/cyanogenmod/trebuchet/Launcher.java27
5 files changed, 101 insertions, 2 deletions
diff --git a/res/menu/apps_tab.xml b/res/menu/apps_tab.xml
new file mode 100644
index 0000000..8e95139
--- /dev/null
+++ b/res/menu/apps_tab.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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" />
+ <item android:id="@+id/apps_sort_install_date"
+ android:title="@string/menu_apps_sort_install_date" />
+ </group>
+</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8f22fcd..5fbb356 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -158,6 +158,11 @@ s -->
<!-- Noun, menu item used to show help. [CHAR_LIMIT=none] -->
<string name="menu_help">Help</string>
+ <!-- Noun, menu item used to sort apps by name -->
+ <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>
+
<!-- URL pointing to help text. If empty, no link to help will be created [DO NOT TRANSLATE] -->
<string name="help_url" translatable="false"></string>
diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java
index 56ca3e6..d78e341 100644
--- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java
+++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java
@@ -246,6 +246,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
Widgets
}
+ /**
+ * The sorting mode of the apps.
+ */
+ public enum SortMode {
+ Title,
+ InstallDate
+ }
+
// Refs
private Launcher mLauncher;
private DragController mDragController;
@@ -259,6 +267,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Content
private ContentType mContentType;
+ private SortMode mSortMode = SortMode.Title;
private ArrayList<ApplicationInfo> mApps;
private ArrayList<Object> mWidgets;
@@ -1869,9 +1878,43 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
}
+ public SortMode getSortMode() {
+ return mSortMode;
+ }
+
+ public void setSortMode(SortMode sortMode) {
+ if (mSortMode == sortMode) {
+ return;
+ }
+
+ mSortMode = sortMode;
+
+ if (mSortMode == SortMode.Title) {
+ Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
+ } else if (mSortMode == SortMode.InstallDate) {
+ Collections.sort(mApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
+ }
+
+ if (mJoinWidgetsApps) {
+ for (int i = 0; i < mNumAppsPages; i++) {
+ syncAppsPageItems(i, true);
+ }
+ } else {
+ if (mContentType == ContentType.Applications) {
+ for (int i = 0; i < getChildCount(); i++) {
+ syncAppsPageItems(i, true);
+ }
+ }
+ }
+ }
+
public void setApps(ArrayList<ApplicationInfo> list) {
mApps = list;
- Collections.sort(mApps, LauncherModel.getAppNameComparator());
+ if (mSortMode == SortMode.Title) {
+ Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
+ } else if (mSortMode == SortMode.InstallDate) {
+ Collections.sort(mApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
+ }
updatePageCounts();
invalidateOnDataChange();
}
@@ -1880,7 +1923,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
int count = list.size();
for (int i = 0; i < count; ++i) {
ApplicationInfo info = list.get(i);
- int index = Collections.binarySearch(mApps, info, LauncherModel.getAppNameComparator());
+ 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);
+ }
if (index < 0) {
mApps.add(-(index + 1), info);
}
diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java b/src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java
index d9bbe6a..63eb013 100644
--- a/src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java
+++ b/src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java
@@ -70,6 +70,9 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
mTabsContainer.setAlpha(1f);
}
};
+
+ mLauncher = (Launcher) context;
+
// Preferences
mJoinWidgetsApps = PreferencesProvider.Interface.Drawer.getJoinWidgetsApps(context);
mFadeScrollingIndicator = PreferencesProvider.Interface.Drawer.Indicator.getFadeScrollingIndicator(context);
@@ -130,6 +133,12 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
+ tabView.setOnLongClickListener(new View.OnLongClickListener() {
+ public boolean onLongClick(View v) {
+ mLauncher.onLongClickAppsTab(v);
+ return true;
+ }
+ });
addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
label = getContext().getString(R.string.widgets_tab_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java
index b91e718..f0dcfae 100644
--- a/src/com/cyanogenmod/trebuchet/Launcher.java
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java
@@ -89,6 +89,7 @@ import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.widget.Advanceable;
import android.widget.ImageView;
+import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
@@ -2053,6 +2054,32 @@ public final class Launcher extends Activity
}
}
+ public void onLongClickAppsTab(View v) {
+ final PopupMenu popupMenu = new PopupMenu(this, v);
+ final Menu menu = popupMenu.getMenu();
+ popupMenu.inflate(R.menu.apps_tab);
+ AppsCustomizePagedView.SortMode sortMode = mAppsCustomizeContent.getSortMode();
+ if (sortMode == AppsCustomizePagedView.SortMode.Title) {
+ menu.findItem(R.id.apps_sort_title).setChecked(true);
+ } else if (sortMode == AppsCustomizePagedView.SortMode.InstallDate) {
+ menu.findItem(R.id.apps_sort_install_date).setChecked(true);
+ }
+ popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ public boolean onMenuItemClick(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.apps_sort_title:
+ mAppsCustomizeContent.setSortMode(AppsCustomizePagedView.SortMode.Title);
+ break;
+ case R.id.apps_sort_install_date:
+ mAppsCustomizeContent.setSortMode(AppsCustomizePagedView.SortMode.InstallDate);
+ break;
+ }
+ return true;
+ }
+ });
+ popupMenu.show();
+ }
+
void startApplicationDetailsActivity(ComponentName componentName) {
String packageName = componentName.getPackageName();
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,