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

The following examples show how to use android.widget.ImageView#getDrawable() . 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: PhotoViewAttacher.java    From Android with 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 2
Source File: DialogCreator.java    From jmessage-android-uikit with 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 3
Source File: DialogCreator.java    From o2oa with GNU Affero General Public License v3.0 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, R.style.loading_dialog);
    loadingDialog.setCancelable(true);
    loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    return loadingDialog;
}
 
Example 4
Source File: PhotoViewAttacher.java    From Album with 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 5
Source File: RepoListAdapterSMS.java    From GPS2SMS with GNU General Public License v3.0 6 votes vote down vote up
@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 6
Source File: AnimationOne.java    From FrameAnimation with 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 7
Source File: CardThumbnailView.java    From example with 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 8
Source File: TemplateAdapter.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 9
Source File: MeasureUtils.java    From zone-sdk with 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 10
Source File: ImageUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调整图片的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 11
Source File: AbstractWorker.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
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 12
Source File: TimeLineBitmapDownloader.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
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 13
Source File: GalleryActivity.java    From Bailan with 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 14
Source File: BitmapUtility.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
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 15
Source File: VideoActivity.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
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 16
Source File: PhotoViewAttacher.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 17
Source File: StyleFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 18
Source File: ImageLoader.java    From cannonball-android with 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 19
Source File: AnimationUtility.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
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;
    }

}
 
Example 20
Source File: PhotoViewAttacher.java    From Album with 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();
}