Loading res/layout/all_apps_tabs.xml +6 −4 Original line number Diff line number Diff line Loading @@ -14,21 +14,23 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <com.android.launcher3.allapps.InterceptingViewPager <com.android.launcher3.allapps.AllAppsPagedView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:launcher="http://schemas.android.com/apk/res-auto" android:id="@+id/all_apps_tabs_view_pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/search_container_all_apps" android:layout_gravity="center_horizontal|top" android:layout_marginTop="@dimen/all_apps_header_tab_height" android:clipChildren="false" android:clipChildren="true" android:clipToPadding="false" android:descendantFocusability="afterDescendants" android:paddingTop="@dimen/all_apps_header_top_padding"> android:paddingTop="@dimen/all_apps_header_top_padding" launcher:pageIndicator="@+id/tabs" > <include layout="@layout/all_apps_rv_layout" /> <include layout="@layout/all_apps_rv_layout" /> </com.android.launcher3.allapps.InterceptingViewPager> No newline at end of file </com.android.launcher3.allapps.AllAppsPagedView> No newline at end of file src/com/android/launcher3/PagedView.java +14 −54 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ import java.util.ArrayList; * An abstraction of the original Workspace which supports browsing through a * sequential list of "pages" */ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarchyChangeListener { public abstract class PagedView<T extends View & PageIndicator> extends ViewGroup { private static final String TAG = "PagedView"; private static final boolean DEBUG = false; protected static final int INVALID_PAGE = -1; Loading Loading @@ -154,7 +154,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // Page Indicator @Thunk int mPageIndicatorViewId; protected PageIndicator mPageIndicator; protected T mPageIndicator; // Reordering // We use the min scale to determine how much to expand the actually PagedView measured Loading Loading @@ -224,7 +224,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * density); mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * density); mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * density); setOnHierarchyChangeListener(this); setWillNotDraw(false); } Loading @@ -235,9 +234,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc public void initParentViews(View parent) { if (mPageIndicatorViewId > -1) { mPageIndicator = (PageIndicator) parent.findViewById(mPageIndicatorViewId); mPageIndicator = parent.findViewById(mPageIndicatorViewId); mPageIndicator.setMarkersCount(getChildCount()); mPageIndicator.setContentDescription(getPageIndicatorDescription()); mPageIndicator.setPageDescription(getPageIndicatorDescription()); } } Loading Loading @@ -282,7 +281,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } public PageIndicator getPageIndicator() { public T getPageIndicator() { return mPageIndicator; } Loading Loading @@ -384,7 +383,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc private void updatePageIndicator() { // Update the page indicator (when we aren't reordering) if (mPageIndicator != null) { mPageIndicator.setContentDescription(getPageIndicatorDescription()); mPageIndicator.setPageDescription(getPageIndicatorDescription()); if (!isReordering(false)) { mPageIndicator.setActiveMarker(getNextPage()); } Loading Loading @@ -748,63 +747,24 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc requestLayout(); } @Override public void onChildViewAdded(View parent, View child) { // Update the page indicator, we don't update the page indicator as we // add/remove pages if (mPageIndicator != null && !isReordering(false)) { mPageIndicator.addMarker(); private void dispatchPageCountChanged() { if (mPageIndicator != null) { mPageIndicator.setMarkersCount(getChildCount()); } // This ensures that when children are added, they get the correct transforms / alphas // in accordance with any scroll effects. invalidate(); } @Override public void onChildViewRemoved(View parent, View child) { mCurrentPage = validateNewPage(mCurrentPage); invalidate(); } private void removeMarkerForView() { // Update the page indicator, we don't update the page indicator as we // add/remove pages if (mPageIndicator != null && !isReordering(false)) { mPageIndicator.removeMarker(); } public void onViewAdded(View child) { dispatchPageCountChanged(); } @Override public void removeView(View v) { // XXX: We should find a better way to hook into this before the view // gets removed form its parent... removeMarkerForView(); super.removeView(v); } @Override public void removeViewInLayout(View v) { // XXX: We should find a better way to hook into this before the view // gets removed form its parent... removeMarkerForView(); super.removeViewInLayout(v); } @Override public void removeViewAt(int index) { // XXX: We should find a better way to hook into this before the view // gets removed form its parent... removeMarkerForView(); super.removeViewAt(index); } @Override public void removeAllViewsInLayout() { // Update the page indicator, we don't update the page indicator as we // add/remove pages if (mPageIndicator != null) { mPageIndicator.setMarkersCount(0); } super.removeAllViewsInLayout(); public void onViewRemoved(View child) { mCurrentPage = validateNewPage(mCurrentPage); dispatchPageCountChanged(); } protected int getChildOffset(int index) { Loading src/com/android/launcher3/Workspace.java +5 −7 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.folder.PreviewBackground; import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.graphics.PreloadIconDrawable; import com.android.launcher3.pageindicators.WorkspacePageIndicator; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.launcher3.uioverrides.UiFactory; Loading @@ -101,10 +102,9 @@ import java.util.Set; * Each page contains a number of icons, folders or widgets the user can * interact with. A workspace is meant to be used with a fixed width only. */ public class Workspace extends PagedView public class Workspace extends PagedView<WorkspacePageIndicator> implements DropTarget, DragSource, View.OnTouchListener, DragController.DragListener, ViewGroup.OnHierarchyChangeListener, Insettable, LauncherStateManager.StateHandler { DragController.DragListener, Insettable, LauncherStateManager.StateHandler { private static final String TAG = "Launcher.Workspace"; /** The value that {@link #mTransitionProgress} must be greater than for Loading Loading @@ -275,9 +275,7 @@ public class Workspace extends PagedView mWallpaperOffset = new WallpaperOffsetInterpolator(this); setOnHierarchyChangeListener(this); setHapticFeedbackEnabled(false); initWorkspace(); // Disable multitouch across the workspace/all apps/customize tray Loading Loading @@ -465,7 +463,7 @@ public class Workspace extends PagedView } @Override public void onChildViewAdded(View parent, View child) { public void onViewAdded(View child) { if (!(child instanceof CellLayout)) { throw new IllegalArgumentException("A Workspace can only have CellLayout children."); } Loading @@ -473,7 +471,7 @@ public class Workspace extends PagedView cl.setOnInterceptTouchListener(this); cl.setClickable(true); cl.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); super.onChildViewAdded(parent, child); super.onViewAdded(child); } boolean isTouchActive() { Loading src/com/android/launcher3/allapps/AllAppsContainerView.java +24 −81 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ import android.graphics.Rect; import android.os.Process; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Selection; Loading Loading @@ -50,7 +48,6 @@ import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.PromiseAppInfo; import com.android.launcher3.R; import com.android.launcher3.anim.SpringAnimationHandler; import com.android.launcher3.config.FeatureFlags; Loading @@ -59,12 +56,8 @@ import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.keyboard.FocusedItemDecorator; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.views.BottomUserEducationView; import java.util.List; import java.util.Set; /** * The all apps view container. */ Loading @@ -80,9 +73,8 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, private SearchUiManager mSearchUiManager; private View mSearchContainer; private InterceptingViewPager mViewPager; private AllAppsPagedView mViewPager; private FloatingHeaderView mHeader; private TabsPagerAdapter mTabsPagerAdapter; private SpannableStringBuilder mSearchQueryBuilder = null; Loading Loading @@ -184,7 +176,7 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, } public AllAppsRecyclerView getActiveRecyclerView() { if (!mUsingTabs || mViewPager.getCurrentItem() == 0) { if (!mUsingTabs || mViewPager.getNextPage() == 0) { return mAH[AdapterHolder.MAIN].recyclerView; } else { return mAH[AdapterHolder.WORK].recyclerView; Loading Loading @@ -329,9 +321,8 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, if (mUsingTabs) { mAH[AdapterHolder.MAIN].setup(mViewPager.getChildAt(0), mPersonalMatcher); mAH[AdapterHolder.WORK].setup(mViewPager.getChildAt(1), mWorkMatcher); setupWorkProfileTabs(); onTabChanged(mViewPager.getNextPage()); } else { mTabsPagerAdapter = null; mAH[AdapterHolder.MAIN].setup(findViewById(R.id.apps_list_view), null); mAH[AdapterHolder.WORK].recyclerView = null; } Loading @@ -355,52 +346,37 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, int layout = showTabs ? R.layout.all_apps_tabs : R.layout.all_apps_rv_layout; View newView = LayoutInflater.from(getContext()).inflate(layout, this, false); addView(newView, index); mViewPager = showTabs ? (InterceptingViewPager) newView : null; if (showTabs) { mViewPager = (AllAppsPagedView) newView; mViewPager.initParentViews(this); mViewPager.getPageIndicator().setContainerView(this); } else { mViewPager = null; } } public View getRecyclerViewContainer() { return mViewPager != null ? mViewPager : findViewById(R.id.apps_list_view); } private void setupWorkProfileTabs() { if (mTabsPagerAdapter != null) { return; } final PersonalWorkSlidingTabStrip tabs = findViewById(R.id.tabs); mViewPager.setAdapter(mTabsPagerAdapter = new TabsPagerAdapter()); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { tabs.updateIndicatorPosition(position, positionOffset); } @Override public void onPageSelected(int pos) { tabs.updateTabTextColor(pos); public void onTabChanged(int pos) { mHeader.setMainActive(pos == 0); reset(); applyTouchDelegate(); if (mAH[pos].recyclerView != null) { mAH[pos].recyclerView.bindFastScrollbar(); findViewById(R.id.tab_personal) .setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.MAIN)); findViewById(R.id.tab_work) .setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.WORK)); } if (pos == AdapterHolder.WORK) { BottomUserEducationView.showIfNeeded(mLauncher); } } @Override public void onPageScrollStateChanged(int state) { } }); mAH[AdapterHolder.MAIN].recyclerView.bindFastScrollbar(); findViewById(R.id.tab_personal) .setOnClickListener((View view) -> mViewPager.setCurrentItem(0)); findViewById(R.id.tab_work) .setOnClickListener((View view) -> mViewPager.setCurrentItem(1)); } public AlphabeticalAppsList getApps() { return mAH[AdapterHolder.MAIN].appsList; } Loading Loading @@ -519,37 +495,4 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, && verticalFadingEdge); } } private class TabsPagerAdapter extends PagerAdapter { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { if (position == 0) { return mAH[AdapterHolder.MAIN].recyclerView; } else { return mAH[AdapterHolder.WORK].recyclerView; } } @Nullable @Override public CharSequence getPageTitle(int position) { if (position == 0) { return getResources().getString(R.string.all_apps_personal_tab); } else { return getResources().getString(R.string.all_apps_work_tab); } } } } src/com/android/launcher3/allapps/AllAppsPagedView.java 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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. */ package com.android.launcher3.allapps; import android.content.Context; import android.util.AttributeSet; import com.android.launcher3.PagedView; import com.android.launcher3.R; public class AllAppsPagedView extends PagedView<PersonalWorkSlidingTabStrip> { public AllAppsPagedView(Context context) { this(context, null); } public AllAppsPagedView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected String getCurrentPageDescription() { return getResources().getString( getNextPage() == 0 ? R.string.all_apps_personal_tab : R.string.all_apps_work_tab); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); mPageIndicator.setScroll(l, mMaxScrollX); } } Loading
res/layout/all_apps_tabs.xml +6 −4 Original line number Diff line number Diff line Loading @@ -14,21 +14,23 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <com.android.launcher3.allapps.InterceptingViewPager <com.android.launcher3.allapps.AllAppsPagedView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:launcher="http://schemas.android.com/apk/res-auto" android:id="@+id/all_apps_tabs_view_pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/search_container_all_apps" android:layout_gravity="center_horizontal|top" android:layout_marginTop="@dimen/all_apps_header_tab_height" android:clipChildren="false" android:clipChildren="true" android:clipToPadding="false" android:descendantFocusability="afterDescendants" android:paddingTop="@dimen/all_apps_header_top_padding"> android:paddingTop="@dimen/all_apps_header_top_padding" launcher:pageIndicator="@+id/tabs" > <include layout="@layout/all_apps_rv_layout" /> <include layout="@layout/all_apps_rv_layout" /> </com.android.launcher3.allapps.InterceptingViewPager> No newline at end of file </com.android.launcher3.allapps.AllAppsPagedView> No newline at end of file
src/com/android/launcher3/PagedView.java +14 −54 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ import java.util.ArrayList; * An abstraction of the original Workspace which supports browsing through a * sequential list of "pages" */ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarchyChangeListener { public abstract class PagedView<T extends View & PageIndicator> extends ViewGroup { private static final String TAG = "PagedView"; private static final boolean DEBUG = false; protected static final int INVALID_PAGE = -1; Loading Loading @@ -154,7 +154,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // Page Indicator @Thunk int mPageIndicatorViewId; protected PageIndicator mPageIndicator; protected T mPageIndicator; // Reordering // We use the min scale to determine how much to expand the actually PagedView measured Loading Loading @@ -224,7 +224,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * density); mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * density); mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * density); setOnHierarchyChangeListener(this); setWillNotDraw(false); } Loading @@ -235,9 +234,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc public void initParentViews(View parent) { if (mPageIndicatorViewId > -1) { mPageIndicator = (PageIndicator) parent.findViewById(mPageIndicatorViewId); mPageIndicator = parent.findViewById(mPageIndicatorViewId); mPageIndicator.setMarkersCount(getChildCount()); mPageIndicator.setContentDescription(getPageIndicatorDescription()); mPageIndicator.setPageDescription(getPageIndicatorDescription()); } } Loading Loading @@ -282,7 +281,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } public PageIndicator getPageIndicator() { public T getPageIndicator() { return mPageIndicator; } Loading Loading @@ -384,7 +383,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc private void updatePageIndicator() { // Update the page indicator (when we aren't reordering) if (mPageIndicator != null) { mPageIndicator.setContentDescription(getPageIndicatorDescription()); mPageIndicator.setPageDescription(getPageIndicatorDescription()); if (!isReordering(false)) { mPageIndicator.setActiveMarker(getNextPage()); } Loading Loading @@ -748,63 +747,24 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc requestLayout(); } @Override public void onChildViewAdded(View parent, View child) { // Update the page indicator, we don't update the page indicator as we // add/remove pages if (mPageIndicator != null && !isReordering(false)) { mPageIndicator.addMarker(); private void dispatchPageCountChanged() { if (mPageIndicator != null) { mPageIndicator.setMarkersCount(getChildCount()); } // This ensures that when children are added, they get the correct transforms / alphas // in accordance with any scroll effects. invalidate(); } @Override public void onChildViewRemoved(View parent, View child) { mCurrentPage = validateNewPage(mCurrentPage); invalidate(); } private void removeMarkerForView() { // Update the page indicator, we don't update the page indicator as we // add/remove pages if (mPageIndicator != null && !isReordering(false)) { mPageIndicator.removeMarker(); } public void onViewAdded(View child) { dispatchPageCountChanged(); } @Override public void removeView(View v) { // XXX: We should find a better way to hook into this before the view // gets removed form its parent... removeMarkerForView(); super.removeView(v); } @Override public void removeViewInLayout(View v) { // XXX: We should find a better way to hook into this before the view // gets removed form its parent... removeMarkerForView(); super.removeViewInLayout(v); } @Override public void removeViewAt(int index) { // XXX: We should find a better way to hook into this before the view // gets removed form its parent... removeMarkerForView(); super.removeViewAt(index); } @Override public void removeAllViewsInLayout() { // Update the page indicator, we don't update the page indicator as we // add/remove pages if (mPageIndicator != null) { mPageIndicator.setMarkersCount(0); } super.removeAllViewsInLayout(); public void onViewRemoved(View child) { mCurrentPage = validateNewPage(mCurrentPage); dispatchPageCountChanged(); } protected int getChildOffset(int index) { Loading
src/com/android/launcher3/Workspace.java +5 −7 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.folder.PreviewBackground; import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.graphics.PreloadIconDrawable; import com.android.launcher3.pageindicators.WorkspacePageIndicator; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.launcher3.uioverrides.UiFactory; Loading @@ -101,10 +102,9 @@ import java.util.Set; * Each page contains a number of icons, folders or widgets the user can * interact with. A workspace is meant to be used with a fixed width only. */ public class Workspace extends PagedView public class Workspace extends PagedView<WorkspacePageIndicator> implements DropTarget, DragSource, View.OnTouchListener, DragController.DragListener, ViewGroup.OnHierarchyChangeListener, Insettable, LauncherStateManager.StateHandler { DragController.DragListener, Insettable, LauncherStateManager.StateHandler { private static final String TAG = "Launcher.Workspace"; /** The value that {@link #mTransitionProgress} must be greater than for Loading Loading @@ -275,9 +275,7 @@ public class Workspace extends PagedView mWallpaperOffset = new WallpaperOffsetInterpolator(this); setOnHierarchyChangeListener(this); setHapticFeedbackEnabled(false); initWorkspace(); // Disable multitouch across the workspace/all apps/customize tray Loading Loading @@ -465,7 +463,7 @@ public class Workspace extends PagedView } @Override public void onChildViewAdded(View parent, View child) { public void onViewAdded(View child) { if (!(child instanceof CellLayout)) { throw new IllegalArgumentException("A Workspace can only have CellLayout children."); } Loading @@ -473,7 +471,7 @@ public class Workspace extends PagedView cl.setOnInterceptTouchListener(this); cl.setClickable(true); cl.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); super.onChildViewAdded(parent, child); super.onViewAdded(child); } boolean isTouchActive() { Loading
src/com/android/launcher3/allapps/AllAppsContainerView.java +24 −81 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ import android.graphics.Rect; import android.os.Process; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Selection; Loading Loading @@ -50,7 +48,6 @@ import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.PromiseAppInfo; import com.android.launcher3.R; import com.android.launcher3.anim.SpringAnimationHandler; import com.android.launcher3.config.FeatureFlags; Loading @@ -59,12 +56,8 @@ import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.keyboard.FocusedItemDecorator; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.views.BottomUserEducationView; import java.util.List; import java.util.Set; /** * The all apps view container. */ Loading @@ -80,9 +73,8 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, private SearchUiManager mSearchUiManager; private View mSearchContainer; private InterceptingViewPager mViewPager; private AllAppsPagedView mViewPager; private FloatingHeaderView mHeader; private TabsPagerAdapter mTabsPagerAdapter; private SpannableStringBuilder mSearchQueryBuilder = null; Loading Loading @@ -184,7 +176,7 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, } public AllAppsRecyclerView getActiveRecyclerView() { if (!mUsingTabs || mViewPager.getCurrentItem() == 0) { if (!mUsingTabs || mViewPager.getNextPage() == 0) { return mAH[AdapterHolder.MAIN].recyclerView; } else { return mAH[AdapterHolder.WORK].recyclerView; Loading Loading @@ -329,9 +321,8 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, if (mUsingTabs) { mAH[AdapterHolder.MAIN].setup(mViewPager.getChildAt(0), mPersonalMatcher); mAH[AdapterHolder.WORK].setup(mViewPager.getChildAt(1), mWorkMatcher); setupWorkProfileTabs(); onTabChanged(mViewPager.getNextPage()); } else { mTabsPagerAdapter = null; mAH[AdapterHolder.MAIN].setup(findViewById(R.id.apps_list_view), null); mAH[AdapterHolder.WORK].recyclerView = null; } Loading @@ -355,52 +346,37 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, int layout = showTabs ? R.layout.all_apps_tabs : R.layout.all_apps_rv_layout; View newView = LayoutInflater.from(getContext()).inflate(layout, this, false); addView(newView, index); mViewPager = showTabs ? (InterceptingViewPager) newView : null; if (showTabs) { mViewPager = (AllAppsPagedView) newView; mViewPager.initParentViews(this); mViewPager.getPageIndicator().setContainerView(this); } else { mViewPager = null; } } public View getRecyclerViewContainer() { return mViewPager != null ? mViewPager : findViewById(R.id.apps_list_view); } private void setupWorkProfileTabs() { if (mTabsPagerAdapter != null) { return; } final PersonalWorkSlidingTabStrip tabs = findViewById(R.id.tabs); mViewPager.setAdapter(mTabsPagerAdapter = new TabsPagerAdapter()); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { tabs.updateIndicatorPosition(position, positionOffset); } @Override public void onPageSelected(int pos) { tabs.updateTabTextColor(pos); public void onTabChanged(int pos) { mHeader.setMainActive(pos == 0); reset(); applyTouchDelegate(); if (mAH[pos].recyclerView != null) { mAH[pos].recyclerView.bindFastScrollbar(); findViewById(R.id.tab_personal) .setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.MAIN)); findViewById(R.id.tab_work) .setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.WORK)); } if (pos == AdapterHolder.WORK) { BottomUserEducationView.showIfNeeded(mLauncher); } } @Override public void onPageScrollStateChanged(int state) { } }); mAH[AdapterHolder.MAIN].recyclerView.bindFastScrollbar(); findViewById(R.id.tab_personal) .setOnClickListener((View view) -> mViewPager.setCurrentItem(0)); findViewById(R.id.tab_work) .setOnClickListener((View view) -> mViewPager.setCurrentItem(1)); } public AlphabeticalAppsList getApps() { return mAH[AdapterHolder.MAIN].appsList; } Loading Loading @@ -519,37 +495,4 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, && verticalFadingEdge); } } private class TabsPagerAdapter extends PagerAdapter { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { if (position == 0) { return mAH[AdapterHolder.MAIN].recyclerView; } else { return mAH[AdapterHolder.WORK].recyclerView; } } @Nullable @Override public CharSequence getPageTitle(int position) { if (position == 0) { return getResources().getString(R.string.all_apps_personal_tab); } else { return getResources().getString(R.string.all_apps_work_tab); } } } }
src/com/android/launcher3/allapps/AllAppsPagedView.java 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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. */ package com.android.launcher3.allapps; import android.content.Context; import android.util.AttributeSet; import com.android.launcher3.PagedView; import com.android.launcher3.R; public class AllAppsPagedView extends PagedView<PersonalWorkSlidingTabStrip> { public AllAppsPagedView(Context context) { this(context, null); } public AllAppsPagedView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected String getCurrentPageDescription() { return getResources().getString( getNextPage() == 0 ? R.string.all_apps_personal_tab : R.string.all_apps_work_tab); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); mPageIndicator.setScroll(l, mMaxScrollX); } }