diff options
author | cretin45 <cretin45@gmail.com> | 2015-11-13 16:51:43 -0800 |
---|---|---|
committer | cretin45 <cretin45@gmail.com> | 2015-11-23 12:10:32 -0800 |
commit | acab44fc939b4083ab7ec889b0c6d4fe0db00cca (patch) | |
tree | 6d7dd6d411404b804814ec4091e007f05dfd4ae5 /src/com/android/launcher3/allapps | |
parent | 35614fdc7d13179ba9cbc80f15eca6d63cf3229d (diff) | |
download | android_packages_apps_Trebuchet-acab44fc939b4083ab7ec889b0c6d4fe0db00cca.tar.gz android_packages_apps_Trebuchet-acab44fc939b4083ab7ec889b0c6d4fe0db00cca.tar.bz2 android_packages_apps_Trebuchet-acab44fc939b4083ab7ec889b0c6d4fe0db00cca.zip |
Reimplement the CM scrubber against the new Launcher
PS4: Implement RTL support
Change-Id: I4456d54b5924913d1b36e1cfa9a2269150f6fb3e
Diffstat (limited to 'src/com/android/launcher3/allapps')
4 files changed, 311 insertions, 41 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 88c6acada..bff7752af 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -35,6 +35,7 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import com.android.launcher3.AppInfo; import com.android.launcher3.BaseContainerView; +import com.android.launcher3.BaseRecyclerView; import com.android.launcher3.CellLayout; import com.android.launcher3.DeleteDropTarget; import com.android.launcher3.DeviceProfile; @@ -130,8 +131,14 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc LauncherTransitionable, View.OnTouchListener, View.OnLongClickListener, AllAppsSearchBarController.Callbacks { + public static final int SECTION_STRATEGY_GRID = 1; + public static final int SECTION_STRATEGY_RAGGED = 2; + + public static final int GRID_THEME_LIGHT = 1; + public static final int GRID_THEME_DARK = 2; + private static final int MIN_ROWS_IN_MERGED_SECTION_PHONE = 3; - private static final int MAX_NUM_MERGES_PHONE = 2; + private static final int MAX_NUM_MERGES_PHONE = 1; @Thunk Launcher mLauncher; @Thunk AlphabeticalAppsList mApps; @@ -148,6 +155,10 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc private View mSearchBarView; private SpannableStringBuilder mSearchQueryBuilder = null; + private int mSectionStrategy = SECTION_STRATEGY_RAGGED; + private int mGridTheme = GRID_THEME_DARK; + private int mLastGridTheme = -1; + private int mSectionNamesMargin; private int mNumAppsPerRow; private int mNumPredictedAppsPerRow; @@ -178,9 +189,12 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc Resources res = context.getResources(); mLauncher = (Launcher) context; - mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); + mSectionNamesMargin = mSectionStrategy == SECTION_STRATEGY_GRID ? + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); mApps = new AlphabeticalAppsList(context); - mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher, this); + mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher, + this, mSectionStrategy, mGridTheme); mApps.setAdapter(mAdapter); mLayoutManager = mAdapter.getLayoutManager(); mItemDecoration = mAdapter.getItemDecoration(); @@ -196,6 +210,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc */ public void setPredictedApps(List<ComponentKey> apps) { mApps.setPredictedApps(apps); + updateScrubber(); } /** @@ -203,6 +218,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc */ public void setApps(List<AppInfo> apps) { mApps.setApps(apps); + updateScrubber(); } /** @@ -210,6 +226,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc */ public void addApps(List<AppInfo> apps) { mApps.addApps(apps); + updateScrubber(); } /** @@ -217,6 +234,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc */ public void updateApps(List<AppInfo> apps) { mApps.updateApps(apps); + updateScrubber(); } /** @@ -224,6 +242,29 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc */ public void removeApps(List<AppInfo> apps) { mApps.removeApps(apps); + updateScrubber(); + } + + private void updateScrubber() { + if (userScrubber()) { + mScrubber.updateSections(); + } + } + + public void setSectionStrategy(int sectionStrategy) { + Resources res = getResources(); + mSectionStrategy = sectionStrategy; + mSectionNamesMargin = mSectionStrategy == SECTION_STRATEGY_GRID ? + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); + mAdapter.setSectionStrategy(mSectionStrategy); + mAppsRecyclerView.setSectionStrategy(mSectionStrategy); + } + + public void setGridTheme(int gridTheme) { + mGridTheme = gridTheme; + mAdapter.setGridTheme(mGridTheme); + updateBackgroundAndPaddings(true); } /** @@ -316,6 +357,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // Load the all apps recycler view mAppsRecyclerView = (AllAppsRecyclerView) findViewById(R.id.apps_list_view); mAppsRecyclerView.setApps(mApps); + mAppsRecyclerView.setSectionStrategy(mSectionStrategy); mAppsRecyclerView.setLayoutManager(mLayoutManager); mAppsRecyclerView.setAdapter(mAdapter); mAppsRecyclerView.setHasFixedSize(true); @@ -337,7 +379,8 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc int availableWidth = !mContentBounds.isEmpty() ? mContentBounds.width() : MeasureSpec.getSize(widthMeasureSpec); DeviceProfile grid = mLauncher.getDeviceProfile(); - grid.updateAppsViewNumCols(getResources(), availableWidth); + grid.updateAppsViewNumCols(getResources(), availableWidth, + mSectionStrategy); if (mNumAppsPerRow != grid.allAppsNumCols || mNumPredictedAppsPerRow != grid.allAppsNumPredictiveCols) { mNumAppsPerRow = grid.allAppsNumCols; @@ -345,7 +388,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // If there is a start margin to draw section names, determine how we are going to merge // app sections - boolean mergeSectionsFully = mSectionNamesMargin == 0 || !grid.isPhone; + boolean mergeSectionsFully = mSectionStrategy == SECTION_STRATEGY_GRID; AlphabeticalAppsList.MergeAlgorithm mergeAlgorithm = mergeSectionsFully ? new FullMergeAlgorithm() : new SimpleSectionMergeAlgorithm((int) Math.ceil(mNumAppsPerRow / 2f), @@ -369,8 +412,10 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc boolean isRtl = Utilities.isRtl(getResources()); // TODO: Use quantum_panel instead of quantum_panel_shape + int bgRes = mGridTheme == GRID_THEME_DARK ? R.drawable.quantum_panel_shape_dark : + R.drawable.quantum_panel_shape; InsetDrawable background = new InsetDrawable( - getResources().getDrawable(R.drawable.quantum_panel_shape), padding.left, 0, + getResources().getDrawable(bgRes), padding.left, 0, padding.right, 0); Rect bgPadding = new Rect(); background.getPadding(bgPadding); @@ -389,12 +434,24 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // names) int startInset = Math.max(mSectionNamesMargin, mAppsRecyclerView.getMaxScrollbarWidth()); int topBottomPadding = mRecyclerViewTopBottomPadding; + final boolean useScubber = userScrubber(); if (isRtl) { mAppsRecyclerView.setPadding(padding.left + mAppsRecyclerView.getMaxScrollbarWidth(), - topBottomPadding, padding.right + startInset, topBottomPadding); + topBottomPadding, padding.right + startInset, useScubber ? + mScrubberHeight + topBottomPadding : topBottomPadding); + if (useScubber) { + mScrubberContainerView + .setPadding(padding.left + mAppsRecyclerView.getMaxScrollbarWidth(), + 0, padding.right, 0); + } } else { mAppsRecyclerView.setPadding(padding.left + startInset, topBottomPadding, - padding.right + mAppsRecyclerView.getMaxScrollbarWidth(), topBottomPadding); + padding.right + mAppsRecyclerView.getMaxScrollbarWidth(), + useScubber ? mScrubberHeight + topBottomPadding : topBottomPadding); + if (useScubber) { + mScrubberContainerView.setPadding(padding.left, 0, + padding.right + mAppsRecyclerView.getMaxScrollbarWidth(), 0); + } } // Inset the search bar to fit its bounds above the container @@ -556,7 +613,9 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { if (toWorkspace) { // Reset the search bar and base recycler view after transitioning home - mSearchBarController.reset(); + if (hasSearchBar()) { + mSearchBarController.reset(); + } mAppsRecyclerView.reset(); } } @@ -614,6 +673,12 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc public void onSearchResult(String query, ArrayList<ComponentKey> apps) { if (apps != null) { mApps.setOrderedFilter(apps); + if (mGridTheme != GRID_THEME_LIGHT) { + mLastGridTheme = mGridTheme; + mGridTheme = GRID_THEME_LIGHT; + updateBackgroundAndPaddings(true); + mAdapter.setGridTheme(mGridTheme); + } mAdapter.setLastSearchQuery(query); mAppsRecyclerView.onSearchResultsChanged(); } @@ -623,10 +688,20 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc public void clearSearchResult() { mApps.setOrderedFilter(null); mAppsRecyclerView.onSearchResultsChanged(); - + if (mLastGridTheme != -1 && mLastGridTheme != GRID_THEME_LIGHT) { + mGridTheme = mLastGridTheme; + updateBackgroundAndPaddings(true); + mAdapter.setGridTheme(mGridTheme); + mLastGridTheme = -1; + } // Clear the search query mSearchQueryBuilder.clear(); mSearchQueryBuilder.clearSpans(); Selection.setSelection(mSearchQueryBuilder, 0); } + + @Override + protected BaseRecyclerView getRecyclerView() { + return mAppsRecyclerView; + } } diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index 1f95133d4..a48390732 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -24,7 +24,6 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; import android.graphics.Rect; -import android.graphics.drawable.Drawable; import android.support.v4.view.accessibility.AccessibilityRecordCompat; import android.support.v4.view.accessibility.AccessibilityEventCompat; import android.net.Uri; @@ -69,6 +68,10 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. // The message to continue to a market search when there are no filtered results public static final int SEARCH_MARKET_VIEW_TYPE = 5; + private boolean mIconsDimmed = false; + + private int mGridTheme; + /** * ViewHolder for each icon. */ @@ -142,7 +145,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. public class GridItemDecoration extends RecyclerView.ItemDecoration { private static final boolean DEBUG_SECTION_MARGIN = false; - private static final boolean FADE_OUT_SECTIONS = false; + private static final boolean FADE_OUT_SECTIONS = true; private HashMap<String, PointF> mCachedSectionBounds = new HashMap<>(); private Rect mTmpBounds = new Rect(); @@ -349,12 +352,16 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. // Section drawing @Thunk int mSectionNamesMargin; @Thunk int mSectionHeaderOffset; + @Thunk int mSectionStrategy; @Thunk Paint mSectionTextPaint; @Thunk Paint mPredictedAppsDividerPaint; + private int mIconSize; + private int mAllAppsTextColor; + public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener, View.OnClickListener iconClickListener, - View.OnLongClickListener iconLongClickListener) { + View.OnLongClickListener iconLongClickListener, int sectionStrategy, int gridTheme) { Resources res = launcher.getResources(); mLauncher = launcher; mApps = apps; @@ -367,13 +374,31 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. mTouchListener = touchListener; mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; - mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); + mSectionStrategy = sectionStrategy; + mGridTheme = gridTheme; + mSectionNamesMargin = mSectionStrategy == + AllAppsContainerView.SECTION_STRATEGY_GRID ? + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); + + mIconSize = mSectionStrategy == + AllAppsContainerView.SECTION_STRATEGY_GRID ? + res.getDimensionPixelSize(R.dimen.all_apps_icon_size_grid) : + res.getDimensionPixelSize(R.dimen.all_apps_icon_size_ragged); + + mAllAppsTextColor = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? + res.getColor(R.color.quantum_panel_text_color_dark) : + res.getColor(R.color.quantum_panel_text_color); + mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset); mSectionTextPaint = new Paint(); mSectionTextPaint.setTextSize(res.getDimensionPixelSize( R.dimen.all_apps_grid_section_text_size)); - mSectionTextPaint.setColor(res.getColor(R.color.all_apps_grid_section_text_color)); + int sectionTextColorId = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? + R.color.all_apps_grid_section_text_color_dark : + R.color.all_apps_grid_section_text_color; + mSectionTextPaint.setColor(res.getColor(sectionTextColorId)); mSectionTextPaint.setAntiAlias(true); mPredictedAppsDividerPaint = new Paint(); @@ -408,6 +433,19 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. mIsRtl = rtl; } + public void setSectionStrategy(int sectionStrategy) { + Resources res = mLauncher.getResources(); + mSectionStrategy = sectionStrategy; + mSectionNamesMargin = mSectionStrategy == + AllAppsContainerView.SECTION_STRATEGY_GRID ? + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); + mIconSize = mSectionStrategy == + AllAppsContainerView.SECTION_STRATEGY_GRID ? + res.getDimensionPixelSize(R.dimen.all_apps_icon_size_grid) : + res.getDimensionPixelSize(R.dimen.all_apps_icon_size_ragged); + } + /** * Sets the last search query that was made, used to show when there are no results and to also * seed the intent for searching the market. @@ -501,12 +539,17 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. case ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; + icon.setIconSize(mIconSize); + icon.setTextColor(mAllAppsTextColor); icon.applyFromApplicationInfo(info); + icon.setFastScrollDimmed(mIconsDimmed, !mIconsDimmed); break; } case PREDICTION_ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; + icon.setIconSize(mIconSize); + icon.setTextColor(mAllAppsTextColor); icon.applyFromApplicationInfo(info); break; } @@ -542,6 +585,25 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. return item.viewType; } + public void setIconsDimmed(boolean iconsDimmed) { + if (mIconsDimmed != iconsDimmed) { + mIconsDimmed = iconsDimmed; + notifyDataSetChanged(); + } + } + + public void setGridTheme(int gridTheme) { + mGridTheme = gridTheme; + int sectionTextColorId = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? + R.color.all_apps_grid_section_text_color_dark : + R.color.all_apps_grid_section_text_color; + mSectionTextPaint.setColor(mLauncher.getResources().getColor(sectionTextColorId)); + Resources res = mLauncher.getResources(); + mAllAppsTextColor = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? + res.getColor(R.color.all_apps_grid_section_text_color_dark) : + res.getColor(R.color.all_apps_grid_section_text_color); + } + /** * Creates a new market search intent. */ diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java index 2f66e2cad..6c853a037 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java @@ -15,7 +15,6 @@ */ package com.android.launcher3.allapps; -import android.animation.ObjectAnimator; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; @@ -34,6 +33,7 @@ import com.android.launcher3.Stats; import com.android.launcher3.Utilities; import com.android.launcher3.util.Thunk; +import java.util.ArrayList; import java.util.List; /** @@ -50,9 +50,15 @@ public class AllAppsRecyclerView extends BaseRecyclerView private AlphabeticalAppsList mApps; private int mNumAppsPerRow; + private int mSectionStrategy = AllAppsContainerView.SECTION_STRATEGY_RAGGED; + + private boolean mFocusSection = false; @Thunk BaseRecyclerViewFastScrollBar.FastScrollFocusableView mLastFastScrollFocusedView; + @Thunk ArrayList<BaseRecyclerViewFastScrollBar.FastScrollFocusableView> + mLastFastScrollFocusedViews = new ArrayList(); @Thunk int mPrevFastScrollFocusedPosition; + @Thunk AlphabeticalAppsList.SectionInfo mPrevFastScrollFocusedSection; @Thunk int mFastScrollFrameIndex; @Thunk final int[] mFastScrollFrames = new int[10]; @@ -81,7 +87,9 @@ public class AllAppsRecyclerView extends BaseRecyclerView super(context, attrs, defStyleAttr); Resources res = getResources(); - mScrollbar.setDetachThumbOnFastScroll(); + if (mUseScrollbar) { + mScrollbar.setDetachThumbOnFastScroll(); + } mEmptySearchBackgroundTopOffset = res.getDimensionPixelSize( R.dimen.all_apps_empty_search_bg_top_offset); } @@ -109,13 +117,20 @@ public class AllAppsRecyclerView extends BaseRecyclerView pool.setMaxRecycledViews(AllAppsGridAdapter.SECTION_BREAK_VIEW_TYPE, approxRows); } + public void setSectionStrategy(int sectionStrategy) { + mSectionStrategy = sectionStrategy; + mFocusSection = mSectionStrategy == AllAppsContainerView.SECTION_STRATEGY_RAGGED; + } + /** * Scrolls this recycler view to the top. */ public void scrollToTop() { - // Ensure we reattach the scrollbar if it was previously detached while fast-scrolling - if (mScrollbar.isThumbDetached()) { - mScrollbar.reattachThumbToScroll(); + if (mUseScrollbar) { + // Ensure we reattach the scrollbar if it was previously detached while fast-scrolling + if (mScrollbar.isThumbDetached()) { + mScrollbar.reattachThumbToScroll(); + } } scrollToPosition(0); } @@ -235,10 +250,18 @@ public class AllAppsRecyclerView extends BaseRecyclerView } if (mPrevFastScrollFocusedPosition != lastInfo.fastScrollToItem.position) { + if (mFocusSection) { + setSectionFastScrollDimmed(mPrevFastScrollFocusedPosition, true, true); + } else if (mLastFastScrollFocusedView != null){ + mLastFastScrollFocusedView.setFastScrollDimmed(true, true); + } mPrevFastScrollFocusedPosition = lastInfo.fastScrollToItem.position; - - // Reset the last focused view - if (mLastFastScrollFocusedView != null) { + mPrevFastScrollFocusedSection = + getSectionInfoForPosition(lastInfo.fastScrollToItem.position); + // Reset the last focused section + if (mFocusSection) { + clearSectionFocusedItems(); + } else if (mLastFastScrollFocusedView != null) { mLastFastScrollFocusedView.setFastScrollFocused(false, true); mLastFastScrollFocusedView = null; } @@ -246,12 +269,17 @@ public class AllAppsRecyclerView extends BaseRecyclerView if (mFastScrollMode == FAST_SCROLL_MODE_JUMP_TO_FIRST_ICON) { smoothSnapToPosition(mPrevFastScrollFocusedPosition, mScrollPosState); } else if (mFastScrollMode == FAST_SCROLL_MODE_FREE_SCROLL) { - final ViewHolder vh = findViewHolderForPosition(mPrevFastScrollFocusedPosition); - if (vh != null && - vh.itemView instanceof BaseRecyclerViewFastScrollBar.FastScrollFocusableView) { - mLastFastScrollFocusedView = - (BaseRecyclerViewFastScrollBar.FastScrollFocusableView) vh.itemView; - mLastFastScrollFocusedView.setFastScrollFocused(true, true); + if (mFocusSection) { + setSectionFastScrollFocused(mPrevFastScrollFocusedPosition); + } else { + final ViewHolder vh = findViewHolderForPosition(mPrevFastScrollFocusedPosition); + if (vh != null && + vh.itemView instanceof + BaseRecyclerViewFastScrollBar.FastScrollFocusableView) { + mLastFastScrollFocusedView = + (BaseRecyclerViewFastScrollBar.FastScrollFocusableView) vh.itemView; + mLastFastScrollFocusedView.setFastScrollFocused(true, true); + } } } else { throw new RuntimeException("Unexpected fast scroll mode"); @@ -264,11 +292,14 @@ public class AllAppsRecyclerView extends BaseRecyclerView public void onFastScrollCompleted() { super.onFastScrollCompleted(); // Reset and clean up the last focused view - if (mLastFastScrollFocusedView != null) { + if (mFocusSection) { + clearSectionFocusedItems(); + } else if (mLastFastScrollFocusedView != null) { mLastFastScrollFocusedView.setFastScrollFocused(false, true); mLastFastScrollFocusedView = null; } mPrevFastScrollFocusedPosition = -1; + mPrevFastScrollFocusedSection = null; } /** @@ -276,6 +307,9 @@ public class AllAppsRecyclerView extends BaseRecyclerView */ @Override public void onUpdateScrollbar(int dy) { + if (!mUseScrollbar) { + return; + } List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems(); // Skip early if there are no items or we haven't been measured @@ -294,7 +328,8 @@ public class AllAppsRecyclerView extends BaseRecyclerView // Only show the scrollbar if there is height to be scrolled int availableScrollBarHeight = getAvailableScrollBarHeight(); - int availableScrollHeight = getAvailableScrollHeight(mApps.getNumAppRows(), mScrollPosState.rowHeight); + int availableScrollHeight = getAvailableScrollHeight(mApps.getNumAppRows(), + mScrollPosState.rowHeight); if (availableScrollHeight <= 0) { mScrollbar.setThumbOffset(-1, -1); return; @@ -354,6 +389,97 @@ public class AllAppsRecyclerView extends BaseRecyclerView } } + @Override + public String scrollToSection(String sectionName) { + List<AlphabeticalAppsList.FastScrollSectionInfo> scrollSectionInfos = + mApps.getFastScrollerSections(); + if (scrollSectionInfos != null) { + for (int i = 0; i < scrollSectionInfos.size(); i++) { + AlphabeticalAppsList.FastScrollSectionInfo info = scrollSectionInfos.get(i); + if (info.sectionName.equals(sectionName)) { + scrollToPositionAtProgress(info.touchFraction); + return info.sectionName; + } + } + } + return null; + } + + @Override + public String[] getSectionNames() { + List<AlphabeticalAppsList.FastScrollSectionInfo> scrollSectionInfos = + mApps.getFastScrollerSections(); + if (scrollSectionInfos != null) { + String[] sectionNames = new String[scrollSectionInfos.size()]; + for (int i = 0; i < scrollSectionInfos.size(); i++) { + AlphabeticalAppsList.FastScrollSectionInfo info = scrollSectionInfos.get(i); + sectionNames[i] = info.sectionName; + } + + return sectionNames; + } + return new String[0]; + } + + private AlphabeticalAppsList.SectionInfo getSectionInfoForPosition(int position) { + List<AlphabeticalAppsList.SectionInfo> sections = + mApps.getSections(); + for (AlphabeticalAppsList.SectionInfo section : sections) { + if (section.firstAppItem.position == position) { + return section; + } + } + return null; + } + + private void setSectionFastScrollFocused(int position) { + if (mPrevFastScrollFocusedSection != null) { + for (int i = 0; i < mPrevFastScrollFocusedSection.numApps; i++) { + int sectionPosition = position+i; + final ViewHolder vh = findViewHolderForAdapterPosition(sectionPosition); + if (vh != null && + vh.itemView instanceof + BaseRecyclerViewFastScrollBar.FastScrollFocusableView) { + final BaseRecyclerViewFastScrollBar.FastScrollFocusableView view = + (BaseRecyclerViewFastScrollBar.FastScrollFocusableView) vh.itemView; + view.setFastScrollFocused(true, true); + mLastFastScrollFocusedViews.add(view); + } + } + } + } + + private void setSectionFastScrollDimmed(int position, boolean dimmed, boolean animate) { + if (mPrevFastScrollFocusedSection != null) { + for (int i = 0; i < mPrevFastScrollFocusedSection.numApps; i++) { + int sectionPosition = position+i; + final ViewHolder vh = findViewHolderForAdapterPosition(sectionPosition); + if (vh != null && + vh.itemView instanceof + BaseRecyclerViewFastScrollBar.FastScrollFocusableView) { + final BaseRecyclerViewFastScrollBar.FastScrollFocusableView view = + (BaseRecyclerViewFastScrollBar.FastScrollFocusableView) vh.itemView; + view.setFastScrollDimmed(dimmed, animate); + } + } + } + } + + private void clearSectionFocusedItems() { + final int N = mLastFastScrollFocusedViews.size(); + for (int i = 0; i < N; i++) { + BaseRecyclerViewFastScrollBar.FastScrollFocusableView view = + mLastFastScrollFocusedViews.get(i); + view.setFastScrollFocused(false, true); + } + mLastFastScrollFocusedViews.clear(); + } + + @Override + public void setFastScrollDragging(boolean dragging) { + ((AllAppsGridAdapter) getAdapter()).setIconsDimmed(dragging); + } + /** * This runnable runs a single frame of the smooth scroll animation and posts the next frame * if necessary. @@ -362,18 +488,27 @@ public class AllAppsRecyclerView extends BaseRecyclerView @Override public void run() { if (mFastScrollFrameIndex < mFastScrollFrames.length) { + if (mFocusSection) { + setSectionFastScrollDimmed(mPrevFastScrollFocusedPosition, false, true); + } scrollBy(0, mFastScrollFrames[mFastScrollFrameIndex]); mFastScrollFrameIndex++; postOnAnimation(mSmoothSnapNextFrameRunnable); } else { - // Animation completed, set the fast scroll state on the target view - final ViewHolder vh = findViewHolderForPosition(mPrevFastScrollFocusedPosition); - if (vh != null && - vh.itemView instanceof BaseRecyclerViewFastScrollBar.FastScrollFocusableView && - mLastFastScrollFocusedView != vh.itemView) { - mLastFastScrollFocusedView = - (BaseRecyclerViewFastScrollBar.FastScrollFocusableView) vh.itemView; - mLastFastScrollFocusedView.setFastScrollFocused(true, true); + if (mFocusSection) { + setSectionFastScrollFocused(mPrevFastScrollFocusedPosition); + } else { + // Animation completed, set the fast scroll state on the target view + final ViewHolder vh = findViewHolderForPosition(mPrevFastScrollFocusedPosition); + if (vh != null && + vh.itemView instanceof + BaseRecyclerViewFastScrollBar.FastScrollFocusableView && + mLastFastScrollFocusedView != vh.itemView) { + mLastFastScrollFocusedView = + (BaseRecyclerViewFastScrollBar.FastScrollFocusableView) vh.itemView; + mLastFastScrollFocusedView.setFastScrollFocused(true, true); + mLastFastScrollFocusedView.setFastScrollDimmed(false, true); + } } } } diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerViewContainerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerViewContainerView.java index 14e2a1863..d5ebdab07 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerViewContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerViewContainerView.java @@ -17,9 +17,7 @@ package com.android.launcher3.allapps; import android.content.Context; import android.graphics.Bitmap; -import android.graphics.Canvas; import android.util.AttributeSet; -import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import com.android.launcher3.BubbleTextView; |