Java Code Examples for android.widget.ImageView#getContext()

The following examples show how to use android.widget.ImageView#getContext() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: imsdk-android   File: PhotoViewAttacher.java    License: MIT License 6 votes vote down vote up
@Override
public void onFling(float startX, float startY, float velocityX,
                    float velocityY) {
    if(Math.abs(velocityX) > Math.abs(velocityY)){
        return;
    }
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView),
            getImageViewHeight(imageView), (int) velocityX, (int) velocityY);
    imageView.post(mCurrentFlingRunnable);
    if(velocityY > 5000){
        if(mOnFlingListener != null)
            mOnFlingListener.onFlingExit(getImageView(), velocityX, velocityY);
    }
}
 
Example 2
Source Project: CrazyDaily   File: WXImageAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy) {

    if (TextUtils.isEmpty(url)) {
        return;
    }
    final Context context = view.getContext();

    if (url.startsWith("mipmap://")) {
        String resIdStr = getResIdStr(url);
        if (TextUtils.isEmpty(resIdStr)) {
            return;
        }
        int imgId = context.getResources().getIdentifier(resIdStr, "mipmap", context.getPackageName());
        view.setImageResource(imgId);
        return;
    }
    ImageLoader.load(context, url, view);
}
 
Example 3
Source Project: QuickReturn   File: TwitterAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void setUpUserImage(ImageView iv, Tweet tweet) {
        Context context = iv.getContext();
        String avatarUrl = tweet.getAvatarUrl();
        if (!TextUtils.isEmpty(avatarUrl)) {
            Picasso.with(context)
                    .load(avatarUrl)
                    .centerCrop()
                    .resize(QuickReturnUtils.dp2px(context, 50),
                            QuickReturnUtils.dp2px(context, 50))
//                    .placeholder(R.drawable.ic_facebook)
                    .error(android.R.drawable.stat_notify_error)
                    .into(iv);
        }
    }
 
Example 4
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

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

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

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

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

    mGestureDetector.setOnDoubleTapListener(this);

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 5
Source Project: MultiView   File: ImageViewScaler.java    License: Apache License 2.0 5 votes vote down vote up
public ImageViewScaler(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

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

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

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

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

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 6
@Override
public void onFling(float startX, float startY, float velocityX,
                    float velocityY) {
    if (DEBUG) {
        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);
}
 
Example 7
Source Project: Aurora   File: AuthorVideosAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, VideoListInfo.Video item) {
    helper.setText(R.id.tv_title,item.getData().getTitle())
            .setText(R.id.tv_type,getDetailStr(item));
    ImageView img = helper.getView(R.id.iv_left);
    AppComponent mAppComponent = ((App)img.getContext().getApplicationContext())
            .getAppComponent();
    Context context = img.getContext();
    mAppComponent.imageLoader().loadImage(context,
            ImageConfigImpl
                    .builder()
                    .url(item.getData().getCover().getFeed())
                    .imageView(img)
                    .build());
}
 
Example 8
Source Project: Album   File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
    ImageView imageView = getImageView();
    mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
    mCurrentFlingRunnable.fling(getImageViewWidth(imageView), getImageViewHeight(imageView), (int)velocityX,
        (int)velocityY);
    imageView.post(mCurrentFlingRunnable);
}
 
Example 9
@Override
public void onFling(float startX, float startY, float velocityX, float velocityY) {
 if (DEBUG) {
  Log.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);
}
 
Example 10
Source Project: QuickReturn   File: FacebookAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void setUpPostImage(ImageView iv, FacebookPost post) {
        Context context = iv.getContext();
        String postImageUrl = post.getPostImageUrl();
        if (!TextUtils.isEmpty(postImageUrl)) {
            Picasso.with(context)
                    .load(postImageUrl)
//                    .placeholder(R.drawable.ic_facebook)
                    .centerCrop()
                    .resize(QuickReturnUtils.dp2px(context, 346),
                            QuickReturnUtils.dp2px(context, 320))
                    .error(android.R.drawable.stat_notify_error)
                    .into(iv);
        }
    }
 
Example 11
Source Project: zen4android   File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

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

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

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

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

    mGestureDetector.setOnDoubleTapListener(this);

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 12
@Override
public final void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {
        Log.d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }

    ImageView imageView = getImageView();
    if (hasDrawable(imageView)) {
        mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
        mCurrentFlingRunnable.fling(imageView.getWidth(), imageView.getHeight(), (int) velocityX, (int) velocityY);
        imageView.post(mCurrentFlingRunnable);
    }
}
 
Example 13
Source Project: PicturePicker   File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {
        Log.d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }

    ImageView imageView = getImageView();
    if (hasDrawable(imageView)) {
        mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
        mCurrentFlingRunnable.fling(imageView.getWidth(), imageView.getHeight(), (int) velocityX, (int) velocityY);
        imageView.post(mCurrentFlingRunnable);
    }
}
 
Example 14
Source Project: Tweetin   File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

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

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

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

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

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 15
@BindingAdapter("imageUrl")
public static void setImageUrl(ImageView imageView, String url) {
    Context context = imageView.getContext();
    Glide.with(context).load(url).into(imageView);
}
 
Example 16
Source Project: Aurora   File: CacheAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
    protected void convert(BaseViewHolder helper, VideoDownLoadInfo item) {
        AppComponent mAppComponent = ((App)helper.getView(R.id.iv_bg).getContext().getApplicationContext())
                .getAppComponent();
        ImageView imgMian = helper.getView(R.id.iv_bg);
        Context context = imgMian.getContext();
        helper.setText(R.id.tv_title,item.getVideo().getTitle());
        if (item.getVideo().getAuthor()!=null){
            helper.setText(R.id.tv_author,item.getVideo().getAuthor().getName());
        }
        helper.setText(R.id.tv_size, StringUtils.getPrintSize(item.getContentLength() == null ?0:item.getContentLength(),true));
        helper.addOnClickListener(R.id.iv_more);
        helper.addOnClickListener(R.id.ll_detail);
        helper.addOnClickListener(R.id.ll_progress);
        helper.addOnClickListener(R.id.ctl_layout);
        if (!type.contains("正在")){
            helper.getView(R.id.ll_detail).setVisibility(View.VISIBLE);
        }else {
            helper.getView(R.id.ll_detail).setVisibility(View.GONE);
        }
        if (item.getFinish()){
            helper.getView(R.id.ll_progress).setVisibility(View.GONE);
            helper.getView(R.id.tv_size).setVisibility(View.VISIBLE);
        }else {
            helper.getView(R.id.tv_size).setVisibility(View.GONE);
//            if (downPosition == helper.getLayoutPosition()){
//                helper.getView(R.id.ll_progress).setVisibility(View.VISIBLE);
//                helper.getView(R.id.sb_progress).setVisibility(View.VISIBLE);
//                ((SeekBar)helper.getView(R.id.sb_progress)).setProgress(item.getPercent());
//                String size = StringUtils.getPrintSize(item.getCurrentBytes() == null ?0:item.getContentLength(),false) + "/" + StringUtils.getPrintSize(item.getContentLength() == null ?0:item.getContentLength(),true);
//                helper.setText(R.id.tv_pause,size);
//            }else {
            if (item.isPending()){
                helper.setText(R.id.tv_pause,"正在连接中...");
                ((ProgressBar)helper.getView(R.id.sb_progress)).setIndeterminate(true);
                helper.getView(R.id.ll_progress).setVisibility(View.VISIBLE);
                helper.getView(R.id.sb_progress).setVisibility(View.VISIBLE);
            }else {
                if (item.isLineUp()){
                    helper.setText(R.id.tv_pause,"排队中");
                }else {
                    helper.setText(R.id.tv_pause,"已暂停");
                }
                helper.getView(R.id.ll_progress).setVisibility(View.VISIBLE);
                helper.getView(R.id.sb_progress).setVisibility(View.GONE);
            }

//            }
        }
        mAppComponent.imageLoader().loadImage(context,
                ImageConfigImpl
                        .builder()
                        .url(item.getVideo().getCover().getFeed())
                        .imageView(imgMian)
                        .build());
    }
 
Example 17
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

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

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

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

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

                @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;
                }
            });
    //modify by ChenSiLiang
    setRotateGestureDetector();

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 18
@Override
public Object instantiateItem(ViewGroup container, int position) {
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.fullscreen_image, null);

    ImageView imageView = (ImageView) view.findViewById(R.id.iv);
    final LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ll);

    String image = images.get(position);

    Context context = imageView.getContext();
    int width = DisplayUtility.getScreenWidth(context);

    fullScreenImageLoader.loadFullScreenImage(imageView, image, width, linearLayout);

    container.addView(view, 0);

    return view;
}
 
Example 19
Source Project: Android   File: PhotoViewAttacher.java    License: MIT License 4 votes vote down vote up
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

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

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

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

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

                @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 DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 20
Source Project: Learning-Resources   File: DataBinder.java    License: MIT License 4 votes vote down vote up
@BindingAdapter("imageUrl")
public static void setImageUrl(ImageView imageView, String url) {
    Context context = imageView.getContext();
    Picasso.with(context).load(url).into(imageView);
}