Skip to content

Commit

Permalink
发布厨房秤API版本
Browse files Browse the repository at this point in the history
  • Loading branch information
chztp committed Oct 28, 2019
1 parent 0cc444a commit c391e9e
Show file tree
Hide file tree
Showing 19 changed files with 1,242 additions and 254 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'cn.bingoogolapple:bga-qrcode-zxing:1.3.6'
// compile ("com.github.duodebuyali:QNScaleSDK:master-SNAPSHOT") {
compile("com.github.YolandaQingniu:qnscalesdk:1.0.0-beta3") {
exclude module: "support-v4"//防止和module引用的v4资源版本不同
}
// compile("com.github.YolandaQingniu:qnscalesdk:1.0.0") {
// exclude module: "support-v4"//防止和module引用的v4资源版本不同
// }
compile project (':qnscalesdk')
}
128 changes: 128 additions & 0 deletions app/src/main/java/com/qingniu/qnble/demo/adapter/ListAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.qingniu.qnble.demo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qingniu.qnble.demo.R;
import com.qingniu.qnble.demo.bean.IndicateBean;
import com.qingniu.qnble.demo.util.IndicateUtils;
import com.qingniu.qnble.utils.QNLogUtils;
import com.yolanda.health.qnblesdk.constant.QNIndicator;
import com.yolanda.health.qnblesdk.out.QNBleApi;
import com.yolanda.health.qnblesdk.out.QNScaleItemData;
import com.yolanda.health.qnblesdk.out.QNUser;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
* Created by ch on 2019/10/23.
*/

public class ListAdapter extends BaseAdapter {

private List<QNScaleItemData> mDatas;
private QNBleApi mQNBleApi;
private QNUser qnUser;

public ListAdapter(List<QNScaleItemData> mDatas, QNBleApi mQNBleApi, QNUser qnUser) {
this.mDatas = mDatas;
this.mQNBleApi = mQNBleApi;
this.qnUser = qnUser;
}

@Override
public int getCount() {
return mDatas.size();
}

@Override
public Object getItem(int position) {
return mDatas.get(position);
}

@Override
public long getItemId(int position) {
return mDatas.get(position).hashCode();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_data, null);
}
TextView indicateNameTv = (TextView) convertView.findViewById(R.id.indicate_nameTv);
TextView indicateValueTv = (TextView) convertView.findViewById(R.id.indicate_valueTv);
TextView indicateLevelTv = (TextView) convertView.findViewById(R.id.indicate_levelTv);
TextView standardJudgeTv = (TextView) convertView.findViewById(R.id.standardJudgeTv);
TextView currentStandardTv = (TextView) convertView.findViewById(R.id.currentStandardTv);
QNScaleItemData itemData = mDatas.get(position);

indicateNameTv.setText(itemData.getName());
//sdk返回的数据单位一直不变,用户需要自己去转化为自己需要的单位数据
//和重量有关的指标
if (itemData.getType() == QNIndicator.TYPE_WEIGHT || itemData.getType() == QNIndicator.TYPE_BONE
|| itemData.getType() == QNIndicator.TYPE_MUSCLE_MASS) {
indicateValueTv.setText(initWeight(itemData.getValue()));
} else {
indicateValueTv.setText(String.valueOf(itemData.getValue()));
}
IndicateBean indicateBean = IndicateUtils.getIndicate(parent.getContext(), itemData.getType(),
qnUser.getGender(), qnUser.getHeight(), calcAge(qnUser.getBirthDay()), itemData.getValue());
standardJudgeTv.setText(indicateBean.getIndicateDescribe().toString());
currentStandardTv.setText(indicateBean.getCurrentIndicate());
return convertView;
}

private String initWeight(double weight) {
int unit = mQNBleApi.getConfig().getUnit();
return mQNBleApi.convertWeightWithTargetUnit(weight, unit);
}

private int calcAge(Date birthday) {
if (birthday == null) {
return 0;
}
int age = getAgeToDay(birthday);

//2019年01月04日16:07:58 修改年龄计算为年月日方式
//修改年龄的界限
if (age < 3) {
return 3;
} else if (age > 80) {
return 80;
} else return age;
}

private int getAgeToDay(Date birthday) {
if (birthday == null) {
return 0;
}

Calendar cal = Calendar.getInstance();

//设置当前日期
cal.setTime(new Date());
int curYear = cal.get(Calendar.YEAR);
int curMonth = cal.get(Calendar.MONTH) + 1;
int curDay = cal.get(Calendar.DAY_OF_MONTH);

//设置生日日期
cal.setTime(birthday);
int userYear = cal.get(Calendar.YEAR);
int userMonth = cal.get(Calendar.MONTH) + 1;
int userDay = cal.get(Calendar.DAY_OF_MONTH);

int age = curYear - userYear - 1;
if ((curMonth > userMonth) || (curMonth == userMonth && curDay >= userDay)) {
age++;
}
QNLogUtils.log("BleUser", "计算的年龄为:" + age + ";当前时间为:" + System.currentTimeMillis() +
";生日为:" + birthday.getTime());
return age;
}
}
65 changes: 65 additions & 0 deletions app/src/main/java/com/qingniu/qnble/demo/bean/IndicateBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.qingniu.qnble.demo.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
* Created by ch on 2019/10/23.
*/

public class IndicateBean implements Parcelable {

private List<String> indicateDescribe;

private String currentIndicate;

public List<String> getIndicateDescribe() {
return indicateDescribe;
}

public void setIndicateDescribe(List<String> indicateDescribe) {
this.indicateDescribe = indicateDescribe;
}

public String getCurrentIndicate() {
return currentIndicate;
}

public void setCurrentIndicate(String currentIndicate) {
this.currentIndicate = currentIndicate;
}


@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringList(this.indicateDescribe);
dest.writeString(this.currentIndicate);
}

public IndicateBean() {
}

protected IndicateBean(Parcel in) {
this.indicateDescribe = in.createStringArrayList();
this.currentIndicate = in.readString();
}

public static final Creator<IndicateBean> CREATOR = new Creator<IndicateBean>() {
@Override
public IndicateBean createFromParcel(Parcel source) {
return new IndicateBean(source);
}

@Override
public IndicateBean[] newArray(int size) {
return new IndicateBean[size];
}
};
}
Loading

0 comments on commit c391e9e

Please sign in to comment.