setAlpha()源码实例Demo

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

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

/**
 * Set the drawable to use for the content scrim from resources. Providing null will disable
 * the scrim functionality.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#FlexibleToolbarLayout_contentScrimColor
 * @see #getContentScrim()
 */
public void setContentScrim(@Nullable Drawable drawable) {
    if (mContentScrim != drawable) {
        if (mContentScrim != null) {
            mContentScrim.setCallback(null);
        }
        if (drawable != null) {
            mContentScrim = drawable.mutate();
            drawable.setBounds(0, 0, getWidth(), getHeight());
            drawable.setCallback(this);
            drawable.setAlpha(mScrimAlpha);
        } else {
            mContentScrim = null;
        }
        ViewCompat.postInvalidateOnAnimation(this);
    }
}
 
源代码2 项目: OneDrawable   文件: OneDrawable.java
private static Drawable getPressedStateDrawable(Context context, @PressedMode.Mode int mode, @FloatRange(from = 0.0f, to = 1.0f) float alpha, @NonNull Drawable pressed) {
    //ColorDrawable is not supported on 4.4 because the size of the ColorDrawable can not be determined unless the View size is passed in
    if (isKitkat() && !(pressed instanceof ColorDrawable)) {
        return kitkatDrawable(context, pressed, mode, alpha);
    }
    switch (mode) {
        case PressedMode.ALPHA:
            pressed.setAlpha(convertAlphaToInt(alpha));
            break;
        case PressedMode.DARK:
            pressed.setColorFilter(alphaColor(Color.BLACK, convertAlphaToInt(alpha)), PorterDuff.Mode.SRC_ATOP);
            break;
        default:
            pressed.setAlpha(convertAlphaToInt(alpha));
    }
    return pressed;
}
 
源代码3 项目: linphone-android   文件: AboutActivity.java
private void displayUploadLogsInProgress() {
    if (mUploadInProgress) {
        return;
    }
    mUploadInProgress = true;

    mProgress = ProgressDialog.show(this, null, null);
    Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.light_grey_color));
    d.setAlpha(200);
    mProgress
            .getWindow()
            .setLayout(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
    mProgress.getWindow().setBackgroundDrawable(d);
    mProgress.setContentView(R.layout.wait_layout);
    mProgress.show();
}
 
源代码4 项目: intra42   文件: CoalitionsActivity.java
@Override
protected void setViewContent() {
    if (blocs == null) {
        setViewState(StatusCode.EMPTY);
        return;
    }
    List<Coalitions> coalitions = blocs.coalitions;
    Collections.sort(coalitions, (o1, o2) -> {
        if (o1.score == o2.score)
            return 0;
        return o1.score < o2.score ? 1 : -1;
    });

    RecyclerAdapterCoalitionsBlocs adapter = new RecyclerAdapterCoalitionsBlocs(this, coalitions);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setNestedScrollingEnabled(false);
    DividerItemDecoration decoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
    Drawable decoDrawable = decoration.getDrawable();
    decoDrawable.setAlpha(1);
    decoration.setDrawable(decoDrawable);
    recyclerView.addItemDecoration(decoration);
}
 
@Override
protected final void onDraw(final float interpolatedTime, @NonNull final Canvas canvas) {
    int currentAlpha = Math.round(255 * interpolatedTime);
    Drawable first = getDrawable(0);

    if (useCrossFade) {
        first.setAlpha(255 - currentAlpha);
    }

    first.draw(canvas);
    Drawable second = getDrawable(1);
    second.setAlpha(currentAlpha);
    second.draw(canvas);
}
 
源代码6 项目: cathode   文件: RemoteImageView.java
protected void drawPlaceholder(Canvas canvas, Drawable placeholder, int alpha) {
  final int width = getWidth();
  final int height = getHeight();
  placeHolder.setBounds(getPaddingStart(), getPaddingTop(), width - getPaddingEnd(),
      height - getPaddingBottom());
  placeholder.setAlpha(alpha);
  placeholder.setAlpha(alpha);
  placeholder.draw(canvas);
}
 
源代码7 项目: PhoneProfilesPlus   文件: GuiInfoPopupWindow.java
static void applyDim(@NonNull ViewGroup parent){
    Drawable dim = new ColorDrawable(Color.BLACK);
    dim.setBounds(0, 0, parent.getWidth(), parent.getHeight());
    dim.setAlpha((int) (255 * 0.5));

    ViewGroupOverlay overlay = parent.getOverlay();
    overlay.add(dim);
}
 
源代码8 项目: Telegram   文件: RadialProgressView.java
@Keep
@Override
public void setAlpha(float alpha) {
    super.setAlpha(alpha);
    if (useSelfAlpha) {
        Drawable background = getBackground();
        int a = (int) (alpha * 255);
        if (background != null) {
            background.setAlpha(a);
        }
        progressPaint.setAlpha(a);
    }
}
 
源代码9 项目: android-file-chooser   文件: WrappedDrawable.java
@Override
public void setAlpha(int alpha) {
    Drawable drawable = getDrawable();
    if (drawable != null) {
        drawable.setAlpha(alpha);
    }
}
 
源代码10 项目: Passbook   文件: EditFragment.java
@Override
public void onScroll(int l, int t, int oldl, int oldt) {
    int height = mHeader.getMeasuredHeight() - mToolbar.getMeasuredHeight();
    Drawable drawable = mToolbarContainer.getBackground();
    int alpha = 255 *  (Math.min(Math.max(t, 0), height))/ height;
    drawable.setAlpha(alpha);
    if(alpha >= 255) {
        ViewCompat.setElevation(mToolbarContainer, mElevation);
        ViewCompat.setElevation(mHeader, 0);
    }
    else {
        ViewCompat.setElevation(mToolbarContainer, 0);
        ViewCompat.setElevation(mHeader, mElevation);
    }
}
 
源代码11 项目: GetApk   文件: DrawableHelper.java
public static Drawable tintDrawable(@NonNull Context context, @NonNull Drawable drawable, int colorAttr, int alpha, PorterDuff.Mode tintMode) {
    if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
        drawable = drawable.mutate();
    }
    final int color = getThemeAttrColor(context, colorAttr);
    drawable.setColorFilter(AppCompatDrawableManager.getPorterDuffColorFilter(color, tintMode));

    if (alpha != -1) {
        drawable.setAlpha(alpha);
    }

    return drawable;
}
 
源代码12 项目: TelePlus-Android   文件: RadialProgressView.java
@Keep
@Override
public void setAlpha(float alpha) {
    super.setAlpha(alpha);
    if (useSelfAlpha) {
        Drawable background = getBackground();
        int a = (int) (alpha * 255);
        if (background != null) {
            background.setAlpha(a);
        }
        progressPaint.setAlpha(a);
    }
}
 
源代码13 项目: Carbon   文件: LayerDrawable.java
@Override
public void setAlpha(int alpha) {
    final ChildDrawable[] array = mLayerState.mChildren;
    final int N = mLayerState.mNum;
    for (int i = 0; i < N; i++) {
        final Drawable dr = array[i].mDrawable;
        if (dr != null) {
            dr.setAlpha(alpha);
        }
    }
}
 
源代码14 项目: school_shop   文件: FloatingActionButton.java
private void updateBackground(Drawable background) {
    if (background instanceof LayerDrawable) {
        LayerDrawable layers = (LayerDrawable) background;
        if (layers.getNumberOfLayers() == 2) {
            Drawable shadow = layers.getDrawable(0);
            Drawable circle = layers.getDrawable(1);

            if (shadow instanceof GradientDrawable) {
                if (mShadow) {
                    ((GradientDrawable) shadow.mutate()).setGradientRadius(getShadowRadius(shadow, circle));
                } else {
                    shadow.setAlpha(0);
                }
            }

            if (circle instanceof GradientDrawable) {
                initCircleDrawable(circle);
            }
        }
    } else if (background instanceof GradientDrawable) {
        initCircleDrawable(background);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mImplicitElevation) {
            setElevation(mShadow ? getResources().getDimension(R.dimen.floating_action_button_elevation) : 0f);
        }
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        //noinspection deprecation
        setBackgroundDrawable(background);
    } else {
        setBackground(background);
    }
}
 
源代码15 项目: OneDrawable   文件: OneDrawable.java
private static Drawable kitkatDrawable(Context context, @NonNull Drawable pressed, @PressedMode.Mode int mode, @FloatRange(from = 0.0f, to = 1.0f) float alpha) {
    Bitmap bitmap = Bitmap.createBitmap(pressed.getIntrinsicWidth(), pressed.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas myCanvas = new Canvas(bitmap);
    switch (mode) {
        case PressedMode.ALPHA:
            pressed.setAlpha(convertAlphaToInt(alpha));
            break;
        case PressedMode.DARK:
            pressed.setColorFilter(alphaColor(Color.BLACK, convertAlphaToInt(alpha)), PorterDuff.Mode.SRC_ATOP);
            break;
    }
    pressed.setBounds(0, 0, pressed.getIntrinsicWidth(), pressed.getIntrinsicHeight());
    pressed.draw(myCanvas);
    return new BitmapDrawable(context.getResources(), bitmap);
}
 
源代码16 项目: WheelView   文件: FadingSelectionTransformer.java
@Override
public void transform(Drawable drawable, WheelView.ItemState itemState) {
    float relativePosition = Math.abs(itemState.getRelativePosition());
    int alpha = (int) ((1f - Math.pow(relativePosition, 2.5f)) * 255f);

    //clamp to between 0 and 255
    if (alpha > 255) alpha = 255;
    else if (alpha < 0) alpha = 0;

    drawable.setAlpha(alpha);
}
 
static boolean tintDrawableUsingColorFilter(@NonNull Context context,
                                            @DrawableRes final int resId, @NonNull Drawable drawable) {
    PorterDuff.Mode tintMode = DEFAULT_MODE;
    boolean colorAttrSet = false;
    int colorAttr = 0;
    int alpha = -1;

    if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) {
        colorAttr = R.attr.colorControlNormal;
        colorAttrSet = true;
    } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) {
        colorAttr = R.attr.colorControlActivated;
        colorAttrSet = true;
    } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) {
        colorAttr = android.R.attr.colorBackground;
        colorAttrSet = true;
        tintMode = PorterDuff.Mode.MULTIPLY;
    } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) {
        colorAttr = android.R.attr.colorForeground;
        colorAttrSet = true;
        alpha = Math.round(0.16f * 255);
    } else if (resId == R.drawable.abc_dialog_material_background) {
        colorAttr = android.R.attr.colorBackground;
        colorAttrSet = true;
    }

    if (colorAttrSet) {
        if (SkinCompatDrawableUtils.canSafelyMutateDrawable(drawable)) {
            drawable = drawable.mutate();
        }

        final int color = getThemeAttrColor(context, colorAttr);
        drawable.setColorFilter(getPorterDuffColorFilter(color, tintMode));

        if (alpha != -1) {
            drawable.setAlpha(alpha);
        }

        if (DEBUG) {
            Log.d(TAG, "[tintDrawableUsingColorFilter] Tinted "
                    + context.getResources().getResourceName(resId) +
                    " with color: #" + Integer.toHexString(color));
        }
        return true;
    }
    return false;
}
 
源代码18 项目: 365browser   文件: AnimatorProperties.java
@Override
public void set(Drawable d, Integer alpha) {
    d.setAlpha(alpha);
}
 
源代码19 项目: NCalendar   文件: InnerPainter.java
private void drawCheckedBackground(Canvas canvas, Drawable drawable, RectF rectF, int alphaColor) {
    Rect drawableBounds = DrawableUtil.getDrawableBounds((int) rectF.centerX(), (int) rectF.centerY(), drawable);
    drawable.setBounds(drawableBounds);
    drawable.setAlpha(alphaColor);
    drawable.draw(canvas);
}
 
源代码20 项目: 365browser   文件: ToolbarPhone.java
/**
 * When entering and exiting the TabSwitcher mode, we fade out or fade in the browsing
 * mode of the toolbar on top of the TabSwitcher mode version of it.  We do this by
 * drawing all of the browsing mode views on top of the android view.
 */
protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animationProgress) {
    if (!isNativeLibraryReady()) return;

    float floatAlpha = 1 - animationProgress;
    int rgbAlpha = (int) (255 * floatAlpha);
    canvas.save();
    canvas.translate(0, -animationProgress * mBackgroundOverlayBounds.height());
    canvas.clipRect(mBackgroundOverlayBounds);

    float previousAlpha = 0.f;
    if (mHomeButton.getVisibility() != View.GONE) {
        // Draw the New Tab button used in the URL view.
        previousAlpha = mHomeButton.getAlpha();
        mHomeButton.setAlpha(previousAlpha * floatAlpha);
        drawChild(canvas, mHomeButton, SystemClock.uptimeMillis());
        mHomeButton.setAlpha(previousAlpha);
    }

    // Draw the location/URL bar.
    previousAlpha = mLocationBar.getAlpha();
    mLocationBar.setAlpha(previousAlpha * floatAlpha);
    // If the location bar is now fully transparent, do not bother drawing it.
    if (mLocationBar.getAlpha() != 0) {
        drawChild(canvas, mLocationBar, SystemClock.uptimeMillis());
    }
    mLocationBar.setAlpha(previousAlpha);

    // Draw the tab stack button and associated text.
    translateCanvasToView(this, mToolbarButtonsContainer, canvas);

    if (mTabSwitcherAnimationTabStackDrawable != null && mToggleTabStackButton != null
            && mUrlExpansionPercent != 1f) {
        // Draw the tab stack button image.
        canvas.save();
        translateCanvasToView(mToolbarButtonsContainer, mToggleTabStackButton, canvas);

        int backgroundWidth = mToggleTabStackButton.getDrawable().getIntrinsicWidth();
        int backgroundHeight = mToggleTabStackButton.getDrawable().getIntrinsicHeight();
        int backgroundLeft = (mToggleTabStackButton.getWidth()
                - mToggleTabStackButton.getPaddingLeft()
                - mToggleTabStackButton.getPaddingRight() - backgroundWidth) / 2;
        backgroundLeft += mToggleTabStackButton.getPaddingLeft();
        int backgroundTop = (mToggleTabStackButton.getHeight()
                - mToggleTabStackButton.getPaddingTop()
                - mToggleTabStackButton.getPaddingBottom() - backgroundHeight) / 2;
        backgroundTop += mToggleTabStackButton.getPaddingTop();
        canvas.translate(backgroundLeft, backgroundTop);

        mTabSwitcherAnimationTabStackDrawable.setAlpha(rgbAlpha);
        mTabSwitcherAnimationTabStackDrawable.draw(canvas);
        canvas.restore();
    }

    // Draw the menu button if necessary.
    if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null
            && mUrlExpansionPercent != 1f) {
        mTabSwitcherAnimationMenuDrawable.setBounds(
                mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(),
                mMenuButton.getWidth() - mMenuButton.getPaddingRight(),
                mMenuButton.getHeight() - mMenuButton.getPaddingBottom());
        translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas);
        mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha);
        int color = mUseLightDrawablesForTextureCapture
                ? mLightModeDefaultColor
                : mDarkModeDefaultColor;
        mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        mTabSwitcherAnimationMenuDrawable.draw(canvas);
    }

    // Draw the menu badge if necessary.
    Drawable badgeDrawable = mUseLightDrawablesForTextureCapture
            ? mTabSwitcherAnimationMenuBadgeLightDrawable
                    : mTabSwitcherAnimationMenuBadgeDarkDrawable;
    if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) {
        badgeDrawable.setBounds(
                mMenuBadge.getPaddingLeft(), mMenuBadge.getPaddingTop(),
                mMenuBadge.getWidth() - mMenuBadge.getPaddingRight(),
                mMenuBadge.getHeight() - mMenuBadge.getPaddingBottom());
        translateCanvasToView(mToolbarButtonsContainer, mMenuBadge, canvas);
        badgeDrawable.setAlpha(rgbAlpha);
        badgeDrawable.draw(canvas);
    }

    mLightDrawablesUsedForLastTextureCapture = mUseLightDrawablesForTextureCapture;

    canvas.restore();
}