org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter Java Examples

The following examples show how to use org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SuggestionsRecyclerView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public void init(
        UiConfig uiConfig, ContextMenuManager contextMenuManager, NewTabPageAdapter adapter) {
    mUiConfig = uiConfig;
    mContextMenuManager = contextMenuManager;
    setAdapter(adapter);
}
 
Example #2
Source File: SuggestionsRecyclerView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public NewTabPageAdapter getNewTabPageAdapter() {
    return (NewTabPageAdapter) getAdapter();
}
 
Example #3
Source File: SuggestionsBottomSheetContent.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public SuggestionsBottomSheetContent(final ChromeActivity activity, final BottomSheet sheet,
        TabModelSelector tabModelSelector, SnackbarManager snackbarManager) {
    Profile profile = Profile.getLastUsedProfile();
    SuggestionsNavigationDelegate navigationDelegate =
            new SuggestionsNavigationDelegateImpl(activity, profile, sheet, tabModelSelector);
    mTileGroupDelegate = new TileGroupDelegateImpl(
            activity, profile, tabModelSelector, navigationDelegate, snackbarManager);
    mSuggestionsUiDelegate = createSuggestionsDelegate(
            profile, navigationDelegate, sheet, activity.getReferencePool());

    mView = LayoutInflater.from(activity).inflate(
            R.layout.suggestions_bottom_sheet_content, null);
    mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycler_view);

    TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() {
        @Override
        public void setTouchEnabled(boolean enabled) {
            activity.getBottomSheet().setTouchEnabled(enabled);
        }
    };
    mContextMenuManager =
            new ContextMenuManager(activity, navigationDelegate, touchEnabledDelegate);
    activity.getWindowAndroid().addContextMenuCloseListener(mContextMenuManager);
    mSuggestionsUiDelegate.addDestructionObserver(new DestructionObserver() {
        @Override
        public void onDestroy() {
            activity.getWindowAndroid().removeContextMenuCloseListener(mContextMenuManager);
        }
    });

    UiConfig uiConfig = new UiConfig(mRecyclerView);

    final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsUiDelegate,
            /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getForProfile(profile),
            mContextMenuManager, mTileGroupDelegate);
    mRecyclerView.init(uiConfig, mContextMenuManager, adapter);

    mBottomSheetObserver = new SuggestionsSheetVisibilityChangeObserver(this, activity) {
        @Override
        public void onSheetOpened() {
            mRecyclerView.scrollToPosition(0);
            adapter.refreshSuggestions();
            mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened();
            mRecyclerView.getScrollEventReporter().reset();

            if (ChromeFeatureList.isEnabled(
                        ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_CAROUSEL)
                    && sheet.getActiveTab() != null) {
                updateContextualSuggestions(sheet.getActiveTab().getUrl());
            }

            super.onSheetOpened();
        }

        @Override
        public void onContentShown() {
            SuggestionsMetrics.recordSurfaceVisible();
        }

        @Override
        public void onContentHidden() {
            SuggestionsMetrics.recordSurfaceHidden();
        }

        @Override
        public void onContentStateChanged(@BottomSheet.SheetState int contentState) {
            if (contentState == BottomSheet.SHEET_STATE_HALF) {
                SuggestionsMetrics.recordSurfaceHalfVisible();
            } else if (contentState == BottomSheet.SHEET_STATE_FULL) {
                SuggestionsMetrics.recordSurfaceFullyVisible();
            }
        }
    };

    mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow);
    mShadowView.init(
            ApiCompatibilityUtils.getColor(mView.getResources(), R.color.toolbar_shadow_color),
            FadingShadow.POSITION_TOP);

    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            boolean shadowVisible = mRecyclerView.canScrollVertically(-1);
            mShadowView.setVisibility(shadowVisible ? View.VISIBLE : View.GONE);
        }
    });

    final LocationBar locationBar = (LocationBar) sheet.findViewById(R.id.location_bar);
    mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        @SuppressLint("ClickableViewAccessibility")
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (locationBar != null && locationBar.isUrlBarFocused()) {
                locationBar.setUrlBarFocus(false);
            }

            // Never intercept the touch event.
            return false;
        }
    });
}