use of android.graphics.drawable.TransitionDrawable in project StaggeredGridView by maurycyw.
the class StaggeredGridView method onTouchEvent.
@Override
public boolean onTouchEvent(MotionEvent ev) {
mVelocityTracker.addMovement(ev);
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
switch(action) {
case MotionEvent.ACTION_DOWN:
mVelocityTracker.clear();
mScroller.abortAnimation();
mLastTouchY = ev.getY();
mLastTouchX = ev.getX();
motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mTouchRemainderY = 0;
if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && mAdapter != null && mAdapter.isEnabled(motionPosition)) {
mTouchMode = TOUCH_MODE_DOWN;
mBeginClick = true;
if (mPendingCheckForTap == null) {
mPendingCheckForTap = new CheckForTap();
}
postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
}
mMotionPosition = motionPosition;
invalidate();
break;
case MotionEvent.ACTION_MOVE:
{
final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
if (index < 0) {
Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?");
return false;
}
final float y = MotionEventCompat.getY(ev, index);
final float dy = y - mLastTouchY + mTouchRemainderY;
final int deltaY = (int) dy;
mTouchRemainderY = dy - deltaY;
if (Math.abs(dy) > mTouchSlop) {
mTouchMode = TOUCH_MODE_DRAGGING;
}
if (mTouchMode == TOUCH_MODE_DRAGGING) {
mLastTouchY = y;
if (!trackMotionScroll(deltaY, true)) {
// Break fling velocity if we impacted an edge.
mVelocityTracker.clear();
}
}
updateSelectorState();
}
break;
case MotionEvent.ACTION_CANCEL:
mTouchMode = TOUCH_MODE_IDLE;
updateSelectorState();
setPressed(false);
View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
if (motionView != null) {
motionView.setPressed(false);
}
final Handler handler = getHandler();
if (handler != null) {
handler.removeCallbacks(mPendingCheckForLongPress);
}
if (mTopEdge != null) {
mTopEdge.onRelease();
mBottomEdge.onRelease();
}
mTouchMode = TOUCH_MODE_IDLE;
break;
case MotionEvent.ACTION_UP:
{
mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
final int prevTouchMode = mTouchMode;
if (Math.abs(velocity) > mFlingVelocity) {
// TODO
mTouchMode = TOUCH_MODE_FLINGING;
mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
mLastTouchY = 0;
invalidate();
} else {
mTouchMode = TOUCH_MODE_IDLE;
}
if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) {
// TODO : handle
mTouchMode = TOUCH_MODE_TAP;
} else {
mTouchMode = TOUCH_MODE_REST;
}
switch(prevTouchMode) {
case TOUCH_MODE_DOWN:
case TOUCH_MODE_TAP:
case TOUCH_MODE_DONE_WAITING:
final View child = getChildAt(motionPosition - mFirstPosition);
final float x = ev.getX();
final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight();
if (child != null && !child.hasFocusable() && inList) {
if (mTouchMode != TOUCH_MODE_DOWN) {
child.setPressed(false);
}
if (mPerformClick == null) {
invalidate();
mPerformClick = new PerformClick();
}
final PerformClick performClick = mPerformClick;
performClick.mClickMotionPosition = motionPosition;
performClick.rememberWindowAttachCount();
if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
final Handler handlerTouch = getHandler();
if (handlerTouch != null) {
handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
}
if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) {
mTouchMode = TOUCH_MODE_TAP;
layoutChildren(mDataChanged);
child.setPressed(true);
positionSelector(mMotionPosition, child);
setPressed(true);
if (mSelector != null) {
Drawable d = mSelector.getCurrent();
if (d != null && d instanceof TransitionDrawable) {
((TransitionDrawable) d).resetTransition();
}
}
if (mTouchModeReset != null) {
removeCallbacks(mTouchModeReset);
}
mTouchModeReset = new Runnable() {
@Override
public void run() {
mTouchMode = TOUCH_MODE_REST;
child.setPressed(false);
setPressed(false);
if (!mDataChanged) {
performClick.run();
}
}
};
postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());
} else {
mTouchMode = TOUCH_MODE_REST;
}
return true;
} else if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) {
performClick.run();
}
}
mTouchMode = TOUCH_MODE_REST;
}
mBeginClick = false;
updateSelectorState();
}
break;
}
return true;
}
use of android.graphics.drawable.TransitionDrawable in project AndroidDynamicLoader by mmin18.
the class ImageWorker method setImageDrawable.
/**
* Called when the processing is complete and the final drawable should be
* set on the ImageView.
*
* @param imageView
* @param drawable
*/
private void setImageDrawable(ImageView imageView, Drawable drawable) {
if (mFadeInBitmap) {
// Transition drawable with a transparent drawable and the final drawable
final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
// Set background to loading bitmap
imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));
imageView.setImageDrawable(td);
td.startTransition(FADE_IN_TIME);
} else {
imageView.setImageDrawable(drawable);
}
}
use of android.graphics.drawable.TransitionDrawable in project androidquery by androidquery.
the class BitmapAjaxCallback method setBmAnimate.
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source) {
bm = filter(iv, bm, fallback);
if (bm == null) {
iv.setImageBitmap(null);
return;
}
Drawable d = makeDrawable(iv, bm, ratio, anchor);
Animation anim = null;
if (fadeIn(animation, source)) {
if (preset == null) {
anim = new AlphaAnimation(0, 1);
anim.setInterpolator(new DecelerateInterpolator());
anim.setDuration(FADE_DUR);
} else {
Drawable pd = makeDrawable(iv, preset, ratio, anchor);
Drawable[] ds = new Drawable[] { pd, d };
TransitionDrawable td = new TransitionDrawable(ds);
td.setCrossFadeEnabled(true);
td.startTransition(FADE_DUR);
d = td;
}
} else if (animation > 0) {
anim = AnimationUtils.loadAnimation(iv.getContext(), animation);
}
iv.setImageDrawable(d);
if (anim != null) {
anim.setStartTime(AnimationUtils.currentAnimationTimeMillis());
iv.startAnimation(anim);
} else {
iv.setAnimation(null);
}
}
use of android.graphics.drawable.TransitionDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.
the class RentalsStyleFragment method createView.
@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_materail_style, null);
setHeaderTitle(R.string.ptr_demo_rentals_style);
final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
// header
final RentalsSunHeaderView header = new RentalsSunHeaderView(getContext());
header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
header.setUp(frame);
frame.setLoadingMinTime(1000);
frame.setDurationToCloseHeader(1500);
frame.setHeaderView(header);
frame.addPtrUIHandler(header);
// frame.setPullToRefresh(true);
frame.postDelayed(new Runnable() {
@Override
public void run() {
frame.autoRefresh(true);
}
}, 100);
frame.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
return true;
}
@Override
public void onRefreshBegin(final PtrFrameLayout frame) {
if (mImageHasLoaded) {
long delay = 1500;
frame.postDelayed(new Runnable() {
@Override
public void run() {
frame.refreshComplete();
}
}, delay);
} else {
mStartLoadingTime = System.currentTimeMillis();
imageView.loadImage(imageLoader, mUrl);
}
}
});
ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {
@Override
public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
}
@Override
public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
mImageHasLoaded = true;
long delay = 1500;
frame.postDelayed(new Runnable() {
@Override
public void run() {
if (cubeImageView != null && bitmapDrawable != null) {
TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
imageView.setImageDrawable(w1);
w1.startTransition(200);
}
frame.refreshComplete();
}
}, delay);
}
@Override
public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
}
};
imageLoader.setImageLoadHandler(imageLoadHandler);
return view;
}
use of android.graphics.drawable.TransitionDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.
the class MaterialStyleFragment method createView.
@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_materail_style, null);
setHeaderTitle(R.string.ptr_demo_material_style);
final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
// header
final MaterialHeader header = new MaterialHeader(getContext());
int[] colors = getResources().getIntArray(R.array.google_colors);
header.setColorSchemeColors(colors);
header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
header.setPtrFrameLayout(mPtrFrameLayout);
mPtrFrameLayout.setLoadingMinTime(1000);
mPtrFrameLayout.setDurationToCloseHeader(1500);
mPtrFrameLayout.setHeaderView(header);
mPtrFrameLayout.addPtrUIHandler(header);
mPtrFrameLayout.postDelayed(new Runnable() {
@Override
public void run() {
mPtrFrameLayout.autoRefresh(false);
}
}, 100);
mPtrFrameLayout.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
return true;
}
@Override
public void onRefreshBegin(final PtrFrameLayout frame) {
if (mImageHasLoaded) {
long delay = (long) (1000 + Math.random() * 2000);
delay = Math.max(0, delay);
delay = 0;
frame.postDelayed(new Runnable() {
@Override
public void run() {
frame.refreshComplete();
}
}, delay);
} else {
mStartLoadingTime = System.currentTimeMillis();
imageView.loadImage(imageLoader, mUrl);
}
}
});
ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {
@Override
public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
}
@Override
public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
mImageHasLoaded = true;
long delay = Math.max(0, 1000 - (System.currentTimeMillis() - mStartLoadingTime));
delay = 0;
mPtrFrameLayout.postDelayed(new Runnable() {
@Override
public void run() {
if (cubeImageView != null && bitmapDrawable != null) {
TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
imageView.setImageDrawable(w1);
w1.startTransition(200);
}
mPtrFrameLayout.refreshComplete();
}
}, delay);
}
@Override
public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
}
};
imageLoader.setImageLoadHandler(imageLoadHandler);
return view;
}
Aggregations