Compare View

switch
from
...
to
 
Commits (2)

Changes

Showing 12 changed files Side-by-side Diff

app/src/main/java/com/dinhcv/lifelogpedometer/activity/DateFragment.java
... ... @@ -4,6 +4,10 @@ import android.app.DatePickerDialog;
4 4 import android.content.Context;
5 5 import android.content.Intent;
6 6 import android.content.SharedPreferences;
  7 +import android.hardware.Sensor;
  8 +import android.hardware.SensorEvent;
  9 +import android.hardware.SensorEventListener;
  10 +import android.hardware.SensorManager;
7 11 import android.os.Bundle;
8 12 import android.support.annotation.Nullable;
9 13 import android.support.v4.app.Fragment;
... ... @@ -14,6 +18,7 @@ import android.widget.DatePicker;
14 18 import android.widget.ImageView;
15 19 import android.widget.LinearLayout;
16 20 import android.widget.TextView;
  21 +import android.widget.Toast;
17 22  
18 23 import com.dinhcv.lifelogpedometer.R;
19 24 import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter;
... ... @@ -280,14 +285,13 @@ public class DateFragment extends FragmentBase implements SettingFragmentPresent
280 285 mTagetInfo = new TagetInfo();;
281 286 }
282 287  
283   - updateUI();
  288 + loadUI();
284 289 }
285 290  
286 291  
287   - private void updateUI(){
288   -
289   - tvStep.setText(mTagetInfo.getSteps());
290   - tvRemain.setText(mTagetInfo.getStepRemain());
  292 + private void loadUI(){
  293 + tvStep.setText(String.valueOf(mTagetInfo.getSteps()));
  294 + tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain()));
291 295 tvRateDone.setText(getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent()));
292 296  
293 297 List<NoticeInfo> infoLists = mTagetInfo.getNoticeList();
... ... @@ -334,4 +338,5 @@ public class DateFragment extends FragmentBase implements SettingFragmentPresent
334 338 super.onActivityResult(requestCode, resultCode, data);
335 339  
336 340 }
  341 +
337 342 }
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
... ... @@ -3,6 +3,10 @@ package com.dinhcv.lifelogpedometer.activity;
3 3 import android.app.DatePickerDialog;
4 4 import android.content.Context;
5 5 import android.graphics.Color;
  6 +import android.hardware.Sensor;
  7 +import android.hardware.SensorEvent;
  8 +import android.hardware.SensorEventListener;
  9 +import android.hardware.SensorManager;
6 10 import android.os.Bundle;
7 11 import android.support.annotation.Nullable;
8 12 import android.util.Pair;
... ... @@ -13,13 +17,20 @@ import android.view.View;
13 17 import android.view.ViewGroup;
14 18 import android.widget.DatePicker;
15 19 import android.widget.ImageView;
  20 +import android.widget.LinearLayout;
16 21 import android.widget.TextView;
  22 +import android.widget.Toast;
17 23  
18 24 import com.dinhcv.lifelogpedometer.R;
19 25 import com.dinhcv.lifelogpedometer.feature.Database;
  26 +import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
20 27 import com.dinhcv.lifelogpedometer.model.StepModel;
  28 +import com.dinhcv.lifelogpedometer.model.structure.top.StepHourInfo;
  29 +import com.dinhcv.lifelogpedometer.model.structure.top.TagetTopInfo;
  30 +import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
21 31 import com.dinhcv.lifelogpedometer.utils.Const;
22 32 import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter;
  33 +import com.dinhcv.lifelogpedometer.utils.Debug;
23 34 import com.dinhcv.lifelogpedometer.utils.Utils;
24 35 import com.github.mikephil.charting.components.XAxis;
25 36 import com.github.mikephil.charting.components.YAxis;
... ... @@ -32,6 +43,9 @@ import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
32 43  
33 44 import org.eazegraph.lib.charts.PieChart;
34 45 import org.eazegraph.lib.models.PieModel;
  46 +import org.json.JSONArray;
  47 +import org.json.JSONException;
  48 +import org.json.JSONObject;
35 49  
36 50 import java.text.NumberFormat;
37 51 import java.util.ArrayList;
... ... @@ -43,9 +57,10 @@ import java.util.Locale;
43 57 import static com.github.mikephil.charting.utils.ColorTemplate.rgb;
44 58  
45 59  
46   -public class TopFragment extends FragmentBase implements SettingFragmentPresenter {
  60 +public class TopFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener {
47 61  
48 62 private TextView stepsView;
  63 + private TextView tvStepGoal;
49 64 private TextView tvDistance;
50 65 private TextView tvStepRemain;
51 66 private TextView tvStepRateDone;
... ... @@ -57,6 +72,10 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
57 72 private ImageView ivNext;
58 73 private ImageView ivPlay;
59 74  
  75 + private LinearLayout llBike;
  76 + private LinearLayout llWalking;
  77 + private LinearLayout llRunning;
  78 + private Const.STEP_TYPE stepType;
60 79  
61 80 private Date mAnaDate;
62 81 private Calendar mCalendar;
... ... @@ -65,11 +84,27 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
65 84 private int mAnaMonth;
66 85 private int mAnaYear;
67 86  
68   - private int todayOffset, total_start, since_boot;
69   - public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault());
70 87 public static int STEP_SIZE = 75;
71 88 private StepModel mStepModel;
  89 + private TextView tvSmallStepGoal;
72 90 private TextView tvSmallRemain;
  91 + private Context mContext;
  92 +
  93 + private SensorManager sensorManager;
  94 + private boolean activityRunning;
  95 + private int stepTotal = 0;
  96 + private int stepRemain = 0;
  97 + private int stepCount = 0;
  98 +
  99 + private Date mFromDate;
  100 + private Date mToDate;
  101 +
  102 + private TagetTopInfo mTagetTopInfo = new TagetTopInfo();
  103 + private BarChart mChart;
  104 +
  105 + private List<String> dateList;
  106 + private String[] mParties;
  107 + private Integer[] mStep;
73 108  
74 109 @Override
75 110 public void onCreate(final Bundle savedInstanceState) {
... ... @@ -80,19 +115,11 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
80 115 @Override
81 116 public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
82 117 final Bundle savedInstanceState) {
83   - final View v = inflater.inflate(com.dinhcv.lifelogpedometer.R.layout.fragment_top, null);
84   - stepsView = (TextView) v.findViewById(R.id.steps);
85   - tvDistance = (TextView) v.findViewById(R.id.tv_distance);
86   - tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain);
87   - tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone);
88   - tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain);
89   - tvDate = (TextView) v.findViewById(R.id.tv_date);
90   - ivBack = (ImageView) v.findViewById(R.id.iv_back);
91   - ivNext = (ImageView) v.findViewById(R.id.iv_next);
92   - ivPlay = (ImageView) v.findViewById(R.id.iv_play);
  118 + final View v = inflater.inflate(R.layout.fragment_top, null);
  119 + mContext = getActivity();
  120 + sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
93 121  
94   - mChart = (BarChart) v.findViewById(R.id.chart);
95   - pg = (PieChart) v.findViewById(R.id.graph);
  122 + initView(v);
96 123  
97 124 // slice for the steps taken today
98 125 sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7"));
... ... @@ -120,6 +147,23 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
120 147 return v;
121 148 }
122 149  
  150 + private void initView(View v){
  151 + stepsView = (TextView) v.findViewById(R.id.steps);
  152 + tvDistance = (TextView) v.findViewById(R.id.tv_distance);
  153 + tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal);
  154 + tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain);
  155 + tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone);
  156 + tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal);
  157 + tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain);
  158 + tvDate = (TextView) v.findViewById(R.id.tv_date);
  159 + ivBack = (ImageView) v.findViewById(R.id.iv_back);
  160 + ivNext = (ImageView) v.findViewById(R.id.iv_next);
  161 + ivPlay = (ImageView) v.findViewById(R.id.iv_play);
  162 +
  163 + mChart = (BarChart) v.findViewById(R.id.chart);
  164 + pg = (PieChart) v.findViewById(R.id.graph);
  165 + }
  166 +
123 167 private void stepsDistanceChanged() {
124 168 updatePie();
125 169 updateBars();
... ... @@ -187,11 +231,6 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
187 231 initGraph();
188 232 }
189 233  
190   - private BarChart mChart;
191   -
192   - private List<String> dateList;
193   - private String[] mParties;
194   - private Integer[] mStep;
195 234  
196 235 private void initGraph(){
197 236  
... ... @@ -321,9 +360,45 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
321 360 }
322 361 });
323 362  
  363 + llWalking.setOnClickListener(new View.OnClickListener() {
  364 + @Override
  365 + public void onClick(View view) {
  366 + stepType = Const.STEP_TYPE.WALKING;
  367 + updateUiStepType(false, true, false);
  368 + // add data
  369 + getTopData(mAnaDate, stepType);
  370 + }
  371 + });
  372 +
  373 + llRunning.setOnClickListener(new View.OnClickListener() {
  374 + @Override
  375 + public void onClick(View view) {
  376 + stepType = Const.STEP_TYPE.RUNNING;
  377 + updateUiStepType(false, false, true);
  378 + // add
  379 + getTopData(mAnaDate, stepType);
  380 + }
  381 + });
  382 +
  383 + llBike.setOnClickListener(new View.OnClickListener() {
  384 + @Override
  385 + public void onClick(View view) {
  386 + stepType = Const.STEP_TYPE.BIKE;
  387 + updateUiStepType(true, false, false);
  388 + // add data
  389 + getTopData(mAnaDate, stepType);
  390 + }
  391 + });
  392 +
324 393  
325 394 }
326 395  
  396 + private void updateUiStepType(boolean b1, boolean b2, boolean b3) {
  397 + llBike.setSelected(b1);
  398 + llWalking.setSelected(b2);
  399 + llRunning.setSelected(b3);
  400 + }
  401 +
327 402  
328 403 /**
329 404 * Show date picker dialog
... ... @@ -347,7 +422,100 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
347 422  
348 423 }
349 424  
  425 + private void getTopData(Date date, Const.STEP_TYPE stepType){
350 426  
  427 + showDialog(mContext);
  428 + LLAPIManager.topInfo(date, stepType, new LLAPIManagerListener() {
  429 + @Override
  430 + public void onError(Error error) {
  431 + Debug.error("Get data history error");
  432 + hiddenDialog();
  433 + showDialogNotData();
  434 + }
  435 +
  436 + @Override
  437 + public void onSuccess(String json) {
  438 + Debug.error("Get data history success");
  439 + hiddenDialog();
  440 + loadDataDone(json);
  441 + }
  442 +
  443 + @Override
  444 + public void onSuccess(JSONObject object) {
  445 + Debug.error("Get data history success");
  446 + hiddenDialog();
  447 + }
  448 + });
  449 + }
  450 +
  451 + private void showDialogNotData(){
  452 + showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data));
  453 + }
  454 +
  455 + private void loadDataDone(String jsonString) {
  456 + JSONObject jsonObject = null;
  457 + try {
  458 + jsonObject = new JSONObject(jsonString);
  459 + int status = jsonObject.optInt("status");
  460 + if (status == 1) {
  461 + JSONObject jsonObject1 = jsonObject.optJSONObject("result");
  462 + JSONObject targetInf = jsonObject1.getJSONObject("targetInf");
  463 + JSONArray listNotice = jsonObject1.getJSONArray("listNotice");
  464 +
  465 + if (targetInf != null){
  466 + String target = targetInf.optString("target_step");
  467 + Debug.normal("Target: "+ target);
  468 + mTagetTopInfo.setTaget(targetInf.optString("target_step"));
  469 + mTagetTopInfo.setSteps(targetInf.optString("num_step"));
  470 + mTagetTopInfo.setStepRemain(targetInf.optString("remaining_step"));
  471 + mTagetTopInfo.setCompletePercent(targetInf.optString("complete_percent"));
  472 + }
  473 +
  474 + if (listNotice != null && listNotice.length() > 0) {
  475 + List<StepHourInfo> infoLists = new ArrayList<>();
  476 + for (int i = 0; i < listNotice.length(); i++){
  477 + StepHourInfo noticeInfo = new StepHourInfo();
  478 + JSONObject ob = (JSONObject) listNotice.get(i);
  479 + noticeInfo.setId(ob.optInt("id"));
  480 + noticeInfo.setContent(ob.optString("notice_content"));
  481 + infoLists.add(noticeInfo);
  482 + }
  483 +
  484 + mTagetTopInfo.setStepHourList(infoLists);
  485 + }
  486 +
  487 + }
  488 + } catch (JSONException e) {
  489 + e.printStackTrace();
  490 + mTagetTopInfo = new TagetTopInfo();;
  491 + }
  492 +
  493 + loadUI();
  494 + }
  495 +
  496 +
  497 + private void loadUI(){
  498 + tvStep.setText(String.valueOf(mTagetInfo.getSteps()));
  499 + tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain()));
  500 + tvRateDone.setText(getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent()));
  501 +
  502 + List<StepHourInfo> infoLists = mTagetTopInfo.getStepHourList();
  503 + if (infoLists != null && infoLists.size() >0){
  504 + mNoticeAdapter = new NoticeAdapter(mContext, infoLists);
  505 + lvNotice.setAdapter(mNoticeAdapter);
  506 + lvNotice.setExpanded(true);
  507 + }
  508 +
  509 + }
  510 +
  511 + private void updateUI(){
  512 + stepTotal = stepTotal + stepCount;
  513 + stepRemain = stepRemain - stepCount;
  514 + double percentDone = stepTotal *100.0 / (stepTotal + stepRemain);
  515 + tvStep.setText(String.valueOf(stepTotal));
  516 + tvRemain.setText(mTagetInfo.getStepRemain());
  517 + tvRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone)));
  518 + }
351 519  
352 520 @Override
353 521 public void onAttach(Context context) {
... ... @@ -376,4 +544,64 @@ public class TopFragment extends FragmentBase implements SettingFragmentPresente
376 544 initData();
377 545 }
378 546  
  547 +
  548 + @Override
  549 + public void onResume() {
  550 + super.onResume();
  551 + activityRunning = true;
  552 + Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
  553 + if (countSensor != null) {
  554 + sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
  555 + } else {
  556 + Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show();
  557 + }
  558 + }
  559 +
  560 + @Override
  561 + public void onSensorChanged(SensorEvent event) {
  562 + if (activityRunning){
  563 + stepCount = (int) event.values[0];
  564 + // update UI
  565 + updateUI();
  566 + }
  567 + }
  568 +
  569 + @Override
  570 + public void onAccuracyChanged(Sensor sensor, int accuracy) {
  571 +
  572 + }
  573 +
  574 + @Override
  575 + public void onPause() {
  576 + super.onPause();
  577 + activityRunning = false;
  578 + }
  579 +
  580 + @Override
  581 + public void onDestroy() {
  582 + super.onDestroy();
  583 + // create log step
  584 + creatLogStep();
  585 + }
  586 +
  587 + private void creatLogStep(){
  588 +
  589 + LLAPIManager.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() {
  590 + @Override
  591 + public void onError(Error error) {
  592 + Debug.error("Get data history error");
  593 + }
  594 +
  595 + @Override
  596 + public void onSuccess(String json) {
  597 + Debug.error("Get data history success");
  598 + }
  599 +
  600 + @Override
  601 + public void onSuccess(JSONObject object) {
  602 + Debug.error("Get data history success");
  603 + }
  604 + });
  605 + }
  606 +
379 607 }
app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/top/StepHourInfo.java
... ... @@ -0,0 +1,23 @@
  1 +package com.dinhcv.lifelogpedometer.model.structure.top;
  2 +
  3 +public class StepHourInfo {
  4 + private int hour;
  5 + private int step;
  6 +
  7 + public int getHour() {
  8 + return hour;
  9 + }
  10 +
  11 + public void setHour(int hour) {
  12 + this.hour = hour;
  13 + }
  14 +
  15 + public int getStep() {
  16 + return step;
  17 + }
  18 +
  19 + public void setStep(int step) {
  20 + this.step = step;
  21 + }
  22 +
  23 +}
app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/top/TagetTopInfo.java
... ... @@ -0,0 +1,83 @@
  1 +package com.dinhcv.lifelogpedometer.model.structure.top;
  2 +
  3 +import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo;
  4 +
  5 +import java.util.List;
  6 +
  7 +public class TagetTopInfo {
  8 + private String taget;
  9 + private String steps;
  10 + private String stepRemain;
  11 + private String completePercent;
  12 + private String calo;
  13 + private String distance;
  14 + private String time;
  15 +
  16 + private List<StepHourInfo> stepHourList;
  17 +
  18 +
  19 + public String getTaget() {
  20 + return taget;
  21 + }
  22 +
  23 + public void setTaget(String taget) {
  24 + this.taget = taget;
  25 + }
  26 +
  27 + public String getSteps() {
  28 + return steps;
  29 + }
  30 +
  31 + public void setSteps(String steps) {
  32 + this.steps = steps;
  33 + }
  34 +
  35 + public String getStepRemain() {
  36 + return stepRemain;
  37 + }
  38 +
  39 + public void setStepRemain(String stepRemain) {
  40 + this.stepRemain = stepRemain;
  41 + }
  42 +
  43 + public String getCompletePercent() {
  44 + return completePercent;
  45 + }
  46 +
  47 + public void setCompletePercent(String completePercent) {
  48 + this.completePercent = completePercent;
  49 + }
  50 +
  51 + public String getCalo() {
  52 + return calo;
  53 + }
  54 +
  55 + public void setCalo(String calo) {
  56 + this.calo = calo;
  57 + }
  58 +
  59 + public String getDistance() {
  60 + return distance;
  61 + }
  62 +
  63 + public void setDistance(String distance) {
  64 + this.distance = distance;
  65 + }
  66 +
  67 + public String getTime() {
  68 + return time;
  69 + }
  70 +
  71 + public void setTime(String taget) {
  72 + this.time = time;
  73 + }
  74 +
  75 + public void setStepHourList(List<StepHourInfo> stepHourList){
  76 + this.stepHourList = stepHourList;
  77 + }
  78 +
  79 + public List<StepHourInfo> getStepHourList(){
  80 + return stepHourList;
  81 + }
  82 +
  83 +}
app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
... ... @@ -61,6 +61,11 @@ public class LLAPIManager {
61 61 public static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm";
62 62 // Refesh Token
63 63 public static String URL_REFESH_TOKEN_INFO = "refreshToken";
  64 + // Top info
  65 + public static String URL_TOP_INFO = "api/top";
  66 + // Refesh Token
  67 + public static String URL_CREATE_LOG_INFO = "api/createLog";
  68 +
64 69  
65 70  
66 71 private static int deviationValue = 1;
... ... @@ -756,6 +761,171 @@ public class LLAPIManager {
756 761 }.execute();
757 762 }
758 763  
  764 + public static void topInfo(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) {
  765 + new AsyncTask<Void, Void, String>() {
  766 +
  767 +
  768 + @Override
  769 + protected void onPreExecute() {
  770 + super.onPreExecute();
  771 + }
  772 +
  773 + @Override
  774 + protected String doInBackground(Void... voids) {
  775 +
  776 + String dateStr = Utils.dateToStringFormatDayMonthYear(date);
  777 + Debug.normal("Token: "+ APIResponse.getInstance().getToken());
  778 + HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_TOP_INFO + "/"+ stepType.value +"/"+ dateStr);
  779 + Debug.normal("URL: "+baseUrl.toString());
  780 + final Request.Builder request = new Request.Builder()
  781 + .url(baseUrl)
  782 + .header("User-Agent", Utils.getCustomUA())
  783 + .header("Content-Type", "application/json")
  784 + .addHeader("token", APIResponse.getInstance().getToken())
  785 + .get();
  786 +
  787 + OkHttpClient httpClient = new OkHttpClient.Builder()
  788 + .readTimeout(30, TimeUnit.SECONDS)
  789 + .writeTimeout(30, TimeUnit.SECONDS)
  790 + .connectTimeout(30, TimeUnit.SECONDS)
  791 + .build();
  792 +
  793 + String jsonString = null;
  794 + try {
  795 + Response response = httpClient.newCall(request.build()).execute();
  796 + if (response == null) {
  797 + action.onError(null);
  798 + Debug.error("Response is null");
  799 + return null;
  800 + }
  801 + jsonString = getResponseData(response.body());
  802 +
  803 + } catch (IOException e) {
  804 + Debug.normal("Error %s", e.getMessage());
  805 + }
  806 + return jsonString;
  807 + }
  808 +
  809 + @Override
  810 + protected void onCancelled() {
  811 + super.onCancelled();
  812 + action.onError(null);
  813 + }
  814 +
  815 + @Override
  816 + protected void onPostExecute(String jsonString) {
  817 + super.onPostExecute(jsonString);
  818 + if ((jsonString == null) || (jsonString.isEmpty())) {
  819 + action.onError(null);
  820 + return;
  821 + }
  822 + Debug.normal("String body: "+jsonString);
  823 +
  824 + try {
  825 + JSONObject jsonObject = new JSONObject(jsonString);
  826 + int status = jsonObject.optInt("status");
  827 + if (status == 1) {
  828 + action.onSuccess(jsonString);
  829 + } else {
  830 + action.onError(new Error(jsonObject.getString("message")));
  831 + }
  832 + } catch (JSONException e) {
  833 + action.onError(null);
  834 + }
  835 + }
  836 + }.execute();
  837 + }
  838 +
  839 + public static void createLog(final Const.STEP_TYPE stepType, final int stepCount, final Date startTime,
  840 + final Date endTime, final LLAPIManagerListener action) {
  841 + new AsyncTask<Void, Void, String>() {
  842 +
  843 +
  844 + @Override
  845 + protected void onPreExecute() {
  846 + super.onPreExecute();
  847 + }
  848 +
  849 + @Override
  850 + protected String doInBackground(Void... voids) {
  851 + HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_CREATE_LOG_INFO);
  852 + JSONObject jsonObject = new JSONObject();
  853 + String startT = Utils.convertDate2DateTimeString(startTime);
  854 + String endT = Utils.convertDate2DateTimeString(endTime);
  855 + try {
  856 + jsonObject.put("mode", stepType.value);
  857 + jsonObject.put("numStep", stepCount);
  858 + jsonObject.put("startTime", startT);
  859 + jsonObject.put("endTime", endT);
  860 +
  861 + Debug.warn("Json data: " + jsonObject.toString());
  862 + } catch (JSONException e) {
  863 + Debug.normal("Error ", e.getMessage());
  864 + }
  865 +
  866 + MediaType JSON
  867 + = MediaType.parse("application/json");
  868 + RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
  869 +
  870 + final Request.Builder request = new Request.Builder()
  871 + .url(baseUrl)
  872 + .header("User-Agent", Utils.getCustomUA())
  873 + .header("Content-Type", "application/json")
  874 + .addHeader("token", APIResponse.getInstance().getToken())
  875 + .post(requestBody);
  876 +
  877 + OkHttpClient httpClient = new OkHttpClient.Builder()
  878 + .readTimeout(30, TimeUnit.SECONDS)
  879 + .writeTimeout(30, TimeUnit.SECONDS)
  880 + .connectTimeout(30, TimeUnit.SECONDS)
  881 + .build();
  882 +
  883 + String jsonString = null;
  884 + try {
  885 + Response response = httpClient.newCall(request.build()).execute();
  886 + if (response == null) {
  887 + action.onError(null);
  888 + Debug.error("Response is null");
  889 + return null;
  890 + }
  891 + jsonString = getResponseData(response.body());
  892 +
  893 + } catch (IOException e) {
  894 + Debug.normal("Error %s", e.getMessage());
  895 + }
  896 + return jsonString;
  897 + }
  898 +
  899 + @Override
  900 + protected void onCancelled() {
  901 + super.onCancelled();
  902 + action.onError(null);
  903 + }
  904 +
  905 + @Override
  906 + protected void onPostExecute(String jsonString) {
  907 + super.onPostExecute(jsonString);
  908 + if ((jsonString == null) || (jsonString.isEmpty())) {
  909 + action.onError(null);
  910 + return;
  911 + }
  912 + Debug.normal("String body: "+jsonString);
  913 +
  914 + try {
  915 + JSONObject jsonObject = new JSONObject(jsonString);
  916 + int status = jsonObject.optInt("status");
  917 + if (status == 1) {
  918 + action.onSuccess(jsonString);
  919 + } else {
  920 + action.onError(new Error(jsonObject.getString("message")));
  921 + }
  922 + } catch (JSONException e) {
  923 + action.onError(null);
  924 + }
  925 + }
  926 + }.execute();
  927 + }
  928 +
759 929 public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) {
760 930 new AsyncTask<Void, Void, String>() {
761 931  
app/src/main/java/com/dinhcv/lifelogpedometer/utils/Utils.java
... ... @@ -255,6 +255,11 @@ public class Utils {
255 255 return date;
256 256 }
257 257  
  258 + public static String convertDate2DateTimeString(Date date) {
  259 + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  260 + return df.format(date);
  261 + }
  262 +
258 263 public static String convertDate2DayString(Date date) {
259 264 DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
260 265 return df.format(date);
app/src/main/res/layout/fragment_top.xml
... ... @@ -124,6 +124,7 @@
124 124 android:textColor="@color/white"/>
125 125  
126 126 <TextView
  127 + android:id="@+id/tv_smallStepGoal"
127 128 android:layout_width="wrap_content"
128 129 android:layout_height="wrap_content"
129 130 android:text="@string/pie_text_content1"
... ... @@ -269,6 +270,7 @@
269 270 android:orientation="vertical">
270 271  
271 272 <TextView
  273 + android:id="@+id/tv_time"
272 274 android:layout_width="wrap_content"
273 275 android:layout_height="wrap_content"
274 276 android:text="1:09"
... ... @@ -335,7 +337,6 @@
335 337 android:orientation="vertical">
336 338  
337 339 <TextView
338   - android:id="@+id/tv_remainingStep"
339 340 android:layout_width="wrap_content"
340 341 android:layout_height="wrap_content"
341 342 android:text="@string/km"
... ... @@ -352,7 +353,6 @@
352 353 android:orientation="vertical">
353 354  
354 355 <TextView
355   - android:id="@+id/tv_time"
356 356 android:layout_width="wrap_content"
357 357 android:layout_height="wrap_content"
358 358 android:text="@string/time"
app/src/main/res/values/strings.xml
... ... @@ -128,46 +128,46 @@
128 128  
129 129 <string name="prefecture">都道府県</string>
130 130  
131   - <string name="login_error_title">Login error</string>
132   - <string name="login_error">Can not login</string>
  131 + <string name="login_error_title">ログインエラー</string>
  132 + <string name="login_error">ログインできません。</string>
133 133 <string name="ok">OK</string>
134   - <string name="error_title">Error</string>
135   - <string name="password_is_null">Password is nulll</string>
136   - <string name="account_is_null">Email is null</string>
137   - <string name="uploading">Uploading</string>
138   - <string name="register_err">Register error</string>
139   - <string name="err_exception">Error exception</string>
  134 + <string name="error_title">エラー</string>
  135 + <string name="password_is_null">パスワードはnullです。</string>
  136 + <string name="account_is_null">メールはヌルです。</string>
  137 + <string name="uploading">アップロード中</string>
  138 + <string name="register_err">レジスタエラー</string>
  139 + <string name="err_exception">エラー例外</string>
140 140 <string name="cm">cm</string>
141 141 <string name="kg">kg</string>
142 142 <string name="percen">%</string>
143   - <string name="waite_some_minute">Please waite some minute</string>
144   - <string name="request_pass_error">Can not sent request get password</string>
145   - <string name="password_not_send">Password have not send, please try it again</string>
146   - <string name="password_have_send">Password have send, please check mail</string>
147   - <string name="register_success">Register success</string>
  143 + <string name="waite_some_minute">しばらくお待ちください。</string>
  144 + <string name="request_pass_error">要求を送信できないため、パスワードを取得できません。</string>
  145 + <string name="password_not_send">パスワードが送信されていません。もう一度お試しください。</string>
  146 + <string name="password_have_send">パスワードが送られてきました、メールをチェックしてください。</string>
  147 + <string name="register_success">登録成功</string>
148 148  
149 149 <!-- message error register -->
150   - <string name="username_null">Username is null</string>
151   - <string name="name_null">Name is null</string>
152   - <string name="nickname_null">Nickname is null</string>
153   - <string name="mail_null">Email is null</string>
154   - <string name="mail_invalid">Email invalid</string>
155   - <string name="password_null">Password is null</string>
156   - <string name="confirm_pass_null">Confirm password is null</string>
157   - <string name="password_less_6">Password length is more than 6 character</string>
158   - <string name="confirm_pass_wrong">Confirm password is wrong</string>
159   - <string name="sex_not_select">Sex is not select</string>
160   - <string name="birthday_not_select">Birthday is not select</string>
161   - <string name="height_null">Hight is null</string>
162   - <string name="weight_null">Weight is null</string>
163   - <string name="body_fat_percent_null">Body fat percent is null</string>
164   - <string name="comment_null">Comment is null</string>
165   - <string name="level_not_select">Level is not select</string>
166   - <string name="province_not_select">Province is not select</string>
  150 + <string name="username_null">ユーザー名はnullです。</string>
  151 + <string name="name_null">名前はnullです。</string>
  152 + <string name="nickname_null">ニックネームはnullです。</string>
  153 + <string name="mail_null">メールはヌルです。</string>
  154 + <string name="mail_invalid">電子メールが無効です。</string>
  155 + <string name="password_null">パスワードはnullです。</string>
  156 + <string name="confirm_pass_null">パスワードの確認はnullです。</string>
  157 + <string name="password_less_6">パスワードの長さは6文字以上です。</string>
  158 + <string name="confirm_pass_wrong">パスワードの確認が間違っています。</string>
  159 + <string name="sex_not_select">性別は選択されていません。</string>
  160 + <string name="birthday_not_select">誕生日は選択されていません。</string>
  161 + <string name="height_null">Hightはnullです。</string>
  162 + <string name="weight_null">重量はnullです。</string>
  163 + <string name="body_fat_percent_null">体脂肪率はnullです。</string>
  164 + <string name="comment_null">コメントはnullです。</string>
  165 + <string name="level_not_select">レベルは選択されていません。</string>
  166 + <string name="province_not_select">州は選択されていません。</string>
167 167  
168   - <string name="please_input_email">Please input email</string>
169   - <string name="please_input_confirm">Please input confirm code</string>
170   - <string name="send_confirm">Send confirm</string>
  168 + <string name="please_input_email">メールを入力してください。</string>
  169 + <string name="please_input_confirm">確認コードを入力してください。</string>
  170 + <string name="send_confirm">送信確認</string>
171 171  
172 172 <!--string relationship-->
173 173 <string name="male">男</string>
... ... @@ -293,7 +293,9 @@
293 293 <string name="weather">天気</string>
294 294  
295 295 <string name="calo_consumed">消費カロリー</string>
296   - <string name="can_not_get_data">Can not get data</string>
  296 + <string name="can_not_get_data">データを取得できません。</string>
297 297 <string name="loading">読み込み中</string>
298 298  
  299 + <string name="sensor_available">カウントセンサーが使用できません。</string>
  300 +
299 301 </resources>
300 302 \ No newline at end of file