If you think the Android project nxt-remote-controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.gc.materialdesign.views;
/*fromwww.java2s.com*/import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
publicabstractclass RippleView extends CustomView{
protectedboolean settedRippleColor = false;
protectedint rippleSize = 3;//???????????????????
protectedInteger rippleColor = null;//the color of ripple
protectedfloat rippleSpeed;//the speed of ripple translate
protected OnClickListener onClickListener;
protectedboolean clickAfterRipple = true;//view is click until the ripple is end
public RippleView(Context context, AttributeSet attrs) {
super(context, attrs);
setAttributes(attrs);
}
// Set atributtes of XML to View
@Override
protectedvoid setAttributes(AttributeSet attrs) {
super.setAttributes(attrs);
setRippleAttributes(attrs);
}
protectedvoid setRippleAttributes(AttributeSet attrs) {
/**
* ????????????
* Set Ripple Color
* Color by resource
*/int color = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"rippleColor",-1);
if(color != -1){
rippleColor = getResources().getColor(color);
settedRippleColor = true;
}else{
// Color by hexadecimal
int rColor = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);// 16?????
if(rColor != -1 && !isInEditMode()) {
rippleColor = rColor;
settedRippleColor = true;
}
}
/**
* ???????????
* init Ripple speed
*/
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed);
/**
* ?????????
*/
clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple);
}
@Override
publicboolean onInterceptTouchEvent(MotionEvent ev) {
// super.onInterceptTouchEvent(ev);
return true;
}
// ripple position
protectedfloat x = -1;
protectedfloat y = -1;
protectedfloat radius = -1;
@Override
publicboolean onTouchEvent(MotionEvent event) {
if (isEnabled()) {
isLastTouch = true;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
radius = getHeight() / rippleSize;
x = event.getX();
y = event.getY();
} elseif (event.getAction() == MotionEvent.ACTION_MOVE) {
radius = getHeight() / rippleSize;
x = event.getX();
y = event.getY();
if (!((event.getX() <= getWidth() && event.getX() >= 0) &&
(event.getY() <= getHeight() && event.getY() >= 0))) {
isLastTouch = false;
x = -1;
y = -1;
}
} elseif (event.getAction() == MotionEvent.ACTION_UP) {
if ((event.getX() <= getWidth() && event.getX() >= 0)
&& (event.getY() <= getHeight() && event.getY() >= 0)) {
radius++;
} else {
isLastTouch = false;
x = -1;
y = -1;
}
if (clickAfterRipple == false && onClickListener != null) {
onClickListener.onClick(this);
}
}
}
return true;
}
public Bitmap makeCircleFromBitmap(Bitmap output) {
Canvas canvas = new Canvas(output);
canvas.drawARGB(0, 0, 0, 0);
Paint paint = new Paint();
paint.setAntiAlias(true);
if (rippleColor == null) {
paint.setColor(makePressColor(255));
}else {
paint.setColor(rippleColor);
}
canvas.drawCircle(x, y, radius, paint);
if (radius > getHeight() / rippleSize)
radius += rippleSpeed;
if (radius >= getWidth()) {
x = -1;
y = -1;
radius = getHeight() / rippleSize;
if(clickAfterRipple == true && onClickListener != null)
onClickListener.onClick(this);
}
return output;
}
@Override
protectedvoid onFocusChanged(boolean gainFocus, int direction,
Rect previouslyFocusedRect) {
if (!gainFocus) {
x = -1;
y = -1;
}
}
@Override
publicvoid setOnClickListener(OnClickListener l) {
onClickListener = l;
}
/**
* set and get ripple color
* @param color
*/publicvoid setRippleColor(int color) {
rippleColor = color;
settedRippleColor = true;
}
publicint getRippleColor() {
if (rippleColor != null) {
return rippleColor;
}else {
return makePressColor(255);
}
}
/**
* set and get ripple speed
* @param speed
*/publicvoid setRippleSpeed(float speed) {
rippleSpeed = speed;
}
publicfloat getRippleSpeed() {
return rippleSpeed;
}
/**
* ?????????????????????????????????????
* @param clickAfterRipple
*/publicvoid setClickAfterRipple(boolean clickAfterRipple) {
this.clickAfterRipple = clickAfterRipple;
}
publicboolean getClickAfterRipple() {
return clickAfterRipple;
}
}