正在查看: 自健身 v3.3.4 应用的 WeightActivity3.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 自健身 v3.3.4 应用的 WeightActivity3.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mu.gymtrain.Activity.MainPackage;
import android.app.Dialog;
import android.bluetooth.BluetoothGatt;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.constraintlayout.widget.Group;
import butterknife.BindView;
import butterknife.OnClick;
import com.blankj.utilcode.util.LogUtils;
import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleGattCallback;
import com.clj.fastble.callback.BleNotifyCallback;
import com.clj.fastble.callback.BleScanCallback;
import com.clj.fastble.data.BleDevice;
import com.clj.fastble.exception.BleException;
import com.clj.fastble.scan.BleScanRuleConfig;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.LargeValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import com.google.gson.Gson;
import com.makeramen.roundedimageview.RoundedDrawable;
import com.mu.gymtrain.Activity.PersonPackage.PersonalInfoActivity;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Base.BaseModel;
import com.mu.gymtrain.Bean.UserInfoBean;
import com.mu.gymtrain.Bean.WeightBean;
import com.mu.gymtrain.Bean.WeightStandardBean;
import com.mu.gymtrain.Dialog.DialogUtils;
import com.mu.gymtrain.Dialog.WeightDialogHolder;
import com.mu.gymtrain.Http.CreatMap;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.Http.ResponseFunc;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.ToastUtil;
import com.mu.gymtrain.Utils.ToastUtils;
import com.mu.gymtrain.Utils.ViewUtils;
import com.mu.gymtrain.Utils.WindowUtils;
import com.mu.gymtrain.Widget.WeightStandardView;
import com.mu.gymtrain.view.CircleProgress;
import com.tencent.connect.common.Constants;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import kotlin.UByte;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class WeightActivity3 extends BaseActivity {
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
private int age;
private BarChart barChart;
private double bodyfat;
private int count;
private double currentWeight;
private double dataWeight;
private CountDownTimer downTimer;
private Group group;
private Group groupStart;
private double height;
private boolean isSendData;
@BindView(R.id.lineChartWeight)
LineChart lineChart;
@BindView(R.id.lineChartSF)
LineChart lineChartSF;
private LineChart lineChartShare;
@BindView(R.id.lineChartTZ)
LineChart lineChartTZ;
private Dialog mDialog;
private Dialog mNoInfoDialog;
WeightDialogHolder mWeightDialog;
private String mac;
private float minRightValue;
private float minTimeValue;
private double moisture;
private YAxis rightAxis;
private Dialog shareDialog;
@BindView(R.id.shuifen_ly)
WeightStandardView shuifen_ly;
private TextView title3;
@BindView(R.id.title_left)
ImageView titleLeft;
@BindView(R.id.title_middle)
TextView titleMiddle;
@BindView(R.id.title_righttext)
TextView titleRight;
@BindView(R.id.tizhil_ly)
WeightStandardView tizhil_ly;
private TextView tvTime;
private TextView tvWeight;
private TextView tvWeightChange;
@BindView(R.id.activity_weight_date)
TextView tv_date;
@BindView(R.id.weight_shuifen_contrast)
TextView tv_shuifen;
@BindView(R.id.weight_tizhi_contrast)
TextView tv_tizhi;
@BindView(R.id.activity_weight)
TextView tv_weight;
private TextView tving;
private String userName;
private double weight;
@BindView(R.id.weight_ly)
WeightStandardView weight_ly;
@BindView(R.id.weight_number)
TextView weight_number;
@BindView(R.id.activity_weight_standard)
TextView weight_standard;
@BindView(R.id.activity_weight_contrast)
TextView xiangdui_weight;
int randomint = 30;
private String str = "";
private boolean isLast = false;
private double[] datas = new double[5];
private boolean is_getuserinfo = false;
private List<WeightStandardBean.Mode> weights = new ArrayList();
private List<WeightStandardBean.Mode> bodyfats = new ArrayList();
private List<WeightStandardBean.Mode> moistures = new ArrayList();
double num = 50.0d;
public int getContentLayout() {
return R.layout.activity_weight;
}
public void parseData(byte[] data, final boolean isLast) {
this.isLast = isLast;
double[] dArr = this.datas;
dArr[0] = ((data[11] & UByte.MAX_VALUE) + ((data[12] & UByte.MAX_VALUE) << 8)) / 10.0f;
double d = (data[9] & UByte.MAX_VALUE) + ((data[10] & UByte.MAX_VALUE) << 8);
Double.isNaN(d);
dArr[1] = d / 10.0d;
double d2 = (data[13] & UByte.MAX_VALUE) + ((data[14] & UByte.MAX_VALUE) << 8);
Double.isNaN(d2);
dArr[2] = d2 / 10.0d;
dArr[0] = new BigDecimal(this.datas[0]).setScale(1, 4).doubleValue();
this.datas[1] = new BigDecimal(this.datas[1]).setScale(1, 4).doubleValue();
this.datas[2] = new BigDecimal(this.datas[2]).setScale(1, 4).doubleValue();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!isLast) {
WeightActivity3.this.groupStart.setVisibility(8);
WeightActivity3.this.tving.setVisibility(0);
WeightActivity3.this.title3.setVisibility(0);
return;
}
WeightActivity3.this.group.setVisibility(0);
WeightActivity3.this.title3.setVisibility(0);
WeightActivity3.this.groupStart.setVisibility(8);
WeightActivity3.this.tving.setVisibility(8);
WeightActivity3 weightActivity3 = WeightActivity3.this;
weightActivity3.dataWeight = weightActivity3.datas[0];
WeightActivity3.this.tvWeight.setText(WeightActivity3.this.datas[0] + "");
WeightActivity3.this.downTimer.cancel();
WeightActivity3.this.downTimer.start();
if (WeightActivity3.this.currentWeight > WeightActivity3.this.datas[0]) {
double d3 = WeightActivity3.this.currentWeight - WeightActivity3.this.datas[0];
DecimalFormat decimalFormat = new DecimalFormat("0.00");
WeightActivity3.this.tvWeightChange.setText("您的体重-" + decimalFormat.format(d3) + "公斤");
return;
}
if (WeightActivity3.this.datas[0] <= WeightActivity3.this.currentWeight) {
if (WeightActivity3.this.datas[0] == WeightActivity3.this.currentWeight) {
WeightActivity3.this.tvWeightChange.setText("您的体重无变化");
return;
}
return;
}
double d4 = WeightActivity3.this.datas[0] - WeightActivity3.this.currentWeight;
DecimalFormat decimalFormat2 = new DecimalFormat("0.00");
WeightActivity3.this.tvWeightChange.setText("您的体重+" + decimalFormat2.format(d4) + "公斤");
}
});
}
private void setDatas(double[] datas) {
WeightDialogHolder weightDialogHolder = this.mWeightDialog;
if (weightDialogHolder != null) {
weightDialogHolder.tvWeight.setText(datas[0] + "");
}
}
public void initData() {
this.downTimer = new CountDownTimer(10000L, 1000L) {
@Override
public void onTick(long millisUntilFinished) {
WeightActivity3.this.tvTime.setText((millisUntilFinished / 1000) + "s");
}
@Override
public void onFinish() {
if (WeightActivity3.this.mDialog == null || WeightActivity3.this.group.getVisibility() != 0) {
return;
}
WeightActivity3.this.mDialog.dismiss();
}
};
initShareDialog();
}
private void initBarChart(BarLineChartBase barChart) {
barChart.getDescription().setEnabled(false);
barChart.setTouchEnabled(false);
barChart.setDragDecelerationFrictionCoef(0.9f);
barChart.setDragEnabled(true);
barChart.setScaleEnabled(false);
barChart.setDrawGridBackground(false);
barChart.setHighlightPerDragEnabled(true);
barChart.setNoDataText("");
barChart.setNoDataTextColor(getResources().getColor(R.color.orange));
barChart.setPinchZoom(false);
barChart.animateY(300);
barChart.getLegend().setEnabled(false);
XAxis xAxis = barChart.getXAxis();
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setDrawLabels(false);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
YAxis axisLeft = barChart.getAxisLeft();
axisLeft.setDrawGridLines(false);
axisLeft.setDrawZeroLine(false);
axisLeft.setDrawLabels(false);
axisLeft.setGranularityEnabled(false);
axisLeft.setEnabled(false);
YAxis axisRight = barChart.getAxisRight();
axisRight.setDrawGridLines(false);
axisRight.setDrawZeroLine(false);
axisRight.setDrawLabels(false);
axisRight.setGranularityEnabled(false);
axisRight.setEnabled(false);
}
private void initShareDialog() {
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_weight_share_layout, (ViewGroup) null, false);
this.barChart = (BarChart) inflate.findViewById(R.id.barChart);
this.lineChartShare = (LineChart) inflate.findViewById(R.id.lineChart);
CircleProgress circleProgress = (CircleProgress) inflate.findViewById(R.id.sportTime);
CircleProgress circleProgress2 = (CircleProgress) inflate.findViewById(R.id.weight);
CircleProgress circleProgress3 = (CircleProgress) inflate.findViewById(R.id.tizhi);
circleProgress.setColor(getResources().getColor(R.color.progress_lvse), getResources().getColor(R.color.progress_lvse), getResources().getColor(R.color.progress_lvse), getResources().getColor(R.color.progress_lvse_shen));
circleProgress2.setColor(getResources().getColor(R.color.progress_qian_lan), getResources().getColor(R.color.progress_qian_lan), getResources().getColor(R.color.progress_qian_lan), getResources().getColor(R.color.progress_lvse_shen));
circleProgress3.setColor(getResources().getColor(R.color.progress_shenlan), getResources().getColor(R.color.progress_shenlan), getResources().getColor(R.color.progress_shenlan), getResources().getColor(R.color.progress_shenlan_shen));
circleProgress.setProgress(30.0f);
circleProgress2.setProgress(60.0f);
circleProgress3.setProgress(50.0f);
initBarChart(this.barChart);
initBarChart(this.lineChartShare);
this.shareDialog = DialogUtils.createDialog(this, inflate);
}
private void setLineChartShare(ArrayList<Float> dataListTiZhi) {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < dataListTiZhi.size(); i++) {
arrayList.add(new Entry(i, dataListTiZhi.get(i).floatValue()));
}
LineDataSet lineDataSet = new LineDataSet(arrayList, "DataSet 1");
lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
lineDataSet.setColor(Color.parseColor("#8059EAB9"));
lineDataSet.setCircleColor(Color.parseColor("#3359EAB9"));
lineDataSet.setCircleHoleColor(Color.parseColor("#CC59EAB9"));
lineDataSet.setLineWidth(2.0f);
lineDataSet.setCircleRadius(6.0f);
lineDataSet.setCircleHoleRadius(3.0f);
lineDataSet.setDrawCircleHole(true);
LineData lineData = new LineData(lineDataSet);
lineData.setDrawValues(false);
this.lineChartShare.setData(lineData);
}
private void setBarChartData(ArrayList<Float> dataListTime, ArrayList<Float> dataListWeight) {
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
for (int i = 0; i < dataListTime.size(); i++) {
arrayList.add(new BarEntry(i, dataListTime.get(i).floatValue()));
}
for (int i2 = 0; i2 < dataListWeight.size(); i2++) {
arrayList2.add(new BarEntry(i2, dataListWeight.get(i2).floatValue()));
}
BarDataSet barDataSet = new BarDataSet(arrayList, "Company A");
barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
barDataSet.setGradientColor(Color.parseColor("#0006E8FF"), Color.parseColor("#8006E8FF"));
BarDataSet barDataSet2 = new BarDataSet(arrayList2, "Company B");
barDataSet2.setGradientColor(Color.parseColor("#004586FA"), Color.parseColor("#804586FA"));
barDataSet2.setAxisDependency(YAxis.AxisDependency.RIGHT);
BarData barData = new BarData(barDataSet, barDataSet2);
barData.setValueFormatter(new LargeValueFormatter());
barData.setDrawValues(false);
this.barChart.setData(barData);
if (arrayList.size() > arrayList2.size()) {
if (arrayList.size() < 5) {
this.barChart.getBarData().setBarWidth(0.1f);
} else {
this.barChart.getBarData().setBarWidth(0.3f);
}
} else if (arrayList2.size() < 5) {
this.barChart.getBarData().setBarWidth(0.1f);
} else {
this.barChart.getBarData().setBarWidth(0.3f);
}
this.barChart.groupBars(-0.4f, 0.28f, 0.05f);
this.barChart.invalidate();
}
protected void onStart() {
super.onStart();
getUserInfo();
getWeightStandard();
getWeight();
}
private void getWeightStandard() {
HttpHelper.getInstance().getRetrofitService(this).getUserWeightStandard(new CreatMap.Builder().build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(new ResponseFunc()).subscribe(new Subscriber<WeightStandardBean>() {
public void onCompleted() {
}
public void onError(Throwable e) {
ToastUtil.showShort((Context) WeightActivity3.this, (CharSequence) "获取标准数据失败!");
}
public void onNext(WeightStandardBean bean) {
LogUtils.i(new Object[]{"体重:" + new Gson().toJson(bean)});
WeightActivity3.this.parseWeightStandard(bean);
}
});
}
public void parseWeightStandard(WeightStandardBean bean) {
if (bean.weight != null) {
this.weights = bean.weight;
}
if (bean.bodyfat != null) {
this.bodyfats = bean.bodyfat;
}
if (bean.moisture != null) {
this.moistures = bean.moisture;
}
this.weight_ly.initView(this.weights);
this.tizhil_ly.initView(this.bodyfats);
this.shuifen_ly.initView(this.moistures);
for (WeightStandardBean.Mode mode : this.weights) {
if ("标准".equals(mode.display_name)) {
this.weight_standard.setText(new BigDecimal((mode.value_max + mode.value_min) / 2.0d).setScale(1, 4).doubleValue() + "kg");
}
}
setStandard();
}
private void getUserInfo() {
ViewUtils.showLoading(this, "加载中...");
HttpHelper.getInstance().getRetrofitService(this).getUserInfo(new CreatMap.Builder().build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(new ResponseFunc()).subscribe(new Subscriber<UserInfoBean>() {
public void onCompleted() {
}
public void onError(Throwable e) {
ViewUtils.hideLoading();
ToastUtil.showShort((Context) WeightActivity3.this, (CharSequence) "获取个人信息失败!");
}
public void onNext(UserInfoBean userInfoBean) {
ViewUtils.hideLoading();
WeightActivity3.this.is_getuserinfo = true;
WeightActivity3.this.height = userInfoBean.getHeight();
WeightActivity3.this.age = userInfoBean.getAge();
WeightActivity3.this.userName = userInfoBean.getUser_name();
}
});
}
public void initView() {
this.titleMiddle.setText("体质数据");
this.titleRight.setText("历史数据");
BleManager.getInstance().initScanRule(new BleScanRuleConfig.Builder().setDeviceName(true, new String[]{"Chipsea"}).setScanTimeOut(10000L).build());
}
private void initChart(LineChart chart, float minValue, float minTimeValue) {
chart.getDescription().setEnabled(false);
chart.setTouchEnabled(true);
chart.setDragDecelerationFrictionCoef(0.9f);
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
chart.setDrawGridBackground(false);
chart.setHighlightPerDragEnabled(true);
chart.setNoDataText("");
chart.setNoDataTextColor(getResources().getColor(R.color.orange));
chart.setPinchZoom(true);
chart.setExtraRightOffset(35.0f);
chart.setExtraLeftOffset(35.0f);
chart.animateY(300);
chart.getLegend().setEnabled(false);
XAxis xAxis = chart.getXAxis();
xAxis.setDrawGridLines(true);
xAxis.setDrawAxisLine(true);
xAxis.setDrawLabels(false);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setAxisLineWidth(1.0f);
YAxis axisLeft = chart.getAxisLeft();
axisLeft.setTextColor(ColorTemplate.getHoloBlue());
axisLeft.setAxisMinimum(minTimeValue);
axisLeft.setDrawZeroLine(false);
axisLeft.setDrawGridLines(true);
axisLeft.setDrawLabels(false);
axisLeft.setGranularityEnabled(true);
YAxis axisRight = chart.getAxisRight();
this.rightAxis = axisRight;
axisRight.setTextColor(-65536);
this.rightAxis.setAxisMinimum(minValue);
this.rightAxis.setDrawGridLines(false);
this.rightAxis.setDrawZeroLine(true);
this.rightAxis.setDrawLabels(false);
this.rightAxis.setGranularityEnabled(false);
this.rightAxis.setEnabled(false);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.imgClose:
case R.id.tvRemove:
CountDownTimer countDownTimer = this.downTimer;
if (countDownTimer != null) {
countDownTimer.cancel();
}
this.mDialog.dismiss();
break;
case R.id.tvInput:
this.mNoInfoDialog.dismiss();
startActivity(new Intent((Context) this, (Class<?>) PersonalInfoActivity.class));
break;
case R.id.tvSave:
CountDownTimer countDownTimer2 = this.downTimer;
if (countDownTimer2 != null) {
countDownTimer2.cancel();
}
if (this.isLast && this.datas[0] != Utils.DOUBLE_EPSILON) {
this.mDialog.dismiss();
subWeight();
break;
}
break;
}
}
@OnClick({R.id.title_left, R.id.title_righttext, R.id.activity_weight_measure})
public void onViewClicked(View view) {
int id = view.getId();
if (id != 2131296339) {
if (id == 2131297253) {
finish();
return;
} else {
if (id != 2131297257) {
return;
}
startActivity(new Intent((Context) this, (Class<?>) WeightHistoricalDatas.class));
return;
}
}
if (this.height == Utils.DOUBLE_EPSILON || this.age == 0 || TextUtils.isEmpty(this.userName)) {
noInfoDialog();
return;
}
this.dataWeight = Utils.DOUBLE_EPSILON;
showDialog();
openBlue();
}
private void openBlue() {
if (TextUtils.isEmpty(this.mac) || !BleManager.getInstance().isConnected(this.mac)) {
BleManager.getInstance().initScanRule(new BleScanRuleConfig.Builder().setDeviceName(true, new String[]{"Chipsea"}).setScanTimeOut(15000L).build());
BleManager.getInstance().scan(new BleScanCallback() {
public void onScanStarted(boolean success) {
LogUtils.i(new Object[]{"开始扫描"});
}
public void onScanning(BleDevice bleDevice) {
LogUtils.i(new Object[]{"onScanning"});
WeightActivity3.this.mac = bleDevice.getMac();
if (TextUtils.isEmpty(WeightActivity3.this.mac)) {
return;
}
BleManager.getInstance().cancelScan();
WeightActivity3 weightActivity3 = WeightActivity3.this;
weightActivity3.connectBlue(weightActivity3.mac);
}
public void onScanFinished(List<BleDevice> scanResultList) {
LogUtils.i(new Object[]{"扫描的设备数量:" + scanResultList.size()});
}
});
}
}
public void connectBlue(String mac) {
BleManager.getInstance().connect(mac, new BleGattCallback() {
public void onStartConnect() {
LogUtils.i(new Object[]{"开始连接"});
}
public void onConnectFail(BleDevice bleDevice, BleException exception) {
LogUtils.i(new Object[]{"onConnectFail: " + exception.getDescription()});
}
public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
WeightActivity3.this.notif(bleDevice);
}
public void onDisConnected(boolean isActiveDisConnected, BleDevice bleDevice, BluetoothGatt gatt, int status) {
LogUtils.i(new Object[]{"onDisConnected: " + isActiveDisConnected});
ToastUtils.show(WeightActivity3.this, "蓝牙已断开");
}
});
}
public void notif(BleDevice bleDevice) {
BleManager.getInstance().notify(bleDevice, "0000181b-0000-1000-8000-00805f9b34fb", "00002a9c-0000-1000-8000-00805f9b34fb", new BleNotifyCallback() {
public void onNotifySuccess() {
LogUtils.i(new Object[]{"打开通知操作成功"});
}
public void onNotifyFailure(BleException exception) {
LogUtils.i(new Object[]{"打开通知操作失败 " + exception.getDescription()});
}
public void onCharacteristicChanged(byte[] data) {
if (new BigDecimal(((data[11] & UByte.MAX_VALUE) + ((data[12] & UByte.MAX_VALUE) << 8)) / 10.0f).setScale(1, 4).doubleValue() != WeightActivity3.this.dataWeight) {
WeightActivity3.this.parseData(data, true);
}
}
});
}
public void noInfoDialog() {
View inflate = View.inflate(this, R.layout.dialog_weight_no_info_layout, null);
this.mNoInfoDialog = DialogUtils.createDialog(this, inflate);
inflate.findViewById(R.id.tvInput).setOnClickListener(this);
this.mNoInfoDialog.setCanceledOnTouchOutside(true);
this.mNoInfoDialog.show();
}
public void showDialog() {
if (!BleManager.getInstance().isBlueEnable()) {
ToastUtils.show(this, "请打开蓝牙");
return;
}
View inflate = View.inflate(this, R.layout.dialog_weight_layout, null);
this.mDialog = DialogUtils.createDialog(this, inflate);
this.tvWeight = (TextView) inflate.findViewById(R.id.tvWeight);
this.mDialog.setCanceledOnTouchOutside(false);
inflate.findViewById(R.id.tvSave).setOnClickListener(this);
inflate.findViewById(R.id.tvRemove).setOnClickListener(this);
inflate.findViewById(R.id.imgClose).setOnClickListener(this);
this.group = inflate.findViewById(R.id.group);
this.groupStart = inflate.findViewById(R.id.groupStart);
this.tving = (TextView) inflate.findViewById(R.id.tving);
this.title3 = (TextView) inflate.findViewById(R.id.title3);
this.tvTime = (TextView) inflate.findViewById(R.id.tvTime);
this.tvWeightChange = (TextView) inflate.findViewById(R.id.tvWeightChange);
this.mDialog.show();
}
private void subWeight() {
ViewUtils.showLoading(this, "提交中...");
this.num += 10.0d;
HttpHelper.getInstance().getRetrofitService(this).subUserWeight2(new CreatMap.Builder().addParams("weight", this.datas[0] + "").addParams("resistance1", this.datas[1] + "").addParams("resistance2", this.datas[2] + "").addParams("banlance_version", "Chipsea-BLE").build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<BaseModel>() {
public void onCompleted() {
}
public void onError(Throwable e) {
ViewUtils.hideLoading();
ToastUtil.showShort((Context) WeightActivity3.this, (CharSequence) "保存失败!");
}
public void onNext(BaseModel baseModel) {
ViewUtils.hideLoading();
ToastUtil.showShort((Context) WeightActivity3.this, (CharSequence) "保存成功!");
WeightActivity3.this.getWeight();
}
});
}
public void getWeight() {
HttpHelper.getInstance().getRetrofitService(this).getUserWeight(new CreatMap.Builder().addParams("pageindex", "1").addParams("pagesize", Constants.VIA_REPORT_TYPE_SET_AVATAR).build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(new ResponseFunc()).subscribe(new Subscriber<List<WeightBean>>() {
public void onCompleted() {
}
public void onError(Throwable e) {
ToastUtil.showShort((Context) WeightActivity3.this, (CharSequence) "获取历史数据失败!");
}
public void onNext(List<WeightBean> listWeightBean) {
WeightActivity3.this.parseWeights(listWeightBean);
}
});
}
public void parseWeights(List<WeightBean> listWeightBean) {
if (listWeightBean == null || listWeightBean.size() == 0) {
this.tv_weight.setText("--");
this.tv_tizhi.setText("--");
this.tv_shuifen.setText("--");
return;
}
WeightBean weightBean = listWeightBean.get(0);
this.weight = weightBean.weight;
this.bodyfat = weightBean.bodyfat;
this.moisture = weightBean.moisture;
this.currentWeight = weightBean.weight;
this.tv_weight.setText(this.currentWeight + "kg");
this.weight_number.setText(weightBean.weight + "kg");
this.tv_tizhi.setText(weightBean.bodyfat + "%");
this.tv_shuifen.setText(weightBean.moisture + "%");
this.tv_date.setText("测量日期 " + weightBean.measure_time.replaceAll("(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})", "$2月$3日"));
if (listWeightBean.size() > 1) {
WeightBean weightBean2 = listWeightBean.get(listWeightBean.size() - 2);
this.xiangdui_weight.setText(new BigDecimal(Math.abs(weightBean.weight - weightBean2.weight)).setScale(1, 4).doubleValue() + "kg");
if (weightBean.weight - weightBean2.weight > Utils.DOUBLE_EPSILON) {
this.xiangdui_weight.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.mipmap.contrast_up), (Drawable) null, (Drawable) null, (Drawable) null);
} else {
this.xiangdui_weight.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.mipmap.contrast_down), (Drawable) null, (Drawable) null, (Drawable) null);
}
} else {
this.xiangdui_weight.setText("--");
}
setStandard();
initLineView(listWeightBean);
}
private void setStandard() {
if (this.weight == Utils.DOUBLE_EPSILON && this.bodyfat == Utils.DOUBLE_EPSILON && this.moisture == Utils.DOUBLE_EPSILON && this.weights.size() == 0 && this.bodyfats.size() == 0 && this.moistures.size() == 0) {
return;
}
if (this.weights.size() != 0) {
setMargin(this.weight_number, getDistens(this.weight, this.weights));
}
if (this.bodyfats.size() != 0) {
setMargin(this.tv_tizhi, getDistens(this.bodyfat, this.bodyfats));
}
if (this.moistures.size() != 0) {
setMargin(this.tv_shuifen, getDistens(this.moisture, this.moistures));
}
}
private int getDistens(double value, List<WeightStandardBean.Mode> modes) {
double wIndowWidth = (WindowUtils.getWIndowWidth(this) - WindowUtils.dip2px(this, 30.0f)) - ((this.weights.size() - 1) * 15);
Double.isNaN(wIndowWidth);
double size = this.weights.size();
Double.isNaN(size);
int i = (int) ((wIndowWidth * 1.0d) / size);
int i2 = 0;
for (int i3 = 0; i3 < modes.size(); i3++) {
if (modes.get(i3).value_max == Utils.DOUBLE_EPSILON) {
modes.get(i3).value_max = 10000.0d;
}
if (value > modes.get(i3).value_max) {
i2 = i3 + 1;
}
if (i2 == modes.size()) {
i2--;
}
}
double d = (value - modes.get(i2).value_min) / (modes.get(i2).value_max - modes.get(i2).value_min);
if (d > 1.0d || d < Utils.DOUBLE_EPSILON) {
return -1;
}
double d2 = i2;
Double.isNaN(d2);
double d3 = d2 + d;
double d4 = i;
Double.isNaN(d4);
double d5 = d3 * d4;
double d6 = i2 * 15;
Double.isNaN(d6);
return (int) (d5 + d6);
}
private void setMargin(View v, int distens) {
if (distens < 0) {
v.setVisibility(4);
return;
}
v.setVisibility(0);
int wIndowWidth = WindowUtils.getWIndowWidth(this) - WindowUtils.dip2px(this, 30.0f);
int width = v.getWidth();
if (wIndowWidth - distens < width) {
distens -= width;
((TextView) v).setCompoundDrawables(null, null, getResources().getDrawable(R.mipmap.contrast_down2), null);
}
((LinearLayout.LayoutParams) v.getLayoutParams()).setMargins(distens, 0, 0, 0);
}
private void initLineView(List<WeightBean> listWeightBean) {
ArrayList arrayList = new ArrayList();
ArrayList<Float> arrayList2 = new ArrayList<>();
ArrayList<Float> arrayList3 = new ArrayList<>();
ArrayList<Float> arrayList4 = new ArrayList<>();
ArrayList<Float> arrayList5 = new ArrayList<>();
ArrayList arrayList6 = new ArrayList();
ArrayList arrayList7 = new ArrayList();
int size = listWeightBean.size() - 1;
this.randomint = size;
while (size >= 0) {
WeightBean weightBean = listWeightBean.get(size);
arrayList.add(weightBean.measure_time.replaceAll("(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})", "$2月$3日"));
arrayList2.add(Float.valueOf(weightBean.ave_execer_time / 3600));
arrayList3.add(Float.valueOf((float) weightBean.weight));
arrayList4.add(Float.valueOf((float) weightBean.bodyfat));
arrayList5.add(Float.valueOf((float) weightBean.moisture));
arrayList6.add(Float.valueOf((float) weightBean.muscle));
arrayList7.add(Float.valueOf((float) weightBean.visceralfat));
size--;
}
setLineChart(this.lineChart, arrayList2, arrayList3, new WeightValueFormatter());
setLineChart(this.lineChartTZ, arrayList2, arrayList4, new TZValueFormatter());
setLineChart(this.lineChartSF, arrayList2, arrayList5, new TZValueFormatter());
setBarChartData(arrayList2, arrayList3);
setLineChartShare(arrayList4);
}
private void setLineChart(LineChart chart, ArrayList<Float> dataListTime, ArrayList<Float> dataListWeight, ValueFormatter valueFormatter) {
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
for (int i = 0; i < dataListTime.size(); i++) {
float floatValue = dataListWeight.get(i).floatValue();
float floatValue2 = dataListTime.get(i).floatValue();
if (i == 0) {
this.minRightValue = floatValue;
this.minTimeValue = floatValue2;
}
if (this.minRightValue > floatValue) {
this.minRightValue = floatValue;
}
if (this.minTimeValue > floatValue2) {
this.minTimeValue = floatValue2;
}
float f = i;
arrayList.add(new Entry(f, floatValue2));
arrayList2.add(new Entry(f, floatValue));
}
initChart(chart, this.minRightValue, this.minTimeValue);
LineDataSet lineDataSet = new LineDataSet(arrayList, "DataSet 1");
lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
lineDataSet.setColor(Color.parseColor("#5F80E0"));
lineDataSet.setCircleColor(getResources().getColor(R.color.gray_e8));
lineDataSet.setLineWidth(2.0f);
lineDataSet.setCircleRadius(5.0f);
lineDataSet.setFillAlpha(65);
lineDataSet.setCircleHoleRadius(3.0f);
lineDataSet.setValueFormatter(new timeFormatter());
lineDataSet.setHighLightColor(Color.rgb(244, 117, 117));
lineDataSet.setDrawCircleHole(true);
LineDataSet lineDataSet2 = new LineDataSet(arrayList2, "DataSet 2");
lineDataSet2.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineDataSet2.setColor(Color.parseColor("#C74E40"));
lineDataSet2.setCircleColor(getResources().getColor(R.color.gray_e8));
lineDataSet2.setLineWidth(2.0f);
lineDataSet2.setCircleRadius(5.0f);
lineDataSet2.setFillAlpha(65);
lineDataSet2.setCircleHoleRadius(3.0f);
lineDataSet2.setValueFormatter(valueFormatter);
lineDataSet2.setDrawCircleHole(true);
lineDataSet2.setHighLightColor(Color.rgb(244, 117, 117));
LineData lineData = new LineData(lineDataSet, lineDataSet2);
lineData.setValueTextColor(RoundedDrawable.DEFAULT_BORDER_COLOR);
lineData.setValueTextSize(9.0f);
chart.setData(lineData);
}
private class timeFormatter extends ValueFormatter {
private timeFormatter() {
}
@Override
public String getFormattedValue(float value) {
return value + "min ";
}
}
private class WeightValueFormatter extends ValueFormatter {
private WeightValueFormatter() {
}
@Override
public String getFormattedValue(float value) {
return " " + value + "KG";
}
}
private class TZValueFormatter extends ValueFormatter {
private TZValueFormatter() {
}
@Override
public String getFormattedValue(float value) {
return " " + value + "%";
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
CountDownTimer countDownTimer;
if (keyCode == 4 && (countDownTimer = this.downTimer) != null) {
countDownTimer.cancel();
}
return super.onKeyDown(keyCode, event);
}
protected void onDestroy() {
super.onDestroy();
BleManager.getInstance().destroy();
}
}