Java Code Examples for android.graphics.drawable.BitmapDrawable#setAlpha()

The following examples show how to use android.graphics.drawable.BitmapDrawable#setAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainView.java    From 2048 with Apache License 2.0 6 votes vote down vote up
private void drawEndGameState(Canvas canvas) {
    double alphaChange = 1;
    continueButtonEnabled = false;
    for (AnimationCell animation : game.aGrid.globalAnimation) {
        if (animation.getAnimationType() == MainGame.FADE_GLOBAL_ANIMATION) {
            alphaChange = animation.getPercentageDone();
        }
    }
    BitmapDrawable displayOverlay = null;
    if (game.gameWon()) {
        if (game.canContinue()) {
            continueButtonEnabled = true;
            displayOverlay = winGameContinueOverlay;
        } else {
            displayOverlay = winGameFinalOverlay;
        }
    } else if (game.gameLost()) {
        displayOverlay = loseGameOverlay;
    }

    if (displayOverlay != null) {
        displayOverlay.setBounds(startingX, startingY, endingX, endingY);
        displayOverlay.setAlpha((int) (255 * alphaChange));
        displayOverlay.draw(canvas);
    }
}
 
Example 2
Source File: InputOverlayDrawableJoystick.java    From citra_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param res                {@link Resources} instance.
 * @param bitmapOuter        {@link Bitmap} which represents the outer non-movable part of the joystick.
 * @param bitmapInnerDefault {@link Bitmap} which represents the default inner movable part of the joystick.
 * @param bitmapInnerPressed {@link Bitmap} which represents the pressed inner movable part of the joystick.
 * @param rectOuter          {@link Rect} which represents the outer joystick bounds.
 * @param rectInner          {@link Rect} which represents the inner joystick bounds.
 * @param joystick           Identifier for which joystick this is.
 */
public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter,
        Bitmap bitmapInnerDefault, Bitmap bitmapInnerPressed,
        Rect rectOuter, Rect rectInner, int joystick)
{
  axisIDs[0] = joystick + 1; // Up
  axisIDs[1] = joystick + 2; // Down
  axisIDs[2] = joystick + 3; // Left
  axisIDs[3] = joystick + 4; // Right
  mJoystickType = joystick;

  mOuterBitmap = new BitmapDrawable(res, bitmapOuter);
  mDefaultStateInnerBitmap = new BitmapDrawable(res, bitmapInnerDefault);
  mPressedStateInnerBitmap = new BitmapDrawable(res, bitmapInnerPressed);
  mBoundsBoxBitmap = new BitmapDrawable(res, bitmapOuter);
  mWidth = bitmapOuter.getWidth();
  mHeight = bitmapOuter.getHeight();

  setBounds(rectOuter);
  mDefaultStateInnerBitmap.setBounds(rectInner);
  mPressedStateInnerBitmap.setBounds(rectInner);
  mVirtBounds = getBounds();
  mOrigBounds = mOuterBitmap.copyBounds();
  mBoundsBoxBitmap.setAlpha(0);
  mBoundsBoxBitmap.setBounds(getVirtBounds());
  SetInnerBounds();
}
 
Example 3
Source File: BlurBehind.java    From RhymeMusic with Apache License 2.0 5 votes vote down vote up
public void setBackground(Activity activity) {
    if (mImageCache.size() != 0) {
        BitmapDrawable bd = new BitmapDrawable(activity.getResources(), mImageCache.get(KEY_CACHE_BLURRED_BACKGROUND_IMAGE));
        bd.setAlpha(mAlpha);
        if (mFilterColor != -1) {
            bd.setColorFilter(mFilterColor, PorterDuff.Mode.DST_ATOP);
        }
        activity.getWindow().setBackgroundDrawable(bd);
        mImageCache.remove(KEY_CACHE_BLURRED_BACKGROUND_IMAGE);
        cacheBlurBehindAndExecuteTask = null;
    }
}
 
Example 4
Source File: PickerUIBlurHelper.java    From PickerUI with Apache License 2.0 5 votes vote down vote up
/**
 * This method set the downscaled and blurred image in the fake ImageView, and with a filter
 * over the image if it's
 * necessary.
 *
 * @param blurBitmap the bitmap downscaled and blurred.
 */
void setBackground(Bitmap blurBitmap) {
    BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), blurBitmap);
    bd.setAlpha(mAlpha);
    if (mFilterColor != -1) {
        changeBitmapColor(bd.getBitmap(), mBlurredImageView, mFilterColor);
    } else {
        mBlurredImageView.setImageBitmap(blurBitmap);
    }
}
 
Example 5
Source File: ThemeableActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
public static void setBackgroundImage (View view, Activity activity)
{
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
    boolean themeDark = settings.getBoolean("themeDark", false);
    String themebg = settings.getString("pref_background", "");

    if(themeDark)
        view.setBackgroundColor(activity.getResources().getColor(R.color.background_dark));
    else
        view.setBackgroundColor(activity.getResources().getColor(R.color.background_light));

    if (themebg != null && themebg.length() > 0)
    {

        File fileThemeBg = new File(themebg);
        if (!fileThemeBg.exists())
            return;

        if (mThemeBg == null || (!mThemeBg.equals(themebg)))
        {
            mThemeBg = themebg;

            Display display = activity.getWindowManager().getDefaultDisplay();
            int width = display.getWidth();  // deprecated
            int height = display.getHeight();  // deprecated

            final BitmapFactory.Options options = new BitmapFactory.Options();
            // Calculate inSampleSize
            options.inSampleSize = 4;

            Bitmap b = BitmapFactory.decodeFile(themebg, options);

            float ratio = ((float)width)/((float)height);
            int bgHeight = b.getHeight();
            int bgWidth = (int)(((float)b.getHeight()) * ratio);

            b = Bitmap.createBitmap(b, 0, 0,Math.min(b.getWidth(),bgWidth),bgHeight);

            mThemeDrawable = new BitmapDrawable(b);
            mThemeDrawable.setAlpha(200);
        }

        view.setBackgroundDrawable(mThemeDrawable);
    }

}
 
Example 6
Source File: ThemeableActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
public static void setBackgroundImage (View view, Activity activity)
{
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
    boolean themeDark = settings.getBoolean("themeDark", false);
    String themebg = settings.getString("pref_background", "");

    if(themeDark)
        view.setBackgroundColor(activity.getResources().getColor(R.color.background_dark));
    else
        view.setBackgroundColor(activity.getResources().getColor(R.color.background_light));

    if (themebg != null && themebg.length() > 0)
    {

        File fileThemeBg = new File(themebg);
        if (!fileThemeBg.exists())
            return;

        if (mThemeBg == null || (!mThemeBg.equals(themebg)))
        {
            mThemeBg = themebg;

            Display display = activity.getWindowManager().getDefaultDisplay();
            int width = display.getWidth();  // deprecated
            int height = display.getHeight();  // deprecated

            final BitmapFactory.Options options = new BitmapFactory.Options();
            // Calculate inSampleSize
            options.inSampleSize = 4;

            Bitmap b = BitmapFactory.decodeFile(themebg, options);

            float ratio = ((float)width)/((float)height);
            int bgHeight = b.getHeight();
            int bgWidth = (int)(((float)b.getHeight()) * ratio);

            b = Bitmap.createBitmap(b, 0, 0,Math.min(b.getWidth(),bgWidth),bgHeight);

            mThemeDrawable = new BitmapDrawable(b);
            mThemeDrawable.setAlpha(200);
        }

        view.setBackgroundDrawable(mThemeDrawable);
    }

}