diff options
-rw-r--r-- | res/layout-xlarge-land/all_apps_tabbed.xml | 49 | ||||
-rw-r--r-- | res/layout-xlarge-land/customization_drawer.xml | 8 | ||||
-rw-r--r-- | res/layout-xlarge-port/all_apps_tabbed.xml (renamed from res/layout-xlarge/all_apps_tabbed.xml) | 6 | ||||
-rw-r--r-- | res/layout-xlarge-port/customization_drawer.xml | 8 | ||||
-rw-r--r-- | res/values/attrs.xml | 5 | ||||
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/com/android/launcher2/AllAppsPagedView.java | 14 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 189 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 27 |
9 files changed, 284 insertions, 26 deletions
diff --git a/res/layout-xlarge-land/all_apps_tabbed.xml b/res/layout-xlarge-land/all_apps_tabbed.xml new file mode 100644 index 000000000..4f573f8a8 --- /dev/null +++ b/res/layout-xlarge-land/all_apps_tabbed.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<com.android.launcher2.AllAppsTabbed + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher" + android:background="#30000000" + android:paddingTop="?android:attr/actionBarSize"> + <LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <TabWidget + android:id="@android:id/tabs" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:tabStripEnabled="false" + android:paddingBottom="10dp" /> + <FrameLayout + android:id="@android:id/tabcontent" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <com.android.launcher2.AllAppsPagedView + android:id="@+id/all_apps_paged_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + launcher:cellCountX="7" + launcher:cellCountY="4" + launcher:pageLayoutPaddingTop="10dp" + launcher:pageLayoutPaddingBottom="15dp" + launcher:pageLayoutPaddingLeft="20dp" + launcher:pageLayoutPaddingRight="20dp"> + </com.android.launcher2.AllAppsPagedView> + </FrameLayout> + </LinearLayout> +</com.android.launcher2.AllAppsTabbed> diff --git a/res/layout-xlarge-land/customization_drawer.xml b/res/layout-xlarge-land/customization_drawer.xml index 4fcf761d1..7ad913236 100644 --- a/res/layout-xlarge-land/customization_drawer.xml +++ b/res/layout-xlarge-land/customization_drawer.xml @@ -19,4 +19,10 @@ android:layout_width="match_parent" android:layout_height="match_parent" - launcher:widgetCellCountX="16" />
\ No newline at end of file + launcher:widgetCellCountX="16" + launcher:cellCountX="7" + launcher:cellCountY="4" + launcher:pageLayoutPaddingTop="10dp" + launcher:pageLayoutPaddingBottom="15dp" + launcher:pageLayoutPaddingLeft="20dp" + launcher:pageLayoutPaddingRight="20dp" />
\ No newline at end of file diff --git a/res/layout-xlarge/all_apps_tabbed.xml b/res/layout-xlarge-port/all_apps_tabbed.xml index 5aca95404..2ff044792 100644 --- a/res/layout-xlarge/all_apps_tabbed.xml +++ b/res/layout-xlarge-port/all_apps_tabbed.xml @@ -38,7 +38,11 @@ android:layout_width="match_parent" android:layout_height="match_parent" launcher:cellCountX="7" - launcher:cellCountY="4"> + launcher:cellCountY="4" + launcher:pageLayoutPaddingTop="10dp" + launcher:pageLayoutPaddingBottom="10dp" + launcher:pageLayoutPaddingLeft="0dp" + launcher:pageLayoutPaddingRight="0dp"> </com.android.launcher2.AllAppsPagedView> </FrameLayout> </LinearLayout> diff --git a/res/layout-xlarge-port/customization_drawer.xml b/res/layout-xlarge-port/customization_drawer.xml index 6e4bc4c23..db264b228 100644 --- a/res/layout-xlarge-port/customization_drawer.xml +++ b/res/layout-xlarge-port/customization_drawer.xml @@ -19,4 +19,10 @@ android:layout_width="match_parent" android:layout_height="match_parent" - launcher:widgetCellCountX="12" />
\ No newline at end of file + launcher:widgetCellCountX="12" + launcher:cellCountX="7" + launcher:cellCountY="4" + launcher:pageLayoutPaddingTop="10dp" + launcher:pageLayoutPaddingBottom="15dp" + launcher:pageLayoutPaddingLeft="0dp" + launcher:pageLayoutPaddingRight="0dp" />
\ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 3ef26fb05..bb1b85f3b 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -75,6 +75,11 @@ <attr name="cellCountX" /> <!-- The number of vertical cells in a page --> <attr name="cellCountY" /> + <!-- The padding of the pages that are dynamically created per page --> + <attr name="pageLayoutPaddingTop" format="dimension" /> + <attr name="pageLayoutPaddingBottom" format="dimension" /> + <attr name="pageLayoutPaddingLeft" format="dimension" /> + <attr name="pageLayoutPaddingRight" format="dimension" /> </declare-styleable> <!-- CustomizePagedView specific attributes. These attributes are used to customize diff --git a/res/values/strings.xml b/res/values/strings.xml index 00febfee5..4d88a3355 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -50,9 +50,11 @@ <string name="folders_tab_label">Folders</string> <!-- Title of tab containing all possible shortcuts (eg Contacts, Bookmarks) that can be added to the home screen --> - <string name="shortcuts_tab_label">Shortcuts</string> + <string name="shortcuts_tab_label">More</string> <!-- Title of tab for configuring wallpapers --> <string name="wallpapers_tab_label">Wallpapers</string> + <!-- Title of tab for configuring applications --> + <string name="applications_tab_label">App Shortcuts</string> <!-- Placeholder text, will be removed --> <string name="wallpapers_temp_tab_text">This will be the wallpapers tab</string> <!-- Labels for the tabs in All Apps --> diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index a2a3793dd..04e1cd96b 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -68,6 +68,10 @@ public class AllAppsPagedView extends PagedView private int mCellCountX; private int mCellCountY; + private int mPageLayoutPaddingTop; + private int mPageLayoutPaddingBottom; + private int mPageLayoutPaddingLeft; + private int mPageLayoutPaddingRight; private final LayoutInflater mInflater; @@ -90,6 +94,14 @@ public class AllAppsPagedView extends PagedView TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6); mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); + mPageLayoutPaddingTop = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingTop, 10); + mPageLayoutPaddingBottom = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingBottom, 10); + mPageLayoutPaddingLeft = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingLeft, 10); + mPageLayoutPaddingRight = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingRight, 10); mInflater = LayoutInflater.from(context); a.recycle(); setSoundEffectsEnabled(false); @@ -354,6 +366,8 @@ public class AllAppsPagedView extends PagedView for (int i = curNumPages; i < numPages; ++i) { PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); layout.setCellCount(mCellCountX, mCellCountY); + layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, + mPageLayoutPaddingRight, mPageLayoutPaddingBottom); addView(layout); } diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 8fb3025c0..ead258c8c 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -59,7 +59,8 @@ public class CustomizePagedView extends PagedView WidgetCustomization, FolderCustomization, ShortcutCustomization, - WallpaperCustomization + WallpaperCustomization, + ApplicationCustomization } /** @@ -109,9 +110,14 @@ public class CustomizePagedView extends PagedView private List<ResolveInfo> mFolderList; private List<ResolveInfo> mShortcutList; private List<ResolveInfo> mWallpaperList; - - private static final int sCellCountX = 8; - private static final int sCellCountY = 4; + private List<ApplicationInfo> mApps; + + private int mCellCountX; + private int mCellCountY; + private int mPageLayoutPaddingTop; + private int mPageLayoutPaddingBottom; + private int mPageLayoutPaddingLeft; + private int mPageLayoutPaddingRight; private static final int sMinWidgetCellHSpan = 2; private static final int sMaxWidgetCellHSpan = 4; @@ -132,14 +138,27 @@ public class CustomizePagedView extends PagedView public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, + TypedArray a; + a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, defStyle, 0); + mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8); + a.recycle(); + a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); + mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 7); + mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); + mPageLayoutPaddingTop = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingTop, 10); + mPageLayoutPaddingBottom = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingBottom, 10); + mPageLayoutPaddingLeft = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingLeft, 10); + mPageLayoutPaddingRight = a.getDimensionPixelSize( + R.styleable.PagedView_pageLayoutPaddingRight, 10); + a.recycle(); mCustomizationType = CustomizationType.WidgetCustomization; mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>(); mWorkspaceWidgetLayout = new PagedViewCellLayout(context); mInflater = LayoutInflater.from(context); - mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8); - a.recycle(); setVisibility(View.GONE); setSoundEffectsEnabled(false); @@ -152,6 +171,93 @@ public class CustomizePagedView extends PagedView mPackageManager = context.getPackageManager(); } + /** + * Sets the list of applications that launcher has loaded. + */ + public void setApps(ArrayList<ApplicationInfo> list) { + mApps = list; + Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); + mPageViewIconCache.clear(); + invalidatePageData(); + } + + /** + * Convenience function to add new items to the set of applications that were previously loaded. + * Called by both updateApps() and setApps(). + */ + private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { + // we add it in place, in alphabetical order + final int count = list.size(); + for (int i = 0; i < count; ++i) { + final ApplicationInfo info = list.get(i); + final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); + if (index < 0) { + mApps.add(-(index + 1), info); + } + } + } + + /** + * Adds new applications to the loaded list, and notifies the paged view to update itself. + */ + public void addApps(ArrayList<ApplicationInfo> list) { + addAppsWithoutInvalidate(list); + invalidatePageData(); + } + + /** + * Convenience function to remove items to the set of applications that were previously loaded. + * Called by both updateApps() and removeApps(). + */ + private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { + // loop through all the apps and remove apps that have the same component + final int length = list.size(); + for (int i = 0; i < length; ++i) { + final ApplicationInfo info = list.get(i); + int removeIndex = findAppByComponent(mApps, info); + if (removeIndex > -1) { + mApps.remove(removeIndex); + mPageViewIconCache.removeOutline(info); + } + } + } + + /** + * Removes applications from the loaded list, and notifies the paged view to update itself. + */ + public void removeApps(ArrayList<ApplicationInfo> list) { + removeAppsWithoutInvalidate(list); + invalidatePageData(); + } + + /** + * Updates a set of applications from the loaded list, and notifies the paged view to update + * itself. + */ + public void updateApps(ArrayList<ApplicationInfo> list) { + // We remove and re-add the updated applications list because it's properties may have + // changed (ie. the title), and this will ensure that the items will be in their proper + // place in the list. + removeAppsWithoutInvalidate(list); + addAppsWithoutInvalidate(list); + invalidatePageData(); + } + + /** + * Convenience function to find matching ApplicationInfos for removal. + */ + private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) { + ComponentName removeComponent = item.intent.getComponent(); + final int length = list.size(); + for (int i = 0; i < length; ++i) { + ApplicationInfo info = list.get(i); + if (info.intent.getComponent().equals(removeComponent)) { + return i; + } + } + return -1; + } + public void update() { Context context = getContext(); @@ -312,6 +418,13 @@ public class CustomizePagedView extends PagedView } }); return true; + case ApplicationCustomization: + // Pick up the application for dropping + ApplicationInfo app = (ApplicationInfo) v.getTag(); + app = new ApplicationInfo(app); + + mDragController.startDrag(v, this, app, DragController.DRAG_ACTION_COPY); + return true; } return false; } @@ -417,12 +530,13 @@ public class CustomizePagedView extends PagedView } private void setupPage(PagedViewCellLayout layout) { - layout.setCellCount(sCellCountX, sCellCountY); - layout.setPadding(20, 10, 20, 0); + layout.setCellCount(mCellCountX, mCellCountY); + layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, + mPageLayoutPaddingBottom); } private void setupWorkspaceLayout() { - mWorkspaceWidgetLayout.setCellCount(sCellCountX, sCellCountY); + mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY); mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0); mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan); @@ -486,7 +600,7 @@ public class CustomizePagedView extends PagedView removeAllViews(); // ensure that we have the right number of pages - int numPages = (int) Math.ceil((float) list.size() / (sCellCountX * sCellCountY)); + int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY)); for (int i = 0; i < numPages; ++i) { PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); setupPage(layout); @@ -496,7 +610,7 @@ public class CustomizePagedView extends PagedView private void syncListPageItems(int page, List<ResolveInfo> list) { // ensure that we have the right number of items on the pages - int numCells = sCellCountX * sCellCountY; + int numCells = mCellCountX * mCellCountY; int startIndex = page * numCells; int endIndex = Math.min(startIndex + numCells, list.size()); PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); @@ -514,8 +628,48 @@ public class CustomizePagedView extends PagedView } final int index = i - startIndex; - final int x = index % sCellCountX; - final int y = index / sCellCountX; + final int x = index % mCellCountX; + final int y = index / mCellCountX; + setupPage(layout); + layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); + } + } + + private void syncAppPages() { + if (mApps == null) return; + + // We need to repopulate with PagedViewCellLayouts + removeAllViews(); + + // Ensure that we have the right number of pages + int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); + for (int i = 0; i < numPages; ++i) { + PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); + setupPage(layout); + addView(layout); + } + } + + private void syncAppPageItems(int page) { + if (mApps == null) return; + + // 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()); + PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); + // TODO: we can optimize by just re-applying to existing views + layout.removeAllViews(); + for (int i = startIndex; i < endIndex; ++i) { + final ApplicationInfo info = mApps.get(i); + PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( + R.layout.all_apps_paged_view_application, layout, false); + icon.applyFromApplicationInfo(info, mPageViewIconCache); + icon.setOnLongClickListener(this); + + final int index = i - startIndex; + final int x = index % mCellCountX; + final int y = index / mCellCountX; setupPage(layout); layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); } @@ -540,6 +694,10 @@ public class CustomizePagedView extends PagedView syncListPages(mWallpaperList); centerPagedViewCellLayouts = true; break; + case ApplicationCustomization: + syncAppPages(); + centerPagedViewCellLayouts = false; + break; default: removeAllViews(); setCurrentPage(0); @@ -579,6 +737,9 @@ public class CustomizePagedView extends PagedView case WallpaperCustomization: syncListPageItems(page, mWallpaperList); break; + case ApplicationCustomization: + syncAppPageItems(page); + break; } } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index d619aa2ce..c82f99828 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -177,6 +177,7 @@ public final class Launcher extends Activity // tags for the customization tabs private static final String WIDGETS_TAG = "widgets"; + private static final String APPLICATIONS_TAG = "applications"; private static final String FOLDERS_TAG = "folders"; private static final String SHORTCUTS_TAG = "shortcuts"; private static final String WALLPAPERS_TAG = "wallpapers"; @@ -292,15 +293,18 @@ public final class Launcher extends Activity String widgetsLabel = getString(R.string.widgets_tab_label); mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG) .setIndicator(widgetsLabel).setContent(contentFactory)); + String applicationsLabel = getString(R.string.applications_tab_label); + mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG) + .setIndicator(applicationsLabel).setContent(contentFactory)); String foldersLabel = getString(R.string.folders_tab_label); mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG) .setIndicator(foldersLabel).setContent(contentFactory)); - String shortcutsLabel = getString(R.string.shortcuts_tab_label); - mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG) - .setIndicator(shortcutsLabel).setContent(contentFactory)); String wallpapersLabel = getString(R.string.wallpapers_tab_label); mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG) .setIndicator(wallpapersLabel).setContent(contentFactory)); + String shortcutsLabel = getString(R.string.shortcuts_tab_label); + mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG) + .setIndicator(shortcutsLabel).setContent(contentFactory)); // TEMP: just styling the tab widget to be a bit nicer until we get the actual // new assets @@ -327,20 +331,23 @@ public final class Launcher extends Activity if (tag == WIDGETS_TAG) { mCustomizePagedView.setCustomizationFilter( CustomizePagedView.CustomizationType.WidgetCustomization); + } else if (tag == APPLICATIONS_TAG) { + mCustomizePagedView.setCustomizationFilter( + CustomizePagedView.CustomizationType.ApplicationCustomization); } else if (tag == FOLDERS_TAG) { mCustomizePagedView.setCustomizationFilter( CustomizePagedView.CustomizationType.FolderCustomization); - } else if (tag == SHORTCUTS_TAG) { - mCustomizePagedView.setCustomizationFilter( - CustomizePagedView.CustomizationType.ShortcutCustomization); } else if (tag == WALLPAPERS_TAG) { mCustomizePagedView.setCustomizationFilter( CustomizePagedView.CustomizationType.WallpaperCustomization); + } else if (tag == SHORTCUTS_TAG) { + mCustomizePagedView.setCustomizationFilter( + CustomizePagedView.CustomizationType.ShortcutCustomization); } final float alpha = mCustomizePagedView.getAlpha(); - ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView, - "alpha", alpha, 1.0f); + ValueAnimator alphaAnim = new ObjectAnimator(duration, + mCustomizePagedView, "alpha", alpha, 1.0f); alphaAnim.start(); } }); @@ -2976,6 +2983,7 @@ public final class Launcher extends Activity */ public void bindAllApplications(ArrayList<ApplicationInfo> apps) { mAllAppsGrid.setApps(apps); + mCustomizePagedView.setApps(apps); updateAppMarketIcon(); } @@ -2987,6 +2995,7 @@ public final class Launcher extends Activity public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { removeDialog(DIALOG_CREATE_SHORTCUT); mAllAppsGrid.addApps(apps); + mCustomizePagedView.addApps(apps); updateAppMarketIcon(); } @@ -2999,6 +3008,7 @@ public final class Launcher extends Activity removeDialog(DIALOG_CREATE_SHORTCUT); mWorkspace.updateShortcuts(apps); mAllAppsGrid.updateApps(apps); + mCustomizePagedView.updateApps(apps); updateAppMarketIcon(); } @@ -3013,6 +3023,7 @@ public final class Launcher extends Activity mWorkspace.removeItems(apps); } mAllAppsGrid.removeApps(apps); + mCustomizePagedView.removeApps(apps); updateAppMarketIcon(); } |