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.artioml.practice.activities.LicenseActivity.java

public BitmapDrawable drawParallelogramLine(int width) {
    Matrix matrix = new Matrix();
    Path path = new Path();
    path.addRect(0, 0, (4 * width) / 40, (4 * width) / 200, Path.Direction.CW);
    Path pathStamp = new Path();
    Paint p;/*from   w  w w  .  java  2 s . c  o m*/
    Bitmap bitmap;

    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setStyle(Paint.Style.FILL);

    bitmap = Bitmap.createBitmap(width / 4, width / 80 * 2 + (4 * width) / 200, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    p.setColor(ContextCompat.getColor(this, R.color.colorPrimaryLight));

    matrix.reset();
    matrix.setTranslate(0, 0);
    matrix.postSkew(-1f, 0.0f, 0, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    p.setColor(ContextCompat.getColor(this, R.color.colorAccent));

    matrix.reset();
    matrix.setTranslate(width / 8, 0);
    matrix.postSkew(-1f, 0.0f, width / 8, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
    bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);

    return bitmapDrawable;
}

From source file:com.linkbubble.ui.ContentViewButton.java

public void setImageDrawable(Drawable drawable) {

    if (drawable instanceof BitmapDrawable) {
        int maxIconSize = getMaxIconSize();

        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        int width = bitmapDrawable.getBitmap().getWidth();
        int height = bitmapDrawable.getBitmap().getHeight();
        if (width > 0 && height > 0 && (width > maxIconSize || height > maxIconSize)) {
            int newHeight;
            int newWidth;
            if (width > height) {
                newWidth = maxIconSize;/*from   w  ww .  j  a v a2  s . c  om*/
                newHeight = (int) ((float) (height / width) * maxIconSize);
            } else if (width < height) {
                newHeight = maxIconSize;
                newWidth = (int) ((float) (width / height) * maxIconSize);
                if (0 == newWidth) {
                    newWidth = newHeight;
                }
            } else {
                newWidth = newHeight = maxIconSize;
            }

            // Potential fix for user exceptions below saying that width and height must be > 0
            newWidth = Math.max(1, newWidth);
            newHeight = Math.max(1, newHeight);

            try {
                Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmapDrawable.getBitmap(), newWidth,
                        newHeight, true);
                drawable = new BitmapDrawable(getResources(), resizedBitmap);
            } catch (java.lang.OutOfMemoryError ex) {

            }
        }
    }

    mImageView.setImageDrawable(drawable);
}

From source file:com.mobicage.rogerthat.NavigationItem.java

public Drawable getIcon(Context context) {
    if (this.faIcon == null) {
        Bitmap bm = ImageHelper//from  w w w  .j a  v a 2s .c  om
                .getRoundedCornerAvatar(BitmapFactory.decodeResource(context.getResources(), this.iconId));
        return new BitmapDrawable(context.getResources(), bm);
    }
    return new IconicsDrawable(context, this.faIcon).color(ContextCompat.getColor(context, R.color.mc_white))
            .paddingDp(8);
}

From source file:ca.taglab.PictureFrame.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout containing a title and body text.
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container,
            false);/*from w ww .j av  a 2  s  . c  om*/

    Bitmap picture = BitmapFactory.decodeFile(mImgPath);
    rootView.setBackground(new BitmapDrawable(getResources(), picture));

    mConfirmation = (ImageView) rootView.findViewById(R.id.confirm);

    ((TextView) rootView.findViewById(R.id.name)).setText(mName);
    rootView.findViewById(R.id.control).getBackground().setAlpha(200);

    optionsOpen = false;

    mMsgHistory = rootView.findViewById(R.id.msg);
    mMsgHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), MessagesActivity.class);
            intent.putExtra("user_name", mName);
            intent.putExtra("user_id", mId);
            intent.putExtra("owner_id", mOwnerId);
            startActivity(intent);
            hideOptions();
        }
    });

    mPhoto = rootView.findViewById(R.id.photo);
    mPhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String filename = String.valueOf(System.currentTimeMillis()) + ".jpg";
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.TITLE, filename);
                mCapturedImageURI = getActivity().getContentResolver()
                        .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
                startActivityForResult(intent, CAPTURE_PICTURE);
                hideOptions();
            } catch (Exception e) {
                Log.e(TAG, "Camera intent failed");
            }
        }
    });

    mVideo = rootView.findViewById(R.id.video);
    mVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String filename = String.valueOf(System.currentTimeMillis()) + ".3gp";
                ContentValues values = new ContentValues();
                values.put(MediaStore.Video.Media.TITLE, filename);
                mCapturedVideoURI = getActivity().getContentResolver()
                        .insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);

                Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedVideoURI);
                startActivityForResult(intent, CAPTURE_VIDEO);
                hideOptions();
            } catch (Exception e) {
                Log.e(TAG, "Video intent failed");
            }
        }
    });

    mAudio = rootView.findViewById(R.id.audio);
    mAudio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Intent intent = new Intent(getActivity(), AudioRecorderActivity.class);
                startActivityForResult(intent, CAPTURE_AUDIO);
                hideOptions();
            } catch (Exception e) {
                Log.e(TAG, "Audio intent failed");
            }
        }
    });

    mWave = rootView.findViewById(R.id.wave);
    mWave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I'm thinking of you",
                        "Wave sent via PictureFrame", null).execute();
                //Toast.makeText(getActivity(), "Wave sent to: " + mEmail, Toast.LENGTH_SHORT).show();
                hideOptions();
                messageSent(v);
            } catch (Exception e) {
                Log.e("SendEmailAsyncTask", e.getMessage(), e);
                //Toast.makeText(getActivity(), "Wave to " + mEmail + " failed", Toast.LENGTH_SHORT).show();
            }
        }
    });

    mCancel = rootView.findViewById(R.id.close);

    mPhoto.getBackground().setAlpha(200);
    mVideo.getBackground().setAlpha(200);
    mAudio.getBackground().setAlpha(200);
    mWave.getBackground().setAlpha(200);

    mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    mLongAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime);

    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!optionsOpen)
                showOptions();
        }
    });

    mCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (optionsOpen)
                hideOptions();
        }
    });

    Cursor unread = getActivity().getContentResolver().query(UserContentProvider.MESSAGE_CONTENT_URI,
            MessageTable.PROJECTION,
            MessageTable.COL_TO_ID + "=? AND " + MessageTable.COL_FROM_ID + "=? AND " + MessageTable.COL_READ
                    + "=?",
            new String[] { Long.toString(mOwnerId), Long.toString(mId), Long.toString(0) }, null);
    if (unread != null && unread.moveToFirst()) {
        rootView.findViewById(R.id.notification).setVisibility(View.VISIBLE);
        rootView.findViewById(R.id.notification).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MessagesActivity.class);
                intent.putExtra("user_name", mName);
                intent.putExtra("user_id", mId);
                intent.putExtra("owner_id", mOwnerId);
                startActivity(intent);
                v.setVisibility(View.INVISIBLE);
            }
        });
    }
    if (unread != null) {
        unread.close();
    }

    return rootView;
}

From source file:com.cooltechworks.views.ScratchTextView.java

/**
 * Initialises the paint drawing elements.
 *//*  w  w w .  j a v a  2s. c  o m*/
private void init() {

    mTouchPath = new Path();

    mErasePaint = new Paint();
    mErasePaint.setAntiAlias(true);
    mErasePaint.setDither(true);
    mErasePaint.setColor(0xFFFF0000);
    mErasePaint.setStyle(Paint.Style.STROKE);
    mErasePaint.setStrokeJoin(Paint.Join.BEVEL);
    mErasePaint.setStrokeCap(Paint.Cap.ROUND);
    mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    setStrokeWidth(6);

    mGradientBgPaint = new Paint();

    mErasePath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    Bitmap scratchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_scratch_pattern);
    mDrawable = new BitmapDrawable(getResources(), scratchBitmap);
    mDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);

}

From source file:com.kayac.slidingmenu.ui.views.DraggableLayout.java

public void setShadowBitmap(Bitmap shadowBitmap) {
    if (shadowBitmap != null) {
        mShadowDrawable = new BitmapDrawable(mContext.getResources(), shadowBitmap);
        if (mDefaultMenuSideLeft) {
            mShadowDrawable.setBounds(-shadowBitmap.getWidth(), 0, 0, screenSize.y);
        } else {//from  ww  w  .java  2  s. c om
            mShadowDrawable.setBounds(screenSize.x, 0, screenSize.x + shadowBitmap.getWidth(), screenSize.y);
        }
    }
}

From source file:com.example.scratchview.ScratchImageView.java

/**
 * Initialises the paint drawing elements.
 *///from  w  w w .j a v a2s .c om
private void init() {

    mTouchPath = new Path();

    mErasePaint = new Paint();
    mErasePaint.setAntiAlias(true);
    mErasePaint.setDither(true);
    mErasePaint.setColor(0xFFFF0000);
    mErasePaint.setStyle(Paint.Style.STROKE);
    mErasePaint.setStrokeJoin(Paint.Join.BEVEL);
    mErasePaint.setStrokeCap(Paint.Cap.ROUND);
    setStrokeWidth(6);

    mGradientBgPaint = new Paint();

    mErasePath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    Bitmap scratchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_scratch_pattern);
    mDrawable = new BitmapDrawable(getResources(), scratchBitmap);
    mDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);

    setEraserMode();

}

From source file:com.github.rutvijkumar.twittfuse.fragments.ProfileImageViewFragment.java

private void setBackGround(User user, ImageLoader imageLoader, final RelativeLayout profileInfoLayout,
        String url) {// w ww .jav a  2 s .  co  m
    imageLoader.loadImage(url, new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingComplete(String arg0, View arg1, Bitmap bitmap) {
            // TODO Auto-generated method stub
            BitmapDrawable bg = new BitmapDrawable(getResources(), bitmap);
            profileInfoLayout.setBackground(bg);

        }

        @Override
        public void onLoadingCancelled(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }
    });

}

From source file:com.example.android.uamp.ui.tv.CardViewHolder.java

private void setCardImage(Context context, Bitmap art) {
    if (mCardView == null) {
        return;/*from  ww  w.  j a  va 2  s.  co m*/
    }
    Drawable artDrawable = null;
    if (art != null) {
        artDrawable = new BitmapDrawable(context.getResources(), art);
    } else {
        CharSequence title = mCardView.getTitleText();
        if (title != null && title.length() > 0) {
            artDrawable = new TextDrawable(String.valueOf(title.charAt(0)));
        }
    }
    mCardView.setMainImage(artDrawable);
}

From source file:Main.java

public static Drawable makeRecoloredDrawable(Context context, BitmapDrawable drawable, int color,
        boolean withStates) {
    Bitmap recoloredBitmap = recolorBitmap(drawable, color);
    BitmapDrawable recoloredDrawable = new BitmapDrawable(context.getResources(), recoloredBitmap);

    if (!withStates) {
        return recoloredDrawable;
    }//from  w w w  . j  av  a  2  s . com

    StateListDrawable stateDrawable = new StateListDrawable();
    stateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawable);
    stateDrawable.addState(new int[] { android.R.attr.state_focused }, drawable);
    stateDrawable.addState(new int[] {}, recoloredDrawable);
    return stateDrawable;
}