use of android.graphics.drawable.TransitionDrawable in project android_frameworks_base by DirtyUnicorns.
the class AbsListView method onTouchUp.
private void onTouchUp(MotionEvent ev) {
switch(mTouchMode) {
case TOUCH_MODE_DOWN:
case TOUCH_MODE_TAP:
case TOUCH_MODE_DONE_WAITING:
final int motionPosition = mMotionPosition;
final View child = getChildAt(motionPosition - mFirstPosition);
if (child != null) {
if (mTouchMode != TOUCH_MODE_DOWN) {
child.setPressed(false);
}
final float x = ev.getX();
final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
if (inList && !child.hasFocusable()) {
if (mPerformClick == null) {
mPerformClick = new PerformClick();
}
final AbsListView.PerformClick performClick = mPerformClick;
performClick.mClickMotionPosition = motionPosition;
performClick.rememberWindowAttachCount();
mResurrectToPosition = motionPosition;
if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
mLayoutMode = LAYOUT_NORMAL;
if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
mTouchMode = TOUCH_MODE_TAP;
setSelectedPositionInt(mMotionPosition);
layoutChildren();
child.setPressed(true);
positionSelector(mMotionPosition, child);
setPressed(true);
if (mSelector != null) {
Drawable d = mSelector.getCurrent();
if (d != null && d instanceof TransitionDrawable) {
((TransitionDrawable) d).resetTransition();
}
mSelector.setHotspot(x, ev.getY());
}
if (mTouchModeReset != null) {
removeCallbacks(mTouchModeReset);
}
mTouchModeReset = new Runnable() {
@Override
public void run() {
mTouchModeReset = null;
mTouchMode = TOUCH_MODE_REST;
child.setPressed(false);
setPressed(false);
if (!mDataChanged && !mIsDetaching && isAttachedToWindow()) {
performClick.run();
}
}
};
postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());
} else {
mTouchMode = TOUCH_MODE_REST;
updateSelectorState();
}
return;
} else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
performClick.run();
}
}
}
mTouchMode = TOUCH_MODE_REST;
updateSelectorState();
break;
case TOUCH_MODE_SCROLL:
final int childCount = getChildCount();
if (childCount > 0) {
final int firstChildTop = getChildAt(0).getTop();
final int lastChildBottom = getChildAt(childCount - 1).getBottom();
final int contentTop = mListPadding.top;
final int contentBottom = getHeight() - mListPadding.bottom;
if (mFirstPosition == 0 && firstChildTop >= contentTop && mFirstPosition + childCount < mItemCount && lastChildBottom <= getHeight() - contentBottom) {
mTouchMode = TOUCH_MODE_REST;
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int initialVelocity = (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale);
// Fling if we have enough velocity and we aren't at a boundary.
// Since we can potentially overfling more than we can overscroll, don't
// allow the weird behavior where you can scroll to a boundary then
// fling further.
boolean flingVelocity = Math.abs(initialVelocity) > mMinimumVelocity;
if (flingVelocity && !((mFirstPosition == 0 && firstChildTop == contentTop - mOverscrollDistance) || (mFirstPosition + childCount == mItemCount && lastChildBottom == contentBottom + mOverscrollDistance))) {
if (!dispatchNestedPreFling(0, -initialVelocity)) {
if (mFlingRunnable == null) {
mFlingRunnable = new FlingRunnable();
}
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
mFlingRunnable.start(-initialVelocity);
dispatchNestedFling(0, -initialVelocity, true);
} else {
mTouchMode = TOUCH_MODE_REST;
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
}
} else {
mTouchMode = TOUCH_MODE_REST;
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
if (mFlingRunnable != null) {
mFlingRunnable.endFling();
}
if (mPositionScroller != null) {
mPositionScroller.stop();
}
if (flingVelocity && !dispatchNestedPreFling(0, -initialVelocity)) {
dispatchNestedFling(0, -initialVelocity, false);
}
}
}
} else {
mTouchMode = TOUCH_MODE_REST;
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
}
break;
case TOUCH_MODE_OVERSCROLL:
if (mFlingRunnable == null) {
mFlingRunnable = new FlingRunnable();
}
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId);
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
if (Math.abs(initialVelocity) > mMinimumVelocity) {
mFlingRunnable.startOverfling(-initialVelocity);
} else {
mFlingRunnable.startSpringback();
}
break;
}
setPressed(false);
if (mEdgeGlowTop != null) {
mEdgeGlowTop.onRelease();
mEdgeGlowBottom.onRelease();
}
// Need to redraw since we probably aren't drawing the selector anymore
invalidate();
removeCallbacks(mPendingCheckForLongPress);
recycleVelocityTracker();
mActivePointerId = INVALID_POINTER;
if (PROFILE_SCROLLING) {
if (mScrollProfilingStarted) {
Debug.stopMethodTracing();
mScrollProfilingStarted = false;
}
}
if (mScrollStrictSpan != null) {
mScrollStrictSpan.finish();
mScrollStrictSpan = null;
}
}
use of android.graphics.drawable.TransitionDrawable in project focus-android by mozilla-mobile.
the class TransitionDrawableGroupTest method testStartIsCalledOnAllItems.
@Test
public void testStartIsCalledOnAllItems() {
final TransitionDrawable transitionDrawable1 = mock(TransitionDrawable.class);
final TransitionDrawable transitionDrawable2 = mock(TransitionDrawable.class);
final TransitionDrawableGroup group = new TransitionDrawableGroup(transitionDrawable1, transitionDrawable2);
group.startTransition(2500);
verify(transitionDrawable1).startTransition(2500);
verify(transitionDrawable2).startTransition(2500);
}
use of android.graphics.drawable.TransitionDrawable in project focus-android by mozilla-mobile.
the class FirstrunFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_firstrun, container, false);
view.findViewById(R.id.skip).setOnClickListener(this);
background = view.findViewById(R.id.background);
final FirstrunPagerAdapter adapter = new FirstrunPagerAdapter(container.getContext(), this);
viewPager = (ViewPager) view.findViewById(R.id.pager);
viewPager.setFocusable(true);
viewPager.setPageTransformer(true, new ViewPager.PageTransformer() {
@Override
public void transformPage(View page, float position) {
page.setAlpha(1 - (0.5f * Math.abs(position)));
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
TelemetryWrapper.showFirstRunPageEvent(position);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
viewPager.setClipToPadding(false);
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
final TransitionDrawable drawable = (TransitionDrawable) background.getBackground();
if (position == adapter.getCount() - 1) {
drawable.startTransition(200);
} else {
drawable.resetTransition();
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager, true);
return view;
}
use of android.graphics.drawable.TransitionDrawable in project android_packages_apps_Dialer by LineageOS.
the class ContactPhotoManagerImpl method loadCachedPhoto.
/**
* Checks if the photo is present in cache. If so, sets the photo on the view.
*
* @return false if the photo needs to be (re)loaded from the provider.
*/
@UiThread
private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) {
BitmapHolder holder = mBitmapHolderCache.get(request.getKey());
if (holder == null) {
// The bitmap has not been loaded ==> show default avatar
request.applyDefaultImage(view, request.mIsCircular);
return false;
}
if (holder.bytes == null) {
request.applyDefaultImage(view, request.mIsCircular);
return holder.fresh;
}
Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get();
if (cachedBitmap == null) {
request.applyDefaultImage(view, request.mIsCircular);
return false;
}
final Drawable previousDrawable = view.getDrawable();
if (fadeIn && previousDrawable != null) {
final Drawable[] layers = new Drawable[2];
// Prevent cascade of TransitionDrawables.
if (previousDrawable instanceof TransitionDrawable) {
final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable;
layers[0] = previousTransitionDrawable.getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1);
} else {
layers[0] = previousDrawable;
}
layers[1] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request);
TransitionDrawable drawable = new TransitionDrawable(layers);
view.setImageDrawable(drawable);
drawable.startTransition(FADE_TRANSITION_DURATION);
} else {
view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request));
}
// (we require that at least six of those can be cached at the same time)
if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) {
mBitmapCache.put(request.getKey(), cachedBitmap);
}
// Soften the reference
holder.bitmap = null;
return holder.fresh;
}
use of android.graphics.drawable.TransitionDrawable in project firefox-tv by mozilla-mobile.
the class TransitionDrawableGroupTest method testResetIsCalledOnAllItems.
@Test
public void testResetIsCalledOnAllItems() {
final TransitionDrawable transitionDrawable1 = mock(TransitionDrawable.class);
final TransitionDrawable transitionDrawable2 = mock(TransitionDrawable.class);
final TransitionDrawableGroup group = new TransitionDrawableGroup(transitionDrawable1, transitionDrawable2);
group.resetTransition();
verify(transitionDrawable1).resetTransition();
verify(transitionDrawable2).resetTransition();
}
Aggregations