android.graphics.drawable.BitmapDrawable#setAlpha()源码实例Demo

下面列出了android.graphics.drawable.BitmapDrawable#setAlpha() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 2048   文件: MainView.java
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);
    }
}
 
/**
 * 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();
}
 
源代码3 项目: RhymeMusic   文件: BlurBehind.java
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;
    }
}
 
源代码4 项目: PickerUI   文件: PickerUIBlurHelper.java
/**
 * 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);
    }
}
 
源代码5 项目: zom-android-matrix   文件: ThemeableActivity.java
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);
    }

}
 
源代码6 项目: Zom-Android-XMPP   文件: ThemeableActivity.java
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);
    }

}