Commit 790fc3bf2bb0bddf37ec9a0290bf194e8be08e34
1 parent
90cd21c2ba
Exists in
master
update: fix bug count step
Showing 7 changed files with 200 additions and 25 deletions Inline Diff
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/interfaces/StepListener.java
- app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
- app/src/main/java/com/dinhcv/lifelogpedometer/utils/SensorFusionMath.java
- app/src/main/java/com/dinhcv/lifelogpedometer/utils/SimpleStepDetector.java
app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryContentFragment.java
| 1 | package com.dinhcv.lifelogpedometer.activity; | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | ||
| 3 | import android.app.DatePickerDialog; | 3 | import android.app.DatePickerDialog; |
| 4 | import android.content.Context; | 4 | import android.content.Context; |
| 5 | import android.content.Intent; | 5 | import android.content.Intent; |
| 6 | import android.graphics.Color; | 6 | import android.graphics.Color; |
| 7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
| 8 | import android.view.LayoutInflater; | 8 | import android.view.LayoutInflater; |
| 9 | import android.view.View; | 9 | import android.view.View; |
| 10 | import android.view.ViewGroup; | 10 | import android.view.ViewGroup; |
| 11 | import android.widget.Button; | 11 | import android.widget.Button; |
| 12 | import android.widget.DatePicker; | 12 | import android.widget.DatePicker; |
| 13 | import android.widget.ImageButton; | 13 | import android.widget.ImageButton; |
| 14 | import android.widget.ImageView; | 14 | import android.widget.ImageView; |
| 15 | import android.widget.LinearLayout; | 15 | import android.widget.LinearLayout; |
| 16 | import android.widget.TextView; | 16 | import android.widget.TextView; |
| 17 | 17 | ||
| 18 | import com.dinhcv.lifelogpedometer.R; | 18 | import com.dinhcv.lifelogpedometer.R; |
| 19 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 19 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 20 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; | 20 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; |
| 21 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | 21 | import com.dinhcv.lifelogpedometer.portal.ApiServices; |
| 22 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 22 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 23 | import com.dinhcv.lifelogpedometer.utils.Const; | 23 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 24 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; | 24 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; |
| 25 | import com.dinhcv.lifelogpedometer.utils.Debug; | 25 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 26 | import com.dinhcv.lifelogpedometer.utils.Utils; | 26 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 27 | import com.github.mikephil.charting.charts.BarChart; | 27 | import com.github.mikephil.charting.charts.BarChart; |
| 28 | import com.github.mikephil.charting.components.XAxis; | 28 | import com.github.mikephil.charting.components.XAxis; |
| 29 | import com.github.mikephil.charting.components.YAxis; | 29 | import com.github.mikephil.charting.components.YAxis; |
| 30 | import com.github.mikephil.charting.data.BarData; | 30 | import com.github.mikephil.charting.data.BarData; |
| 31 | import com.github.mikephil.charting.data.BarDataSet; | 31 | import com.github.mikephil.charting.data.BarDataSet; |
| 32 | import com.github.mikephil.charting.data.BarEntry; | 32 | import com.github.mikephil.charting.data.BarEntry; |
| 33 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; | 33 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; |
| 34 | 34 | ||
| 35 | import org.json.JSONException; | 35 | import org.json.JSONException; |
| 36 | import org.json.JSONObject; | 36 | import org.json.JSONObject; |
| 37 | 37 | ||
| 38 | import java.util.ArrayList; | 38 | import java.util.ArrayList; |
| 39 | import java.util.Calendar; | 39 | import java.util.Calendar; |
| 40 | import java.util.Date; | 40 | import java.util.Date; |
| 41 | import java.util.List; | 41 | import java.util.List; |
| 42 | 42 | ||
| 43 | import butterknife.BindView; | 43 | import butterknife.BindView; |
| 44 | import butterknife.ButterKnife; | 44 | import butterknife.ButterKnife; |
| 45 | import butterknife.OnClick; | 45 | import butterknife.OnClick; |
| 46 | 46 | ||
| 47 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; | 47 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; |
| 48 | 48 | ||
| 49 | public class HistoryContentFragment extends FragmentBase { | 49 | public class HistoryContentFragment extends FragmentBase { |
| 50 | 50 | ||
| 51 | @BindView(R.id.btn_left_date) | 51 | @BindView(R.id.btn_left_date) |
| 52 | ImageButton btnLeftDate; | 52 | ImageButton btnLeftDate; |
| 53 | @BindView(R.id.btn_right_date) | 53 | @BindView(R.id.btn_right_date) |
| 54 | ImageButton btnRightDate; | 54 | ImageButton btnRightDate; |
| 55 | @BindView(R.id.tv_date) | 55 | @BindView(R.id.tv_date) |
| 56 | TextView tvDate; | 56 | TextView tvDate; |
| 57 | @BindView(R.id.tv_week_day) | 57 | @BindView(R.id.tv_week_day) |
| 58 | TextView tvWeekDay; | 58 | TextView tvWeekDay; |
| 59 | private ImageView btnFace; | 59 | private ImageView btnFace; |
| 60 | private ImageView btnTwitter; | 60 | private ImageView btnTwitter; |
| 61 | private ImageView btnLine; | 61 | private ImageView btnLine; |
| 62 | private ImageView btnEmail; | 62 | private ImageView btnEmail; |
| 63 | private ImageView btnOther; | 63 | private ImageView btnOther; |
| 64 | @BindView(R.id.tv_steps) | 64 | @BindView(R.id.tv_steps) |
| 65 | TextView tvStep; | 65 | TextView tvStep; |
| 66 | @BindView(R.id.tv_remainingStep) | 66 | @BindView(R.id.tv_remainingStep) |
| 67 | TextView tvRemain; | 67 | TextView tvRemain; |
| 68 | @BindView(R.id.tv_stepRateDone) | 68 | @BindView(R.id.tv_stepRateDone) |
| 69 | TextView tvRateDone; | 69 | TextView tvRateDone; |
| 70 | @BindView(R.id.tv_smallRemain) | 70 | @BindView(R.id.tv_smallRemain) |
| 71 | TextView tvSmallRemain; | 71 | TextView tvSmallRemain; |
| 72 | @BindView(R.id.tv_stepGoal) | 72 | @BindView(R.id.tv_stepGoal) |
| 73 | TextView tvGoal; | 73 | TextView tvGoal; |
| 74 | @BindView(R.id.tv_stepRemain) | ||
| 75 | TextView tv_stepRemain; | ||
| 74 | 76 | ||
| 75 | @BindView(R.id.tv_caloConsumned) | 77 | @BindView(R.id.tv_caloConsumned) |
| 76 | TextView tvCaloConsumned; | 78 | TextView tvCaloConsumned; |
| 77 | @BindView(R.id.tv_distance) | 79 | @BindView(R.id.tv_distance) |
| 78 | TextView tvDistance; | 80 | TextView tvDistance; |
| 79 | @BindView(R.id.tv_time) | 81 | @BindView(R.id.tv_time) |
| 80 | TextView tvTime; | 82 | TextView tvTime; |
| 81 | 83 | ||
| 82 | @BindView(R.id.ll_bike) | 84 | @BindView(R.id.ll_bike) |
| 83 | LinearLayout llBike; | 85 | LinearLayout llBike; |
| 84 | @BindView(R.id.ll_walking) | 86 | @BindView(R.id.ll_walking) |
| 85 | LinearLayout llWalking; | 87 | LinearLayout llWalking; |
| 86 | @BindView(R.id.ll_running) | 88 | @BindView(R.id.ll_running) |
| 87 | LinearLayout llRunning; | 89 | LinearLayout llRunning; |
| 88 | @BindView(R.id.btn_oneDay) | 90 | @BindView(R.id.btn_oneDay) |
| 89 | Button btnOneDay; | 91 | Button btnOneDay; |
| 90 | @BindView(R.id.btn_oneWeek) | 92 | @BindView(R.id.btn_oneWeek) |
| 91 | Button btnOneWeek; | 93 | Button btnOneWeek; |
| 92 | @BindView(R.id.btn_oneMonth) | 94 | @BindView(R.id.btn_oneMonth) |
| 93 | Button btnOneMonth; | 95 | Button btnOneMonth; |
| 94 | @BindView(R.id.btn_threeMonth) | 96 | @BindView(R.id.btn_threeMonth) |
| 95 | Button btnThreeMonth; | 97 | Button btnThreeMonth; |
| 96 | @BindView(R.id.btn_sixMonth) | 98 | @BindView(R.id.btn_sixMonth) |
| 97 | Button btnSixMonth; | 99 | Button btnSixMonth; |
| 98 | 100 | ||
| 99 | // bar chart | 101 | // bar chart |
| 100 | private BarChart mBarChart; | 102 | private BarChart mBarChart; |
| 101 | private List<String> dateList; | 103 | private List<String> dateList; |
| 102 | private String[] mParties; | 104 | private String[] mParties; |
| 103 | private Integer[] mStep; | 105 | private Integer[] mStep; |
| 104 | 106 | ||
| 105 | private Date mAnaDate; | 107 | private Date mAnaDate; |
| 106 | private Calendar mCalendar; | 108 | private Calendar mCalendar; |
| 107 | 109 | ||
| 108 | private int mAnaDay; | 110 | private int mAnaDay; |
| 109 | private int mAnaMonth; | 111 | private int mAnaMonth; |
| 110 | private int mAnaYear; | 112 | private int mAnaYear; |
| 111 | 113 | ||
| 112 | private HistoryInfo mDataModWalking = new HistoryInfo(); | 114 | private HistoryInfo mDataModWalking = new HistoryInfo(); |
| 113 | private HistoryInfo mDataModRunning = new HistoryInfo(); | 115 | private HistoryInfo mDataModRunning = new HistoryInfo(); |
| 114 | private HistoryInfo mDataModBike = new HistoryInfo(); | 116 | private HistoryInfo mDataModBike = new HistoryInfo(); |
| 115 | private HistoryInfo mDataCurrent = new HistoryInfo(); | 117 | private HistoryInfo mDataCurrent = new HistoryInfo(); |
| 116 | 118 | ||
| 117 | private Const.DATA_TYPE dataType; | 119 | private Const.DATA_TYPE dataType; |
| 118 | private Const.STEP_TYPE stepType; | 120 | private Const.STEP_TYPE stepType; |
| 119 | 121 | ||
| 120 | private Context mContext; | 122 | private Context mContext; |
| 121 | private View mRootView; | 123 | private View mRootView; |
| 122 | 124 | ||
| 123 | private HistoryFragment mHistoryFragment; | 125 | private HistoryFragment mHistoryFragment; |
| 124 | 126 | ||
| 125 | public void setRootFragment(HistoryFragment frag) { | 127 | public void setRootFragment(HistoryFragment frag) { |
| 126 | this.mHistoryFragment = frag; | 128 | this.mHistoryFragment = frag; |
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | @Override | 131 | @Override |
| 130 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 132 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 131 | final Bundle savedInstanceState) { | 133 | final Bundle savedInstanceState) { |
| 132 | mRootView = inflater.inflate(R.layout.fragment_history_content, null); | 134 | mRootView = inflater.inflate(R.layout.fragment_history_content, null); |
| 133 | ButterKnife.bind(this, mRootView); | 135 | ButterKnife.bind(this, mRootView); |
| 134 | mContext = getActivity(); | 136 | mContext = getActivity(); |
| 135 | initView(mRootView); | 137 | initView(mRootView); |
| 136 | initData(); | 138 | initData(); |
| 137 | 139 | ||
| 138 | return mRootView; | 140 | return mRootView; |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 141 | 143 | ||
| 142 | private void initView(View view) { | 144 | private void initView(View view) { |
| 143 | btnFace = (ImageView) view.findViewById(R.id.btn_face); | 145 | btnFace = (ImageView) view.findViewById(R.id.btn_face); |
| 144 | btnTwitter = (ImageView) view.findViewById(R.id.btn_twitter); | 146 | btnTwitter = (ImageView) view.findViewById(R.id.btn_twitter); |
| 145 | btnLine = (ImageView) view.findViewById(R.id.btn_line); | 147 | btnLine = (ImageView) view.findViewById(R.id.btn_line); |
| 146 | btnEmail = (ImageView) view.findViewById(R.id.btn_email); | 148 | btnEmail = (ImageView) view.findViewById(R.id.btn_email); |
| 147 | btnOther = (ImageView) view.findViewById(R.id.btn_other); | 149 | btnOther = (ImageView) view.findViewById(R.id.btn_other); |
| 148 | 150 | ||
| 149 | mBarChart = (BarChart) view.findViewById(R.id.chart); | 151 | mBarChart = (BarChart) view.findViewById(R.id.chart); |
| 150 | } | 152 | } |
| 151 | 153 | ||
| 152 | 154 | ||
| 153 | /** | 155 | /** |
| 154 | * Show date picker dialog | 156 | * Show date picker dialog |
| 155 | */ | 157 | */ |
| 156 | private void handleAnaDatePicker() { | 158 | private void handleAnaDatePicker() { |
| 157 | 159 | ||
| 158 | new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { | 160 | new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { |
| 159 | @Override | 161 | @Override |
| 160 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { | 162 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 161 | 163 | ||
| 162 | mCalendar = Calendar.getInstance(); | 164 | mCalendar = Calendar.getInstance(); |
| 163 | mCalendar.set(year, monthOfYear, dayOfMonth); | 165 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 164 | mAnaYear = year; | 166 | mAnaYear = year; |
| 165 | mAnaMonth = monthOfYear; | 167 | mAnaMonth = monthOfYear; |
| 166 | mAnaDay = dayOfMonth; | 168 | mAnaDay = dayOfMonth; |
| 167 | Date date = mCalendar.getTime(); | 169 | Date date = mCalendar.getTime(); |
| 168 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 170 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 169 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); | 171 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); |
| 170 | mAnaDate = date; | 172 | mAnaDate = date; |
| 171 | getHistoryData(dataType, mAnaDate); | 173 | getHistoryData(dataType, mAnaDate); |
| 172 | } | 174 | } |
| 173 | }, mAnaYear, mAnaMonth, mAnaDay).show(); | 175 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 174 | 176 | ||
| 175 | } | 177 | } |
| 176 | 178 | ||
| 177 | 179 | ||
| 178 | /** | 180 | /** |
| 179 | * init data for | 181 | * init data for |
| 180 | */ | 182 | */ |
| 181 | private void initData() { | 183 | private void initData() { |
| 182 | mCalendar = Calendar.getInstance(); | 184 | mCalendar = Calendar.getInstance(); |
| 183 | mCalendar.setTime(new Date()); | 185 | mCalendar.setTime(new Date()); |
| 184 | mAnaDate = mCalendar.getTime(); | 186 | mAnaDate = mCalendar.getTime(); |
| 185 | mAnaYear = mCalendar.get(Calendar.YEAR); | 187 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 186 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 188 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 187 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 189 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 188 | 190 | ||
| 189 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 191 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 190 | tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate)); | 192 | tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate)); |
| 191 | 193 | ||
| 192 | dataType = Const.DATA_TYPE.ONE_DAY; | 194 | dataType = Const.DATA_TYPE.ONE_DAY; |
| 193 | stepType = Const.STEP_TYPE.WALKING; | 195 | stepType = Const.STEP_TYPE.WALKING; |
| 194 | updateUiType(); | 196 | updateUiType(); |
| 195 | updateUiStepType(false, true, false); | 197 | updateUiStepType(false, true, false); |
| 196 | 198 | ||
| 197 | getHistoryData(dataType, mAnaDate); | 199 | getHistoryData(dataType, mAnaDate); |
| 198 | } | 200 | } |
| 199 | 201 | ||
| 200 | private void updateUiType() { | 202 | private void updateUiType() { |
| 201 | if (dataType == Const.DATA_TYPE.ONE_DAY) { | 203 | if (dataType == Const.DATA_TYPE.ONE_DAY) { |
| 202 | setButtonSelected(true, false, false, false, false); | 204 | setButtonSelected(true, false, false, false, false); |
| 203 | } else if (dataType == Const.DATA_TYPE.ONE_WEEK) { | 205 | } else if (dataType == Const.DATA_TYPE.ONE_WEEK) { |
| 204 | setButtonSelected(false, true, false, false, false); | 206 | setButtonSelected(false, true, false, false, false); |
| 205 | } else if (dataType == Const.DATA_TYPE.ONE_MONTH) { | 207 | } else if (dataType == Const.DATA_TYPE.ONE_MONTH) { |
| 206 | setButtonSelected(false, false, true, false, false); | 208 | setButtonSelected(false, false, true, false, false); |
| 207 | } else if (dataType == Const.DATA_TYPE.THREE_MONTH){ | 209 | } else if (dataType == Const.DATA_TYPE.THREE_MONTH){ |
| 208 | setButtonSelected(false, false, false, true, false); | 210 | setButtonSelected(false, false, false, true, false); |
| 209 | } else if (dataType == Const.DATA_TYPE.SIX_MONTH){ | 211 | } else if (dataType == Const.DATA_TYPE.SIX_MONTH){ |
| 210 | setButtonSelected(false, false, false, false, true); | 212 | setButtonSelected(false, false, false, false, true); |
| 211 | } | 213 | } |
| 212 | } | 214 | } |
| 213 | 215 | ||
| 214 | private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) { | 216 | private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) { |
| 215 | btnOneDay.setSelected(b1); | 217 | btnOneDay.setSelected(b1); |
| 216 | btnOneWeek.setSelected(b2); | 218 | btnOneWeek.setSelected(b2); |
| 217 | btnOneMonth.setSelected(b3); | 219 | btnOneMonth.setSelected(b3); |
| 218 | btnThreeMonth.setSelected(b4); | 220 | btnThreeMonth.setSelected(b4); |
| 219 | btnSixMonth.setSelected(b5); | 221 | btnSixMonth.setSelected(b5); |
| 220 | } | 222 | } |
| 221 | 223 | ||
| 222 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 224 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 223 | llBike.setSelected(b1); | 225 | llBike.setSelected(b1); |
| 224 | llWalking.setSelected(b2); | 226 | llWalking.setSelected(b2); |
| 225 | llRunning.setSelected(b3); | 227 | llRunning.setSelected(b3); |
| 226 | } | 228 | } |
| 227 | 229 | ||
| 228 | private void getHistoryData(Const.DATA_TYPE dataType, Date toDate){ | 230 | private void getHistoryData(Const.DATA_TYPE dataType, Date toDate){ |
| 229 | 231 | ||
| 230 | Date fromDate = Utils.getFromDate(mAnaDate, dataType); | 232 | Date fromDate = Utils.getFromDate(mAnaDate, dataType); |
| 231 | 233 | ||
| 232 | showDialog(mContext); | 234 | showDialog(mContext); |
| 233 | ApiServices.history(fromDate, toDate, new LLAPIManagerListener() { | 235 | ApiServices.history(fromDate, toDate, new LLAPIManagerListener() { |
| 234 | @Override | 236 | @Override |
| 235 | public void onError(Error error) { | 237 | public void onError(Error error) { |
| 236 | Debug.error("Get data history error"); | 238 | Debug.error("Get data history error"); |
| 237 | hiddenDialog(); | 239 | hiddenDialog(); |
| 238 | showDialogNotData(); | 240 | showDialogNotData(); |
| 239 | } | 241 | } |
| 240 | 242 | ||
| 241 | @Override | 243 | @Override |
| 242 | public void onSuccess(String json) { | 244 | public void onSuccess(String json) { |
| 243 | Debug.error("Get data history success"); | 245 | Debug.error("Get data history success"); |
| 244 | hiddenDialog(); | 246 | hiddenDialog(); |
| 245 | loadDataDone(json); | 247 | loadDataDone(json); |
| 246 | } | 248 | } |
| 247 | 249 | ||
| 248 | @Override | 250 | @Override |
| 249 | public void onSuccess(JSONObject object) { | 251 | public void onSuccess(JSONObject object) { |
| 250 | Debug.error("Get data history success"); | 252 | Debug.error("Get data history success"); |
| 251 | hiddenDialog(); | 253 | hiddenDialog(); |
| 252 | } | 254 | } |
| 253 | }); | 255 | }); |
| 254 | } | 256 | } |
| 255 | 257 | ||
| 256 | private void showDialogNotData(){ | 258 | private void showDialogNotData(){ |
| 257 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 259 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 258 | } | 260 | } |
| 259 | 261 | ||
| 260 | private void loadDataDone(String jsonString) { | 262 | private void loadDataDone(String jsonString) { |
| 261 | JSONObject jsonObject = null; | 263 | JSONObject jsonObject = null; |
| 262 | try { | 264 | try { |
| 263 | jsonObject = new JSONObject(jsonString); | 265 | jsonObject = new JSONObject(jsonString); |
| 264 | int status = jsonObject.optInt("status"); | 266 | int status = jsonObject.optInt("status"); |
| 265 | if (status == 1) { | 267 | if (status == 1) { |
| 266 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 268 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 267 | JSONObject jsonMod1 = jsonObject1.getJSONObject("mode_1"); | 269 | JSONObject jsonMod1 = jsonObject1.optJSONObject("mode_1"); |
| 268 | JSONObject jsonMod2 = jsonObject1.getJSONObject("mode_2"); | 270 | JSONObject jsonMod2 = jsonObject1.optJSONObject("mode_2"); |
| 269 | JSONObject jsonMod3 = jsonObject1.getJSONObject("mode_3"); | 271 | JSONObject jsonMod3 = jsonObject1.optJSONObject("mode_3"); |
| 270 | addDataModWalking(jsonMod1); | 272 | if (jsonMod1 != null)addDataModWalking(jsonMod1); |
| 271 | addDataModRunning(jsonMod2); | 273 | if (jsonMod2 != null)addDataModRunning(jsonMod2); |
| 272 | addDataModBike(jsonMod3); | 274 | if (jsonMod3 != null)addDataModBike(jsonMod3); |
| 273 | 275 | ||
| 274 | } | 276 | } |
| 275 | } catch (JSONException e) { | 277 | } catch (JSONException e) { |
| 276 | e.printStackTrace(); | 278 | e.printStackTrace(); |
| 277 | mDataModWalking = new HistoryInfo(); | 279 | mDataModWalking = new HistoryInfo(); |
| 278 | mDataModRunning = new HistoryInfo();; | 280 | mDataModRunning = new HistoryInfo();; |
| 279 | mDataModBike = new HistoryInfo();; | 281 | mDataModBike = new HistoryInfo();; |
| 280 | } | 282 | } |
| 281 | 283 | ||
| 282 | if (stepType == Const.STEP_TYPE.WALKING){ | 284 | if (stepType == Const.STEP_TYPE.WALKING){ |
| 283 | mDataCurrent = mDataModWalking; | 285 | mDataCurrent = mDataModWalking; |
| 284 | }else if (stepType == Const.STEP_TYPE.RUNNING){ | 286 | }else if (stepType == Const.STEP_TYPE.RUNNING){ |
| 285 | mDataCurrent = mDataModRunning; | 287 | mDataCurrent = mDataModRunning; |
| 286 | }else { | 288 | }else { |
| 287 | mDataCurrent = mDataModBike; | 289 | mDataCurrent = mDataModBike; |
| 288 | } | 290 | } |
| 289 | 291 | ||
| 290 | updateUI(); | 292 | updateUI(); |
| 291 | } | 293 | } |
| 292 | 294 | ||
| 293 | private void updateUI(){ | 295 | private void updateUI(){ |
| 294 | // get data server | 296 | // get data server |
| 295 | tvGoal.setText(getResources().getString(R.string.step_unit, mDataCurrent.getTaget())); | 297 | tvGoal.setText(getResources().getString(R.string.step_unit, mDataCurrent.getTaget())); |
| 296 | tvStep.setText(getResources().getString(R.string.step_unit, mDataCurrent.getSteps())); | 298 | tvStep.setText(getResources().getString(R.string.step_unit, mDataCurrent.getSteps())); |
| 297 | tvSmallRemain.setText(getResources().getString(R.string.step_unit_1, mDataCurrent.getStepRemain())); | 299 | tvSmallRemain.setText(getResources().getString(R.string.step_unit_1, mDataCurrent.getStepRemain())); |
| 300 | tv_stepRemain.setText(mDataCurrent.getStepRemain() + getResources().getString(R.string.step)); | ||
| 298 | tvRemain.setText(getResources().getString(R.string.step_unit, mDataCurrent.getStepRemain())); | 301 | tvRemain.setText(getResources().getString(R.string.step_unit, mDataCurrent.getStepRemain())); |
| 299 | tvRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(mDataCurrent.getCompletePercent()))); | 302 | tvRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(mDataCurrent.getCompletePercent()))); |
| 300 | tvCaloConsumned.setText(getResources().getString(R.string.kcal_unit, Utils.convert2String2Decimal(mDataCurrent.getKcal()))); | 303 | tvCaloConsumned.setText(getResources().getString(R.string.kcal_unit, Utils.convert2String2Decimal(mDataCurrent.getKcal()))); |
| 301 | tvDistance.setText(getResources().getString(R.string.distance_unit, Utils.convert2String2Decimal(mDataCurrent.getDistance()))); | 304 | tvDistance.setText(getResources().getString(R.string.distance_unit, Utils.convert2String2Decimal(mDataCurrent.getDistance()))); |
| 302 | tvTime.setText(getResources().getString(R.string.time_unit, Utils.convertTimeStringFromString(mDataCurrent.getTime()))); | 305 | tvTime.setText(getResources().getString(R.string.time_unit, Utils.convertTimeStringFromString(mDataCurrent.getTime()))); |
| 303 | 306 | ||
| 304 | // update bar | 307 | // update bar |
| 305 | if (mDataCurrent.getDataChart() != null && mDataCurrent.getDataChart().size() == 24) { | 308 | if (mDataCurrent.getDataChart() != null && mDataCurrent.getDataChart().size() == 24) { |
| 306 | updateBars(); | 309 | updateBars(); |
| 307 | } | 310 | } |
| 308 | 311 | ||
| 309 | } | 312 | } |
| 310 | 313 | ||
| 311 | private void updateBars() { | 314 | private void updateBars() { |
| 312 | dateList = new ArrayList<>(); | 315 | dateList = new ArrayList<>(); |
| 313 | List<Integer> stepList = new ArrayList<>(); | 316 | List<Integer> stepList = new ArrayList<>(); |
| 314 | 317 | ||
| 315 | stepList = mDataCurrent.getDataChart(); | 318 | stepList = mDataCurrent.getDataChart(); |
| 316 | for (int i = 0; i < 24; i++){ | 319 | for (int i = 0; i < 24; i++){ |
| 317 | dateList.add(String.valueOf(i)); | 320 | dateList.add(String.valueOf(i)); |
| 318 | } | 321 | } |
| 319 | 322 | ||
| 320 | mStep = stepList.toArray(new Integer[0]); | 323 | mStep = stepList.toArray(new Integer[0]); |
| 321 | mParties = dateList.toArray(new String[0]); | 324 | mParties = dateList.toArray(new String[0]); |
| 322 | 325 | ||
| 323 | initGraph(); | 326 | initGraph(); |
| 324 | } | 327 | } |
| 325 | 328 | ||
| 326 | private void initGraph(){ | 329 | private void initGraph(){ |
| 327 | 330 | ||
| 328 | mBarChart.setDrawBarShadow(false); | 331 | mBarChart.setDrawBarShadow(false); |
| 329 | mBarChart.setDrawValueAboveBar(true); | 332 | mBarChart.setDrawValueAboveBar(true); |
| 330 | 333 | ||
| 331 | // if more than 60 entries are displayed in the chart, no values will be | 334 | // if more than 60 entries are displayed in the chart, no values will be |
| 332 | // drawn | 335 | // drawn |
| 333 | mBarChart.setMaxVisibleValueCount(60); | 336 | mBarChart.setMaxVisibleValueCount(60); |
| 334 | 337 | ||
| 335 | mBarChart.getDescription().setEnabled(false); | 338 | mBarChart.getDescription().setEnabled(false); |
| 336 | // scaling can now only be done on x- and y-axis separately | 339 | // scaling can now only be done on x- and y-axis separately |
| 337 | mBarChart.setPinchZoom(false); | 340 | mBarChart.setPinchZoom(false); |
| 338 | 341 | ||
| 339 | mBarChart.setDrawGridBackground(false); | 342 | mBarChart.setDrawGridBackground(false); |
| 340 | // mChart.setDrawYLabels(false); | 343 | // mChart.setDrawYLabels(false); |
| 341 | 344 | ||
| 342 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(dateList); | 345 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(dateList); |
| 343 | 346 | ||
| 344 | XAxis xAxis = mBarChart.getXAxis(); | 347 | XAxis xAxis = mBarChart.getXAxis(); |
| 345 | xAxis.setLabelRotationAngle(0); | 348 | xAxis.setLabelRotationAngle(0); |
| 346 | xAxis.setPosition(XAxis.XAxisPosition.TOP); | 349 | xAxis.setPosition(XAxis.XAxisPosition.TOP); |
| 347 | xAxis.setDrawGridLines(true); | 350 | xAxis.setDrawGridLines(true); |
| 348 | xAxis.setLabelCount(10); | 351 | xAxis.setLabelCount(10); |
| 349 | xAxis.setTextColor(Color.WHITE); | 352 | xAxis.setTextColor(Color.WHITE); |
| 350 | xAxis.setValueFormatter(xValueFormatter); | 353 | xAxis.setValueFormatter(xValueFormatter); |
| 351 | 354 | ||
| 352 | 355 | ||
| 353 | YAxis leftAxis = mBarChart.getAxisLeft(); | 356 | YAxis leftAxis = mBarChart.getAxisLeft(); |
| 354 | leftAxis.setDrawLabels(false); | 357 | leftAxis.setDrawLabels(false); |
| 355 | leftAxis.setDrawGridLines(false); | 358 | leftAxis.setDrawGridLines(false); |
| 356 | leftAxis.setAxisMinimum(0f); | 359 | leftAxis.setAxisMinimum(0f); |
| 357 | leftAxis.setAxisMaximum(10000f); | 360 | leftAxis.setAxisMaximum(10000f); |
| 358 | leftAxis.setDrawZeroLine(false); | 361 | leftAxis.setDrawZeroLine(false); |
| 359 | 362 | ||
| 360 | leftAxis.setEnabled(false); | 363 | leftAxis.setEnabled(false); |
| 361 | mBarChart.setDrawValueAboveBar(false); | 364 | mBarChart.setDrawValueAboveBar(false); |
| 362 | mBarChart.getAxisRight().setEnabled(false); | 365 | mBarChart.getAxisRight().setEnabled(false); |
| 363 | 366 | ||
| 364 | // set auto scale min max | 367 | // set auto scale min max |
| 365 | mBarChart.setAutoScaleMinMaxEnabled(true); | 368 | mBarChart.setAutoScaleMinMaxEnabled(true); |
| 366 | mBarChart.notifyDataSetChanged(); | 369 | mBarChart.notifyDataSetChanged(); |
| 367 | 370 | ||
| 368 | // Set enimate y | 371 | // Set enimate y |
| 369 | mBarChart.animateY(2000); | 372 | mBarChart.animateY(2000); |
| 370 | 373 | ||
| 371 | setData(); | 374 | setData(); |
| 372 | 375 | ||
| 373 | mBarChart.getLegend().setEnabled(false); | 376 | mBarChart.getLegend().setEnabled(false); |
| 374 | } | 377 | } |
| 375 | 378 | ||
| 376 | 379 | ||
| 377 | private void setData() { | 380 | private void setData() { |
| 378 | 381 | ||
| 379 | ArrayList<String> xVals = new ArrayList<>(); | 382 | ArrayList<String> xVals = new ArrayList<>(); |
| 380 | for (int i = 0; i < mStep.length; i++) { | 383 | for (int i = 0; i < mStep.length; i++) { |
| 381 | xVals.add(mParties[i % mStep.length]); | 384 | xVals.add(mParties[i % mStep.length]); |
| 382 | } | 385 | } |
| 383 | 386 | ||
| 384 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); | 387 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); |
| 385 | for (int i = 0; i < mStep.length; i++) { | 388 | for (int i = 0; i < mStep.length; i++) { |
| 386 | float val = (float) (mStep[i]*1); | 389 | float val = (float) (mStep[i]*1); |
| 387 | yVals1.add(new BarEntry(i, val)); | 390 | yVals1.add(new BarEntry(i, val)); |
| 388 | } | 391 | } |
| 389 | 392 | ||
| 390 | BarDataSet set1; | 393 | BarDataSet set1; |
| 391 | 394 | ||
| 392 | if (mBarChart.getData() != null && mBarChart.getData().getDataSetCount() > 0) { | 395 | if (mBarChart.getData() != null && mBarChart.getData().getDataSetCount() > 0) { |
| 393 | set1 = (BarDataSet)mBarChart.getData().getDataSetByIndex(0); | 396 | set1 = (BarDataSet)mBarChart.getData().getDataSetByIndex(0); |
| 394 | set1.setValues(yVals1); | 397 | set1.setValues(yVals1); |
| 395 | mBarChart.getData().notifyDataChanged(); | 398 | mBarChart.getData().notifyDataChanged(); |
| 396 | mBarChart.notifyDataSetChanged(); | 399 | mBarChart.notifyDataSetChanged(); |
| 397 | } else { | 400 | } else { |
| 398 | ArrayList<Integer> colors = new ArrayList<>(); | 401 | ArrayList<Integer> colors = new ArrayList<>(); |
| 399 | 402 | ||
| 400 | 403 | ||
| 401 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; | 404 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; |
| 402 | 405 | ||
| 403 | for (int c : MATERIAL_COLORS) | 406 | for (int c : MATERIAL_COLORS) |
| 404 | colors.add(c); | 407 | colors.add(c); |
| 405 | 408 | ||
| 406 | set1 = new BarDataSet(yVals1, null); | 409 | set1 = new BarDataSet(yVals1, null); |
| 407 | 410 | ||
| 408 | set1.setColors(colors); | 411 | set1.setColors(colors); |
| 409 | 412 | ||
| 410 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); | 413 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); |
| 411 | dataSets.add(set1); | 414 | dataSets.add(set1); |
| 412 | 415 | ||
| 413 | BarData data = new BarData(dataSets); | 416 | BarData data = new BarData(dataSets); |
| 414 | data.setValueTextSize(10f); | 417 | data.setValueTextSize(10f); |
| 415 | 418 | ||
| 416 | mBarChart.setData(data); | 419 | mBarChart.setData(data); |
| 417 | } | 420 | } |
| 418 | } | 421 | } |
| 419 | 422 | ||
| 420 | private void addDataModWalking(JSONObject jsonObject){ | 423 | private void addDataModWalking(JSONObject jsonObject){ |
| 421 | if (jsonObject == null) return; | 424 | if (jsonObject == null) return; |
| 422 | mDataModWalking.setTaget(jsonObject.optInt("target")); | 425 | mDataModWalking.setTaget(jsonObject.optInt("target")); |
| 423 | mDataModWalking.setSteps(jsonObject.optInt("steps")); | 426 | mDataModWalking.setSteps(jsonObject.optInt("steps")); |
| 424 | mDataModWalking.setStepRemain(jsonObject.optInt("step_remain")); | 427 | mDataModWalking.setStepRemain(jsonObject.optInt("step_remain")); |
| 425 | mDataModWalking.setCompletePercent(jsonObject.optDouble("complete_percent")); | 428 | mDataModWalking.setCompletePercent(jsonObject.optDouble("complete_percent")); |
| 426 | mDataModWalking.setTime(jsonObject.optInt("time")); | 429 | mDataModWalking.setTime(jsonObject.optInt("time")); |
| 427 | mDataModWalking.setDistance(jsonObject.optInt("distance")); | 430 | mDataModWalking.setDistance(jsonObject.optInt("distance")); |
| 428 | mDataModWalking.setKcal(jsonObject.optInt("kcal")); | 431 | mDataModWalking.setKcal(jsonObject.optInt("kcal")); |
| 429 | 432 | ||
| 430 | JSONObject dataChart = jsonObject.optJSONObject("data_chart"); | 433 | JSONObject dataChart = jsonObject.optJSONObject("data_chart"); |
| 431 | ArrayList<Integer> dataChartList = new ArrayList<>(); | 434 | ArrayList<Integer> dataChartList = new ArrayList<>(); |
| 432 | dataChartList.add(dataChart.optInt("0")); | 435 | dataChartList.add(dataChart.optInt("0")); |
| 433 | dataChartList.add(dataChart.optInt("1")); | 436 | dataChartList.add(dataChart.optInt("1")); |
| 434 | dataChartList.add(dataChart.optInt("2")); | 437 | dataChartList.add(dataChart.optInt("2")); |
| 435 | dataChartList.add(dataChart.optInt("3")); | 438 | dataChartList.add(dataChart.optInt("3")); |
| 436 | dataChartList.add(dataChart.optInt("4")); | 439 | dataChartList.add(dataChart.optInt("4")); |
| 437 | dataChartList.add(dataChart.optInt("5")); | 440 | dataChartList.add(dataChart.optInt("5")); |
| 438 | dataChartList.add(dataChart.optInt("6")); | 441 | dataChartList.add(dataChart.optInt("6")); |
| 439 | dataChartList.add(dataChart.optInt("7")); | 442 | dataChartList.add(dataChart.optInt("7")); |
| 440 | dataChartList.add(dataChart.optInt("8")); | 443 | dataChartList.add(dataChart.optInt("8")); |
| 441 | dataChartList.add(dataChart.optInt("9")); | 444 | dataChartList.add(dataChart.optInt("9")); |
| 442 | dataChartList.add(dataChart.optInt("10")); | 445 | dataChartList.add(dataChart.optInt("10")); |
| 443 | dataChartList.add(dataChart.optInt("11")); | 446 | dataChartList.add(dataChart.optInt("11")); |
| 444 | dataChartList.add(dataChart.optInt("12")); | 447 | dataChartList.add(dataChart.optInt("12")); |
| 445 | dataChartList.add(dataChart.optInt("13")); | 448 | dataChartList.add(dataChart.optInt("13")); |
| 446 | dataChartList.add(dataChart.optInt("14")); | 449 | dataChartList.add(dataChart.optInt("14")); |
| 447 | dataChartList.add(dataChart.optInt("15")); | 450 | dataChartList.add(dataChart.optInt("15")); |
| 448 | dataChartList.add(dataChart.optInt("16")); | 451 | dataChartList.add(dataChart.optInt("16")); |
| 449 | dataChartList.add(dataChart.optInt("17")); | 452 | dataChartList.add(dataChart.optInt("17")); |
| 450 | dataChartList.add(dataChart.optInt("18")); | 453 | dataChartList.add(dataChart.optInt("18")); |
| 451 | dataChartList.add(dataChart.optInt("19")); | 454 | dataChartList.add(dataChart.optInt("19")); |
| 452 | dataChartList.add(dataChart.optInt("20")); | 455 | dataChartList.add(dataChart.optInt("20")); |
| 453 | dataChartList.add(dataChart.optInt("21")); | 456 | dataChartList.add(dataChart.optInt("21")); |
| 454 | dataChartList.add(dataChart.optInt("22")); | 457 | dataChartList.add(dataChart.optInt("22")); |
| 455 | dataChartList.add(dataChart.optInt("23")); | 458 | dataChartList.add(dataChart.optInt("23")); |
| 456 | 459 | ||
| 457 | mDataModWalking.setDataChart(dataChartList); | 460 | mDataModWalking.setDataChart(dataChartList); |
| 458 | } | 461 | } |
| 459 | 462 | ||
| 460 | private void addDataModRunning(JSONObject jsonObject){ | 463 | private void addDataModRunning(JSONObject jsonObject){ |
| 461 | if (jsonObject == null) return; | 464 | if (jsonObject == null) return; |
| 462 | mDataModRunning.setTaget(jsonObject.optInt("target")); | 465 | mDataModRunning.setTaget(jsonObject.optInt("target")); |
| 463 | mDataModRunning.setSteps(jsonObject.optInt("steps")); | 466 | mDataModRunning.setSteps(jsonObject.optInt("steps")); |
| 464 | mDataModRunning.setStepRemain(jsonObject.optInt("step_remain")); | 467 | mDataModRunning.setStepRemain(jsonObject.optInt("step_remain")); |
| 465 | mDataModRunning.setCompletePercent(jsonObject.optDouble("complete_percent")); | 468 | mDataModRunning.setCompletePercent(jsonObject.optDouble("complete_percent")); |
| 466 | mDataModRunning.setTime(jsonObject.optInt("time")); | 469 | mDataModRunning.setTime(jsonObject.optInt("time")); |
| 467 | mDataModRunning.setDistance(jsonObject.optInt("distance")); | 470 | mDataModRunning.setDistance(jsonObject.optInt("distance")); |
| 468 | mDataModRunning.setKcal(jsonObject.optInt("kcal")); | 471 | mDataModRunning.setKcal(jsonObject.optInt("kcal")); |
| 469 | 472 | ||
| 470 | JSONObject dataChart = jsonObject.optJSONObject("data_chart"); | 473 | JSONObject dataChart = jsonObject.optJSONObject("data_chart"); |
| 471 | ArrayList<Integer> dataChartList = new ArrayList<>(); | 474 | ArrayList<Integer> dataChartList = new ArrayList<>(); |
| 472 | dataChartList.add(dataChart.optInt("0")); | 475 | dataChartList.add(dataChart.optInt("0")); |
| 473 | dataChartList.add(dataChart.optInt("1")); | 476 | dataChartList.add(dataChart.optInt("1")); |
| 474 | dataChartList.add(dataChart.optInt("2")); | 477 | dataChartList.add(dataChart.optInt("2")); |
| 475 | dataChartList.add(dataChart.optInt("3")); | 478 | dataChartList.add(dataChart.optInt("3")); |
| 476 | dataChartList.add(dataChart.optInt("4")); | 479 | dataChartList.add(dataChart.optInt("4")); |
| 477 | dataChartList.add(dataChart.optInt("5")); | 480 | dataChartList.add(dataChart.optInt("5")); |
| 478 | dataChartList.add(dataChart.optInt("6")); | 481 | dataChartList.add(dataChart.optInt("6")); |
| 479 | dataChartList.add(dataChart.optInt("7")); | 482 | dataChartList.add(dataChart.optInt("7")); |
| 480 | dataChartList.add(dataChart.optInt("8")); | 483 | dataChartList.add(dataChart.optInt("8")); |
| 481 | dataChartList.add(dataChart.optInt("9")); | 484 | dataChartList.add(dataChart.optInt("9")); |
| 482 | dataChartList.add(dataChart.optInt("10")); | 485 | dataChartList.add(dataChart.optInt("10")); |
| 483 | dataChartList.add(dataChart.optInt("11")); | 486 | dataChartList.add(dataChart.optInt("11")); |
| 484 | dataChartList.add(dataChart.optInt("12")); | 487 | dataChartList.add(dataChart.optInt("12")); |
| 485 | dataChartList.add(dataChart.optInt("13")); | 488 | dataChartList.add(dataChart.optInt("13")); |
| 486 | dataChartList.add(dataChart.optInt("14")); | 489 | dataChartList.add(dataChart.optInt("14")); |
| 487 | dataChartList.add(dataChart.optInt("15")); | 490 | dataChartList.add(dataChart.optInt("15")); |
| 488 | dataChartList.add(dataChart.optInt("16")); | 491 | dataChartList.add(dataChart.optInt("16")); |
| 489 | dataChartList.add(dataChart.optInt("17")); | 492 | dataChartList.add(dataChart.optInt("17")); |
| 490 | dataChartList.add(dataChart.optInt("18")); | 493 | dataChartList.add(dataChart.optInt("18")); |
| 491 | dataChartList.add(dataChart.optInt("19")); | 494 | dataChartList.add(dataChart.optInt("19")); |
| 492 | dataChartList.add(dataChart.optInt("20")); | 495 | dataChartList.add(dataChart.optInt("20")); |
| 493 | dataChartList.add(dataChart.optInt("21")); | 496 | dataChartList.add(dataChart.optInt("21")); |
| 494 | dataChartList.add(dataChart.optInt("22")); | 497 | dataChartList.add(dataChart.optInt("22")); |
| 495 | dataChartList.add(dataChart.optInt("23")); | 498 | dataChartList.add(dataChart.optInt("23")); |
| 496 | 499 | ||
| 497 | mDataModRunning.setDataChart(dataChartList); | 500 | mDataModRunning.setDataChart(dataChartList); |
| 498 | } | 501 | } |
| 499 | 502 | ||
| 500 | private void addDataModBike(JSONObject jsonObject){ | 503 | private void addDataModBike(JSONObject jsonObject){ |
| 501 | if (jsonObject == null) return; | 504 | if (jsonObject == null) return; |
| 502 | mDataModBike.setTaget(jsonObject.optInt("target")); | 505 | mDataModBike.setTaget(jsonObject.optInt("target")); |
| 503 | mDataModBike.setSteps(jsonObject.optInt("steps")); | 506 | mDataModBike.setSteps(jsonObject.optInt("steps")); |
| 504 | mDataModBike.setStepRemain(jsonObject.optInt("step_remain")); | 507 | mDataModBike.setStepRemain(jsonObject.optInt("step_remain")); |
| 505 | mDataModBike.setCompletePercent(jsonObject.optDouble("complete_percent")); | 508 | mDataModBike.setCompletePercent(jsonObject.optDouble("complete_percent")); |
| 506 | mDataModBike.setTime(jsonObject.optInt("time")); | 509 | mDataModBike.setTime(jsonObject.optInt("time")); |
| 507 | mDataModBike.setDistance(jsonObject.optInt("distance")); | 510 | mDataModBike.setDistance(jsonObject.optInt("distance")); |
| 508 | mDataModBike.setKcal(jsonObject.optInt("kcal")); | 511 | mDataModBike.setKcal(jsonObject.optInt("kcal")); |
| 509 | 512 | ||
| 510 | JSONObject dataChart = jsonObject.optJSONObject("data_chart"); | 513 | JSONObject dataChart = jsonObject.optJSONObject("data_chart"); |
| 511 | ArrayList<Integer> dataChartList = new ArrayList<>(); | 514 | ArrayList<Integer> dataChartList = new ArrayList<>(); |
| 512 | dataChartList.add(dataChart.optInt("0")); | 515 | dataChartList.add(dataChart.optInt("0")); |
| 513 | dataChartList.add(dataChart.optInt("1")); | 516 | dataChartList.add(dataChart.optInt("1")); |
| 514 | dataChartList.add(dataChart.optInt("2")); | 517 | dataChartList.add(dataChart.optInt("2")); |
| 515 | dataChartList.add(dataChart.optInt("3")); | 518 | dataChartList.add(dataChart.optInt("3")); |
| 516 | dataChartList.add(dataChart.optInt("4")); | 519 | dataChartList.add(dataChart.optInt("4")); |
| 517 | dataChartList.add(dataChart.optInt("5")); | 520 | dataChartList.add(dataChart.optInt("5")); |
| 518 | dataChartList.add(dataChart.optInt("6")); | 521 | dataChartList.add(dataChart.optInt("6")); |
| 519 | dataChartList.add(dataChart.optInt("7")); | 522 | dataChartList.add(dataChart.optInt("7")); |
| 520 | dataChartList.add(dataChart.optInt("8")); | 523 | dataChartList.add(dataChart.optInt("8")); |
| 521 | dataChartList.add(dataChart.optInt("9")); | 524 | dataChartList.add(dataChart.optInt("9")); |
| 522 | dataChartList.add(dataChart.optInt("10")); | 525 | dataChartList.add(dataChart.optInt("10")); |
| 523 | dataChartList.add(dataChart.optInt("11")); | 526 | dataChartList.add(dataChart.optInt("11")); |
| 524 | dataChartList.add(dataChart.optInt("12")); | 527 | dataChartList.add(dataChart.optInt("12")); |
| 525 | dataChartList.add(dataChart.optInt("13")); | 528 | dataChartList.add(dataChart.optInt("13")); |
| 526 | dataChartList.add(dataChart.optInt("14")); | 529 | dataChartList.add(dataChart.optInt("14")); |
| 527 | dataChartList.add(dataChart.optInt("15")); | 530 | dataChartList.add(dataChart.optInt("15")); |
| 528 | dataChartList.add(dataChart.optInt("16")); | 531 | dataChartList.add(dataChart.optInt("16")); |
| 529 | dataChartList.add(dataChart.optInt("17")); | 532 | dataChartList.add(dataChart.optInt("17")); |
| 530 | dataChartList.add(dataChart.optInt("18")); | 533 | dataChartList.add(dataChart.optInt("18")); |
| 531 | dataChartList.add(dataChart.optInt("19")); | 534 | dataChartList.add(dataChart.optInt("19")); |
| 532 | dataChartList.add(dataChart.optInt("20")); | 535 | dataChartList.add(dataChart.optInt("20")); |
| 533 | dataChartList.add(dataChart.optInt("21")); | 536 | dataChartList.add(dataChart.optInt("21")); |
| 534 | dataChartList.add(dataChart.optInt("22")); | 537 | dataChartList.add(dataChart.optInt("22")); |
| 535 | dataChartList.add(dataChart.optInt("23")); | 538 | dataChartList.add(dataChart.optInt("23")); |
| 536 | 539 | ||
| 537 | mDataModBike.setDataChart(dataChartList); | 540 | mDataModBike.setDataChart(dataChartList); |
| 538 | } | 541 | } |
| 539 | 542 | ||
| 540 | @OnClick({R.id.btn_oneDay, R.id.btn_oneWeek, R.id.btn_oneMonth, R.id.btn_threeMonth, | 543 | @OnClick({R.id.btn_oneDay, R.id.btn_oneWeek, R.id.btn_oneMonth, R.id.btn_threeMonth, |
| 541 | R.id.btn_sixMonth, R.id.btn_left_date, R.id.btn_right_date, R.id.ll_bike, | 544 | R.id.btn_sixMonth, R.id.btn_left_date, R.id.btn_right_date, R.id.ll_bike, |
| 542 | R.id.ll_walking, R.id.ll_running, R.id.rl_stepView}) | 545 | R.id.ll_walking, R.id.ll_running, R.id.rl_stepView}) |
| 543 | public void onClick(View v){ | 546 | public void onClick(View v){ |
| 544 | switch (v.getId()){ | 547 | switch (v.getId()){ |
| 545 | case R.id.btn_left_date: | 548 | case R.id.btn_left_date: |
| 546 | mCalendar = Calendar.getInstance(); | 549 | mCalendar = Calendar.getInstance(); |
| 547 | mCalendar.setTime(mAnaDate); | 550 | mCalendar.setTime(mAnaDate); |
| 548 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 551 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 549 | Date date = mCalendar.getTime(); | 552 | Date date = mCalendar.getTime(); |
| 550 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 553 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 551 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); | 554 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); |
| 552 | mAnaDate = date; | 555 | mAnaDate = date; |
| 553 | getHistoryData(dataType, mAnaDate); | 556 | getHistoryData(dataType, mAnaDate); |
| 554 | break; | 557 | break; |
| 555 | 558 | ||
| 556 | case R.id.btn_right_date: | 559 | case R.id.btn_right_date: |
| 557 | mCalendar = Calendar.getInstance(); | 560 | mCalendar = Calendar.getInstance(); |
| 558 | mCalendar.setTime(mAnaDate); | 561 | mCalendar.setTime(mAnaDate); |
| 559 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 562 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); |
| 560 | Date date1 = mCalendar.getTime(); | 563 | Date date1 = mCalendar.getTime(); |
| 561 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date1)); | 564 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date1)); |
| 562 | tvWeekDay.setText(Utils.getWeekdayFromDate(date1)); | 565 | tvWeekDay.setText(Utils.getWeekdayFromDate(date1)); |
| 563 | mAnaDate = date1; | 566 | mAnaDate = date1; |
| 564 | getHistoryData(dataType, mAnaDate); | 567 | getHistoryData(dataType, mAnaDate); |
| 565 | break; | 568 | break; |
| 566 | 569 | ||
| 567 | case R.id.btn_oneDay: | 570 | case R.id.btn_oneDay: |
| 568 | dataType = Const.DATA_TYPE.ONE_DAY; | 571 | dataType = Const.DATA_TYPE.ONE_DAY; |
| 569 | updateUiType(); | 572 | updateUiType(); |
| 570 | getHistoryData(dataType, mAnaDate); | 573 | getHistoryData(dataType, mAnaDate); |
| 571 | break; | 574 | break; |
| 572 | 575 | ||
| 573 | case R.id.btn_oneWeek: | 576 | case R.id.btn_oneWeek: |
| 574 | dataType = Const.DATA_TYPE.ONE_WEEK; | 577 | dataType = Const.DATA_TYPE.ONE_WEEK; |
| 575 | updateUiType(); | 578 | updateUiType(); |
| 576 | getHistoryData(dataType, mAnaDate); | 579 | getHistoryData(dataType, mAnaDate); |
| 577 | break; | 580 | break; |
| 578 | 581 | ||
| 579 | case R.id.btn_oneMonth: | 582 | case R.id.btn_oneMonth: |
| 580 | dataType = Const.DATA_TYPE.ONE_MONTH; | 583 | dataType = Const.DATA_TYPE.ONE_MONTH; |
| 581 | updateUiType(); | 584 | updateUiType(); |
| 582 | getHistoryData(dataType, mAnaDate); | 585 | getHistoryData(dataType, mAnaDate); |
| 583 | break; | 586 | break; |
| 584 | 587 | ||
| 585 | case R.id.btn_threeMonth: | 588 | case R.id.btn_threeMonth: |
| 586 | dataType = Const.DATA_TYPE.THREE_MONTH; | 589 | dataType = Const.DATA_TYPE.THREE_MONTH; |
| 587 | updateUiType(); | 590 | updateUiType(); |
| 588 | getHistoryData(dataType, mAnaDate); | 591 | getHistoryData(dataType, mAnaDate); |
| 589 | break; | 592 | break; |
| 590 | 593 | ||
| 591 | case R.id.btn_sixMonth: | 594 | case R.id.btn_sixMonth: |
| 592 | dataType = Const.DATA_TYPE.SIX_MONTH; | 595 | dataType = Const.DATA_TYPE.SIX_MONTH; |
| 593 | updateUiType(); | 596 | updateUiType(); |
| 594 | getHistoryData(dataType, mAnaDate); | 597 | getHistoryData(dataType, mAnaDate); |
| 595 | break; | 598 | break; |
| 596 | 599 | ||
| 597 | case R.id.tv_date: | 600 | case R.id.tv_date: |
| 598 | handleAnaDatePicker(); | 601 | handleAnaDatePicker(); |
| 599 | break; | 602 | break; |
| 600 | 603 | ||
| 601 | case R.id.ll_bike: | 604 | case R.id.ll_bike: |
| 602 | stepType = Const.STEP_TYPE.BIKE; | 605 | stepType = Const.STEP_TYPE.BIKE; |
| 603 | updateUiStepType(true, false, false); | 606 | updateUiStepType(true, false, false); |
| 604 | // add data | 607 | // add data |
| 605 | mDataCurrent = mDataModBike; | 608 | mDataCurrent = mDataModBike; |
| 606 | updateUI(); | 609 | updateUI(); |
| 607 | break; | 610 | break; |
| 608 | 611 | ||
| 609 | case R.id.ll_walking: | 612 | case R.id.ll_walking: |
| 610 | stepType = Const.STEP_TYPE.WALKING; | 613 | stepType = Const.STEP_TYPE.WALKING; |
| 611 | updateUiStepType(false, true, false); | 614 | updateUiStepType(false, true, false); |
| 612 | // add data | 615 | // add data |
| 613 | mDataCurrent = mDataModWalking; | 616 | mDataCurrent = mDataModWalking; |
| 614 | updateUI(); | 617 | updateUI(); |
| 615 | break; | 618 | break; |
| 616 | 619 | ||
| 617 | case R.id.ll_running: | 620 | case R.id.ll_running: |
| 618 | stepType = Const.STEP_TYPE.RUNNING; | 621 | stepType = Const.STEP_TYPE.RUNNING; |
| 619 | updateUiStepType(false, false, true); | 622 | updateUiStepType(false, false, true); |
| 620 | // add | 623 | // add |
| 621 | mDataCurrent = mDataModRunning; | 624 | mDataCurrent = mDataModRunning; |
| 622 | updateUI(); | 625 | updateUI(); |
| 623 | break; | 626 | break; |
| 624 | 627 | ||
| 625 | case R.id.rl_stepView: | 628 | case R.id.rl_stepView: |
| 626 | mHistoryFragment.showDetailFragment(); | 629 | mHistoryFragment.showDetailFragment(); |
| 627 | break; | 630 | break; |
| 628 | 631 | ||
| 629 | default: | 632 | default: |
| 630 | break; | 633 | break; |
| 631 | } | 634 | } |
| 632 | } | 635 | } |
| 633 | 636 | ||
| 634 | @Override | 637 | @Override |
| 635 | public void onActivityResult(int requestCode, int resultCode, Intent data) { | 638 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 636 | super.onActivityResult(requestCode, resultCode, data); | 639 | super.onActivityResult(requestCode, resultCode, data); |
| 637 | 640 | ||
| 638 | } | 641 | } |
| 639 | } | 642 | } |
| 640 | 643 |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/HistoryDetailFragment.java
| 1 | package com.dinhcv.lifelogpedometer.activity; | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | ||
| 3 | import android.app.DatePickerDialog; | 3 | import android.app.DatePickerDialog; |
| 4 | import android.content.Context; | 4 | import android.content.Context; |
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | import android.view.LayoutInflater; | 6 | import android.view.LayoutInflater; |
| 7 | import android.view.View; | 7 | import android.view.View; |
| 8 | import android.view.ViewGroup; | 8 | import android.view.ViewGroup; |
| 9 | import android.widget.Button; | 9 | import android.widget.Button; |
| 10 | import android.widget.DatePicker; | 10 | import android.widget.DatePicker; |
| 11 | import android.widget.EditText; | 11 | import android.widget.EditText; |
| 12 | import android.widget.ImageButton; | 12 | import android.widget.ImageButton; |
| 13 | import android.widget.LinearLayout; | 13 | import android.widget.LinearLayout; |
| 14 | import android.widget.ProgressBar; | 14 | import android.widget.ProgressBar; |
| 15 | import android.widget.TextView; | 15 | import android.widget.TextView; |
| 16 | 16 | ||
| 17 | import com.dinhcv.lifelogpedometer.R; | 17 | import com.dinhcv.lifelogpedometer.R; |
| 18 | import com.dinhcv.lifelogpedometer.adapter.HistoryAdapter; | 18 | import com.dinhcv.lifelogpedometer.adapter.HistoryAdapter; |
| 19 | import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; | 19 | import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; |
| 20 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 20 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 21 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; | 21 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; |
| 22 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryItemInfo; | 22 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryItemInfo; |
| 23 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | 23 | import com.dinhcv.lifelogpedometer.portal.ApiServices; |
| 24 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 24 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 25 | import com.dinhcv.lifelogpedometer.utils.Const; | 25 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 26 | import com.dinhcv.lifelogpedometer.utils.Debug; | 26 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 27 | import com.dinhcv.lifelogpedometer.utils.Utils; | 27 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 28 | 28 | ||
| 29 | import org.json.JSONException; | 29 | import org.json.JSONException; |
| 30 | import org.json.JSONObject; | 30 | import org.json.JSONObject; |
| 31 | 31 | ||
| 32 | import java.util.ArrayList; | 32 | import java.util.ArrayList; |
| 33 | import java.util.Calendar; | 33 | import java.util.Calendar; |
| 34 | import java.util.Date; | 34 | import java.util.Date; |
| 35 | import java.util.HashMap; | 35 | import java.util.HashMap; |
| 36 | import java.util.List; | 36 | import java.util.List; |
| 37 | import java.util.Map; | 37 | import java.util.Map; |
| 38 | 38 | ||
| 39 | import butterknife.BindView; | 39 | import butterknife.BindView; |
| 40 | import butterknife.ButterKnife; | 40 | import butterknife.ButterKnife; |
| 41 | import butterknife.OnClick; | 41 | import butterknife.OnClick; |
| 42 | import retrofit2.Callback; | 42 | import retrofit2.Callback; |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | public class HistoryDetailFragment extends FragmentBase { | 45 | public class HistoryDetailFragment extends FragmentBase { |
| 46 | private View mRootView; | 46 | private View mRootView; |
| 47 | 47 | ||
| 48 | @BindView(R.id.btn_left_date) | 48 | @BindView(R.id.btn_left_date) |
| 49 | ImageButton btnLeftDate; | 49 | ImageButton btnLeftDate; |
| 50 | @BindView(R.id.btn_right_date) | 50 | @BindView(R.id.btn_right_date) |
| 51 | ImageButton btnRightDate; | 51 | ImageButton btnRightDate; |
| 52 | @BindView(R.id.tv_date) | 52 | @BindView(R.id.tv_date) |
| 53 | TextView tvDate; | 53 | TextView tvDate; |
| 54 | @BindView(R.id.tv_week_day) | 54 | @BindView(R.id.tv_week_day) |
| 55 | TextView tvWeekDay; | 55 | TextView tvWeekDay; |
| 56 | @BindView(R.id.ll_bike) | 56 | @BindView(R.id.ll_bike) |
| 57 | LinearLayout llBike; | 57 | LinearLayout llBike; |
| 58 | @BindView(R.id.ll_walking) | 58 | @BindView(R.id.ll_walking) |
| 59 | LinearLayout llWalking; | 59 | LinearLayout llWalking; |
| 60 | @BindView(R.id.ll_running) | 60 | @BindView(R.id.ll_running) |
| 61 | LinearLayout llRunning; | 61 | LinearLayout llRunning; |
| 62 | @BindView(R.id.lv_history) | 62 | @BindView(R.id.lv_history) |
| 63 | ExpandableListCustomView lvHistory; | 63 | ExpandableListCustomView lvHistory; |
| 64 | private HistoryAdapter mHistoreAdapter; | 64 | private HistoryAdapter mHistoreAdapter; |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | @BindView(R.id.btn_sixMonth) | 67 | @BindView(R.id.btn_sixMonth) |
| 68 | Button btnSixMonth; | 68 | Button btnSixMonth; |
| 69 | @BindView(R.id.btn_oneDay) | 69 | @BindView(R.id.btn_oneDay) |
| 70 | Button btnOneDay; | 70 | Button btnOneDay; |
| 71 | @BindView(R.id.btn_oneWeek) | 71 | @BindView(R.id.btn_oneWeek) |
| 72 | Button btnOneWeek; | 72 | Button btnOneWeek; |
| 73 | @BindView(R.id.btn_oneMonth) | 73 | @BindView(R.id.btn_oneMonth) |
| 74 | Button btnOneMonth; | 74 | Button btnOneMonth; |
| 75 | @BindView(R.id.btn_threeMonth) | 75 | @BindView(R.id.btn_threeMonth) |
| 76 | Button btnThreeMonth; | 76 | Button btnThreeMonth; |
| 77 | 77 | ||
| 78 | private Date mAnaDate; | 78 | private Date mAnaDate; |
| 79 | private Calendar mCalendar; | 79 | private Calendar mCalendar; |
| 80 | 80 | ||
| 81 | private int mAnaDay; | 81 | private int mAnaDay; |
| 82 | private int mAnaMonth; | 82 | private int mAnaMonth; |
| 83 | private int mAnaYear; | 83 | private int mAnaYear; |
| 84 | private Context mContext; | 84 | private Context mContext; |
| 85 | private Const.DATA_TYPE dataType; | 85 | private Const.DATA_TYPE dataType; |
| 86 | private Const.STEP_TYPE stepType; | 86 | private Const.STEP_TYPE stepType; |
| 87 | 87 | ||
| 88 | private List<HistoryItemInfo> mDataModWalking = new ArrayList<>(); | 88 | private List<HistoryItemInfo> mDataModWalking = new ArrayList<>(); |
| 89 | private List<HistoryItemInfo> mDataModRunning = new ArrayList<>(); | 89 | private List<HistoryItemInfo> mDataModRunning = new ArrayList<>(); |
| 90 | private List<HistoryItemInfo> mDataModBike = new ArrayList<>(); | 90 | private List<HistoryItemInfo> mDataModBike = new ArrayList<>(); |
| 91 | private List<HistoryItemInfo> mDataCurrent = new ArrayList<>(); | 91 | private List<HistoryItemInfo> mDataCurrent = new ArrayList<>(); |
| 92 | 92 | ||
| 93 | private HistoryFragment mHistoryFragment; | 93 | private HistoryFragment mHistoryFragment; |
| 94 | 94 | ||
| 95 | public void setRootFragment(HistoryFragment frag) { | 95 | public void setRootFragment(HistoryFragment frag) { |
| 96 | this.mHistoryFragment = frag; | 96 | this.mHistoryFragment = frag; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | @Override | 99 | @Override |
| 100 | public View onCreateView(final LayoutInflater inflater,final ViewGroup container, | 100 | public View onCreateView(final LayoutInflater inflater,final ViewGroup container, |
| 101 | final Bundle savedInstanceState) { | 101 | final Bundle savedInstanceState) { |
| 102 | // Inflate the layout for this fragment | 102 | // Inflate the layout for this fragment |
| 103 | mRootView = inflater.inflate(R.layout.fragment_history_detail, null); | 103 | mRootView = inflater.inflate(R.layout.fragment_history_detail, null); |
| 104 | ButterKnife.bind(this, mRootView); | 104 | ButterKnife.bind(this, mRootView); |
| 105 | mContext = getActivity(); | 105 | mContext = getActivity(); |
| 106 | initView(); | 106 | initView(); |
| 107 | initData(); | 107 | initData(); |
| 108 | 108 | ||
| 109 | return mRootView; | 109 | return mRootView; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | private void initView() { | 112 | private void initView() { |
| 113 | 113 | ||
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | /** | 116 | /** |
| 117 | * init data for | 117 | * init data for |
| 118 | */ | 118 | */ |
| 119 | private void initData() { | 119 | private void initData() { |
| 120 | mCalendar = Calendar.getInstance(); | 120 | mCalendar = Calendar.getInstance(); |
| 121 | mCalendar.setTime(new Date()); | 121 | mCalendar.setTime(new Date()); |
| 122 | mAnaDate = mCalendar.getTime(); | 122 | mAnaDate = mCalendar.getTime(); |
| 123 | mAnaYear = mCalendar.get(Calendar.YEAR); | 123 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 124 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 124 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 125 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 125 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 126 | 126 | ||
| 127 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 127 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 128 | tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate)); | 128 | tvWeekDay.setText(Utils.getWeekdayFromDate(mAnaDate)); |
| 129 | 129 | ||
| 130 | dataType = Const.DATA_TYPE.ONE_DAY; | 130 | dataType = Const.DATA_TYPE.ONE_DAY; |
| 131 | stepType = Const.STEP_TYPE.WALKING; | 131 | stepType = Const.STEP_TYPE.WALKING; |
| 132 | updateUiType(); | 132 | updateUiType(); |
| 133 | updateUiStepType(false, true, false); | 133 | updateUiStepType(false, true, false); |
| 134 | 134 | ||
| 135 | getHistoryDetail(dataType, mAnaDate); | 135 | getHistoryDetail(dataType, mAnaDate); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | 138 | ||
| 139 | /** | 139 | /** |
| 140 | * Show date picker dialog | 140 | * Show date picker dialog |
| 141 | */ | 141 | */ |
| 142 | private void handleAnaDatePicker() { | 142 | private void handleAnaDatePicker() { |
| 143 | 143 | ||
| 144 | new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { | 144 | new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { |
| 145 | @Override | 145 | @Override |
| 146 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { | 146 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 147 | 147 | ||
| 148 | mCalendar = Calendar.getInstance(); | 148 | mCalendar = Calendar.getInstance(); |
| 149 | mCalendar.set(year, monthOfYear, dayOfMonth); | 149 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 150 | mAnaYear = year; | 150 | mAnaYear = year; |
| 151 | mAnaMonth = monthOfYear; | 151 | mAnaMonth = monthOfYear; |
| 152 | mAnaDay = dayOfMonth; | 152 | mAnaDay = dayOfMonth; |
| 153 | Date date = mCalendar.getTime(); | 153 | Date date = mCalendar.getTime(); |
| 154 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 154 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 155 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); | 155 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); |
| 156 | mAnaDate = date; | 156 | mAnaDate = date; |
| 157 | getHistoryDetail(dataType, mAnaDate); | 157 | getHistoryDetail(dataType, mAnaDate); |
| 158 | } | 158 | } |
| 159 | }, mAnaYear, mAnaMonth, mAnaDay).show(); | 159 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 160 | 160 | ||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | private void updateUiType() { | 163 | private void updateUiType() { |
| 164 | if (dataType == Const.DATA_TYPE.ONE_DAY) { | 164 | if (dataType == Const.DATA_TYPE.ONE_DAY) { |
| 165 | setButtonSelected(true, false, false, false, false); | 165 | setButtonSelected(true, false, false, false, false); |
| 166 | } else if (dataType == Const.DATA_TYPE.ONE_WEEK) { | 166 | } else if (dataType == Const.DATA_TYPE.ONE_WEEK) { |
| 167 | setButtonSelected(false, true, false, false, false); | 167 | setButtonSelected(false, true, false, false, false); |
| 168 | } else if (dataType == Const.DATA_TYPE.ONE_MONTH) { | 168 | } else if (dataType == Const.DATA_TYPE.ONE_MONTH) { |
| 169 | setButtonSelected(false, false, true, false, false); | 169 | setButtonSelected(false, false, true, false, false); |
| 170 | } else if (dataType == Const.DATA_TYPE.THREE_MONTH){ | 170 | } else if (dataType == Const.DATA_TYPE.THREE_MONTH){ |
| 171 | setButtonSelected(false, false, false, true, false); | 171 | setButtonSelected(false, false, false, true, false); |
| 172 | } else if (dataType == Const.DATA_TYPE.SIX_MONTH){ | 172 | } else if (dataType == Const.DATA_TYPE.SIX_MONTH){ |
| 173 | setButtonSelected(false, false, false, false, true); | 173 | setButtonSelected(false, false, false, false, true); |
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) { | 177 | private void setButtonSelected(boolean b1, boolean b2, boolean b3, boolean b4, boolean b5 ) { |
| 178 | btnOneDay.setSelected(b1); | 178 | btnOneDay.setSelected(b1); |
| 179 | btnOneWeek.setSelected(b2); | 179 | btnOneWeek.setSelected(b2); |
| 180 | btnOneMonth.setSelected(b3); | 180 | btnOneMonth.setSelected(b3); |
| 181 | btnThreeMonth.setSelected(b4); | 181 | btnThreeMonth.setSelected(b4); |
| 182 | btnSixMonth.setSelected(b5); | 182 | btnSixMonth.setSelected(b5); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 185 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 186 | llBike.setSelected(b1); | 186 | llBike.setSelected(b1); |
| 187 | llWalking.setSelected(b2); | 187 | llWalking.setSelected(b2); |
| 188 | llRunning.setSelected(b3); | 188 | llRunning.setSelected(b3); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | private void updateUI(){ | 191 | private void updateUI(){ |
| 192 | // get data server | 192 | // get data server |
| 193 | if (mDataCurrent != null && mDataCurrent.size() >0){ | 193 | if (mDataCurrent != null && mDataCurrent.size() >0){ |
| 194 | mHistoreAdapter = new HistoryAdapter(mContext, mDataCurrent); | 194 | mHistoreAdapter = new HistoryAdapter(mContext, mDataCurrent); |
| 195 | lvHistory.setAdapter(mHistoreAdapter); | 195 | lvHistory.setAdapter(mHistoreAdapter); |
| 196 | lvHistory.setExpanded(true); | 196 | lvHistory.setExpanded(true); |
| 197 | } | 197 | } |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | private void getHistoryDetail(Const.DATA_TYPE dataType, Date toDate){ | 200 | private void getHistoryDetail(Const.DATA_TYPE dataType, Date toDate){ |
| 201 | Date fromDate = Utils.getFromDate(mAnaDate, dataType); | 201 | Date fromDate = Utils.getFromDate(mAnaDate, dataType); |
| 202 | 202 | ||
| 203 | showDialog(mContext); | 203 | showDialog(mContext); |
| 204 | ApiServices.historyDetail(fromDate, toDate, new LLAPIManagerListener() { | 204 | ApiServices.historyDetail(fromDate, toDate, new LLAPIManagerListener() { |
| 205 | @Override | 205 | @Override |
| 206 | public void onError(Error error) { | 206 | public void onError(Error error) { |
| 207 | Debug.error("Get data history error"); | 207 | Debug.error("Get data history error"); |
| 208 | hiddenDialog(); | 208 | hiddenDialog(); |
| 209 | showDialogNotData(); | 209 | showDialogNotData(); |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | @Override | 212 | @Override |
| 213 | public void onSuccess(String json) { | 213 | public void onSuccess(String json) { |
| 214 | Debug.error("Get data history success"); | 214 | Debug.error("Get data history success"); |
| 215 | hiddenDialog(); | 215 | hiddenDialog(); |
| 216 | loadDataDone(json); | 216 | loadDataDone(json); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | @Override | 219 | @Override |
| 220 | public void onSuccess(JSONObject object) { | 220 | public void onSuccess(JSONObject object) { |
| 221 | Debug.error("Get data history success"); | 221 | Debug.error("Get data history success"); |
| 222 | hiddenDialog(); | 222 | hiddenDialog(); |
| 223 | } | 223 | } |
| 224 | }); | 224 | }); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | private void showDialogNotData(){ | 227 | private void showDialogNotData(){ |
| 228 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 228 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | private void loadDataDone(String jsonString) { | 231 | private void loadDataDone(String jsonString) { |
| 232 | JSONObject jsonObject = null; | 232 | JSONObject jsonObject = null; |
| 233 | try { | 233 | try { |
| 234 | jsonObject = new JSONObject(jsonString); | 234 | jsonObject = new JSONObject(jsonString); |
| 235 | int status = jsonObject.optInt("status"); | 235 | int status = jsonObject.optInt("status"); |
| 236 | if (status == 1) { | 236 | if (status == 1) { |
| 237 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 237 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 238 | JSONObject jsonMod1 = jsonObject1.getJSONObject("mode_1"); | 238 | JSONObject jsonMod1 = jsonObject1.optJSONObject("mode_1"); |
| 239 | JSONObject jsonMod2 = jsonObject1.getJSONObject("mode_2"); | 239 | JSONObject jsonMod2 = jsonObject1.optJSONObject("mode_2"); |
| 240 | JSONObject jsonMod3 = jsonObject1.getJSONObject("mode_3"); | 240 | JSONObject jsonMod3 = jsonObject1.optJSONObject("mode_3"); |
| 241 | //addDataModWalking(jsonMod1); | 241 | //addDataModWalking(jsonMod1); |
| 242 | //addDataModRunning(jsonMod2); | 242 | //addDataModRunning(jsonMod2); |
| 243 | //addDataModBike(jsonMod3); | 243 | //addDataModBike(jsonMod3); |
| 244 | 244 | ||
| 245 | } | 245 | } |
| 246 | } catch (JSONException e) { | 246 | } catch (JSONException e) { |
| 247 | e.printStackTrace(); | 247 | e.printStackTrace(); |
| 248 | mDataModWalking.clear(); | 248 | mDataModWalking.clear(); |
| 249 | mDataModRunning.clear();; | 249 | mDataModRunning.clear();; |
| 250 | mDataModBike.clear();; | 250 | mDataModBike.clear();; |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | if (stepType == Const.STEP_TYPE.WALKING){ | 253 | if (stepType == Const.STEP_TYPE.WALKING){ |
| 254 | mDataCurrent = mDataModWalking; | 254 | mDataCurrent = mDataModWalking; |
| 255 | }else if (stepType == Const.STEP_TYPE.RUNNING){ | 255 | }else if (stepType == Const.STEP_TYPE.RUNNING){ |
| 256 | mDataCurrent = mDataModRunning; | 256 | mDataCurrent = mDataModRunning; |
| 257 | }else { | 257 | }else { |
| 258 | mDataCurrent = mDataModBike; | 258 | mDataCurrent = mDataModBike; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | updateUI(); | 261 | updateUI(); |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | @OnClick({R.id.tv_date, R.id.btn_left_date, R.id.btn_right_date, R.id.btn_oneDay, R.id.btn_oneWeek, | 264 | @OnClick({R.id.tv_date, R.id.btn_left_date, R.id.btn_right_date, R.id.btn_oneDay, R.id.btn_oneWeek, |
| 265 | R.id.btn_oneMonth, R.id.btn_threeMonth, R.id.btn_sixMonth, R.id.ll_walking, R.id.ll_bike, | 265 | R.id.btn_oneMonth, R.id.btn_threeMonth, R.id.btn_sixMonth, R.id.ll_walking, R.id.ll_bike, |
| 266 | R.id.ll_running}) | 266 | R.id.ll_running}) |
| 267 | public void onClick(View view){ | 267 | public void onClick(View view){ |
| 268 | Date date; | 268 | Date date; |
| 269 | switch (view.getId()){ | 269 | switch (view.getId()){ |
| 270 | case R.id.tv_date: | 270 | case R.id.tv_date: |
| 271 | handleAnaDatePicker(); | 271 | handleAnaDatePicker(); |
| 272 | break; | 272 | break; |
| 273 | case R.id.btn_left_date: | 273 | case R.id.btn_left_date: |
| 274 | mCalendar = Calendar.getInstance(); | 274 | mCalendar = Calendar.getInstance(); |
| 275 | mCalendar.setTime(mAnaDate); | 275 | mCalendar.setTime(mAnaDate); |
| 276 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 276 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 277 | date = mCalendar.getTime(); | 277 | date = mCalendar.getTime(); |
| 278 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 278 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 279 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); | 279 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); |
| 280 | mAnaDate = date; | 280 | mAnaDate = date; |
| 281 | getHistoryDetail(dataType, mAnaDate); | 281 | getHistoryDetail(dataType, mAnaDate); |
| 282 | break; | 282 | break; |
| 283 | 283 | ||
| 284 | case R.id.btn_right_date: | 284 | case R.id.btn_right_date: |
| 285 | mCalendar = Calendar.getInstance(); | 285 | mCalendar = Calendar.getInstance(); |
| 286 | mCalendar.setTime(mAnaDate); | 286 | mCalendar.setTime(mAnaDate); |
| 287 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 287 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); |
| 288 | date = mCalendar.getTime(); | 288 | date = mCalendar.getTime(); |
| 289 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 289 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 290 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); | 290 | tvWeekDay.setText(Utils.getWeekdayFromDate(date)); |
| 291 | mAnaDate = date; | 291 | mAnaDate = date; |
| 292 | getHistoryDetail(dataType, mAnaDate); | 292 | getHistoryDetail(dataType, mAnaDate); |
| 293 | break; | 293 | break; |
| 294 | 294 | ||
| 295 | case R.id.btn_oneDay: | 295 | case R.id.btn_oneDay: |
| 296 | dataType = Const.DATA_TYPE.ONE_DAY; | 296 | dataType = Const.DATA_TYPE.ONE_DAY; |
| 297 | updateUiType(); | 297 | updateUiType(); |
| 298 | getHistoryDetail(dataType, mAnaDate); | 298 | getHistoryDetail(dataType, mAnaDate); |
| 299 | break; | 299 | break; |
| 300 | 300 | ||
| 301 | case R.id.btn_oneWeek: | 301 | case R.id.btn_oneWeek: |
| 302 | dataType = Const.DATA_TYPE.ONE_WEEK; | 302 | dataType = Const.DATA_TYPE.ONE_WEEK; |
| 303 | updateUiType(); | 303 | updateUiType(); |
| 304 | getHistoryDetail(dataType, mAnaDate); | 304 | getHistoryDetail(dataType, mAnaDate); |
| 305 | break; | 305 | break; |
| 306 | 306 | ||
| 307 | case R.id.btn_oneMonth: | 307 | case R.id.btn_oneMonth: |
| 308 | dataType = Const.DATA_TYPE.ONE_MONTH; | 308 | dataType = Const.DATA_TYPE.ONE_MONTH; |
| 309 | updateUiType(); | 309 | updateUiType(); |
| 310 | getHistoryDetail(dataType, mAnaDate); | 310 | getHistoryDetail(dataType, mAnaDate); |
| 311 | break; | 311 | break; |
| 312 | 312 | ||
| 313 | case R.id.btn_threeMonth: | 313 | case R.id.btn_threeMonth: |
| 314 | dataType = Const.DATA_TYPE.THREE_MONTH; | 314 | dataType = Const.DATA_TYPE.THREE_MONTH; |
| 315 | updateUiType(); | 315 | updateUiType(); |
| 316 | getHistoryDetail(dataType, mAnaDate); | 316 | getHistoryDetail(dataType, mAnaDate); |
| 317 | break; | 317 | break; |
| 318 | 318 | ||
| 319 | case R.id.btn_sixMonth: | 319 | case R.id.btn_sixMonth: |
| 320 | dataType = Const.DATA_TYPE.SIX_MONTH; | 320 | dataType = Const.DATA_TYPE.SIX_MONTH; |
| 321 | updateUiType(); | 321 | updateUiType(); |
| 322 | getHistoryDetail(dataType, mAnaDate); | 322 | getHistoryDetail(dataType, mAnaDate); |
| 323 | break; | 323 | break; |
| 324 | 324 | ||
| 325 | case R.id.ll_walking: | 325 | case R.id.ll_walking: |
| 326 | stepType = Const.STEP_TYPE.WALKING; | 326 | stepType = Const.STEP_TYPE.WALKING; |
| 327 | updateUiStepType(false, true, false); | 327 | updateUiStepType(false, true, false); |
| 328 | // add data | 328 | // add data |
| 329 | mDataCurrent = mDataModWalking; | 329 | mDataCurrent = mDataModWalking; |
| 330 | updateUI(); | 330 | updateUI(); |
| 331 | break; | 331 | break; |
| 332 | 332 | ||
| 333 | case R.id.ll_running: | 333 | case R.id.ll_running: |
| 334 | stepType = Const.STEP_TYPE.RUNNING; | 334 | stepType = Const.STEP_TYPE.RUNNING; |
| 335 | updateUiStepType(false, false, true); | 335 | updateUiStepType(false, false, true); |
| 336 | // add | 336 | // add |
| 337 | mDataCurrent = mDataModRunning; | 337 | mDataCurrent = mDataModRunning; |
| 338 | updateUI(); | 338 | updateUI(); |
| 339 | break; | 339 | break; |
| 340 | 340 | ||
| 341 | case R.id.ll_bike: | 341 | case R.id.ll_bike: |
| 342 | stepType = Const.STEP_TYPE.BIKE; | 342 | stepType = Const.STEP_TYPE.BIKE; |
| 343 | updateUiStepType(true, false, false); | 343 | updateUiStepType(true, false, false); |
| 344 | // add data | 344 | // add data |
| 345 | mDataCurrent = mDataModBike; | 345 | mDataCurrent = mDataModBike; |
| 346 | updateUI(); | 346 | updateUI(); |
| 347 | break; | 347 | break; |
| 348 | 348 | ||
| 349 | default: | 349 | default: |
| 350 | break; | 350 | break; |
| 351 | 351 | ||
| 352 | } | 352 | } |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | 355 | ||
| 356 | } | 356 | } |
| 357 | 357 |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
| 1 | package com.dinhcv.lifelogpedometer.activity; | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | ||
| 3 | import android.app.DatePickerDialog; | 3 | import android.app.DatePickerDialog; |
| 4 | import android.app.ProgressDialog; | 4 | import android.app.ProgressDialog; |
| 5 | import android.content.Context; | 5 | import android.content.Context; |
| 6 | import android.graphics.Color; | 6 | import android.graphics.Color; |
| 7 | import android.hardware.Sensor; | 7 | import android.hardware.Sensor; |
| 8 | import android.hardware.SensorEvent; | 8 | import android.hardware.SensorEvent; |
| 9 | import android.hardware.SensorEventListener; | 9 | import android.hardware.SensorEventListener; |
| 10 | import android.hardware.SensorManager; | 10 | import android.hardware.SensorManager; |
| 11 | import android.os.Bundle; | 11 | import android.os.Bundle; |
| 12 | import android.support.annotation.Nullable; | 12 | import android.support.annotation.Nullable; |
| 13 | import android.view.LayoutInflater; | 13 | import android.view.LayoutInflater; |
| 14 | import android.view.Menu; | 14 | import android.view.Menu; |
| 15 | import android.view.MenuInflater; | 15 | import android.view.MenuInflater; |
| 16 | import android.view.View; | 16 | import android.view.View; |
| 17 | import android.view.ViewGroup; | 17 | import android.view.ViewGroup; |
| 18 | import android.widget.DatePicker; | 18 | import android.widget.DatePicker; |
| 19 | import android.widget.ImageView; | 19 | import android.widget.ImageView; |
| 20 | import android.widget.LinearLayout; | 20 | import android.widget.LinearLayout; |
| 21 | import android.widget.TextView; | 21 | import android.widget.TextView; |
| 22 | import android.widget.Toast; | 22 | import android.widget.Toast; |
| 23 | 23 | ||
| 24 | import com.dinhcv.lifelogpedometer.R; | 24 | import com.dinhcv.lifelogpedometer.R; |
| 25 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 25 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 26 | import com.dinhcv.lifelogpedometer.interfaces.StepListener; | ||
| 26 | import com.dinhcv.lifelogpedometer.model.StepModel; | 27 | import com.dinhcv.lifelogpedometer.model.StepModel; |
| 27 | import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo; | 28 | import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo; |
| 28 | import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo; | 29 | import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo; |
| 29 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | 30 | import com.dinhcv.lifelogpedometer.portal.ApiServices; |
| 30 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 31 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 31 | import com.dinhcv.lifelogpedometer.utils.Const; | 32 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 32 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; | 33 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; |
| 33 | import com.dinhcv.lifelogpedometer.utils.Debug; | 34 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 35 | import com.dinhcv.lifelogpedometer.utils.SimpleStepDetector; | ||
| 34 | import com.dinhcv.lifelogpedometer.utils.Utils; | 36 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 35 | import com.github.mikephil.charting.components.XAxis; | 37 | import com.github.mikephil.charting.components.XAxis; |
| 36 | import com.github.mikephil.charting.components.YAxis; | 38 | import com.github.mikephil.charting.components.YAxis; |
| 37 | 39 | ||
| 38 | import com.github.mikephil.charting.charts.BarChart; | 40 | import com.github.mikephil.charting.charts.BarChart; |
| 39 | import com.github.mikephil.charting.data.BarData; | 41 | import com.github.mikephil.charting.data.BarData; |
| 40 | import com.github.mikephil.charting.data.BarDataSet; | 42 | import com.github.mikephil.charting.data.BarDataSet; |
| 41 | import com.github.mikephil.charting.data.BarEntry; | 43 | import com.github.mikephil.charting.data.BarEntry; |
| 42 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; | 44 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; |
| 43 | 45 | ||
| 44 | import org.eazegraph.lib.charts.PieChart; | 46 | import org.eazegraph.lib.charts.PieChart; |
| 45 | import org.eazegraph.lib.models.PieModel; | 47 | import org.eazegraph.lib.models.PieModel; |
| 46 | import org.json.JSONArray; | 48 | import org.json.JSONArray; |
| 47 | import org.json.JSONException; | 49 | import org.json.JSONException; |
| 48 | import org.json.JSONObject; | 50 | import org.json.JSONObject; |
| 49 | 51 | ||
| 50 | import java.text.NumberFormat; | 52 | import java.text.NumberFormat; |
| 51 | import java.util.ArrayList; | 53 | import java.util.ArrayList; |
| 52 | import java.util.Arrays; | 54 | import java.util.Arrays; |
| 53 | import java.util.Calendar; | 55 | import java.util.Calendar; |
| 54 | import java.util.Date; | 56 | import java.util.Date; |
| 55 | import java.util.List; | 57 | import java.util.List; |
| 56 | import java.util.Locale; | 58 | import java.util.Locale; |
| 57 | 59 | ||
| 58 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; | 60 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; |
| 59 | 61 | ||
| 60 | 62 | ||
| 61 | public class TopTodayFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { | 63 | public class TopTodayFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener, StepListener { |
| 62 | 64 | ||
| 63 | private TextView stepsView; | 65 | private TextView stepsView; |
| 64 | private TextView tvStepGoal; | 66 | private TextView tvStepGoal; |
| 65 | private TextView tvDistance; | 67 | private TextView tvDistance; |
| 66 | private TextView tvTime; | 68 | private TextView tvTime; |
| 67 | private TextView tvStepRemain; | 69 | private TextView tvStepRemain; |
| 68 | private TextView tvStepRateDone; | 70 | private TextView tvStepRateDone; |
| 69 | private boolean showSteps = true; | 71 | private boolean showSteps = true; |
| 70 | private PieModel sliceGoal, sliceCurrent; | 72 | private PieModel sliceGoal, sliceCurrent; |
| 71 | private PieChart pg; | 73 | private PieChart pg; |
| 72 | private TextView tvDate; | 74 | private TextView tvDate; |
| 73 | private ImageView ivBack; | 75 | private ImageView ivBack; |
| 74 | private ImageView ivNext; | 76 | private ImageView ivNext; |
| 75 | 77 | ||
| 76 | private LinearLayout llBike; | 78 | private LinearLayout llBike; |
| 77 | private LinearLayout llWalking; | 79 | private LinearLayout llWalking; |
| 78 | private LinearLayout llRunning; | 80 | private LinearLayout llRunning; |
| 79 | private Const.STEP_TYPE stepType; | 81 | private Const.STEP_TYPE stepType; |
| 80 | 82 | ||
| 81 | private Date mAnaDate; | 83 | private Date mAnaDate; |
| 82 | private Calendar mCalendar; | 84 | private Calendar mCalendar; |
| 83 | 85 | ||
| 84 | private int mAnaDay; | 86 | private int mAnaDay; |
| 85 | private int mAnaMonth; | 87 | private int mAnaMonth; |
| 86 | private int mAnaYear; | 88 | private int mAnaYear; |
| 87 | 89 | ||
| 88 | public static int STEP_SIZE = 75; | 90 | public static int STEP_SIZE = 75; |
| 89 | private StepModel mStepModel; | 91 | private StepModel mStepModel; |
| 90 | private TextView tvSmallStepGoal; | 92 | private TextView tvSmallStepGoal; |
| 91 | private TextView tvSmallRemain; | 93 | private TextView tvSmallRemain; |
| 92 | private Context mContext; | 94 | private Context mContext; |
| 93 | 95 | ||
| 94 | public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); | 96 | public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); |
| 95 | private SensorManager sensorManager; | 97 | private SensorManager sensorManager; |
| 96 | private boolean activityRunning; | 98 | private boolean activityRunning; |
| 97 | private int stepTotal = 0; | 99 | private int stepTotal = 0; |
| 98 | private int stepGoal = 0; | 100 | private int stepGoal = 0; |
| 99 | private int stepCount = 0; | 101 | private int stepCount = 0; |
| 100 | 102 | ||
| 101 | private Date mFromDate; | 103 | private Date mFromDate; |
| 102 | private Date mToDate; | 104 | private Date mToDate; |
| 103 | 105 | ||
| 104 | private TopInfo mTopInfo = new TopInfo(); | 106 | private TopInfo mTopInfo = new TopInfo(); |
| 105 | private BarChart mChart; | 107 | private BarChart mChart; |
| 106 | 108 | ||
| 107 | private List<String> dateList; | 109 | private List<String> dateList; |
| 108 | private String[] mParties; | 110 | private String[] mParties; |
| 109 | private Integer[] mStep; | 111 | private Integer[] mStep; |
| 110 | private ProgressDialog progress; | 112 | private ProgressDialog progress; |
| 113 | private boolean isAccelo = false; | ||
| 114 | private boolean isBusy = false; | ||
| 115 | private SimpleStepDetector simpleStepDetector; | ||
| 111 | 116 | ||
| 112 | private TopFragment mTopFragment; | 117 | private TopFragment mTopFragment; |
| 113 | public void setRootFragment(TopFragment frag) { | 118 | public void setRootFragment(TopFragment frag) { |
| 114 | this.mTopFragment = frag; | 119 | this.mTopFragment = frag; |
| 115 | } | 120 | } |
| 116 | 121 | ||
| 117 | @Override | 122 | @Override |
| 118 | public void onCreate(final Bundle savedInstanceState) { | 123 | public void onCreate(final Bundle savedInstanceState) { |
| 119 | super.onCreate(savedInstanceState); | 124 | super.onCreate(savedInstanceState); |
| 120 | setHasOptionsMenu(true); | 125 | setHasOptionsMenu(true); |
| 126 | |||
| 121 | } | 127 | } |
| 122 | 128 | ||
| 123 | @Override | 129 | @Override |
| 124 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 130 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 125 | final Bundle savedInstanceState) { | 131 | final Bundle savedInstanceState) { |
| 126 | final View v = inflater.inflate(R.layout.fragment_top_today, null); | 132 | final View v = inflater.inflate(R.layout.fragment_top_today, null); |
| 127 | mContext = getActivity(); | 133 | mContext = getActivity(); |
| 128 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); | 134 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); |
| 129 | 135 | ||
| 136 | simpleStepDetector = new SimpleStepDetector(); | ||
| 137 | simpleStepDetector.registerListener(this); | ||
| 138 | |||
| 130 | initView(v); | 139 | initView(v); |
| 131 | 140 | ||
| 132 | // slice for the steps taken today | 141 | // slice for the steps taken today |
| 133 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); | 142 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); |
| 134 | pg.addPieSlice(sliceCurrent); | 143 | pg.addPieSlice(sliceCurrent); |
| 135 | 144 | ||
| 136 | // slice for the "missing" steps until reaching the goal | 145 | // slice for the "missing" steps until reaching the goal |
| 137 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); | 146 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); |
| 138 | pg.addPieSlice(sliceGoal); | 147 | pg.addPieSlice(sliceGoal); |
| 139 | 148 | ||
| 140 | pg.setDrawValueInPie(false); | 149 | pg.setDrawValueInPie(false); |
| 141 | pg.setUsePieRotation(false); | 150 | pg.setUsePieRotation(false); |
| 142 | pg.startAnimation(); | 151 | pg.startAnimation(); |
| 143 | pg.setAutoCenterInSlice(false); | 152 | pg.setAutoCenterInSlice(false); |
| 144 | 153 | ||
| 145 | mCalendar = Calendar.getInstance(); | 154 | mCalendar = Calendar.getInstance(); |
| 146 | mCalendar.setTime(new Date()); | 155 | mCalendar.setTime(new Date()); |
| 147 | mAnaDate = mCalendar.getTime(); | 156 | mAnaDate = mCalendar.getTime(); |
| 148 | mAnaYear = mCalendar.get(Calendar.YEAR); | 157 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 149 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 158 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 150 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 159 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 151 | 160 | ||
| 152 | mFromDate = new Date(); | 161 | mFromDate = new Date(); |
| 153 | 162 | ||
| 154 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 163 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 155 | 164 | ||
| 156 | initData(); | 165 | initData(); |
| 157 | 166 | ||
| 158 | handleEvent(); | 167 | handleEvent(); |
| 159 | 168 | ||
| 160 | getTopPage(mAnaDate, stepType); | 169 | getTopPage(mAnaDate, stepType); |
| 161 | 170 | ||
| 162 | return v; | 171 | return v; |
| 163 | } | 172 | } |
| 164 | 173 | ||
| 165 | private void initView(View v){ | 174 | private void initView(View v){ |
| 166 | stepsView = (TextView) v.findViewById(R.id.steps); | 175 | stepsView = (TextView) v.findViewById(R.id.steps); |
| 167 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); | 176 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); |
| 168 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); | 177 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); |
| 169 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); | 178 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); |
| 170 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); | 179 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); |
| 171 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); | 180 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); |
| 172 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); | 181 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); |
| 173 | tvTime = (TextView) v.findViewById(R.id.tv_time); | 182 | tvTime = (TextView) v.findViewById(R.id.tv_time); |
| 174 | tvDate = (TextView) v.findViewById(R.id.tv_date); | 183 | tvDate = (TextView) v.findViewById(R.id.tv_date); |
| 175 | ivBack = (ImageView) v.findViewById(R.id.iv_back); | 184 | ivBack = (ImageView) v.findViewById(R.id.iv_back); |
| 176 | ivNext = (ImageView) v.findViewById(R.id.iv_next); | 185 | ivNext = (ImageView) v.findViewById(R.id.iv_next); |
| 177 | 186 | ||
| 178 | mChart = (BarChart) v.findViewById(R.id.chart); | 187 | mChart = (BarChart) v.findViewById(R.id.chart); |
| 179 | pg = (PieChart) v.findViewById(R.id.graph); | 188 | pg = (PieChart) v.findViewById(R.id.graph); |
| 180 | 189 | ||
| 181 | llRunning = (LinearLayout) v.findViewById(R.id.ll_running); | 190 | llRunning = (LinearLayout) v.findViewById(R.id.ll_running); |
| 182 | llWalking = (LinearLayout) v.findViewById(R.id.ll_walking); | 191 | llWalking = (LinearLayout) v.findViewById(R.id.ll_walking); |
| 183 | llBike = (LinearLayout) v.findViewById(R.id.ll_bike); | 192 | llBike = (LinearLayout) v.findViewById(R.id.ll_bike); |
| 184 | } | 193 | } |
| 185 | 194 | ||
| 186 | private void initData(){ | 195 | private void initData(){ |
| 187 | mCalendar = Calendar.getInstance(); | 196 | mCalendar = Calendar.getInstance(); |
| 188 | mCalendar.setTime(new Date()); | 197 | mCalendar.setTime(new Date()); |
| 189 | mAnaDate = mCalendar.getTime(); | 198 | mAnaDate = mCalendar.getTime(); |
| 190 | mAnaYear = mCalendar.get(Calendar.YEAR); | 199 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 191 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 200 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 192 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 201 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 193 | 202 | ||
| 194 | 203 | ||
| 195 | stepType = Const.STEP_TYPE.WALKING; | 204 | stepType = Const.STEP_TYPE.WALKING; |
| 196 | updateUiStepType(false, true, false); | 205 | updateUiStepType(false, true, false); |
| 197 | 206 | ||
| 198 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 207 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 199 | } | 208 | } |
| 200 | 209 | ||
| 201 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 210 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 202 | llBike.setSelected(b1); | 211 | llBike.setSelected(b1); |
| 203 | llWalking.setSelected(b2); | 212 | llWalking.setSelected(b2); |
| 204 | llRunning.setSelected(b3); | 213 | llRunning.setSelected(b3); |
| 205 | } | 214 | } |
| 206 | 215 | ||
| 207 | private void stepsDistanceChanged() { | 216 | private void stepsDistanceChanged() { |
| 208 | if (progress != null){ | 217 | if (progress != null){ |
| 209 | progress.dismiss(); | 218 | progress.dismiss(); |
| 210 | } | 219 | } |
| 211 | updatePie(); | 220 | updatePie(); |
| 212 | updateBars(); | 221 | updateBars(); |
| 213 | } | 222 | } |
| 214 | 223 | ||
| 215 | 224 | ||
| 216 | @Override | 225 | @Override |
| 217 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { | 226 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { |
| 218 | inflater.inflate(R.menu.main, menu); | 227 | inflater.inflate(R.menu.main, menu); |
| 219 | } | 228 | } |
| 220 | 229 | ||
| 221 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ | 230 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ |
| 222 | 231 | ||
| 223 | progress = new ProgressDialog(mContext); | 232 | progress = new ProgressDialog(mContext); |
| 224 | progress.setMessage(getString(R.string.loading)); | 233 | progress.setMessage(getString(R.string.loading)); |
| 225 | progress.setCancelable(false); | 234 | progress.setCancelable(false); |
| 226 | progress.show(); | 235 | progress.show(); |
| 227 | ApiServices.topInfo(date, stepType, new LLAPIManagerListener() { | 236 | ApiServices.topInfo(date, stepType, new LLAPIManagerListener() { |
| 228 | @Override | 237 | @Override |
| 229 | public void onError(Error error) { | 238 | public void onError(Error error) { |
| 230 | Debug.error("Get data history error"); | 239 | Debug.error("Get data history error"); |
| 231 | hiddenDialog(); | 240 | hiddenDialog(); |
| 232 | showDialogNotData(); | 241 | showDialogNotData(); |
| 233 | } | 242 | } |
| 234 | 243 | ||
| 235 | @Override | 244 | @Override |
| 236 | public void onSuccess(String json) { | 245 | public void onSuccess(String json) { |
| 237 | Debug.error("Get data history success"); | 246 | Debug.error("Get data history success"); |
| 238 | loadDataDone(json); | 247 | loadDataDone(json); |
| 239 | } | 248 | } |
| 240 | 249 | ||
| 241 | @Override | 250 | @Override |
| 242 | public void onSuccess(JSONObject object) { | 251 | public void onSuccess(JSONObject object) { |
| 243 | Debug.error("Get data history success"); | 252 | Debug.error("Get data history success"); |
| 244 | hiddenDialog(); | 253 | hiddenDialog(); |
| 245 | } | 254 | } |
| 246 | }); | 255 | }); |
| 247 | } | 256 | } |
| 248 | 257 | ||
| 249 | private void showDialogNotData(){ | 258 | private void showDialogNotData(){ |
| 250 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 259 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 251 | } | 260 | } |
| 252 | 261 | ||
| 253 | private void loadDataDone(String jsonString) { | 262 | private void loadDataDone(String jsonString) { |
| 254 | JSONObject jsonObject = null; | 263 | JSONObject jsonObject = null; |
| 255 | try { | 264 | try { |
| 256 | jsonObject = new JSONObject(jsonString); | 265 | jsonObject = new JSONObject(jsonString); |
| 257 | int status = jsonObject.optInt("status"); | 266 | int status = jsonObject.optInt("status"); |
| 258 | if (status == 1) { | 267 | if (status == 1) { |
| 259 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 268 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 260 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); | 269 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); |
| 261 | 270 | ||
| 262 | if (targetInf != null){ | 271 | if (targetInf != null){ |
| 263 | String target = targetInf.optString("target_step"); | 272 | String target = targetInf.optString("target_step"); |
| 264 | Debug.normal("Target: "+ target); | 273 | Debug.normal("Target: "+ target); |
| 265 | mTopInfo.setTaget(targetInf.optString("target_step")); | 274 | mTopInfo.setTaget(targetInf.optString("target_step")); |
| 266 | mTo |