Example usage for android.widget ImageView getContext

List of usage examples for android.widget ImageView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:com.example.g40_70m.framedemo.view.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {/*from   w w w  .ja va 2  s. co  m*/
        L.w("onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.github.chrisbanes.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/*w ww .ja va2 s .  co  m*/
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            final float x = e.getX(), y = e.getY();

            if (mViewTapListener != null) {
                mViewTapListener.onViewTap(mImageView, x, y);
            }

            if (displayRect != null) {

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:com.org.lengend.photoview.library.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    Logger.d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/*from  ww w .  j  av  a  2 s  . c  o m*/
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), onGestureListener);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            final float x = e.getX(), y = e.getY();

            if (mViewTapListener != null) {
                mViewTapListener.onViewTap(mImageView, x, y);
            }

            if (displayRect != null) {

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:im.neon.util.VectorUtils.java

/**
 * Set the user avatar in an imageView.//from   ww  w. ja  v a  2  s . c  o m
 *
 * @param context     the context
 * @param session     the session
 * @param imageView   the image view
 * @param avatarUrl   the avatar url
 * @param userId      the user id
 * @param displayName the user display name
 */
public static void loadUserAvatar(final Context context, final MXSession session, final ImageView imageView,
        final String avatarUrl, final String userId, final String displayName) {
    // sanity check
    if ((null == session) || (null == imageView) || !session.isAlive()) {
        return;
    }

    // reset the imageView tag
    imageView.setTag(null);

    if (session.getMediasCache().isAvatarThumbnailCached(avatarUrl,
            context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size))) {
        session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView, avatarUrl,
                context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size));
    } else {
        if (null == mImagesThread) {
            mImagesThread = new HandlerThread("ImagesThread", Thread.MIN_PRIORITY);
            mImagesThread.start();
            mImagesThreadHandler = new android.os.Handler(mImagesThread.getLooper());
            mUIHandler = new Handler(Looper.getMainLooper());
        }

        final Bitmap bitmap = VectorUtils.getAvatar(imageView.getContext(), VectorUtils.getAvatarColor(userId),
                TextUtils.isEmpty(displayName) ? userId : displayName, false);

        // test if the default avatar has been computed
        if (null != bitmap) {
            imageView.setImageBitmap(bitmap);

            final String tag = avatarUrl + userId + displayName;
            imageView.setTag(tag);

            if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) {
                mImagesThreadHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (TextUtils.equals(tag, (String) imageView.getTag())) {
                            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(),
                                    imageView, avatarUrl,
                                    context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size),
                                    bitmap);
                        }
                    }
                });
            }
        } else {
            final String tmpTag0 = "00" + avatarUrl + "-" + userId + "--" + displayName;
            imageView.setTag(tmpTag0);

            // create the default avatar in the background thread
            mImagesThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (TextUtils.equals(tmpTag0, (String) imageView.getTag())) {
                        imageView.setTag(null);
                        setDefaultMemberAvatar(imageView, userId, displayName);

                        if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) {
                            final String tmpTag1 = "11" + avatarUrl + "-" + userId + "--" + displayName;
                            imageView.setTag(tmpTag1);

                            // wait that it is rendered to load the right one
                            mUIHandler.post(new Runnable() {
                                @Override
                                public void run() {
                                    // test if the imageView tag has not been updated
                                    if (TextUtils.equals(tmpTag1, (String) imageView.getTag())) {
                                        final String tmptag2 = "22" + avatarUrl + userId + displayName;
                                        imageView.setTag(tmptag2);

                                        mImagesThreadHandler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                // test if the imageView tag has not been updated
                                                if (TextUtils.equals(tmptag2, (String) imageView.getTag())) {
                                                    final Bitmap bitmap = VectorUtils.getAvatar(
                                                            imageView.getContext(),
                                                            VectorUtils.getAvatarColor(userId),
                                                            TextUtils.isEmpty(displayName) ? userId
                                                                    : displayName,
                                                            false);
                                                    session.getMediasCache().loadAvatarThumbnail(
                                                            session.getHomeserverConfig(), imageView, avatarUrl,
                                                            context.getResources().getDimensionPixelSize(
                                                                    R.dimen.profile_avatar_size),
                                                            bitmap);
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    }
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {//from   w  ww . j  a  v a 2  s  .  c o  m
        LogManager.getLogger().d(LOG_TAG,
                "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int) velocityX,
            (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
}

From source file:kuta.adrian.cv.displayingbitmaps.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.// w  w w.j a va2 s  .  c  o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    try {
        ViewGroup viewGroup = (ViewGroup) imageView.getParent();
        if (viewGroup instanceof FrameLayout) {
            FrameLayout parent = (FrameLayout) viewGroup;
            View view;
            if ((view = parent.getChildAt(0)) instanceof ProgressBar)
                parent.removeView(view);
        }
    } catch (Exception e) {
        Log.e(getClass().getSimpleName(), "onPostExecute, progressBar not found", e);
    }

    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(ContextCompat.getColor(imageView.getContext(), android.R.color.transparent)),
                drawable });
        // Set background to loading bitmap
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
            imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));
        else
            imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

private boolean setIcon(final ImageView iconView, GuidedAction action) {
    Drawable icon = null;/*  w  ww . j  a  va  2s  . c  o  m*/
    if (iconView != null) {
        Context context = iconView.getContext();
        icon = action.getIcon();
        if (icon != null) {
            // setImageDrawable resets the drawable's level unless we set the view level first.
            iconView.setImageLevel(icon.getLevel());
            iconView.setImageDrawable(icon);
            iconView.setVisibility(View.VISIBLE);
        } else {
            iconView.setVisibility(View.GONE);
        }
    }
    return icon != null;
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

@Override
public void async(Context context) {
    String url = getUrl();//from w  w  w . jav a 2s.com
    ImageView v = this.v.get();
    if (url == null) {
        showProgress(false);
        setBitmap(url, v, null, false);
        return;
    }
    Bitmap bm = memGet(url);
    if (bm != null) {
        v.setTag(Constants.TAG_URL, url);
        status = new AjaxStatus().source(AjaxStatus.MEMORY).done();
        callback(url, bm, status);
        return;
    }
    presetBitmap(url, v);
    if (!queueMap.containsKey(url)) {
        addQueue(url, v);
        super.async(v.getContext());
    } else {
        showProgress(true);
        addQueue(url, v);
    }
}

From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
        // Create Gesture Detectors...
        mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

        mGestureDetector = new GestureDetector(imageView.getContext(),
                new GestureDetector.SimpleOnGestureListener() {

                    // forward long click listener
                    @Override/*from   ww  w. j  a v  a 2 s .c  om*/
                    public void onLongPress(MotionEvent e) {
                        if (null != mLongClickListener) {
                            mLongClickListener.onLongClick(mImageView.get());
                        }
                    }
                });

        mGestureDetector.setOnDoubleTapListener(this);

        // Finally, update the UI so that we're zoomable
        setZoomable(true);
    }
}