Example usage for android.graphics.drawable BitmapDrawable getIntrinsicHeight

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

Introduction

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

Prototype

@Override
    public int getIntrinsicHeight() 

Source Link

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static int PutImageScale(Canvas canvas, Drawable image, double Angle, int x, int y, double scale) {

    if (scale == 0.0)
        return 0;

    float newWidth = (int) Math.round((float) image.getIntrinsicWidth() * scale);
    float newHeight = (int) Math.round((float) image.getIntrinsicHeight() * scale);

    Bitmap bmp = ((BitmapDrawable) image).getBitmap();
    int width = bmp.getWidth();
    int height = bmp.getHeight();

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // createa matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // rotate the Bitmap
    matrix.postRotate((float) Angle);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
    // make a Drawable from Bitmap to allow to set the BitMap
    // to the ImageView, ImageButton or what ever
    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

    bmd.setBounds(x, y, x + bmd.getIntrinsicWidth(), y + bmd.getIntrinsicHeight());
    bmd.draw(canvas);/*  w  w  w  .  j a  v  a2 s  . co  m*/

    return bmd.getIntrinsicWidth();

}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int PutImageTargetHeight(Canvas canvas, Drawable image, double Angle, int x, int y,
        int newHeight) {

    float scale = (float) newHeight / (float) image.getIntrinsicHeight();
    float newWidth = (int) Math.round((float) image.getIntrinsicWidth() * scale);

    Bitmap bmp = ((BitmapDrawable) image).getBitmap();
    int width = bmp.getWidth();
    int height = bmp.getHeight();

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // createa matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // rotate the Bitmap
    matrix.postRotate((float) Angle);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
    // make a Drawable from Bitmap to allow to set the BitMap
    // to the ImageView, ImageButton or what ever
    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

    bmd.setBounds(x, y, x + bmd.getIntrinsicWidth(), y + bmd.getIntrinsicHeight());
    bmd.draw(canvas);// w  w  w .  j  ava2s. co m

    return bmd.getIntrinsicWidth();

}

From source file:Main.java

public static CharSequence addIcon(CharSequence total, BitmapDrawable bitmapDrawable, int height) {
    SpannableString string = new SpannableString("  ");
    ImageSpan imageSpan = new ImageSpan(bitmapDrawable);

    int width = (int) (height
            / (bitmapDrawable.getIntrinsicHeight() / (float) bitmapDrawable.getIntrinsicWidth()));

    imageSpan.getDrawable().setBounds(0, 0, width, height);
    string.setSpan(imageSpan, 0, 1, 0);/*ww w . ja v  a  2  s .c  o m*/
    if (total == null) {
        return string;
    } else {
        return TextUtils.concat(total, string);
    }
}

From source file:org.jitsi.android.gui.util.DrawableCache.java

/**
 * Gets cached <tt>BitmapDrawable</tt> for given <tt>resId</tt>. If it
 * doesn't exist in the cache it will be loaded and stored for later use.
 *
 * @param resId bitmap drawable resource id(it must be bitmap resource)
 *
 * @return <tt>BitmapDrawable</tt> for given <tt>resId</tt>
 *
 * @throws Resources.NotFoundException if there's no bitmap for given
 *                                     <tt>resId</tt>
 *///from w ww.j av  a 2s.  c  o m
public BitmapDrawable getBitmapFromMemCache(Integer resId) throws Resources.NotFoundException {
    String key = "res:" + resId;
    // Check for cached bitmap
    BitmapDrawable img = cache.get(key);
    // Eventually loads the bitmap
    if (img == null) {
        // Load and store the bitmap
        Resources res = JitsiApplication.getAppResources();
        Bitmap bmp = BitmapFactory.decodeResource(res, resId);
        img = new BitmapDrawable(res, bmp);
        img.setBounds(0, 0, img.getIntrinsicWidth(), img.getIntrinsicHeight());
        cache.put(key, img);
    }
    return cache.get(key);
}

From source file:com.nononsenseapps.feeder.model.ImageTextLoader.java

/**
 *
 * @return a Drawable with a youtube logo in the center
 *///ww  w.  j  a v  a  2 s.  c o m
protected Drawable getYoutubeThumb(final com.nononsenseapps.text.VideoTagHunter.Video video) {
    Drawable[] layers = new Drawable[2];

    int w1, h1;
    try {
        //final Bitmap b = p.load(video.imageurl).tag(ImageTextLoader.this).get();
        final Bitmap b = g.load(video.imageurl).asBitmap().fitCenter().into(maxSize.x, maxSize.y).get();
        //final Point newSize = scaleImage(b.getWidth(), b.getHeight());
        w1 = b.getWidth();
        h1 = b.getHeight();
        final BitmapDrawable d = new BitmapDrawable(getContext().getResources(), b);
        Log.d("JONASYOUTUBE", "Bounds: " + d.getIntrinsicWidth() + ", " + "" + d.getIntrinsicHeight() + " vs "
                + w1 + ", " + h1);
        // Settings bounds later
        //d.setBounds(0, 0, w1, h1);
        // Set in layer
        layers[0] = d;
    } catch (InterruptedException | ExecutionException e) {
        Log.e("JONASYOUTUBE", "" + e.getMessage());
        throw new NullPointerException(e.getLocalizedMessage());
    }

    // Add layer with play icon
    final Drawable playicon = getContext().getResources().getDrawable(R.drawable.youtube_icon);
    // 20% size, in middle
    int w2 = playicon.getIntrinsicWidth();
    int h2 = playicon.getIntrinsicHeight();

    final double ratio = ((double) h2) / ((double) w2);

    // Start with width which is known
    final double relSize = 0.2;
    w2 = (int) (relSize * w1);
    final int left = (int) (((double) (w1 - w2)) / 2.0);
    // Then height is simple
    h2 = (int) (ratio * w2);
    final int top = (int) (((double) (h1 - h2)) / 2.0);

    Log.d("JONASYOUTUBE", "l t w h: " + left + " " + top + " " + w2 + " " + h2);

    // And add to layer
    layers[1] = playicon;
    final LayerDrawable ld = new LayerDrawable(layers);
    // Need to set bounds on outer drawable first as it seems to override
    // child bounds
    ld.setBounds(0, 0, w1, h1);
    // Now set smaller bounds on youtube icon
    playicon.setBounds(left, top, left + w2, top + h2);
    return ld;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.TracksDropdownFragment.java

private void loadTrack(Cursor cursor, boolean triggerCallback) {
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);

        mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

        String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME);

        mTitle.setText(trackName);//from ww  w .java 2s  .c  o  m
        mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

        int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable",
                getActivity().getPackageName());
        if (iconResId != 0) {
            BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId);
            Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(),
                    sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(icon);
            sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight());
            sourceIconDrawable.draw(canvas);
            BitmapDrawable iconDrawable = new BitmapDrawable(res, icon);
            mIcon.setImageDrawable(iconDrawable);
        } else {
            mIcon.setImageDrawable(null);
        }
    } else {
        trackColor = res.getColor(R.color.all_track_color);
        mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID;

        mIcon.setImageDrawable(null);
        switch (mViewType) {
        case VIEW_TYPE_SESSIONS:
            mTitle.setText(R.string.all_tracks_sessions);
            mAbstract.setText(R.string.all_tracks_subtitle_sessions);
            break;
        case VIEW_TYPE_SANDBOX:
            mTitle.setText(R.string.all_tracks_sandbox);
            mAbstract.setText(R.string.all_tracks_subtitle_sandbox);
            break;
        }
    }

    mRootView.setBackgroundColor(trackColor);
    mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString());

    if (triggerCallback) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCallbacks.onTrackSelected(mTrackId);
            }
        });
    }
}

From source file:com.conferenceengineer.android.iosched.ui.tablet.TracksDropdownFragment.java

private void loadTrack(Cursor cursor, boolean triggerCallback) {
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);

        mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

        String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME);

        mTitle.setText(trackName);//from   www .  j  a v  a 2  s  .  com
        mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

        int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable",
                getActivity().getPackageName());
        if (iconResId != 0) {
            BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId);
            Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(),
                    sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(icon);
            sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight());
            sourceIconDrawable.draw(canvas);
            BitmapDrawable iconDrawable = new BitmapDrawable(res, icon);
            mIcon.setImageDrawable(iconDrawable);
        } else {
            mIcon.setImageDrawable(null);
        }
    } else {
        trackColor = res.getColor(R.color.all_track_color);
        mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID;

        mIcon.setImageDrawable(null);
        switch (mViewType) {
        case VIEW_TYPE_SESSIONS:
            mTitle.setText(R.string.all_tracks_sessions);
            mAbstract.setText(R.string.all_tracks_subtitle_sessions);
            break;
        case VIEW_TYPE_OFFICE_HOURS:
            mTitle.setText(R.string.all_tracks_office_hours);
            mAbstract.setText(R.string.all_tracks_subtitle_office_hours);
            break;
        case VIEW_TYPE_SANDBOX:
            mTitle.setText(R.string.all_tracks_sandbox);
            mAbstract.setText(R.string.all_tracks_subtitle_sandbox);
            break;
        }
    }

    mRootView.setBackgroundColor(trackColor);
    mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString());

    if (triggerCallback) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCallbacks.onTrackSelected(mTrackId);
            }
        });
    }
}

From source file:tv.acfun.video.CommentsActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    int count = mAdapter.getCount();
    if (position > count) {
        if (isreload) {
            mFootview.findViewById(R.id.list_footview_progress).setVisibility(View.VISIBLE);
            TextView textview = (TextView) mFootview.findViewById(R.id.list_footview_text);
            textview.setText(R.string.buffering);
            requestData(pageIndex, false);
        }//from  w w  w  . j a v  a2 s .c  o  m
        return;
    }
    //        showBar(); //TODO: show input bar when selected comment
    Object o = parent.getItemAtPosition(position);
    if (o == null || !(o instanceof Comment))
        return;
    Comment c = (Comment) o;
    int quoteCount = getQuoteCount();
    removeQuote(mCommentText.getText());
    if (quoteCount == c.count)
        return; // ?
    String pre = ":#" + c.count;
    mQuoteSpan = new Quote(c.count);
    SpannableStringBuilder sb = SpannableStringBuilder.valueOf(mCommentText.getText());
    TextView tv = TextViewUtils.createBubbleTextView(this, pre);
    BitmapDrawable bd = (BitmapDrawable) TextViewUtils.convertViewToDrawable(tv);
    bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
    sb.insert(0, pre);
    mQuoteImage = new ImageSpan(bd);
    sb.setSpan(mQuoteImage, 0, pre.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.setSpan(mQuoteSpan, 0, pre.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.append("");
    mCommentText.setText(sb);
    mCommentText.setSelection(mCommentText.getText().length());
}

From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java

private void displaySplash() {
    // Don't show the splash screen if this app appears to be registered
    if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
            .getString(InformOnlineState.DEVICE_ID, null) instanceof String) {
        return;/*  w  ww. j a  va 2s  .c om*/
    }

    // Fetch the splash screen Drawable
    Drawable image = null;

    try {
        // Attempt to load the configured default splash screen
        // The following code only works in 1.6+
        // BitmapDrawable bitImage = new BitmapDrawable(getResources(), FileUtils.SPLASH_SCREEN_FILE_PATH);
        BitmapDrawable bitImage = new BitmapDrawable(
                FileUtilsExtended.EXTERNAL_FILES + File.separator + FileUtilsExtended.SPLASH_SCREEN_FILE);

        if (bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0
                && bitImage.getIntrinsicWidth() > 0) {
            image = bitImage;
        }
    } catch (Exception e) {
        // TODO: log exception for debugging?
    }

    // TODO: rework
    if (image == null) {
        // no splash provided...
        //            if (FileUtils.storageReady() && !((new File(FileUtils.DEFAULT_CONFIG_PATH)).exists())) {
        // Show the built-in splash image if the config directory 
        // does not exist. Otherwise, suppress the icon.
        image = getResources().getDrawable(R.drawable.gc_color);
        //            }

        if (image == null)
            return;
    }

    // Create ImageView to hold the Drawable...
    ImageView view = new ImageView(getApplicationContext());

    // Initialise it with Drawable and full-screen layout parameters
    view.setImageDrawable(image);

    int width = getWindowManager().getDefaultDisplay().getWidth();
    int height = getWindowManager().getDefaultDisplay().getHeight();

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height, 0);

    view.setLayoutParams(lp);
    view.setScaleType(ScaleType.CENTER);
    view.setBackgroundColor(Color.WHITE);

    // And wrap the image view in a frame layout so that the full-screen layout parameters are honoured
    FrameLayout layout = new FrameLayout(getApplicationContext());
    layout.addView(view);

    // Create the toast and set the view to be that of the FrameLayout
    mSplashToast = Toast.makeText(getApplicationContext(), "splash screen", Toast.LENGTH_LONG);
    mSplashToast.setView(layout);
    mSplashToast.setGravity(Gravity.CENTER, 0, 0);
    mSplashToast.show();
}

From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java

private Bitmap combineDrawablesToBitmap(final Drawable backgroundImage, final BitmapDrawable overlayImage,
        int width, int height) {

    Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    // Create a canvas, that will draw on to canvasBitmap.
    Canvas imageCanvas = new Canvas(canvasBitmap);

    // Draw the image to our canvas
    backgroundImage.setBounds(0, 0, width, height);
    backgroundImage.draw(imageCanvas);/*from  w w w  .j  a  v a 2 s .com*/
    overlayImage.setBounds(0, 0, (int) (overlayImage.getIntrinsicWidth() * 0.5),
            (int) (overlayImage.getIntrinsicHeight() * 0.5));
    final int scaleWidth = 24;
    final int scaleHeight = 24;
    final float scaleWidthPercent = ((float) scaleWidth) / overlayImage.getIntrinsicWidth();
    final float scaleHeightPercent = ((float) scaleHeight) / overlayImage.getIntrinsicHeight();
    ScaleDrawable scaleDrawable = new ScaleDrawable(overlayImage, 0, scaleWidthPercent, scaleHeightPercent);
    Drawable scaledOverlay = scaleDrawable.getDrawable();
    scaledOverlay.setBounds(0, 0, width, height);
    scaledOverlay.draw(imageCanvas);

    // Combine background and text to a LayerDrawable
    LayerDrawable layerDrawable = new LayerDrawable(
            new Drawable[] { backgroundImage, new BitmapDrawable(canvasBitmap) });
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    layerDrawable.setBounds(0, 0, width, height);
    layerDrawable.draw(new Canvas(newBitmap));
    return newBitmap;
}