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.stoneapp.ourvlemoodle2.adapters.PostListAdapter.java

@Override
public void onBindViewHolder(PostListViewHolder holder, int position) {

    MoodlePost post = postList.get(position);

    String subject = post.getSubject();
    if (!TextUtils.isEmpty(subject))
        holder.getSubjectView().setText(subject);

    String username = post.getUserfullname();
    if (!TextUtils.isEmpty(username))
        holder.getUserNameView().setText(username);

    String message = post.getMessage();
    if (!TextUtils.isEmpty(message))
        holder.getMessageView().setText(message);

    //Extracts image from string to show in text view
    CharSequence format_message = Html.fromHtml(message, new Html.ImageGetter() {
        @Override//from ww  w.ja  va2 s  . c  om
        public Drawable getDrawable(String source) {
            try {
                //InputStream is = (InputStream) new URL(source).getContent();
                //Drawable d = Drawable.createFromStream(is, "sc name");
                //d.setBounds(0,0,50,50);
                //return d;
                Drawable drawFromPath;
                int path = context.getResources().getIdentifier(source, "drawable", context.getPackageName());
                drawFromPath = ContextCompat.getDrawable(context, path);
                drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(),
                        drawFromPath.getIntrinsicHeight());
                return drawFromPath;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }, null);

    if (!TextUtils.isEmpty(message))
        holder.getMessageView().setText(format_message);

    int time = post.getModified();
    holder.getPostTimeView().setText(TimeUtils.getTime(time));

    char firstLetter = username.toUpperCase().charAt(0);
    ColorGenerator generator = ColorGenerator.MATERIAL;
    int color2 = generator.getColor(username);
    TextDrawable drawable2 = TextDrawable.builder().beginConfig().textColor(Color.WHITE)
            .useFont(Typeface.DEFAULT).toUpperCase().endConfig().buildRound(firstLetter + "", color2);

    holder.getPostImageView().setImageDrawable(drawable2);
}

From source file:com.shizhefei.view.largeimage.UpdateImageView.java

private void resizeFromDrawable() {
    Drawable d = mDrawable;
    if (d != null) {
        int w = d.getIntrinsicWidth();
        if (w < 0)
            w = mDrawableWidth;//w  w w  .  j  a  v  a 2  s  .  c  o  m
        int h = d.getIntrinsicHeight();
        if (h < 0)
            h = mDrawableHeight;
        if (w != mDrawableWidth || h != mDrawableHeight) {
            mDrawableWidth = w;
            mDrawableHeight = h;
            requestLayout();
        }
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsLinearLayout.java

/**
 * Set a drawable to be used as a divider between items.
 * @param divider Drawable that will divide each item.
 * @see #setShowDividers(int)// www  . j a  va 2  s  . c  o  m
 */
public void setDividerDrawable(Drawable divider) {
    if (divider == mDivider) {
        return;
    }
    mDivider = divider;
    if (divider != null) {
        mDividerWidth = divider.getIntrinsicWidth();
        mDividerHeight = divider.getIntrinsicHeight();
    } else {
        mDividerWidth = 0;
        mDividerHeight = 0;
    }
    setWillNotDraw(divider == null);
    requestLayout();
}

From source file:com.trellmor.berrymotes.EmoteGetter.java

@Override
public Drawable getDrawable(String source) {
    if (mBlacklist.contains(source))
        return null;

    Drawable d = mCache.get(source);
    if (d != null)
        return d;

    AnimationEmode ae = mAnimationCache.get(source);
    if (ae != null) {
        try {//  w w w . j  a  va  2s  .co m
            d = ae.newDrawable();
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            return d;
        } catch (OutOfMemoryError e) {
            return null;
        }
    }

    Cursor cursor = mResolver.query(EmotesContract.Emote.CONTENT_URI, PROJECTION,
            EmotesContract.Emote.COLUMN_NAME + "=?", new String[] { source },
            EmotesContract.Emote.COLUMN_INDEX + " ASC");

    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();

        final int POS_IMAGE = cursor.getColumnIndex(EmotesContract.Emote.COLUMN_IMAGE);

        if (cursor.getCount() > 1
                && cursor.getInt(cursor.getColumnIndex(EmotesContract.Emote.COLUMN_APNG)) == 1) {

            // Create AnimationDrawable
            ae = new AnimationEmode();

            final int POS_DELAY = cursor.getColumnIndex(EmotesContract.Emote.COLUMN_DELAY);

            try {
                do {
                    String path = cursor.getString(POS_IMAGE);
                    Drawable frame = mLoader.fromPath(path);
                    if (frame != null) {
                        ae.addFrame(frame, cursor.getInt(POS_DELAY));
                    }
                } while (cursor.moveToNext());
                d = ae.newDrawable();
                mAnimationCache.put(source, ae);
            } catch (OutOfMemoryError e) {
                d = null;
                mBlacklist.add(source);
                Log.e(TAG, "Failed to load " + source, e);
            }
        } else {
            String path = cursor.getString(POS_IMAGE);
            try {
                d = mLoader.fromPath(path);
            } catch (OutOfMemoryError e) {
                d = null;
                mBlacklist.add(source);
                Log.e(TAG, "Failed to load " + source, e);
            }
            if (d != null) {
                mCache.put(source, d);
            }
        }
    }

    if (cursor != null)
        cursor.close();

    if (d != null) {
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }
    return d;
}

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 a2  s.  c  o m*/

    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:self.philbrown.droidQuery.AsyncImageGetter.java

/**
 * Gets the drawable from the given URL resource, or from the local file path.
 * @param source the URL of the drawable, or the local file path to the image.
 *//*from   w w w  .  j  a  v a  2  s .c o  m*/
public Drawable getDrawable(String source) {

    if (URLUtil.isValidUrl(source)) {
        //need to download image
        URLDrawable urlDrawable = new URLDrawable();

        // get the actual source
        ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable);

        asyncTask.execute(source);

        // return reference to URLDrawable where I will change with actual image from
        // the src tag
        return urlDrawable;
    } else {
        //must be a local reference
        Drawable drawFromPath;
        int path = c.getResources().getIdentifier(source, "drawable", c.getApplicationInfo().packageName);
        if (path == 0) {
            return new TextDrawable("Could not set image");
        }
        drawFromPath = (Drawable) c.getResources().getDrawable(path);
        drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(), drawFromPath.getIntrinsicHeight());
        return drawFromPath;
    }

}

From source file:com.tct.mail.browse.SubjectAndFolderView.java

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;//from w w w  . j  a  v  a  2 s  .com
    final BidiFormatter bidiFormatter = getBidiFormatter();
    if (TextUtils.isEmpty(mSubject)) {
        mSubject = conv.subject;
    }
    final SpannableStringBuilder sb = new SpannableStringBuilder(bidiFormatter.unicodeWrap(mSubject));
    sb.append('\u0020');
    final Settings settings = account.settings;
    final int start = sb.length();
    if (settings.importanceMarkersEnabled && conv.isImportant()) {
        sb.append(".\u0020");
        sb.setSpan(new DynamicDrawableSpan(DynamicDrawableSpan.ALIGN_BASELINE) {
            @Override
            public Drawable getDrawable() {
                Drawable d = getContext().getResources()
                        .getDrawable(R.drawable.ic_email_caret_none_important_unread);
                d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                return d;
            }
        }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_S
    //        mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */);
    //        mFolderDisplayer.appendFolderSpans(sb, bidiFormatter);

    //        final int end = sb.length();
    //        sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    setText(sb);
    //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_S
    //        if(isNeedMove()){
    //            setMovementMethod(LinkMovementMethod.getInstance());
    //        }
    //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_E
    //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_E
}

From source file:android.support.v7.preference.PreferenceDialogFragmentCompat.java

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

    final Fragment rawFragment = getTargetFragment();
    if (!(rawFragment instanceof DialogPreference.TargetFragment)) {
        throw new IllegalStateException("Target fragment must implement TargetFragment" + " interface");
    }/*from   w  w w.  j  a  v a 2s  . c  o  m*/

    final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;

    final String key = getArguments().getString(ARG_KEY);
    if (savedInstanceState == null) {
        mPreference = (DialogPreference) fragment.findPreference(key);
        mDialogTitle = mPreference.getDialogTitle();
        mPositiveButtonText = mPreference.getPositiveButtonText();
        mNegativeButtonText = mPreference.getNegativeButtonText();
        mDialogMessage = mPreference.getDialogMessage();
        mDialogLayoutRes = mPreference.getDialogLayoutResource();

        final Drawable icon = mPreference.getDialogIcon();
        if (icon == null || icon instanceof BitmapDrawable) {
            mDialogIcon = (BitmapDrawable) icon;
        } else {
            final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
            icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            icon.draw(canvas);
            mDialogIcon = new BitmapDrawable(getResources(), bitmap);
        }
    } else {
        mDialogTitle = savedInstanceState.getCharSequence(SAVE_STATE_TITLE);
        mPositiveButtonText = savedInstanceState.getCharSequence(SAVE_STATE_POSITIVE_TEXT);
        mNegativeButtonText = savedInstanceState.getCharSequence(SAVE_STATE_NEGATIVE_TEXT);
        mDialogMessage = savedInstanceState.getCharSequence(SAVE_STATE_MESSAGE);
        mDialogLayoutRes = savedInstanceState.getInt(SAVE_STATE_LAYOUT, 0);
        final Bitmap bitmap = savedInstanceState.getParcelable(SAVE_STATE_ICON);
        if (bitmap != null) {
            mDialogIcon = new BitmapDrawable(getResources(), bitmap);
        }
    }
}

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

/**
 *
 * @return a Drawable with a youtube logo in the center
 *///from  ww w  .  ja  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.boha.malengagolf.library.util.PagerTitleStrip22.java

int getMinHeight() {
    int minHeight = 0;
    final Drawable bg = getBackground();
    if (bg != null) {
        minHeight = bg.getIntrinsicHeight();
    }//from w  w w. ja  v  a  2  s.c o m
    return minHeight;
}