Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

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

Introduction

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

Prototype

private BitmapDrawable(BitmapState state, Resources res) 

Source Link

Usage

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeSearchBox() {
    int boxColor = Color.rgb(241, 238, 229);
    int innerBoxColor = Color.rgb(246, 244, 239);
    int inlineColor = Color.rgb(133, 105, 75);

    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); // width,height
    searchBox = new SkyBox(this);
    searchBox.setBoxColor(boxColor);//from  w  ww . j ava  2  s .  c  o  m
    searchBox.setArrowHeight(ps(25));
    searchBox.setArrowDirection(false);
    param.leftMargin = ps(50);
    param.topMargin = ps(400);
    param.width = ps(400);
    param.height = ps(300);
    searchBox.setLayoutParams(param);
    searchBox.setArrowDirection(false);

    searchEditor = new EditText(this);
    this.setFrame(searchEditor, ps(20), ps(20), ps(400 - 140), ps(50));
    searchEditor.setTextSize(15f);
    searchEditor.setEllipsize(TruncateAt.END);
    searchEditor.setBackgroundColor(innerBoxColor);
    Drawable icon = getResources().getDrawable(R.drawable.search2x);

    Bitmap bitmap = ((BitmapDrawable) icon).getBitmap();
    Drawable fd = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, ps(28), ps(28), true));
    searchEditor.setCompoundDrawablesWithIntrinsicBounds(fd, null, null, null);
    RoundRectShape rrs = new RoundRectShape(
            new float[] { ps(15), ps(15), ps(15), ps(15), ps(15), ps(15), ps(15), ps(15) }, null, null);
    SkyDrawable sd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 2);
    searchEditor.setBackgroundDrawable(sd);
    searchEditor.setHint(getString(R.string.searchhint));
    searchEditor.setPadding(ps(20), ps(5), ps(10), ps(5));
    searchEditor.setLines(1);
    searchEditor.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchEditor.setSingleLine();
    searchEditor.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_GO
                    || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_NEXT) {
                String key = searchEditor.getText().toString();
                if (key != null && key.length() > 1) {
                    showIndicator();
                    clearSearchBox(1);
                    makeFullScreen();
                    rv.searchKey(key);
                }
            }
            return false;
        }
    });
    searchBox.contentView.addView(searchEditor);

    Button cancelButton = new Button(this);
    this.setFrame(cancelButton, ps(290), ps(20), ps(90), ps(50));
    cancelButton.setText(getString(R.string.cancel));
    cancelButton.setId(3001);
    RoundRectShape crs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable cd = new SkyDrawable(crs, innerBoxColor, inlineColor, 2);
    cancelButton.setBackgroundDrawable(cd);
    cancelButton.setTextSize(12);
    cancelButton.setOnClickListener(listener);
    cancelButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(cancelButton));

    searchBox.contentView.addView(cancelButton);

    searchScrollView = new ScrollView(this);
    RoundRectShape rvs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable rd = new SkyDrawable(rvs, innerBoxColor, inlineColor, 2);
    searchScrollView.setBackgroundDrawable(rd);
    this.setFrame(searchScrollView, ps(20), ps(100), ps(360), ps(200));
    this.searchBox.contentView.addView(searchScrollView);

    searchResultView = new LinearLayout(this);
    searchResultView.setOrientation(LinearLayout.VERTICAL);
    searchScrollView.addView(searchResultView,
            new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    this.ePubView.addView(searchBox);
    this.hideSearchBox();
}

From source file:dev.memento.MainActivity.java

private void displayFavicon(Bitmap favicon) {
    BitmapDrawable bd = null;//  w w  w  . ja va  2 s .  co  m
    if (favicon != null) {
        bd = new BitmapDrawable(this.getResources(), favicon);
        bd = resizeImage(bd, 32);
    }
    mLocation.setCompoundDrawablesWithIntrinsicBounds(bd, null, null, null);
}

From source file:dev.memento.MainActivity.java

private BitmapDrawable resizeImage(BitmapDrawable image, int size) {
    Bitmap b = image.getBitmap();/*from  w  ww.  j av  a 2s  . co m*/
    if (b.getWidth() < size) {
        Bitmap bitmapResized = Bitmap.createScaledBitmap(b, size, size, false);
        return new BitmapDrawable(this.getResources(), bitmapResized);
    } else {
        // Don't worry about resizing if large enough
        return image;
    }
}

From source file:com.filemanager.free.activities.MainActivity.java

@Override
public void onConnected(Bundle bundle) {

    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

        String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
        Person.Image personImage;
        Person.Cover.CoverPhoto personCover;

        try {//from  w  w  w.ja v a  2s  . c  om

            personImage = currentPerson.getImage();
            personCover = currentPerson.getCover().getCoverPhoto();
        } catch (Exception e) {

            personCover = null;
            personImage = null;
        }

        if (personCover != null && personImage != null) {

            String imgUrl = personImage.getUrl();

            // getting full size image
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(imgUrl);
            stringBuilder.delete(imgUrl.length() - 6, imgUrl.length());
            Log.d("G+", stringBuilder.toString());
            mGoogleName.setText(currentPerson.getDisplayName());
            mGoogleId.setText(accountName);
            // setting cover pic
            ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions,
                    new SimpleImageLoadingListener() {
                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            super.onLoadingComplete(imageUri, view, loadedImage);
                            drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff"));

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                                drawerHeaderView
                                        .setBackground(new BitmapDrawable(con.getResources(), loadedImage));
                            } else {
                                drawerHeaderView.setBackgroundDrawable(
                                        new BitmapDrawable(con.getResources(), loadedImage));
                            }
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                            super.onLoadingFailed(imageUri, view, failReason);
                            drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
                            drawerHeaderParent.setBackgroundColor(Color.parseColor(skin));
                        }

                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                            super.onLoadingStarted(imageUri, view);
                            drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
                            drawerHeaderParent.setBackgroundColor(Color.parseColor(skin));
                        }
                    });

            // setting profile pic
            ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions,
                    new SimpleImageLoadingListener() {
                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                            super.onLoadingComplete(imageUri, view, loadedImage);

                            drawerProfilePic.setImageBitmap(loadedImage);
                            drawerProfilePic.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                            super.onLoadingFailed(imageUri, view, failReason);
                        }
                    });
        } else {
            Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show();
            drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
            drawerHeaderParent.setBackgroundColor(Color.parseColor(skin));
        }
    }
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
  * Reuse of bitmaps in tiled backgrounds is a known cause of problems:
  *      http://stackoverflow.com/questions/4077487/background-image-not-repeating-in-android-layout
 * So we avoid reusing them.// ww  w.  j a  v a  2 s . co m
 * 
 * This seems to have become further messed up in 4.1 so now, we just created them manually. No references,
 * but the old cleanup method (see below for cleanupTiledBackground()) no longer works. Since it effectively
 * un-cached the background, we just create it here.
 * 
 * The main problem with this approach is that the style is defined in code rather than XML.
 *
 * @param a         Activity context
 * @param bright   Flag indicating if background should be 'bright'
 * 
 * @return         Background Drawable
 */
public static Drawable makeTiledBackground(boolean bright) {
    // Storage for the layers
    Drawable[] drawables = new Drawable[2];
    // Get the BG image, put in tiled drawable
    Bitmap b = BitmapFactory.decodeResource(BookCatalogueApp.context.getResources(), R.drawable.books_bg);
    BitmapDrawable bmD = new BitmapDrawable(BookCatalogueApp.context.getResources(), b);
    bmD.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    // Add to layers
    drawables[0] = bmD;

    // Set up the gradient colours based on 'bright' setting
    int[] colours = new int[3];
    if (bright) {
        colours[0] = Color.argb(224, 0, 0, 0);
        colours[1] = Color.argb(208, 0, 0, 0);
        colours[2] = Color.argb(48, 0, 0, 0);
    } else {
        colours[0] = Color.argb(255, 0, 0, 0);
        colours[1] = Color.argb(208, 0, 0, 0);
        colours[2] = Color.argb(160, 0, 0, 0);
    }

    // Create a gradient and add to layers
    GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colours);
    drawables[1] = gd;

    // Make the layers and we are done.
    LayerDrawable ll = new LayerDrawable(drawables);
    ll.setDither(true);

    return ll;
}

From source file:org.cryptsecure.Utility.java

/**
 * Gets the drawable from bitmap.//  w ww.  jav a2s.c o m
 * 
 * @param bitmap
 *            the bitmap
 * @return the drawable from bitmap
 */
public static Drawable getDrawableFromBitmap(Context context, Bitmap bitmap) {
    if (bitmap != null) {
        Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
        return drawable;
    }
    return null;
}

From source file:org.zirco.ui.activities.MainActivity.java

/**
 * Get a Drawable of the current favicon, with its size normalized relative to current screen density.
 * @return The normalized favicon.//  www .j av  a 2s. c om
 */
private BitmapDrawable getNormalizedFavicon() {

    BitmapDrawable favIcon = new BitmapDrawable(getResources(), mCurrentWebView.getFavicon());

    if (mCurrentWebView.getFavicon() != null) {
        int imageButtonSize = ApplicationUtils.getImageButtonSize(this);
        int favIconSize = ApplicationUtils.getFaviconSize(this);

        Bitmap bm = Bitmap.createBitmap(imageButtonSize, imageButtonSize, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bm);

        favIcon.setBounds((imageButtonSize / 2) - (favIconSize / 2), (imageButtonSize / 2) - (favIconSize / 2),
                (imageButtonSize / 2) + (favIconSize / 2), (imageButtonSize / 2) + (favIconSize / 2));
        favIcon.draw(canvas);

        favIcon = new BitmapDrawable(getResources(), bm);
    }

    return favIcon;
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static Drawable getTabIconDrawable(final Context context, final Object icon_obj) {
    if (context == null)
        return null;
    final Resources res = context.getResources();
    if (icon_obj instanceof Integer) {
        try {/*  w  w w. ja v a 2  s  . c  om*/
            return res.getDrawable((Integer) icon_obj);
        } catch (final Resources.NotFoundException e) {
            // Ignore.
        }
    } else if (icon_obj instanceof Bitmap)
        return new BitmapDrawable(res, (Bitmap) icon_obj);
    else if (icon_obj instanceof Drawable)
        return (Drawable) icon_obj;
    else if (icon_obj instanceof File) {
        final Bitmap b = getTabIconFromFile((File) icon_obj, res);
        if (b != null)
            return new BitmapDrawable(res, b);
    }
    return res.getDrawable(R.drawable.ic_tab_list);
}

From source file:com.androzic.Androzic.java

void installData() {
    defWaypointSet = new WaypointSet(dataPath + File.separator + "myWaypoints.wpt", "myWaypoints");
    waypointSets.add(defWaypointSet);//from  ww w .j av a2 s. com

    File icons = new File(iconPath, "icons.dat");
    if (icons.exists()) {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(icons));
            String[] fields = CSV.parseLine(reader.readLine());
            if (fields.length == 3) {
                iconsEnabled = true;
                iconX = Integer.parseInt(fields[0]);
                iconY = Integer.parseInt(fields[1]);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    File datums = new File(rootPath, "datums.dat");
    if (datums.exists()) {
        try {
            OziExplorerFiles.loadDatums(datums);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    File cursor = new File(rootPath, "cursor.png");
    if (cursor.exists()) {
        try {
            customCursor = new BitmapDrawable(getResources(), cursor.getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //installRawResource(R.raw.datums, "datums.xml");
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private MoreImageSpan createMoreSpan(final int count) {
    final String moreText = String.format(mMoreItem.getText().toString(), count);
    final TextPaint morePaint = new TextPaint(getPaint());
    morePaint.setTextSize(mMoreItem.getTextSize());
    morePaint.setColor(mMoreItem.getCurrentTextColor());
    final int width = (int) morePaint.measureText(moreText) + mMoreItem.getPaddingLeft()
            + mMoreItem.getPaddingRight();
    final int height = getLineHeight();
    final Bitmap drawable = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(drawable);
    int adjustedHeight = height;
    final Layout layout = getLayout();
    if (layout != null)
        adjustedHeight -= layout.getLineDescent(0);
    canvas.drawText(moreText, 0, moreText.length(), 0, adjustedHeight, morePaint);
    final Drawable result = new BitmapDrawable(getResources(), drawable);
    result.setBounds(0, 0, width, height);
    return new MoreImageSpan(result);
}