Example usage for android.graphics.drawable Drawable getBounds

List of usage examples for android.graphics.drawable Drawable getBounds

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable getBounds.

Prototype

@NonNull
public final Rect getBounds() 

Source Link

Document

Return the drawable's bounds Rect.

Usage

From source file:net.sarangnamu.android.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }//from www  .j a  v a2  s.c  om

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = null;

        drawable = Drawable.createFromStream(is, "src");

        if (drawable != null) {
            drawableMap.put(urlString, drawable);
            Log.d(this.getClass().getSimpleName(),
                    "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight()
                            + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + ","
                            + drawable.getMinimumWidth());
        }
        return drawable;
    } catch (MalformedURLException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    }
}

From source file:com.neudesic.mobile.pulse.ui.drawable.DrawableManager.java

public synchronized Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        Log.d(getClass().getSimpleName(), "loading image from localcache");
        return drawableMap.get(urlString);
    }//from w  ww.jav a  2  s . c  om

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);

        Drawable drawable = Drawable.createFromStream(is, "src");
        if (drawableMap.size() > MAX_CACHE_SIZE) {
            drawableMap.clear();
        }
        drawableMap.put(urlString, drawable);
        Log.d(this.getClass().getSimpleName(),
                "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + ","
                        + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + ","
                        + drawable.getMinimumWidth());
        return drawable;
    } catch (MalformedURLException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    }
}

From source file:com.android.launcher3.Hotseat.java

void resetLayout() {
    mContent.removeAllViewsInLayout();//from  ww w  .  j  a  v  a2s.co m

    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView) inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}

From source file:com.cooltechworks.views.ScratchImageView.java

public int[] getImageBounds() {

    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();

    int vwidth = getWidth() - paddingLeft - paddingRight;
    int vheight = getHeight() - paddingBottom - paddingTop;

    int centerX = vwidth / 2;
    int centerY = vheight / 2;

    Drawable drawable = getDrawable();
    Rect bounds = drawable.getBounds();

    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();

    if (width <= 0) {
        width = bounds.right - bounds.left;
    }/*from  w w w.j  av  a  2  s.  c o m*/

    if (height <= 0) {
        height = bounds.bottom - bounds.top;
    }

    int left;
    int top;

    if (height > vheight) {
        height = vheight;
    }

    if (width > vwidth) {
        width = vwidth;
    }

    ScaleType scaleType = getScaleType();

    switch (scaleType) {
    case FIT_START:
        left = paddingLeft;
        top = centerY - height / 2;
        break;
    case FIT_END:
        left = vwidth - paddingRight - width;
        top = centerY - height / 2;
        break;
    case CENTER:
        left = centerX - width / 2;
        top = centerY - height / 2;
        break;
    default:
        left = paddingLeft;
        top = paddingTop;
        width = vwidth;
        height = vheight;
        break;

    }

    return new int[] { left, top, left + width, top + height };
}

From source file:com.cm.beer.util.DrawableManager.java

/**
 * /*from   w ww.j a v  a2 s . c  o m*/
 * @param urlString
 * @return
 */
public Drawable fetchDrawable(String urlString) {
    if (mDrawableCache.containsKey(urlString)) {
        if (Logger.isLogEnabled())
            Logger.log("Returning Drawable from Cache:" + urlString);
        SoftReference<Drawable> softReference = mDrawableCache.get(urlString);
        if ((softReference == null) || (softReference.get() == null)) {
            mDrawableCache.remove(urlString);
            if (Logger.isLogEnabled())
                Logger.log("fetchDrawable():Soft Reference has been Garbage Collected:" + urlString);
        } else {
            return softReference.get();
        }
    }

    if (Logger.isLogEnabled())
        Logger.log("image url:" + urlString);
    try {
        // prevents multithreaded fetches for the same image
        mLockCache.put(urlString, urlString);
        if (Logger.isLogEnabled())
            Logger.log("Begin Downloading:" + urlString);
        InputStream is = fetch(urlString);
        if (Logger.isLogEnabled())
            Logger.log("End Downloading:" + urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        mDrawableCache.put(urlString, new SoftReference<Drawable>(drawable));
        mLockCache.remove(urlString);
        if (Logger.isLogEnabled())
            Logger.log("got a thumbnail drawable: " + drawable.getBounds() + ", "
                    + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
                    + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
        return drawable;
    } catch (Throwable e) {
        Log.e(this.getClass().getName(), "fetchDrawable failed", e);
        return null;
    }
}

From source file:com.achep.acdisplay.ui.widgets.CircleView.java

private void drawCornerIcon(@NonNull Canvas canvas, @NonNull Drawable drawable, int xm, int ym) {
    int width = getMeasuredWidth() - drawable.getBounds().width();
    int height = getMeasuredHeight() - drawable.getBounds().height();
    float margin = (1 - 2 * xm) * mCornerMargin;
    // Draw/*from   ww  w  .  j  a v a  2  s . c o  m*/
    canvas.save();
    canvas.translate(xm * width + margin, ym * height + margin);
    drawable.draw(canvas);
    canvas.restore();
}

From source file:com.albedinsky.android.ui.graphics.drawable.DrawableWrapper.java

/**
 * Creates a new instance of DrawableWrapper which wraps the given <var>drawable</var>.
 *
 * @param drawable The drawable to wrap.
 *//* w w  w .  j  a  v a  2  s  .c  o  m*/
public DrawableWrapper(@NonNull Drawable drawable) {
    this.mDrawable = drawable;

    /**
     * Copy current state of the wrapped drawable.
     */
    setState(drawable.getState());
    setBounds(drawable.getBounds());
    setLevel(drawable.getLevel());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        setCallback(drawable.getCallback());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setAlpha(drawable.getAlpha());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setColorFilter(drawable.getColorFilter());
    }
    mDrawable.setCallback(this);
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

private boolean onTouchEventTraditionalRotation(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }/*w  ww .j  a v  a  2 s  . c o  m*/

    final Drawable mThumb = getThumbCompat();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        setPressed(true);
        if (mThumb != null) {
            // This may be within the padding region
            invalidate(mThumb.getBounds());
        }
        onStartTrackingTouch();
        trackTouchEvent(event);
        attemptClaimDrag(true);
        break;

    case MotionEvent.ACTION_MOVE:
        if (mIsDragging) {
            trackTouchEvent(event);
        }
        break;

    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            trackTouchEvent(event);
            onStopTrackingTouch();
            setPressed(false);
        } else {
            // Touch up when we never crossed the touch slop threshold
            // should
            // be interpreted as a tap-seek to that location.
            onStartTrackingTouch();
            trackTouchEvent(event);
            onStopTrackingTouch();
            attemptClaimDrag(false);
        }
        // ProgressBar doesn't know to repaint the thumb drawable
        // in its inactive state when the touch stops (because the
        // value has not apparently changed)
        invalidate();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            onStopTrackingTouch();
            setPressed(false);
        }
        invalidate(); // see above explanation
        break;
    }
    return true;
}

From source file:com.labs.okey.commonride.utils.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }//from  w  w w .j  a  va2  s.c  om

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        if (isRounded) {
            drawable = RoundedDrawable.fromDrawable(drawable);
            if (drawable instanceof RoundedDrawable) {
                ((RoundedDrawable) drawable).setCornerRadius(cornerRadius).setBorderColor(borderColor)
                        .setBorderWidth(4).setOval(true);
            }
        }

        if (drawable != null) {
            drawableMap.put(urlString, drawable);
            Log.d(this.getClass().getSimpleName(),
                    "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight()
                            + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + ","
                            + drawable.getMinimumWidth());
        } else {
            Log.w(this.getClass().getSimpleName(), "could not get thumbnail");
        }

        return drawable;
    } catch (MalformedURLException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    } catch (Exception e) {
        Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
        return null;
    }
}

From source file:com.android.launcher3.folder.FolderIcon.java

private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) {
    canvas.save();//from  w ww.j  a  v a2  s  . c om
    canvas.translate(params.transX, params.transY);
    canvas.scale(params.scale, params.scale);
    Drawable d = params.drawable;

    if (d != null) {
        mOldBounds.set(d.getBounds());
        d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize);
        if (d instanceof FastBitmapDrawable) {
            FastBitmapDrawable fd = (FastBitmapDrawable) d;
            float oldBrightness = fd.getBrightness();
            fd.setBrightness(params.overlayAlpha);
            d.draw(canvas);
            fd.setBrightness(oldBrightness);
        } else {
            d.setColorFilter(Color.argb((int) (params.overlayAlpha * 255), 255, 255, 255),
                    PorterDuff.Mode.SRC_ATOP);
            d.draw(canvas);
            d.clearColorFilter();
        }
        d.setBounds(mOldBounds);
    }
    canvas.restore();
}