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:com.linhnv.apps.maxim.utils.ImageWorker.java

private BitmapDrawable roundCornered(BitmapDrawable scaledBitmap, int i) {

    Bitmap bitmap = scaledBitmap.getBitmap();

    Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);

    int color = 0xff424242;
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect);
    int roundPx = i;
    paint.setAntiAlias(true);//from  w w w .j a v  a  2 s.  co  m
    canvas.drawARGB(0, 0, 0, 0);
    // paint.setColor(Color.BLUE);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    BitmapDrawable finalresult = new BitmapDrawable(mResources, result);
    return finalresult;
}

From source file:com.xamoom.android.xamoomcontentblocks.ViewHolders.ContentBlock2ViewHolder.java

private void setupYoutube(final ContentBlock contentBlock) {
    final String youtubeVideoId = getYoutubeVideoId(contentBlock.getVideoUrl());

    Bitmap savedBitmap = mBitmapCache.get(youtubeVideoId);
    if (savedBitmap != null) {
        mProgressBar.setVisibility(View.GONE);
        mYouTubeThumbnailView.setImageBitmap(savedBitmap);
    } else {/*from w ww.  j  a v a 2 s  .c om*/
        mYouTubeThumbnailView.initialize(mYoutubeApiKey, new YouTubeThumbnailView.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView,
                    final YouTubeThumbnailLoader youTubeThumbnailLoader) {
                youTubeThumbnailLoader.setVideo(youtubeVideoId);
                youTubeThumbnailLoader
                        .setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
                            @Override
                            public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
                                mProgressBar.setVisibility(View.GONE);

                                Drawable drawable = mYouTubeThumbnailView.getDrawable();
                                if (drawable instanceof BitmapDrawable) {
                                    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                                    mBitmapCache.put(youtubeVideoId, bitmapDrawable.getBitmap());
                                }
                                youTubeThumbnailLoader.release();
                            }

                            @Override
                            public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView,
                                    YouTubeThumbnailLoader.ErrorReason errorReason) {
                                youTubeThumbnailView.setBackgroundColor(Color.BLACK);
                                mProgressBar.setVisibility(View.GONE);
                                youtubeFallback(contentBlock.getVideoUrl());
                                youTubeThumbnailLoader.release();
                            }
                        });
            }

            @Override
            public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView,
                    YouTubeInitializationResult youTubeInitializationResult) {
                mProgressBar.setVisibility(View.GONE);
                mVideoPlayImageView.setVisibility(View.GONE);
                youtubeFallback(contentBlock.getVideoUrl());
            }
        });
    }

    mYouTubeThumbnailView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendResetYoutubeBroadcast();
            LocalBroadcastManager.getInstance(mContext).registerReceiver(mResetYoutubeBroadCastReciever,
                    new IntentFilter(RESET_YOUTUBE));

            mVideoPlayImageView.setVisibility(View.GONE);

            final FrameLayout frame = new FrameLayout(mContext);
            frame.setId(R.id.youtube_fragment_id);

            FrameLayout.LayoutParams layoutParams = layoutParams = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
            frame.setLayoutParams(layoutParams);

            mFramelayout.addView(frame);

            final YouTubePlayerSupportFragment youTubePlayerSupportFragment = YouTubePlayerSupportFragment
                    .newInstance();
            mFragment.getChildFragmentManager().beginTransaction()
                    .add(frame.getId(), youTubePlayerSupportFragment).commit();

            youTubePlayerSupportFragment.initialize(mYoutubeApiKey, new YouTubePlayer.OnInitializedListener() {
                @Override
                public void onInitializationSuccess(YouTubePlayer.Provider provider,
                        final YouTubePlayer youTubePlayer, boolean b) {
                    youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);

                    youTubePlayer.loadVideo(youtubeVideoId);
                    mProgressBar.setVisibility(View.GONE);

                    youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
                        @Override
                        public void onFullscreen(boolean enterFullscreen) {
                            if (enterFullscreen) {
                                Intent intent = YouTubeStandalonePlayer.createVideoIntent(
                                        mFragment.getActivity(), mYoutubeApiKey, youtubeVideoId,
                                        youTubePlayer.getCurrentTimeMillis(), true, false);
                                mFragment.getActivity().startActivity(intent);
                            }
                        }
                    });
                }

                @Override
                public void onInitializationFailure(YouTubePlayer.Provider provider,
                        YouTubeInitializationResult youTubeInitializationResult) {
                    mProgressBar.setVisibility(View.GONE);
                    youtubeFallback(contentBlock.getVideoUrl());
                    Log.e("tag", youTubeInitializationResult.toString());
                }
            });
        }
    });
}

From source file:org.herrlado.websms.connector.smsge.ConnectorSmsge.java

/**
 * Load captcha and wait for user input to solve it.
 * /*w w w  . j a  v  a 2 s  .co m*/
 * @param context
 *            {@link Context}
 * @param flow
 *            _flowExecutionKey
 * @return true if captcha was solved
 * @throws IOException
 *             IOException
 */
private String solveCaptcha(final ConnectorContext ctx) throws IOException {

    HttpGet cap = new HttpGet(URL_CAPTCHA);
    cap.addHeader("Referer", "http://www.sms.ge/ngeo/index.php");
    cap.setHeader("User-Agent", FAKE_USER_AGENT);
    HttpResponse response = ctx.getClient().execute(cap);
    int resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(ctx.getContext(), R.string.error_http, "" + resp);
    }
    BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent());
    final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST);
    intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap());
    captcha = null;
    Context context = ctx.getContext();
    this.getSpec(context).setToIntent(intent);
    context.sendBroadcast(intent);
    try {
        synchronized (CAPTCHA_SYNC) {
            CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT);
        }
    } catch (InterruptedException e) {
        Log.e(TAG, null, e);
        return null;
    }
    if (captchaSolve == null) {
        return captchaSolve;
    }
    // got user response, try to solve captcha
    Log.d(TAG, "got solved captcha: " + captchaSolve);

    return captchaSolve;
}

From source file:cn.com.caronwer.activity.AuthSecondActivity.java

private void getImg() {
    BitmapDrawable cardNoDrawable = (BitmapDrawable) cardNoImg.getDrawable();
    if (cardNoDrawable != null) {
        Bitmap cardNoBitmap = cardNoDrawable.getBitmap();
        jsonObject.addProperty("Sfz", BitmapUtil.getImgStr(cardNoBitmap));//?
        isCardNoImgSuccess = true;/*from ww w.jav  a2 s . c om*/
    }

    BitmapDrawable drivingLicenseDrawable = ((BitmapDrawable) drivingLicenseImg.getDrawable());
    if (drivingLicenseDrawable != null) {
        Bitmap drivingLicenseBitmap = drivingLicenseDrawable.getBitmap();
        jsonObject.addProperty("Driver", BitmapUtil.getImgStr(drivingLicenseBitmap));
        isDrivingLicenseImgSuccess = true;
    }

    BitmapDrawable carHeadDrawable = ((BitmapDrawable) carHeadImg.getDrawable());
    if (carHeadDrawable != null) {
        Bitmap carHeadBitmap = carHeadDrawable.getBitmap();
        jsonObject.addProperty("CarFront", BitmapUtil.getImgStr(carHeadBitmap));
        isCarHeadImgSuccess = true;
    }

    BitmapDrawable carTailDrawable = (BitmapDrawable) carTailImg.getDrawable();
    if (carTailDrawable != null) {
        Bitmap carTailBitmap = carTailDrawable.getBitmap();
        jsonObject.addProperty("CarBack", BitmapUtil.getImgStr(carTailBitmap));
        isCarTailImgSuccess = true;
    }

    BitmapDrawable carLeftDrawable = (BitmapDrawable) carLeftImg.getDrawable();
    if (carLeftDrawable != null) {
        Bitmap carLeftBitmap = carLeftDrawable.getBitmap();
        jsonObject.addProperty("CarLeft", BitmapUtil.getImgStr(carLeftBitmap));
        isCarLeftImgSuccess = true;
    }

    BitmapDrawable carRightDrawable = (BitmapDrawable) carRightImg.getDrawable();
    if (carRightDrawable != null) {
        Bitmap carRightBitmap = carRightDrawable.getBitmap();
        jsonObject.addProperty("CarRight", BitmapUtil.getImgStr(carRightBitmap));
        isCarRightImgSuccess = true;
    }
}

From source file:com.example.rps.RpsFragment.java

private ShareOpenGraphAction getThrowAction() {
    // The OG objects have their own bitmaps we could rely on, but in order to demonstrate
    // attaching an in-memory bitmap (e.g., a game screencap) we'll send the bitmap explicitly
    // ourselves.
    ImageButton view = gestureImages[playerChoice];
    BitmapDrawable drawable = (BitmapDrawable) view.getBackground();
    final Bitmap bitmap = drawable.getBitmap();

    return new ShareOpenGraphAction.Builder().setActionType(OpenGraphConsts.THROW_ACTION_TYPE)
            .putString("fb_sample_rps:gesture", getBuiltInGesture(playerChoice))
            .putString("fb_sample_rps:opposing_gesture", getBuiltInGesture(computerChoice))
            .putPhotoArrayList("og:image", new ArrayList<SharePhoto>() {
                {/*  w w  w  .  j a  v a2 s  .c  o m*/
                    add(new SharePhoto.Builder().setBitmap(bitmap).build());
                }
            }).build();
}

From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

/**
 * Checks whether a Drawable is a small grayscale icon.
 * Grayscale here means "very close to a perfect gray"; icon means "no larger than 64dp".
 *
 * @param d The drawable to test./* w  ww  . j  av  a2  s  .  c o m*/
 * @return True if the bitmap is grayscale; false if it is color or too large to examine.
 */
public boolean isGrayscaleIcon(Drawable d) {
    if (d == null) {
        return false;
    } else if (d instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) d;
        return bd.getBitmap() != null && isGrayscaleIcon(bd.getBitmap());
    } else if (d instanceof AnimationDrawable) {
        AnimationDrawable ad = (AnimationDrawable) d;
        int count = ad.getNumberOfFrames();
        return count > 0 && isGrayscaleIcon(ad.getFrame(0));
    } else if (d instanceof VectorDrawable) {
        // We just assume you're doing the right thing if using vectors
        return true;
    } else {
        return false;
    }
}

From source file:poisondog.android.image.ImageCache.java

public void addBitmapToCache(String key, BitmapDrawable bitmap) throws FileSystemException, IOException {
    //      if (getBitmapFromMemCache(key) == null) {
    //         if (RecyclingBitmapDrawable.class.isInstance(bitmap)) {
    //            ((RecyclingBitmapDrawable) bitmap).setIsCached(true);
    //         }//from w w w.j a  va  2 s .  c o m
    //         new PutMemoryCacheTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, new Pair(key, bitmap));
    //      }
    //      synchronized (mDiskCacheLock) {
    if (mImageDiskCache != null && mImageDiskCache.get(key) == null) {
        mImageDiskCache.put(key, bitmap.getBitmap());
    }
    //      }
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

public static BitmapDrawable scaleTo(BitmapDrawable bmd, float newSize) {
    Bitmap bm = bmd.getBitmap();
    int width = bm.getWidth();
    float scale = (float) (newSize / (float) width);
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);//from   w w w . j  av a  2 s .com
    Bitmap bmNew = Bitmap.createBitmap(bm, 0, 0, width, width, matrix, true);
    return new BitmapDrawable(bmNew);
}

From source file:com.sqkj.engine.image.ImageCache.java

private void init(ImageCacheParams cacheParams) {
    mCacheParams = cacheParams;/*from  w  ww.  ja v a  2  s . c  om*/
    if (mCacheParams.memoryCacheEnabled) {
        WaterDropsLog.v("Memory cache created (size = " + mCacheParams.memCacheSize + ")");
        if (SdkUtils.hasHoneycomb()) {
            mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
        }
        mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) {
            @Override
            protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue,
                    BitmapDrawable newValue) {
                if (RecyclingBitmapDrawable.class.isInstance(oldValue)) {
                    ((RecyclingBitmapDrawable) oldValue).setIsCached(false);
                } else {
                    if (SdkUtils.hasHoneycomb()) {
                        mReusableBitmaps.add(new SoftReference<Bitmap>(oldValue.getBitmap()));
                    }
                }
            }

            @Override
            protected int sizeOf(String key, BitmapDrawable value) {
                final int bitmapSize = getBitmapSize(value) / 1024;
                WaterDropsLog.d("@@@@@@Bitmap Size==>" + bitmapSize);
                return bitmapSize == 0 ? 1 : bitmapSize;
            }
        };
    }
}

From source file:org.herrlado.websms.connector.magtifunge.ConnectorMagtifun.java

/**
 * Load captcha and wait for user input to solve it.
 * /*  ww w  .j a v  a  2 s .c o  m*/
 * @param second
 * 
 * @param context
 *            {@link Context}
 * @param flow
 *            _flowExecutionKey
 * @return true if captcha was solved
 * @throws IOException
 *             IOException
 */
private String solveCaptcha(final ConnectorContext ctx, String body) throws IOException {

    String url = URL_CAPTCHA;

    String num = findCaptchaNum(body);
    if (TextUtils.isEmpty(num) == false) {
        url = url + num;
    } else {
        url = url + DEFAULT_URL_CAPTCHA_PARAMETER;
    }

    HttpGet cap = new HttpGet(url);
    cap.addHeader("Referer", "http://www.magtifun.ge/index.php?page=2&lang=ge");
    cap.setHeader("User-Agent", FAKE_USER_AGENT);
    HttpResponse response = ctx.getClient().execute(cap);
    int resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(ctx.getContext(), R.string.error_http, "" + resp);
    }
    BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent());
    final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST);
    intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap());
    captcha = null;
    Context context = ctx.getContext();
    this.getSpec(context).setToIntent(intent);
    context.sendBroadcast(intent);
    try {
        synchronized (CAPTCHA_SYNC) {
            CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT);
        }
    } catch (InterruptedException e) {
        Log.e(TAG, null, e);
        return null;
    }
    if (captchaSolve == null) {
        return captchaSolve;
    }
    // got user response, try to solve captcha
    Log.d(TAG, "got solved captcha: " + captchaSolve);

    return captchaSolve;
}