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

The following examples show how to use android.widget.ImageView#getTag() . 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 check out the related API usage on the sidebar.
Example 1
Source File: ImageDownloader.java    From letv with Apache License 2.0 7 votes vote down vote up
static void setBitmapForView(View view, Bitmap bitmap, String url, boolean doAnim) {
    if (view != null && bitmap != null && !TextUtils.isEmpty(url) && !bitmap.isRecycled() && view.getTag(R.id.view_tag) != null && view.getTag(R.id.view_tag).toString().equals(url)) {
        view.setTag(R.id.view_result, Boolean.valueOf(true));
        if (view instanceof ImageView) {
            ImageView imageView = (ImageView) view;
            if (imageView.getTag(R.id.imageview_atts) == null || !imageView.getTag(R.id.imageview_atts).toString().contains("background")) {
                if (imageView.getTag(R.id.scale_type) instanceof ScaleType) {
                    imageView.setScaleType((ScaleType) imageView.getTag(R.id.scale_type));
                } else {
                    imageView.setScaleType(ScaleType.FIT_XY);
                }
                imageView.setImageBitmap(bitmap);
            } else {
                view.setBackgroundDrawable(new BitmapDrawable(bitmap));
            }
        } else {
            view.setBackgroundDrawable(new BitmapDrawable(bitmap));
        }
        if (doAnim) {
            view.startAnimation(AnimationUtils.loadAnimation(BaseApplication.getInstance(), R.anim.fade_in));
        }
    }
}
 
Example 2
Source File: ImageWorker.java    From bither-bitmap-sample with Apache License 2.0 6 votes vote down vote up
@Override
protected void onProgressUpdate(Object... values) {
    if (!isCancelled()) {
        if (imageViewReference != null && values != null
                && values.length > 0) {
            ImageView imageView = imageViewReference.get();
            if (imageView != null
                    && imageView.getTag() != null
                    && (imageView.getTag() instanceof FileDowloadProgressListener)) {
                FileDowloadProgressListener imageProgressListener = (FileDowloadProgressListener) imageView
                        .getTag();
                if (values[0] instanceof FileDowloadProgressListener.ProgressValue) {
                    FileDowloadProgressListener.ProgressValue v = (FileDowloadProgressListener.ProgressValue) values[0];
                    if (v.getDownloadType() == FileDowloadProgressListener.DownloadType.ERROR) {
                        imageView.setImageDrawable(null);
                    }
                    imageProgressListener.onProgress(v);
                }
            }
        }
    }
    super.onProgressUpdate(values);
}
 
Example 3
Source File: AdapterImageLoaderListener.java    From WeGit with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
    if (loadedImage != null) {
        ImageView imageView = (ImageView) view;
        String viewTag = (String)imageView.getTag();
        if(!TextUtils.isEmpty(viewTag)) {
            if(viewTag.equals(imageUri)) {
                 ((ImageView) view).setImageBitmap(loadedImage);
                Log.i(TAG, "hit tag");
            } else{
                Log.i(TAG, "miss tag");
            }
        } else {
            Log.i(TAG, "have not tag");
            ((ImageView) view).setImageBitmap(loadedImage);
        }
    }
}
 
Example 4
Source File: BannerView.java    From Tangram-Android with MIT License 6 votes vote down vote up
public void setCurrItem(int position) {
    if (mImageViews != null) {
        for (int i = 0; i < mImageViews.length; i++) {
            if (style == STYLE_DOT) {
                mImageViews[i].setImageDrawable(getGradientDrawable(position == i ? focusColor : norColor, radius));
            } else if (style == STYLE_IMG) {
                ImageView imageView = mImageViews[i];
                if (imageView.getTag(R.id.TANGRAM_BANNER_INDICATOR_POS) == null) {
                    continue;
                } else {
                    imageView.setTag(R.id.TANGRAM_BANNER_INDICATOR_POS, null);
                    ImageUtils.doLoadImageUrl(imageView, norUrl);
                }
            }
        }
        mImageViews[currentItemPos].setTag(R.id.TANGRAM_BANNER_INDICATOR_POS, currentItemPos);
        if (style == STYLE_IMG) {
            ImageUtils.doLoadImageUrl(mImageViews[currentItemPos], focusUrl);
        }
    }
}
 
Example 5
Source File: RawDataDiceView.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public void deleteLast() {
    int size = data.size();
    if (size <= 0) {
        return;
    }
    data.remove(size - 1);
    final ImageView iv = (ImageView) ((FrameLayout) getChildAt(size - 1)).getChildAt(0);
    if (iv.getVisibility() == View.VISIBLE) {
        ScaleAnimation anim = new ScaleAnimation(1, 0, 1, 0, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        anim.setDuration(300);
        anim.setFillAfter(true);
        iv.startAnimation(anim);
        if (iv.getTag() != null && iv.getTag() instanceof HideIvRunnable) {
            iv.removeCallbacks((Runnable) iv.getTag());
        }
        HideIvRunnable r = new HideIvRunnable(iv);
        iv.setTag(r);
        iv.postDelayed(r, 300);
    }
}
 
Example 6
Source File: ImageWorker.java    From bither-bitmap-sample with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCancelled(Bitmap bitmap) {
    if (imageViewReference != null) {//
        ImageView imageView = imageViewReference.get();
        if (imageView != null
                && imageView.getTag() != null
                && (imageView.getTag() instanceof FileDowloadProgressListener)) {
            FileDowloadProgressListener imageProgressListener = (FileDowloadProgressListener) imageView
                    .getTag();
            imageProgressListener.onCancel();
        }
    }
    super.onCancelled(bitmap);
    synchronized (mPauseWorkLock) {
        mPauseWorkLock.notifyAll();
    }
}
 
Example 7
Source File: ImageLoader.java    From AntennaPodSP with MIT License 6 votes vote down vote up
/**
 * Load a bitmap from the thumbnail cache. If the bitmap is not in the
 * cache, it will be loaded from the disk. This method should either be
 * called if the ImageView's size has already been set or inside a Runnable
 * which is posted to the ImageView's message queue.
 */
public void loadThumbnailBitmap(ImageWorkerTaskResource source,
                                ImageView target, int length) {
    final int defaultCoverResource = getDefaultCoverResource(target
            .getContext());
    final String cacheKey;
    if (source != null && (cacheKey = source.getImageLoaderCacheKey()) != null) {
        final Object currentTag = target.getTag(R.id.imageloader_key);
        if (currentTag == null || !cacheKey.equals(currentTag)) {
            target.setTag(R.id.imageloader_key, cacheKey);
            CachedBitmap cBitmap = getBitmapFromThumbnailCache(cacheKey);
            if (cBitmap != null && cBitmap.getLength() >= length) {
                target.setImageBitmap(cBitmap.getBitmap());
            } else {
                target.setImageResource(defaultCoverResource);
                BitmapDecodeWorkerTask worker = new BitmapDecodeWorkerTask(
                        handler, target, source, length, IMAGE_TYPE_THUMBNAIL);
                executor.submit(worker);
            }
        }
    } else {
        target.setImageResource(defaultCoverResource);
    }
}
 
Example 8
Source File: PhotoUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the image view bitmap loader.
 * 
 * @param imageView the image view
 */
public static BitmapLoader getBitmapLoader(ImageView imageView) {
  if (imageView != null) {
    Object object = imageView.getTag();
    if (object instanceof WeakReference<?>) {
      @SuppressWarnings("unchecked")
      WeakReference<BitmapLoader> bitmapLoaderReference = (WeakReference<BitmapLoader>) object;
      return bitmapLoaderReference.get();
    }
  }
  return null;
}
 
Example 9
Source File: ImageLoader.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public ImageContainer get(String requestUrl, ImageView imageView, Drawable placeHolder, int maxWidth, int maxHeight) {

        // Find any old image load request pending on this ImageView (in case this view was
        // recycled)
        ImageContainer imageContainer = imageView.getTag() != null && imageView.getTag() instanceof ImageContainer ? (ImageContainer) imageView.getTag() : null;

        // Find image url from prior request
        String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

        // If the new requestUrl is null or the new requestUrl is different to the previous
        // recycled requestUrl
        if (requestUrl == null || !requestUrl.equals(recycledImageUrl)) {
            if (imageContainer != null) {
                // Cancel previous image request
                imageContainer.cancelRequest();
                imageView.setTag(null);
            }
            if (requestUrl != null) {
                // Queue new request to fetch image
                imageContainer = get(requestUrl, getImageListener(mResources, imageView, placeHolder, mFadeInImage), maxWidth, maxHeight);
                // Store request in ImageView tag
                imageView.setTag(imageContainer);
            } else {
                imageView.setImageDrawable(placeHolder);
                imageView.setTag(null);
            }
        }

        return imageContainer;
    }
 
Example 10
Source File: FantasyFallAdapter.java    From catnut with MIT License 5 votes vote down vote up
@Override
public void bindView(View view, final Context context, Cursor cursor) {
	final ImageView imageView = (ImageView) view;
	ViewHolder holder = (ViewHolder) imageView.getTag();
	int width = cursor.getInt(holder.widthIndex);
	int height = cursor.getInt(holder.heightIndex);
	final String url = cursor.getString(cursor.getColumnIndex(Photo.image_url));

	if (width == 0 || height == 0) { // fall back, if width or height not provide
		width = (int) mFactor;
		height = (int) (Constants.GOLDEN_RATIO * width);
	} else {
		height = (int) (mFactor * height / width);
	}

	Picasso.with(context)
			.load(url)
			.placeholder(mColors[((int) (Math.random() * N))])
			.resize((int) mFactor, height)
			.into(imageView);

	final String name = cursor.getString(holder.nameIndex);
	view.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			// clear
			imageView.getDrawable().clearColorFilter();
			imageView.invalidate();
			// intent
			Intent intent = new Intent(context, HelloActivity.class);
			intent.setAction(HelloActivity.ACTION_FROM_GRID);
			intent.putExtra(Photo.image_url, url);
			intent.putExtra(Photo.name, name);
			context.startActivity(intent);
		}
	});
}
 
Example 11
Source File: UTilitiesActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
/**
 * Reset the checkmark overlays that act as temp login indicators to
 * ensure they show the correct login status.
 */
private void resetChecks() {
    boolean persistentLoginEnabled = settings.getBoolean(getString(R.string.pref_logintype_key), false);
    for (ImageView featureButton : featureButtons) {
        DashboardButtonData button = (DashboardButtonData) featureButton.getTag();
        if (button.authCookie != null) {
            button.checkOverlay.setVisibility(persistentLoginEnabled ? View.GONE : View.VISIBLE);
            if (button.authCookie.hasCookieBeenSet()) {
                button.checkOverlay.setAlpha(1f);
            } else {
                button.checkOverlay.setAlpha(CHECK_TRANSLUCENT_OPACITY);
            }
        }
    }
}
 
Example 12
Source File: ThumbnailManager.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
public void loadMediaThumbnail(final BoxItem item, final ImageView targetImage) {
    if (targetImage.getTag() == null){
        ViewData data = new ViewData(TYPE_MEDIA, null);
        targetImage.setTag(data);
    }
    loadThumbnail(item, targetImage);
}
 
Example 13
Source File: ImageLoader.java    From android_tv_metro with Apache License 2.0 5 votes vote down vote up
/**
 * The default implementation of ImageListener which handles basic functionality
 * of showing a default image until the network response is received, at which point
 * it will switch to either the actual image or the error image.
 * @param view The imageView that the listener is associated with.
 * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist.
 * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist.
 */
public static ImageListener getImageListener(final ImageView view,
        final int defaultImageResId, final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null ) {
                Object tag = view.getTag();
                if(tag != null && tag instanceof String){
                    String baseURL = (String) tag;
                    if(baseURL.equals(response.getRequestUrl())){
                        view.setImageBitmap(response.getBitmap());
                    }
                }else {
                    view.setImageBitmap(response.getBitmap());
                }
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    };
}
 
Example 14
Source File: ImagePickerFactory.java    From android-json-form-wizard with MIT License 5 votes vote down vote up
public static ValidationStatus validate(ImageView imageView) {
    if (!(imageView.getTag(R.id.v_required) instanceof String) || !(imageView.getTag(R.id.error) instanceof String)) {
        return new ValidationStatus(true, null);
    }
    Boolean isRequired = Boolean.valueOf((String) imageView.getTag(R.id.v_required));
    if (!isRequired) {
        return new ValidationStatus(true, null);
    }
    Object path = imageView.getTag(R.id.imagePath);
    if (path instanceof String && !TextUtils.isEmpty((String) path)) {
        return new ValidationStatus(true, null);
    }
    return new ValidationStatus(false, (String) imageView.getTag(R.id.error));
}
 
Example 15
Source File: PairingActivity.java    From microbit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a clicked cell on/off.
 *
 * @param image An image of a clicked cell.
 * @param pos   Position of a clicked cell.
 * @return True, if cell is on and false otherwise.
 */
private boolean toggleLED(ImageView image, int pos) {
    boolean isOn;
    //Toast.makeText(this, "Pos :" +  pos, Toast.LENGTH_SHORT).show();
    int state = (Integer) image.getTag(R.id.ledState);
    if(state != 1) {
        DEVICE_CODE_ARRAY[pos] = 1;
        image.setBackground(getApplication().getResources().getDrawable(R.drawable.red_white_led_btn));
        image.setTag(R.id.ledState, 1);
        isOn = true;

    } else {
        DEVICE_CODE_ARRAY[pos] = 0;
        image.setBackground(getApplication().getResources().getDrawable(R.drawable.white_red_led_btn));
        image.setTag(R.id.ledState, 0);
        isOn = false;
        // Update the code to consider the still ON LED below the toggled one
        if(pos < 20) {
            DEVICE_CODE_ARRAY[pos + 5] = 1;
        }
    }

    image.setSelected(false);
    int position = (Integer) image.getTag(R.id.position);
    image.setContentDescription("" + position + getLEDStatus(pos));
    return isOn;
}
 
Example 16
Source File: UTilitiesActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
/**
 * Log the user out of all UT web services.
 */
private void logout() {
    app.logoutAll();
    for (ImageView ib : featureButtons) {
        enableFeature(ib);
        if (((DashboardButtonData) ib.getTag()).loginProgress != null) {
            ((DashboardButtonData) ib.getTag()).loginProgress.setVisibility(View.GONE);
        }
    }
    loginFailed = false;
    resetChecks();
}
 
Example 17
Source File: ContactsAsyncHelper.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isAlreadyProcessed(ImageView imageView, Uri uri) {
    if(imageView != null) {
        PhotoViewTag vt = (PhotoViewTag) imageView.getTag(TAG_PHOTO_INFOS);
        return (vt != null && UriUtils.areEqual(uri, vt.uri));
    }
    return true;
}
 
Example 18
Source File: ThumbnailManager.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
static ImageLoadListener getImageLoadListener(ImageView view) {
    if(view != null) {
        ViewData data = (ViewData) view.getTag();
        if(data != null && data.mListener != null) {
            return data.mListener;
        }
    }
    return NULL_LISTENER;
}
 
Example 19
Source File: FirebaseStorageHelper.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
private static void loadImageFromCacheFile(ImageView imageView, File file, String tag) {
    if (!(imageView.getTag() instanceof String)) return;
    if (!imageView.getTag().equals(tag)) return;

    try {
        FileInputStream fis = new FileInputStream(file);
        Bitmap bitmap = BitmapFactory.decodeStream(fis);
        imageView.setImageBitmap(bitmap);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 20
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
private void requestForImageView(ImageView imageView,final SingleConfig config) {

           /* config.setBitmapListener(new SingleConfig.BitmapListener() {
                @Override
                public void onSuccess(Bitmap bitmap) {
                    imageView.setImageBitmap(bitmap);
                }

                @Override
                public void onFail(Throwable e) {
                    if(config.getErrorResId() >0){
                        imageView.setImageResource(config.getErrorResId());
                    }
                }
            });
            requestBitmap(config);
            return;*/
           checkWrapContentOrMatchParent(config);


        //GenericDraweeHierarchy hierarchy=null;
        GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder.newInstance(imageView.getContext().getResources()).build();
        setupHierarchy(hierarchy,config);

        // 数据-model
        ImageRequest request = buildRequest(config);

        //设置controller

        DraweeHolder draweeHolder= (DraweeHolder) imageView.getTag(R.id.fresco_drawee);


        PipelineDraweeControllerBuilder controllerBuilder = buildPipelineDraweeController(config,request);


        if (draweeHolder == null) {
            draweeHolder=DraweeHolder.create(hierarchy,imageView.getContext());
        }else {
             controllerBuilder.setOldController(draweeHolder.getController());
            draweeHolder.setHierarchy(hierarchy);
        }

        draweeHolder.setController(controllerBuilder.build());


        //imageview的特殊处理
        ViewStatesListener mStatesListener=new ViewStatesListener(draweeHolder);

        imageView.addOnAttachStateChangeListener(mStatesListener);

        // 判断是否ImageView已经 attachToWindow
        if (ViewCompat.isAttachedToWindow(imageView)) {
            draweeHolder.onAttach();
        }

        //设置scaletype
        //setImageViewScaleType(imageView,config);


//        if (ViewC.isAttachedToWindow()) {
//            draweeHolder.onAttach();
//        }
        // 保证每一个ImageView中只存在一个draweeHolder
        imageView.setTag(R.id.fresco_drawee,draweeHolder);
        // 拿到数据
        imageView.setImageDrawable(draweeHolder.getTopLevelDrawable());


    }