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));
}
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");
}
});
}
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();
}
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();
}
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();
}
Aggregations