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.vuze.android.remote.activity.LoginActivity.java

private void setupGuideText(TextView tvLoginGuide) {
    AndroidUtilsUI.linkify(tvLoginGuide);
    CharSequence text = tvLoginGuide.getText();

    SpannableStringBuilder ss = new SpannableStringBuilder(text);
    String string = text.toString();

    new SpanBubbles().setSpanBubbles(ss, string, "|", tvLoginGuide.getPaint(),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_text_color),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_textbubble_color),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_text_color));

    int indexOf = string.indexOf("@@");
    if (indexOf >= 0) {
        int style = ImageSpan.ALIGN_BASELINE;
        int newHeight = tvLoginGuide.getBaseline();
        if (newHeight <= 0) {
            newHeight = tvLoginGuide.getLineHeight();
            style = ImageSpan.ALIGN_BOTTOM;
            if (newHeight <= 0) {
                newHeight = 20;//from   w w w .jav a2  s  .  c om
            }
        }
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.guide_icon);
        int oldWidth = drawable.getIntrinsicWidth();
        int oldHeight = drawable.getIntrinsicHeight();
        int newWidth = (oldHeight > 0) ? (oldWidth * newHeight) / oldHeight : newHeight;
        drawable.setBounds(0, 0, newWidth, newHeight);

        ImageSpan imageSpan = new ImageSpan(drawable, style);
        ss.setSpan(imageSpan, indexOf, indexOf + 2, 0);
    }

    tvLoginGuide.setText(ss);
}

From source file:com.androidformenhancer.helper.FormHelper.java

private void setDrawableIntrinsicBounds(final Drawable d) {
    if (d != null) {
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }//from  w w  w . jav  a2s .co  m
}

From source file:com.chrisrenke.giv.GravityImageView.java

private void updateMatrix(int viewWidth, int viewHeight) {
    Drawable drawable = getDrawable();
    // If we're in the constructor pass, ignore this for now.
    if (drawable == null || matrix == null)
        return;// w  ww . j a v  a  2s. co  m

    matrix.reset();
    imageRect.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

    // Adjust the matrix to center the image and scale as needed.
    applyCenterAndScaleMode(viewWidth, viewHeight);

    // Adjust the matrix for the imageGravity position
    applyGravity(viewWidth, viewHeight);

    // Apply the matrix changes.
    setImageMatrix(matrix);
}

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

/**
 * Initializes the activity, filling in the data from the Intent.
 * @param savedInstanceState Contains information about the saved state of the activity
 *//*from   w ww  . j av  a 2 s.c o  m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    //Initialize the views
    TextView sportsTitle = (TextView) findViewById(R.id.titleDetail);
    ImageView sportsImage = (ImageView) findViewById(R.id.sportsImageDetail);

    //Get the drawable
    Drawable drawable = ContextCompat.getDrawable(this, getIntent().getIntExtra(Sport.IMAGE_KEY, 0));

    //Create a placeholder gray scrim while the image loads
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(Color.GRAY);

    //Make it the same size as the image
    if (drawable != null) {
        gradientDrawable.setSize(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    }

    //Set the text from the Intent extra
    sportsTitle.setText(getIntent().getStringExtra(Sport.TITLE_KEY));

    //Load the image using the glide library and the Intent extra
    Glide.with(this).load(getIntent().getIntExtra(Sport.IMAGE_KEY, 0)).placeholder(gradientDrawable)
            .into(sportsImage);
}

From source file:com.lee.sdk.widget.viewpager.PointPageIndicator.java

/**
 * Set the point drawable/*from  w  w  w.j a  va 2 s . co  m*/
 * 
 * @param normal normal drawable
 * @param select selected drawable
 * @return this;
 */
public PointPageIndicator setPointDrawable(Drawable normal, Drawable select) {
    mNormalDrawable = normal;
    mSelectDrawable = select;

    if (normal instanceof BitmapDrawable) {
        mNormalPointRect.set(0, 0, normal.getIntrinsicWidth(), normal.getIntrinsicHeight());
    }

    if (select instanceof BitmapDrawable) {
        mSelectPointRect.set(0, 0, select.getIntrinsicWidth(), select.getIntrinsicHeight());
    }

    return this;
}

From source file:com.ape.cloudfile.widget.vpi.TabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId, int count) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*w  ww  .  ja  v a  2 s.  com*/
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    tabView.setGravity(Gravity.CENTER);
    tabView.setPadding(0, 15, 0, 15);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    tabView.setTextColor(getResources().getColorStateList(R.color.myos_tab_text_color));

    //        if (iconResId != 0) {
    //            tabView.setCompoundDrawablesWithIntrinsicBounds(0, iconResId, 0, 0);
    //        }

    if (count > 1) {
        tabView.setBackgroundResource(R.drawable.action_tab_background);
    } else {
        tabView.setBackgroundResource(R.drawable.tinno_title_bg_holo_light);
        tabView.setTextColor(getResources().getColor(R.color.tab_bar_title_color));
        tabView.setPadding(20, 0, 0, 0);
        tabView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        Drawable drawable = getResources().getDrawable(R.drawable.title_panel_back);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        tabView.setCompoundDrawables(drawable, null, null, null);
    }

    //add by zjw
    //        if(index == 0)
    //        {
    //           tabView.setBackgroundResource(R.drawable.title_bar_left_selector);
    //        }else if(index == (count - 1))
    //        {
    //           tabView.setBackgroundResource(R.drawable.title_bar_right_selector);
    //        }else
    //        {
    //           tabView.setBackgroundResource(R.drawable.title_bar_middle_selector);
    //        }

    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:fr.simon.marquis.secretcodes.util.ExportContentProvider.java

private void saveImageFiles(ArrayList<SecretCode> secretCodes) {
    for (SecretCode secretCode : secretCodes) {
        try {/*  ww  w  . j  a va  2  s.c o  m*/
            if (secretCode.getDrawableResource() == 0) {
                continue;
            }
            Drawable drawable = getContext().getPackageManager().getDrawable(secretCode.getPackageManager(),
                    secretCode.getDrawableResource(), null);
            if (drawable == null) {
                continue;
            }
            int height = drawable.getIntrinsicHeight();
            int width = drawable.getIntrinsicWidth();
            Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            if (createBitmap == null) {
                continue;
            }
            Canvas canvas = new Canvas(createBitmap);
            drawable.setBounds(0, 0, width, height);
            drawable.draw(canvas);

            FileOutputStream openFileOutput = getContext().openFileOutput(secretCode.getCode() + ".png",
                    Context.MODE_PRIVATE);
            createBitmap.compress(Bitmap.CompressFormat.PNG, 100, openFileOutput);
            openFileOutput.flush();
            openFileOutput.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.common.widget.pageindicator.C_TabPageIndicator.java

/**
 * Icon? // w ww  .jav a 2s.  c  o m
 *
 * @param view
 * @param iconResId
 */
private void setTabIcon(TextView view, int iconResId) {
    Drawable drawable = context.getResources().getDrawable(iconResId);
    int h = drawable.getIntrinsicHeight(); // 
    int hs = drawable.getMinimumHeight(); // 
    // int crop = h - hs; // ?
    int crop = h / 5;
    Rect cRect = new Rect(crop, crop, h - crop, h - crop);// ?
    // drawable.setBounds(crop, crop, h - crop, h - crop); // 
    // view.setCompoundDrawablesWithIntrinsicBounds(0, drawable, 0, 0);
    // view.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end,
    view.setCompoundDrawables(null, drawable, null, null);
}

From source file:org.gateshipone.odyssey.playbackservice.managers.OdysseyNotificationManager.java

public void updateNotification(TrackModel track, PlaybackService.PLAYSTATE state,
        MediaSessionCompat.Token mediaSessionToken) {
    if (track != null) {
        mNotificationBuilder = new NotificationCompat.Builder(mContext);

        // Open application intent
        Intent contentIntent = new Intent(mContext, OdysseyMainActivity.class);
        contentIntent.putExtra(OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW,
                OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW);
        contentIntent.addFlags(/*from  w  w  w  .j  a v a 2 s  . co m*/
                Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY);
        PendingIntent contentPendingIntent = PendingIntent.getActivity(mContext, NOTIFICATION_INTENT_OPENGUI,
                contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setContentIntent(contentPendingIntent);

        // Set pendingintents
        // Previous song action
        Intent prevIntent = new Intent(PlaybackService.ACTION_PREVIOUS);
        PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PREVIOUS,
                prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build();

        // Pause/Play action
        PendingIntent playPauseIntent;
        int playPauseIcon;
        if (state == PlaybackService.PLAYSTATE.PLAYING) {
            Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE);
            playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, pauseIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_pause_48dp;
        } else {
            Intent playIntent = new Intent(PlaybackService.ACTION_PLAY);
            playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, playIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_play_arrow_48dp;
        }
        NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon,
                "PlayPause", playPauseIntent).build();

        // Next song action
        Intent nextIntent = new Intent(PlaybackService.ACTION_NEXT);
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_NEXT,
                nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build();

        // Quit action
        Intent quitIntent = new Intent(PlaybackService.ACTION_QUIT);
        PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_QUIT,
                quitIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setDeleteIntent(quitPendingIntent);

        mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mNotificationBuilder.setSmallIcon(R.drawable.odyssey_notification);
        mNotificationBuilder.addAction(prevAction);
        mNotificationBuilder.addAction(playPauseAction);
        mNotificationBuilder.addAction(nextAction);
        NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle();
        notificationStyle.setShowActionsInCompactView(1, 2);
        notificationStyle.setMediaSession(mediaSessionToken);
        mNotificationBuilder.setStyle(notificationStyle);
        mNotificationBuilder.setContentTitle(track.getTrackName());
        mNotificationBuilder.setContentText(track.getTrackArtistName());

        // Remove unnecessary time info
        mNotificationBuilder.setWhen(0);

        // Cover but only if changed
        if (mLastTrack == null || !track.getTrackAlbumKey().equals(mLastTrack.getTrackAlbumKey())) {
            mLastTrack = track;
            mLastBitmap = null;
        }

        // Only set image if an saved one is available
        if (mLastBitmap != null) {
            mNotificationBuilder.setLargeIcon(mLastBitmap);
        } else {
            /**
             * Create a dummy placeholder image for versions greater android 7 because it
             * does not automatically show the application icon anymore in mediastyle notifications.
             */
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Drawable icon = mContext.getDrawable(R.drawable.notification_placeholder_256dp);

                Bitmap iconBitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(iconBitmap);
                DrawFilter filter = new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, 1);

                canvas.setDrawFilter(filter);
                icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                icon.setFilterBitmap(true);

                icon.draw(canvas);
                mNotificationBuilder.setLargeIcon(iconBitmap);

            } else {
                /**
                 * For older android versions set the null icon which will result in a dummy icon
                 * generated from the application icon.
                 */
                mNotificationBuilder.setLargeIcon(null);

            }
        }

        // Build the notification
        mNotification = mNotificationBuilder.build();

        // Check if run from service and check if playing or pause.
        // Pause notification should be dismissible.
        if (mContext instanceof Service) {
            if (state == PlaybackService.PLAYSTATE.PLAYING) {
                ((Service) mContext).startForeground(NOTIFICATION_ID, mNotification);
            } else {
                ((Service) mContext).stopForeground(false);
            }
        }

        // Send the notification away
        mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    }

}

From source file:com.coco.flowimageview.FlowImageView.java

private void initFlow() {
    Drawable drawable = getDrawable();
    if (drawable != null) {
        final float viewWidth = getWidth();
        final float viewHeight = getHeight();
        final float imgWidth = drawable.getIntrinsicWidth();
        final float imgHeight = drawable.getIntrinsicHeight();
        mScale = viewHeight / imgHeight;
        mTranslateXEnd = viewWidth - imgWidth * mScale;
        mIsFlowInited = true;/*from w  ww. j  ava2s .com*/
        setImageMatrix();
    } else {
        mIsFlowInited = false;
    }
}