Example usage for android.graphics.drawable Drawable getIntrinsicHeight

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

Introduction

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

Prototype

public int getIntrinsicHeight() 

Source Link

Document

Returns the drawable's intrinsic height.

Usage

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Creates and returns a bitmap from a specific drawable.
 *
 * @param drawable//from  w w  w .j  a  v a2 s  . c  o  m
 *         The drawable, which should be converted, as an instance of the class {@link
 *         Drawable}. The drawable may not be null
 * @return The bitmap, which has been created, as an instance of the class {@link Bitmap}
 */
public static Bitmap drawableToBitmap(@NonNull final Drawable drawable) {
    ensureNotNull(drawable, "The drawable may not be null");

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    Bitmap bitmap;

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:com.bobomee.android.tab_navigator.recyclerview.HorizontalDividerItemDecoration.java

private int getDividerSize(int position, RecyclerView parent) {
    if (mPaintProvider != null) {
        return (int) mPaintProvider.dividerPaint(position, parent).getStrokeWidth();
    } else if (mSizeProvider != null) {
        return mSizeProvider.dividerSize(position, parent);
    } else if (mDrawableProvider != null) {
        Drawable drawable = mDrawableProvider.drawableProvider(position, parent);
        return drawable.getIntrinsicHeight();
    }/*from w w  w.ja v  a  2  s .  com*/
    throw new RuntimeException("failed to get size");
}

From source file:de.geeksfactory.opacclient.ui.AccountDividerItemDecoration.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.ViewHolder vh = parent.getChildViewHolder(child);

        if (!isDecorated(child, parent))
            continue;
        if (!(vh instanceof AccountAdapter.ViewHolder))
            continue;

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;

        final Drawable drawable = (((AccountAdapter.ViewHolder) vh).isCoversHidden() ? mDividerWithoutInset
                : mDividerWithInset);/*from  www .  j  a v  a  2s .  co m*/
        final int bottom = top + drawable.getIntrinsicHeight();
        drawable.setBounds(left, top, right, bottom);
        drawable.draw(c);
    }
}

From source file:com.github.magiepooh.recycleritemdecoration.VerticalItemDecoration.java

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

    // last position
    if (isLastPosition(view, parent)) {
        if (mLastDrawable != null) {
            outRect.bottom = mLastDrawable.getIntrinsicHeight();
        }//  ww w . jav  a 2 s . c  o m
        return;
    }

    // specific view type
    int childType = parent.getLayoutManager().getItemViewType(view);
    Drawable drawable = mDividerViewTypeMap.get(childType);
    if (drawable != null) {
        outRect.bottom = drawable.getIntrinsicHeight();
    }

    // first position
    if (isFirstPosition(view, parent)) {
        if (mFirstDrawable != null) {
            outRect.top = mFirstDrawable.getIntrinsicHeight();
        }
    }
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void startImg(SpannableStringBuilder text, Attributes attributes, HtmlParser.ImageGetter img) {
    String src = attributes.getValue("", "src");
    Drawable d = null;

    if (img != null) {
        d = img.getDrawable(src);//from   w  w  w .ja v a2  s  . c o m
    }

    if (d == null) {
        d = ResourcesCompat.getDrawable(Resources.getSystem(), android.R.drawable.ic_menu_report_image, null);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }

    int len = text.length();
    text.append("\uFFFC");

    text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:org.opensourcetlapp.tl.CustomImageGetter.java

@Override
public Drawable getDrawable(String url) {
    try {//from   w ww .  ja  v  a  2s .  c om
        // get name of image
        String name = url.substring(url.lastIndexOf("/") + 1);
        InputStream is;
        try {
            try {
                is = assetManager.open("images/" + name);
            } catch (IOException e) {
                is = context.openFileInput(name);
            }
        } catch (FileNotFoundException e) {
            is = getImageInputStream(url);
            if (!name.contains("draw.php?poll_id")) {
                FileOutputStream out = context.openFileOutput(name, Context.MODE_PRIVATE);
                byte[] buffer = new byte[1024];
                int totalLength = 0;
                int length;
                while ((length = is.read(buffer)) >= 0) {
                    totalLength += length;
                    out.write(buffer, 0, length);
                }
                is.close();
                out.close();
                is = context.openFileInput(name);
            }
        }

        // cache dir + name of image + the image save format

        Drawable d = Drawable.createFromStream(is, name);
        //Drawable d = Drawable.createFromPath(f.getAbsolutePath());
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());// make it the size of the image
        return d;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.pansapiens.occyd.MapResults.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // receive search results from calling Activity, 
    // as a raw json string
    Bundle incoming_data = getIntent().getExtras();
    String json_txt = null;/*  w w w . j  ava  2 s. c  o  m*/
    ArrayList<Post> post_results = new ArrayList();
    if (incoming_data != null) {
        json_txt = incoming_data.getString("json");
        try {
            post_results = JSONdecoder.json2postArray(json_txt);
        } catch (JSONException e) {
            Toast.makeText(MapResults.this, "FAIL: Malformed response from server.", Toast.LENGTH_LONG).show();
        }
    }

    setContentView(R.layout.mapview);
    map = (MapView) findViewById(R.id.map);

    // zoom controls are placed in their own 'sub-layout' called
    // "@+id/zoom" in the mapview.xml layout.
    // this ensures they are correctly positioned, don't scroll offscreen
    // and don't prevent touch scrolling of the map when visible 
    LinearLayout zoomView = (LinearLayout) findViewById(R.id.zoom);
    zoomView.addView(map.getZoomControls());

    // (straight out of the MapViewCompassDemo.java API Demos)
    // put a dot on our current location once we have a fix
    mMyLocationOverlay = new MyLocationOverlay(this, map);
    mMyLocationOverlay.runOnFirstFix(new Runnable() {
        public void run() {
            map.getController().animateTo(mMyLocationOverlay.getMyLocation());
        }
    });
    map.getOverlays().add(mMyLocationOverlay);
    map.getController().setZoom(17);

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    LocationUpdater locupdater = new LocationUpdater(locationManager, this);
    locupdater.startUpdating();

    // add markers for search results
    // marker from: http://commons.wikimedia.org/wiki/File:Map_symbol_location_02.png
    Drawable marker = getResources().getDrawable(R.drawable.marker);

    marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());

    map.getOverlays().add(new MapResultsOverlay(marker, post_results));
    //map.getOverlays().add(new MapResultsOverlay(marker)); // dummy testing constructor ....
}

From source file:com.example.android.materialme.SportsAdapter.java

/**
 * Constructor that passes in the sports data and the context
 * @param sportsData ArrayList containing the sports data
 * @param context Context of the application
 *//*from w  w  w. java 2s.c o m*/
SportsAdapter(Context context, ArrayList<Sport> sportsData) {
    this.mSportsData = sportsData;
    this.mContext = context;

    //Prepare gray placeholder
    mGradientDrawable = new GradientDrawable();
    mGradientDrawable.setColor(Color.GRAY);

    //Make the placeholder same size as the images
    Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.img_badminton);
    if (drawable != null) {
        mGradientDrawable.setSize(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    }
}

From source file:com.hippo.gl.glrenderer.XmlResourceTexture.java

@Override
protected Bitmap onGetBitmap() {
    Drawable drawable = ContextCompat.getDrawable(mContext, mResId);

    int width = mWidth;
    int height = mHeight;
    if (width <= 0) {
        width = drawable.getIntrinsicWidth();
    }//from  w w w  . j ava2 s .  c om
    if (height <= 0) {
        height = drawable.getIntrinsicHeight();
    }
    if (width <= 0) {
        width = 1;
    }
    if (height <= 0) {
        height = 1;
    }

    drawable.setBounds(0, 0, width, height);

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.draw(canvas);

    return bitmap;
}

From source file:com.google.android.gms.samples.wallet.CartDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_cart_detail, container, false);

    ItemInfo itemInfo = Constants.ITEMS_FOR_SALE[mItemId];

    TextView itemName = (TextView) view.findViewById(R.id.text_item_name);
    itemName.setText(itemInfo.name);//  www.java  2 s  . c om

    Drawable itemImage = getResources().getDrawable(itemInfo.imageResourceId);
    int imageSize = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    int actualWidth = itemImage.getIntrinsicWidth();
    int actualHeight = itemImage.getIntrinsicHeight();
    int scaledHeight = imageSize;
    int scaledWidth = (int) (((float) actualWidth / actualHeight) * scaledHeight);
    itemImage.setBounds(0, 0, scaledWidth, scaledHeight);
    itemName.setCompoundDrawables(itemImage, null, null, null);

    TextView itemPrice = (TextView) view.findViewById(R.id.text_item_price);
    itemPrice.setText(Util.formatPrice(getActivity(), itemInfo.priceMicros));
    TextView shippingCost = (TextView) view.findViewById(R.id.text_shipping_price);
    TextView tax = (TextView) view.findViewById(R.id.text_tax_price);
    TextView total = (TextView) view.findViewById(R.id.text_total_price);
    if ((mItemId == Constants.PROMOTION_ITEM) && getApplication().isAddressValidForPromo()) {
        shippingCost.setText(Util.formatPrice(getActivity(), 0L));
    } else {
        shippingCost.setText(Util.formatPrice(getActivity(), itemInfo.shippingPriceMicros));
    }

    tax.setText(Util.formatPrice(getActivity(), itemInfo.taxMicros));
    total.setText(Util.formatPrice(getActivity(), itemInfo.getTotalPrice()));

    return view;
}