paint.setAntiAlias(true);

canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2,

getHeight() / 2, getHeight() / 3, paint);

}

invalidate();

}

@Override

public boolean onTouchEvent(MotionEvent event) {

isLastTouch = true;

if (isEnabled()) {

if (event.getAction() == MotionEvent.ACTION_DOWN

|| event.getAction() == MotionEvent.ACTION_MOVE) {

if (numberIndicator != null

&& numberIndicator.isShowing() == false)

numberIndicator.show();

if ((event.getX() <= getWidth() && event.getX() >= 0)) {

press = true;

// calculate value

int newValue = 0;

float division = (ball.xFin - ball.xIni) / (max - min);

if (event.getX() > ball.xFin) {

newValue = max;

} else if (event.getX() < ball.xIni) {

newValue = min;

} else {

newValue = min

  • (int) ((event.getX() - ball.xIni) / division);

}

if (value != newValue) {

value = newValue;

if (onValueChangedListener != null)

onValueChangedListener.onValueChanged(newValue);

}

// move ball indicator

float x = event.getX();

x = (x < ball.xIni) ? ball.xIni : x;

x = (x > ball.xFin) ? ball.xFin : x;

ViewHelper.setX(ball, x);

ball.changeBackground();

// If slider has number indicator

if (numberIndicator != null) {

// move number indicator

numberIndicator.indicator.x = x;

numberIndicator.indicator.finalY = Utils

.getRelativeTop(this) - getHeight() / 2;

numberIndicator.indicator.finalSize = getHeight() / 2;

numberIndicator.numberIndicator.setText(“”);

}

} else {

press = false;

isLastTouch = false;

if (numberIndicator != null)

numberIndicator.dismiss();

}

} else if (event.getAction() == MotionEvent.ACTION_UP

|| event.getAction() == MotionEvent.ACTION_CANCEL) {

if (numberIndicator != null)

numberIndicator.dismiss();

isLastTouch = false;

press = false;

}

}

return true;

}

/**

  • Make a dark color to press effect

  • @return

*/

protected int makePressColor() {

int r = (this.backgroundColor >> 16) & 0xFF;

int g = (this.backgroundColor >> 8) & 0xFF;

int b = (this.backgroundColor >> 0) & 0xFF;

r = (r - 30 < 0) ? 0 : r - 30;

g = (g - 30 < 0) ? 0 : g - 30;

b = (b - 30 < 0) ? 0 : b - 30;

return Color.argb(70, r, g, b);

}

private void placeBall() {

ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2);

ball.xIni = ViewHelper.getX(ball);

ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2;

ball.xCen = getWidth() / 2 - ball.getWidth() / 2;

placedBall = true;

}

// GETERS & SETTERS

public OnValueChangedListener getOnValueChangedListener() {

return onValueChangedListener;

}

public void setOnValueChangedListener(

OnValueChangedListener onValueChangedListener) {

this.onValueChangedListener = onValueChangedListener;

}

public int getValue() {

return value;

}

public void setValue(final int value) {

if (placedBall == false)

post(new Runnable() {

@Override

public void run() {

setValue(value);

}

});

else {

this.value = value;

float division = (ball.xFin - ball.xIni) / max;

ViewHelper.setX(ball,

value * division + getHeight() / 2 - ball.getWidth() / 2);

ball.changeBackground();

}

}

public int getMax() {

return max;

}

public void setMax(int max) {

this.max = max;

}

public int getMin() {

return min;

}

public void setMin(int min) {

this.min = min;

}

public boolean isShowNumberIndicator() {

return showNumberIndicator;

}

public void setShowNumberIndicator(boolean showNumberIndicator) {

this.showNumberIndicator = showNumberIndicator;

numberIndicator = (showNumberIndicator) ? new NumberIndicator(

getContext()) : null;

}

@Override

public void setBackgroundColor(int color) {

backgroundColor = color;

if (isEnabled())

beforeBackground = backgroundColor;

}

boolean placedBall = false;

class Ball extends View {

float xIni, xFin, xCen;

public Ball(Context context) {

super(context);

setBackgroundResource(R.drawable.background_switch_ball_uncheck);

}

public void changeBackground() {

if (value != min) {

setBackgroundResource(R.drawable.background_checkbox);

LayerDrawable layer = (LayerDrawable) getBackground();

GradientDrawable shape = (GradientDrawable) layer

.findDrawableByLayerId(R.id.shape_bacground);

shape.setColor(backgroundColor);

} else {

setBackgroundResource(R.drawable.background_switch_ball_uncheck);

}

}

}

// Slider Number Indicator

class NumberIndicator extends Dialog {

Indicator indicator;

TextView numberIndicator;

public NumberIndicator(Context context) {

super(context, android.R.style.Theme_Translucent);

}

@Override

protected void onCreate(Bundle savedInstanceState) {

requestWindowFeature(Window.FEATURE_NO_TITLE);

super.onCreate(savedInstanceState);

setContentView(R.layout.number_indicator_spinner);

setCanceledOnTouchOutside(false);

RelativeLayout content = (RelativeLayout) this

.findViewById(R.id.number_indicator_spinner_content);

indicator = new Indicator(this.getContext());

content.addView(indicator);

numberIndicator = new TextView(getContext());

numberIndicator.setTextColor(Color.WHITE);

numberIndicator.setGravity(Gravity.CENTER);

content.addView(numberIndicator);

indicator.setLayoutParams(new RelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.FILL_PARENT,

RelativeLayout.LayoutParams.FILL_PARENT));

}

@Override

public void dismiss() {

super.dismiss();

indicator.y = 0;

indicator.size = 0;

indicator.animate = true;

}

@Override

public void onBackPressed() {

}

}

class Indicator extends RelativeLayout {

// Position of number indicator

float x = 0;

float y = 0;

// Size of number indicator

float size = 0;

// Final y position after animation

float finalY = 0;

// Final size after animation

float finalSize = 0;

boolean animate = true;

boolean numberIndicatorResize = false;

public Indicator(Context context) {

super(context);

setBackgroundColor(getResources().getColor(

android.R.color.transparent));

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

if (numberIndicatorResize == false) {

LayoutParams params = (LayoutParams) numberIndicator.numberIndicator

.getLayoutParams();

params.height = (int) finalSize * 2;

params.width = (int) finalSize * 2;

numberIndicator.numberIndicator.setLayoutParams(params);

}

Paint paint = new Paint();

最后笔者收集整理了一份Flutter高级入门进阶资料PDF

以下是资料目录和内容部分截图



里面包括详细的知识点讲解分析,带你一个星期入门Flutter。还有130个进阶学习项目实战视频教程,让你秒变大前端。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

arams(params);

}

Paint paint = new Paint();

最后笔者收集整理了一份Flutter高级入门进阶资料PDF

以下是资料目录和内容部分截图

[外链图片转存中…(img-j13oh6YU-1714328889568)]
[外链图片转存中…(img-rKvTBgEn-1714328889569)]
里面包括详细的知识点讲解分析,带你一个星期入门Flutter。还有130个进阶学习项目实战视频教程,让你秒变大前端。

[外链图片转存中…(img-eXpNgX28-1714328889569)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐