ipAddr = intf.getInetAddresses(); ipAddr.hasMoreElements(); ) {
InetAddress inetAddress = ipAddr.nextElement();
- if(isV4) {
+ if (isV4) {
// ipv4地址
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
return inetAddress.getHostAddress();
}
- }else{
+ } else {
// ipv6地址
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv6Address(inetAddress.getHostAddress())) {
return inetAddress.getHostAddress();
@@ -310,7 +304,7 @@ public String GetIp(Boolean isV4) {
return "";
}
- private String getLocalDNS(){
+ private String getLocalDNS() {
Process cmdProcess = null;
BufferedReader reader = null;
String dnsIP = "";
@@ -321,7 +315,7 @@ private String getLocalDNS(){
return dnsIP;
} catch (IOException e) {
return null;
- } finally{
+ } finally {
try {
if (reader != null) {
reader.close();
diff --git a/app/src/main/java/cn/darkal/networkdiagnosis/Utils/NetInfo/SystemBasicInfo.java b/app/src/main/java/cn/darkal/networkdiagnosis/Utils/NetInfo/SystemBasicInfo.java
index 76fed93..5de9a59 100644
--- a/app/src/main/java/cn/darkal/networkdiagnosis/Utils/NetInfo/SystemBasicInfo.java
+++ b/app/src/main/java/cn/darkal/networkdiagnosis/Utils/NetInfo/SystemBasicInfo.java
@@ -37,7 +37,7 @@ public static String getBuildInfo() {
public static String getUUID(Context context) {
try {
String androidId = getAndroidId(context);
- String deviceId = getDeviceId(context)==null? "null":getDeviceId(context);
+ String deviceId = getDeviceId(context) == null ? "null" : getDeviceId(context);
UUID uuid = new UUID(androidId.hashCode(), ((long) deviceId.hashCode() << 32) | deviceId.hashCode());
return uuid.toString();
} catch (Exception e) {
diff --git a/app/src/main/java/cn/darkal/networkdiagnosis/Utils/SharedPreferenceUtils.java b/app/src/main/java/cn/darkal/networkdiagnosis/Utils/SharedPreferenceUtils.java
index 1627148..d8a8d26 100644
--- a/app/src/main/java/cn/darkal/networkdiagnosis/Utils/SharedPreferenceUtils.java
+++ b/app/src/main/java/cn/darkal/networkdiagnosis/Utils/SharedPreferenceUtils.java
@@ -1,6 +1,5 @@
package cn.darkal.networkdiagnosis.Utils;
-import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
@@ -166,7 +165,7 @@ public static void save(Context context, String key, Object saveObject) {
/**
* 获取SharedPreference保存的对象
*
- * @param context context
+ * @param context context
* @param key 储存对象的key
* @return object 返回根据key得到的对象
*/
diff --git a/app/src/main/java/cn/darkal/networkdiagnosis/View/ClearTextView.java b/app/src/main/java/cn/darkal/networkdiagnosis/View/ClearTextView.java
index 63634a1..5c1824b 100644
--- a/app/src/main/java/cn/darkal/networkdiagnosis/View/ClearTextView.java
+++ b/app/src/main/java/cn/darkal/networkdiagnosis/View/ClearTextView.java
@@ -33,26 +33,12 @@ public class ClearTextView extends EditText {
private int mButtonPadding = dp2px(3);
-
-
-
- /**
- * 按钮显示方式
- * NEVER 不显示清空按钮
- * ALWAYS 始终显示清空按钮
- * WHILEEDITING 输入框内容不为空且有获得焦点
- * UNLESSEDITING 输入框内容不为空且没有获得焦点
- * */
- public enum ClearButtonMode {
- NEVER, ALWAYS, WHILEEDITING, UNLESSEDITING
- }
-
-
public ClearTextView(Context context) {
super(context);
init(context, null);
}
+
public ClearTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
@@ -63,10 +49,6 @@ public ClearTextView(Context context, AttributeSet attrs, int defStyleAttr) {
init(context, attrs);
}
-
-
-
-
/**
* 初始化
*/
@@ -101,10 +83,9 @@ private void init(Context context, AttributeSet attributeSet) {
mInitPaddingRight = getPaddingRight();
}
-
-
/**
* 按钮状态管理
+ *
* @param canvas onDraw的Canvas
*/
private void buttonManager(Canvas canvas) {
@@ -123,11 +104,10 @@ private void buttonManager(Canvas canvas) {
}
}
-
-
/**
* 设置输入框的内边距
- * @param isShow 是否显示按钮
+ *
+ * @param isShow 是否显示按钮
*/
private void setPadding(boolean isShow) {
int paddingRight = mInitPaddingRight + (isShow ? mClearButton.getWidth() + mButtonPadding + mButtonPadding : 0);
@@ -135,19 +115,18 @@ private void setPadding(boolean isShow) {
setPadding(getPaddingLeft(), getPaddingTop(), paddingRight, getPaddingBottom());
}
-
-
/**
* 取得显示按钮与不显示按钮时的Rect
- * @param isShow 是否显示按钮
+ *
+ * @param isShow 是否显示按钮
*/
private Rect getRect(boolean isShow) {
int left, top, right, bottom;
- right = isShow ? getMeasuredWidth() + getScrollX() - mButtonPadding - mButtonPadding : 0;
- left = isShow ? right - mClearButton.getWidth() : 0;
- top = isShow ? (getMeasuredHeight() - mClearButton.getHeight())/2 : 0;
- bottom = isShow ? top + mClearButton.getHeight() : 0;
+ right = isShow ? getMeasuredWidth() + getScrollX() - mButtonPadding - mButtonPadding : 0;
+ left = isShow ? right - mClearButton.getWidth() : 0;
+ top = isShow ? (getMeasuredHeight() - mClearButton.getHeight()) / 2 : 0;
+ bottom = isShow ? top + mClearButton.getHeight() : 0;
//更新输入框内边距
@@ -157,10 +136,9 @@ private Rect getRect(boolean isShow) {
return new Rect(left, top, right, bottom);
}
-
-
/**
* 绘制按钮图片
+ *
* @param canvas onDraw的Canvas
* @param rect 图片位置
*/
@@ -170,9 +148,6 @@ private void drawBitmap(Canvas canvas, Rect rect) {
}
}
-
-
-
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
@@ -194,19 +169,17 @@ public boolean onTouchEvent(MotionEvent event) {
this.setText("");
}
break;
+ default:
+ break;
}
return super.onTouchEvent(event);
}
-
-
-
-
-
/**
* 获取Drawable
- * @param resourseId 资源ID
+ *
+ * @param resourseId 资源ID
*/
private Drawable getDrawableCompat(int resourseId) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
@@ -218,6 +191,7 @@ private Drawable getDrawableCompat(int resourseId) {
/**
* 设置按钮左右内边距
+ *
* @param buttonPadding 单位为dp
*/
public void setButtonPadding(int buttonPadding) {
@@ -226,6 +200,7 @@ public void setButtonPadding(int buttonPadding) {
/**
* 设置按钮显示方式
+ *
* @param clearButtonMode 显示方式
*/
public void setClearButtonMode(ClearButtonMode clearButtonMode) {
@@ -240,4 +215,15 @@ public int dp2px(float dipValue) {
final float scale = getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
+
+ /**
+ * 按钮显示方式
+ * NEVER 不显示清空按钮
+ * ALWAYS 始终显示清空按钮
+ * WHILEEDITING 输入框内容不为空且有获得焦点
+ * UNLESSEDITING 输入框内容不为空且没有获得焦点
+ */
+ public enum ClearButtonMode {
+ NEVER, ALWAYS, WHILEEDITING, UNLESSEDITING
+ }
}
diff --git a/app/src/main/java/cn/darkal/networkdiagnosis/View/LoadingDialog.java b/app/src/main/java/cn/darkal/networkdiagnosis/View/LoadingDialog.java
index 492dfde..cdd22c4 100644
--- a/app/src/main/java/cn/darkal/networkdiagnosis/View/LoadingDialog.java
+++ b/app/src/main/java/cn/darkal/networkdiagnosis/View/LoadingDialog.java
@@ -23,6 +23,7 @@ public class LoadingDialog extends ProgressDialog {
private boolean mSingleLine;
private Context mContext;
private ProgressWheel mProgressWheel;
+
public LoadingDialog(Context context) {
super(context, R.style.JzAlertDialogWhite);
}
@@ -52,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_loading2_dialog);
TextView mMessage = (TextView) findViewById(R.id.loading_dialog_message);
- if ((mText == null) || (mText.equals(""))) {
+ if (TextUtils.isEmpty(mText)) {
mMessage.setVisibility(View.GONE);
} else {
mMessage.setVisibility(View.VISIBLE);
@@ -96,7 +97,7 @@ public void show() {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
- if(mProgressWheel != null) {
+ if (mProgressWheel != null) {
mProgressWheel.spin();
}
}
@@ -104,7 +105,7 @@ public void onAttachedToWindow() {
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
- if(mProgressWheel != null) {
+ if (mProgressWheel != null) {
mProgressWheel.stopSpinning();
}
}
diff --git a/app/src/main/java/cn/darkal/networkdiagnosis/View/ProgressWheel.java b/app/src/main/java/cn/darkal/networkdiagnosis/View/ProgressWheel.java
index 83b4586..3e9282e 100644
--- a/app/src/main/java/cn/darkal/networkdiagnosis/View/ProgressWheel.java
+++ b/app/src/main/java/cn/darkal/networkdiagnosis/View/ProgressWheel.java
@@ -17,138 +17,135 @@
/**
* An indicator of progress, similar to Android's ProgressBar.
* Can be used in 'spin mode' or 'increment mode'
- * @author Todd Davies
*
+ * @author Todd Davies
+ *
* Licensed under the Creative Commons Attribution 3.0 license see:
* http://creativecommons.org/licenses/by/3.0/
*/
public class ProgressWheel extends View {
-
- //Sizes (with defaults)
- private int fullRadius = 100;
- private int circleRadius = 80;
- private int barLength = 60;
- private int barWidth = 20; //内部圆弧的宽度
- private int rimWidth = 20;
- private int textSize = 20;
+
+ int progress = 0;
+ boolean isSpinning = false;
+ //Sizes (with defaults)
+ private int fullRadius = 100;
+ private int circleRadius = 80;
+ private int barLength = 60;
+ private int barWidth = 20; //内部圆弧的宽度
+ private int rimWidth = 20;
+ private int textSize = 20;
private int barDegree = 60;
- private float arcR = barWidth/2; //内部圆弧的半径
-
- //Padding (with defaults)
- private int paddingTop = 5;
- private int paddingBottom = 5;
- private int paddingLeft = 5;
- private int paddingRight = 5;
-
- //Colors (with defaults)
- private int barColor = 0xAA000000;
- private int circleColor = 0x0000ffff;
- private int rimColor = 0xAADDDDDD;
+ private float arcR = barWidth / 2; //内部圆弧的半径
+ //Padding (with defaults)
+ private int paddingTop = 5;
+ private int paddingBottom = 5;
+ private int paddingLeft = 5;
+ private int paddingRight = 5;
+ //Colors (with defaults)
+ private int barColor = 0xAA000000;
+ private int circleColor = 0x0000ffff;
+ private int rimColor = 0xAADDDDDD;
private int spinRimColor = 0xAADDDDDD;
- private int textColor = 0xFF000000;
- private int spinCircleColor = 0x00000000;
-
- //Paints
- private Paint barPaint = new Paint(); //圆画笔
- private Paint circlePaint = new Paint(); //内部填充圆画笔
- private Paint barCirclePaint = new Paint(); //圆弧上两端点圆的画笔
- private Paint rimPaint = new Paint(); //底部圈画笔
- private Paint textPaint = new Paint();
+ private int textColor = 0xFF000000;
+ private int spinCircleColor = 0x00000000;
+ //Paints
+ private Paint barPaint = new Paint(); //圆画笔
+ private Paint circlePaint = new Paint(); //内部填充圆画笔
+ private Paint barCirclePaint = new Paint(); //圆弧上两端点圆的画笔
+ private Paint rimPaint = new Paint(); //底部圈画笔
+ private Paint textPaint = new Paint();
private Paint spinRimPaint = new Paint(); //旋转时,底部圈画笔,主要用于此时改变底部圈颜色
- private Paint spinCirclePaint = new Paint();//旋转时,圆的画笔
-
- //Rectangles
- @SuppressWarnings("unused")
- private RectF rectBounds = new RectF();
- private RectF circleBounds = new RectF();
-
- private int startDegree = -90; //圆弧的起始位置, -90 顶上
- private float startArcX = 0;
- private float startArcY = 0;
-
- //Animation
- //The amount of pixels to move the bar by on each draw
- private int spinSpeed = 2;
- //The number of milliseconds to wait inbetween each draw
- private int delayMillis = 0;
- private Handler spinHandler = new Handler() {
- /**
- * This is the code that will increment the progress variable
- * and so spin the wheel
- */
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0:
- invalidate();
- if (isSpinning) {
- progress += spinSpeed;
- if (progress > 360) {
- progress = 0;
- }
- spinHandler.sendEmptyMessageDelayed(0, delayMillis);
- }
- break;
- case 1:
- spinHandler.removeMessages(0);
- isSpinning = false;
- invalidate();
- break;
- }
- }
- };
- int progress = 0;
- boolean isSpinning = false;
-
- //Other
- private String text = "";
- private String[] splitText = {};
-
- /**
- * The constructor for the ProgressWheel
- * @param context
- * @param attrs
- */
- public ProgressWheel(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- parseAttributes(context.obtainStyledAttributes(attrs,
- R.styleable.ProgressWheel));
- }
-
- //----------------------------------
- //Setting up stuff
- //----------------------------------
-
- /**
- * Now we know the dimensions of the view, setup the bounds and paints
- */
- @Override
- public void onAttachedToWindow() {
- super.onAttachedToWindow();
-
- setupBounds();
- setupPaints();
- invalidate();
-
- }
-
- @Override
- protected void onDetachedFromWindow() {
- invalidate();
- super.onDetachedFromWindow();
- }
-
- /**
- * Set the properties of the paints we're using to
- * draw the progress wheel
- */
- private void setupPaints() {
- barPaint.setColor(barColor);
+ private Paint spinCirclePaint = new Paint();//旋转时,圆的画笔
+ //Rectangles
+ @SuppressWarnings("unused")
+ private RectF rectBounds = new RectF();
+ private RectF circleBounds = new RectF();
+ private int startDegree = -90; //圆弧的起始位置, -90 顶上
+ private float startArcX = 0;
+ private float startArcY = 0;
+ //Animation
+ //The amount of pixels to move the bar by on each draw
+ private int spinSpeed = 2;
+ //The number of milliseconds to wait inbetween each draw
+ private int delayMillis = 0;
+ private Handler spinHandler = new Handler() {
+ /**
+ * This is the code that will increment the progress variable
+ * and so spin the wheel
+ */
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case 0:
+ invalidate();
+ if (isSpinning) {
+ progress += spinSpeed;
+ if (progress > 360) {
+ progress = 0;
+ }
+ spinHandler.sendEmptyMessageDelayed(0, delayMillis);
+ }
+ break;
+ case 1:
+ spinHandler.removeMessages(0);
+ isSpinning = false;
+ invalidate();
+ break;
+ default:
+ break;
+ }
+ }
+ };
+ //Other
+ private String text = "";
+ private String[] splitText = {};
+
+ /**
+ * The constructor for the ProgressWheel
+ *
+ * @param context
+ * @param attrs
+ */
+ public ProgressWheel(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ parseAttributes(context.obtainStyledAttributes(attrs,
+ R.styleable.ProgressWheel));
+ }
+
+ //----------------------------------
+ //Setting up stuff
+ //----------------------------------
+
+ /**
+ * Now we know the dimensions of the view, setup the bounds and paints
+ */
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ setupBounds();
+ setupPaints();
+ invalidate();
+
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ invalidate();
+ super.onDetachedFromWindow();
+ }
+
+ /**
+ * Set the properties of the paints we're using to
+ * draw the progress wheel
+ */
+ private void setupPaints() {
+ barPaint.setColor(barColor);
barPaint.setAntiAlias(true);
barPaint.setStyle(Style.STROKE);
barPaint.setStrokeWidth(barWidth);
-
+
rimPaint.setColor(rimColor);
rimPaint.setAntiAlias(true);
rimPaint.setStyle(Style.STROKE);
@@ -159,331 +156,338 @@ private void setupPaints() {
spinRimPaint.setStyle(Style.STROKE);
spinRimPaint.setStrokeWidth(rimWidth);
- spinCirclePaint.setColor(spinCircleColor);
- spinCirclePaint.setAntiAlias(true);
- spinCirclePaint.setStyle(Style.FILL);
- spinCirclePaint.setShadowLayer(1, 2, 2, 0x40000000);
-
+ spinCirclePaint.setColor(spinCircleColor);
+ spinCirclePaint.setAntiAlias(true);
+ spinCirclePaint.setStyle(Style.FILL);
+ spinCirclePaint.setShadowLayer(1, 2, 2, 0x40000000);
+
circlePaint.setColor(circleColor);
circlePaint.setAntiAlias(true);
circlePaint.setStyle(Style.FILL);
- barCirclePaint.setColor(barColor);
- barCirclePaint.setAntiAlias(true);
- barCirclePaint.setStyle(Style.FILL);
- barCirclePaint.setStrokeWidth(barWidth);
-
+ barCirclePaint.setColor(barColor);
+ barCirclePaint.setAntiAlias(true);
+ barCirclePaint.setStyle(Style.FILL);
+ barCirclePaint.setStrokeWidth(barWidth);
+
textPaint.setColor(textColor);
textPaint.setStyle(Style.FILL);
textPaint.setAntiAlias(true);
textPaint.setTextSize(textSize);
- }
-
- /**
- * Set the bounds of the component
- */
- private void setupBounds() {
- paddingTop = this.getPaddingTop();
- paddingBottom = this.getPaddingBottom();
- paddingLeft = this.getPaddingLeft();
- paddingRight = this.getPaddingRight();
-
- rectBounds = new RectF(paddingLeft,
- paddingTop,
+ }
+
+ /**
+ * Set the bounds of the component
+ */
+ private void setupBounds() {
+ paddingTop = this.getPaddingTop();
+ paddingBottom = this.getPaddingBottom();
+ paddingLeft = this.getPaddingLeft();
+ paddingRight = this.getPaddingRight();
+
+ rectBounds = new RectF(paddingLeft,
+ paddingTop,
this.getLayoutParams().width - paddingRight,
this.getLayoutParams().height - paddingBottom);
-
- circleBounds = new RectF(paddingLeft + barWidth,
- paddingTop + barWidth,
+
+ circleBounds = new RectF(paddingLeft + barWidth,
+ paddingTop + barWidth,
this.getLayoutParams().width - paddingRight - barWidth,
this.getLayoutParams().height - paddingBottom - barWidth);
-
- fullRadius = (this.getLayoutParams().width - paddingRight - barWidth)/2;
- circleRadius = (fullRadius - barWidth) + 1; //内部圆的半径
-
- arcR = barWidth/2; //圆弧的半径
- startArcX = (float) (-circleBounds.width()/2* Math.sin( 2* Math.PI/360*(startDegree+270))+this.getLayoutParams().width/2); //计算时角度要换成弧度
- startArcY = (float) (circleBounds.height()/2* Math.cos(2 * Math.PI / 360 * (startDegree+270)) + this.getLayoutParams().height/2);
- }
-
- /**
- * Parse the attributes passed to the view from the XML
- * @param a the attributes to parse
- */
- private void parseAttributes(TypedArray a) {
- barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth_progress,
- barWidth);
-
- rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth_progress,
- rimWidth);
-
- spinSpeed = (int) a.getInteger(R.styleable.ProgressWheel_spinSpeed_progress,
- spinSpeed);
-
- delayMillis = (int) a.getInteger(R.styleable.ProgressWheel_delayMillis_progress,
- delayMillis);
- if(delayMillis<0) {
- delayMillis = 0;
- }
-
- barColor = a.getColor(R.styleable.ProgressWheel_barColor_progress, barColor);
-
- barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength_progress,
- barLength);
-
- textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize_progress,
- textSize);
-
- textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor_progress,
- textColor);
-
- setText(a.getString(R.styleable.ProgressWheel_text_progress));
-
- rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor_progress,
- rimColor);
+
+ fullRadius = (this.getLayoutParams().width - paddingRight - barWidth) / 2;
+ circleRadius = (fullRadius - barWidth) + 1; //内部圆的半径
+
+ arcR = barWidth / 2; //圆弧的半径
+ startArcX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * (startDegree + 270)) + this.getLayoutParams().width / 2); //计算时角度要换成弧度
+ startArcY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * (startDegree + 270)) + this.getLayoutParams().height / 2);
+ }
+
+ /**
+ * Parse the attributes passed to the view from the XML
+ *
+ * @param a the attributes to parse
+ */
+ private void parseAttributes(TypedArray a) {
+ barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth_progress,
+ barWidth);
+
+ rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth_progress,
+ rimWidth);
+
+ spinSpeed = (int) a.getInteger(R.styleable.ProgressWheel_spinSpeed_progress,
+ spinSpeed);
+
+ delayMillis = (int) a.getInteger(R.styleable.ProgressWheel_delayMillis_progress,
+ delayMillis);
+ if (delayMillis < 0) {
+ delayMillis = 0;
+ }
+
+ barColor = a.getColor(R.styleable.ProgressWheel_barColor_progress, barColor);
+
+ barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength_progress,
+ barLength);
+
+ textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize_progress,
+ textSize);
+
+ textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor_progress,
+ textColor);
+
+ setText(a.getString(R.styleable.ProgressWheel_text_progress));
+
+ rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor_progress,
+ rimColor);
spinRimColor = (int) a.getColor(R.styleable.ProgressWheel_spinRimColor_progress,
spinRimColor);
-
- circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor_progress, circleColor);
- spinCircleColor = (int) a.getColor(R.styleable.ProgressWheel_spinCircleColor_progress, spinCircleColor);
-
- barDegree = (int) a.getInteger(R.styleable.ProgressWheel_barDegree_progress,-1);
- }
-
- //----------------------------------
- //Animation stuff
- //----------------------------------
-
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
-
- //Draw the rim
- if(isSpinning()){
+
+ circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor_progress, circleColor);
+ spinCircleColor = (int) a.getColor(R.styleable.ProgressWheel_spinCircleColor_progress, spinCircleColor);
+
+ barDegree = (int) a.getInteger(R.styleable.ProgressWheel_barDegree_progress, -1);
+ }
+
+ //----------------------------------
+ //Animation stuff
+ //----------------------------------
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ //Draw the rim
+ if (isSpinning()) {
canvas.drawArc(circleBounds, 360, 360, false, spinRimPaint);
- }else {
+ } else {
canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
}
- //Draw the bar
- if(isSpinning) {
- if(barDegree != -1) { //按度数
+ //Draw the bar
+ if (isSpinning) {
+ if (barDegree != -1) { //按度数
canvas.drawArc(circleBounds, progress - 90, barDegree, false,
barPaint);
- //结束度数
- double t = (progress - 90+barDegree + 270);
- //起始点坐标
- float startX = (float) (-circleBounds.width()/2* Math.sin( 2* Math.PI/360*(progress - 90+270))+this.getLayoutParams().width/2); //计算时角度要换成弧度
- float startY = (float) (circleBounds.height()/2* Math.cos(2 * Math.PI / 360 * (progress - 90 + 270)) + this.getLayoutParams().height/2);
- //结束点坐标
- float endX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * t) + this.getLayoutParams().width / 2);
- float endY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * t) + this.getLayoutParams().height / 2);
- //计算两点间距离
- float tmpR = (float) Math.sqrt((endX-startX)*(endX-startX)+(endY-startY)*(endY-startY));
+ //结束度数
+ double t = (progress - 90 + barDegree + 270);
+ //起始点坐标
+ float startX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * (progress - 90 + 270)) + this.getLayoutParams().width / 2); //计算时角度要换成弧度
+ float startY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * (progress - 90 + 270)) + this.getLayoutParams().height / 2);
+ //结束点坐标
+ float endX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * t) + this.getLayoutParams().width / 2);
+ float endY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * t) + this.getLayoutParams().height / 2);
+ //计算两点间距离
+ float tmpR = (float) Math.sqrt((endX - startX) * (endX - startX) + (endY - startY) * (endY - startY));
// canvas.drawCircle(startX, startY, tmpR, barPaint); //画圆弧起始圆
// canvas.drawCircle(x, y, tmpR, barPaint); //画圆弧起始圆
- //确定圆心点
- double tmp = (progress - 90 + barDegree)+(360-barDegree)/2+270;
- float x2 = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * tmp) + this.getLayoutParams().width / 2);
- float y2 = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * tmp) + this.getLayoutParams().height / 2);
- canvas.drawCircle(x2, y2, tmpR, spinCirclePaint); //画圆
- }else{ //按长度
+ //确定圆心点
+ double tmp = (progress - 90 + barDegree) + (360 - barDegree) / 2 + 270;
+ float x2 = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * tmp) + this.getLayoutParams().width / 2);
+ float y2 = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * tmp) + this.getLayoutParams().height / 2);
+ canvas.drawCircle(x2, y2, tmpR, spinCirclePaint); //画圆
+ } else { //按长度
canvas.drawArc(circleBounds, progress - 90, barLength, false,
barPaint);
- //结束度数
- double t = (progress - 90+barLength + 270);
- //起始点坐标
- float startX = (float) (-circleBounds.width()/2* Math.sin( 2* Math.PI/360*(progress - 90+270))+this.getLayoutParams().width/2); //计算时角度要换成弧度
- float startY = (float) (circleBounds.height()/2* Math.cos(2 * Math.PI / 360 * (progress - 90 + 270)) + this.getLayoutParams().height/2);
- //结束点坐标
- float endX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * t) + this.getLayoutParams().width / 2);
- float endY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * t) + this.getLayoutParams().height / 2);
- //计算两点间距离
- float tmpR = (float) Math.sqrt((endX-startX)*(endX-startX)+(endY-startY)*(endY-startY));
+ //结束度数
+ double t = (progress - 90 + barLength + 270);
+ //起始点坐标
+ float startX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * (progress - 90 + 270)) + this.getLayoutParams().width / 2); //计算时角度要换成弧度
+ float startY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * (progress - 90 + 270)) + this.getLayoutParams().height / 2);
+ //结束点坐标
+ float endX = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * t) + this.getLayoutParams().width / 2);
+ float endY = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * t) + this.getLayoutParams().height / 2);
+ //计算两点间距离
+ float tmpR = (float) Math.sqrt((endX - startX) * (endX - startX) + (endY - startY) * (endY - startY));
// canvas.drawCircle(startX, startY, tmpR, barPaint); //画圆弧起始圆
// canvas.drawCircle(x, y, tmpR, barPaint); //画圆弧起始圆
- //确定圆心点
- double tmp = (progress - 90 + barLength)+(360-barLength)/2+270;
- float x2 = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * tmp) + this.getLayoutParams().width / 2);
- float y2 = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * tmp) + this.getLayoutParams().height / 2);
- canvas.drawCircle(x2, y2, tmpR, spinCirclePaint); //画圆
- }
- } else {
- canvas.drawArc(circleBounds, startDegree, progress, false, barPaint); // -90 从顶上开始
- double t = progress+startDegree+270;
- if(progress != 0) {
- canvas.drawCircle(startArcX, startArcY, arcR, barCirclePaint); //画圆弧起始圆
-
- float x = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * t) + this.getLayoutParams().width / 2);
- float y = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * t) + this.getLayoutParams().height / 2);
- canvas.drawCircle(x, y, arcR, barCirclePaint); //画圆弧结束圆
- }
- }
- //Draw the inner circle
- canvas.drawCircle((circleBounds.width()/2) + rimWidth + paddingLeft,
- (circleBounds.height()/2) + rimWidth + paddingTop,
- circleRadius,
- circlePaint);
- //Draw the text (attempts to center it horizontally and vertically)
- int offsetNum = 0;
- for(String s : splitText) {
- float offset = textPaint.measureText(s) / 2;
- canvas.drawText(s, this.getWidth() / 2 - offset,
- this.getHeight() / 2 + (textSize*(offsetNum))
- - ((splitText.length-1)*(textSize/2)), textPaint);
- offsetNum++;
- }
- }
-
- /**
- * Reset the count (in increment mode)
- */
- public void resetCount() {
- progress = 0;
- setText("0%");
- invalidate();
- }
-
- /**
- * Turn off spin mode
- */
- public void stopSpinning() {
- spinHandler.sendEmptyMessageDelayed(1,200);
- }
-
-
- /**
- * Puts the view on spin mode
- */
- public void spin() {
- isSpinning = true;
- spinHandler.sendEmptyMessage(0);
- }
-
- public boolean isSpinning(){
+ //确定圆心点
+ double tmp = (progress - 90 + barLength) + (360 - barLength) / 2 + 270;
+ float x2 = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * tmp) + this.getLayoutParams().width / 2);
+ float y2 = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * tmp) + this.getLayoutParams().height / 2);
+ canvas.drawCircle(x2, y2, tmpR, spinCirclePaint); //画圆
+ }
+ } else {
+ canvas.drawArc(circleBounds, startDegree, progress, false, barPaint); // -90 从顶上开始
+ double t = progress + startDegree + 270;
+ if (progress != 0) {
+ canvas.drawCircle(startArcX, startArcY, arcR, barCirclePaint); //画圆弧起始圆
+
+ float x = (float) (-circleBounds.width() / 2 * Math.sin(2 * Math.PI / 360 * t) + this.getLayoutParams().width / 2);
+ float y = (float) (circleBounds.height() / 2 * Math.cos(2 * Math.PI / 360 * t) + this.getLayoutParams().height / 2);
+ canvas.drawCircle(x, y, arcR, barCirclePaint); //画圆弧结束圆
+ }
+ }
+ //Draw the inner circle
+ canvas.drawCircle((circleBounds.width() / 2) + rimWidth + paddingLeft,
+ (circleBounds.height() / 2) + rimWidth + paddingTop,
+ circleRadius,
+ circlePaint);
+ //Draw the text (attempts to center it horizontally and vertically)
+ int offsetNum = 0;
+ for (String s : splitText) {
+ float offset = textPaint.measureText(s) / 2;
+ canvas.drawText(s, this.getWidth() / 2 - offset,
+ this.getHeight() / 2 + (textSize * (offsetNum))
+ - ((splitText.length - 1) * (textSize / 2)), textPaint);
+ offsetNum++;
+ }
+ }
+
+ /**
+ * Reset the count (in increment mode)
+ */
+ public void resetCount() {
+ progress = 0;
+ setText("0%");
+ invalidate();
+ }
+
+ /**
+ * Turn off spin mode
+ */
+ public void stopSpinning() {
+ spinHandler.sendEmptyMessageDelayed(1, 200);
+ }
+
+
+ /**
+ * Puts the view on spin mode
+ */
+ public void spin() {
+ isSpinning = true;
+ spinHandler.sendEmptyMessage(0);
+ }
+
+ public boolean isSpinning() {
return isSpinning;
}
- /**
- * Increment the progress by 1 (of 360)
- */
- public void incrementProgress() {
- isSpinning = false;
- progress++;
- setText(Math.round(((float)progress/360)*100) + "%");
- spinHandler.sendEmptyMessage(0);
- }
-
- /**
- * Set the progress to a specific value
- */
- public void setProgress(int i) {
- isSpinning = false;
- progress=i;
- spinHandler.sendEmptyMessage(0);
- }
-
- //----------------------------------
- //Getters + setters
- //----------------------------------
-
- /**
- * Set the text in the progress bar
- * Doesn't invalidate the view
- * @param text the text to show ('\n' constitutes a new line)
- */
- public void setText(String text) {
- this.text = text;
- splitText = this.text.split("\n");
- }
-
- public int getCircleRadius() {
- return circleRadius;
- }
-
- public void setCircleRadius(int circleRadius) {
- this.circleRadius = circleRadius;
- }
-
- public int getBarLength() {
- return barLength;
- }
-
- public void setBarLength(int barLength) {
- this.barLength = barLength;
- }
-
- public int getBarWidth() {
- return barWidth;
- }
-
- public void setBarWidth(int barWidth) {
- this.barWidth = barWidth;
- }
-
- public int getTextSize() {
- return textSize;
- }
-
- public void setTextSize(int textSize) {
- this.textSize = textSize;
- }
-
- public int getPaddingTop() {
- return paddingTop;
- }
-
- public void setPaddingTop(int paddingTop) {
- this.paddingTop = paddingTop;
- }
-
- public int getPaddingBottom() {
- return paddingBottom;
- }
-
- public void setPaddingBottom(int paddingBottom) {
- this.paddingBottom = paddingBottom;
- }
-
- public int getPaddingLeft() {
- return paddingLeft;
- }
-
- public void setPaddingLeft(int paddingLeft) {
- this.paddingLeft = paddingLeft;
- }
-
- public int getPaddingRight() {
- return paddingRight;
- }
-
- public void setPaddingRight(int paddingRight) {
- this.paddingRight = paddingRight;
- }
-
- public int getBarColor() {
- return barColor;
- }
-
- public void setBarColor(int barColor) {
- this.barColor = barColor;
- }
-
- public int getCircleColor() {
- return circleColor;
- }
-
- public void setCircleColor(int circleColor) {
- this.circleColor = circleColor;
- }
-
- public int getRimColor() {
- return rimColor;
- }
-
- public void setRimColor(int rimColor) {
- this.rimColor = rimColor;
- }
+ /**
+ * Increment the progress by 1 (of 360)
+ */
+ public void incrementProgress() {
+ isSpinning = false;
+ progress++;
+ setText(Math.round(((float) progress / 360) * 100) + "%");
+ spinHandler.sendEmptyMessage(0);
+ }
+
+ /**
+ * Set the progress to a specific value
+ */
+ public void setProgress(int i) {
+ isSpinning = false;
+ progress = i;
+ spinHandler.sendEmptyMessage(0);
+ }
+
+ //----------------------------------
+ //Getters + setters
+ //----------------------------------
+
+ /**
+ * Set the text in the progress bar
+ * Doesn't invalidate the view
+ *
+ * @param text the text to show ('\n' constitutes a new line)
+ */
+ public void setText(String text) {
+ this.text = text;
+ splitText = this.text.split("\n");
+ }
+
+ public int getCircleRadius() {
+ return circleRadius;
+ }
+
+ public void setCircleRadius(int circleRadius) {
+ this.circleRadius = circleRadius;
+ }
+
+ public int getBarLength() {
+ return barLength;
+ }
+
+ public void setBarLength(int barLength) {
+ this.barLength = barLength;
+ }
+
+ public int getBarWidth() {
+ return barWidth;
+ }
+
+ public void setBarWidth(int barWidth) {
+ this.barWidth = barWidth;
+ }
+
+ public int getTextSize() {
+ return textSize;
+ }
+
+ public void setTextSize(int textSize) {
+ this.textSize = textSize;
+ }
+
+ @Override
+ public int getPaddingTop() {
+ return paddingTop;
+ }
+
+ public void setPaddingTop(int paddingTop) {
+ this.paddingTop = paddingTop;
+ }
+
+ @Override
+ public int getPaddingBottom() {
+ return paddingBottom;
+ }
+
+ public void setPaddingBottom(int paddingBottom) {
+ this.paddingBottom = paddingBottom;
+ }
+
+ @Override
+ public int getPaddingLeft() {
+ return paddingLeft;
+ }
+
+ public void setPaddingLeft(int paddingLeft) {
+ this.paddingLeft = paddingLeft;
+ }
+
+ @Override
+ public int getPaddingRight() {
+ return paddingRight;
+ }
+
+ public void setPaddingRight(int paddingRight) {
+ this.paddingRight = paddingRight;
+ }
+
+ public int getBarColor() {
+ return barColor;
+ }
+
+ public void setBarColor(int barColor) {
+ this.barColor = barColor;
+ }
+
+ public int getCircleColor() {
+ return circleColor;
+ }
+
+ public void setCircleColor(int circleColor) {
+ this.circleColor = circleColor;
+ }
+
+ public int getRimColor() {
+ return rimColor;
+ }
+
+ public void setRimColor(int rimColor) {
+ this.rimColor = rimColor;
+ }
public int getSpinRimColor() {
return spinRimColor;
@@ -493,43 +497,43 @@ public void setSpinRimColor(int spinRimColor) {
this.spinRimColor = spinRimColor;
}
- public Shader getRimShader() {
- return rimPaint.getShader();
- }
-
- public void setRimShader(Shader shader) {
- this.rimPaint.setShader(shader);
- }
-
- public int getTextColor() {
- return textColor;
- }
-
- public void setTextColor(int textColor) {
- this.textColor = textColor;
- }
-
- public int getSpinSpeed() {
- return spinSpeed;
- }
-
- public void setSpinSpeed(int spinSpeed) {
- this.spinSpeed = spinSpeed;
- }
-
- public int getRimWidth() {
- return rimWidth;
- }
-
- public void setRimWidth(int rimWidth) {
- this.rimWidth = rimWidth;
- }
-
- public int getDelayMillis() {
- return delayMillis;
- }
-
- public void setDelayMillis(int delayMillis) {
- this.delayMillis = delayMillis;
- }
+ public Shader getRimShader() {
+ return rimPaint.getShader();
+ }
+
+ public void setRimShader(Shader shader) {
+ this.rimPaint.setShader(shader);
+ }
+
+ public int getTextColor() {
+ return textColor;
+ }
+
+ public void setTextColor(int textColor) {
+ this.textColor = textColor;
+ }
+
+ public int getSpinSpeed() {
+ return spinSpeed;
+ }
+
+ public void setSpinSpeed(int spinSpeed) {
+ this.spinSpeed = spinSpeed;
+ }
+
+ public int getRimWidth() {
+ return rimWidth;
+ }
+
+ public void setRimWidth(int rimWidth) {
+ this.rimWidth = rimWidth;
+ }
+
+ public int getDelayMillis() {
+ return delayMillis;
+ }
+
+ public void setDelayMillis(int delayMillis) {
+ this.delayMillis = delayMillis;
+ }
}
diff --git a/app/src/main/java/cn/darkal/networkdiagnosis/View/RecycleViewDivider.java b/app/src/main/java/cn/darkal/networkdiagnosis/View/RecycleViewDivider.java
index 61d4732..9ad08b8 100644
--- a/app/src/main/java/cn/darkal/networkdiagnosis/View/RecycleViewDivider.java
+++ b/app/src/main/java/cn/darkal/networkdiagnosis/View/RecycleViewDivider.java
@@ -14,14 +14,11 @@
*/
public class RecycleViewDivider extends RecyclerView.ItemDecoration {
+ public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
+ public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
private static final int[] ATTRS = new int[]{
android.R.attr.listDivider
};
-
- public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
-
- public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
-
private Drawable mDivider;
private int mOrientation;
diff --git a/app/src/main/java/com/google/zxing/QrCodeScanActivity.java b/app/src/main/java/com/google/zxing/QrCodeScanActivity.java
index c02d3da..b6fabdb 100644
--- a/app/src/main/java/com/google/zxing/QrCodeScanActivity.java
+++ b/app/src/main/java/com/google/zxing/QrCodeScanActivity.java
@@ -1,4 +1,3 @@
-
package com.google.zxing;
import android.app.Activity;
@@ -45,6 +44,18 @@
*/
public class QrCodeScanActivity extends Activity implements SurfaceHolder.Callback {
+ private static final float BEEP_VOLUME = 1.00f;
+ private static final int REQUEST_CODE_GALLERY = 0x0708;
+ private static final long VIBRATE_DURATION = 200L;
+ /**
+ * When the beep has finished playing, rewind to queue up another one.
+ */
+ private final OnCompletionListener beepListener = new OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer mediaPlayer) {
+ mediaPlayer.seekTo(0);
+ }
+ };
private CameraManager cameraManager;
private CaptureActivityHandler handler;
private ViewfinderView viewfinderView;
@@ -54,9 +65,7 @@ public class QrCodeScanActivity extends Activity implements SurfaceHolder.Callba
private InactivityTimer inactivityTimer;
private MediaPlayer mediaPlayer;
private boolean playBeep;
- private static final float BEEP_VOLUME = 1.00f;
private boolean vibrate;
- private static final int REQUEST_CODE_GALLERY = 0x0708;
public CameraManager getCameraManager() {
return cameraManager;
@@ -274,8 +283,6 @@ private void initBeepSound() {
}
}
- private static final long VIBRATE_DURATION = 200L;
-
private void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
@@ -286,15 +293,6 @@ private void playBeepSoundAndVibrate() {
}
}
- /**
- * When the beep has finished playing, rewind to queue up another one.
- */
- private final OnCompletionListener beepListener = new OnCompletionListener() {
- public void onCompletion(MediaPlayer mediaPlayer) {
- mediaPlayer.seekTo(0);
- }
- };
-
public void onGalleryClick(View view) {
// 设定action和miniType
Intent intent = new Intent();
@@ -349,6 +347,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
break;
+ default:
+ break;
}
}
}
diff --git a/app/src/main/java/com/google/zxing/camera/AutoFocusManager.java b/app/src/main/java/com/google/zxing/camera/AutoFocusManager.java
index f42adbb..34ec94a 100644
--- a/app/src/main/java/com/google/zxing/camera/AutoFocusManager.java
+++ b/app/src/main/java/com/google/zxing/camera/AutoFocusManager.java
@@ -40,10 +40,10 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO);
}
- private boolean stopped;
- private boolean focusing;
private final boolean useAutoFocus;
private final Camera camera;
+ private boolean stopped;
+ private boolean focusing;
private AsyncTask, ?, ?> outstandingTask;
AutoFocusManager(Context context, Camera camera) {
diff --git a/app/src/main/java/com/google/zxing/camera/CameraManager.java b/app/src/main/java/com/google/zxing/camera/CameraManager.java
index fb227c9..4ba94d1 100644
--- a/app/src/main/java/com/google/zxing/camera/CameraManager.java
+++ b/app/src/main/java/com/google/zxing/camera/CameraManager.java
@@ -48,6 +48,11 @@ public final class CameraManager {
private final Context context;
private final CameraConfigurationManager configManager;
+ /**
+ * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
+ * clear the handler so it will only receive one message.
+ */
+ private final PreviewCallback previewCallback;
private Camera camera;
private AutoFocusManager autoFocusManager;
private Rect framingRect;
@@ -57,11 +62,6 @@ public final class CameraManager {
private int requestedCameraId = -1;
private int requestedFramingRectWidth;
private int requestedFramingRectHeight;
- /**
- * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
- * clear the handler so it will only receive one message.
- */
- private final PreviewCallback previewCallback;
public CameraManager(Context context) {
this.context = context;
@@ -69,6 +69,17 @@ public CameraManager(Context context) {
previewCallback = new PreviewCallback(configManager);
}
+ private static int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) {
+ int dim = 5 * resolution / 8; // Target 5/8 of each dimension
+ if (dim < hardMin) {
+ return hardMin;
+ }
+ if (dim > hardMax) {
+ return hardMax;
+ }
+ return dim;
+ }
+
/**
* Opens the camera driver and initializes the hardware parameters.
*
@@ -172,8 +183,6 @@ public synchronized void stopPreview() {
}
/**
- *
- *
* @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
*/
public synchronized void setTorch(boolean newSetting) {
@@ -240,17 +249,6 @@ public synchronized Rect getFramingRect() {
return framingRect;
}
- private static int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) {
- int dim = 5 * resolution / 8; // Target 5/8 of each dimension
- if (dim < hardMin) {
- return hardMin;
- }
- if (dim > hardMax) {
- return hardMax;
- }
- return dim;
- }
-
/**
* Like {@link #getFramingRect} but coordinates are in terms of the preview frame,
* not UI / screen.
diff --git a/app/src/main/java/com/google/zxing/decoding/CaptureActivityHandler.java b/app/src/main/java/com/google/zxing/decoding/CaptureActivityHandler.java
index 66fbe7c..0b77e3c 100644
--- a/app/src/main/java/com/google/zxing/decoding/CaptureActivityHandler.java
+++ b/app/src/main/java/com/google/zxing/decoding/CaptureActivityHandler.java
@@ -53,14 +53,8 @@ public final class CaptureActivityHandler extends Handler {
private final QrCodeScanActivity activity;
private final DecodeThread decodeThread;
- private State state;
private final CameraManager cameraManager;
-
- private enum State {
- PREVIEW,
- SUCCESS,
- DONE
- }
+ private State state;
public CaptureActivityHandler(QrCodeScanActivity activity,
Collection decodeFormats,
@@ -160,4 +154,10 @@ private void restartPreviewAndDecode() {
}
}
+ private enum State {
+ PREVIEW,
+ SUCCESS,
+ DONE
+ }
+
}
diff --git a/app/src/main/java/com/google/zxing/decoding/DecodeFormatManager.java b/app/src/main/java/com/google/zxing/decoding/DecodeFormatManager.java
index 20f8989..48d6c80 100644
--- a/app/src/main/java/com/google/zxing/decoding/DecodeFormatManager.java
+++ b/app/src/main/java/com/google/zxing/decoding/DecodeFormatManager.java
@@ -31,15 +31,15 @@
final class DecodeFormatManager {
- private static final Pattern COMMA_PATTERN = Pattern.compile(",");
-
static final Set PRODUCT_FORMATS;
static final Set INDUSTRIAL_FORMATS;
- private static final Set ONE_D_FORMATS;
static final Set QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
static final Set DATA_MATRIX_FORMATS = EnumSet.of(BarcodeFormat.DATA_MATRIX);
static final Set AZTEC_FORMATS = EnumSet.of(BarcodeFormat.AZTEC);
static final Set PDF417_FORMATS = EnumSet.of(BarcodeFormat.PDF_417);
+ private static final Pattern COMMA_PATTERN = Pattern.compile(",");
+ private static final Set ONE_D_FORMATS;
+ private static final Map> FORMATS_FOR_MODE;
static {
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A,
@@ -57,8 +57,6 @@ final class DecodeFormatManager {
ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS);
}
- private static final Map> FORMATS_FOR_MODE;
-
static {
FORMATS_FOR_MODE = new HashMap>();
FORMATS_FOR_MODE.put(Intents.Scan.ONE_D_MODE, ONE_D_FORMATS);
diff --git a/app/src/main/java/com/google/zxing/decoding/DecodeHandler.java b/app/src/main/java/com/google/zxing/decoding/DecodeHandler.java
index 5735af3..eb0f1d6 100644
--- a/app/src/main/java/com/google/zxing/decoding/DecodeHandler.java
+++ b/app/src/main/java/com/google/zxing/decoding/DecodeHandler.java
@@ -51,12 +51,23 @@ final class DecodeHandler extends Handler {
this.activity = activity;
}
+ private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
+ int[] pixels = source.renderThumbnail();
+ int width = source.getThumbnailWidth();
+ int height = source.getThumbnailHeight();
+ Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
+ bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
+ bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
+ }
+
@Override
public void handleMessage(Message message) {
if (!running) {
return;
}
- if (message.what == R.id.decode) {
+ if (message.what == R.id.decode) {
decode((byte[]) message.obj, message.arg1, message.arg2);
} else if (message.what == R.id.quit) {
running = false;
@@ -119,15 +130,4 @@ private void decode(byte[] data, int width, int height) {
}
}
- private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
- int[] pixels = source.renderThumbnail();
- int width = source.getThumbnailWidth();
- int height = source.getThumbnailHeight();
- Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
- bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
- bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
- }
-
}
diff --git a/app/src/main/java/com/google/zxing/decoding/DecodeThread.java b/app/src/main/java/com/google/zxing/decoding/DecodeThread.java
index 420358a..a2386bb 100644
--- a/app/src/main/java/com/google/zxing/decoding/DecodeThread.java
+++ b/app/src/main/java/com/google/zxing/decoding/DecodeThread.java
@@ -45,8 +45,8 @@ final class DecodeThread extends Thread {
private final QrCodeScanActivity activity;
private final Map hints;
- private Handler handler;
private final CountDownLatch handlerInitLatch;
+ private Handler handler;
DecodeThread(QrCodeScanActivity activity,
Collection decodeFormats,
diff --git a/app/src/main/java/com/google/zxing/view/ViewfinderView.java b/app/src/main/java/com/google/zxing/view/ViewfinderView.java
index 03a9c8c..f173b27 100644
--- a/app/src/main/java/com/google/zxing/view/ViewfinderView.java
+++ b/app/src/main/java/com/google/zxing/view/ViewfinderView.java
@@ -51,12 +51,6 @@ public final class ViewfinderView extends View {
private static final int CURRENT_POINT_OPACITY = 0xA0;
private static final int MAX_RESULT_POINTS = 20;
private static final int POINT_SIZE = 6;
-
- /**
- * 四个绿色边角对应的长度
- */
- private int ScreenRate;
-
/**
* 四个绿色边角对应的宽度
*/
@@ -65,21 +59,14 @@ public final class ViewfinderView extends View {
* 扫描框中的中间线的宽度
*/
private static final float MIDDLE_LINE_WIDTH = 3;
-
/**
* 扫描框中的中间线的与扫描框左右的间隙
*/
private static final float MIDDLE_LINE_PADDING = 5;
-
/**
* 中间那条线每次刷新移动的距离
*/
private static final float SPEEN_DISTANCE = 4;
-
- /**
- * 手机的屏幕密度
- */
- private static float density;
/**
* 字体大小
*/
@@ -88,30 +75,32 @@ public final class ViewfinderView extends View {
* 字体距离扫描框下面的距离
*/
private static final int TEXT_PADDING_TOP = 24;
-
+ /**
+ * 手机的屏幕密度
+ */
+ private static float density;
+ private final int maskColor;
+ private final int resultColor;
+ private final int resultPointColor;
+ boolean isFirst;
+ /**
+ * 四个绿色边角对应的长度
+ */
+ private int ScreenRate;
/**
* 画笔对象的引用
*/
private Paint paint;
-
/**
* 中间滑动线的最顶端位置
*/
private float slideTop;
-
/**
* 中间滑动线的最底端位置
*/
private int slideBottom;
-
-
- boolean isFirst;
-
private CameraManager cameraManager;
private Bitmap resultBitmap;
- private final int maskColor;
- private final int resultColor;
- private final int resultPointColor;
private int scannerAlpha;
private List possibleResultPoints;
private List lastPossibleResultPoints;
@@ -153,7 +142,7 @@ public void onDraw(Canvas canvas) {
}
//初始化中间线滑动的最上边和最下边
- if(!isFirst){
+ if (!isFirst) {
isFirst = true;
slideTop = frame.top;
slideBottom = frame.bottom;
@@ -183,11 +172,11 @@ public void onDraw(Canvas canvas) {
canvas.drawRect(frame.left - 1, frame.top - 1, frame.left - 1 + ScreenRate, frame.top - 1 + CORNER_WIDTH, paint);
canvas.drawRect(frame.left - 1, frame.top - 1, frame.left - 1 + CORNER_WIDTH, frame.top - 1 + ScreenRate, paint);
canvas.drawRect(frame.right + 2 - ScreenRate, frame.top - 1, frame.right + 2, frame.top - 1 + CORNER_WIDTH, paint);
- canvas.drawRect(frame.right+2 - CORNER_WIDTH, frame.top-1, frame.right+2, frame.top-1 + ScreenRate, paint);
- canvas.drawRect(frame.left-1, frame.bottom+2 - CORNER_WIDTH, frame.left-1 + ScreenRate, frame.bottom+2, paint);
- canvas.drawRect(frame.left-1, frame.bottom+2 - ScreenRate, frame.left-1 + CORNER_WIDTH, frame.bottom+2, paint);
- canvas.drawRect(frame.right+2 - ScreenRate, frame.bottom+2 - CORNER_WIDTH, frame.right+2, frame.bottom+2, paint);
- canvas.drawRect(frame.right+2 - CORNER_WIDTH, frame.bottom+2 - ScreenRate, frame.right+2, frame.bottom+2, paint);
+ canvas.drawRect(frame.right + 2 - CORNER_WIDTH, frame.top - 1, frame.right + 2, frame.top - 1 + ScreenRate, paint);
+ canvas.drawRect(frame.left - 1, frame.bottom + 2 - CORNER_WIDTH, frame.left - 1 + ScreenRate, frame.bottom + 2, paint);
+ canvas.drawRect(frame.left - 1, frame.bottom + 2 - ScreenRate, frame.left - 1 + CORNER_WIDTH, frame.bottom + 2, paint);
+ canvas.drawRect(frame.right + 2 - ScreenRate, frame.bottom + 2 - CORNER_WIDTH, frame.right + 2, frame.bottom + 2, paint);
+ canvas.drawRect(frame.right + 2 - CORNER_WIDTH, frame.bottom + 2 - ScreenRate, frame.right + 2, frame.bottom + 2, paint);
paint.setColor(Color.WHITE);
canvas.drawLine(frame.left, frame.bottom, frame.left, frame.top, paint);
@@ -197,15 +186,15 @@ public void onDraw(Canvas canvas) {
//绘制中间的线,每次刷新界面,中间的线往下移动SPEEN_DISTANCE
slideTop += SPEEN_DISTANCE;
- if(slideTop >= frame.bottom) {
+ if (slideTop >= frame.bottom) {
slideTop = frame.top;
}
Shader shaderNew = new LinearGradient(frame.left + MIDDLE_LINE_PADDING, 0, frame.right - MIDDLE_LINE_PADDING, 0,
- new int[] { 0x00FFFFFF, 0xFF00FF00, 0xFF00FF00, 0x00FFFFFF }, null, Shader.TileMode.MIRROR);
+ new int[]{0x00FFFFFF, 0xFF00FF00, 0xFF00FF00, 0x00FFFFFF}, null, Shader.TileMode.MIRROR);
Shader shaderOld = paint.getShader();
paint.setShader(shaderNew);
- canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - MIDDLE_LINE_WIDTH/2,
- frame.right - MIDDLE_LINE_PADDING, slideTop + MIDDLE_LINE_WIDTH/2, paint);
+ canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - MIDDLE_LINE_WIDTH / 2,
+ frame.right - MIDDLE_LINE_PADDING, slideTop + MIDDLE_LINE_WIDTH / 2, paint);
paint.setShader(shaderOld);
@@ -215,7 +204,7 @@ public void onDraw(Canvas canvas) {
paint.setTextAlign(Paint.Align.CENTER);
paint.setTypeface(Typeface.create("system", Typeface.NORMAL));
//paint.setTypeface(Typeface.SANS_SERIF);
- canvas.drawText(getResources().getString(R.string.scan_text), frame.centerX(), (float) (frame.bottom + (float)TEXT_PADDING_TOP * density), paint);
+ canvas.drawText(getResources().getString(R.string.scan_text), frame.centerX(), (float) (frame.bottom + (float) TEXT_PADDING_TOP * density), paint);
float scaleX = frame.width() / (float) previewFrame.width();
float scaleY = frame.height() / (float) previewFrame.height();
diff --git a/app/src/main/java/com/netease/LDNetDiagnoService/AbstractLDNetAsyncTaskEx.java b/app/src/main/java/com/netease/LDNetDiagnoService/AbstractLDNetAsyncTaskEx.java
new file mode 100644
index 0000000..04695df
--- /dev/null
+++ b/app/src/main/java/com/netease/LDNetDiagnoService/AbstractLDNetAsyncTaskEx.java
@@ -0,0 +1,222 @@
+package com.netease.LDNetDiagnoService;
+
+import android.os.AsyncTask;
+import android.os.Handler;
+import android.os.Message;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * @author liujie
+ *
+ *
+ * The most part is copied for {@link AsyncTask}.
+ *
+ * What's we do here is to control the executor and the core
+ *
+ * number of thread parallely.
+ *
+ *
+ * Since Starting with HONEYCOMB, tasks are executed on a single thread
+ *
+ * to avoid common application errors caused by parallel execution.
+ */
+
+public abstract class AbstractLDNetAsyncTaskEx {
+ private static final int MESSAGE_POST_RESULT = 0x1;
+ private static final int MESSAGE_POST_PROGRESS = 0x2;
+ private static final int MESSAGE_POST_CANCEL = 0x3;
+ private static final LDNetInternalHandler sHandler = new LDNetInternalHandler();
+ private final AbstractLDNetWorkerRunnable mWorker;
+ private final FutureTask mFuture;
+ private volatile Status mStatus = Status.PENDING;
+
+ public AbstractLDNetAsyncTaskEx() {
+ mWorker = new AbstractLDNetWorkerRunnable() {
+ @Override
+ public Result call() throws Exception {
+ // Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+ return doInBackground(mParams);
+ }
+ };
+
+ mFuture = new FutureTask(mWorker) {
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void done() {
+ Message message;
+ Result result = null;
+
+ try {
+ result = get();
+ } catch (InterruptedException e) {
+ android.util.Log.w(this.getClass().getSimpleName(), e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(
+ "An error occured while executing doInBackground()",
+ e.getCause());
+ } catch (CancellationException e) {
+ message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
+ new LDNetAsyncTaskResult(AbstractLDNetAsyncTaskEx.this,
+ (Result[]) null));
+ message.sendToTarget();
+ return;
+ } catch (Throwable t) {
+// throw new RuntimeException(
+// "An error occured while executing "
+// + "doInBackground()", t);
+ }
+
+ message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
+ new LDNetAsyncTaskResult(AbstractLDNetAsyncTaskEx.this, result));
+ message.sendToTarget();
+ }
+ };
+ }
+
+ // protected Hashtable mTaskCache = new
+ // Hashtable();
+
+ public final Status getStatus() {
+ return mStatus;
+ }
+
+ protected abstract Result doInBackground(Params... params);
+
+ /**
+ * 后台线程准备运行阶段
+ */
+ protected void onPreExecute() {
+ }
+
+ /**
+ * 后台运行阶段,当前运行已经结束
+ *
+ * @param result
+ */
+ protected void onPostExecute(Result result) {
+ }
+
+ /**
+ * 进度更新阶段
+ *
+ * @param values
+ */
+ protected void onProgressUpdate(Progress... values) {
+ }
+
+ /**
+ * 取消运行
+ */
+ protected void onCancelled() {
+ }
+
+ public final boolean isCancelled() {
+ return mFuture.isCancelled();
+ }
+
+ public final boolean cancel(boolean mayInterruptIfRunning) {
+ return mFuture.cancel(mayInterruptIfRunning);
+ }
+
+ /**
+ * 初始化运行阶段
+ *
+ * @param params
+ * @return
+ */
+ @SuppressWarnings("incomplete-switch")
+ public final AbstractLDNetAsyncTaskEx execute(Params... params) {
+ if (mStatus != Status.PENDING) {
+ switch (mStatus) {
+ case RUNNING:
+ throw new IllegalStateException("Cannot execute task:"
+ + " the task is already running.");
+ case FINISHED:
+ throw new IllegalStateException("Cannot execute task:"
+ + " the task has already been executed "
+ + "(a task can be executed only once)");
+ default:
+ break;
+ }
+ }
+
+ mStatus = Status.RUNNING;
+
+ onPreExecute();
+
+ mWorker.mParams = params;
+ ThreadPoolExecutor sExecutor = getThreadPoolExecutor();
+ // ThreadPoolExecutor sExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,
+ // MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sWorkQueue,
+ // sThreadFactory);
+ if (sExecutor != null) {
+ sExecutor.execute(mFuture);
+ return this;
+ } else {
+ return null;
+ }
+ }
+
+ protected abstract ThreadPoolExecutor getThreadPoolExecutor();
+
+ protected final void publishProgress(Progress... values) {
+ sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
+ new LDNetAsyncTaskResult