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:com.calvitium.playground.marvelcharacters.util.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }/*from   ww  w.jav  a  2s .co  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:edu.mit.mobile.android.imagecache.test.ImageCacheJunitTest.java

private void assertBitmapMaxSize(int maxExpectedWidth, int maxExpectedHeight, Drawable actual) {
    assertTrue(maxExpectedWidth >= actual.getIntrinsicWidth());
    assertTrue(maxExpectedHeight >= actual.getIntrinsicHeight());

}

From source file:edu.mit.mobile.android.imagecache.test.ImageCacheJunitTest.java

private void assertBitmapMinSize(int minExpectedWidth, int minExpectedHeight, Drawable actual) {
    assertTrue(minExpectedWidth <= actual.getIntrinsicWidth());
    assertTrue(minExpectedHeight <= actual.getIntrinsicHeight());

}

From source file:io.mapsquare.osmcontributor.utils.core.ArpiInitializer.java

/**
 * Pre-compute the different PoiTypes bitmaps icons for the ArpiGL fragment and view.
 *//* ww w  .  j a va  2  s .c  om*/
public void precomputeArpiBitmaps() {
    try {
        if (!ArpiGlInstaller.getInstance(application.getApplicationContext()).isInstalled()) {
            ArpiGlInstaller.getInstance(application.getApplicationContext()).install();

            Map<Long, PoiType> poiTypes = poiManager.loadPoiTypes();

            for (Map.Entry<Long, PoiType> entry : poiTypes.entrySet()) {
                Integer id = bitmapHandler.getIconDrawableId(entry.getValue());
                if (id != null && id > 0) {
                    Drawable d = application.getApplicationContext().getResources().getDrawableForDensity(id,
                            DisplayMetrics.DENSITY_XXHIGH);
                    int width = d.getIntrinsicWidth();
                    int height = d.getIntrinsicHeight();
                    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(bitmap);
                    d.setBounds(0, 0, width, height);
                    d.draw(c);

                    File dest = new File(application.getApplicationContext().getFilesDir(),
                            ArpiGlInstaller.INSTALLATION_DIR + "/" + ArpiGlInstaller.TEXTURE_ICONS_SUBDIR + "/"
                                    + entry.getValue().getIcon() + ".png");
                    dest.getParentFile().mkdirs();

                    if (dest.exists()) {
                        dest.delete();
                    }
                    dest.createNewFile();
                    OutputStream stream = new FileOutputStream(dest);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    stream.close();
                    bitmap.recycle();
                }
            }
        }
    } catch (IOException | JSONException e) {
        Timber.e("Error while initializing ArpiGl library: {}", e.getMessage());
    }
}

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

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }/* w  w w . j a  va 2  s. com*/
    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.silentcircle.contacts.calllognew.CallTypeIconsView.java

@Override
protected void onDraw(Canvas canvas) {
    int left = 0;
    for (Integer callType : mCallTypes) {
        final Drawable drawable = getCallTypeDrawable(callType);
        final int right = left + drawable.getIntrinsicWidth();
        drawable.setBounds(left, 0, right, drawable.getIntrinsicHeight());
        drawable.draw(canvas);/*  w  w  w.j a va  2  s.  c o  m*/
        left = right + mResources.iconMargin;
    }

    // If showing the video call icon, draw it scaled appropriately.
    //        if (mShowVideo) {
    //            final Drawable drawable = mResources.videoCall;
    //            final int right = left + mResources.videoCall.getIntrinsicWidth();
    //            drawable.setBounds(left, 0, right, mResources.videoCall.getIntrinsicHeight());
    //            drawable.draw(canvas);
    //        }
}

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

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

    int childCount = parent.getChildCount();
    for (int i = 0; i <= childCount - 1; i++) {
        View child = parent.getChildAt(i);
        int childViewType = parent.getLayoutManager().getItemViewType(child);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        // last position
        if (isLastPosition(child, parent)) {
            if (mLastDrawable != null) {
                int top = child.getBottom() + params.bottomMargin;
                int bottom = top + mLastDrawable.getIntrinsicHeight();
                mLastDrawable.setBounds(left, top, right, bottom);
                mLastDrawable.draw(c);//from  ww w .  jav  a2s. c  o  m
            }
            return;
        }

        // specific view type
        Drawable drawable = mDividerViewTypeMap.get(childViewType);
        if (drawable != null) {
            int top = child.getBottom() + params.bottomMargin;
            int bottom = top + drawable.getIntrinsicHeight();
            drawable.setBounds(left, top, right, bottom);
            drawable.draw(c);
        }

        // first position
        if (isFirstPosition(child, parent)) {
            if (mFirstDrawable != null) {
                int bottom = child.getTop() - params.topMargin;
                int top = bottom - mFirstDrawable.getIntrinsicHeight();
                mFirstDrawable.setBounds(left, top, right, bottom);
                mFirstDrawable.draw(c);
            }
        }
    }
}

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  ava 2  s. 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.handmark.pulltorefresh.library.internal.LoadingLayout.java

private void rotateArrow() {
    final Drawable drawable = mHeaderArrow.getDrawable();
    final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Config.ARGB_8888);/*from   www .  ja  v  a2s .  com*/
    final Canvas canvas = new Canvas(bitmap);
    canvas.save();
    canvas.rotate(180.0f, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    canvas.restore();
    mHeaderArrow.setImageBitmap(bitmap);
}

From source file:fr.ippon.android.opendata.android.AbstractParkingListFragment.java

private void configureSearchField(RelativeLayout r) {
    final AbstractParkingListFragment loaderCallBack = this;
    searchField = (EditText) r.findViewById(R.id.searchField);

    if (TextUtils.isEmpty(searchField.getText()))
        searchField.setText(searchHint);

    searchField.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // hide the keyboard
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchField.getWindowToken(), 0);

                // Perform action on key press
                boolean okSearch = !TextUtils.isEmpty(searchField.getText())
                        && !searchHint.equals(searchField.getText());
                queryText = okSearch ? searchField.getText().toString() : null;
                Log.d(TAG, "query: " + queryText);
                hasSearched = true;//from w ww .java2s .  c o  m
                getLoaderManager().restartLoader(0, null, loaderCallBack);
                if (queryText == null) {
                    searchField.setText(searchHint);
                }
                return true;
            }
            return false;
        }
    });
    // afichage d'une croix dans l'edit text pour effacer le texte saisie
    final Drawable x = getResources().getDrawable(R.drawable.ic_cancel);
    x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight());
    searchField.setCompoundDrawables(null, null, x, null);
    searchField.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN
                    && searchHint.equals(searchField.getText().toString())) {
                searchField.setText("");
            }
            if (searchField.getCompoundDrawables()[2] == null) {
                // cross is not being shown so no need to handle
                return false;
            }
            if (event.getAction() != MotionEvent.ACTION_DOWN) {
                // only respond to the down type
                return false;
            }
            if (event.getX() > searchField.getMeasuredWidth() - searchField.getPaddingRight()
                    - x.getIntrinsicWidth()) {
                searchField.setText("");
                return true;
            } else {
                return false;
            }
        }
    });
}