Search in sources :

Example 51 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project MyJapanese by 54wall.

the class LessonsFragment method onLeftItemSelected.

@Override
public void onLeftItemSelected(int position, Book menu) {
    int sum = 0;
    Long start = System.currentTimeMillis();
    for (int i = 0; i < position; i++) {
        sum += mBookList.get(i).getLessonList().size() + 1;
    }
    Long end = System.currentTimeMillis();
    Log.e(TAG, "onLeftItemSelected-time: " + (end - start));
    Long start2 = System.currentTimeMillis();
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRightMenu.getLayoutManager();
    layoutManager.scrollToPositionWithOffset(sum, 0);
    leftClickType = true;
    Long end2 = System.currentTimeMillis();
    Log.e(TAG, "onLeftItemSelected-time: " + (end2 - start2));
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 52 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project MyJapanese by 54wall.

the class LessonsFragment method initView.

@Override
public void initView() {
    mLeftMenu.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRightMenu.setLayoutManager(new LinearLayoutManager(getActivity()));
    // 如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    mLeftMenu.setHasFixedSize(true);
    mRightMenu.setHasFixedSize(true);
    mRightMenu.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            Log.e(TAG, "onScrolled start");
            super.onScrolled(recyclerView, dx, dy);
            if (recyclerView.canScrollVertically(1) == false) {
                // 无法下滑
                showHeadView();
                return;
            }
            View underView = null;
            if (dy > 0) {
                underView = mRightMenu.findChildViewUnder(headerLayout.getX(), headerLayout.getMeasuredHeight() + 1);
            } else {
                underView = mRightMenu.findChildViewUnder(headerLayout.getX(), 0);
            }
            if (underView != null && underView.getContentDescription() != null) {
                int position = Integer.parseInt(underView.getContentDescription().toString());
                Book menu = rightAdapter.getMenuOfMenuByPosition(position);
                if (leftClickType || !menu.getName().equals(headMenu.getName())) {
                    if (dy > 0 && headerLayout.getTranslationY() <= 1 && headerLayout.getTranslationY() >= -1 * headerLayout.getMeasuredHeight() * 4 / 5 && !leftClickType) {
                        // underView.getTop()>9
                        int dealtY = underView.getTop() - headerLayout.getMeasuredHeight();
                        headerLayout.setTranslationY(dealtY);
                    // Log.e(TAG, "onScrolled: "+headerLayout.getTranslationY()+"   "+headerLayout.getBottom()+"  -  "+headerLayout.getMeasuredHeight() );
                    } else if (dy < 0 && headerLayout.getTranslationY() <= 0 && !leftClickType) {
                        headerView.setText(menu.getName());
                        int dealtY = underView.getBottom() - headerLayout.getMeasuredHeight();
                        headerLayout.setTranslationY(dealtY);
                    // Log.e(TAG, "onScrolled: "+headerLayout.getTranslationY()+"   "+headerLayout.getBottom()+"  -  "+headerLayout.getMeasuredHeight() );
                    } else {
                        headerLayout.setTranslationY(0);
                        headMenu = menu;
                        headerView.setText(headMenu.getName());
                        for (int i = 0; i < mBookList.size(); i++) {
                            if (mBookList.get(i) == headMenu) {
                                leftAdapter.setSelectedNum(i);
                                break;
                            }
                        }
                        if (leftClickType)
                            leftClickType = false;
                        Log.e(TAG, "onScrolled: " + menu.getName());
                    }
                }
            }
            Log.e(TAG, "onScrolled end");
        }
    });
}
Also used : Book(pri.weiqiang.myjapanese.mvp.bean.Book) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) BaseView(pri.weiqiang.myjapanese.mvp.view.BaseView)

Example 53 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project instructure-android by instructure.

the class ExpandCollapseItemAnimator method animateRemoveImpl.

private void animateRemoveImpl(final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mRemoveAnimations.add(holder);
    animation.setDuration(getRemoveDuration()).alpha(0).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchRemoveStarting(holder);
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            ViewCompat.setAlpha(view, 1);
            dispatchRemoveFinished(holder);
            mRemoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 54 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project instructure-android by instructure.

the class ExpandCollapseItemAnimator method animateAddImpl.

private void animateAddImpl(final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);
    animation.alpha(1).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchAddStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            ViewCompat.setAlpha(view, 1);
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 55 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project instructure-android by instructure.

the class ExpandCollapseItemAnimator method animateMoveImpl.

private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        ViewCompat.animate(view).translationX(0);
    }
    if (deltaY != 0) {
        ViewCompat.animate(view).translationY(0);
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mMoveAnimations.add(holder);
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            if (deltaX != 0) {
                ViewCompat.setTranslationX(view, 0);
            }
            if (deltaY != 0) {
                ViewCompat.setTranslationY(view, 0);
            }
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)367 RecyclerView (android.support.v7.widget.RecyclerView)271 TextView (android.widget.TextView)175 Intent (android.content.Intent)109 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)84 Toolbar (android.support.v7.widget.Toolbar)77 TextWatcher (android.text.TextWatcher)77 Editable (android.text.Editable)76 ImageView (android.widget.ImageView)76 ArrayList (java.util.ArrayList)68 Bundle (android.os.Bundle)48 DialogInterface (android.content.DialogInterface)47 AlertDialog (android.support.v7.app.AlertDialog)47 AdapterView (android.widget.AdapterView)46 EditText (android.widget.EditText)42 SuppressLint (android.annotation.SuppressLint)39 Button (android.widget.Button)39 ActionBar (android.support.v7.app.ActionBar)34 List (java.util.List)34 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)33