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:it.cdpaf.helper.DrawableManager.java

public static Drawable fetchDrawable(String urlString, Context ctx) {
    if (drawableMap.containsKey(urlString)) {
        Log.d(ctx.getClass().getSimpleName(),
                "DRAWABLE MANAGER FD:" + "RIUSO: " + urlString + " Size:" + drawableMap.size());
        return drawableMap.get(urlString);

    }//from w ww.  j  a  v a2 s .c  o m

    Log.d(ctx.getClass().getSimpleName(), "image url:" + urlString);
    try {

        InputStream is = fetch(urlString, ctx);

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

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

        return drawable;
    } catch (MalformedURLException e) {
        Log.e(ctx.getClass().getSimpleName(), "MALFORMEDURL EXC fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(ctx.getClass().getSimpleName(), "IO EXCP fetchDrawable failed", e);
        return null;
    }
}

From source file:android.support.design.testutils.TestUtilsMatchers.java

/**
 * Returns a matcher that matches TextViews whose start drawable is filled with the specified
 * fill color./* w w  w .j a v a  2  s. c o m*/
 */
public static Matcher withStartDrawableFilledWith(final @ColorInt int fillColor,
        final int allowedComponentVariance) {
    return new BoundedMatcher<View, TextView>(TextView.class) {
        private String failedCheckDescription;

        @Override
        public void describeTo(final Description description) {
            description.appendText(failedCheckDescription);
        }

        @Override
        public boolean matchesSafely(final TextView view) {
            final Drawable[] compoundDrawables = view.getCompoundDrawables();
            final boolean isRtl = (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL);
            final Drawable startDrawable = isRtl ? compoundDrawables[2] : compoundDrawables[0];
            if (startDrawable == null) {
                failedCheckDescription = "no start drawable";
                return false;
            }
            try {
                final Rect bounds = startDrawable.getBounds();
                TestUtils.assertAllPixelsOfColor("", startDrawable, bounds.width(), bounds.height(), true,
                        fillColor, allowedComponentVariance, true);
            } catch (Throwable t) {
                failedCheckDescription = t.getMessage();
                return false;
            }
            return true;
        }
    };
}

From source file:com.example.prox.model.DrawableLoader.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }/*from  ww  w .  j a  v a 2 s .  c  o m*/

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        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.wilson.android.library.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }/*from w  w w.  j a v  a 2 s.co  m*/

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");
        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;
    } catch (NullPointerException e) {
        Log.e(this.getClass().getSimpleName(), "Null image. Bad url?", e);
        return null;
    }
}

From source file:com.calvitium.playground.marvelcharacters.util.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }//from   w  w  w .jav a2s  .  c o m

    Log.d(TAG, "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = Drawable.createFromStream(is, "src");

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

        return drawable;
    } catch (MalformedURLException e) {
        Log.e(TAG, "fetchDrawable failed", e);
        return null;
    } catch (IOException e) {
        Log.e(TAG, "fetchDrawable failed", e);
        return null;
    }
}

From source file:me.henrytao.mdcore.widgets.internal.MdCheckBox.java

@Override
protected void onDraw(Canvas canvas) {
    if (isLayoutRtl()) {
        canvas.translate(-mPaddingRight, 0);
    } else {/*from   ww w . j av  a 2 s .  c o  m*/
        canvas.translate(mPaddingLeft, 0);
    }
    super.onDraw(canvas);
    Drawable background = getBackground();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && background != null) {
        boolean isLayoutRtl = isLayoutRtl();
        Rect bounds = background.getBounds();
        int top = bounds.top;
        int bottom = bounds.bottom;
        int left = (isLayoutRtl ? getWidth() - mMinWidth : 0)
                + (!mHasCustomDrawable && !isLayoutRtl ? mPaddingLeft : 0);
        int right = (isLayoutRtl ? getWidth() : mMinWidth)
                - (!mHasCustomDrawable && isLayoutRtl ? mPaddingRight : 0);
        background.setHotspotBounds(left, top, right, bottom);
    }
}

From source file:com.novel.lightnovel.Utils.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }//w ww  .  j  a v a  2s .co m
    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable 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());
        } 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;
    }
}

From source file:com.aldogomez.bluebird.DrawableManager.java

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

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable 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());
        } 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;
    }
}

From source file:com.facebook.litho.ComponentAccessibilityDelegate.java

/**
 * Finds extra accessibility nodes under the given event coordinates.
 * Returns {@link #INVALID_ID} otherwise.
 *///from  w  w  w . j  a  v a 2  s. c o  m
@Override
protected int getVirtualViewAt(float x, float y) {
    final MountItem mountItem = getAccessibleMountItem(mView);
    if (mountItem == null) {
        return INVALID_ID;
    }

    final Component<?> component = mountItem.getComponent();
    final ComponentLifecycle lifecycle = component.getLifecycle();

    if (lifecycle.getExtraAccessibilityNodesCount(component) == 0) {
        return INVALID_ID;
    }

    final Drawable drawable = (Drawable) mountItem.getContent();
    final Rect bounds = drawable.getBounds();

    // Try to find an extra accessibility node that intersects with
    // the given coordinates.
    final int virtualViewId = lifecycle.getExtraAccessibilityNodeAt((int) x - bounds.left, (int) y - bounds.top,
            component);

    return (virtualViewId >= 0 ? virtualViewId : INVALID_ID);
}

From source file:com.facebook.litho.ComponentAccessibilityDelegate.java

@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) {
    final MountItem mountItem = getAccessibleMountItem(mView);
    if (mountItem == null) {
        Log.e(TAG, "No accessible mount item found for view: " + mView);

        // ExploreByTouchHelper insists that we set something.
        node.setContentDescription("");
        node.setBoundsInParent(getDefaultBounds());
        return;//from  ww w .  j  a  v  a2 s. c o  m
    }

    final Drawable drawable = (Drawable) mountItem.getContent();
    final Rect bounds = drawable.getBounds();

    final Component<?> component = mountItem.getComponent();
    final ComponentLifecycle lifecycle = component.getLifecycle();

    node.setClassName(lifecycle.getClass().getName());

    if (virtualViewId >= lifecycle.getExtraAccessibilityNodesCount(component)) {
        Log.e(TAG, "Received unrecognized virtual view id: " + virtualViewId);

        // ExploreByTouchHelper insists that we set something.
        node.setContentDescription("");
        node.setBoundsInParent(getDefaultBounds());
        return;
    }

    lifecycle.onPopulateExtraAccessibilityNode(node, virtualViewId, bounds.left, bounds.top, component);
}