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:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

public static Drawable getCachedArtwork(Context context, long artIndex, BitmapDrawable defaultArtwork) {
    Drawable d = null;//from w  w w  .  ja v  a2  s  . co m
    synchronized (sArtCache) {
        d = sArtCache.get(artIndex);
    }
    if (d == null) {
        d = defaultArtwork;
        final Bitmap icon = defaultArtwork.getBitmap();
        int w = icon.getWidth();
        int h = icon.getHeight();
        Bitmap b = MusicUtils.getArtworkQuick(context, artIndex, w, h);
        if (b != null) {
            d = new FastBitmapDrawable(b);
            synchronized (sArtCache) {
                // the cache may have changed since we checked
                Drawable value = sArtCache.get(artIndex);
                if (value == null) {
                    sArtCache.put(artIndex, d);
                } else {
                    d = value;
                }
            }
        }
    }
    return d;
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private Bitmap setScaledImage(final Drawable bgImage, View view, Bitmap prevScaled) {
    if (bgImage != null) {
        if (prevScaled != null)
            prevScaled.recycle();/*from  ww  w.  ja v a2  s. co  m*/

        int screenWidthPx = Resources.getSystem().getDisplayMetrics().widthPixels;
        int viewHeightPx = view.getMeasuredHeight();

        // view.setBackgroundResource(bgImage);
        if (bgImage instanceof BitmapDrawable) {
            BitmapDrawable bmDrawable = (BitmapDrawable) bgImage;
            Bitmap bmImage = bmDrawable.getBitmap();

            prevScaled = scaleCenterCrop(bmImage, screenWidthPx, viewHeightPx);
            view.setBackgroundDrawable(new BitmapDrawable(prevScaled));
        } else {

            // TODO - compute scale factor from screenWidthPx and viewHeightx
            Drawable scaleDrawable = new ScaleDrawable(bgImage, Gravity.NO_GRAVITY, 1.0f, 0.1f);
            view.setBackgroundDrawable(scaleDrawable);
        }
    }

    return prevScaled;
}

From source file:com.example.locale.MainActivity.java

private void showDefaultLocale() {
    Locale locale = Locale.getDefault();
    setTitle(locale.getDisplayName());/*www .  j a v  a2 s.c o  m*/
    BitmapDrawable d = (BitmapDrawable) ImageUtil.getFlagIcon(this, locale.getCountry());
    if (d != null) {
        final Bitmap bitmap = d.getBitmap();
        mPaletteTask = new Palette.Builder(bitmap).generate(new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
                mPaletteTask = null;
                int color = palette.getDarkVibrantColor(0);
                mToolbar.setBackgroundColor(color);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Window window = getWindow();
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.setStatusBarColor(getDarkerColor(color));
                }
            }
        });
    }
}

From source file:com.example.android.CreateNewPlayer.java

/**
 * Called when the user clicks the Create New Player button If the user name
 * already exits a popup dialog appears and ask the user to write another
 * name. If the name is valid and does not exits the activity finish and
 * store the name and/if picture in db/*from w w w  .j  a  va2  s . c  om*/
 * 
 * @param v
 */
public void createPlayer(View v) {

    if (checkIfUserNameAlreadyExits(userName.getText().toString())) {
        if (checkIfUsernameIsValid(userName.getText().toString())) {
            playButton();
            BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
            Bitmap bitmap = drawable.getBitmap();
            User user = new User(userName.getText().toString(), zero, bitmap, zero, zero);
            db.addUser(user);
            soundData.addEntry(user);
            finish();
        }
    } else {
        // Show a dialog that the username is invalid
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Anvndarnamnet r inte tilltet").setCancelable(false).setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        createPlayerButton.setEnabled(false);
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
        playButton();
    }
}

From source file:com.SwedishSignAlphabet.CreateNewPlayer.java

/**
 * Called when the user clicks the Create New Player button If the user name
 * already exits a popup dialog appears and ask the user to write another
 * name. If the name is valid and does not exits the activity finish and
 * store the name and/if picture in db/*w ww.  j  a v a2  s . c o  m*/
 * 
 * @param v
 */
public void createPlayer(View v) {

    if (checkIfUserNameAlreadyExits(userName.getText().toString())) {
        if (checkIfUsernameIsValid(userName.getText().toString())) {
            playButton();
            BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
            Bitmap bitmap = drawable.getBitmap();
            User user = new User(userName.getText().toString(), zero, bitmap, zero, zero);
            db.addUser(user);
            soundData.addEntry(user);
            finish();
        }
    } else {
        // Show a dialog that the username is invalid
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Anvandarnamnet ar inte tillatet").setCancelable(false).setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        createPlayerButton.setEnabled(false);
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
        playButton();
    }
}

From source file:org.odk.collect.android.widgets.QuestionWidget.java

public void recycleDrawables() {
    List<ImageView> images = new ArrayList<>();
    // collect all the image views
    recycleDrawablesRecursive(this, images);
    for (ImageView imageView : images) {
        imageView.destroyDrawingCache();
        Drawable d = imageView.getDrawable();
        if (d != null && d instanceof BitmapDrawable) {
            imageView.setImageDrawable(null);
            BitmapDrawable bd = (BitmapDrawable) d;
            Bitmap bmp = bd.getBitmap();
            if (bmp != null) {
                bmp.recycle();//from w w  w  . jav  a2  s  .  c o  m
            }
        }
    }
}

From source file:pl.itiner.nutiteq.NutiteqMap.java

public Bitmap createMissingTileBitmap(final int tileSize, final String bitmapText, Resources res) {
    Bitmap canvasBitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.RGB_565);
    Canvas imageCanvas = new Canvas(canvasBitmap);

    Paint textPaint = new Paint();
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(16f);/*  ww w  .  j  av  a  2  s .c o m*/

    Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStrokeWidth(3);
    imageCanvas.drawRect(0, 0, tileSize, tileSize, backgroundPaint);

    imageCanvas.drawText(bitmapText, tileSize / 2, tileSize / 2, textPaint);

    BitmapDrawable finalImage = new BitmapDrawable(res, canvasBitmap);
    return finalImage.getBitmap();
}

From source file:us.koller.todolist.Activities.InfoActivity.java

public void initTheme(Toolbar toolbar) {
    helper = new ThemeHelper(this);

    findViewById(R.id.info_activity_layout).setBackgroundColor(helper.get(ThemeHelper.CORD_COLOR));
    toolbar.setBackgroundColor(helper.get(ThemeHelper.TOOLBAR_COLOR));
    toolbar.setTitleTextColor(helper.get(ThemeHelper.TOOLBAR_TEXT_COLOR));
    if (helper.get(ThemeHelper.CORD_COLOR) != helper.get(ThemeHelper.TOOLBAR_COLOR)) {
        elevateToolbar(toolbar);/*from   w w  w .  j a v  a  2  s .  c  o m*/
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && helper.lightCoordColor()) {
        toolbar.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }

    View drawerIcon;
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        if (toolbar.getChildAt(i) instanceof ImageView) {
            drawerIcon = toolbar.getChildAt(i);
            ((ImageView) drawerIcon).setColorFilter(helper.getToolbarIconColor(), PorterDuff.Mode.SRC_IN);
        }
    }

    String title = getString(R.string.app_name);
    BitmapDrawable icon = (BitmapDrawable) ContextCompat.getDrawable(InfoActivity.this, R.mipmap.ic_launcher);

    ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(title, icon.getBitmap(),
            helper.get(ThemeHelper.TOOLBAR_COLOR));
    this.setTaskDescription(tDesc);
}

From source file:de.mtrstudios.nflpickem.UI.Games.GamesFragment.java

/**
 * Scales and positions the background icon
 *//*from   ww  w .jav a 2  s.c o m*/
private void scaleIcon(View target) {
    // Scale Icon View
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int height = metrics.heightPixels;
    int width = metrics.widthPixels;

    BitmapDrawable bmap = (BitmapDrawable) getResources().getDrawable(R.drawable.loginbackgroundicon);
    float bmapWidth = bmap.getBitmap().getWidth();
    float bmapHeight = bmap.getBitmap().getHeight();

    float wRatio = width / bmapWidth;
    float hRatio = height / bmapHeight;

    float ratioMultiplier = wRatio;
    // Untested conditional though I expect this might work for landscape mode
    if (hRatio < wRatio) {
        ratioMultiplier = hRatio;
    }

    int newBmapWidth = (int) (bmapWidth * ratioMultiplier);
    int newBmapHeight = (int) (bmapHeight * ratioMultiplier);

    target.setLayoutParams(new RelativeLayout.LayoutParams(newBmapWidth, newBmapHeight));
}

From source file:com.renard.ocr.OCRActivity.java

@Override
protected void onDestroy() {
    if (mFinalPix != null) {
        mFinalPix.recycle();//from   w w w .j  ava 2s .c  o m
        mFinalPix = null;
    }

    BitmapDrawable bd = (BitmapDrawable) mImageView.getDrawable();
    if (bd != null) {
        bd.getBitmap().recycle();
    }
    super.onDestroy();
}