From 9678557e66afe9c76103119df30ee13bf79581df Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 14 Oct 2010 13:37:13 -0700 Subject: [PATCH] Adding message when there are no icons in a particular tab. Change-Id: Icbf122d10d07fcacb8a4429431ea389826a3d173 --- res/drawable-xlarge/ic_no_applications.png | Bin 0 -> 3190 bytes ....xml => all_apps_no_items_placeholder.xml} | 8 +- res/values/strings.xml | 6 + .../android/launcher2/AllAppsPagedView.java | 106 +++++++++++++----- src/com/android/launcher2/PagedViewIcon.java | 2 +- 5 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 res/drawable-xlarge/ic_no_applications.png rename res/layout-xlarge/{customize_paged_view_wallpaper_placeholder.xml => all_apps_no_items_placeholder.xml} (87%) diff --git a/res/drawable-xlarge/ic_no_applications.png b/res/drawable-xlarge/ic_no_applications.png new file mode 100644 index 0000000000000000000000000000000000000000..a4f695aca830a48a382468cd205a7d6c57ee1c92 GIT binary patch literal 3190 zcmV-+42koJP)6`CR- z6=?v4kT{#`CEo4Sc5IJ5_RPHHzT11p?>TQCV|yl<@lcd29X-z*`z_!7&N<&X_Zn__ zUIoP*pCow5j$51>DboGZKJ&!_z!=bWei4*n0fdS~3}`WAnDrdA0k>*{F9JL4V3;q? z7@-?SQY;rnMPdiLFSoryZM(fnz0#N%&M+%mzS<12F@tOL;TuFms=%0Vf_}z^fnu_R zFA^)+eR+ofkcc2-g@c-A0HPVD8X17BW{~AqF>V0EB?M|BGgSuy2UF+V1{kWvkO538 zuF&h~CVL7A4!=r3n3+T{*uYHEC?Fb2o%0!hD26dWWaDQO6!WOlYm-6&!xtC~WUzua zOrqwZ=43`)#!(^>#+FhWLl_uI<7j1#Vu>{c0fxVT7Y23_WlO7O)({O#ff4rLx~nVj zRclLe^M(Kpl{$3SRaM%?$po68mO(5k!&rZe8$2|@A2~Y1^%}flB8-sX-7^ zAQ+0Fnf)XD!M_ZO`{yx?(qBtZo42tCFO!vs^_U4XyL8VL5WA?#G)yoU5bkeO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zd1c5FOAO|mV+zKR2AAHnD=cr{TCWBx3+x^%QkbNH!R3`9wuL9Nk!-HF2*!2bdLM40 zk~>)E)fbl+iZw_&7$94Qpd6WK?W#Lzobb3f;xks_q<8--96ddQCKL?8mt??PD&1UM zCJl_WUR-xySbns%3}4Q^I61|2z1S_i*E7e(spj}sYngs`h{vlEM6*!SnE=WQAgPsm z2?5t5t@2Y>*Qvo$qxBc`>n&lQ9)9vu*K0?n`I&zV2>m~3)q|`x2)|rRxp0@U#SeaK zg}N?Mj)P^+g*3{H6=d`rdN?9~ovG-(J<`eED8ecR|92zT7{ZqbB*6Nn_S(ax%+OlUAA(e1SaOSKP1W;BW7wbg`8ZfP6mi3;sTmUhb9<)Dp zOK%L!BF!En%v$2kMx`O*#h%Zm_}=%2gfp`lz*`0CTX!JgYynv@%UF7-CLl^jj2nFG zwD^IgGedf5%TG5KiR4b)}90ldr6q7xq!mw;Ey^u zx7{iJ>VWjlq>K_AA}&mzNK5>bBBa4K1zbV_S_wy#2^mfQrrq&oy_-}}3i0gs^aWXs zNFGZZdLh=|$2 z5QbQSt99QNHg3vWY6oJ|0Xne#r-RM%2?zk`i}7YK)$<)gGWAl;n<8TtmI5SG!Bxn7 zV_jyoE diff --git a/res/values/strings.xml b/res/values/strings.xml index 4f74b59859..89992827c0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -67,6 +67,12 @@ Downloaded + + + No games found. + + No downloaded apps found. + %1$d x %2$d diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index cbb46e2fdd..42101eb4ca 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -16,13 +16,16 @@ package com.android.launcher2; -import com.android.launcher.R; +import java.util.ArrayList; +import java.util.Collections; import android.content.ComponentName; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.ActionMode; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -32,8 +35,7 @@ import android.view.animation.AnimationUtils; import android.widget.Checkable; import android.widget.TextView; -import java.util.ArrayList; -import java.util.Collections; +import com.android.launcher.R; /** * An implementation of PagedView that populates the pages of the workspace @@ -341,8 +343,9 @@ public class AllAppsPagedView extends PagedView @Override public void syncPages() { - // ensure that we have the right number of pages - int numPages = (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)); + // ensure that we have the right number of pages (min of 1, since we have placeholders) + int numPages = Math.max(1, + (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY))); int curNumPages = getChildCount(); // remove any extra pages after the "last" page int extraPageDiff = curNumPages - numPages; @@ -364,41 +367,82 @@ public class AllAppsPagedView extends PagedView @Override public void syncPageItems(int page) { - // ensure that we have the right number of items on the pages + // Ensure that we have the right number of items on the pages final int cellsPerPage = mCellCountX * mCellCountY; final int startIndex = page * cellsPerPage; final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size()); PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); - final int curNumPageItems = layout.getChildCount(); - final int numPageItems = endIndex - startIndex; + if (!mFilteredApps.isEmpty()) { + int curNumPageItems = layout.getChildCount(); + int numPageItems = endIndex - startIndex; - // remove any extra items - int extraPageItemsDiff = curNumPageItems - numPageItems; - for (int i = 0; i < extraPageItemsDiff; ++i) { - layout.removeViewAt(numPageItems); - } - // add any necessary items - for (int i = curNumPageItems; i < numPageItems; ++i) { - TextView text = (TextView) mInflater.inflate(R.layout.all_apps_paged_view_application, layout, false); - text.setOnClickListener(this); - text.setOnLongClickListener(this); + // If we were previously an empty page, then restart anew + boolean wasEmptyPage = false; + if (curNumPageItems == 1) { + View icon = layout.getChildAt(0); + if (icon.getTag() == null) { + wasEmptyPage = true; + } + } - layout.addViewToCellLayout(text, -1, i, - new PagedViewCellLayout.LayoutParams(0, 0, 1, 1)); - } + if (wasEmptyPage) { + // Remove all the previous items + curNumPageItems = 0; + layout.removeAllViews(); + } else { + // Remove any extra items + int extraPageItemsDiff = curNumPageItems - numPageItems; + for (int i = 0; i < extraPageItemsDiff; ++i) { + layout.removeViewAt(numPageItems); + } + } - // actually reapply to the existing text views - for (int i = startIndex; i < endIndex; ++i) { - final int index = i - startIndex; - final ApplicationInfo info = mFilteredApps.get(i); - PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index); - icon.applyFromApplicationInfo(info, mPageViewIconCache); + // Add any necessary items + for (int i = curNumPageItems; i < numPageItems; ++i) { + TextView text = (TextView) mInflater.inflate( + R.layout.all_apps_paged_view_application, layout, false); + text.setOnClickListener(this); + text.setOnLongClickListener(this); - PagedViewCellLayout.LayoutParams params = - (PagedViewCellLayout.LayoutParams) icon.getLayoutParams(); - params.cellX = index % mCellCountX; - params.cellY = index / mCellCountX; + layout.addViewToCellLayout(text, -1, i, + new PagedViewCellLayout.LayoutParams(0, 0, 1, 1)); + } + + // Actually reapply to the existing text views + for (int i = startIndex; i < endIndex; ++i) { + final int index = i - startIndex; + final ApplicationInfo info = mFilteredApps.get(i); + PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index); + icon.applyFromApplicationInfo(info, mPageViewIconCache); + + PagedViewCellLayout.LayoutParams params = + (PagedViewCellLayout.LayoutParams) icon.getLayoutParams(); + params.cellX = index % mCellCountX; + params.cellY = index / mCellCountX; + } + + // Default to left-aligned icons + layout.enableCenteredContent(false); + } else { + // There are no items, so show the user a small message + TextView icon = (TextView) mInflater.inflate( + R.layout.all_apps_no_items_placeholder, layout, false); + switch (mAppFilter) { + case ApplicationInfo.GAME_FLAG: + icon.setText(mContext.getString(R.string.all_apps_no_games)); + break; + case ApplicationInfo.DOWNLOADED_FLAG: + icon.setText(mContext.getString(R.string.all_apps_no_downloads)); + break; + default: break; + } + + // Center-align the message + layout.enableCenteredContent(true); + layout.removeAllViews(); + layout.addViewToCellLayout(icon, -1, 0, + new PagedViewCellLayout.LayoutParams(0, 0, 2, 1)); } } diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java index ff5ea496b3..0f7898b271 100644 --- a/src/com/android/launcher2/PagedViewIcon.java +++ b/src/com/android/launcher2/PagedViewIcon.java @@ -137,7 +137,7 @@ public class PagedViewIcon extends TextView implements Checkable { protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - if (mHolographicOutline == null) { + if (mIconCache != null && mHolographicOutline == null) { // update the clipping rect to be used in the holographic pass below getDrawingRect(mDrawableClipRect); mDrawableClipRect.bottom = getPaddingTop() + getCompoundPaddingTop();