Example usage for android.widget ImageView invalidate

List of usage examples for android.widget ImageView invalidate

Introduction

In this page you can find the example usage for android.widget ImageView invalidate.

Prototype

public void invalidate() 

Source Link

Document

Invalidate the whole view.

Usage

From source file:org.catnut.adapter.TweetAdapter.java

private void injectThumbs(final Context context, final String originUri, String mediumThumbUrl,
        String smallThumbUrl, final ImageView thumbs) {
    switch (mThumbsOption) {
    case SMALL:/*from   w w  w .j a v a  2 s .c o m*/
    case MEDIUM:
        if (!TextUtils.isEmpty(originUri)) {
            if (mStayInLatest) { // not in offline mode
                RequestCreator creator;
                if (mThumbsOption == ThumbsOption.MEDIUM) {
                    creator = Picasso.with(context).load(mediumThumbUrl).centerCrop().resize(mScreenWidth,
                            (int) (mScreenWidth * Constants.GOLDEN_RATIO));
                } else {
                    creator = Picasso.with(context).load(smallThumbUrl);
                }
                creator.placeholder(android.R.drawable.ic_menu_report_image).error(R.drawable.error)
                        .into(thumbs);
                thumbs.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        return CatnutUtils.imageOverlay(v, event);
                    }
                });
                thumbs.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        thumbs.getDrawable().clearColorFilter();
                        thumbs.invalidate();
                        Intent intent = SingleFragmentActivity.getIntent(context,
                                SingleFragmentActivity.PHOTO_VIEWER);
                        intent.putExtra(Constants.PIC, originUri);
                        mContext.startActivity(intent);
                    }
                });
            } else {
                // sometimes, the user may read timeline in offline mode(may opening the 2/3g),
                // so, don' t load the image
                // todo, may be we need to check it in cache or place the network unavailable image?
                thumbs.setImageResource(android.R.drawable.ic_menu_report_image);
            }
            thumbs.setVisibility(View.VISIBLE);
            break;
        }
        // otherwise, fall through...
    case NONE:
    case ORIGINAL:
    default:
        thumbs.setVisibility(View.GONE);
        break;
    }
}

From source file:com.cloverstudio.spika.CameraCropActivity.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);//  w w  w.j  ava 2 s .  com
        start.set(event.getX(), event.getY());
        mode = DRAG;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
            // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
            start_x = event.getX() - start.x;
            start_y = event.getY() - start.y;
        } else if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > 10f) {
                matrix.set(savedMatrix);
                float scale = newDist / oldDist;
                mAspect = scale;
                matrix.postScale(scale, scale, mid.x, mid.y);
            }
        }
        break;
    }

    view.setImageMatrix(matrix);
    view.invalidate();
    return true;
}