Search in sources :

Example 1 with WidgetsFullSheet

use of com.android.launcher3.widget.WidgetsFullSheet in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherUIScrollTest method testWidgetsListScroll.

@Test
public void testWidgetsListScroll() throws Exception {
    // Install 100 widgets
    for (int i = 0; i < 100; i++) {
        mModelHelper.installCustomShortcut(TEST_PACKAGE + i, "shortcutProvider");
    }
    // Bind and open widgets
    Launcher launcher = loadLauncher();
    WidgetsFullSheet widgets = WidgetsFullSheet.show(launcher, false);
    doLayout(launcher);
    int currentScroll = widgets.getRecyclerView().getCurrentScrollY();
    launcher.dispatchGenericMotionEvent(createScrollEvent(-1));
    int newScroll = widgets.getRecyclerView().getCurrentScrollY();
    assertNotEquals("Widgets was not scrolled", currentScroll, newScroll);
    assertEquals("Workspace was scrolled", 0, launcher.getWorkspace().getNextPage());
}
Also used : LauncherUIHelper.buildAndBindLauncher(com.android.launcher3.util.LauncherUIHelper.buildAndBindLauncher) Launcher(com.android.launcher3.Launcher) WidgetsFullSheet(com.android.launcher3.widget.picker.WidgetsFullSheet) Test(org.junit.Test)

Example 2 with WidgetsFullSheet

use of com.android.launcher3.widget.WidgetsFullSheet in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherUIScrollTest method testWidgetsListScroll.

@Test
public void testWidgetsListScroll() throws Exception {
    // Install 100 widgets
    for (int i = 0; i < 100; i++) {
        mModelHelper.installCustomShortcut(TEST_PACKAGE + i, "shortcutProvider");
    }
    // Bind and open widgets
    Launcher launcher = loadLauncher();
    WidgetsFullSheet widgets = WidgetsFullSheet.show(launcher, false);
    doLayout(launcher);
    int currentScroll = widgets.getRecyclerView().getCurrentScrollY();
    launcher.dispatchGenericMotionEvent(createScrollEvent(-1));
    int newScroll = widgets.getRecyclerView().getCurrentScrollY();
    assertNotEquals("Widgets was not scrolled", currentScroll, newScroll);
    assertEquals("Workspace was scrolled", 0, launcher.getWorkspace().getNextPage());
}
Also used : LauncherUIHelper.buildAndBindLauncher(com.android.launcher3.util.LauncherUIHelper.buildAndBindLauncher) Launcher(com.android.launcher3.Launcher) WidgetsFullSheet(com.android.launcher3.widget.WidgetsFullSheet) Test(org.junit.Test)

Example 3 with WidgetsFullSheet

use of com.android.launcher3.widget.WidgetsFullSheet in project android_packages_apps_Launcher3 by crdroidandroid.

the class SearchAndRecommendationsScrollController method updateMarginAndPadding.

/**
 * Updates the margin and padding of {@link WidgetsFullSheet} to accumulate collapsible views.
 *
 * @return {@code true} if margins or/and padding of views in the search and recommendations
 * container have been updated.
 */
public boolean updateMarginAndPadding() {
    boolean hasMarginOrPaddingUpdated = false;
    mCollapsibleHeightForSearch = measureHeightWithVerticalMargins(mViewHolder.mHeaderTitle);
    mCollapsibleHeightForRecommendation = measureHeightWithVerticalMargins(mViewHolder.mHeaderTitle) + measureHeightWithVerticalMargins(mViewHolder.mCollapseHandle) + measureHeightWithVerticalMargins((View) mViewHolder.mSearchBarContainer) + measureHeightWithVerticalMargins(mViewHolder.mRecommendedWidgetsTable);
    int topContainerHeight = measureHeightWithVerticalMargins(mViewHolder.mContainer);
    int noWidgetsViewHeight = topContainerHeight - mBottomInset;
    if (mHasWorkProfile) {
        mCollapsibleHeightForTabs = measureHeightWithVerticalMargins(mViewHolder.mHeaderTitle) + measureHeightWithVerticalMargins(mViewHolder.mRecommendedWidgetsTable);
        // In a work profile setup, the full widget sheet contains the following views:
        // ------- (pinned)           -|
        // Widgets (collapsible)       -|---> LinearLayout for search & recommendations
        // Search bar (pinned)         -|
        // Widgets recommendation (collapsible)-|
        // Personal | Work (pinned)
        // View Pager
        // 
        // Views after the search & recommendations are not bound by RelativelyLayout param.
        // To position them on the expected location, padding & margin are added to these views
        // Tabs should have a padding of the height of the search & recommendations container.
        RelativeLayout.LayoutParams tabsLayoutParams = (RelativeLayout.LayoutParams) mPrimaryWorkTabsView.getLayoutParams();
        tabsLayoutParams.topMargin = topContainerHeight;
        mPrimaryWorkTabsView.setLayoutParams(tabsLayoutParams);
        // Instead of setting the top offset directly, we split the top offset into two values:
        // 1. topOffsetAfterAllViewsCollapsed: this is the top offset after all collapsible
        // views are no longer visible on the screen.
        // This value is set as the margin for the view pager.
        // 2. mMaxCollapsibleDistance
        // This value is set as the padding for the recycler views in order to work with
        // clipToPadding="false", which is an attribute for not showing top / bottom padding
        // when a recycler view has not reached the top or bottom of the list.
        // e.g. a list of 10 entries, only 3 entries are visible at a time.
        // case 1: recycler view is scrolled to the top. Top padding is visible/
        // (top padding)
        // item 1
        // item 2
        // item 3
        // 
        // case 2: recycler view is scrolled to the middle. No padding is visible.
        // item 4
        // item 5
        // item 6
        // 
        // case 3: recycler view is scrolled to the end. bottom padding is visible.
        // item 8
        // item 9
        // item 10
        // (bottom padding): not set in this case.
        // 
        // When the views are first inflated, the sum of topOffsetAfterAllViewsCollapsed and
        // mMaxCollapsibleDistance should equal to the top container height.
        int topOffsetAfterAllViewsCollapsed = topContainerHeight + mTabsHeight - mCollapsibleHeightForTabs;
        if (mPrimaryWorkTabsView.getVisibility() == View.VISIBLE) {
            noWidgetsViewHeight += mTabsHeight;
        }
        RelativeLayout.LayoutParams viewPagerLayoutParams = (RelativeLayout.LayoutParams) mPrimaryWorkViewPager.getLayoutParams();
        if (viewPagerLayoutParams.topMargin != topOffsetAfterAllViewsCollapsed) {
            viewPagerLayoutParams.topMargin = topOffsetAfterAllViewsCollapsed;
            mPrimaryWorkViewPager.setLayoutParams(viewPagerLayoutParams);
            hasMarginOrPaddingUpdated = true;
        }
        if (mPrimaryRecyclerView.getPaddingTop() != mCollapsibleHeightForTabs) {
            mPrimaryRecyclerView.setPadding(mPrimaryRecyclerView.getPaddingLeft(), mCollapsibleHeightForTabs, mPrimaryRecyclerView.getPaddingRight(), mPrimaryRecyclerView.getPaddingBottom());
            hasMarginOrPaddingUpdated = true;
        }
        if (mWorkRecyclerView.getPaddingTop() != mCollapsibleHeightForTabs) {
            mWorkRecyclerView.setPadding(mWorkRecyclerView.getPaddingLeft(), mCollapsibleHeightForTabs, mWorkRecyclerView.getPaddingRight(), mWorkRecyclerView.getPaddingBottom());
            hasMarginOrPaddingUpdated = true;
        }
    } else {
        if (mPrimaryRecyclerView.getPaddingTop() != topContainerHeight) {
            mPrimaryRecyclerView.setPadding(mPrimaryRecyclerView.getPaddingLeft(), topContainerHeight, mPrimaryRecyclerView.getPaddingRight(), mPrimaryRecyclerView.getPaddingBottom());
            hasMarginOrPaddingUpdated = true;
        }
    }
    if (mSearchRecyclerView.getPaddingTop() != topContainerHeight) {
        mSearchRecyclerView.setPadding(mSearchRecyclerView.getPaddingLeft(), topContainerHeight, mSearchRecyclerView.getPaddingRight(), mSearchRecyclerView.getPaddingBottom());
        hasMarginOrPaddingUpdated = true;
    }
    if (mNoWidgetsView.getPaddingTop() != noWidgetsViewHeight) {
        mNoWidgetsView.setPadding(mNoWidgetsView.getPaddingLeft(), noWidgetsViewHeight, mNoWidgetsView.getPaddingRight(), mNoWidgetsView.getPaddingBottom());
        hasMarginOrPaddingUpdated = true;
    }
    return hasMarginOrPaddingUpdated;
}
Also used : MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) PersonalWorkPagedView(com.android.launcher3.workprofile.PersonalWorkPagedView) View(android.view.View) Point(android.graphics.Point)

Aggregations

Launcher (com.android.launcher3.Launcher)2 LauncherUIHelper.buildAndBindLauncher (com.android.launcher3.util.LauncherUIHelper.buildAndBindLauncher)2 Test (org.junit.Test)2 Point (android.graphics.Point)1 View (android.view.View)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 WidgetsFullSheet (com.android.launcher3.widget.WidgetsFullSheet)1 WidgetsFullSheet (com.android.launcher3.widget.picker.WidgetsFullSheet)1 PersonalWorkPagedView (com.android.launcher3.workprofile.PersonalWorkPagedView)1