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.putao.widget.touchgallery.GalleryWidget.FilePagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    Loger.i("FilePagerAdapter destroyItem:----------" + position);
    View view = (View) object;
    if (view != null) {
        FileTouchImageView aFileTouchImageView = (FileTouchImageView) view;
        BitmapDrawable mBitmapDrawable = (BitmapDrawable) aFileTouchImageView.mImageView.getDrawable();
        if (mBitmapDrawable != null) {
            Bitmap bitmap = mBitmapDrawable.getBitmap();
            bitmap.recycle();/*  www.ja va2  s  . c  om*/
            bitmap = null;
        }
    }
    ((ViewPager) container).removeView(view);
    view = null;
}

From source file:my.home.lehome.asynctask.LoadProfileHeaderBgAsyncTask.java

@Override
protected void onPostExecute(Bitmap resultBitmap) {
    ProgressBar progressBar = mProgressBar.get();
    if (progressBar != null) {
        progressBar.setVisibility(View.GONE);
    }//  w  ww  . j a  v  a  2  s  .c om
    ImageView imageView = mImageView.get();
    if (imageView != null) {
        // recycle previous bitmap
        Drawable drawable = imageView.getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap != null)
                bitmap.recycle();
            imageView.setImageBitmap(null);
        }
        imageView.setImageBitmap(resultBitmap);
    }
}

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

public ImageCache(Context context, FileObject cacheDirectory) {
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int cacheSize = maxMemory / 4;

    mMemoryCache = new LruCache<String, BitmapDrawable>(cacheSize) {
        @Override/*from   w  w  w  . j av  a  2s .  c o m*/
        protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue,
                BitmapDrawable newValue) {
            if (RecyclingBitmapDrawable.class.isInstance(oldValue)) {
                ((RecyclingBitmapDrawable) oldValue).setIsCached(false);
            }
        }

        @Override
        protected int sizeOf(String key, BitmapDrawable bitmap) {
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            bitmap.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, bao);
            return bao.toByteArray().length / 1024;
        }
    };
    new InitDiskCacheTask().execute(cacheDirectory);
}

From source file:org.huxizhijian.hhcomicviewer.adapter.GalleryViewPagerAdapter.java

private void releaseImageViewResource(ZoomImageView imageView) {
    if (imageView == null)
        return;/*from w  w  w.j av  a  2s  .c  o m*/
    Drawable drawable = imageView.getDrawable();
    if (drawable != null && drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
            bitmap = null;
        }
    }
    System.gc();
}

From source file:android.support.v7.widget.AppCompatProgressBarHelper.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *///from  w w w.j a  v  a2  s.  co  m
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

From source file:com.jobs.lib_v1.imageloader.core.download.BaseImageDownloader.java

/**
 * Retrieves {@link InputStream} of image by URI (image is located in drawable resources of application).
 *
 * @param imageUri Image URI/*from   w w  w .j a v  a2  s  . co m*/
 * @param extra    Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
 *                 DisplayImageOptions.extraForDownloader(Object)}; can be null
 * @return {@link InputStream} of image
 */
protected InputStream getStreamFromDrawable(String imageUri, Object extra) {
    String drawableIdString = Scheme.DRAWABLE.crop(imageUri);
    int drawableId = Integer.parseInt(drawableIdString);
    BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(drawableId);
    Bitmap bitmap = drawable.getBitmap();

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0, os);
    return new ByteArrayInputStream(os.toByteArray());
}

From source file:com.charbgr.BlurNavigationDrawer.v4.BlurActionBarDrawerToggle.java

private void handleRecycle() {
    Drawable drawable = mBlurredImageView.getDrawable();

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
        Bitmap bitmap = bitmapDrawable.getBitmap();

        if (bitmap != null)
            bitmap.recycle();//w w  w  .  j  a v a  2  s  .co  m

        mBlurredImageView.setImageBitmap(null);
    }

    prepareToRender = true;
}

From source file:com.mercandalli.android.apps.files.user.ProfileFragment.java

@Override
public void onDestroy() {
    super.onDestroy();

    Drawable drawable = mIconBack.getDrawable();
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        bitmapDrawable.getBitmap().recycle();
    }//from  w ww  .j ava2  s  .c  o  m
}

From source file:com.vanity.mobilevanity.gcm.MyGcmListenerService.java

private void sendNotification(Notify notify) {
    Intent intent = new Intent(this, BeautyTipDetailActivity.class);
    intent.putExtra(BeautyTipDetailActivity.TAG_BEAUTY_TIP_ID,
            notify.getBeautyTipId().getKey().getRaw().getId());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    int bgColor = MyApplication.getContext().getResources().getColor(R.color.colorMain);

    BitmapDrawable drawable = (BitmapDrawable) MyApplication.getContext().getResources()
            .getDrawable(R.drawable.vanity_logo_big);
    Bitmap appIcon = drawable.getBitmap();

    int smallIconId;

    if (notify.getType().equals("comment"))
        smallIconId = R.drawable.icon_notify_comment;
    else// w ww .j  a  v  a2  s.c om
        smallIconId = R.drawable.icon_notify_like;

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setLargeIcon(appIcon)
            .setSmallIcon(smallIconId).setColor(bgColor).setTicker("GCM Message").setContentTitle("Vanity")
            .setContentText(notify.getMessage()).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.csipsimple.plugins.twvoip.CallHandler.java

@Override
public void onReceive(Context context, Intent intent) {
    if (ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_12VOIP_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_12VOIP_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_12VOIP_NBR, "");

        // We must handle that clean way cause when call just to
        // get the row in account list expect this to reply correctly
        if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr)
                && !TextUtils.isEmpty(pwd)) {
            // Build pending intent
            Intent i = new Intent(ACTION_DO_TWVOIP_CALL);
            i.setClass(context, getClass());
            i.putExtra(Intent.EXTRA_PHONE_NUMBER, number);

            pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
            // = PendingIntent.getActivity(context, 0, i, 0);
        }//from   w ww  .  j a  va2s .c  o  m

        // Build icon
        Bitmap bmp = null;
        Drawable icon = context.getResources().getDrawable(R.drawable.icon);
        BitmapDrawable bd = ((BitmapDrawable) icon);
        bmp = bd.getBitmap();

        // Build the result for the row (label, icon, pending intent, and
        // excluded phone number)
        Bundle results = getResultExtras(true);
        if (pendingIntent != null) {
            results.putParcelable(Intent.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }
        results.putString(Intent.EXTRA_TITLE, "12voip WebCallback");
        if (bmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp);
        }

        // DO *NOT* exclude from next tel: intent cause we use a http method
        // results.putString(Intent.EXTRA_PHONE_NUMBER, number);

    } else if (ACTION_DO_TWVOIP_CALL.equals(intent.getAction())) {

        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_12VOIP_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_12VOIP_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_12VOIP_NBR, "");

        // params
        List<NameValuePair> params = new LinkedList<NameValuePair>();
        params.add(new BasicNameValuePair("username", user));
        params.add(new BasicNameValuePair("password", pwd));
        params.add(new BasicNameValuePair("from", nbr));
        params.add(new BasicNameValuePair("to", number));
        String paramString = URLEncodedUtils.format(params, "utf-8");

        String requestURL = "https://www.12voip.com//myaccount/makecall.php?" + paramString;

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(requestURL);

        // Create a response handler
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpGet);
            Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent());
                BufferedReader br = new BufferedReader(isr);

                String line;
                String fullReply = "";
                boolean foundSuccess = false;
                while ((line = br.readLine()) != null) {
                    if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) {
                        showToaster(context, "Success... wait a while you'll called back");
                        foundSuccess = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(line)) {
                        fullReply = fullReply.concat(line);
                    }
                }
                if (!foundSuccess) {
                    showToaster(context, "Error : server error : " + fullReply);
                }
            } else {
                showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode());
            }
        } catch (ClientProtocolException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        } catch (IOException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        }

    }
}