diff options
-rw-r--r-- | res/menu/apps_tab.xml | 10 | ||||
-rw-r--r-- | res/values/strings.xml | 5 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java | 53 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java | 12 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Launcher.java | 25 |
5 files changed, 102 insertions, 3 deletions
diff --git a/res/menu/apps_tab.xml b/res/menu/apps_tab.xml new file mode 100644 index 000000000..8e95139d1 --- /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 3f4f89cfe..f8ed8476c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -155,6 +155,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 c2ad80580..c4274bdd7 100644 --- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java +++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java @@ -181,6 +181,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; @@ -193,6 +201,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Content private ContentType mContentType; + private SortMode mSortMode = SortMode.Title; private ArrayList<ApplicationInfo> mApps; private ArrayList<Object> mWidgets; @@ -1565,10 +1574,45 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public boolean isAnimating() { return false; } + + 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); + } + } + } + } + @Override public void setApps(ArrayList<ApplicationInfo> list) { mApps = list; - Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); + 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(); // The next layout pass will trigger data-ready if both widgets and apps are set, so @@ -1580,7 +1624,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.APP_NAME_COMPARATOR); + int index = 0; + if (mSortMode == SortMode.Title) { + index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); + } 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 ad02a305a..6a97ea052 100644 --- a/src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java +++ b/src/com/cyanogenmod/trebuchet/AppsCustomizeTabHost.java @@ -39,7 +39,7 @@ import com.cyanogenmod.trebuchet.preference.PreferencesProvider; import java.util.ArrayList; public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable, - TabHost.OnTabChangeListener { + TabHost.OnTabChangeListener { static final String LOG_TAG = "AppsCustomizeTabHost"; private static final String APPS_TAB_TAG = "APPS"; @@ -53,6 +53,8 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona private FrameLayout mAnimationBuffer; private LinearLayout mContent; + private Launcher mLauncher; + private boolean mInTransition; private boolean mResetAfterTransition; private Animator mLauncherTransition; @@ -65,6 +67,8 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona super(context, attrs); mLayoutInflater = LayoutInflater.from(context); + mLauncher = (Launcher) context; + // Preferences mJoinWidgetsApps = PreferencesProvider.Interface.Drawer.getJoinWidgetsApps(context); mFadeScrollingIndicator = PreferencesProvider.Interface.Drawer.Indicator.getFadeScrollingIndicator(context); @@ -125,6 +129,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 = mContext.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 84a798e02..0df98045e 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -1786,6 +1786,31 @@ public final class Launcher extends Activity popupMenu.show(); } + 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(); |