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.app.uafeed.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);//w w  w  .j  a v a 2s. c  o  m

        byte[] iconBytes = entryCursor.getBlob(mFeedIconPos);
        Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
        if (bitmap != null) {
            activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
        } else {
            activity.getActionBar().setIcon(R.drawable.icon);
        }

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        boolean isRefreshing = FetcherService.hasTasks(mEntriesIds[mCurrentPagerPos]);
        activity.getProgressBar().setVisibility(isRefreshing ? View.VISIBLE : View.GONE);

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

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

/**
 * ?//from  w w w.java2  s  .  co m
 *
 * @param data
 */
private void setPicToView(Intent data) {

    Bundle extras = data.getExtras();
    if (extras != null) {

        Bitmap bitmap = extras.getParcelable("data");

        Drawable drawable = new BitmapDrawable(null, bitmap);

        String HeadPortrait = BitmapUtil.getImgStr(bitmap);
        switch (imgType) {
        case 0:
            mIv_sf.setImageDrawable(drawable);
            mJsonObject.addProperty("IDNumberImg", HeadPortrait);//?
            isimg0 = true;
            break;
        case 1:
            mIv_js.setImageDrawable(drawable);
            mJsonObject.addProperty("DriverLicenseImg", HeadPortrait);//?
            isimg1 = true;
            break;
        case 2:
            mIv_xs.setImageDrawable(drawable);
            mJsonObject.addProperty("TravelCardImg", HeadPortrait);//?
            isimg2 = true;
            break;
        case 3:
            mIv_che.setImageDrawable(drawable);
            mJsonObject.addProperty("VehImg", HeadPortrait);//
            isimg3 = true;
            break;

        }

    }

}

From source file:com.appgeneration.magmanager.imagefetcher.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from w  w  w  . j av  a  2  s  . c  o  m
 * @param bitmap
 */
@SuppressWarnings("deprecation")
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        imageView.setBackgroundDrawable(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.android.beez.loadimage.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*ww w .  ja  va  2s  .  c om*/
 * 
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final
        // drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.jcsoluciones.superdt.utilities.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//  w  w w.j a  va2 s.  co  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(R.color.colorPrimary), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private ExtensibleKeyButtonView generateKey(boolean landscape, String clickAction, String longpress,
        String iconUri) {//from ww  w. ja  v a2s.  c  o m

    final int iconSize = 80;
    ExtensibleKeyButtonView v = new ExtensibleKeyButtonView(mContext, null, clickAction, longpress);
    Log.i("key.ext", "generated ex key: " + clickAction);
    v.setLayoutParams(getLayoutParams(landscape, iconSize));

    boolean drawableSet = false;

    if (iconUri != null) {
        if (iconUri.length() > 0) {
            // custom icon from the URI here
            File f = new File(Uri.parse(iconUri).getPath());
            if (f.exists()) {
                v.setImageDrawable(new BitmapDrawable(getResources(), f.getAbsolutePath()));
                drawableSet = true;
            }
        }
        if (!drawableSet && clickAction != null && !clickAction.startsWith("**")) {
            // here it's not a system action (**action**), so it must be an
            // app intent
            try {
                Drawable d = mContext.getPackageManager().getActivityIcon(Intent.parseUri(clickAction, 0));
                final int[] appIconPadding = getAppIconPadding();
                if (landscape)
                    v.setPaddingRelative(appIconPadding[1], appIconPadding[0], appIconPadding[3],
                            appIconPadding[2]);
                else
                    v.setPaddingRelative(appIconPadding[0], appIconPadding[1], appIconPadding[2],
                            appIconPadding[3]);
                v.setImageDrawable(d);
                drawableSet = true;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
                drawableSet = false;
            } catch (URISyntaxException e) {
                e.printStackTrace();
                drawableSet = false;
            }
        }
    }

    if (!drawableSet) {
        v.setImageDrawable(getNavbarIconImage(landscape, clickAction));
    }

    v.setGlowBackground(landscape ? R.drawable.ic_sysbar_highlight_land : R.drawable.ic_sysbar_highlight);
    return v;
}

From source file:com.krava.vkmessenger.domain.image.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*from  ww w.  j a v  a 2s. c  om*/
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(imageView.getResources().getColor(android.R.color.transparent)), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

void switchToGrid() {
    IS_LIST = false;/*from w w w.  ja  v  a 2 s  . c o  m*/

    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    folder = new BitmapDrawable(res, mFolderBitmap);
    fixIcons(true);

    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT)) {

        // will always be grid, set alternate white background
        listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light));
    }

    if (mLayoutManagerGrid == null)
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
    listView.setLayoutManager(mLayoutManagerGrid);
    adapter = null;
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.e("Activity sss1", "sds");
    if (requestCode == GALLERY_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data != null) {
                uri = data.getData();//  ww  w .j ava2  s . co  m
                image_path = uri.getPath();
                //addNewVehicalFragment.setImagePath(image_path);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                try {
                    // BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
                    options.inSampleSize = calculateInSampleSize(options, 100, 100);
                    options.inJustDecodeBounds = false;
                    Bitmap image = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null,
                            options);

                    car_image.setImageBitmap(image);
                    car_image1.setImageBitmap(image);
                    /*
                    Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap();
                    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                    File destination = new File(getCacheDir(), "car.jpg");
                    FileOutputStream fo;
                    try {
                    fo = new FileOutputStream(destination);
                    fo.write(bytes.toByteArray());
                    fo.close();
                    } catch (IOException e) {
                    e.printStackTrace();
                    }
                    image_path = destination.getAbsolutePath();*/
                    // car_image.setImageBitmap(bitmap);
                    //  addNewVehicalFragment.setImagePath(image_path);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    } else if (requestCode == CAMERA_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data.hasExtra("data")) {
                Bitmap bitmap = (Bitmap) data.getExtras().get("data");
                /* ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                 bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                 File destination = new File(getCacheDir(), "car.jpg");
                 FileOutputStream fo;
                 try {
                fo = new FileOutputStream(destination);
                fo.write(bytes.toByteArray());
                fo.close();
                 } catch (IOException e) {
                e.printStackTrace();
                 }
                 image_path = destination.getAbsolutePath();*/
                car_image.setImageBitmap(bitmap);
                car_image1.setImageBitmap(bitmap);
                // addNewVehicalFragment.setImagePath(image_path);
            } else if (data.getExtras() == null) {

                Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show();

                BitmapDrawable thumbnail = new BitmapDrawable(getResources(), data.getData().getPath());
                //img_view_drivingLicense.setImageDrawable(thumbnail);
                car_image.setImageDrawable(thumbnail);
                car_image1.setImageDrawable(thumbnail);

            }

        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

void switchToList() {
    IS_LIST = true;// w ww. j  a v a  2s.co  m

    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT)) {

        listView.setBackgroundDrawable(null);
    }

    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    folder = new BitmapDrawable(res, mFolderBitmap);
    fixIcons(true);
    if (mLayoutManager == null)
        mLayoutManager = new LinearLayoutManager(getActivity());
    listView.setLayoutManager(mLayoutManager);
    adapter = null;
}