Commit cb2ba72a7e49da54339fed07eec14d148bd173f2
1 parent
383e854984
Exists in
master
and in
1 other branch
update handle count step
Showing 8 changed files with 46 additions and 24 deletions Side-by-side Diff
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
- app/src/main/res/layout/fragment_top_today.xml
- app/src/main/res/mipmap-hdpi/ic_launcher.png
- app/src/main/res/mipmap-mdpi/ic_launcher.png
- app/src/main/res/mipmap-xhdpi/ic_launcher.png
- app/src/main/res/mipmap-xxhdpi/ic_launcher.png
- app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | import android.widget.FrameLayout; |
12 | 12 | |
13 | 13 | import com.dinhcv.lifelogpedometer.R; |
14 | +import com.dinhcv.lifelogpedometer.utils.Debug; | |
14 | 15 | |
15 | 16 | public class TopFragment extends FragmentBase implements SettingFragmentPresenter { |
16 | 17 | public enum TopFragmentTag { |
... | ... | @@ -90,7 +91,12 @@ |
90 | 91 | * Init data |
91 | 92 | */ |
92 | 93 | private void initData() { |
93 | - | |
94 | + Debug.normal("Current fragment : "+ mCurrentFragment); | |
95 | + if (mCurrentFragment == TopFragmentTag.TOP_DATE){ | |
96 | + ((PedometerActivity) getActivity()).setVisibleIconHome(false); | |
97 | + }else { | |
98 | + ((PedometerActivity) getActivity()).setVisibleIconHome(true); | |
99 | + } | |
94 | 100 | } |
95 | 101 | |
96 | 102 | @Override |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
1 | 1 | package com.dinhcv.lifelogpedometer.activity; |
2 | 2 | |
3 | 3 | import android.app.DatePickerDialog; |
4 | +import android.app.ProgressDialog; | |
4 | 5 | import android.content.Context; |
5 | 6 | import android.graphics.Color; |
6 | 7 | import android.hardware.Sensor; |
... | ... | @@ -93,7 +94,7 @@ |
93 | 94 | private SensorManager sensorManager; |
94 | 95 | private boolean activityRunning; |
95 | 96 | private int stepTotal = 0; |
96 | - private int stepRemain = 0; | |
97 | + private int stepGoal = 0; | |
97 | 98 | private int stepCount = 0; |
98 | 99 | |
99 | 100 | private Date mFromDate; |
... | ... | @@ -105,6 +106,7 @@ |
105 | 106 | private List<String> dateList; |
106 | 107 | private String[] mParties; |
107 | 108 | private Integer[] mStep; |
109 | + private ProgressDialog progress; | |
108 | 110 | |
109 | 111 | private TopFragment mTopFragment; |
110 | 112 | public void setRootFragment(TopFragment frag) { |
... | ... | @@ -201,6 +203,9 @@ |
201 | 203 | } |
202 | 204 | |
203 | 205 | private void stepsDistanceChanged() { |
206 | + if (progress != null){ | |
207 | + progress.dismiss(); | |
208 | + } | |
204 | 209 | updatePie(); |
205 | 210 | updateBars(); |
206 | 211 | } |
... | ... | @@ -213,7 +218,10 @@ |
213 | 218 | |
214 | 219 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ |
215 | 220 | |
216 | - showDialog(mContext); | |
221 | + progress = new ProgressDialog(mContext); | |
222 | + progress.setMessage(getString(R.string.loading)); | |
223 | + progress.setCancelable(false); | |
224 | + progress.show(); | |
217 | 225 | LLAPIManager.topInfo(date, stepType, new LLAPIManagerListener() { |
218 | 226 | @Override |
219 | 227 | public void onError(Error error) { |
... | ... | @@ -225,7 +233,6 @@ |
225 | 233 | @Override |
226 | 234 | public void onSuccess(String json) { |
227 | 235 | Debug.error("Get data history success"); |
228 | - hiddenDialog(); | |
229 | 236 | loadDataDone(json); |
230 | 237 | } |
231 | 238 | |
... | ... | @@ -292,7 +299,12 @@ |
292 | 299 | int stepsToday = 0; |
293 | 300 | int stepTarget = 0; |
294 | 301 | if (mTopInfo != null) { |
295 | - stepsToday = Integer.valueOf(mTopInfo.getSteps()); | |
302 | + if (mTopInfo.getSteps().contains(",")){ | |
303 | + stepsToday = Integer.valueOf(mTopInfo.getSteps().replace(",", "")); | |
304 | + }else { | |
305 | + stepsToday = Integer.valueOf(mTopInfo.getSteps()); | |
306 | + } | |
307 | + | |
296 | 308 | if (mTopInfo.getTaget().contains(",")) { |
297 | 309 | stepTarget = Integer.valueOf(mTopInfo.getTaget().replace(",", "")); |
298 | 310 | }else { |
299 | 311 | |
300 | 312 | |
... | ... | @@ -312,17 +324,16 @@ |
312 | 324 | pg.addPieSlice(sliceCurrent); |
313 | 325 | } |
314 | 326 | pg.update(); |
315 | - | |
316 | - tvDistance.setText(mTopInfo.getDistance()); | |
317 | - tvTime.setText(mTopInfo.getTime()); | |
318 | - | |
327 | + stepGoal = stepTarget; | |
328 | + stepTotal = stepsToday; | |
319 | 329 | stepsView.setText(formatter.format(stepsToday)); |
320 | - int remain = stepTarget - stepsToday; | |
321 | - tvStepRemain.setText(String.valueOf(remain)); | |
322 | - tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(stepsToday *100/ Const.STEP_GOAL))); | |
323 | - tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, remain)); | |
330 | + int stepRemain = stepTarget - stepsToday; | |
331 | + tvStepRemain.setText(String.valueOf(stepRemain)); | |
332 | + tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(stepsToday *100/ stepTarget))); | |
333 | + tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, stepRemain)); | |
324 | 334 | tvStepGoal.setText(mTopInfo.getTaget()); |
325 | 335 | tvSmallStepGoal.setText(mTopInfo.getTaget()); |
336 | + | |
326 | 337 | tvDistance.setText(mTopInfo.getDistance()); |
327 | 338 | tvTime.setText(mTopInfo.getTime()); |
328 | 339 | |
... | ... | @@ -487,7 +498,7 @@ |
487 | 498 | @Override |
488 | 499 | public void onClick(View view) { |
489 | 500 | stepType = Const.STEP_TYPE.BIKE; |
490 | - updateUiStepType(false, false, true); | |
501 | + updateUiStepType(true, false, false); | |
491 | 502 | getTopPage(mAnaDate, stepType); |
492 | 503 | } |
493 | 504 | }); |
... | ... | @@ -505,7 +516,7 @@ |
505 | 516 | @Override |
506 | 517 | public void onClick(View view) { |
507 | 518 | stepType = Const.STEP_TYPE.WALKING; |
508 | - updateUiStepType(false, false, true); | |
519 | + updateUiStepType(false, true, false); | |
509 | 520 | getTopPage(mAnaDate, stepType); |
510 | 521 | } |
511 | 522 | }); |
... | ... | @@ -539,9 +550,9 @@ |
539 | 550 | |
540 | 551 | |
541 | 552 | private void updateUI(){ |
542 | - stepTotal = stepTotal + stepCount; | |
543 | - stepRemain = stepRemain - stepCount; | |
544 | - double percentDone = stepTotal *100.0 / (stepTotal + stepRemain); | |
553 | + Debug.normal("Step total================ "+ stepTotal); | |
554 | + int stepRemain = stepGoal - stepTotal; | |
555 | + double percentDone = stepTotal *100.0 / stepGoal; | |
545 | 556 | stepsView.setText(String.valueOf(stepTotal)); |
546 | 557 | tvStepRemain.setText(String.valueOf(stepRemain)); |
547 | 558 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone))); |
... | ... | @@ -589,6 +600,8 @@ |
589 | 600 | Debug.normal("Sensor count step active"); |
590 | 601 | if (activityRunning){ |
591 | 602 | stepCount = (int) event.values[0]; |
603 | + Debug.normal("Step change: "+ stepCount); | |
604 | + stepTotal++; | |
592 | 605 | // update UI |
593 | 606 | updateUI(); |
594 | 607 | } |
... | ... | @@ -605,6 +618,9 @@ |
605 | 618 | activityRunning = false; |
606 | 619 | Debug.normal("Start create log"); |
607 | 620 | mToDate = new Date(); |
621 | + if (sensorManager != null) { | |
622 | + sensorManager.unregisterListener(this); | |
623 | + } | |
608 | 624 | // create log step |
609 | 625 | creatLogStep(); |
610 | 626 | } |
app/src/main/res/layout/fragment_top_today.xml
... | ... | @@ -224,7 +224,7 @@ |
224 | 224 | <LinearLayout |
225 | 225 | android:layout_width="0dp" |
226 | 226 | android:layout_height="wrap_content" |
227 | - android:layout_weight="20" | |
227 | + android:layout_weight="10" | |
228 | 228 | android:gravity="center" |
229 | 229 | android:orientation="vertical"> |
230 | 230 | |
... | ... | @@ -248,7 +248,7 @@ |
248 | 248 | <LinearLayout |
249 | 249 | android:layout_width="0dp" |
250 | 250 | android:layout_height="wrap_content" |
251 | - android:layout_weight="20" | |
251 | + android:layout_weight="30" | |
252 | 252 | android:gravity="center" |
253 | 253 | android:orientation="vertical"> |
254 | 254 | |
255 | 255 | |
... | ... | @@ -258,14 +258,14 @@ |
258 | 258 | android:layout_height="wrap_content" |
259 | 259 | android:text="4.9" |
260 | 260 | android:textColor="@color/white" |
261 | - android:textSize="30sp" /> | |
261 | + android:textSize="22sp" /> | |
262 | 262 | |
263 | 263 | </LinearLayout> |
264 | 264 | |
265 | 265 | <LinearLayout |
266 | 266 | android:layout_width="0dp" |
267 | 267 | android:layout_height="wrap_content" |
268 | - android:layout_weight="20" | |
268 | + android:layout_weight="30" | |
269 | 269 | android:gravity="center" |
270 | 270 | android:orientation="vertical"> |
271 | 271 | |
272 | 272 | |
... | ... | @@ -275,14 +275,14 @@ |
275 | 275 | android:layout_height="wrap_content" |
276 | 276 | android:text="1:09" |
277 | 277 | android:textColor="@color/white" |
278 | - android:textSize="30sp" /> | |
278 | + android:textSize="22sp" /> | |
279 | 279 | |
280 | 280 | </LinearLayout> |
281 | 281 | |
282 | 282 | <LinearLayout |
283 | 283 | android:layout_width="0dp" |
284 | 284 | android:layout_height="wrap_content" |
285 | - android:layout_weight="20" | |
285 | + android:layout_weight="10" | |
286 | 286 | android:gravity="center" |
287 | 287 | android:orientation="vertical"> |
288 | 288 |
app/src/main/res/mipmap-hdpi/ic_launcher.png
app/src/main/res/mipmap-mdpi/ic_launcher.png
app/src/main/res/mipmap-xhdpi/ic_launcher.png
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png