Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

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

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:uk.org.ngo.squeezer.util.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//  w  w w  .ja  va2 s .  com
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable between the pending image and the final bitmap.
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { imageView.getDrawable(), new BitmapDrawable(mResources, bitmap) });

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(new BitmapDrawable(mResources, bitmap));
    }
}

From source file:com.android.aft.AFCoreTools.ImageDownloader.java

/**
 * Same as download but the image is always downloaded and the cache is not
 * used. Kept private at the moment as its interest is not clear.
 *///from w ww  .j  a v  a2 s .  c  o  m
private void forceDownload(String url, ImageView imageView, int reqWidth, int reqHeight,
        ImageDownloaderListener listener, Animation animation) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, listener, reqWidth, reqHeight);

        Bitmap bg = null;
        if (imageView.getDrawable() instanceof BitmapDrawable)
            bg = ((BitmapDrawable) imageView.getDrawable()).getBitmap();

        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, bg);

        imageView.setImageDrawable(downloadedDrawable);
        if (animation != null) {
            imageView.setAnimation(animation);
        }
        imageView.setMinimumHeight(156);

        task.execute(Mode.Parallel, url);
    }
}

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

private void RotatePicture(ImageView imageView) {
    Bitmap picture = null;/* w  w  w  .  jav a 2 s .c o  m*/

    picture = ((BitmapDrawable) (imageView.getDrawable())).getBitmap();

    Matrix m = new Matrix();
    m.postRotate(90);
    picture = Bitmap.createBitmap(picture, 0, 0, picture.getWidth(), picture.getHeight(), m, true);

    imageView.setImageBitmap(picture);

}

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

public final void update() {
    ImageView imageView = getImageView();

    if (null != imageView) {
        if (mZoomEnabled) {
            // Make sure we using MATRIX Scale Type
            setImageViewScaleTypeMatrix(imageView);

            // Update the base matrix using the current drawable
            updateBaseMatrix(imageView.getDrawable());
        } else {/*from  w  w  w. j av  a2  s .com*/
            // Reset the Matrix...
            resetMatrix();
        }
    }
}

From source file:com.widgets.photoview.PhotoViewAttacher.java

private void checkRotationMatrix() {

    ImageView imageView = getImageView();
    Drawable d = imageView.getDrawable();
    if (null == imageView || null == d) {
        return;/* w ww.j a v a2s.  c  om*/
    }

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();
    float widthScale;
    float heightScale;

    if (this.degrees % 180 != 0) {
        widthScale = viewHeight / drawableWidth;
        heightScale = viewWidth / drawableHeight;
    } else {
        widthScale = viewWidth / drawableWidth;
        heightScale = viewHeight / drawableHeight;
    }
    float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
    mBaseMatrix.postScale(scale, scale);
    mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
            (viewHeight - drawableHeight * scale) / 2F);
}

From source file:com.android.tv.settings.dialog.DialogFragment.java

private void updateViewSize(ImageView iconView) {
    int intrinsicWidth = iconView.getDrawable().getIntrinsicWidth();
    LayoutParams lp = iconView.getLayoutParams();
    if (intrinsicWidth > 0) {
        lp.height = lp.width * iconView.getDrawable().getIntrinsicHeight() / intrinsicWidth;
    } else {/*from  w  w  w . ja  v  a2  s .com*/
        // If no intrinsic width, then just mke this a square.
        lp.height = lp.width;
    }
}

From source file:cn.golden.pinchzoomcanvasview.PinchZoomCanvasViewAttacher.java

@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);// w ww.j a va  2 s.com
    setImageViewMatrix(getDrawMatrix());
    checkMatrixBounds();

    return true;
}

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

/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle//w  ww.j  av  a  2 s  .  c om
 */
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;
}

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

@Override
public boolean setDisplayMatrix(Matrix finalMatrix) {
    if (finalMatrix == null) {
        throw new IllegalArgumentException("Matrix cannot be null");
    }//from ww w  .  j av a 2 s.c  o  m

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

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

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

    return true;
}

From source file:android_network.hetnet.vpn_service.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views/*from ww w.j  av a2  s  .  c  o  m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            tvDaddr.setText(daddr);
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvDaddr, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return InetAddress.getByName(args[0]).getHostName();
                    } catch (UnknownHostException ignored) {
                        return args[0];
                    }
                }

                @Override
                protected void onPostExecute(String name) {
                    tvDaddr.setText(">" + name);
                    ViewCompat.setHasTransientState(tvDaddr, false);
                }
            }.execute(daddr);
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr))
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvOrganization, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    if (organization != null) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    ViewCompat.setHasTransientState(tvOrganization, false);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}