當前位置: 首頁>>代碼示例>>Java>>正文


Java RippleDrawable類代碼示例

本文整理匯總了Java中android.graphics.drawable.RippleDrawable的典型用法代碼示例。如果您正苦於以下問題:Java RippleDrawable類的具體用法?Java RippleDrawable怎麽用?Java RippleDrawable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RippleDrawable類屬於android.graphics.drawable包,在下文中一共展示了RippleDrawable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateRippleDrawable

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static Drawable generateRippleDrawable(final int color, Rect bounds) {
        ColorStateList list = ColorStateList.valueOf(color);
        Drawable mask = generateCircleDrawable(Color.WHITE);
        RippleDrawable rippleDrawable = new RippleDrawable(list, null, mask);
//        API 21
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
            rippleDrawable.setBounds(bounds);
        }

//        API 22. Technically harmless to leave on for API 21 and 23, but not worth risking for 23+
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) {
            int center = (bounds.left + bounds.right) / 2;
            rippleDrawable.setHotspotBounds(center, bounds.top, center, bounds.bottom);
        }

        return rippleDrawable;
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:DayView.java

示例2: update

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
private void update(@ColorInt int color) {
    innerPaint.setColor(color);
    outerPaint.setColor(shiftColorDown(color));

    Drawable selector = createSelector(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int[][] states = new int[][]{
                new int[]{android.R.attr.state_pressed}
        };
        int[] colors = new int[]{shiftColorUp(color)};
        ColorStateList rippleColors = new ColorStateList(states, colors);
        setForeground(new RippleDrawable(rippleColors, selector, null));
    } else {
        setForeground(selector);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:CircleView.java

示例3: setDiscrete

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
/**
 * Sets a flag indicating whether this seek bar is <b>discrete</b> or not.
 * <p>
 * SeekBarWidget in the discrete mode draws, above the progress track and the thumb, a discrete
 * indicator to show to a user current progress value. Discrete indicator's drawable can be set
 * via {@link #setDiscreteIndicator(android.graphics.drawable.Drawable)}.
 *
 * @param discrete {@code True} to enable discrete mode, {@code false} otherwise.
 * @see R.attr#uiDiscrete ui:uiDiscrete
 * @see #isDiscrete()
 */
public void setDiscrete(boolean discrete) {
	if (discrete && UiConfig.MATERIALIZED) {
		final Drawable background = getBackground();
		if (background instanceof RippleDrawable) {
			// This is a little bit harsh, but the RippleDrawable background is showing a ripple
			// in discrete mode in top left corner of this view's bounds which is kind of weird
			// behaviour.
			this.mRippleBackgroundDrawable = background;
			setBackgroundDrawable(null);
		}
	} else if (!discrete && mRippleBackgroundDrawable != null) {
		setBackgroundDrawable(mRippleBackgroundDrawable);
		this.mRippleBackgroundDrawable = null;
	}
	this.ensureDecorator();
	if (mDecorator.hasPrivateFlag(PFLAG_DISCRETE) != discrete) {
		mDecorator.updatePrivateFlags(PFLAG_DISCRETE, discrete);
		this.updateThumb(mThumb);
		this.updateDiscreteIndicator(mDiscreteIndicator);
		requestLayout();
	}
}
 
開發者ID:universum-studios,項目名稱:android_ui,代碼行數:34,代碼來源:SeekBarWidget.java

示例4: setupForeground

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
private static void setupForeground(View view, Drawable drawable, Integer color, Integer alpha) {
    if (view instanceof IForeground) {
        if (color != null) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                if (drawable instanceof RippleDrawable) {
                    RippleDrawable rippleDrawable = (RippleDrawable) drawable;
                    rippleDrawable.setColor(ColorStateList.valueOf(color));
                    if (alpha != null) {
                        rippleDrawable.setAlpha(alpha);
                    }

                }
            }
        }
        ((IForeground) view).setForeground(drawable);
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:18,代碼來源:ForegroundDelegate.java

示例5: showStopwatchRipple

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
public void showStopwatchRipple()
{
    new Handler(Looper.getMainLooper()).post(new Runnable()
    {
        @Override
        public void run()
        {
            View stopwatchView = findViewById(R.id.stopwatch);
            if(stopwatchView!=null)
            {
                RippleDrawable rd = (RippleDrawable) stopwatchView.getBackground();
                rd.setState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled });
                rd.setState(new int[] {  });
            }
        }
    });
}
 
開發者ID:kingblaubart,項目名稱:quidditchtimekeeper,代碼行數:18,代碼來源:GameActivity.java

示例6: createBackgroundDrawable

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
private Drawable createBackgroundDrawable(int width, int height) {
    if (isCircular && height > width) {
        width = height;
    } else if (isCircular && width > height) {
        height = width;
    }

    Drawable content = createContentDrawable(width, height);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Log.d(TAG, "RIPPLE APPLIED, with color: " + mRippleColor);
        Drawable mask = createMaskDrawable(width, height);
        ColorStateList stateList = ColorStateList.valueOf(mRippleColor);
        return new RippleDrawable(stateList, content, mask);
    } else {
        return content;
    }
}
 
開發者ID:bartbergmans,項目名稱:GradientButton,代碼行數:19,代碼來源:GradientButton.java

示例7: createFillDrawable

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
    drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
    drawable.addState(new int[]{}, createCircleDrawable(mColorNormal));

    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
                new int[]{mColorRipple}), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }

    mBackgroundDrawable = drawable;
    return drawable;
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:25,代碼來源:FloatingActionButton.java

示例8: createFillDrawable

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
    drawable.addState(new int[]{}, createRectDrawable(mColorNormal));

    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
                new int[]{mColorRipple}), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }

    mBackgroundDrawable = drawable;
    return drawable;
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:24,代碼來源:Label.java

示例9: onActionDown

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }

    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_pressed});
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
    setPressed(true);
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:18,代碼來源:Label.java

示例10: onActionUp

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }

    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{});
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{});
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
    setPressed(false);
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:18,代碼來源:Label.java

示例11: onActionDown

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionDown() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{android.R.attr.state_pressed});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(true);
    }
 
開發者ID:Blankeer,項目名稱:MDWechat,代碼行數:18,代碼來源:Label.java

示例12: onActionUp

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionUp() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(false);
    }
 
開發者ID:Blankeer,項目名稱:MDWechat,代碼行數:18,代碼來源:Label.java

示例13: createRippleDrawable

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
/**
 * Creates a new {@link RippleDrawable} introduced in Lollipop.
 *
 * @param normalColor  Color for the idle/normal state
 * @param rippleColor  Color for the ripple effect
 * @param bounds       Clipping bounds for the ripple state. Set to {@code null} to get a borderless ripple
 * @param cornerRadius Set to round the corners on rectangular drawables, 0 to disable
 * @return A fully colored RippleDrawable, new instance each time
 */
@NonNull
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static RippleDrawable createRippleDrawable(@ColorInt final int normalColor, @ColorInt final int rippleColor, @Nullable final Rect bounds,
                                                  @IntRange(from = 0) final int cornerRadius) {
    Drawable maskDrawable = null;
    if (bounds != null) {
        // clip color is white
        maskDrawable = createColoredDrawable(Color.WHITE, bounds);
        if (maskDrawable instanceof GradientDrawable) {
            ((GradientDrawable) maskDrawable).setCornerRadius(cornerRadius);
        }
        maskDrawable.setBounds(bounds);
    }

    Drawable normalStateDrawable = null;
    // transparent has no idle state
    if (normalColor != Color.TRANSPARENT) {
        normalStateDrawable = createColoredDrawable(normalColor, bounds);
        if (normalStateDrawable instanceof GradientDrawable) {
            ((GradientDrawable) normalStateDrawable).setCornerRadius(cornerRadius);
        }
    }

    return new RippleDrawable(ColorStateList.valueOf(rippleColor), normalStateDrawable, maskDrawable);
}
 
開發者ID:milosmns,項目名稱:silly-android,代碼行數:35,代碼來源:Coloring.java

示例14: onActionUp

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
開發者ID:HueToYou,項目名稱:ChatExchange-old,代碼行數:13,代碼來源:FloatingActionButton.java

示例15: createBtnAndSetFunc

import android.graphics.drawable.RippleDrawable; //導入依賴的package包/類
/**
 * 創建按鈕並且設置對應功能
 *
 * @param line
 * @param sc
 */
public void createBtnAndSetFunc(LinearLayout line, ShortCut sc) {
    int iconScale = DataHook.iconScale;
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    p.weight = 1;
    p.gravity = Gravity.CENTER;

    Context context = line.getContext();
    ImageView btn = new ImageView(context);

    String iconPath = sc.getIconPath();
    Bitmap iconBitmap = null;
    if (iconPath != null) {
        iconBitmap = ImageUtil.zoomBitmap(iconPath, iconScale);
    }
    if (iconBitmap == null) {
        iconBitmap = ImageUtil.byte2Bitmap(mMapImgRes.get(sc.getCode()));
        iconBitmap = ImageUtil.zommBitmap(iconBitmap, iconScale);
    }
    btn.setImageBitmap(iconBitmap);

    ColorStateList colorStateList = createColorStateList(0xffffffff, 0xffffff00, 0xff0000ff, 0xffff0000);
    RippleDrawable ripple = new RippleDrawable(colorStateList, null, null);
    btn.setBackground(ripple);
    btn.setScaleType(ImageView.ScaleType.CENTER);
    btn.setOnClickListener(getBtnFuncOfName(sc));
    btn.setOnLongClickListener(getBtnLongFuncOfName(sc.getCode()));

    line.addView(btn, p);
}
 
開發者ID:EggUncle,項目名稱:XposedNavigationBar,代碼行數:37,代碼來源:BtnFuncFactory.java


注:本文中的android.graphics.drawable.RippleDrawable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。