Example usage for android.graphics.drawable BitmapDrawable setFilterBitmap

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

Introduction

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

Prototype

@Override
    public void setFilterBitmap(boolean filter) 

Source Link

Usage

From source file:Main.java

/**
 * This method of image pixelization utilizes the bitmap scaling operations built
 * into the framework. By downscaling the bitmap and upscaling it back to its
 * original size (while setting the filter flag to false), the same effect can be
 * achieved with much better performance.
 *///from  w  w  w.  ja v  a  2s  . c o m
public static BitmapDrawable builtInPixelization(Context context, float pixelizationFactor, Bitmap bitmap) {

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    int downScaleFactorWidth = (int) (pixelizationFactor * width);
    downScaleFactorWidth = downScaleFactorWidth > 0 ? downScaleFactorWidth : 1;
    int downScaleFactorHeight = (int) (pixelizationFactor * height);
    downScaleFactorHeight = downScaleFactorHeight > 0 ? downScaleFactorHeight : 1;

    int downScaledWidth = width / downScaleFactorWidth;
    int downScaledHeight = height / downScaleFactorHeight;

    Bitmap pixelatedBitmap = Bitmap.createScaledBitmap(bitmap, downScaledWidth, downScaledHeight, false);

    /* Bitmap's createScaledBitmap method has a filter parameter that can be set to either
     * true or false in order to specify either bilinear filtering or point sampling
     * respectively when the bitmap is scaled up or now.
     *
     * Similarly, a BitmapDrawable also has a flag to specify the same thing. When the
     * BitmapDrawable is applied to an ImageView that has some scaleType, the filtering
     * flag is taken into consideration. However, for optimization purposes, this flag was
     * ignored in BitmapDrawables before Jelly Bean MR1.
     *
     * Here, it is important to note that prior to JBMR1, two bitmap scaling operations
     * are required to achieve the pixelization effect. Otherwise, a BitmapDrawable
     * can be created corresponding to the downscaled bitmap such that when it is
     * upscaled to fit the ImageView, the upscaling operation is a lot faster since
     * it uses internal optimizations to fit the ImageView.
     * */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), pixelatedBitmap);
        bitmapDrawable.setFilterBitmap(false);
        return bitmapDrawable;
    } else {
        Bitmap upscaled = Bitmap.createScaledBitmap(pixelatedBitmap, width, height, false);
        return new BitmapDrawable(context.getResources(), upscaled);
    }
}

From source file:de.schildbach.wallet.ui.BitmapFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final BitmapDrawable bitmap = new BitmapDrawable(getResources(), (Bitmap) args.getParcelable(KEY_BITMAP));
    bitmap.setFilterBitmap(false);

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.bitmap_dialog);
    dialog.setCanceledOnTouchOutside(true);

    final ImageView imageView = (ImageView) dialog.findViewById(R.id.bitmap_dialog_image);
    imageView.setImageDrawable(bitmap);/* w w w.  j  av a  2 s.com*/
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            dismissAllowingStateLoss();
        }
    });

    return dialog;
}

From source file:de.schildbach.wallet.ui.WalletAddressDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final Address address = (Address) args.getSerializable(KEY_ADDRESS);
    final String addressStr = address.toBase58();
    final String addressLabel = args.getString(KEY_ADDRESS_LABEL);

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.wallet_address_dialog);
    dialog.setCanceledOnTouchOutside(true);

    final String uri = BitcoinURI.convertToBitcoinURI(address, null, addressLabel, null);
    final BitmapDrawable bitmap = new BitmapDrawable(getResources(), Qr.bitmap(uri));
    bitmap.setFilterBitmap(false);
    final ImageView imageView = (ImageView) dialog.findViewById(R.id.wallet_address_dialog_image);
    imageView.setImageDrawable(bitmap);/* www  .  ja v a 2 s  . c  om*/

    final View labelButtonView = dialog.findViewById(R.id.wallet_address_dialog_label_button);
    final TextView labelView = (TextView) dialog.findViewById(R.id.wallet_address_dialog_label);
    final CharSequence label = WalletUtils.formatHash(addressStr, Constants.ADDRESS_FORMAT_GROUP_SIZE,
            Constants.ADDRESS_FORMAT_LINE_SIZE);
    labelView.setText(label);
    labelButtonView.setVisibility(View.VISIBLE);
    labelButtonView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, addressStr);
            startActivity(Intent.createChooser(intent, getString(R.string.bitmap_fragment_share)));
            log.info("wallet address shared via intent: {}", addressStr);
        }
    });

    final View hintView = dialog.findViewById(R.id.wallet_address_dialog_hint);
    hintView.setVisibility(
            getResources().getBoolean(R.bool.show_wallet_address_dialog_hint) ? View.VISIBLE : View.GONE);

    final View dialogView = dialog.findViewById(R.id.wallet_address_dialog_group);
    dialogView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            dismiss();
        }
    });

    return dialog;
}

From source file:net.sourceforge.servestream.fragment.NowPlayingFragment.java

private void updateNowPlaying() {
    if (mNowPlayingView == null) {
        return;//w  w  w. j  a  v  a  2  s.  c om
    }
    try {
        if (true && mService != null && mService.getAudioId() != -1) {
            Drawable d = null;

            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
            if (preferences.getBoolean(PreferenceConstants.RETRIEVE_ALBUM_ART, false)) {
                long id = mService.getAudioId();
                if (id >= 0) {
                    Bitmap b = BitmapFactory.decodeResource(getActivity().getResources(),
                            R.drawable.albumart_mp_unknown_list);
                    BitmapDrawable defaultAlbumIcon = new BitmapDrawable(getActivity().getResources(), b);
                    // no filter or dither, it's a lot faster and we can't tell the difference
                    defaultAlbumIcon.setFilterBitmap(false);
                    defaultAlbumIcon.setDither(false);

                    d = MusicUtils.getCachedArtwork(getActivity(), mService.getAudioId(), defaultAlbumIcon,
                            true);
                }
            }

            if (d == null) {
                mCoverart.setVisibility(View.GONE);
            } else {
                mCoverart.setVisibility(View.VISIBLE);
                mCoverart.setImageDrawable(d);
            }

            mTitle.setSelected(true);
            mArtist.setSelected(true);

            CharSequence trackName = mService.getTrackName();
            CharSequence artistName = mService.getArtistName();

            if (trackName == null || trackName.equals(Media.UNKNOWN_STRING)) {
                mTitle.setText(R.string.widget_one_track_info_unavailable);
            } else {
                mTitle.setText(trackName);
            }

            if (artistName == null || artistName.equals(Media.UNKNOWN_STRING)) {
                artistName = mService.getMediaUri();
            }

            mArtist.setText(artistName);

            if (mPreviousButton != null) {
                mPreviousButton.setImageResource(R.drawable.btn_player_prev);
                mPreviousButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        try {
                            mService.prev();
                        } catch (RemoteException e) {
                        }
                    }
                });
            }

            mPauseButton.setVisibility(View.VISIBLE);

            if (mService.isPlaying()) {
                mPauseButton.setImageResource(R.drawable.btn_playerpreview_pause);
            } else {
                mPauseButton.setImageResource(R.drawable.btn_playerpreview_play);
            }

            mPauseButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    try {
                        if (mService.isPlaying()) {
                            mService.pause();
                        } else {
                            mService.play();
                        }
                    } catch (RemoteException e) {
                    }
                }
            });

            if (mNextButton != null) {
                mNextButton.setImageResource(R.drawable.btn_player_next);
                mNextButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        try {
                            mService.next();
                        } catch (RemoteException e) {
                        }
                    }
                });
            }

            if (mNowPlayingView.getVisibility() != View.VISIBLE) {
                Animation fade_in = AnimationUtils.loadAnimation(getActivity(), R.anim.player_in);
                mNowPlayingView.startAnimation(fade_in);
            }

            mNowPlayingView.setVisibility(View.VISIBLE);
            mNowPlayingView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Context c = v.getContext();
                    c.startActivity(new Intent(c, MediaPlayerActivity.class));
                }
            });

            return;
        }
    } catch (RemoteException ex) {
    }
    Animation fade_out = AnimationUtils.loadAnimation(getActivity(), R.anim.player_out);
    mNowPlayingView.startAnimation(fade_out);
    mNowPlayingView.setVisibility(View.GONE);
}