麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

手勢密碼

2019-11-09 16:22:05
字體:
來源:轉載
供稿:網友
package com.xiaoyu.shoushi_pass_exercise;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.widget.Toast;import java.util.ArrayList;import java.util.List;/** * 1.類的用途: * 2.作者:段玉 * 3.時間:2017/2/8 07 * 4.郵箱:1239959892@QQ.com */public class Shou_Shi extends View {    //畫筆顏色    public final static int Before_Color = Color.parseColor("#FAEB76");    public final static int After_Color = Color.parseColor("#000000");    //畫圓集合    List<Circle> circleList = new ArrayList<>();    //畫線的集合    List<Circle> lineList = new ArrayList<Circle>();   //獲取寬高    PRivate int width;    private int height;    //半徑    private int radio;    private Paint paint;    public Shou_Shi(Context context) {        super(context);    }    public Shou_Shi(Context context, AttributeSet attrs) {        super(context, attrs);    }    public Shou_Shi(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        width = getWidth();        height = getHeight();        radio = width / 10;        addlist();        drawCircle(canvas);    }    @Override    public boolean onTouchEvent(MotionEvent event) {        switch (event.getAction()){            case MotionEvent.ACTION_DOWN:            {            }                break;            case MotionEvent.ACTION_MOVE:            {                int x = (int) event.getX();                int y = (int) event.getY();                Log.d("段玉",x+"---"+y);                //坐標轉換                for (int i = 0; i < circleList.size(); i++) {                    int xx = (int) Math.pow((x - circleList.get(i).x), 2);                    int yy = (int) Math.pow((y - circleList.get(i).y),2);                    int num = xx + yy;                    //根據勾股定力判斷                    if (num <= Math.pow(radio,2)){                        //重新設置畫筆顏色                        circleList.get(i).color = After_Color;                        //設置為選中狀態                        circleList.get(i).isSelect = true;                        //判斷是否存在,避免加重復                        Boolean isflag = false;                        for (int j = 0; j < lineList.size(); j++) {                            //通過數字判斷存在不存在                            if (circleList.get(i).number == lineList.get(j).number){                                isflag = true;                            }                        }                        //否則就加入                        if (isflag == false){                            Circle circle = new Circle();                            circle.x = circleList.get(i).x;                            circle.y = circleList.get(i).y;                            circle.color = circleList.get(i).color;                            circle.number = circleList.get(i).number;                            lineList.add(circle);                        }                        //同時刷新ui                        postInvalidate();                    }                }            }                break;            case MotionEvent.ACTION_UP:            {                String passWord = "";                for (int i = 0; i < lineList.size(); i++) {                    passWord += lineList.get(i).number+"";                }                Toast.makeText(getContext(),"當前密碼是"+passWord, Toast.LENGTH_SHORT).show();                //清理屏幕                for (int i = 0; i < circleList.size(); i++) {                    circleList.get(i).color = Before_Color;                    circleList.get(i).isSelect = false;                }                //清空集合                lineList.clear();                //同時刷新ui                postInvalidate();            }                break;        }        return true;    }    private void drawCircle(Canvas canvas) {        //實例化畫筆        paint = new Paint();        //設置畫筆抗鋸齒        paint.setAntiAlias(true);        //設置畫筆寬度        paint.setStrokeWidth(3);        //設置空心圓        paint.setStyle(Paint.Style.STROKE);        for (int i = 0; i < circleList.size(); i++) {            //設置畫筆顏色            paint.setColor(circleList.get(i).color);            //畫圓            canvas.drawCircle(circleList.get(i).x,circleList.get(i).y,circleList.get(i).radio,paint);        }        boolean isFirst = false;        int startX = 0;        int startY = 0;        //畫線的方法        for (int i = 0; i < lineList.size(); i++) {            if (isFirst == false){                isFirst = true;                startX = lineList.get(i).x;                startY = lineList.get(i).y;            }else{                paint.setColor(lineList.get(i).color);                //畫線                canvas.drawLine(startX,startY,lineList.get(i).x,lineList.get(i).y,paint);                startX = lineList.get(i).x;                startY = lineList.get(i).y;            }        }    }    private void addlist() {        for (int i = 1; i <= 9; i++) {            //實例化對象            Circle circle = new Circle();            if (i <= 3){                circle.y = height/2 - radio*3;            }else if (i > 3 && i <= 6){                circle.y = height / 2;            }else{                circle.y = height/2 +radio*3;            }            if (i == 1 || i == 4 || i == 7){                circle.x = radio * 2;            }else if (i == 2 || i == 5 || i == 8){                circle.x = radio * 5;            }else{                circle.x = radio * 8;            }            circle.radio = radio;            circle.isSelect = false;            circle.color = Before_Color;            circle.number = i;            circleList.add(circle);        }    }}//一下就是簡單的xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#00ff00"    tools:context="com.xiaoyu.shoushi_pass_exercise.MainActivity">    <com.baway.shoushi_pass_exercise.Shou_Shi        android:layout_width="match_parent"        android:layout_height="match_parent"/></RelativeLayout> 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩专区在线 | 国产精品伊人久久 | 新久草视频 | 日韩精品久久久久久久电影99爱 | 日产精品久久久一区二区福利 | av日韩一区二区三区 | 日本羞羞的午夜电视剧 | 2019中文字幕在线播放 | 亚洲男人的天堂在线视频 | 成年免费在线视频 | 亚洲精品久久久久久久久久久 | 日韩美女电影 | 日韩色视频在线观看 | 一级成人欧美一区在线观看 | 国产精品性夜天天视频 | av7777777 | 国产午夜精品一区二区三区免费 | japanese xxxxhd | av噜噜在线 | 国产成人在线一区二区 | 国产资源在线观看视频 | 天天干天天碰 | 福利在线国产 | av免费av| 成人精品一区二区三区中文字幕 | 91成人在线免费视频 | hdhdhd69ⅹxxx黑人 | 4p嗯啊巨肉寝室调教男男视频 | 少妇一级淫片免费放播放 | 精品一区二区免费 | 精品国产91久久久久久 | 精品成人久久久 | 午夜视频在线观看91 | 在线a免费观看 | 国产人成精品一区二区三 | 国产91丝袜在线播放 | 成年人免费高清视频 | 国产91精品一区二区麻豆亚洲 | 久久久久在线观看 | 久久久久久久久久久综合 | 性少妇videosexfreexx |