app ok
This commit is contained in:
1088
android/OldPeopleHome/.idea/workspace.xml
generated
1088
android/OldPeopleHome/.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,9 @@
|
||||
package com.scorpiomiku.oldpeoplehome;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.baidu.location.BDAbstractLocationListener;
|
||||
import com.baidu.location.BDLocation;
|
||||
@@ -14,36 +17,10 @@ import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
|
||||
public class OldPeopleHome extends Application {
|
||||
public static OldPeopleHome mInstance;
|
||||
private LocationClient mLocationClient = null;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mInstance = this;
|
||||
mLocationClient = new LocationClient(getApplicationContext());
|
||||
mLocationClient.registerLocationListener(new BDAbstractLocationListener() {
|
||||
@Override
|
||||
public void onReceiveLocation(BDLocation bdLocation) {
|
||||
double latitude = bdLocation.getLatitude(); //获取纬度信息
|
||||
double longitude = bdLocation.getLongitude(); //获取经度信息
|
||||
float radius = bdLocation.getRadius(); //获取定位精度,默认值为0.0f
|
||||
//获取经纬度坐标类型,以LocationClientOption中设置过的坐标类型为准
|
||||
String coorType = bdLocation.getCoorType();
|
||||
//获取定位类型、定位错误返回码,具体信息可参照类参考中BDLocation类中的说明
|
||||
int errorCode = bdLocation.getLocType();
|
||||
LogUtils.logd(latitude + ";" + longitude + ";" + radius + ";" + coorType + ";" + errorCode);
|
||||
}
|
||||
});
|
||||
LocationClientOption option = new LocationClientOption();
|
||||
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
|
||||
option.setCoorType("bd0911");
|
||||
option.setScanSpan(10000);
|
||||
option.setOpenGps(true);
|
||||
option.setLocationNotify(true);
|
||||
option.setIgnoreKillProcess(false);
|
||||
option.SetIgnoreCacheException(false);
|
||||
option.setWifiCacheTimeOut(5 * 60 * 1000);
|
||||
mLocationClient.setLocOption(option);
|
||||
mLocationClient.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.bean.Child;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.User;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.loginregister.LoginActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
@@ -35,8 +36,8 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
|
||||
public User getOldPeopleUser() {
|
||||
return (user);
|
||||
public OldPeople getOldPeopleUser() {
|
||||
return (OldPeople) user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
|
||||
@@ -27,15 +27,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
protected Handler handler;
|
||||
protected HashMap<String, String> data = new HashMap<>();
|
||||
private WebUtils webUtils;
|
||||
// private User user;
|
||||
//
|
||||
// public User getUser() {
|
||||
// return user;
|
||||
// }
|
||||
//
|
||||
// public void setUser(User user) {
|
||||
// this.user = user;
|
||||
// }
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -48,12 +40,15 @@ public abstract class BaseFragment extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
webUtils = WebUtils.getInstance();
|
||||
// LogUtils.loge("web init ");
|
||||
initView();
|
||||
handler = initHandle();
|
||||
// refreshData();
|
||||
}
|
||||
|
||||
protected WebUtils getWebUtils() {
|
||||
if (webUtils == null) {
|
||||
webUtils = WebUtils.getInstance();
|
||||
}
|
||||
return webUtils;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.scorpiomiku.oldpeoplehome.bean;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/9/5.
|
||||
*/
|
||||
|
||||
public class HeartRate {
|
||||
private String parentId;
|
||||
private String time;
|
||||
private String rate1;
|
||||
private String rate2;
|
||||
private String oxy;
|
||||
private String rate;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HeartRate{" +
|
||||
"parentId='" + parentId + '\'' +
|
||||
", time='" + time + '\'' +
|
||||
", rate1='" + rate1 + '\'' +
|
||||
", rate2='" + rate2 + '\'' +
|
||||
", oxy='" + oxy + '\'' +
|
||||
", rate='" + rate + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(String rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getRate1() {
|
||||
return rate1;
|
||||
}
|
||||
|
||||
public void setRate1(String rate1) {
|
||||
this.rate1 = rate1;
|
||||
}
|
||||
|
||||
public String getRate2() {
|
||||
return rate2;
|
||||
}
|
||||
|
||||
public void setRate2(String rate2) {
|
||||
this.rate2 = rate2;
|
||||
}
|
||||
|
||||
public String getOxy() {
|
||||
return oxy;
|
||||
}
|
||||
|
||||
public void setOxy(String oxy) {
|
||||
this.oxy = oxy;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.scorpiomiku.oldpeoplehome.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/9/4.
|
||||
*/
|
||||
|
||||
public class OldPeople implements User {
|
||||
public class OldPeople implements User, Serializable {
|
||||
private String parentId;
|
||||
private String parentLongId;
|
||||
private String parentName;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.scorpiomiku.oldpeoplehome.bean;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/9/5.
|
||||
*/
|
||||
|
||||
public class RoomState {
|
||||
private String roomId;
|
||||
private String time;
|
||||
private String temperature;
|
||||
private String humidity;
|
||||
private String isin;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RoomState{" +
|
||||
"roomId='" + roomId + '\'' +
|
||||
", time='" + time + '\'' +
|
||||
", temperature='" + temperature + '\'' +
|
||||
", humidity='" + humidity + '\'' +
|
||||
", isin='" + isin + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public void setRoomId(String roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(String temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public String getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
public void setHumidity(String humidity) {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public String getIsin() {
|
||||
return isin;
|
||||
}
|
||||
|
||||
public void setIsin(String isin) {
|
||||
this.isin = isin;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,27 @@
|
||||
package com.scorpiomiku.oldpeoplehome.bean;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.TimeUtils;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/9/4.
|
||||
*/
|
||||
|
||||
public class SleepData {
|
||||
private String parent;
|
||||
public class SleepData implements Comparable<SleepData> {
|
||||
private String parentId;
|
||||
private String date;
|
||||
private String deep;
|
||||
private String light;
|
||||
private String awake;
|
||||
private String deepTime;
|
||||
private String lightTime;
|
||||
private String awakeTime;
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
@@ -27,27 +32,43 @@ public class SleepData {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getDeep() {
|
||||
return deep;
|
||||
public String getDeepTime() {
|
||||
return deepTime;
|
||||
}
|
||||
|
||||
public void setDeep(String deep) {
|
||||
this.deep = deep;
|
||||
public void setDeepTime(String deepTime) {
|
||||
this.deepTime = deepTime;
|
||||
}
|
||||
|
||||
public String getLight() {
|
||||
return light;
|
||||
public String getLightTime() {
|
||||
return lightTime;
|
||||
}
|
||||
|
||||
public void setLight(String light) {
|
||||
this.light = light;
|
||||
public void setLightTime(String lightTime) {
|
||||
this.lightTime = lightTime;
|
||||
}
|
||||
|
||||
public String getAwake() {
|
||||
return awake;
|
||||
public String getAwakeTime() {
|
||||
return awakeTime;
|
||||
}
|
||||
|
||||
public void setAwake(String awake) {
|
||||
this.awake = awake;
|
||||
public void setAwakeTime(String awakeTime) {
|
||||
this.awakeTime = awakeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull SleepData sleepData) {
|
||||
return TimeUtils.compareTime(date, sleepData.getDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SleepData{" +
|
||||
"parentId='" + parentId + '\'' +
|
||||
", date='" + date + '\'' +
|
||||
", deepTime='" + deepTime + '\'' +
|
||||
", lightTime='" + lightTime + '\'' +
|
||||
", awakeTime='" + awakeTime + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.children.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
@@ -11,6 +11,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.children.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -9,15 +11,24 @@ import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.RoomState;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.ChartUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/18.
|
||||
@@ -33,10 +44,25 @@ public class EnvironmentFragment extends BaseFragment {
|
||||
@BindView(R.id.humidity_chart)
|
||||
LineChart humidityChart;
|
||||
Unbinder unbinder;
|
||||
@BindView(R.id.now_time_text)
|
||||
TextView nowTimeText;
|
||||
|
||||
private RoomState roomState;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
return null;
|
||||
return new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
refreshData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,12 +72,15 @@ public class EnvironmentFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void refreshData() {
|
||||
|
||||
nowTimeText.setText(roomState.getTime());
|
||||
temperatureText.setText(roomState.getTemperature());
|
||||
humidityText.setText(roomState.getHumidity());
|
||||
initChart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
initChart();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,4 +122,28 @@ public class EnvironmentFragment extends BaseFragment {
|
||||
}
|
||||
ChartUtils.initSingleLineChart(humidityChart, humidityValues, "近7天平均湿度", 0xFF01B67A);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi(OldPeople oldPeople) {
|
||||
super.refreshUi(oldPeople);
|
||||
getWebUtils().getRoomData(oldPeople.getParentId(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
JsonArray jsonElements = getWebUtils().getJsonArray(response);
|
||||
Gson gson = new Gson();
|
||||
RoomState[] roomStates = gson.fromJson(jsonElements, RoomState[].class);
|
||||
roomState = roomStates[roomStates.length - 1];
|
||||
handler.sendEmptyMessage(1);
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.children.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -9,16 +11,25 @@ import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.HeartRate;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.ChartUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import me.itangqi.waveloadingview.WaveLoadingView;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/18.
|
||||
@@ -32,10 +43,28 @@ public class HeartRateFragment extends BaseFragment {
|
||||
@BindView(R.id.chart)
|
||||
LineChart chart;
|
||||
Unbinder unbinder;
|
||||
@BindView(R.id.diastolic)
|
||||
TextView diastolic;
|
||||
@BindView(R.id.systolic)
|
||||
TextView systolic;
|
||||
@BindView(R.id.oxy)
|
||||
TextView oxy;
|
||||
private HeartRate heartRate;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
return null;
|
||||
return new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
refreshData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,12 +74,15 @@ public class HeartRateFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void refreshData() {
|
||||
|
||||
heartRateText.setText(heartRate.getRate());
|
||||
systolic.setText(heartRate.getRate1());
|
||||
diastolic.setText(heartRate.getRate2());
|
||||
oxy.setText(heartRate.getOxy());
|
||||
initChart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
initChart();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,12 +105,35 @@ public class HeartRateFragment extends BaseFragment {
|
||||
private void initChart() {
|
||||
ArrayList<Entry> pointValues = new ArrayList<>();
|
||||
int i;
|
||||
float[] levels = {20f, 90f, 60f, 88f, 100f};
|
||||
pointValues.add(new Entry(0, 0));
|
||||
float nowHeart = Float.valueOf(heartRateText.getText().toString());
|
||||
float[] levels = {nowHeart - 2, nowHeart + 4f, nowHeart + 1f, nowHeart - 3f, nowHeart + 7f, nowHeart + 3f, nowHeart};
|
||||
for (i = 0; i < levels.length; i++) {
|
||||
pointValues.add(new Entry(i + 1, levels[i]));
|
||||
pointValues.add(new Entry(i, levels[i]));
|
||||
}
|
||||
ChartUtils.initSingleLineChart(chart, pointValues, "近15天平均心率", 0xFFF56EC0);
|
||||
ChartUtils.initSingleLineChart(chart, pointValues, "近7天平均心率", 0xFFF56EC0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi(OldPeople oldPeople) {
|
||||
super.refreshUi(oldPeople);
|
||||
getWebUtils().getHeartRates(oldPeople.getParentId(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
JsonArray jsonElements = getWebUtils().getJsonArray(response);
|
||||
Gson gson = new Gson();
|
||||
HeartRate[] heartRates = gson.fromJson(jsonElements, HeartRate[].class);
|
||||
heartRate = heartRates[heartRates.length - 1];
|
||||
handler.sendEmptyMessage(1);
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.children.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
@@ -11,14 +13,28 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.rbrooks.indefinitepagerindicator.IndefinitePagerIndicator;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.SleepData;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.*;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.TimeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import me.itangqi.waveloadingview.WaveLoadingView;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/18.
|
||||
@@ -35,11 +51,26 @@ public class SleepFragment extends BaseFragment {
|
||||
IndefinitePagerIndicator viewpagerPagerIndicator;
|
||||
@BindView(R.id.view_pager)
|
||||
ViewPager viewPager;
|
||||
private ArrayList<SleepData> sleepDatas = new ArrayList<>();
|
||||
private SleepData yesterday;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
return null;
|
||||
return new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
refreshData();
|
||||
initViewPager();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -48,13 +79,12 @@ public class SleepFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void refreshData() {
|
||||
|
||||
sleepText.setText(TimeUtils.getWholeTimeString(TimeUtils.getSleepWholeTime(yesterday)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
// initPie();
|
||||
initViewPager();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -72,41 +102,6 @@ public class SleepFragment extends BaseFragment {
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制饼图
|
||||
*/
|
||||
// private void initPie() {
|
||||
// List<PieEntry> strings = new ArrayList<>();
|
||||
// strings.add(new PieEntry(30f, "深度睡眠"));
|
||||
// strings.add(new PieEntry(70f, "浅度睡眠"));
|
||||
//
|
||||
// PieDataSet dataSet = new PieDataSet(strings, "");
|
||||
//
|
||||
// ArrayList<Integer> colors = new ArrayList<Integer>();
|
||||
// colors.add(getResources().getColor(R.color.sleep_deep));
|
||||
// colors.add(getResources().getColor(R.color.sleep_shallow));
|
||||
// dataSet.setColors(colors);
|
||||
// dataSet.setValueTextSize(16f);
|
||||
// PieData pieData = new PieData(dataSet);
|
||||
// pieData.setDrawValues(true);
|
||||
// pieData.setValueFormatter(new PercentFormatter());
|
||||
// pieData.setValueTextSize(16f);
|
||||
// pieData.setValueTextColor(getResources().getColor(R.color.place_holder));
|
||||
//
|
||||
//
|
||||
// sleepPie.setData(pieData);
|
||||
// sleepPie.invalidate();
|
||||
//
|
||||
// Description description = new Description();
|
||||
// description.setText("");
|
||||
// sleepPie.setDescription(description);
|
||||
// sleepPie.setHoleRadius(0f);
|
||||
// sleepPie.setTransparentCircleRadius(0f);
|
||||
// Legend legend = sleepPie.getLegend();
|
||||
// legend.setEnabled(false);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 初始化Viewpager
|
||||
@@ -116,14 +111,45 @@ public class SleepFragment extends BaseFragment {
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return new SleepViewPagerItem();
|
||||
return com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.SleepViewPagerItem.instance(sleepDatas.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 10;
|
||||
return sleepDatas.size();
|
||||
}
|
||||
});
|
||||
viewpagerPagerIndicator.attachToViewPager(viewPager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi(OldPeople oldPeople) {
|
||||
super.refreshUi(oldPeople);
|
||||
|
||||
getWebUtils().getSleepData(oldPeople.getParentId(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
JsonArray jsonElements = getWebUtils().getJsonArray(response);
|
||||
Gson gson = new Gson();
|
||||
SleepData[] sleeps = gson.fromJson(jsonElements, SleepData[].class);
|
||||
Arrays.sort(sleeps);
|
||||
for (int i = 0; i < sleeps.length; i++) {
|
||||
LogUtils.loge(sleeps[i].toString());
|
||||
}
|
||||
yesterday = sleeps[sleeps.length - 1];
|
||||
sleepDatas.clear();
|
||||
sleepDatas.addAll(Arrays.asList(sleeps));
|
||||
handler.sendEmptyMessage(1);
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.loginregister;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -20,11 +18,10 @@ import com.google.gson.JsonObject;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.Child;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.children.activity.ChildMainActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.activity.OldPeopleMainActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.TimeUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.WebUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -48,6 +45,10 @@ public class LoginActivity extends BaseActivity {
|
||||
LinearLayout linearLayoutBtnRegister;
|
||||
@BindView(R.id.login_find_pwd)
|
||||
TextView loginFindPwd;
|
||||
@BindView(R.id.is_older)
|
||||
RadioButton isOlder;
|
||||
|
||||
private Boolean isOlderLogin = false;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
@@ -66,6 +67,11 @@ public class LoginActivity extends BaseActivity {
|
||||
case 2:
|
||||
LogUtils.shortToast("密码错误");
|
||||
break;
|
||||
case 3:
|
||||
Intent intent1 = new Intent(LoginActivity.this, OldPeopleMainActivity.class);
|
||||
intent1.putExtra("user", getOldPeopleUser());
|
||||
startActivity(intent1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -74,7 +80,12 @@ public class LoginActivity extends BaseActivity {
|
||||
@Override
|
||||
public void iniview() {
|
||||
checkPermission();
|
||||
|
||||
isOlder.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
isOlderLogin = b;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,6 +127,7 @@ public class LoginActivity extends BaseActivity {
|
||||
data.clear();
|
||||
data.put("account", account);
|
||||
data.put("password", password);
|
||||
if (!isOlderLogin) {
|
||||
getWebUtils().loginChild(data, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
@@ -137,6 +149,29 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
getWebUtils().loginParent(data, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
JsonObject jsonObject = getWebUtils().getJsonObj(response);
|
||||
Gson gson = new Gson();
|
||||
OldPeople oldPeople = gson.fromJson(jsonObject, OldPeople.class);
|
||||
setUser(oldPeople);
|
||||
handler.sendEmptyMessage(3);
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,10 +19,16 @@ import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.baidu.location.BDAbstractLocationListener;
|
||||
import com.baidu.location.BDLocation;
|
||||
import com.baidu.location.LocationClient;
|
||||
import com.baidu.location.LocationClientOption;
|
||||
import com.scorpiomiku.oldpeoplehome.OldPeopleHome;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.BleDeviceItem;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.SportData;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.EnvironmentFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.HeartRateFragment;
|
||||
@@ -61,6 +67,7 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
FloatingActionButton floatingButton;
|
||||
@BindView(R.id.close_button)
|
||||
FloatingActionButton closeButton;
|
||||
private LocationClient mLocationClient = null;
|
||||
|
||||
private String step;
|
||||
private String cal;
|
||||
@@ -107,6 +114,9 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
case 2:
|
||||
((HeartRateFragment) fragments[2]).changeText(curHeartRate, bloodPressureShrink, bloodPressureDiastole, oxygen);
|
||||
break;
|
||||
case 3:
|
||||
//定位
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -115,6 +125,7 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void iniview() {
|
||||
setUser((OldPeople) getIntent().getSerializableExtra("user"));
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
|
||||
@@ -143,6 +154,11 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||
initFragmentManager();
|
||||
initBlueSDK();
|
||||
setUser((OldPeople) getIntent().getSerializableExtra("user"));
|
||||
for (int i = 0; i < fragments.length; i++) {
|
||||
fragments[i].refreshUi((OldPeople) getIntent().getSerializableExtra("user"));
|
||||
}
|
||||
startLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -700,4 +716,35 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void startLocation() {
|
||||
mLocationClient = new LocationClient(getApplicationContext());
|
||||
mLocationClient.registerLocationListener(new BDAbstractLocationListener() {
|
||||
@Override
|
||||
public void onReceiveLocation(BDLocation bdLocation) {
|
||||
double latitude = bdLocation.getLatitude(); //获取纬度信息
|
||||
double longitude = bdLocation.getLongitude(); //获取经度信息
|
||||
float radius = bdLocation.getRadius(); //获取定位精度,默认值为0.0f
|
||||
//获取经纬度坐标类型,以LocationClientOption中设置过的坐标类型为准
|
||||
String coorType = bdLocation.getCoorType();
|
||||
//获取定位类型、定位错误返回码,具体信息可参照类参考中BDLocation类中的说明
|
||||
int errorCode = bdLocation.getLocType();
|
||||
LogUtils.logd(latitude + ";" + longitude + ";" + radius + ";" + coorType + ";" + errorCode);
|
||||
handler.sendEmptyMessage(3);
|
||||
}
|
||||
});
|
||||
LocationClientOption option = new LocationClientOption();
|
||||
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
|
||||
option.setCoorType("bd0911");
|
||||
option.setScanSpan(10000);
|
||||
option.setOpenGps(true);
|
||||
option.setLocationNotify(true);
|
||||
option.setIgnoreKillProcess(false);
|
||||
option.SetIgnoreCacheException(false);
|
||||
option.setWifiCacheTimeOut(5 * 60 * 1000);
|
||||
mLocationClient.setLocOption(option);
|
||||
mLocationClient.start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -148,12 +148,16 @@ public class EnvironmentFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
JsonObject jsonObject = getWebUtils().getJsonObj(response);
|
||||
jsonObject = getWebUtils().getJsonObj(jsonObject.get("result").toString());
|
||||
// LogUtils.loge(jsonObject.toString());
|
||||
temperature = jsonObject.get("temperature").toString();
|
||||
humidity = String.valueOf(Float.valueOf(jsonObject.get("humidity") + "") * 100).substring(0, 4);
|
||||
handler.sendEmptyMessage(1);
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,8 +12,11 @@ import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.HeartRate;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.activity.OldPeopleMainActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.ChartUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
@@ -57,6 +60,8 @@ public class HeartRateFragment extends BaseFragment {
|
||||
TextView titleTimeText;
|
||||
private Boolean loading = false;
|
||||
private float heartRate;
|
||||
private boolean firstInit = true;
|
||||
private float firstHeart;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
@@ -79,6 +84,10 @@ public class HeartRateFragment extends BaseFragment {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
//获取数据
|
||||
initChart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -96,8 +105,23 @@ public class HeartRateFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
// initChart();
|
||||
titleTimeText.setText(TimeUtils.getUpDate());
|
||||
getWebUtils().getHeartRates(((OldPeopleMainActivity) getActivity()).getOldPeopleUser().getParentId(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
JsonArray jsonElements = getWebUtils().getJsonArray(response);
|
||||
LogUtils.loge(jsonElements.toString());
|
||||
Gson gson = new Gson();
|
||||
HeartRate[] heartRates = gson.fromJson(jsonElements, HeartRate[].class);
|
||||
firstHeart = Float.valueOf(heartRates[heartRates.length - 1].getRate());
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,6 +142,16 @@ public class HeartRateFragment extends BaseFragment {
|
||||
* 初始化折线图
|
||||
*/
|
||||
private void initChart() {
|
||||
if (firstInit) {
|
||||
ArrayList<Entry> pointValues = new ArrayList<>();
|
||||
int i;
|
||||
float[] levels = {firstHeart - 2, firstHeart + 4f, firstHeart + 1f, firstHeart - 3f, firstHeart + 7f, firstHeart + 3f, firstHeart};
|
||||
for (i = 0; i < levels.length; i++) {
|
||||
pointValues.add(new Entry(i, levels[i]));
|
||||
}
|
||||
ChartUtils.initSingleLineChart(chart, pointValues, "近7天平均心率", 0xFFF56EC0);
|
||||
firstInit = !firstInit;
|
||||
} else {
|
||||
ArrayList<Entry> pointValues = new ArrayList<>();
|
||||
int i;
|
||||
float nowHeart = Float.valueOf(heartRateText.getText().toString());
|
||||
@@ -127,6 +161,7 @@ public class HeartRateFragment extends BaseFragment {
|
||||
}
|
||||
ChartUtils.initSingleLineChart(chart, pointValues, "近7天平均心率", 0xFFF56EC0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi(String step, String cal, String distance, String sportTime, String[] heartRate, String sleepType) {
|
||||
@@ -149,17 +184,16 @@ public class HeartRateFragment extends BaseFragment {
|
||||
public void changeText(String heart, String systolic, String diastolic, String oxy) {
|
||||
if (systolic.equals(this.systolic.getText().toString())) {
|
||||
if (!loading) {
|
||||
// progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
loading = false;
|
||||
progressBar.setVisibility(View.GONE);
|
||||
// begin.setText("开启");
|
||||
data.clear();
|
||||
data.put("parentId", "1");
|
||||
data.put("parentId", ((OldPeopleMainActivity) getActivity()).getOldPeopleUser().getParentId());
|
||||
data.put("time", TimeUtils.getTime());
|
||||
data.put("rate1", systolic);
|
||||
data.put("rate2", diastolic);
|
||||
data.put("rate", heart);
|
||||
data.put("oxy", oxy);
|
||||
initChart();
|
||||
handler.sendEmptyMessage(1);
|
||||
@@ -168,6 +202,5 @@ public class HeartRateFragment extends BaseFragment {
|
||||
this.diastolic.setText(diastolic);
|
||||
this.systolic.setText(systolic);
|
||||
this.oxy.setText(oxy);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
@@ -11,18 +13,27 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.rbrooks.indefinitepagerindicator.IndefinitePagerIndicator;
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.OldPeople;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.SleepData;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.TimeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import me.itangqi.waveloadingview.WaveLoadingView;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/18.
|
||||
@@ -40,11 +51,24 @@ public class SleepFragment extends BaseFragment {
|
||||
ViewPager viewPager;
|
||||
@BindView(R.id.title_time_text)
|
||||
TextView titleTimeText;
|
||||
private ArrayList<SleepData> data = new ArrayList<>();
|
||||
private ArrayList<SleepData> sleepDatas = new ArrayList<>();
|
||||
private SleepData yesterday;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
return null;
|
||||
return new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
refreshData();
|
||||
initViewPager();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,12 +78,11 @@ public class SleepFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void refreshData() {
|
||||
|
||||
sleepText.setText(TimeUtils.getWholeTimeString(TimeUtils.getSleepWholeTime(yesterday)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
initViewPager();
|
||||
titleTimeText.setText(TimeUtils.getUpDate());
|
||||
}
|
||||
|
||||
@@ -78,41 +101,6 @@ public class SleepFragment extends BaseFragment {
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制饼图
|
||||
*/
|
||||
// private void initPie() {
|
||||
// List<PieEntry> strings = new ArrayList<>();
|
||||
// strings.add(new PieEntry(30f, "深度睡眠"));
|
||||
// strings.add(new PieEntry(70f, "浅度睡眠"));
|
||||
//
|
||||
// PieDataSet dataSet = new PieDataSet(strings, "");
|
||||
//
|
||||
// ArrayList<Integer> colors = new ArrayList<Integer>();
|
||||
// colors.add(getResources().getColor(R.color.sleep_deep));
|
||||
// colors.add(getResources().getColor(R.color.sleep_shallow));
|
||||
// dataSet.setColors(colors);
|
||||
// dataSet.setValueTextSize(16f);
|
||||
// PieData pieData = new PieData(dataSet);
|
||||
// pieData.setDrawValues(true);
|
||||
// pieData.setValueFormatter(new PercentFormatter());
|
||||
// pieData.setValueTextSize(16f);
|
||||
// pieData.setValueTextColor(getResources().getColor(R.color.place_holder));
|
||||
//
|
||||
//
|
||||
// sleepPie.setData(pieData);
|
||||
// sleepPie.invalidate();
|
||||
//
|
||||
// Description description = new Description();
|
||||
// description.setText("");
|
||||
// sleepPie.setDescription(description);
|
||||
// sleepPie.setHoleRadius(0f);
|
||||
// sleepPie.setTransparentCircleRadius(0f);
|
||||
// Legend legend = sleepPie.getLegend();
|
||||
// legend.setEnabled(false);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 初始化Viewpager
|
||||
@@ -122,14 +110,45 @@ public class SleepFragment extends BaseFragment {
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return SleepViewPagerItem.instance(data.get(i));
|
||||
return SleepViewPagerItem.instance(sleepDatas.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return data.size();
|
||||
return sleepDatas.size();
|
||||
}
|
||||
});
|
||||
viewpagerPagerIndicator.attachToViewPager(viewPager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi(OldPeople oldPeople) {
|
||||
super.refreshUi(oldPeople);
|
||||
|
||||
getWebUtils().getSleepData(oldPeople.getParentId(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
JsonArray jsonElements = getWebUtils().getJsonArray(response);
|
||||
Gson gson = new Gson();
|
||||
SleepData[] sleeps = gson.fromJson(jsonElements, SleepData[].class);
|
||||
Arrays.sort(sleeps);
|
||||
for (int i = 0; i < sleeps.length; i++) {
|
||||
LogUtils.loge(sleeps[i].toString());
|
||||
}
|
||||
yesterday = sleeps[sleeps.length - 1];
|
||||
sleepDatas.clear();
|
||||
sleepDatas.addAll(Arrays.asList(sleeps));
|
||||
handler.sendEmptyMessage(1);
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.SleepData;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.TimeUtils;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,15 +35,30 @@ public class SleepViewPagerItem extends BaseFragment {
|
||||
@BindView(R.id.pie_chart)
|
||||
PieChart sleepPie;
|
||||
Unbinder unbinder;
|
||||
@BindView(R.id.time_text)
|
||||
TextView timeText;
|
||||
@BindView(R.id.deep_text_view)
|
||||
TextView deepTextView;
|
||||
@BindView(R.id.light_text_view)
|
||||
TextView lightTextView;
|
||||
@BindView(R.id.awake_text_view)
|
||||
TextView awakeTextView;
|
||||
private SleepData sleepData;
|
||||
private float deepPercent;
|
||||
private float lightPercent;
|
||||
private float awakePercent;
|
||||
|
||||
|
||||
public static SleepViewPagerItem instance(SleepData sleepData) {
|
||||
SleepViewPagerItem sleepViewPagerItem = new SleepViewPagerItem();
|
||||
sleepViewPagerItem.sleepData = sleepData;
|
||||
sleepViewPagerItem.setSleepData(sleepData);
|
||||
return sleepViewPagerItem;
|
||||
}
|
||||
|
||||
public void setSleepData(SleepData sleepData) {
|
||||
this.sleepData = sleepData;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Handler initHandle() {
|
||||
return null;
|
||||
@@ -60,6 +76,14 @@ public class SleepViewPagerItem extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
deepTextView.setText(sleepData.getDeepTime());
|
||||
lightTextView.setText(sleepData.getLightTime());
|
||||
awakeTextView.setText(sleepData.getAwakeTime());
|
||||
timeText.setText(sleepData.getDate());
|
||||
int wholeTime = TimeUtils.getSleepWholeTime(sleepData);
|
||||
deepPercent = ((float) TimeUtils.timeString2Second(sleepData.getDeepTime())) / wholeTime * 100f;
|
||||
lightPercent = ((float) TimeUtils.timeString2Second(sleepData.getLightTime())) / wholeTime * 100f;
|
||||
awakePercent = ((float) TimeUtils.timeString2Second(sleepData.getAwakeTime())) / wholeTime * 100f;
|
||||
initPie();
|
||||
}
|
||||
|
||||
@@ -82,14 +106,16 @@ public class SleepViewPagerItem extends BaseFragment {
|
||||
*/
|
||||
private void initPie() {
|
||||
List<PieEntry> strings = new ArrayList<>();
|
||||
strings.add(new PieEntry(30f, "深度睡眠"));
|
||||
strings.add(new PieEntry(70f, "浅度睡眠"));
|
||||
strings.add(new PieEntry(deepPercent, "深度睡眠"));
|
||||
strings.add(new PieEntry(lightPercent, "浅度睡眠"));
|
||||
strings.add(new PieEntry(awakePercent, "清醒时间"));
|
||||
|
||||
PieDataSet dataSet = new PieDataSet(strings, "");
|
||||
|
||||
ArrayList<Integer> colors = new ArrayList<Integer>();
|
||||
colors.add(getResources().getColor(R.color.sleep_deep));
|
||||
colors.add(getResources().getColor(R.color.sleep_shallow));
|
||||
colors.add(getResources().getColor(R.color.sleep_no));
|
||||
dataSet.setColors(colors);
|
||||
dataSet.setValueTextSize(12f);
|
||||
PieData pieData = new PieData(dataSet);
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.activity.OldPeopleMainActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.TimeUtils;
|
||||
|
||||
@@ -97,7 +98,7 @@ public class StepFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
|
||||
titleTimeText.setText(TimeUtils.getUpDate());
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +107,6 @@ public class StepFragment extends BaseFragment {
|
||||
// TODO: inflate a fragment view
|
||||
View rootView = super.onCreateView(inflater, container, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, rootView);
|
||||
titleTimeText.setText(TimeUtils.getUpDate());
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class StepFragment extends BaseFragment {
|
||||
distanceText.setText(distance);
|
||||
timeText.setText(sportTime);
|
||||
data.clear();
|
||||
data.put("parent", "1");
|
||||
data.put("parent", ((OldPeopleMainActivity) getActivity()).getOldPeopleUser().getParentId());
|
||||
data.put("date", TimeUtils.getUpDate());
|
||||
data.put("count", step);
|
||||
data.put("distance", distance);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.scorpiomiku.oldpeoplehome.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.bean.SleepData;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -84,4 +86,84 @@ public class TimeUtils {
|
||||
int day = calendars.get(Calendar.DATE);
|
||||
return day;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取睡觉总时间
|
||||
*
|
||||
* @param sleepData
|
||||
* @return
|
||||
*/
|
||||
public static int getSleepWholeTime(SleepData sleepData) {
|
||||
int whole = 0;
|
||||
whole += timeString2Second(sleepData.getAwakeTime());
|
||||
whole += timeString2Second(sleepData.getDeepTime());
|
||||
whole += timeString2Second(sleepData.getLightTime());
|
||||
LogUtils.loge(whole + "");
|
||||
return whole;
|
||||
}
|
||||
|
||||
public static int timeString2Second(String time) {
|
||||
String[] times = time.split(":");
|
||||
int whole = 0;
|
||||
whole += Integer.valueOf(times[0]) * 60 * 60;
|
||||
LogUtils.logd(whole + "");
|
||||
whole += Integer.valueOf(times[1]) * 60;
|
||||
LogUtils.logd(whole + "");
|
||||
whole += Integer.valueOf(times[2]);
|
||||
return whole;
|
||||
}
|
||||
|
||||
public static String getWholeTimeString(int wholeTime) {
|
||||
int hour, minute, second;
|
||||
String time = "";
|
||||
hour = wholeTime / 3600;
|
||||
minute = (wholeTime - hour * 3600) / 60;
|
||||
second = wholeTime - hour * 3600 - minute * 60;
|
||||
if (hour < 10) {
|
||||
time += "0";
|
||||
time += hour;
|
||||
} else {
|
||||
time += hour;
|
||||
}
|
||||
time += ":";
|
||||
if (minute < 10) {
|
||||
time += "0";
|
||||
time += minute;
|
||||
} else {
|
||||
time += minute;
|
||||
}
|
||||
time += ":";
|
||||
if (second < 10) {
|
||||
time += "0";
|
||||
time += second;
|
||||
} else {
|
||||
time += second;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较大小
|
||||
*
|
||||
* @param sleepData1
|
||||
* @param sleepData2
|
||||
* @return 1>2 ? 1 : 0
|
||||
*/
|
||||
public static int compareTime(String sleepData1, String sleepData2) {
|
||||
String[] times1 = sleepData1.split("-");
|
||||
String[] times2 = sleepData2.split("-");
|
||||
if (Integer.valueOf(times1[1]) > Integer.valueOf(times2[1])) {
|
||||
return -1;
|
||||
} else if (Integer.valueOf(times1[1]) == Integer.valueOf(times2[1])) {
|
||||
if (Integer.valueOf(times1[2]) > Integer.valueOf(times2[2])) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,6 +118,19 @@ public class WebUtils {
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取心率
|
||||
*
|
||||
* @param parentId
|
||||
* @param callback
|
||||
*/
|
||||
public void getHeartRates(String parentId, Callback callback) {
|
||||
Request request = new Request.Builder()
|
||||
.url(webHost + "/heartrate/get/" + parentId).build();
|
||||
Call call = mClient.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取房间数据
|
||||
*
|
||||
@@ -184,6 +197,19 @@ public class WebUtils {
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 老人登录
|
||||
*
|
||||
* @param hashMap
|
||||
* @param callback
|
||||
*/
|
||||
public void loginParent(HashMap<String, String> hashMap, Callback callback) {
|
||||
Request request = new Request.Builder().post(getRequestBody(hashMap))
|
||||
.url(webHost + "/parent/login/").build();
|
||||
Call call = mClient.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 孩子绑定老人
|
||||
*
|
||||
@@ -210,4 +236,17 @@ public class WebUtils {
|
||||
Call call = mClient.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取睡眠数据
|
||||
*
|
||||
* @param parentId
|
||||
* @param callback
|
||||
*/
|
||||
public void getSleepData(String parentId, Callback callback) {
|
||||
Request request = new Request.Builder()
|
||||
.url(webHost + "/sleep/get/" + parentId).build();
|
||||
Call call = mClient.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.scorpiomiku.oldpeoplehome.modules.loginregister.LoginActivity">
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/default_bar" />
|
||||
|
||||
@@ -121,12 +119,20 @@
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/is_older"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="老人登录" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/login_btn_login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="#41a4f5"
|
||||
android:elevation="5dp"
|
||||
android:text="登 录"
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="00:00"
|
||||
android:text="0"
|
||||
android:textColor="#FFF"
|
||||
android:textSize="30sp" />
|
||||
|
||||
@@ -98,13 +98,13 @@
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_heart_log" />
|
||||
android:src="@drawable/ic_bloodpressure" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="最小心率"
|
||||
android:text="血压(收缩压)"
|
||||
android:textColor="@color/heart_rate_bg"
|
||||
android:textSize="14sp" />
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/diastolic"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
@@ -128,7 +129,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:gravity="center"
|
||||
android:text="BPM"
|
||||
android:text="mmHg"
|
||||
android:textColor="@color/heart_rate_bg"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
@@ -145,13 +146,13 @@
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_heart_log" />
|
||||
android:src="@drawable/ic_bloodpressure" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="平均心率"
|
||||
android:text="血压(舒张压)"
|
||||
android:textColor="@color/heart_rate_bg"
|
||||
android:textSize="14sp" />
|
||||
|
||||
@@ -163,6 +164,7 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/systolic"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
@@ -175,7 +177,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:gravity="center"
|
||||
android:text="BPM"
|
||||
android:text="mmHg"
|
||||
android:textColor="@color/heart_rate_bg"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
@@ -192,13 +194,13 @@
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_heart_log" />
|
||||
android:src="@drawable/ic_oxy" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="最大心率"
|
||||
android:text="血氧"
|
||||
android:textColor="@color/heart_rate_bg"
|
||||
android:textSize="14sp" />
|
||||
|
||||
@@ -210,6 +212,7 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/oxy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
@@ -222,7 +225,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:gravity="center"
|
||||
android:text="BPM"
|
||||
android:text="HbO2"
|
||||
android:textColor="@color/heart_rate_bg"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deep_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
@@ -105,6 +106,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/light_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
@@ -141,6 +143,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/awake_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
|
||||
@@ -8,10 +8,5 @@
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="SpinnerStyle">
|
||||
<item name="colorAccent">#2f2a94</item>
|
||||
<item name="colorControlNormal">#ddf16565</item> <!--改变了spinner的颜色 -->
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user