欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android九宮格鎖屏控件使用詳解

 更新時(shí)間:2022年06月28日 08:51:27   作者:poorSir  
這篇文章主要為大家詳細(xì)介紹了android九宮格鎖屏控件使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android九宮格鎖屏控件的具體代碼,供大家參考,具體內(nèi)容如下

代碼:

public class LockView extends View {
? ? //半徑
? ? private int radius;
? ? //中心小圓半徑
? ? private int smallRadius;
? ? //一行個(gè)數(shù)
? ? private int column;
? ? //選中顏色
? ? private int selectColor;
? ? //未選中顏色
? ? private int normalColor;
? ? //陰影顏色
? ? private int shaderColor;
? ? //連線的顏色
? ? private int lineColor;
? ? //圓線寬
? ? private int circleStrokeWidth;
? ? //連線的線寬
? ? private int lineStrokeWidth;

? ? private Paint normalPaint;
? ? private Paint selectPaint;
? ? private Paint linePaint;
? ? private Paint centerPaint;
? ? private int width;
? ? //每個(gè)圓寬度
? ? private int everyWidth;
? ? //是否是選中繪制
? ? private boolean isSelect;
? ? //所有圓信息
? ? private List<Point> allCircleList = new ArrayList<>();
? ? //選中圓的標(biāo)志
? ? private List<Integer> selectList = new ArrayList<>();
? ? //是否是重置
? ? private boolean isReSet;
? ? private LockViewFinishListener lockViewFinishListener;

? ? public LockView(Context context, @Nullable AttributeSet attrs) {
? ? ? ? super(context, attrs);
? ? ? ? init(context, attrs);
? ? }

? ? public LockViewFinishListener getLockViewFinishListener() {
? ? ? ? return lockViewFinishListener;
? ? }

? ? public void setLockViewFinishListener(LockViewFinishListener lockViewFinishListener) {
? ? ? ? this.lockViewFinishListener = lockViewFinishListener;
? ? }

? ? private void init(Context context, AttributeSet attrs) {
? ? ? ? TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.LockView);
? ? ? ? radius = typedArray.getInteger(R.styleable.LockView_lock_radius,100);
? ? ? ? smallRadius = typedArray.getInteger(R.styleable.LockView_smallRadius,30);
? ? ? ? column = typedArray.getInteger(R.styleable.LockView_column,3);
? ? ? ? selectColor =typedArray.getColor(R.styleable.LockView_selectColor,Color.RED);
? ? ? ? normalColor = typedArray.getColor(R.styleable.LockView_lock_normalColor,Color.GRAY);
? ? ? ? shaderColor = typedArray.getColor(R.styleable.LockView_shaderColor,Color.argb(80, 0xff, 0x00, 0x00));
? ? ? ? lineColor = typedArray.getColor(R.styleable.LockView_lineColor,Color.RED);
? ? ? ? circleStrokeWidth = typedArray.getInteger(R.styleable.LockView_circleStrokeWidth,5);
? ? ? ? lineStrokeWidth = typedArray.getInteger(R.styleable.LockView_lineStrokeWidth,15);

? ? ? ? normalPaint = new Paint();
? ? ? ? normalPaint.setColor(normalColor);
? ? ? ? normalPaint.setAntiAlias(false);//設(shè)置為無(wú)鋸齒
? ? ? ? normalPaint.setStrokeWidth(circleStrokeWidth);//線寬
? ? ? ? normalPaint.setStyle(Paint.Style.STROKE);

? ? ? ? selectPaint = new Paint();
? ? ? ? selectPaint.setColor(selectColor);
? ? ? ? selectPaint.setAntiAlias(false);
? ? ? ? selectPaint.setStrokeWidth(circleStrokeWidth);
? ? ? ? selectPaint.setStyle(Paint.Style.STROKE);

? ? ? ? centerPaint = new Paint();
? ? ? ? centerPaint.setColor(selectColor);
? ? ? ? centerPaint.setAntiAlias(false);
? ? ? ? centerPaint.setStrokeWidth(radius - smallRadius);
? ? ? ? centerPaint.setStyle(Paint.Style.FILL_AND_STROKE);

? ? ? ? linePaint = new Paint();
? ? ? ? linePaint.setColor(lineColor);
? ? ? ? linePaint.setAntiAlias(false);//設(shè)置為無(wú)鋸齒
? ? ? ? linePaint.setStrokeWidth(lineStrokeWidth);//線寬
? ? ? ? linePaint.setAlpha(150);
? ? ? ? linePaint.setStyle(Paint.Style.STROKE);
? ? }

? ? @Override
? ? protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
? ? ? ? width = measureWidth(widthMeasureSpec);
? ? ? ? setMeasuredDimension(width, width);
? ? ? ? everyWidth = (width - getPaddingLeft() - getPaddingRight()) / column;
? ? ? ? allCircleList.clear();
? ? ? ? for (int i = 0; i < column; i++) {
? ? ? ? ? ? for (int j = 0; j < column; j++) {
? ? ? ? ? ? ? ? float cx = getPaddingLeft() + everyWidth / 2 * (2 * j + 1);
? ? ? ? ? ? ? ? float cy = getPaddingTop() + everyWidth / 2 * (2 * i + 1);
? ? ? ? ? ? ? ? Point point = new Point();
? ? ? ? ? ? ? ? point.cx = cx;
? ? ? ? ? ? ? ? point.cy = cy;
? ? ? ? ? ? ? ? allCircleList.add(point);
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? @Override
? ? protected void onDraw(Canvas canvas) {
? ? ? ? super.onDraw(canvas);
? ? ? ? for (int i = 0; i < allCircleList.size(); i++) {
? ? ? ? ? ? Point point = allCircleList.get(i);
? ? ? ? ? ? canvas.drawCircle(point.cx, point.cy, radius, normalPaint);
? ? ? ? }
? ? ? ? if (isReSet) {//重置
? ? ? ? ? ? isReSet = false;
? ? ? ? ? ? postInvalidate();
? ? ? ? } else {
? ? ? ? ? ? if (isSelect) {
? ? ? ? ? ? ? ? for (int i = 0; i < selectList.size(); i++) {
? ? ? ? ? ? ? ? ? ? int index = selectList.get(i);
? ? ? ? ? ? ? ? ? ? Point point = allCircleList.get(index);
? ? ? ? ? ? ? ? ? ? canvas.drawCircle(point.cx, point.cy, radius, selectPaint);
? ? ? ? ? ? ? ? ? ? Shader mShader = new RadialGradient(point.cx, point.cy, smallRadius, new int[]{selectColor, shaderColor},
? ? ? ? ? ? ? ? ? ? ? ? ? ? new float[]{0.9f, 1f}, Shader.TileMode.CLAMP);
? ? ? ? ? ? ? ? ? ? centerPaint.setShader(mShader);
? ? ? ? ? ? ? ? ? ? canvas.drawCircle(point.cx, point.cy, smallRadius, centerPaint);
? ? ? ? ? ? ? ? ? ? if (i >= 1) {
? ? ? ? ? ? ? ? ? ? ? ? int lastIndex = selectList.get(i - 1);
? ? ? ? ? ? ? ? ? ? ? ? Point lastPoint = allCircleList.get(lastIndex);
? ? ? ? ? ? ? ? ? ? ? ? canvas.drawLine(lastPoint.cx, lastPoint.cy, point.cx, point.cy, linePaint);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? @Override
? ? public boolean onTouchEvent(MotionEvent event) {
? ? ? ? switch (event.getAction()) {
? ? ? ? ? ? case MotionEvent.ACTION_DOWN:
? ? ? ? ? ? ? ? isReSet = true;
? ? ? ? ? ? ? ? selectList.clear();

? ? ? ? ? ? ? ? int index = calculateWhich(event.getX(), event.getY());
? ? ? ? ? ? ? ? if (index != -1) {
? ? ? ? ? ? ? ? ? ? selectList.add(index);
? ? ? ? ? ? ? ? ? ? isSelect = true;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case MotionEvent.ACTION_MOVE:
? ? ? ? ? ? ? ? index = calculateWhich(event.getX(), event.getY());
? ? ? ? ? ? ? ? if (index != -1) {
? ? ? ? ? ? ? ? ? ? if (!selectList.contains(index)) {
? ? ? ? ? ? ? ? ? ? ? ? selectList.add(index);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case MotionEvent.ACTION_UP:
? ? ? ? ? ? ? ? if (lockViewFinishListener != null) {
? ? ? ? ? ? ? ? ? ? StringBuffer result = new StringBuffer();
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < selectList.size(); i++) {
? ? ? ? ? ? ? ? ? ? ? ? result.append(selectList.get(i));
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? lockViewFinishListener.onSuccess(result + "");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? postInvalidate();
? ? ? ? return true;
? ? }

? ? /**
? ? ?* 計(jì)算控件寬高
? ? ?*
? ? ?* @param widthMeasureSpec
? ? ?* @return
? ? ?*/
? ? private int measureWidth(int widthMeasureSpec) {
? ? ? ? int result;
? ? ? ? int specSize = MeasureSpec.getSize(widthMeasureSpec);
? ? ? ? int specMode = MeasureSpec.getMode(widthMeasureSpec);
? ? ? ? if (specMode == MeasureSpec.EXACTLY) {
? ? ? ? ? ? result = specSize;
? ? ? ? } else {
? ? ? ? ? ? result = getPaddingLeft() + getPaddingRight() + radius * 2 * column ;
? ? ? ? ? ? if (specMode == MeasureSpec.AT_MOST) {
? ? ? ? ? ? ? ? result = Math.min(result, specSize);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return result;
? ? }

? ? /**
? ? ?* 計(jì)算是在哪個(gè)圓中
? ? ?*
? ? ?* @return
? ? ?*/
? ? private int calculateWhich(float lx, float ly) {
? ? ? ? for (int i = 0; i < allCircleList.size(); i++) {
? ? ? ? ? ? Point point = allCircleList.get(i);
? ? ? ? ? ? if (lx > point.cx - radius && lx < point.cx + radius) {
? ? ? ? ? ? ? ? if (ly > point.cy - radius && ly < point.cy + radius) {
? ? ? ? ? ? ? ? ? ? return i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return -1;
? ? }

? ? public interface LockViewFinishListener {
? ? ? ? void onSuccess(String result);
? ? }

? ? private class Point {
? ? ? ? private float cx;
? ? ? ? private float cy;
? ? }

}
<!--九宮格鎖屏控件-->
? ? <declare-styleable name="LockView">
? ? ? ? <!--大圓半徑-->
? ? ? ? <attr name="lock_radius" format="integer"/>
? ? ? ? <!--小圓半徑-->
? ? ? ? <attr name="smallRadius" format="integer"/>
? ? ? ? <!--一行個(gè)數(shù)-->
? ? ? ? <attr name="column" format="integer"/>
? ? ? ? <!--選中顏色-->
? ? ? ? <attr name="selectColor" format="color"/>
? ? ? ? <!--未選中顏色-->
? ? ? ? <attr name="lock_normalColor" format="color"/>
? ? ? ? <!--陰影顏色-->
? ? ? ? <attr name="shaderColor" format="color"/>
? ? ? ? <!--連線的顏色-->
? ? ? ? <attr name="lineColor" format="color"/>
? ? ? ? <!--圓線寬-->
? ? ? ? <attr name="circleStrokeWidth" format="integer"/>
? ? ? ? <!--連線的線寬-->
? ? ? ? <attr name="lineStrokeWidth" format="integer"/>
</declare-styleable>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android編程中Handler原理及用法實(shí)例分析

    Android編程中Handler原理及用法實(shí)例分析

    這篇文章主要介紹了Android編程中Handler用法,結(jié)合實(shí)例形式分析了Handler的功能,原理及使用技巧,需要的朋友可以參考下
    2016-01-01
  • 全面解析Android應(yīng)用開發(fā)中Activity類的用法

    全面解析Android應(yīng)用開發(fā)中Activity類的用法

    這篇文章主要介紹了Android應(yīng)用開發(fā)中Activity類的用法,包括Activity間的數(shù)據(jù)傳遞以及Activity的創(chuàng)建方式等,需要的朋友可以參考下
    2016-02-02
  • 詳解Android版本適配:9.0 Pie

    詳解Android版本適配:9.0 Pie

    這篇文章主要介紹了Android版本適配9.0 Pie,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Android自定義標(biāo)尺滑動(dòng)選擇值效果

    Android自定義標(biāo)尺滑動(dòng)選擇值效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義標(biāo)尺滑動(dòng)選擇值效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • Android實(shí)現(xiàn)擴(kuò)展Menu的方法

    Android實(shí)現(xiàn)擴(kuò)展Menu的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)擴(kuò)展Menu的方法,涉及Android操作menu菜單的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android自定義動(dòng)態(tài)壁紙開發(fā)詳解

    Android自定義動(dòng)態(tài)壁紙開發(fā)詳解

    這篇文章主要為大家詳細(xì)介紹了Android自定義動(dòng)態(tài)壁紙開發(fā),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android 實(shí)現(xiàn)帶角標(biāo)的ImageView(微博,QQ消息提示)

    Android 實(shí)現(xiàn)帶角標(biāo)的ImageView(微博,QQ消息提示)

    下面小編就為大家分享一篇Android 實(shí)現(xiàn)帶角標(biāo)的ImageView(微博,QQ消息提示),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • android球形水波百分比控件代碼

    android球形水波百分比控件代碼

    本篇文章主要是介紹android球形水波百分比控件,現(xiàn)在很多地方都能用的,有需要的可以來(lái)了解一下。
    2016-11-11
  • Android Bitmap和Drawable的對(duì)比

    Android Bitmap和Drawable的對(duì)比

    這篇文章主要介紹了Android Bitmap和Drawable的對(duì)比的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android 編程下的計(jì)時(shí)器代碼

    Android 編程下的計(jì)時(shí)器代碼

    在安卓 APP 的手機(jī)號(hào)注冊(cè)邏輯中,經(jīng)常會(huì)有將激活碼發(fā)送到手機(jī)的環(huán)節(jié),這個(gè)環(huán)節(jié)中絕大多數(shù)的應(yīng)用考慮到網(wǎng)絡(luò)延遲或服務(wù)器壓力以及短信服務(wù)商的延遲等原因,會(huì)給用戶提供一個(gè)重新獲取激活碼的按鈕
    2013-08-08

最新評(píng)論