Example usage for android.graphics.drawable BitmapDrawable getBitmap

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

Introduction

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

Prototype

public final Bitmap getBitmap() 

Source Link

Document

Returns the bitmap used by this drawable to render.

Usage

From source file:java_lang_programming.com.android_media_demo.article80.ImageFragment.java

/**
 * ??bitmap?// ww  w . j  a v a  2 s  .c o  m
 * Returns changeable bmp
 *
 * @return
 */
private Bitmap getMutableBitmap() {
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    Bitmap bitmap = drawable.getBitmap();

    // ??bitmap
    Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    return mutableBitmap;
}

From source file:com.sonetel.plugins.sonetelcallback.CallBack.java

@Override
public void onReceive(final Context context, Intent intent) {
    if (SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
        // Retrieve and cache infos from the phone app 
        if (!sPhoneAppInfoLoaded) {
            Resources r = context.getResources();
            BitmapDrawable drawable = (BitmapDrawable) r.getDrawable(R.drawable.ic_wizard_sonetel);
            sPhoneAppBmp = drawable.getBitmap();

            sPhoneAppInfoLoaded = true;/*from  w ww.  j  av a2  s . co  m*/
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call back");// context.getResources().getString(R.string.use_pstn));
        if (sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }
        if (intent.getStringExtra(Intent.EXTRA_TEXT) == null)
            return;

        final String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        DBAdapter dbAdapt = new DBAdapter(context);

        // Build pending intent

        SipAccount = dbAdapt.getAccount(1);

        if (SipAccount != null) {

            //Intent i = new Intent(Intent.ACTION_CALL);
            //i.setData(Uri.fromParts("tel", callthrunum, null));
            //final PendingIntent pendingIntent  = PendingIntent.getActivity(context, 0, i,  PendingIntent.FLAG_CANCEL_CURRENT);

            NetWorkThread = new Thread() {
                public void run() {
                    SendMsgToNetWork(dialledNum, callthrunum, context, null);
                };
            };

            NetWorkThread.start();

        } else if (SipAccount.acc_id != "1")
            Toast.makeText(context, "Unable to find Sonetel account. Please sign in using your Sonetel account",
                    Toast.LENGTH_LONG).show();

        if (!dialledNum.equalsIgnoreCase("")) {
            SipCallSessionImpl callInfo = new SipCallSessionImpl();

            callInfo.setRemoteContact(dialledNum);
            callInfo.setIncoming(false);
            callInfo.callStart = System.currentTimeMillis();
            callInfo.setAccId(4);
            //callInfo.setLastStatusCode(pjsua.PJ_SUCCESS);

            ContentValues cv = CallLogHelper.logValuesForCall(context, callInfo, callInfo.callStart);
            context.getContentResolver().insert(SipManager.CALLLOG_URI, cv);

        }
        //}
        //else
        //{

        //}
    }

    // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
    //results.putString(Intent.EXTRA_PHONE_NUMBER, callthrunum);

}

From source file:com.google.samples.apps.topeka.widget.AvatarView.java

private void setAvatarPreLollipop(@DrawableRes int resId) {
    Drawable drawable = ResourcesCompat.getDrawable(getResources(), resId, getContext().getTheme());
    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    @SuppressWarnings("ConstantConditions")
    RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(),
            bitmapDrawable.getBitmap());
    roundedDrawable.setCircular(true);/* w  w  w .  j  a  v  a2s.com*/
    setImageDrawable(roundedDrawable);
}

From source file:com.sonetel.plugins.sonetelcallthru.CallThru.java

@Override
public void onReceive(final Context context, Intent intent) {
    if (SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
        // Retrieve and cache infos from the phone app 
        if (!sPhoneAppInfoLoaded) {
            Resources r = context.getResources();
            BitmapDrawable drawable = (BitmapDrawable) r.getDrawable(R.drawable.ic_wizard_sonetel);
            sPhoneAppBmp = drawable.getBitmap();

            sPhoneAppInfoLoaded = true;//from  w  w  w  . j a  v  a 2s  .  co m
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call thru");// context.getResources().getString(R.string.use_pstn));
        if (sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }
        if (intent.getStringExtra(Intent.EXTRA_TEXT) == null)
            return;

        //final PendingIntent pendingIntent = null;
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        final String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        // We must handle that clean way cause when call just to 
        // get the row in account list expect this to reply correctly
        if (callthrunum != null && PhoneCapabilityTester.isPhone(context)) {

            if (!callthrunum.equalsIgnoreCase("")) {
                DBAdapter dbAdapt = new DBAdapter(context);

                // Build pending intent

                SipAccount = dbAdapt.getAccount(1);

                if (SipAccount != null) {

                    Intent i = new Intent(Intent.ACTION_CALL);
                    i.setData(Uri.fromParts("tel", callthrunum, null));
                    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                            PendingIntent.FLAG_CANCEL_CURRENT);

                    NetWorkThread = new Thread() {
                        public void run() {
                            SendMsgToNetWork(dialledNum, context, pendingIntent);
                        };
                    };

                    NetWorkThread.start();

                }

                if (!dialledNum.equalsIgnoreCase("")) {
                    SipCallSessionImpl callInfo = new SipCallSessionImpl();

                    callInfo.setRemoteContact(dialledNum);
                    callInfo.setIncoming(false);
                    callInfo.callStart = System.currentTimeMillis();
                    callInfo.setAccId(3);
                    //callInfo.setLastStatusCode(pjsua.PJ_SUCCESS);

                    ContentValues cv = CallLogHelper.logValuesForCall(context, callInfo, callInfo.callStart);
                    context.getContentResolver().insert(SipManager.CALLLOG_URI, cv);

                }
            } else {
                Location_Finder LocFinder = new Location_Finder(context);
                if (LocFinder.getContryName().startsWith("your"))
                    Toast.makeText(context,
                            "Country of your current location unknown. Call thru not available.",
                            Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(context,
                            "No Call thru access number available in " + LocFinder.getContryName(),
                            Toast.LENGTH_LONG).show();
                //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
            }
        }

        // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
        results.putString(Intent.EXTRA_PHONE_NUMBER, callthrunum);

    }

}

From source file:com.mobicage.rogerthat.NavigationItem.java

public Drawable getFooterIcon(Context context) {
    if (this.faIcon == null) {
        BitmapDrawable image = (BitmapDrawable) context.getResources().getDrawable(this.iconId);
        int w = UIUtils.convertDipToPixels(context, 34);
        Bitmap bitmapResized = Bitmap.createScaledBitmap(image.getBitmap(), w, w, false);
        return new BitmapDrawable(context.getResources(), bitmapResized);
    }//from   ww  w . j a  v a2 s  .  com
    return new IconicsDrawable(context, this.faIcon).color(ContextCompat.getColor(context, R.color.mc_white))
            .sizeDp(20);
}

From source file:com.viettel.dms.util.StatusNotificationHandler.java

/**
 * // w ww .ja  va 2s . com
*  tao notification len status notification
*  @author: AnhND
*  @param appContext
*  @param activity
*  @return: void
*  @throws:
 */
private void postNotificationMessage(GlobalBaseActivity activity) {
    NotificationManager notificationManager = (NotificationManager) GlobalInfo.getInstance().getAppContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.icon_app_small;
    BitmapDrawable bd = (BitmapDrawable) GlobalInfo.getInstance().getAppContext().getResources()
            .getDrawable(icon);
    int iconWidth = bd.getBitmap().getWidth();
    CharSequence tickerText = getMessageNotify();
    long when = System.currentTimeMillis();
    // noi dung trong status bar khi keo xuong xem thong bao
    CharSequence contentText = Constants.STR_BLANK;
    contentText = getMessageNotify();

    int screenWidth = ((WindowManager) GlobalInfo.getInstance().getAppContext()
            .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
    screenWidth -= iconWidth;//for icon
    TextView textView = new TextView(GlobalInfo.getInstance().getAppContext());
    int count = tickerText.length();
    StringBuilder wrapTickerText = new StringBuilder();
    wrapTickerText.append(tickerText);
    while (count > 0) {
        if (count < tickerText.length()) {
            wrapTickerText.append("...");
        }
        float measuredWidth = textView.getPaint().measureText(wrapTickerText.toString());
        if (measuredWidth < screenWidth) {
            break;
        }
        count--;
        wrapTickerText.setLength(count);
    }
    Intent notificationIntent = initIntentMessage();
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau
    int requestCode = (int) System.currentTimeMillis();
    PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(),
            requestCode, notificationIntent, 0);

    //       Notification notification = new Notification(icon, wrapTickerText, when);
    //       Intent notificationIntent = initIntentMessage();
    //       notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //       //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau
    //       int requestCode = (int) System.currentTimeMillis();
    //       PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0);
    //
    //       notification.setLatestEventInfo(GlobalInfo.getInstance().getAppContext(), StringUtil.getString(R.string.app_name), contentText, contentIntent);
    //       notification.flags |= Notification.FLAG_AUTO_CANCEL;
    //       notification.defaults = Notification.DEFAULT_ALL;
    //
    //       notificationManager.cancel(NOTIFICATION_MESSAGE_ID);
    //       notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            GlobalInfo.getInstance().getAppContext());
    Notification notification = builder.setContentIntent(contentIntent).setSmallIcon(icon)
            .setTicker(contentText).setWhen(when).setAutoCancel(true)
            .setContentTitle(StringUtil.getString(R.string.app_name)).setContentText(contentText).build();
    notificationManager.cancel(NOTIFICATION_MESSAGE_ID);
    notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification);

}

From source file:com.alex.view.loop.IndicatorView.java

/**
 * drawablebitmap/*from ww w  .  j  av  a2  s. co  m*/
 *
 * @param drawable
 * @return
 */
private Bitmap drawableToBitamp(Drawable drawable) {
    if (null == drawable) {
        return null;
    }
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) drawable;
        return bd.getBitmap();
    }
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}

From source file:org.messic.android.smartphone.activities.main.fragments.explore.ExploreFragment.java

/**
 * Show the AlbumInfo Activity/*from ww  w  . j  ava2 s.c  om*/
 *
 * @param cover
 * @param album
 */
private void showAlbumInfo(ImageView cover, MDMAlbum album) {
    //lets show the albuminfoactivity
    Intent ssa = new Intent(getActivity(), AlbumInfoActivity.class);
    ssa.putExtra(AlbumInfoActivity.EXTRA_ALBUM_SID, album);
    BitmapDrawable d = ((BitmapDrawable) cover.getDrawable());
    if (d != null) {
        Bitmap bitmap = d.getBitmap();
        AlbumInfoActivity.defaultArt = bitmap;
        //ssa.putExtra(AlbumInfoActivity.EXTRA_ALBUM_ART, bitmap);

        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this.getActivity(),
                cover, "cover");
        getActivity().startActivity(ssa, options.toBundle());
    }
}

From source file:com.fastbootmobile.encore.service.ServiceNotification.java

public ServiceNotification(Context ctx) {
    mContext = ctx;//from w  w w  .j  a  v a 2 s. c o  m
    mResources = ctx.getResources();

    // Get the default album art
    BitmapDrawable bdDefault = (BitmapDrawable) mResources.getDrawable(R.drawable.album_placeholder);
    mDefaultArt = bdDefault.getBitmap().copy(bdDefault.getBitmap().getConfig(), false);
    mCurrentArt = null;

    // Build the static notification actions
    setPlayPauseActionImpl(false, false);
}

From source file:at.florian_lentsch.expirysync.AddProductActivity.java

/**
 * Adds the image from the form to {@link Article#images} (if there is one)
 * //from   w  w  w.  j  a va 2  s  . c  om
 * @param article
 *            the article to add the image to
 * @return list of images (currently only contains 1 or 0
 *         {@link ArticleImage}s)
 */
private ArrayList<ArticleImage> addFormImageToArticle(Article article) {
    final DatabaseManager dbManager = DatabaseManager.getInstance();
    final ArrayList<ArticleImage> imagesList = new ArrayList<ArticleImage>();
    final ImageView productImageView = (ImageView) findViewById(R.id.product_img);
    final BitmapDrawable drawable = ((BitmapDrawable) productImageView.getDrawable());
    final Bitmap productBitmap = drawable != null ? drawable.getBitmap() : null;

    article = dbManager.updateOrAddArticle(article);
    if (this.photoPath != null || productBitmap != null) {
        final Resources res = getResources();
        ArticleImage image = new ArticleImage();
        // TODO: Make hardcoded dimensions configurable:
        image.imageData = (this.photoPath != null) ? getPhotoData(300, 200)
                : getBitmapData(productBitmap, res.getDimensionPixelSize(R.dimen.product_img_width),
                        res.getDimensionPixelSize(R.dimen.product_img_height));
        image.article = article;
        article.images = dbManager.initializeArticleImagesCollection();
        article.images.add(image);
        imagesList.add(image);
    }

    return imagesList;
}