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.baoyz.dribble.widget.SwipeHoverLayout.java

private Drawable generateBlurDrawable() {
    return new BitmapDrawable(getResources(), Blur.apply(getContext(), Util.getViewBitmap(this)));
}

From source file:mp.paschalis.LoginFragment.java

/**
 * Update the login View/* ww w . j  a v  a  2s .  c o  m*/
 *
 * @param code the Library code
 */
public void updateLoginView(Library lib) {

    try {
        ((StartActivity) getSherlockActivity()).isLibrarySelected = true;
        // Invalidate the menu, so a new one will be created
        ((StartActivity) getSherlockActivity()).invalidateOptionsMenu();

        TextView loginLibrary = (TextView) getSherlockActivity().findViewById(R.id.TextViewLoginLibraryName);

        loginLibrary.setText(lib.name);

        textViewLibraryLocation = (TextView) getSherlockActivity()
                .findViewById(R.id.textViewLoginLibraryLocation);

        textViewLibraryLocation.setText(lib.location);

        ImageView loginLogo = (ImageView) getSherlockActivity().findViewById(R.id.imageViewLoginLibraryLogo);

        // Show logo
        ImageLoader.DataClassDisplayBookCover bk = new ImageLoader.DataClassDisplayBookCover();
        bk.iv = loginLogo;
        App.imageLoader.DisplayImage(lib.getImageURL(), bk);

        // Save bitmap in app
        loginLogo.buildDrawingCache();

        // Save Library logo as drawable in app
        app.loginLogoDrawable = new BitmapDrawable(getResources(), loginLogo.getDrawingCache());

        enableLoginForm();
        tryToAutofillWithPrefs();
    } catch (NullPointerException npe) {
        // noth
    }

}

From source file:com.mycelium.wallet.activity.modern.ModernMain.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _mbwManager = MbwManager.getInstance(this);
    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);/*  w ww .  jav a  2  s .  c  om*/
    setContentView(mViewPager);
    ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(1, ActionBar.DISPLAY_SHOW_TITLE);

    // Load the theme-background (usually happens in styles.xml) but use a lower
    // pixel format, this saves around 10MB of allocated memory
    // persist the loaded Bitmap in the context of mbw-manager and reuse it every time this activity gets created
    try {
        BitmapDrawable background = (BitmapDrawable) _mbwManager.getBackgroundObjectsCache()
                .get("mainBackground", new Callable<BitmapDrawable>() {
                    @Override
                    public BitmapDrawable call() throws Exception {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        options.inPreferredConfig = Bitmap.Config.RGB_565;
                        Bitmap background = BitmapFactory.decodeResource(getResources(),
                                R.drawable.background_witherrors_dimmed, options);
                        BitmapDrawable drawable = new BitmapDrawable(getResources(), background);
                        drawable.setGravity(Gravity.CENTER);
                        return drawable;
                    }
                });
        getWindow().setBackgroundDrawable(background);
    } catch (ExecutionException ignore) {
    }

    mTabsAdapter = new TabsAdapter(this, mViewPager, _mbwManager);
    mAccountsTab = bar.newTab();
    mTabsAdapter.addTab(mAccountsTab.setText(getString(R.string.tab_accounts)), AccountsFragment.class, null);
    mBalanceTab = bar.newTab();
    mTabsAdapter.addTab(mBalanceTab.setText(getString(R.string.tab_balance)), BalanceMasterFragment.class,
            null);
    mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.tab_transactions)),
            TransactionHistoryFragment.class, null);
    final Bundle addressBookConfig = new Bundle();
    addressBookConfig.putBoolean(AddressBookFragment.SELECT_ONLY, false);
    mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.tab_addresses)), AddressBookFragment.class,
            addressBookConfig);

    bar.selectTab(mBalanceTab);
    _toaster = new Toaster(this);

    ChangeLog cl = new DarkThemeChangeLog(this);
    if (cl.isFirstRun() && cl.getChangeLog(false).size() > 0 && !cl.isFirstRunEver()) {
        cl.getLogDialog().show();
    }

    checkTorState();

    if (savedInstanceState != null) {
        _lastSync = savedInstanceState.getLong(LAST_SYNC, 0);
        _isAppStart = savedInstanceState.getBoolean(APP_START, true);
    }

    if (_isAppStart) {
        _mbwManager.getVersionManager().showFeatureWarningIfNeeded(this, Feature.APP_START);
        checkGapBug();
        _isAppStart = false;
    }
}

From source file:com.hengtan.nanodegreeapp.stocount.ProductDetailGridPagerAdapter.java

@Override
public Drawable getBackgroundForRow(final int row) {

    if (mThumbnail != null) {
        return new BitmapDrawable(mContext.getResources(), mThumbnail);
    } else {// www  . jav  a  2s  . com
        return mRowBackgrounds.get(row);
    }
}

From source file:com.ae.apps.tripmeter.fragments.expenses.TripDetailsFragment.java

private void addTripMembersToContainer() {
    String[] memberIds = mTrip.getMemberIds().split(AppConstants.CONTACT_ID_SEPARATOR);
    RoundedImageView roundedImageView;//www  .  j a va 2s  .  co m
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(5, 5, 5, 5);
    for (String memberId : memberIds) {
        roundedImageView = new RoundedImageView(getContext());
        roundedImageView.setImageDrawable(
                new BitmapDrawable(getResources(), mExpenseManager.getContactPhoto(memberId)));
        mTripMembersContainer.addView(roundedImageView, layoutParams);
    }
}

From source file:com.example.app_2.utils.Utils.java

public static void setWallpaper(android.view.ViewGroup vg, int reqWidth, int reqHeight, Bitmap wallpaper,
        ScalingLogic sl) {/* w ww.  j  a  v  a  2s . c  o  m*/

    if (wallpaper == null) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(App_2.getAppContext());
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        wallpaper = BitmapCalc.drawableToBitmap(wallpaperDrawable);
    }

    if (reqHeight == 0 || reqWidth == 0) {
        reqHeight = App_2.getMaxHeight();
        reqWidth = App_2.getMaxWidth();
    }

    Resources r = App_2.getAppContext().getResources();
    int orientation = r.getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE: // landscape
        Bitmap wallpaperLandscape = ScalingUtilities.createScaledBitmap(wallpaper, reqHeight, reqWidth, sl);
        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperLandscape));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            }

        }
        //wallpaperLandscape.recycle();
        break;
    case Configuration.ORIENTATION_PORTRAIT: // portrait
        Bitmap wallpaperPortrait = ScalingUtilities.createScaledBitmap(wallpaper, reqWidth, reqHeight, sl);

        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperPortrait));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            }
        }
        //wallpaperPortrait.recycle();
        break;
    default:
        //ll.setBackgroundDrawable(App_2.wallpaperDrawable);
        break;
    }
}

From source file:co.nerdart.ourss.adapter.FeedsCursorAdapter.java

@Override
protected void bindChildView(View view, Context context, Cursor cursor) {
    view.findViewById(R.id.indicator).setVisibility(View.INVISIBLE);

    TextView textView = ((TextView) view.findViewById(android.R.id.text1));
    long feedId = cursor.getLong(idPosition);
    if (feedId == mSelectedFeedId) {
        view.setBackgroundResource(android.R.color.holo_blue_dark);
    } else {/*from w  w w.j ava 2  s  .com*/
        view.setBackgroundResource(android.R.color.transparent);
    }

    TextView updateTextView = ((TextView) view.findViewById(android.R.id.text2));
    updateTextView.setVisibility(View.VISIBLE);

    if (cursor.isNull(errorPosition)) {
        long timestamp = cursor.getLong(lastUpdateColumn);

        // Date formatting is expensive, look at the cache
        String formattedDate = mFormattedDateCache.get(timestamp);
        if (formattedDate == null) {
            Date date = new Date(timestamp);

            formattedDate = context.getString(R.string.update) + COLON
                    + (timestamp == 0 ? context.getString(R.string.never)
                            : new StringBuilder(Constants.DATE_FORMAT.format(date)).append(' ')
                                    .append(Constants.TIME_FORMAT.format(date)));
            mFormattedDateCache.put(timestamp, formattedDate);
        }

        updateTextView.setText(formattedDate);
    } else {
        updateTextView.setText(new StringBuilder(context.getString(R.string.error)).append(COLON)
                .append(cursor.getString(errorPosition)));
    }

    byte[] iconBytes = cursor.getBlob(iconPosition);

    if (iconBytes != null && iconBytes.length > 0) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length);

        if (bitmap != null && bitmap.getHeight() > 0 && bitmap.getWidth() > 0) {
            int bitmapSizeInDip = UiUtils.dpToPixel(18);

            if (bitmap.getHeight() != bitmapSizeInDip) {
                bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false);
            }
            textView.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(context.getResources(), bitmap),
                    null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }
    } else {
        view.setTag(null);
        textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }

    int unreadCount;
    synchronized (mUnreadItemsByFeed) {
        unreadCount = mUnreadItemsByFeed.get(feedId);
    }

    if (unreadCount > 0) {
        textView.setEnabled(true);
        updateTextView.setEnabled(true);
    } else {
        textView.setEnabled(false);
        updateTextView.setEnabled(false);
    }
    textView.setText(
            (cursor.isNull(namePosition) ? cursor.getString(linkPosition) : cursor.getString(namePosition))
                    + (unreadCount > 0 ? " (" + unreadCount + ")" : ""));

    View sortView = view.findViewById(R.id.sortitem);
    if (!sortViews.contains(sortView)) { // as we are reusing views, this is fine
        sortViews.add(sortView);
    }
    sortView.setVisibility(feedSort ? View.VISIBLE : View.GONE);
}

From source file:com.conferenceengineer.android.iosched.ui.tablet.TracksDropdownFragment.java

private void loadTrack(Cursor cursor, boolean triggerCallback) {
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);

        mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

        String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME);

        mTitle.setText(trackName);//from  w w  w.  j  a va 2  s . c  o  m
        mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

        int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable",
                getActivity().getPackageName());
        if (iconResId != 0) {
            BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId);
            Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(),
                    sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(icon);
            sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight());
            sourceIconDrawable.draw(canvas);
            BitmapDrawable iconDrawable = new BitmapDrawable(res, icon);
            mIcon.setImageDrawable(iconDrawable);
        } else {
            mIcon.setImageDrawable(null);
        }
    } else {
        trackColor = res.getColor(R.color.all_track_color);
        mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID;

        mIcon.setImageDrawable(null);
        switch (mViewType) {
        case VIEW_TYPE_SESSIONS:
            mTitle.setText(R.string.all_tracks_sessions);
            mAbstract.setText(R.string.all_tracks_subtitle_sessions);
            break;
        case VIEW_TYPE_OFFICE_HOURS:
            mTitle.setText(R.string.all_tracks_office_hours);
            mAbstract.setText(R.string.all_tracks_subtitle_office_hours);
            break;
        case VIEW_TYPE_SANDBOX:
            mTitle.setText(R.string.all_tracks_sandbox);
            mAbstract.setText(R.string.all_tracks_subtitle_sandbox);
            break;
        }
    }

    mRootView.setBackgroundColor(trackColor);
    mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString());

    if (triggerCallback) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCallbacks.onTrackSelected(mTrackId);
            }
        });
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.TracksDropdownFragment.java

private void loadTrack(Cursor cursor, boolean triggerCallback) {
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);

        mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

        String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME);

        mTitle.setText(trackName);//from   w w w  .  j  av  a 2  s  .c  om
        mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

        int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable",
                getActivity().getPackageName());
        if (iconResId != 0) {
            BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId);
            Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(),
                    sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(icon);
            sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight());
            sourceIconDrawable.draw(canvas);
            BitmapDrawable iconDrawable = new BitmapDrawable(res, icon);
            mIcon.setImageDrawable(iconDrawable);
        } else {
            mIcon.setImageDrawable(null);
        }
    } else {
        trackColor = res.getColor(R.color.all_track_color);
        mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID;

        mIcon.setImageDrawable(null);
        switch (mViewType) {
        case VIEW_TYPE_SESSIONS:
            mTitle.setText(R.string.all_tracks_sessions);
            mAbstract.setText(R.string.all_tracks_subtitle_sessions);
            break;
        case VIEW_TYPE_SANDBOX:
            mTitle.setText(R.string.all_tracks_sandbox);
            mAbstract.setText(R.string.all_tracks_subtitle_sandbox);
            break;
        }
    }

    mRootView.setBackgroundColor(trackColor);
    mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString());

    if (triggerCallback) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCallbacks.onTrackSelected(mTrackId);
            }
        });
    }
}

From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java

@Override
protected Object doInBackground(Object[] params) {

    Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);

    Canvas canvasBackground = new Canvas(bitmapBackground);
    Paint paint = new Paint();
    paint.setStrokeWidth(1f);/* w  w  w  . j a  v a 2s  .com*/
    int starty = 0;
    int endy = mViewHeight;
    canvasBackground.drawColor(Color.BLACK);
    double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth);
    mLogScaledX_values = new double[mViewWidth];
    for (int i = 0; i < mViewWidth; i++) {
        if (i == 0) {
            mLogScaledX_values[i] = 20;
        } else {
            mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio;
        }
    }

    //Major lines
    for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]);
        float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480;
        paint.setTextSize(textSize);
        Log.i("Density", "" + getPixelDensity(mContext));
        if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart + (getPixelDensity(mContext) * 10) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 70) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
            canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);
        }
    }

    //Minor lines
    for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]);
        canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);

        if (isShowLabels()) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500
                    || MINOR_GRIDLINE_POINTS[i] == 5000)
                canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        }
    }

    float[] Y_points = calculateGraphYAxis();
    float div = mViewHeight / (Y_points.length - 1);
    //Level lines
    for (int i = 0; i < Y_points.length - 1; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint);
    }

    //Level labels
    if (isShowLabels()) {
        for (int i = 0; i < Y_points.length; i++) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (i == 0)
                canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint);
            else if (i == Y_points.length - 1)
                canvasBackground.drawText("", 0, div * i, paint);
            else
                canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint);
        }
    }

    BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground);
    mDrawableBackground = drawable;

    //Plotting the curve points

    Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);
    Canvas canvasForeground = new Canvas(bitmapForeground);
    Paint plotPaint = new Paint();
    plotPaint.setStyle(Paint.Style.STROKE);
    plotPaint.setStrokeCap(Paint.Cap.ROUND);
    plotPaint.setStrokeWidth(PLOT_THICKNESS);
    plotPaint.setAntiAlias(true);
    plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color));

    for (int i = 0; i < X_values.length; i++) {
        //            canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint);
        /*float startX, float startY, float stopX, float stopY,
        @NonNull Paint paint*/
        float startX = (float) getGetPixelValueForX(X_values[i]);
        float startY = mViewHeight
                - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        float stopX;
        float stopY;
        if (i == X_values.length - 1) {
            stopX = (float) getGetPixelValueForX(X_values[i]);
            stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        } else {
            stopX = (float) getGetPixelValueForX(X_values[i + 1]);
            stopY = mViewHeight
                    - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]);
        }

        canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint);

    }

    BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground);
    mDrawableForeground = drawableFore;
    return null;
}