Search in sources :

Example 11 with OnScrollListener

use of android.support.v7.widget.RecyclerView.OnScrollListener in project android_frameworks_base by DirtyUnicorns.

the class RecentsTvView method launchTaskFomRecents.

/**
     * Launch the given task from recents with animation. If the task is not focused, this will
     * attempt to scroll to focus the task before launching.
     * @param task
     */
private void launchTaskFomRecents(final Task task, boolean animate) {
    if (!animate) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
        return;
    }
    mTaskStackHorizontalView.requestFocus();
    Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
    if (focusedTask != null && task != focusedTask) {
        if (mScrollListener != null) {
            mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
        }
        mScrollListener = new OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
                    if (cardView != null) {
                        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
                    } else {
                        // This should not happen normally. If this happens then the data in
                        // the grid view was altered during the scroll. Log error and launch
                        // task with no animation.
                        Log.e(TAG, "Card view for task : " + task + ", returned null.");
                        SystemServicesProxy ssp = Recents.getSystemServices();
                        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
                    }
                    mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
                }
            }
        };
        mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
        mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
    } else {
        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) Task(com.android.systemui.recents.model.Task) OnScrollListener(android.support.v7.widget.RecyclerView.OnScrollListener) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)9 OnScrollListener (android.support.v7.widget.RecyclerView.OnScrollListener)6 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)5 Task (com.android.systemui.recents.model.Task)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 ActionBar (android.app.ActionBar)1 Paint (android.graphics.Paint)1 Handler (android.os.Handler)1 NestedScrollView (android.support.v4.widget.NestedScrollView)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 View (android.view.View)1 RecyclerViewAdapter (com.daimajia.swipedemo.adapter.RecyclerViewAdapter)1 DividerItemDecoration (com.daimajia.swipedemo.adapter.util.DividerItemDecoration)1 FadeInLeftAnimator (jp.wasabeef.recyclerview.animators.FadeInLeftAnimator)1 ObservableNestedScrollView (me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView)1 ObservableRecyclerView (me.henrytao.smoothappbarlayout.base.ObservableRecyclerView)1 OnScrollListener (me.henrytao.smoothappbarlayout.base.OnScrollListener)1