From bedf9232eb67a420f0372d3ca135ca13194e603b Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 10 Jul 2015 12:38:30 -0700 Subject: Adding market search. Change-Id: Id41615653cd4fa76213add4595418ad0cc6e7852 --- res/drawable-hdpi/ic_arrow_back_grey.png | Bin 190 -> 152 bytes res/drawable-hdpi/ic_search_grey.png | Bin 743 -> 419 bytes res/drawable-mdpi/ic_arrow_back_grey.png | Bin 151 -> 117 bytes res/drawable-mdpi/ic_search_grey.png | Bin 497 -> 263 bytes res/drawable-v21/all_apps_search_market_bg.xml | 19 +++ res/drawable-xhdpi/ic_arrow_back_grey.png | Bin 234 -> 151 bytes res/drawable-xhdpi/ic_search_grey.png | Bin 972 -> 497 bytes res/drawable-xxhdpi/ic_arrow_back_grey.png | Bin 308 -> 190 bytes res/drawable-xxhdpi/ic_search_grey.png | Bin 1473 -> 743 bytes res/drawable-xxxhdpi/ic_arrow_back_grey.png | Bin 359 -> 234 bytes res/drawable-xxxhdpi/ic_search_grey.png | Bin 1996 -> 972 bytes res/drawable/all_apps_search_market_bg.xml | 20 ++++ res/drawable/horizontal_line.xml | 21 ++++ res/layout/all_apps_empty_search.xml | 15 ++- res/layout/all_apps_search_bar.xml | 13 +-- res/layout/all_apps_search_market.xml | 29 +++++ res/layout/all_apps_search_market_divider.xml | 27 +++++ res/values/colors.xml | 1 + res/values/strings.xml | 7 +- src/com/android/launcher3/Launcher.java | 15 ++- src/com/android/launcher3/LauncherCallbacks.java | 1 + .../launcher3/allapps/AllAppsContainerView.java | 31 ++--- .../launcher3/allapps/AllAppsGridAdapter.java | 130 +++++++++++++++------ .../launcher3/allapps/AllAppsRecyclerView.java | 2 + .../launcher3/allapps/AlphabeticalAppsList.java | 59 ++++++++-- .../allapps/DefaultAppSearchController.java | 18 +-- .../launcher3/testing/LauncherExtension.java | 5 + 27 files changed, 326 insertions(+), 87 deletions(-) create mode 100644 res/drawable-v21/all_apps_search_market_bg.xml create mode 100644 res/drawable/all_apps_search_market_bg.xml create mode 100644 res/drawable/horizontal_line.xml create mode 100644 res/layout/all_apps_search_market.xml create mode 100644 res/layout/all_apps_search_market_divider.xml diff --git a/res/drawable-hdpi/ic_arrow_back_grey.png b/res/drawable-hdpi/ic_arrow_back_grey.png index ccd3900dd..c7c00886f 100755 Binary files a/res/drawable-hdpi/ic_arrow_back_grey.png and b/res/drawable-hdpi/ic_arrow_back_grey.png differ diff --git a/res/drawable-hdpi/ic_search_grey.png b/res/drawable-hdpi/ic_search_grey.png index f4c5e27d2..bd20ba062 100755 Binary files a/res/drawable-hdpi/ic_search_grey.png and b/res/drawable-hdpi/ic_search_grey.png differ diff --git a/res/drawable-mdpi/ic_arrow_back_grey.png b/res/drawable-mdpi/ic_arrow_back_grey.png index 11996efe3..5892c77d5 100755 Binary files a/res/drawable-mdpi/ic_arrow_back_grey.png and b/res/drawable-mdpi/ic_arrow_back_grey.png differ diff --git a/res/drawable-mdpi/ic_search_grey.png b/res/drawable-mdpi/ic_search_grey.png index e83891c11..c386dbb38 100755 Binary files a/res/drawable-mdpi/ic_search_grey.png and b/res/drawable-mdpi/ic_search_grey.png differ diff --git a/res/drawable-v21/all_apps_search_market_bg.xml b/res/drawable-v21/all_apps_search_market_bg.xml new file mode 100644 index 000000000..7bd2f8816 --- /dev/null +++ b/res/drawable-v21/all_apps_search_market_bg.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/res/drawable-xhdpi/ic_arrow_back_grey.png b/res/drawable-xhdpi/ic_arrow_back_grey.png index 79b9b486c..11996efe3 100755 Binary files a/res/drawable-xhdpi/ic_arrow_back_grey.png and b/res/drawable-xhdpi/ic_arrow_back_grey.png differ diff --git a/res/drawable-xhdpi/ic_search_grey.png b/res/drawable-xhdpi/ic_search_grey.png index bd5fdf444..e83891c11 100755 Binary files a/res/drawable-xhdpi/ic_search_grey.png and b/res/drawable-xhdpi/ic_search_grey.png differ diff --git a/res/drawable-xxhdpi/ic_arrow_back_grey.png b/res/drawable-xxhdpi/ic_arrow_back_grey.png index 8e42e091d..ccd3900dd 100755 Binary files a/res/drawable-xxhdpi/ic_arrow_back_grey.png and b/res/drawable-xxhdpi/ic_arrow_back_grey.png differ diff --git a/res/drawable-xxhdpi/ic_search_grey.png b/res/drawable-xxhdpi/ic_search_grey.png index 1d5c91361..f4c5e27d2 100755 Binary files a/res/drawable-xxhdpi/ic_search_grey.png and b/res/drawable-xxhdpi/ic_search_grey.png differ diff --git a/res/drawable-xxxhdpi/ic_arrow_back_grey.png b/res/drawable-xxxhdpi/ic_arrow_back_grey.png index 854a9bd1a..79b9b486c 100755 Binary files a/res/drawable-xxxhdpi/ic_arrow_back_grey.png and b/res/drawable-xxxhdpi/ic_arrow_back_grey.png differ diff --git a/res/drawable-xxxhdpi/ic_search_grey.png b/res/drawable-xxxhdpi/ic_search_grey.png index 28519fda6..bd5fdf444 100755 Binary files a/res/drawable-xxxhdpi/ic_search_grey.png and b/res/drawable-xxxhdpi/ic_search_grey.png differ diff --git a/res/drawable/all_apps_search_market_bg.xml b/res/drawable/all_apps_search_market_bg.xml new file mode 100644 index 000000000..5278e00a6 --- /dev/null +++ b/res/drawable/all_apps_search_market_bg.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/res/drawable/horizontal_line.xml b/res/drawable/horizontal_line.xml new file mode 100644 index 000000000..3f3f17e35 --- /dev/null +++ b/res/drawable/horizontal_line.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/res/layout/all_apps_empty_search.xml b/res/layout/all_apps_empty_search.xml index f60c4a09a..b9b493eab 100644 --- a/res/layout/all_apps_empty_search.xml +++ b/res/layout/all_apps_empty_search.xml @@ -18,11 +18,14 @@ android:id="@+id/empty_text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:gravity="center" - android:paddingTop="24dp" - android:paddingBottom="24dp" - android:paddingRight="@dimen/all_apps_grid_view_start_margin" - android:textSize="16sp" - android:textColor="#4c4c4c" + android:gravity="start" + android:paddingTop="20dp" + android:paddingBottom="8dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:fontFamily="sans-serif-medium" + android:textSize="14sp" + android:textColor="#212121" + android:alpha="0.56" android:focusable="false" /> diff --git a/res/layout/all_apps_search_bar.xml b/res/layout/all_apps_search_bar.xml index cf30eac36..4947203df 100644 --- a/res/layout/all_apps_search_bar.xml +++ b/res/layout/all_apps_search_bar.xml @@ -32,11 +32,10 @@ android:id="@+id/dismiss_search_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="4dp" - android:layout_marginStart="4dp" + android:layout_gravity="center_vertical" + android:layout_marginLeft="16dp" + android:layout_marginStart="16dp" android:contentDescription="@string/all_apps_button_label" - android:paddingBottom="13dp" - android:paddingTop="13dp" android:src="@drawable/ic_arrow_back_grey" /> \ No newline at end of file diff --git a/res/layout/all_apps_search_market.xml b/res/layout/all_apps_search_market.xml new file mode 100644 index 000000000..1282069c8 --- /dev/null +++ b/res/layout/all_apps_search_market.xml @@ -0,0 +1,29 @@ + + + diff --git a/res/layout/all_apps_search_market_divider.xml b/res/layout/all_apps_search_market_divider.xml new file mode 100644 index 000000000..39097818f --- /dev/null +++ b/res/layout/all_apps_search_market_divider.xml @@ -0,0 +1,27 @@ + + + \ No newline at end of file diff --git a/res/values/colors.xml b/res/values/colors.xml index 51e4d40a5..0add48cd8 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -44,6 +44,7 @@ #009688 + #DDDDDD #42FFFFFF diff --git a/res/values/strings.xml b/res/values/strings.xml index 88f149bd0..fefadef28 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -24,10 +24,10 @@ content://com.android.launcher2.settings/favorites?notify=true - + com.android.launcher3.permission.RECEIVE_LAUNCH_BROADCASTS - + com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST @@ -61,6 +61,9 @@ Loading Apps… No Apps found matching \"%1$s\" + + Go to %1$s diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 9d04770af..2d338e3d4 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2132,6 +2132,15 @@ public class Launcher extends Activity } } + public void startSearchFromAllApps(View v, Intent searchIntent, String searchQuery) { + if (mLauncherCallbacks != null && mLauncherCallbacks.startSearchFromAllApps(searchQuery)) { + return; + } + + // If not handled, then just start the provided search intent + startActivitySafely(v, searchIntent, null); + } + public boolean isOnCustomContent() { return mWorkspace.isOnOrMovingToCustomContent(); } @@ -2533,6 +2542,10 @@ public class Launcher extends Activity if (!isAppsViewVisible()) { showAppsView(true /* animated */, false /* resetListToTop */, true /* updatePredictedApps */, false /* focusSearchBar */); + + if (mLauncherCallbacks != null) { + mLauncherCallbacks.onClickAllAppsButton(v); + } } } @@ -2924,7 +2937,7 @@ public class Launcher extends Activity return false; } - @Thunk boolean startActivitySafely(View v, Intent intent, Object tag) { + public boolean startActivitySafely(View v, Intent intent, Object tag) { boolean success = false; if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java index 6618cca78..e34bd57fd 100644 --- a/src/com/android/launcher3/LauncherCallbacks.java +++ b/src/com/android/launcher3/LauncherCallbacks.java @@ -77,6 +77,7 @@ public interface LauncherCallbacks { public boolean providesSearch(); public boolean startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds); + public boolean startSearchFromAllApps(String query); @Deprecated public void startVoice(); public boolean hasCustomContentToLeft(); diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 010b2cb48..e129dc6d3 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -16,34 +16,26 @@ package com.android.launcher3.allapps; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.Context; +import android.content.Intent; import android.content.res.Resources; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.InsetDrawable; -import android.os.Build; -import android.os.Bundle; import android.support.v7.widget.RecyclerView; import android.text.Selection; import android.text.SpannableStringBuilder; import android.text.method.TextKeyListener; import android.util.AttributeSet; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.widget.FrameLayout; import android.widget.LinearLayout; - import com.android.launcher3.AppInfo; import com.android.launcher3.BaseContainerView; -import com.android.launcher3.BubbleTextView; import com.android.launcher3.CellLayout; -import com.android.launcher3.CheckLongPressHelper; import com.android.launcher3.DeleteDropTarget; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; @@ -53,7 +45,6 @@ import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherTransitionable; import com.android.launcher3.R; -import com.android.launcher3.Stats; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; import com.android.launcher3.util.ComponentKey; @@ -155,6 +146,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc @Thunk AllAppsSearchBarController mSearchBarController; private ViewGroup mSearchBarContainerView; private View mSearchBarView; + private SpannableStringBuilder mSearchQueryBuilder = null; private int mSectionNamesMargin; private int mNumAppsPerRow; @@ -165,7 +157,13 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // This coordinate is relative to its parent private final Point mIconLastTouchPos = new Point(); - private SpannableStringBuilder mSearchQueryBuilder = null; + private View.OnClickListener mSearchClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent searchIntent = (Intent) v.getTag(); + mLauncher.startActivitySafely(v, searchIntent, null); + } + }; public AllAppsContainerView(Context context) { this(context, null); @@ -182,8 +180,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc mLauncher = (Launcher) context; mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); mApps = new AlphabeticalAppsList(context); - mAdapter = new AllAppsGridAdapter(context, mApps, this, mLauncher, this); - mAdapter.setEmptySearchText(res.getString(R.string.all_apps_loading_message)); + mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher, this); mApps.setAdapter(mAdapter); mLayoutManager = mAdapter.getLayoutManager(); mItemDecoration = mAdapter.getItemDecoration(); @@ -615,13 +612,9 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc @Override public void onSearchResult(String query, ArrayList apps) { if (apps != null) { - if (apps.isEmpty()) { - String formatStr = getResources().getString(R.string.all_apps_no_search_results); - mAdapter.setEmptySearchText(String.format(formatStr, query)); - } else { - mAppsRecyclerView.scrollToTop(); - } mApps.setOrderedFilter(apps); + mAdapter.setLastSearchQuery(query); + mAppsRecyclerView.scrollToTop(); } } diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index e96567c41..4acfc5ca6 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -16,14 +16,17 @@ package com.android.launcher3.allapps; import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; import android.graphics.Rect; -import android.os.Handler; import android.support.v4.view.accessibility.AccessibilityRecordCompat; import android.support.v4.view.accessibility.AccessibilityEventCompat; +import android.net.Uri; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -34,6 +37,7 @@ import android.view.accessibility.AccessibilityEvent; import android.widget.TextView; import com.android.launcher3.AppInfo; import com.android.launcher3.BubbleTextView; +import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.util.Thunk; @@ -58,6 +62,10 @@ class AllAppsGridAdapter extends RecyclerView.Adapter 1) { return false; } - // If there is exactly one icon, then quick-launch it + // Otherwise, find the first icon, or fallback to the search-market-view and launch it List items = mApps.getAdapterItems(); for (int i = 0; i < items.size(); i++) { AlphabeticalAppsList.AdapterItem item = items.get(i); - if (item.viewType == AllAppsGridAdapter.ICON_VIEW_TYPE) { - mAppsRecyclerView.getChildAt(i).performClick(); - mInputMethodManager.hideSoftInputFromWindow( - mContainerView.getWindowToken(), 0); - return true; + switch (item.viewType) { + case AllAppsGridAdapter.ICON_VIEW_TYPE: + case AllAppsGridAdapter.SEARCH_MARKET_VIEW_TYPE: + mAppsRecyclerView.getChildAt(i).performClick(); + mInputMethodManager.hideSoftInputFromWindow( + mContainerView.getWindowToken(), 0); + return true; } } return false; diff --git a/src/com/android/launcher3/testing/LauncherExtension.java b/src/com/android/launcher3/testing/LauncherExtension.java index 34492e4ca..8702877bf 100644 --- a/src/com/android/launcher3/testing/LauncherExtension.java +++ b/src/com/android/launcher3/testing/LauncherExtension.java @@ -201,6 +201,11 @@ public class LauncherExtension extends Launcher { return false; } + @Override + public boolean startSearchFromAllApps(String query) { + return false; + } + @Override public void startVoice() { } -- cgit v1.2.3