android九宫格隐藏,android九宫格锁屏控件
allCircleList = new ArrayList<>();
//选中圆的标志
private ListselectList = 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);//设置为无锯齿
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);//设置为无锯齿
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;
}
/**
* 计算控件宽高
*
* @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;
}
/**
* 计算是在哪个圆中
*
* @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;
}
}
android九宫格隐藏,android九宫格锁屏控件相关推荐
- python 阻止锁屏_想要自己的手机锁屏更加安全吗?python带你打造个性的锁屏控件...
原标题:想要自己的手机锁屏更加安全吗?python带你打造个性的锁屏控件 Python是一种面向对象.直译式电脑编程语言,也是一种功能强大的通用型语言,已经具有近二十年的发展历史,成熟且稳定.它包含了 ...
- Android安全学习笔记1——锁屏密码方式
前言 在Android安全学习中,我接触到第一个例子是锁屏密码.我们日常使用手机的时候使用最多的锁屏密码是怎么构成的?下面分享一下我接触到的知识. 锁屏密码的思考 为了安全,Android设备在解锁屏 ...
- android 监听屏幕是否锁屏
今天,简单讲讲如何监听手机屏幕是否锁屏. 实现方法:1)通过BroadcastReceiver接收广播Intent.ACTION_SCREEN_ON和Intent.ACTION_SCREEN_OFF可 ...
- Android关闭屏幕时不锁屏
Android关闭屏幕时不锁屏 权限 <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/ ...
- Android直播软件搭建左滑右滑清屏控件
Android直播软件搭建左滑右滑清屏控件 最近在迭代直播软件搭建功能时,项目中之前的左滑清屏是用ViewPager实现的.这次迭代遇到一个布局层次导致的点击失效问题,继续用ViewPager的话改动 ...
- android app自动锁屏,Android开机自动启动app 不锁屏
Android开机自动启动app 不锁屏 发布时间:2020-07-17 03:22:20 来源:51CTO 阅读:2086 作者:清水禅石 主要参考:http://life173.blog.51ct ...
- Android技术分享| 【Android 自定义View】多人视频通话控件
[Android 自定义View]多人视频通话控件 *以上图片截自微信等待中界面 等待中界面 上图是微信多人视频通话时未接通的界面状态,可见每个人的 View 中大致需包含了以下元素. 头像 昵称 L ...
- android怎么查看方法被谁调用,Android中查看布局文件中的控件(view,id)在哪里被调用(使用)...
在阅读别人的代码时通常是很痛苦的,有时很想要看一看布局中的控件在哪里被调用了,为之很苦恼 在这里提供一种方法. 复制要查看的控件ID,到R文件中搜索到该ID, 接下来就好办的了,选中ID按下Ctrl鼠 ...
- Android横向滑动加载更多的控件的实现---HorizontalScrollSlideView
Android横向滑动加载更多的控件的实现-HorizontalScrollSlideView 需求 之前公司业务要求做一个横向滑动的,可以加载更多的控件,第一时间想到的就是 RecyclerView ...
最新文章
- friend之友元函数和友元类
- 牛客16589 机器翻译
- oracle PL/SQL编程基础
- MicropPython的学习,如何从0到1?
- 解决window资源管理器打开无法删除文件
- myblog test
- mysql 主从数据库配置_8、MySQL主从数据库配置
- Win7安装IE10或IE11 离线安装注意问题
- 内置式永磁同步电机IPMSM,最大转矩电流比MTPA控制仿真模型
- iphone11 sim卡故障_苹果手机出现sim卡故障怎么处理?
- android方法不混淆,Android 混淆时不混淆注解方法
- 移动跨平台框架ReactNative文本组件Text【06】
- Updates were rejected because the tip of your current branch is behind hint: its remote counterpart
- 输入年月日获取农历日期
- E575: viminfo: Illegal starting char in line:
- 电脑视频怎么录制?好用的电脑录屏方法
- 0-SIM卡的迭代(SIM-USIM-eSIM-vSIM-softSIM)
- 自建家居 Wiki 系统(BookStack 服务)
- R语言的四种数据结构---向量
- 机器学习笔记之深度信念网络(二)模型构建思想(RBM叠加结构)