Example usage for android.graphics.drawable Drawable getIntrinsicWidth

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

Introduction

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

Prototype

public int getIntrinsicWidth() 

Source Link

Document

Returns the drawable's intrinsic width.

Usage

From source file:com.android.mail.browse.ConversationPagerController.java

private void setupPageMargin(Context c) {
    final TypedArray a = c.obtainStyledAttributes(new int[] { android.R.attr.listDivider });
    final Drawable divider = a.getDrawable(0);
    a.recycle();//from w ww  .j a v a2  s  .  c om
    final int padding = c.getResources().getDimensionPixelOffset(R.dimen.conversation_page_gutter);
    final Drawable gutterDrawable = new PageMarginDrawable(divider, padding, 0, padding, 0,
            c.getResources().getColor(R.color.conversation_view_background_color));
    mPager.setPageMargin(gutterDrawable.getIntrinsicWidth() + 2 * padding);
    mPager.setPageMarginDrawable(gutterDrawable);
}

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(/* w  w  w  .ja v a  2s .  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.dycody.android.idealnote.SketchFragment.java

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

    getMainActivity().getToolbar().setNavigationOnClickListener(v -> getActivity().onBackPressed());

    mSketchView.setOnDrawChangedListener(this);

    Uri baseUri = getArguments().getParcelable("base");
    if (baseUri != null) {
        Bitmap bmp;//w  ww.  jav  a  2s.  c  o  m
        try {
            bmp = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(baseUri));
            mSketchView.setBackgroundBitmap(getActivity(), bmp);
        } catch (FileNotFoundException e) {
            Log.e(Constants.TAG, "Error replacing sketch bitmap background", e);
        }
    }

    // Show the Up button in the action bar.
    if (getMainActivity().getSupportActionBar() != null) {
        getMainActivity().getSupportActionBar().setDisplayShowTitleEnabled(true);
        getMainActivity().getSupportActionBar().setTitle(R.string.title_activity_sketch);
        getMainActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    stroke.setOnClickListener(v -> {
        if (mSketchView.getMode() == SketchView.STROKE) {
            showPopup(v, SketchView.STROKE);
        } else {
            mSketchView.setMode(SketchView.STROKE);
            AlphaManager.setAlpha(eraser, 0.4f);
            AlphaManager.setAlpha(stroke, 1f);
        }
    });

    AlphaManager.setAlpha(eraser, 0.4f);
    eraser.setOnClickListener(v -> {
        if (mSketchView.getMode() == SketchView.ERASER) {
            showPopup(v, SketchView.ERASER);
        } else {
            mSketchView.setMode(SketchView.ERASER);
            AlphaManager.setAlpha(stroke, 0.4f);
            AlphaManager.setAlpha(eraser, 1f);
        }
    });

    undo.setOnClickListener(v -> mSketchView.undo());

    redo.setOnClickListener(v -> mSketchView.redo());

    erase.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            askForErase();
        }

        private void askForErase() {
            new MaterialDialog.Builder(getActivity()).content(R.string.erase_sketch)
                    .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            mSketchView.erase();
                        }
                    }).build().show();
        }
    });

    // Inflate the popup_layout.xml
    LayoutInflater inflater = (LayoutInflater) getActivity()
            .getSystemService(ActionBarActivity.LAYOUT_INFLATER_SERVICE);
    popupLayout = inflater.inflate(R.layout.popup_sketch_stroke, null);
    // And the one for eraser
    LayoutInflater inflaterEraser = (LayoutInflater) getActivity()
            .getSystemService(ActionBarActivity.LAYOUT_INFLATER_SERVICE);
    popupEraserLayout = inflaterEraser.inflate(R.layout.popup_sketch_eraser, null);

    // Actual stroke shape size is retrieved
    strokeImageView = (ImageView) popupLayout.findViewById(R.id.stroke_circle);
    final Drawable circleDrawable = getResources().getDrawable(R.drawable.circle);
    size = circleDrawable.getIntrinsicWidth();
    // Actual eraser shape size is retrieved
    eraserImageView = (ImageView) popupEraserLayout.findViewById(R.id.stroke_circle);
    size = circleDrawable.getIntrinsicWidth();

    setSeekbarProgress(SketchView.DEFAULT_STROKE_SIZE, SketchView.STROKE);
    setSeekbarProgress(SketchView.DEFAULT_ERASER_SIZE, SketchView.ERASER);

    // Stroke color picker initialization and event managing
    mColorPicker = (ColorPicker) popupLayout.findViewById(R.id.stroke_color_picker);
    mColorPicker.addSVBar((SVBar) popupLayout.findViewById(R.id.svbar));
    mColorPicker.addOpacityBar((OpacityBar) popupLayout.findViewById(R.id.opacitybar));
    mColorPicker.setOnColorChangedListener(mSketchView::setStrokeColor);
    mColorPicker.setColor(mSketchView.getStrokeColor());
    mColorPicker.setOldCenterColor(mSketchView.getStrokeColor());
}

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  va2  s  . c o  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: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 a2 s  .  c  om
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.github.magiepooh.recycleritemdecoration.HorizontalItemDecoration.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int top = parent.getPaddingTop();
    int bottom = parent.getHeight() - parent.getPaddingBottom();
    boolean isReverse = ((LinearLayoutManager) parent.getLayoutManager()).getReverseLayout();

    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 left, right;
                if (isReverse) {
                    right = child.getLeft() - params.leftMargin;
                    left = right - mLastDrawable.getIntrinsicWidth();
                } else {
                    left = child.getRight() + params.rightMargin;
                    right = left + mLastDrawable.getIntrinsicWidth();
                }//from  w  ww  .j  av  a  2  s.  co m
                mLastDrawable.setBounds(left, top, right, bottom);
                mLastDrawable.draw(c);
            }
            return;
        }

        // specific view type
        Drawable drawable = mDividerViewTypeMap.get(childViewType);
        if (drawable != null) {
            int left, right;
            if (isReverse) {
                right = child.getLeft() - params.leftMargin;
                left = right - drawable.getIntrinsicWidth();
            } else {
                left = child.getRight() + params.rightMargin;
                right = left + drawable.getIntrinsicWidth();
            }
            drawable.setBounds(left, top, right, bottom);
            drawable.draw(c);
        }

        // first position
        if (isFirstPosition(child, parent)) {
            if (mFirstDrawable != null) {
                int left, right;
                if (isReverse) {
                    left = child.getRight() + params.rightMargin;
                    right = left + mFirstDrawable.getIntrinsicWidth();
                } else {
                    right = child.getLeft() - params.leftMargin;
                    left = right - mFirstDrawable.getIntrinsicWidth();
                }
                mFirstDrawable.setBounds(left, top, right, bottom);
                mFirstDrawable.draw(c);
            }
        }
    }
}

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

/**
 *
 * @return a Drawable with a youtube logo in the center
 *//*from w w w  . ja v  a  2  s. co 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:net.sarangnamu.android.DrawableManager.java

public Drawable fetchDrawable(String urlString) {
    if (drawableMap.containsKey(urlString)) {
        return drawableMap.get(urlString);
    }// w w w  . j  a  v a  2 s .  c  om

    Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = null;

        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());
        }
        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.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java

private Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable)
        ((BitmapDrawable) drawable).getBitmap();
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap bitmap = this.createBitmapSafely(width, height, Bitmap.Config.ARGB_8888, 1);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);//www  . j  a va  2  s  . com
    return bitmap;
}

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

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;/* w w w . j  a  v a2s . c  o  m*/
    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
}