Browse Source

更新黑馬2

tags/old_version_1
fyf 1 year ago
parent
commit
f1327ebf32
19 changed files with 1130 additions and 0 deletions
  1. +234
    -0
      app/src/main/java/com/bonait/bnframework/common/myprogress/CircleProgress.java
  2. +222
    -0
      app/src/main/java/com/bonait/bnframework/common/myprogress/CustomSeekbar.java
  3. +125
    -0
      app/src/main/java/com/bonait/bnframework/common/myprogress/HorizonalProgress.java
  4. +190
    -0
      app/src/main/java/com/bonait/bnframework/common/myprogress/MyProgress.java
  5. +6
    -0
      app/src/main/java/com/bonait/bnframework/common/myprogress/ResponseOnTouch.java
  6. +316
    -0
      app/src/main/java/com/bonait/bnframework/common/myprogress/SlideSelectView.java
  7. +3
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java
  8. +2
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java
  9. BIN
     
  10. BIN
     
  11. BIN
     
  12. BIN
     
  13. BIN
     
  14. +12
    -0
      app/src/main/res/layout/fragment_home1.xml
  15. +1
    -0
      app/src/main/res/layout/fragment_system_cs_fltl.xml
  16. BIN
     
  17. BIN
     
  18. +13
    -0
      app/src/main/res/values/attrs.xml
  19. +6
    -0
      app/src/main/res/values/dimens.xml

+ 234
- 0
app/src/main/java/com/bonait/bnframework/common/myprogress/CircleProgress.java View File

@@ -0,0 +1,234 @@
package com.bonait.bnframework.common.myprogress;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.DecelerateInterpolator;

import com.bonait.bnframework.R;

/**
* Description 圆形装逼进度条
* Author: tu
* Date: 2016-08-19
* Time: 14:33
*/
public class CircleProgress extends View{

private float textSize = getResources().getDimension(R.dimen.text_size_14);
private float dotX, dotY;//圆点xy
private int viewWidth;//view的宽度
private int viewHigth;//view的高度
private Paint mPaint,mPaintArc;//画笔 212 62 96
private int colorBg = Color.argb(255,54,68,76);//背景圆颜色
private int colorWhite = Color.argb(255,255,255,255);//文字颜色
private int colorBlack = Color.argb(255,34,49,59);//第二刻度颜色
private int colorBlue = Color.argb(255,94,248,249);//刻度颜色
private int pandding = 10;
private RectF rectF;
private float radius = 10;//半径
private float scaleLineLenth = 3;//刻度线长
private int scaleAngle = 10;//刻度间隔
private int scaleWidth = 5;//刻度宽度
private int curProgress = 0;//0 ~ 100进度 当前进度
private int oldProgress = 0;

public void setColorBlue(int colorBlue) {
this.colorBlue = colorBlue;
}

public void setTextSize(float textSize) {
this.textSize = textSize;
}

public int getCurProgress() {
return curProgress;
}

public void setCurProgress(int curProgress) {
this.curProgress = curProgress;
invalidate();
}

public CircleProgress(Context context) {
this(context,null);
}

public CircleProgress(Context context, AttributeSet attrs) {
this(context, attrs,0);
}

public CircleProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}

/**
* 初始化画笔
*/
private void init(Context context) {

//初始化坐标画笔
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);//
mPaintArc = new Paint(Paint.ANTI_ALIAS_FLAG);//
mPaint.setColor(colorWhite);
mPaintArc.setColor(colorBg);
mPaint.setAntiAlias(true);
mPaintArc.setAntiAlias(true);
mPaint.setTextSize(15);
mPaint.setStyle(Paint.Style.STROKE);//空心
//当前进度

}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int height;
int width;

//宽度测量
if (widthMode == MeasureSpec.EXACTLY) {
width = widthSize;
} else {
width = getMeasuredWidth();
}
dotX = width / 2;
viewWidth = width;
//高度测量
if (heightMode == MeasureSpec.EXACTLY) {
height = heightSize;
} else {
height = getMeasuredHeight();
}
viewHigth = height;
dotY = height / 2;
radius = dotX-(getPaddingLeft() + getPaddingRight())/2;
scaleLineLenth = (int)(radius/2.5);
//
rectF = new RectF(dotX - radius, dotY - radius, dotX + radius, dotY + radius);
setMeasuredDimension(width, height);
}
private void drawProgress(Canvas canvas){
if(mPaintArc == null){
return;
}
//圆
mPaintArc.setStyle(Paint.Style.FILL);
canvas.drawCircle(dotX, dotY, radius, mPaintArc);
//中心进度值
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);//实心
mPaint.setTextAlign(Paint.Align.CENTER);
mPaint.setStrokeWidth(1);
mPaint.setTextSize(textSize);
mPaint.setColor(colorWhite);
canvas.drawText(curProgress + "%",dotX,
dotY+getResources().getDimension(R.dimen.text_size_14)/2
,mPaint);
//黑色刻度 12点钟方向为起始点(-90°),正时针方法绘制
for (int angle = -90; angle <= 270; angle += scaleAngle){
float xY[] = caculCoordinate(angle);
if(xY != null) {
mPaint.setStrokeWidth(scaleWidth);
mPaint.setColor(colorBlack);
canvas.drawLine(xY[0], xY[1],xY[2],xY[3], mPaint);
}
}
//进度算法
//360 除与 scaleAngle(进度间隔10) = 36; 再拿进度总数100换算当前进度
//算出当前进度占几个刻度
int curProgressCount = curProgress * (360/scaleAngle) /100;
int angleStart = -90;
for (int count = 0; count < curProgressCount;count ++){
float xY[] = caculCoordinate(angleStart);
if(xY != null) {
mPaint.setStrokeWidth(scaleWidth);
mPaint.setColor(colorBlue);
canvas.drawLine(xY[0], xY[1],xY[2],xY[3], mPaint);
}
angleStart += scaleAngle;
}

}

/**
* 根据圆心角 计算圆周上的坐标
* @param angle
* @return xY[0] startX; xY[1] startY; xY[2] endX; xY[3] endY;
*/
private float[] caculCoordinate(int angle){
//angle >180 angle = angle -180
float xY[] = new float[4];
//角度处理
int tempAngle = Math.abs(angle);
float tempScaleLineLenth = scaleLineLenth;

if(270 > tempAngle && tempAngle >= 180) {
tempAngle = tempAngle - 180;
xY[0] = dotX - getCoordinateX(tempAngle,radius);
xY[1] = dotY - getCoordinateY(tempAngle,radius);

xY[2] = xY[0] + getCoordinateX(tempAngle,tempScaleLineLenth);
xY[3] = xY[1] + getCoordinateY(tempAngle,tempScaleLineLenth);
}else if(180 > tempAngle && tempAngle > 90){
tempAngle = 180 - tempAngle;
xY[0] = dotX - getCoordinateX(tempAngle,radius);
xY[1] = dotY + getCoordinateY(tempAngle,radius);

xY[2] = xY[0] + getCoordinateX(tempAngle,tempScaleLineLenth);
xY[3] = xY[1] - getCoordinateY(tempAngle,tempScaleLineLenth);
}else if(90 >= tempAngle && tempAngle >= 0){
xY[0] = dotX + getCoordinateX(tempAngle,radius);
xY[1] = angle < 0 ? dotY - getCoordinateY(tempAngle,radius) : dotY + getCoordinateY(tempAngle,radius);

xY[2] = xY[0] - getCoordinateX(tempAngle,tempScaleLineLenth);
xY[3] = angle < 0 ? xY[1] + getCoordinateY(tempAngle,tempScaleLineLenth) : xY[1] - getCoordinateY(tempAngle,tempScaleLineLenth);
}

return xY;
}


/**
* 获取圆周上y值相对值
* @param tempAngle
* @param radius 算开始坐标是传半径,算结束坐标时传刻度线的长度
* @return
*/
private float getCoordinateY(int tempAngle,float radius){

//利用正弦函数算出y坐标
return (float) (Math.sin(tempAngle*Math.PI/180)*(radius - 15)); //10 是离圆弧的距离
}
/**
* 获取圆周上X值相对值
* @param tempAngle
* @return
*/
private float getCoordinateX(int tempAngle,float radius){

//利用余弦函数算出y坐标
return (float) (Math.cos(tempAngle*Math.PI/180)*(radius - 15));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawProgress(canvas);
}
public void setProgress(int progress){
if (progress < 0 || progress > 100)
return;
ObjectAnimator o = ObjectAnimator.ofInt(this, "curProgress", oldProgress, progress);
o.setDuration(1000);
o.setInterpolator(new DecelerateInterpolator());
o.start();
oldProgress = progress;
}
}

+ 222
- 0
app/src/main/java/com/bonait/bnframework/common/myprogress/CustomSeekbar.java View File

@@ -0,0 +1,222 @@
package com.bonait.bnframework.common.myprogress;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;

import com.bonait.bnframework.R;

import java.util.ArrayList;


//ArrayList<String> volume_sections = new ArrayList<String>();
// volume_sections.add("小");
// volume_sections.add("标准");
// volume_sections.add("大");
// volume_sections.add("特大");
// progressBar.initData(volume_sections);
// progressBar.setProgress(0); //设置默认级别
// progressBar.setResponseOnTouch(this);//activity实现了下面的接口ResponseOnTouch,每次touch会回调onTouchResponse
//@Override
//public void onTouchResponse(int volume) {
// }
public class CustomSeekbar extends View {
private final String TAG = "CustomSeekbar";
private int width;
private int height;
private int downX = 0;
private int downY = 0;
private int upX = 0;
private int upY = 0;
private int moveX = 0;
private int moveY = 0;
private float scale = 0;
private int perWidth = 0;
private Paint mPaint;
private Paint mTextPaint;
private Paint buttonPaint;
private Canvas canvas;
private Bitmap bitmap;
private Bitmap thumb;
private Bitmap spot;
private Bitmap spot_on;
private int hotarea = 150;//点击的热区
private int cur_sections = 2;
private ResponseOnTouch responseOnTouch;
private int bitMapHeight = 30;//第一个点的起始位置起始,图片的长宽是76,所以取一半的距离
private int textMove = 60;//字与下方点的距离,因为字体字体是40px,再加上10的间隔
private int[] colors = new int[]{0xffdf5600, 0x33000000};//进度条的橙色,进度条的灰色,字体的灰色
private int textSize;
private int circleRadius;
private ArrayList<String> section_title;

public CustomSeekbar(Context context) {
super(context);
}

public CustomSeekbar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public CustomSeekbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
cur_sections = 0;
bitmap = Bitmap.createBitmap(900, 1100, Bitmap.Config.ARGB_8888);
canvas = new Canvas();
canvas.setBitmap(bitmap);
thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large); //这个是滑动图标
spot = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe); //这个是未滑动到的界点的图标
spot_on = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe); //这个是已经滑动过的界点的图标
bitMapHeight = thumb.getHeight() / 2; //这里影响点中的图标的位置 这个正好 不用改
textMove = bitMapHeight + 50; //xqx 这里参数大小要改,不是固定的,具体看项目效果
textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()); //文字大小,第二个参数个人设置
circleRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics());
mPaint = new Paint(Paint.DITHER_FLAG);
mPaint.setAntiAlias(true);//锯齿不显示
mPaint.setStrokeWidth(5);
mTextPaint = new Paint(Paint.DITHER_FLAG);
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(textSize);
mTextPaint.setColor(0xffb5b5b4);
buttonPaint = new Paint(Paint.DITHER_FLAG);
buttonPaint.setAntiAlias(true);

}

/**
* 实例化后调用,设置bar的段数和文字
*/
public void initData(ArrayList<String> section) {
if (section != null) {
section_title = section;
} else {
//如果没有传入正确的分类级别数据,则默认使用“低”“中”“高”
String[] str = new String[]{"低", "中", "高"};
section_title = new ArrayList<String>();
for (int i = 0; i < str.length; i++) {
section_title.add(str[i]);
}
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);

width = widthSize;
float scaleX = widthSize / 1080;
float scaleY = heightSize / 1920;
scale = Math.max(scaleX, scaleY);
//控件的高度
height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 62, getResources().getDisplayMetrics());
setMeasuredDimension(width, height);
width = width - bitMapHeight / 2;
perWidth = (width - section_title.size() * spot.getWidth() - thumb.getWidth() / 2) / (section_title.size() - 1);
hotarea = perWidth / 2;
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setColor(Color.WHITE);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAlpha(0);
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), mPaint);
canvas.drawBitmap(bitmap, 0, 0, null);
mPaint.setAlpha(255);
mPaint.setColor(colors[1]);
canvas.drawLine(bitMapHeight, height * 2 / 3, width - bitMapHeight - spot_on.getWidth() / 2 + 10, height * 2 / 3, mPaint);
int section = 0;
while (section < section_title.size()) {
if (section < cur_sections) {
mPaint.setColor(colors[0]);
canvas.drawLine(thumb.getWidth() / 2 + section * perWidth + (section + 1) * spot_on.getWidth(), height * 2 / 3,
thumb.getWidth() / 2 + section * perWidth + (section + 1) * spot_on.getWidth() + perWidth, height * 2 / 3, mPaint);
canvas.drawBitmap(spot_on, thumb.getWidth() / 2 + section * perWidth + section * spot_on.getWidth(), height * 2 / 3 - spot_on.getHeight() / 2, mPaint);
} else {
mPaint.setAlpha(255);
if (section == section_title.size() - 1) {
canvas.drawBitmap(spot, width - spot_on.getWidth() - bitMapHeight / 2, height * 2 / 3 - spot.getHeight() / 2, mPaint);
} else {
canvas.drawBitmap(spot, thumb.getWidth() / 2 + section * perWidth + section * spot_on.getWidth(), height * 2 / 3 - spot.getHeight() / 2, mPaint);
}
}

if (section == section_title.size() - 1) {
canvas.drawText(section_title.get(section), width - spot_on.getWidth() - bitMapHeight / 4 - textSize / 2 - 38, height * 2 / 3 - textMove, mTextPaint);
} else {
if (section_title.get(section).length() == 2)
canvas.drawText(section_title.get(section), thumb.getWidth() / 2 + section * perWidth + section * spot_on.getWidth() - 40, height * 2 / 3 - textMove, mTextPaint);
else
canvas.drawText(section_title.get(section), thumb.getWidth() / 2 + section * perWidth + section * spot_on.getWidth() - 20, height * 2 / 3 - textMove, mTextPaint);
}
section++;
}
if (cur_sections == section_title.size() - 1) {
canvas.drawBitmap(thumb, width - spot_on.getWidth() - bitMapHeight / 2 - thumb.getWidth() / 2,
height * 2 / 3 - bitMapHeight, buttonPaint);
} else {
canvas.drawBitmap(thumb, thumb.getWidth() / 2 + cur_sections * perWidth + cur_sections * spot_on.getWidth() - thumb.getWidth() / 4,
height * 2 / 3 - bitMapHeight, buttonPaint);
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large);
downX = (int) event.getX();
downY = (int) event.getY();
responseTouch(downX, downY);
break;
case MotionEvent.ACTION_MOVE:
thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large);
moveX = (int) event.getX();
moveY = (int) event.getY();
responseTouch(moveX, moveY);
break;
case MotionEvent.ACTION_UP:
thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large);
upX = (int) event.getX();
upY = (int) event.getY();
responseTouch(upX, upY);
responseOnTouch.onTouchResponse(cur_sections);
break;
}
return true;
}

private void responseTouch(int x, int y) {
if (x <= width - bitMapHeight / 2) {
cur_sections = (x + perWidth / 3) / perWidth;
} else {
cur_sections = section_title.size() - 1;
}
invalidate();
}

//设置监听
public void setResponseOnTouch(ResponseOnTouch response) {
//注意 ,这里是接口,实现你到达界点的监听事件,因为这个自定义控件继承的View而不是SeekBar,所以只能使用接口实现监听
responseOnTouch = response;
}


//设置进度
public void setProgress(int progress) {
cur_sections = progress;
invalidate();
}
}

+ 125
- 0
app/src/main/java/com/bonait/bnframework/common/myprogress/HorizonalProgress.java View File

@@ -0,0 +1,125 @@
package com.bonait.bnframework.common.myprogress;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.DecelerateInterpolator;

/**
* Description 酷炫水平进度条
* Author: tu
* Date: 2016-08-22
* Time: 14:59
*/
public class HorizonalProgress extends View {
private int viewWidth;//view的宽度
private int viewHigth;//view的高度
private Paint mPaint;//画笔 212 62 96
private int colorSecondProgress = Color.argb(255,229,237,245);//背景圆颜色,进度条背景色
private int colorProgress = Color.argb(255,19,146,255);//背景圆颜色,一级进度条颜色
private int progressHeight = 30;//进度条的高度
private RectF rectF = new RectF();
private int curProgress = 0; //必须小于等于100 大于0
private int oldProgress = 0;
public void setColorSecondProgress(int colorSecondProgress) {
this.colorSecondProgress = colorSecondProgress;
}
public void setColorProgress(int colorProgress) {
this.colorProgress = colorProgress;
}
public void setProgressHeight(int progressHeight) {
this.progressHeight = progressHeight;
}
public void setCurProgress(int curProgress) {
this.curProgress = curProgress;
invalidate();
}
public HorizonalProgress(Context context) {
this(context,null);
}

public HorizonalProgress(Context context, AttributeSet attrs) {
this(context, attrs,0);
}

public HorizonalProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
//初始化坐标画笔
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);//
mPaint.setColor(colorSecondProgress);
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);//空心
curProgress = 0;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int height;
int width;

//宽度测量
if (widthMode == MeasureSpec.EXACTLY) {
width = widthSize;
} else {
width = getMeasuredWidth();
}
viewWidth = width;
//高度测量
if (heightMode == MeasureSpec.EXACTLY) {
height = heightSize;
} else {
height = getMeasuredHeight();
}
//进度条的高度根据
viewHigth = progressHeight;

setMeasuredDimension(width, viewHigth);
}

/**
* 绘制进度
* @param canvas
*/
private void drawProgress(Canvas canvas){
rectF.left = 0;
rectF.right = viewWidth;
rectF.top = 0;
rectF.bottom = viewHigth;
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(colorSecondProgress);
//灰色背景
canvas.drawRoundRect(rectF,viewHigth/2,viewHigth/2,mPaint);

//进度
mPaint.setColor(colorProgress);
rectF.right = curProgress * viewWidth / 100;
canvas.drawRoundRect(rectF,viewHigth/2,viewHigth/2,mPaint);

}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawProgress(canvas);
}
public void setProgress(int progress){
if (progress < 0 || progress > 100)
return;
ObjectAnimator o = ObjectAnimator.ofInt(this, "curProgress", oldProgress, progress);
o.setDuration(1000);
o.setInterpolator(new DecelerateInterpolator());
o.start();
oldProgress = progress;
}
}

+ 190
- 0
app/src/main/java/com/bonait/bnframework/common/myprogress/MyProgress.java View File

@@ -0,0 +1,190 @@
package com.bonait.bnframework.common.myprogress;

import android.R.dimen;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.bonait.bnframework.R;

/**
* Description 组合装逼进度
* Author: tu
* Date: 2016-08-22
* Time: 15:36
*/
public class MyProgress extends RelativeLayout {
private Context context;
private float textProgressSize;//圆形进度条中间文字
private float horizonalProgressHeight;//横条高度
private float circleProgressRadus;//圆形半径
private int colorProgress;//进度条颜色,圆盘刻度颜色
private int colorSecondProgress;//进度条背景颜色
private boolean flagPaint = true;//绘图标志
int newProgress;
private CircleProgress mCircleProgress;
private HorizonalProgress mHorizonalProgress;
//private int touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();//最小滑动阀值

public MyProgress(Context context) {
this(context,null);
}

public MyProgress(Context context, AttributeSet attrs) {
this(context, attrs,0);
}

public MyProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
init(attrs);
ViewTreeObserver vto = getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(flagPaint){
flagPaint = false;
initHorizonalProgress();
}else{
}
}
});
}

private void init(AttributeSet attrs){
flagPaint = true;
//获取自定义xml属性
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.myMagicProgress);
int n = typedArray.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = typedArray.getIndex(i);
switch (attr) {
case R.styleable.myMagicProgress_circleProgressRadus:
// Log.e("tag", "typedArray.getDimension(attr, 0)="+typedArray.getDimension(attr, 0)+",typedArray.getDimension(i, 0)="+typedArray.getDimension(i, 0));
circleProgressRadus = typedArray.getDimension(attr, 0);
break;
case R.styleable.myMagicProgress_horizonalProgressHeight:
horizonalProgressHeight = typedArray.getDimension(attr, 0);
break;
case R.styleable.myMagicProgress_textProgressSize:
textProgressSize = typedArray.getDimension(attr, 0);
break;
case R.styleable.myMagicProgress_colorProgress:
colorProgress = typedArray.getColor(attr, Color.GRAY);
break;
case R.styleable.myMagicProgress_colorSecondProgress:
colorSecondProgress = typedArray.getColor(attr, Color.GRAY);
break;
default:
break;
}
}
//横向进度条稍后设置参数,需要圆形进度条绘图完成,根据宽度绘制左右边距
mHorizonalProgress = new HorizonalProgress(getContext());
mHorizonalProgress.setProgressHeight((int) horizonalProgressHeight);
mHorizonalProgress.setColorSecondProgress(colorSecondProgress);
mHorizonalProgress.setColorProgress(colorProgress);
int radus = (int) circleProgressRadus;
mCircleProgress = new CircleProgress(getContext());
mCircleProgress.setTextSize(textProgressSize);
mCircleProgress.setColorBlue(colorProgress);
LayoutParams cp_lp = new LayoutParams(radus,radus);
cp_lp.addRule(RelativeLayout.CENTER_VERTICAL);
mCircleProgress.setLayoutParams(cp_lp);

addView(mHorizonalProgress);
addView(mCircleProgress);

initView();
}
private float mDownX;
private void initView(){
mCircleProgress.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mDownX = event.getX();
// Log.d("Tag",event.getX() + ":" + event.getRawX());
break;
case MotionEvent.ACTION_MOVE:
// Log.d("Tag",event.getX() + ":" + event.getRawX());
float disX = event.getX() - mDownX;
float llX = mCircleProgress.getX() + disX;
// Log.e("tag", "disX="+disX+",llX="+llX+",mHorizonalProgress.getWidth()="+mHorizonalProgress.getWidth());
//校正边界,反正滑块划出
llX = checkoundary(llX);
mCircleProgress.setX(llX);
//计算进度条百分比
newProgress = getProgress(llX);
//更新进度条
updateProgress(newProgress);
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
return true;
}
});
}
/**
* 绘制横向进度条
*/
public void initHorizonalProgress(){
// Log.e("tag", "mCircleProgress.getWidth()="+mCircleProgress.getWidth());
//设置边距,左右空出滑块半径的距离
LayoutParams hp_lp = new LayoutParams(LayoutParams.MATCH_PARENT,(int) horizonalProgressHeight);
hp_lp.leftMargin = mCircleProgress.getWidth()/2;
hp_lp.rightMargin = mCircleProgress.getWidth()/2;
hp_lp.addRule(RelativeLayout.CENTER_VERTICAL);
mHorizonalProgress.setLayoutParams(hp_lp);
}
/**
* 校正边界
* @return
*/
public float checkoundary(float llX){
if(llX<0){
llX = 0f;
}else if(llX>mHorizonalProgress.getWidth()){
llX = mHorizonalProgress.getWidth();
}
return llX;
}
/**
* 换算百分比
*/
public int getProgress(float llX){
return (int) ((llX/mHorizonalProgress.getWidth())*100);
}
/**
* 更新进度
* @param newProgress
*/
public void updateProgress(int newProgress){
// Log.e("tag", "newProgress="+newProgress);
mCircleProgress.setProgress(newProgress);
mHorizonalProgress.setProgress(newProgress);
}
}

+ 6
- 0
app/src/main/java/com/bonait/bnframework/common/myprogress/ResponseOnTouch.java View File

@@ -0,0 +1,6 @@
package com.bonait.bnframework.common.myprogress;


public interface ResponseOnTouch {
void onTouchResponse(int volume);
}

+ 316
- 0
app/src/main/java/com/bonait/bnframework/common/myprogress/SlideSelectView.java View File

@@ -0,0 +1,316 @@
package com.bonait.bnframework.common.myprogress;

import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateInterpolator;

import com.bonait.bnframework.R;

/**
* Created by xuxinghai on 09/05/16.
* 设置字体大小专用
*/
public class SlideSelectView extends View {

//小圆半径
private static final float RADIU_SMALL = 15;
//大圆半径
private static final float RADIU_BIG = 22;
private static final float RADIU_BIGS = 23;
//线的高度
private static float HEIGHT_LINE = 2;
//线距离两头的边距
// private static float MARGEN_LINE = RADIU_BIG * 3;
private static float MARGEN_LINE = 33;
//小圆的数量
private int countOfSmallCircle;
//小圆的横坐标
private float circlesX[];
private Context mContext;
//画笔
private Paint mPaint;
//文字画笔
private TextPaint mTextPaint;
//控件高度
private float mHeight;
//控件宽度
private float mWidth;
//大圆的横坐标
private float bigCircleX;
//是否是手指跟随模式
private boolean isFollowMode;
//手指按下的x坐标
private float startX;
//文字大小
private float textSize;
//文字宽度
private float textWidth;
//当前大球距离最近的位置
private int currentPosition;
//小圆之间的间距
private float distanceX;
//利率文字
private String[] text4Rates;
//依附效果实现
private ValueAnimator valueAnimator;
//用于纪录松手后的x坐标
private float currentPositionX;

private onSelectListener selectListener;


public SlideSelectView(Context context) {
this(context, null);
}

public SlideSelectView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlideSelectView);
countOfSmallCircle = a.getInt(R.styleable.SlideSelectView_circleCount, 5);
textSize = a.getInt(R.styleable.SlideSelectView_sstextSize, (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
a.recycle();

mPaint = new Paint();
mPaint.setColor(Color.GRAY);
mPaint.setAntiAlias(true);

textSize = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics());

mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mTextPaint.setColor(Color.GRAY);
mTextPaint.setTextSize(textSize);

currentPosition = countOfSmallCircle / 2;

}

/**
* 设置显示文本
*
* @param strings
*/
public void setString(String[] strings) {
text4Rates = strings;
textWidth = mTextPaint.measureText(text4Rates[0]);

if (countOfSmallCircle != text4Rates.length) {
throw new IllegalArgumentException("the count of small circle must be equal to the " +
"text array length !");
}

}

public int getCurrentPosition() {
return currentPosition;
}

public void setCurrentPosition(int currentPosition) {
this.currentPosition = currentPosition;
}

/**
* 设置监听器
*
* @param listener
*/
public void setOnSelectListener(onSelectListener listener) {
selectListener = listener;
}


@Override
protected void onDraw(Canvas canvas) {
//画中间的线
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(HEIGHT_LINE);
canvas.drawLine(MARGEN_LINE, mHeight / 2, mWidth - MARGEN_LINE, mHeight / 2,
mPaint);


mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeWidth(HEIGHT_LINE);
for (int i = 0; i < countOfSmallCircle; i++) {
canvas.drawLine(circlesX[i], mHeight / 2,circlesX[i], mHeight / 2-12,
mPaint);
}


// //画小圆
// mPaint.setStyle(Paint.Style.FILL);
// for (int i = 0; i < countOfSmallCircle; i++) {
// canvas.drawCircle(circlesX[i], mHeight / 2, RADIU_SMALL, mPaint);
// }


//画文字
canvas.drawText(text4Rates[currentPosition], circlesX[currentPosition] - textWidth / 2,
(mHeight / 2) - RADIU_BIG -
RADIU_SMALL,
mTextPaint);

//画大圆的默认位置
mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeWidth(2);
mPaint.setColor(Color.WHITE);
canvas.drawCircle(bigCircleX, mHeight / 2, RADIU_BIG, mPaint);

//画大圆的默认位置
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(2);
mPaint.setColor(Color.GRAY);
canvas.drawCircle(bigCircleX, mHeight / 2, RADIU_BIGS, mPaint);

}

@Override
public boolean onTouchEvent(MotionEvent event) {

switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:

startX = event.getX();
//如果手指按下的x坐标与大圆的x坐标的距离小于半径,则是follow模式
if (Math.abs(startX - bigCircleX) <= RADIU_BIG) {
isFollowMode = true;
} else {
isFollowMode = false;
}

break;
case MotionEvent.ACTION_MOVE:

//如果是follow模式,则大圆跟随手指移动
if (isFollowMode) {
//防止滑出边界
if (event.getX() >= MARGEN_LINE && event.getX() <= (mWidth - MARGEN_LINE)) {
//Log.d("TAG", "event.getX()=" + event.getX() + "__mWidth=" + mWidth);
bigCircleX = event.getX();
int position = (int) ((event.getX() - MARGEN_LINE) / (distanceX / 2));
//更新当前位置
currentPosition = (position + 1) / 2;
invalidate();
}

}

break;
case MotionEvent.ACTION_UP:

if (isFollowMode) {
float endX = event.getX();
//当前位置距离最近的小白点的距离
float currentDistance = endX - MARGEN_LINE - currentPosition * distanceX;

if ((currentPosition == 0 && currentDistance < 0) || (currentPosition == (text4Rates.length - 1) && currentDistance > 0)) {

if (null != selectListener) {
selectListener.onSelect(currentPosition);
}
return true;
}

currentPositionX = bigCircleX;

valueAnimator = ValueAnimator.ofFloat(currentDistance);
valueAnimator.setInterpolator(new AccelerateInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float slideDistance = (float) animation.getAnimatedValue();
bigCircleX = currentPositionX - slideDistance;
invalidate();
}
});

valueAnimator.setDuration(100);
valueAnimator.start();
if (null != selectListener) {
selectListener.onSelect(currentPosition);
}
}

break;
}


return true;
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mHeight = h;
mWidth = w;
//计算每个小圆点的x坐标
circlesX = new float[countOfSmallCircle];
distanceX = (mWidth - MARGEN_LINE * 2) / (countOfSmallCircle - 1);
for (int i = 0; i < countOfSmallCircle; i++) {
circlesX[i] = i * distanceX + MARGEN_LINE;
}

bigCircleX = circlesX[currentPosition];
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int screenSize[] = getScreenSize((Activity) mContext);

int resultWidth;
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);

if (widthMode == MeasureSpec.EXACTLY) {
resultWidth = widthSize;
} else {
resultWidth = screenSize[0];

if (widthMode == MeasureSpec.AT_MOST) {
resultWidth = Math.min(widthSize, screenSize[0]);
}
}

int resultHeight;
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);

if (heightMode == MeasureSpec.EXACTLY) {
resultHeight = heightSize;
} else {
resultHeight = (int) (RADIU_BIG * 6);

if (heightMode == MeasureSpec.AT_MOST) {
resultHeight = Math.min(heightSize, resultHeight);
}
}

setMeasuredDimension(resultWidth, resultHeight);

}

private static int[] getScreenSize(Activity activity) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
return new int[]{metrics.widthPixels, metrics.heightPixels};
}

public interface onSelectListener {
public void onSelect(int index);
}

}

+ 3
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java View File

@@ -11,12 +11,15 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
import com.bonait.bnframework.common.db.mode.BPA_SILOS;
import com.bonait.bnframework.common.myprogress.CustomSeekbar;
import com.bonait.bnframework.common.myprogress.ResponseOnTouch;
import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc_control;
import com.bonait.bnframework.modules.home.fragment.mode.fragment_silos_cl;
import com.orhanobut.logger.Logger;


+ 2
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java View File

@@ -40,6 +40,8 @@ public class SystemCsMonitorFragment extends BaseFragment {

@BindView(R.id.fanzhuandianji)
TextView fanzhuandianji;//工序子集


private Context context;

monitor_adapter adapter;


BIN
View File


BIN
View File


BIN
View File


BIN
View File


BIN
View File


+ 12
- 0
app/src/main/res/layout/fragment_home1.xml View File

@@ -207,7 +207,19 @@ android:orientation="vertical">
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<com.bonait.bnframework.common.myprogress.MyProgress
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:circleProgressRadus="50dp"
app:horizonalProgressHeight="10dp"
app:textProgressSize="10sp"
app:colorProgress="#fd9112"
app:colorSecondProgress="#1592ff"
/>


<SeekBar android:id="@+id/jb_dw"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_marginRight="@dimen/dp_10"
android:layout_height="wrap_content"


+ 1
- 0
app/src/main/res/layout/fragment_system_cs_fltl.xml View File

@@ -10,6 +10,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/main_background">

<ScrollView
android:layout_marginTop="20dp"
android:layout_weight="1"


BIN
View File


BIN
View File


+ 13
- 0
app/src/main/res/values/attrs.xml View File

@@ -8,4 +8,17 @@
<attr name="imagesrc_ks" format="reference" />
<attr name="imagesrc_tz" format="reference" />
</declare-styleable>

<declare-styleable name="myMagicProgress">
<attr name="circleProgressRadus" format="dimension"/>
<attr name="horizonalProgressHeight" format="dimension"/>
<attr name="textProgressSize" format="dimension"/>
<attr name="colorProgress" format="reference|color"/>
<attr name="colorSecondProgress" format="reference|color"/>
</declare-styleable>

<declare-styleable name="SlideSelectView">
<attr name="circleCount" format="integer"></attr>
<attr name="sstextSize" format="integer"></attr>
</declare-styleable>
</resources>

+ 6
- 0
app/src/main/res/values/dimens.xml View File

@@ -44,4 +44,10 @@
<dimen name="textSize">14dp</dimen>
<dimen name="textTitleSize">16sp</dimen>
<dimen name="TitleSize">18sp</dimen>

<dimen name="text_size_14">14sp</dimen>
<dimen name="text_size_12">12sp</dimen>
<dimen name="text_size_10">10sp</dimen>
<dimen name="text_size_16">16sp</dimen>
<dimen name="radus_dp">60dp</dimen>
</resources>

Loading…
Cancel
Save