|
@@ -1,5 +1,6 @@
|
|
|
package com.ht.gate;
|
|
package com.ht.gate;
|
|
|
|
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
import android.content.res.TypedArray;
|
|
import android.content.res.TypedArray;
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
@@ -42,6 +43,9 @@ public class UnlockView extends View {
|
|
|
private DrawFilter drawFilter;
|
|
private DrawFilter drawFilter;
|
|
|
private Typeface source_han_sans_sc_normal;
|
|
private Typeface source_han_sans_sc_normal;
|
|
|
private Typeface source_han_sans_sc_light;
|
|
private Typeface source_han_sans_sc_light;
|
|
|
|
|
+ private int colorLight = 0xFFFFFFFF;
|
|
|
|
|
+ private int colorDark = 0xFF222639;
|
|
|
|
|
+ private boolean dark;
|
|
|
|
|
|
|
|
private String hint;
|
|
private String hint;
|
|
|
|
|
|
|
@@ -70,18 +74,27 @@ public class UnlockView extends View {
|
|
|
|
|
|
|
|
public UnlockView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
public UnlockView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
|
super(context, attrs, defStyleAttr, defStyleRes);
|
|
super(context, attrs, defStyleAttr, defStyleRes);
|
|
|
|
|
+
|
|
|
|
|
+ TypedArray t = getContext().obtainStyledAttributes(attrs,
|
|
|
|
|
+ R.styleable.UnlockView);
|
|
|
|
|
+ hint = t.getString(R.styleable.UnlockView_hint);
|
|
|
|
|
+ if (TextUtils.isEmpty(hint)) {
|
|
|
|
|
+ hint = "滑动解锁";
|
|
|
|
|
+ }
|
|
|
|
|
+ dark = t.getBoolean(R.styleable.UnlockView_darkMode, false);
|
|
|
|
|
+ t.recycle();
|
|
|
|
|
+
|
|
|
source_han_sans_sc_normal = Typeface.createFromAsset(this.getContext().getAssets(), "font/source_han_sans_sc_normal.otf");
|
|
source_han_sans_sc_normal = Typeface.createFromAsset(this.getContext().getAssets(), "font/source_han_sans_sc_normal.otf");
|
|
|
source_han_sans_sc_light = Typeface.createFromAsset(this.getContext().getAssets(), "font/source_han_sans_sc_light.otf");
|
|
source_han_sans_sc_light = Typeface.createFromAsset(this.getContext().getAssets(), "font/source_han_sans_sc_light.otf");
|
|
|
borderPaint = new Paint();
|
|
borderPaint = new Paint();
|
|
|
borderPaint.setAntiAlias(true);
|
|
borderPaint.setAntiAlias(true);
|
|
|
- borderPaint.setColor(Color.WHITE);
|
|
|
|
|
borderWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getContext().getResources().getDisplayMetrics());
|
|
borderWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getContext().getResources().getDisplayMetrics());
|
|
|
borderPaint.setStrokeWidth(borderWidth);
|
|
borderPaint.setStrokeWidth(borderWidth);
|
|
|
borderPaint.setStyle(Paint.Style.STROKE);
|
|
borderPaint.setStyle(Paint.Style.STROKE);
|
|
|
borderPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
|
borderPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
|
|
borderPath = new Path();
|
|
borderPath = new Path();
|
|
|
padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7, getContext().getResources().getDisplayMetrics());
|
|
padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7, getContext().getResources().getDisplayMetrics());
|
|
|
- bmUnlock = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_unlock);
|
|
|
|
|
|
|
+ bmUnlock = BitmapFactory.decodeResource(getResources(), dark ? R.mipmap.icon_unlock_dark : R.mipmap.icon_unlock);
|
|
|
src = new Rect(0, 0, bmUnlock.getWidth(), bmUnlock.getHeight());
|
|
src = new Rect(0, 0, bmUnlock.getWidth(), bmUnlock.getHeight());
|
|
|
dst = new RectF();
|
|
dst = new RectF();
|
|
|
|
|
|
|
@@ -93,18 +106,9 @@ public class UnlockView extends View {
|
|
|
|
|
|
|
|
textPaint = new Paint();
|
|
textPaint = new Paint();
|
|
|
textPaint.setAntiAlias(true);
|
|
textPaint.setAntiAlias(true);
|
|
|
- textPaint.setColor(Color.WHITE);
|
|
|
|
|
textPaint.setTextSize(sp2px(25));
|
|
textPaint.setTextSize(sp2px(25));
|
|
|
textPaint.setStyle(Paint.Style.FILL);
|
|
textPaint.setStyle(Paint.Style.FILL);
|
|
|
textPaint.setTypeface(source_han_sans_sc_light);
|
|
textPaint.setTypeface(source_han_sans_sc_light);
|
|
|
-
|
|
|
|
|
- TypedArray t = getContext().obtainStyledAttributes(attrs,
|
|
|
|
|
- R.styleable.UnlockView);
|
|
|
|
|
- hint = t.getString(R.styleable.UnlockView_hint);
|
|
|
|
|
- if (TextUtils.isEmpty(hint)) {
|
|
|
|
|
- hint = "滑动解锁";
|
|
|
|
|
- }
|
|
|
|
|
- t.recycle();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -112,6 +116,7 @@ public class UnlockView extends View {
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @SuppressLint("DrawAllocation")
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDraw(Canvas canvas) {
|
|
protected void onDraw(Canvas canvas) {
|
|
|
canvas.setDrawFilter(drawFilter);
|
|
canvas.setDrawFilter(drawFilter);
|
|
@@ -119,6 +124,13 @@ public class UnlockView extends View {
|
|
|
float height = getHeight();
|
|
float height = getHeight();
|
|
|
float d = (height - borderWidth);
|
|
float d = (height - borderWidth);
|
|
|
float r = d / 2;
|
|
float r = d / 2;
|
|
|
|
|
+ if (dark) {
|
|
|
|
|
+ borderPaint.setColor(colorDark);
|
|
|
|
|
+ textPaint.setColor(colorDark);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ borderPaint.setColor(colorLight);
|
|
|
|
|
+ textPaint.setColor(colorDark);
|
|
|
|
|
+ }
|
|
|
borderPath.reset();
|
|
borderPath.reset();
|
|
|
borderPath.moveTo(r + borderWidth / 2, borderWidth / 2);
|
|
borderPath.moveTo(r + borderWidth / 2, borderWidth / 2);
|
|
|
borderPath.lineTo(width - r, borderWidth / 2);
|
|
borderPath.lineTo(width - r, borderWidth / 2);
|
|
@@ -131,8 +143,17 @@ public class UnlockView extends View {
|
|
|
int dd = (int) Math.max(0, Math.min(distance, getWidth() - padding * 2 - size));
|
|
int dd = (int) Math.max(0, Math.min(distance, getWidth() - padding * 2 - size));
|
|
|
|
|
|
|
|
linePaint.setStrokeWidth(height - padding * 2);
|
|
linePaint.setStrokeWidth(height - padding * 2);
|
|
|
- lineShader = new LinearGradient(0, 0, width, 0,
|
|
|
|
|
- new int[]{Color.argb(0, 255, 255, 255), Color.argb(30, 255, 255, 255), Color.argb(117, 255, 255, 255), Color.argb(255, 255, 255, 255)},
|
|
|
|
|
|
|
+ lineShader = dark ? new LinearGradient(0, 0, width, 0,
|
|
|
|
|
+ new int[]{0x00222639,
|
|
|
|
|
+ 0x1F222639,
|
|
|
|
|
+ 0x78222639,
|
|
|
|
|
+ 0xD4222639},
|
|
|
|
|
+ new float[]{0, 0.19f, 0.42f, 1}, Shader.TileMode.CLAMP)
|
|
|
|
|
+ : new LinearGradient(0, 0, width, 0,
|
|
|
|
|
+ new int[]{Color.argb(0, 255, 255, 255),
|
|
|
|
|
+ Color.argb(30, 255, 255, 255),
|
|
|
|
|
+ Color.argb(117, 255, 255, 255),
|
|
|
|
|
+ Color.argb(255, 255, 255, 255)},
|
|
|
new float[]{0, 0.19f, 0.42f, 1}, Shader.TileMode.CLAMP);
|
|
new float[]{0, 0.19f, 0.42f, 1}, Shader.TileMode.CLAMP);
|
|
|
linePaint.setShader(lineShader);
|
|
linePaint.setShader(lineShader);
|
|
|
canvas.drawLine(r, height / 2, r + dd, height / 2, linePaint);
|
|
canvas.drawLine(r, height / 2, r + dd, height / 2, linePaint);
|