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

The following examples show how to use android.widget.ImageView#getDrawable() . 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: jmessage-android-uikit   File: DialogCreator.java    License: MIT License 6 votes vote down vote up
public static Dialog createLoadingDialog(Context context, String msg) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(IdHelper.getLayout(context, "jmui_loading_view"), null);
    RelativeLayout layout = (RelativeLayout) v.findViewById(IdHelper.getViewID(context, "jmui_dialog_view"));
    ImageView mLoadImg = (ImageView) v.findViewById(IdHelper.getViewID(context, "jmui_loading_img"));
    TextView mLoadText = (TextView) v.findViewById(IdHelper.getViewID(context, "jmui_loading_txt"));
    AnimationDrawable mDrawable = (AnimationDrawable) mLoadImg.getDrawable();
    mDrawable.start();
    mLoadText.setText(msg);
    final Dialog loadingDialog = new Dialog(context, IdHelper.getStyle(context, "jmui_loading_dialog_style"));
    loadingDialog.setCancelable(true);
    loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    return loadingDialog;
}
 
Example 2
Source Project: Album   File: PhotoViewAttacher.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean setDisplayMatrix(Matrix finalMatrix) {
    if (finalMatrix == null) {
        throw new IllegalArgumentException("Matrix cannot be null");
    }

    ImageView imageView = getImageView();
    if (null == imageView) {
        return false;
    }

    if (null == imageView.getDrawable()) {
        return false;
    }

    mSuppMatrix.set(finalMatrix);
    setImageViewMatrix(getDrawMatrix());
    checkMatrixBounds();

    return true;
}
 
Example 3
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = super.getView(position, convertView, parent);

    //imageView.setImageDrawable(icons[position]);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);

    if (contactids.length > position) {
        if (contactids[position] != null) {
            Uri u = getPhotoUri(contactids[position]);
            if (u != null) {
                imageView.setImageURI(u);
                if (imageView.getDrawable() == null)
                    imageView.setImageResource(R.drawable.ic_launcher);
                //Log.d("gps1", u.toString());
            } else {
                //imageView.setImageResource(R.drawable.ic_contact_picture_2);
            }
        }

    }

    return rowView;
}
 
Example 4
public static Dialog createLoadingDialog(Context context, String msg) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(IdHelper.getLayout(context, "jmui_loading_view"), null);
    RelativeLayout layout = (RelativeLayout) v.findViewById(IdHelper.getViewID(context, "jmui_dialog_view"));
    ImageView mLoadImg = (ImageView) v.findViewById(IdHelper.getViewID(context, "jmui_loading_img"));
    TextView mLoadText = (TextView) v.findViewById(IdHelper.getViewID(context, "jmui_loading_txt"));
    AnimationDrawable mDrawable = (AnimationDrawable) mLoadImg.getDrawable();
    mDrawable.start();
    mLoadText.setText(msg);
    final Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);
    loadingDialog.setCancelable(true);
    loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    return loadingDialog;
}
 
Example 5
Source Project: Android   File: PhotoViewAttacher.java    License: MIT License 6 votes vote down vote up
@Override
public boolean setDisplayMatrix(Matrix finalMatrix) {
    if (finalMatrix == null) {
        throw new IllegalArgumentException("Matrix cannot be null");
    }

    ImageView imageView = getImageView();
    if (null == imageView) {
        return false;
    }

    if (null == imageView.getDrawable()) {
        return false;
    }

    mSuppMatrix.set(finalMatrix);
    setImageViewMatrix(getDrawMatrix());
    checkMatrixBounds();

    return true;
}
 
Example 6
Source Project: example   File: CardThumbnailView.java    License: Apache License 2.0 5 votes vote down vote up
protected static BitmapWorkerUrlTask getBitmapWorkerUrlTask(ImageView imageView) {
    if (imageView != null) {
        final Drawable drawable = imageView.getDrawable();
        if (drawable instanceof AsyncDrawableUrl) {
            final AsyncDrawableUrl asyncDrawable = (AsyncDrawableUrl) drawable;
            return asyncDrawable.getBitmapWorkerUrlTask();
        }
    }
    return null;
}
 
Example 7
Source Project: cannonball-android   File: ImageLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param imageView Any imageView
 * @return Retrieve the currently active task (if any) associated with this imageView.
 * null if there is no such task.
 */
private BackgroundTask getBitmapDownloaderTask(ImageView imageView) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable instanceof BackgroundTaskDrawable) {
            BackgroundTaskDrawable downloadedDrawable = (BackgroundTaskDrawable) drawable;
            return downloadedDrawable.getBitmapDownloaderTask();
        }
    }
    return null;
}
 
Example 8
private static void setColor(ImageView image, TextView text, int color) {
    // set color
    GradientDrawable sd = (GradientDrawable) image.getDrawable();
    sd.setColor(color);
    image.invalidate();

    // set color name
    text.setText(getColorName(color));
}
 
Example 9
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        Drawable d = imageView.getDrawable();
        if (null != d) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                    d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
    }
    return null;
}
 
Example 10
private Bitmap getBitmapFromImageView(ImageView imageView) {
    Bitmap bitmap = null;
    if (imageView.getDrawable() instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    } else {
        Drawable drawable = imageView.getDrawable();
        if (drawable != null) {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);

            Canvas canvas = new Canvas(bitmap);
            drawable.draw(canvas);
        }
    }
    return bitmap;
}
 
Example 11
public static int getPaletteColor(ImageView imageView) {
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    Bitmap bitmap = drawable.getBitmap();
    Palette palette = Palette.generate(bitmap);
    int x = Color.parseColor("#ea0101");
    return palette.getVibrantColor(x);
}
 
Example 12
Source Project: Bailan   File: GalleryActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void recycleImage(View view) {
    if (!(view instanceof ImageView)) {
        ImageView imageView = (ImageView) view;
        Drawable drawable = imageView.getDrawable();
        if (drawable == null || !(drawable instanceof BitmapDrawable)) {
            return;
        } else {
            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
            if (bitmap == null || bitmap.isRecycled()) {
                return;
            }
            bitmap.recycle();
        }
    }
}
 
Example 13
private static IPictureWorker getBitmapDownloaderTask(ImageView imageView) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable instanceof PictureBitmapDrawable) {
            PictureBitmapDrawable downloadedDrawable = (PictureBitmapDrawable) drawable;
            return downloadedDrawable.getBitmapDownloaderTask();
        }
    }
    return null;
}
 
Example 14
private IPictureWorker getBitmapDownloaderTask(ImageView imageView) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable instanceof PictureBitmapDrawable) {
            PictureBitmapDrawable downloadedDrawable = (PictureBitmapDrawable) drawable;
            return downloadedDrawable.getBitmapDownloaderTask();
        }
    }
    return null;
}
 
Example 15
/**
 * 调整图片的frame
 *
 * @param imageView
 */
public static void adjustSize(ImageView imageView) {
    if (imageView != null && imageView.getLayoutParams() != null && imageView.getDrawable() != null) {
         int width = (imageView.getDrawable()).getIntrinsicWidth();
         int height = (imageView.getDrawable()).getIntrinsicHeight();
        if (width != imageView.getLayoutParams().width || height != imageView.getLayoutParams().height) {
            imageView.getLayoutParams().width = width;
            imageView.getLayoutParams().height = height;
            imageView.requestLayout();
        }
    }
}
 
Example 16
Source Project: zone-sdk   File: MeasureUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 返回的 宽高数组 是图片 在当前分辨率手机的宽高
 *
 * @param imageView
 * @return
 */
public static float[] measureDrawableWH(final ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Matrix mar = imageView.getImageMatrix();
    int intrinsicHeight = drawable.getIntrinsicHeight();
    int intrinsicWidth = drawable.getIntrinsicWidth();
    return new float[]{intrinsicWidth, intrinsicHeight};
}
 
Example 17
private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
    if (imageView != null) {
        final Drawable drawable = imageView.getDrawable();
        if (drawable instanceof AsyncDrawable) {
            final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
            return asyncDrawable.getBitmapWorkerTask();
        }
    }
    return null;
}
 
Example 18
Source Project: FrameAnimation   File: AnimationOne.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.one);
    ImageView image = (ImageView) findViewById(R.id.image);


    AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable();
    animationDrawable.start();
}
 
Example 19
Source Project: Album   File: PhotoViewAttacher.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if the ImageView exists, and its Drawable exists
 */
private static boolean hasDrawable(ImageView imageView) {
    return null != imageView && null != imageView.getDrawable();
}
 
Example 20
public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;
    if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }

    Rect rect = new Rect();
    boolean isVisible = imageView.getGlobalVisibleRect(rect);
    if (!isVisible) {
        int[] location = new int[2];
        imageView.getLocationOnScreen(location);

        rect.left = location[0];
        rect.top = location[1];
        rect.right = rect.left + imageView.getWidth();
        rect.bottom = rect.top + imageView.getHeight();
    }

    if (bitmap != null) {

        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        int imageViewWidth = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
        int imageviewHeight = imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();

        float startScale;
        if ((float) imageViewWidth / bitmapWidth > (float) imageviewHeight / bitmapHeight) {
            // Extend start bounds horizontally
            startScale = (float) imageviewHeight / bitmapHeight;

        } else {
            startScale = (float) imageViewWidth / bitmapWidth;

        }

        bitmapHeight = (int) (bitmapHeight * startScale);
        bitmapWidth = (int) (bitmapWidth * startScale);

        int deltaX = (imageViewWidth - bitmapWidth) / 2;
        int deltaY = (imageviewHeight - bitmapHeight) / 2;

        rect.set(rect.left + deltaX, rect.top + deltaY, rect.right - deltaX, rect.bottom - deltaY);

        return rect;
    } else {
        return null;
    }

}