Compare View
Commits (2)
Changes
Showing 12 changed files Inline Diff
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/DateFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/MainActivity.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/SensorFilter.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/StepDetector.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/StepListener.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/top/StepHourInfo.java
- app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/top/TagetTopInfo.java
- app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
- app/src/main/java/com/dinhcv/lifelogpedometer/utils/Utils.java
- app/src/main/res/layout/fragment_top.xml
- app/src/main/res/values/strings.xml
app/src/main/java/com/dinhcv/lifelogpedometer/activity/DateFragment.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.content.SharedPreferences; | 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 | import android.hardware.Sensor; | 11 | import android.os.Bundle; |
| 8 | import android.hardware.SensorEvent; | 12 | import android.support.annotation.Nullable; |
| 9 | import android.hardware.SensorEventListener; | 13 | import android.support.v4.app.Fragment; |
| 10 | import android.hardware.SensorManager; | 14 | import android.view.LayoutInflater; |
| 11 | import android.os.Bundle; | 15 | import android.view.View; |
| 12 | import android.support.annotation.Nullable; | 16 | import android.view.ViewGroup; |
| 13 | import android.support.v4.app.Fragment; | 17 | import android.widget.DatePicker; |
| 14 | import android.view.LayoutInflater; | 18 | import android.widget.ImageView; |
| 15 | import android.view.View; | 19 | import android.widget.LinearLayout; |
| 16 | import android.view.ViewGroup; | 20 | import android.widget.TextView; |
| 21 | import android.widget.Toast; | ||
| 17 | import android.widget.DatePicker; | 22 | |
| 18 | import android.widget.ImageView; | 23 | import com.dinhcv.lifelogpedometer.R; |
| 19 | import android.widget.LinearLayout; | 24 | import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter; |
| 20 | import android.widget.TextView; | 25 | import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; |
| 21 | import android.widget.Toast; | 26 | import com.dinhcv.lifelogpedometer.feature.Database; |
| 22 | 27 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | |
| 23 | import com.dinhcv.lifelogpedometer.R; | 28 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; |
| 24 | import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter; | 29 | import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo; |
| 25 | import com.dinhcv.lifelogpedometer.customview.ExpandableListCustomView; | 30 | import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo; |
| 26 | import com.dinhcv.lifelogpedometer.feature.Database; | 31 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 27 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 32 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 28 | import com.dinhcv.lifelogpedometer.model.structure.history.HistoryInfo; | 33 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 29 | import com.dinhcv.lifelogpedometer.model.structure.home.NoticeInfo; | 34 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 30 | import com.dinhcv.lifelogpedometer.model.structure.home.TagetInfo; | 35 | |
| 31 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 36 | import org.json.JSONArray; |
| 32 | import com.dinhcv.lifelogpedometer.utils.Const; | 37 | import org.json.JSONException; |
| 33 | import com.dinhcv.lifelogpedometer.utils.Debug; | 38 | import org.json.JSONObject; |
| 34 | import com.dinhcv.lifelogpedometer.utils.Utils; | 39 | |
| 35 | 40 | import java.util.ArrayList; | |
| 36 | import org.json.JSONArray; | 41 | import java.util.Calendar; |
| 37 | import org.json.JSONException; | 42 | import java.util.Date; |
| 38 | import org.json.JSONObject; | 43 | import java.util.List; |
| 39 | 44 | ||
| 40 | import java.util.ArrayList; | 45 | import static com.dinhcv.lifelogpedometer.utils.Utils.getStandarDate; |
| 41 | import java.util.Calendar; | 46 | |
| 42 | import java.util.Date; | 47 | public class DateFragment extends FragmentBase implements SettingFragmentPresenter { |
| 43 | import java.util.List; | 48 | |
| 44 | 49 | private TextView tvDate; | |
| 45 | import static com.dinhcv.lifelogpedometer.utils.Utils.getStandarDate; | 50 | private TextView tvStep; |
| 46 | 51 | private TextView tvRemain; | |
| 47 | public class DateFragment extends FragmentBase implements SettingFragmentPresenter { | 52 | private TextView tvRateDone; |
| 48 | 53 | private ImageView ivBack; | |
| 49 | private TextView tvDate; | 54 | private ImageView ivNext; |
| 50 | private TextView tvStep; | 55 | |
| 51 | private TextView tvRemain; | 56 | private LinearLayout llBike; |
| 52 | private TextView tvRateDone; | 57 | private LinearLayout llWalking; |
| 53 | private ImageView ivBack; | 58 | private LinearLayout llRunning; |
| 54 | private ImageView ivNext; | 59 | |
| 55 | 60 | private Date mAnaDate; | |
| 56 | private LinearLayout llBike; | 61 | private Calendar mCalendar; |
| 57 | private LinearLayout llWalking; | 62 | |
| 58 | private LinearLayout llRunning; | 63 | private int mAnaDay; |
| 59 | 64 | private int mAnaMonth; | |
| 60 | private Date mAnaDate; | 65 | private int mAnaYear; |
| 61 | private Calendar mCalendar; | 66 | private Context mContext; |
| 62 | 67 | ||
| 63 | private int mAnaDay; | 68 | private Const.STEP_TYPE stepType; |
| 64 | private int mAnaMonth; | 69 | private TagetInfo mTagetInfo = new TagetInfo(); |
| 65 | private int mAnaYear; | 70 | |
| 66 | private Context mContext; | 71 | private ExpandableListCustomView lvNotice; |
| 67 | 72 | private NoticeAdapter mNoticeAdapter; | |
| 68 | private Const.STEP_TYPE stepType; | 73 | |
| 69 | private TagetInfo mTagetInfo = new TagetInfo(); | 74 | @Override |
| 70 | 75 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle | |
| 71 | private ExpandableListCustomView lvNotice; | 76 | savedInstanceState) { |
| 72 | private NoticeAdapter mNoticeAdapter; | 77 | // Inflate the layout for this fragment |
| 73 | 78 | View rootView = inflater.inflate(R.layout.fragment_date, container, false); | |
| 74 | @Override | 79 | mContext = getActivity(); |
| 75 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle | 80 | initView(rootView); |
| 76 | savedInstanceState) { | 81 | initData(); |
| 77 | // Inflate the layout for this fragment | 82 | return rootView; |
| 78 | View rootView = inflater.inflate(R.layout.fragment_date, container, false); | 83 | } |
| 79 | mContext = getActivity(); | 84 | |
| 80 | initView(rootView); | 85 | |
| 81 | initData(); | 86 | private void initView(View rootView) { |
| 82 | return rootView; | 87 | tvDate = (TextView) rootView.findViewById(R.id.tv_date); |
| 83 | } | 88 | tvStep = (TextView) rootView.findViewById(R.id.tv_step); |
| 84 | 89 | tvRemain = (TextView) rootView.findViewById(R.id.tv_remainingStep); | |
| 85 | 90 | tvRateDone = (TextView) rootView.findViewById(R.id.tv_completeRate); | |
| 86 | private void initView(View rootView) { | 91 | ivBack = (ImageView) rootView.findViewById(R.id.iv_back); |
| 87 | tvDate = (TextView) rootView.findViewById(R.id.tv_date); | 92 | ivNext = (ImageView) rootView.findViewById(R.id.iv_next); |
| 88 | tvStep = (TextView) rootView.findViewById(R.id.tv_step); | 93 | |
| 89 | tvRemain = (TextView) rootView.findViewById(R.id.tv_remainingStep); | 94 | llBike = (LinearLayout) rootView.findViewById(R.id.ll_bike); |
| 90 | tvRateDone = (TextView) rootView.findViewById(R.id.tv_completeRate); | 95 | llWalking = (LinearLayout) rootView.findViewById(R.id.ll_walking); |
| 91 | ivBack = (ImageView) rootView.findViewById(R.id.iv_back); | 96 | llRunning = (LinearLayout) rootView.findViewById(R.id.ll_running); |
| 92 | ivNext = (ImageView) rootView.findViewById(R.id.iv_next); | 97 | |
| 93 | 98 | lvNotice = (ExpandableListCustomView) rootView.findViewById(R.id.lv_notice); | |
| 94 | llBike = (LinearLayout) rootView.findViewById(R.id.ll_bike); | 99 | |
| 95 | llWalking = (LinearLayout) rootView.findViewById(R.id.ll_walking); | 100 | handleEvent(); |
| 96 | llRunning = (LinearLayout) rootView.findViewById(R.id.ll_running); | 101 | } |
| 97 | 102 | ||
| 98 | lvNotice = (ExpandableListCustomView) rootView.findViewById(R.id.lv_notice); | 103 | private void handleEvent(){ |
| 99 | 104 | tvDate.setOnClickListener(new View.OnClickListener() { | |
| 100 | handleEvent(); | 105 | @Override |
| 101 | } | 106 | public void onClick(View view) { |
| 102 | 107 | handleAnaDatePicker(); | |
| 103 | private void handleEvent(){ | 108 | } |
| 104 | tvDate.setOnClickListener(new View.OnClickListener() { | 109 | }); |
| 105 | @Override | 110 | |
| 106 | public void onClick(View view) { | 111 | ivBack.setOnClickListener(new View.OnClickListener() { |
| 107 | handleAnaDatePicker(); | 112 | @Override |
| 108 | } | 113 | public void onClick(View view) { |
| 109 | }); | 114 | mCalendar = Calendar.getInstance(); |
| 110 | 115 | mCalendar.setTime(mAnaDate); | |
| 111 | ivBack.setOnClickListener(new View.OnClickListener() { | 116 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 112 | @Override | 117 | Date date = mCalendar.getTime(); |
| 113 | public void onClick(View view) { | 118 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 114 | mCalendar = Calendar.getInstance(); | 119 | mAnaDate = date; |
| 115 | mCalendar.setTime(mAnaDate); | 120 | getHomePage(mAnaDate, stepType); |
| 116 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 121 | } |
| 117 | Date date = mCalendar.getTime(); | 122 | }); |
| 118 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 123 | |
| 119 | mAnaDate = date; | 124 | ivNext.setOnClickListener(new View.OnClickListener() { |
| 120 | getHomePage(mAnaDate, stepType); | 125 | @Override |
| 121 | } | 126 | public void onClick(View view) { |
| 122 | }); | 127 | mCalendar = Calendar.getInstance(); |
| 123 | 128 | mCalendar.setTime(mAnaDate); | |
| 124 | ivNext.setOnClickListener(new View.OnClickListener() { | 129 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); |
| 125 | @Override | 130 | Date date = mCalendar.getTime(); |
| 126 | public void onClick(View view) { | 131 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 127 | mCalendar = Calendar.getInstance(); | 132 | mAnaDate = date; |
| 128 | mCalendar.setTime(mAnaDate); | 133 | getHomePage(mAnaDate, stepType); |
| 129 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 134 | } |
| 130 | Date date = mCalendar.getTime(); | 135 | }); |
| 131 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 136 | |
| 132 | mAnaDate = date; | 137 | |
| 133 | getHomePage(mAnaDate, stepType); | 138 | llWalking.setOnClickListener(new View.OnClickListener() { |
| 134 | } | 139 | @Override |
| 135 | }); | 140 | public void onClick(View view) { |
| 136 | 141 | stepType = Const.STEP_TYPE.WALKING; | |
| 137 | 142 | updateUiStepType(false, true, false); | |
| 138 | llWalking.setOnClickListener(new View.OnClickListener() { | 143 | // add data |
| 139 | @Override | 144 | getHomePage(mAnaDate, stepType); |
| 140 | public void onClick(View view) { | 145 | } |
| 141 | stepType = Const.STEP_TYPE.WALKING; | 146 | }); |
| 142 | updateUiStepType(false, true, false); | 147 | |
| 143 | // add data | 148 | llRunning.setOnClickListener(new View.OnClickListener() { |
| 144 | getHomePage(mAnaDate, stepType); | 149 | @Override |
| 145 | } | 150 | public void onClick(View view) { |
| 146 | }); | 151 | stepType = Const.STEP_TYPE.RUNNING; |
| 147 | 152 | updateUiStepType(false, false, true); | |
| 148 | llRunning.setOnClickListener(new View.OnClickListener() { | 153 | // add |
| 149 | @Override | 154 | getHomePage(mAnaDate, stepType); |
| 150 | public void onClick(View view) { | 155 | } |
| 151 | stepType = Const.STEP_TYPE.RUNNING; | 156 | }); |
| 152 | updateUiStepType(false, false, true); | 157 | |
| 153 | // add | 158 | llBike.setOnClickListener(new View.OnClickListener() { |
| 154 | getHomePage(mAnaDate, stepType); | 159 | @Override |
| 155 | } | 160 | public void onClick(View view) { |
| 156 | }); | 161 | stepType = Const.STEP_TYPE.BIKE; |
| 157 | 162 | updateUiStepType(true, false, false); | |
| 158 | llBike.setOnClickListener(new View.OnClickListener() { | 163 | // add data |
| 159 | @Override | 164 | getHomePage(mAnaDate, stepType); |
| 160 | public void onClick(View view) { | 165 | } |
| 161 | stepType = Const.STEP_TYPE.BIKE; | 166 | }); |
| 162 | updateUiStepType(true, false, false); | 167 | |
| 163 | // add data | 168 | } |
| 164 | getHomePage(mAnaDate, stepType); | 169 | |
| 165 | } | 170 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 166 | }); | 171 | llBike.setSelected(b1); |
| 167 | 172 | llWalking.setSelected(b2); | |
| 168 | } | 173 | llRunning.setSelected(b3); |
| 169 | 174 | } | |
| 170 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 175 | |
| 171 | llBike.setSelected(b1); | 176 | /** |
| 172 | llWalking.setSelected(b2); | 177 | * Show date picker dialog |
| 173 | llRunning.setSelected(b3); | 178 | */ |
| 174 | } | 179 | private void handleAnaDatePicker() { |
| 175 | 180 | ||
| 176 | /** | 181 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { |
| 177 | * Show date picker dialog | 182 | @Override |
| 178 | */ | 183 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 179 | private void handleAnaDatePicker() { | 184 | |
| 180 | 185 | mCalendar = Calendar.getInstance(); | |
| 181 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { | 186 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 182 | @Override | 187 | mAnaYear = year; |
| 183 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { | 188 | mAnaMonth = monthOfYear; |
| 184 | 189 | mAnaDay = dayOfMonth; | |
| 185 | mCalendar = Calendar.getInstance(); | 190 | Date date = mCalendar.getTime(); |
| 186 | mCalendar.set(year, monthOfYear, dayOfMonth); | 191 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 187 | mAnaYear = year; | 192 | mAnaDate = date; |
| 188 | mAnaMonth = monthOfYear; | 193 | |
| 189 | mAnaDay = dayOfMonth; | 194 | getHomePage(mAnaDate, stepType); |
| 190 | Date date = mCalendar.getTime(); | 195 | } |
| 191 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 196 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 192 | mAnaDate = date; | 197 | |
| 193 | 198 | } | |
| 194 | getHomePage(mAnaDate, stepType); | 199 | |
| 195 | } | 200 | |
| 196 | }, mAnaYear, mAnaMonth, mAnaDay).show(); | 201 | /** |
| 197 | 202 | * init data for | |
| 198 | } | 203 | */ |
| 199 | 204 | private void initData() { | |
| 200 | 205 | mCalendar = Calendar.getInstance(); | |
| 201 | /** | 206 | mCalendar.setTime(new Date()); |
| 202 | * init data for | 207 | mAnaDate = mCalendar.getTime(); |
| 203 | */ | 208 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 204 | private void initData() { | 209 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 205 | mCalendar = Calendar.getInstance(); | 210 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 206 | mCalendar.setTime(new Date()); | 211 | |
| 207 | mAnaDate = mCalendar.getTime(); | 212 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 208 | mAnaYear = mCalendar.get(Calendar.YEAR); | 213 | |
| 209 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 214 | stepType = Const.STEP_TYPE.WALKING; |
| 210 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 215 | updateUiStepType(false, true, false); |
| 211 | 216 | getHomePage(mAnaDate, stepType); | |
| 212 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 217 | } |
| 213 | 218 | ||
| 214 | stepType = Const.STEP_TYPE.WALKING; | 219 | |
| 215 | updateUiStepType(false, true, false); | 220 | private void getHomePage(Date date, Const.STEP_TYPE stepType){ |
| 216 | getHomePage(mAnaDate, stepType); | 221 | |
| 217 | } | 222 | showDialog(mContext); |
| 218 | 223 | LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() { | |
| 219 | 224 | @Override | |
| 220 | private void getHomePage(Date date, Const.STEP_TYPE stepType){ | 225 | public void onError(Error error) { |
| 221 | 226 | Debug.error("Get data history error"); | |
| 222 | showDialog(mContext); | 227 | hiddenDialog(); |
| 223 | LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() { | 228 | showDialogNotData(); |
| 224 | @Override | 229 | } |
| 225 | public void onError(Error error) { | 230 | |
| 226 | Debug.error("Get data history error"); | 231 | @Override |
| 227 | hiddenDialog(); | 232 | public void onSuccess(String json) { |
| 228 | showDialogNotData(); | 233 | Debug.error("Get data history success"); |
| 229 | } | 234 | hiddenDialog(); |
| 230 | 235 | loadDataDone(json); | |
| 231 | @Override | 236 | } |
| 232 | public void onSuccess(String json) { | 237 | |
| 233 | Debug.error("Get data history success"); | 238 | @Override |
| 234 | hiddenDialog(); | 239 | public void onSuccess(JSONObject object) { |
| 235 | loadDataDone(json); | 240 | Debug.error("Get data history success"); |
| 236 | } | 241 | hiddenDialog(); |
| 237 | 242 | } | |
| 238 | @Override | 243 | }); |
| 239 | public void onSuccess(JSONObject object) { | 244 | } |
| 240 | Debug.error("Get data history success"); | 245 | |
| 241 | hiddenDialog(); | 246 | private void showDialogNotData(){ |
| 242 | } | 247 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 243 | }); | 248 | } |
| 244 | } | 249 | |
| 245 | 250 | private void loadDataDone(String jsonString) { | |
| 246 | private void showDialogNotData(){ | 251 | JSONObject jsonObject = null; |
| 247 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 252 | try { |
| 248 | } | 253 | jsonObject = new JSONObject(jsonString); |
| 249 | 254 | int status = jsonObject.optInt("status"); | |
| 250 | private void loadDataDone(String jsonString) { | 255 | if (status == 1) { |
| 251 | JSONObject jsonObject = null; | 256 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 252 | try { | 257 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); |
| 253 | jsonObject = new JSONObject(jsonString); | 258 | JSONArray listNotice = jsonObject1.getJSONArray("listNotice"); |
| 254 | int status = jsonObject.optInt("status"); | 259 | |
| 255 | if (status == 1) { | 260 | if (targetInf != null){ |
| 256 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 261 | String target = targetInf.optString("target_step"); |
| 257 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); | 262 | Debug.normal("Target: "+ target); |
| 258 | JSONArray listNotice = jsonObject1.getJSONArray("listNotice"); | 263 | mTagetInfo.setTaget(targetInf.optString("target_step")); |
| 259 | 264 | mTagetInfo.setSteps(targetInf.optString("num_step")); | |
| 260 | if (targetInf != null){ | 265 | mTagetInfo.setStepRemain(targetInf.optString("remaining_step")); |
| 261 | String target = targetInf.optString("target_step"); | 266 | mTagetInfo.setCompletePercent(targetInf.optString("complete_percent")); |
| 262 | Debug.normal("Target: "+ target); | 267 | } |
| 263 | mTagetInfo.setTaget(targetInf.optString("target_step")); | 268 | |
| 264 | mTagetInfo.setSteps(targetInf.optString("num_step")); | 269 | if (listNotice != null && listNotice.length() > 0) { |
| 265 | mTagetInfo.setStepRemain(targetInf.optString("remaining_step")); | 270 | List<NoticeInfo> infoLists = new ArrayList<>(); |
| 266 | mTagetInfo.setCompletePercent(targetInf.optString("complete_percent")); | 271 | for (int i = 0; i < listNotice.length(); i++){ |
| 267 | } | 272 | NoticeInfo noticeInfo = new NoticeInfo(); |
| 268 | 273 | JSONObject ob = (JSONObject) listNotice.get(i); | |
| 269 | if (listNotice != null && listNotice.length() > 0) { | 274 | noticeInfo.setId(ob.optInt("id")); |
| 270 | List<NoticeInfo> infoLists = new ArrayList<>(); | 275 | noticeInfo.setContent(ob.optString("notice_content")); |
| 271 | for (int i = 0; i < listNotice.length(); i++){ | 276 | infoLists.add(noticeInfo); |
| 272 | NoticeInfo noticeInfo = new NoticeInfo(); | 277 | } |
| 273 | JSONObject ob = (JSONObject) listNotice.get(i); | 278 | |
| 274 | noticeInfo.setId(ob.optInt("id")); | 279 | mTagetInfo.setNoticeList(infoLists); |
| 275 | noticeInfo.setContent(ob.optString("notice_content")); | 280 | } |
| 276 | infoLists.add(noticeInfo); | 281 | |
| 277 | } | 282 | } |
| 278 | 283 | } catch (JSONException e) { | |
| 279 | mTagetInfo.setNoticeList(infoLists); | 284 | e.printStackTrace(); |
| 280 | } | 285 | mTagetInfo = new TagetInfo();; |
| 281 | 286 | } | |
| 282 | } | 287 | |
| 283 | } catch (JSONException e) { | 288 | loadUI(); |
| 284 | e.printStackTrace(); | 289 | } |
| 285 | mTagetInfo = new TagetInfo();; | 290 | |
| 286 | } | 291 | |
| 287 | 292 | private void loadUI(){ | |
| 288 | loadUI(); | 293 | tvStep.setText(String.valueOf(mTagetInfo.getSteps())); |
| 289 | } | 294 | tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); |
| 290 | |||
| 291 | 295 | tvRateDone.setText(getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); | |
| 292 | private void loadUI(){ | 296 | |
| 293 | tvStep.setText(String.valueOf(mTagetInfo.getSteps())); | 297 | List<NoticeInfo> infoLists = mTagetInfo.getNoticeList(); |
| 294 | tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); | 298 | if (infoLists != null && infoLists.size() >0){ |
| 295 | tvRateDone.setText(getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); | 299 | mNoticeAdapter = new NoticeAdapter(mContext, infoLists); |
| 296 | 300 | lvNotice.setAdapter(mNoticeAdapter); | |
| 297 | List<NoticeInfo> infoLists = mTagetInfo.getNoticeList(); | 301 | lvNotice.setExpanded(true); |
| 298 | if (infoLists != null && infoLists.size() >0){ | 302 | } |
| 299 | mNoticeAdapter = new NoticeAdapter(mContext, infoLists); | 303 | |
| 300 | lvNotice.setAdapter(mNoticeAdapter); | 304 | } |
| 301 | lvNotice.setExpanded(true); | 305 | |
| 302 | } | 306 | private void addDataToObject(){ |
| 303 | 307 | ||
| 304 | } | 308 | } |
| 305 | 309 | ||
| 306 | private void addDataToObject(){ | 310 | |
| 307 | 311 | @Override | |
| 308 | } | 312 | public void onAttach(Context context) { |
| 309 | 313 | super.onAttach(context); | |
| 310 | 314 | ||
| 311 | @Override | 315 | } |
| 312 | public void onAttach(Context context) { | 316 | |
| 313 | super.onAttach(context); | 317 | |
| 314 | 318 | @Override | |
| 315 | } | 319 | public void onSaveData() { |
| 316 | 320 | ||
| 317 | 321 | } | |
| 318 | @Override | 322 | |
| 319 | public void onSaveData() { | 323 | @Override |
| 320 | 324 | public void onInvalidate(boolean isInit) { | |
| 321 | } | 325 | initData(); |
| 322 | 326 | } | |
| 323 | @Override | 327 | |
| 324 | public void onInvalidate(boolean isInit) { | 328 | @Override |
| 325 | initData(); | 329 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { |
| 326 | } | 330 | super.onViewStateRestored(savedInstanceState); |
| 327 | 331 | ||
| 328 | @Override | 332 | initData(); |
| 329 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { | 333 | } |
| 330 | super.onViewStateRestored(savedInstanceState); | 334 | |
| 331 | 335 | ||
| 332 | initData(); | 336 | @Override |
| 333 | } | 337 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 334 | 338 | super.onActivityResult(requestCode, resultCode, data); | |
| 335 | 339 | ||
| 336 | @Override | 340 | } |
| 341 | |||
| 337 | public void onActivityResult(int requestCode, int resultCode, Intent data) { | 342 | } |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.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.graphics.Color; | 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 | import android.hardware.Sensor; | 10 | import android.os.Bundle; |
| 7 | import android.hardware.SensorEvent; | 11 | import android.support.annotation.Nullable; |
| 8 | import android.hardware.SensorEventListener; | 12 | import android.util.Pair; |
| 9 | import android.hardware.SensorManager; | 13 | import android.view.LayoutInflater; |
| 10 | import android.os.Bundle; | 14 | import android.view.Menu; |
| 11 | import android.support.annotation.Nullable; | 15 | import android.view.MenuInflater; |
| 12 | import android.util.Pair; | 16 | import android.view.View; |
| 13 | import android.view.LayoutInflater; | 17 | import android.view.ViewGroup; |
| 14 | import android.view.Menu; | 18 | import android.widget.DatePicker; |
| 15 | import android.view.MenuInflater; | 19 | import android.widget.ImageView; |
| 20 | import android.widget.LinearLayout; | ||
| 16 | import android.view.View; | 21 | import android.widget.TextView; |
| 22 | import android.widget.Toast; | ||
| 17 | import android.view.ViewGroup; | 23 | |
| 18 | import android.widget.DatePicker; | 24 | import com.dinhcv.lifelogpedometer.R; |
| 19 | import android.widget.ImageView; | 25 | import com.dinhcv.lifelogpedometer.feature.Database; |
| 26 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | ||
| 20 | import android.widget.LinearLayout; | 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 | import android.widget.TextView; | 31 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 22 | import android.widget.Toast; | 32 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; |
| 33 | import com.dinhcv.lifelogpedometer.utils.Debug; | ||
| 23 | 34 | import com.dinhcv.lifelogpedometer.utils.Utils; | |
| 24 | import com.dinhcv.lifelogpedometer.R; | 35 | import com.github.mikephil.charting.components.XAxis; |
| 25 | import com.dinhcv.lifelogpedometer.feature.Database; | 36 | import com.github.mikephil.charting.components.YAxis; |
| 26 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 37 | |
| 27 | import com.dinhcv.lifelogpedometer.model.StepModel; | 38 | import com.github.mikephil.charting.charts.BarChart; |
| 28 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 39 | import com.github.mikephil.charting.data.BarData; |
| 29 | import com.dinhcv.lifelogpedometer.utils.Const; | 40 | import com.github.mikephil.charting.data.BarDataSet; |
| 30 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; | 41 | import com.github.mikephil.charting.data.BarEntry; |
| 31 | import com.dinhcv.lifelogpedometer.utils.Debug; | 42 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; |
| 32 | import com.dinhcv.lifelogpedometer.utils.Utils; | 43 | |
| 33 | import com.github.mikephil.charting.components.XAxis; | 44 | import org.eazegraph.lib.charts.PieChart; |
| 34 | import com.github.mikephil.charting.components.YAxis; | 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 | import com.github.mikephil.charting.charts.BarChart; | 50 | import java.text.NumberFormat; |
| 37 | import com.github.mikephil.charting.data.BarData; | 51 | import java.util.ArrayList; |
| 38 | import com.github.mikephil.charting.data.BarDataSet; | 52 | import java.util.Calendar; |
| 39 | import com.github.mikephil.charting.data.BarEntry; | 53 | import java.util.Date; |
| 40 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; | 54 | import java.util.List; |
| 41 | 55 | import java.util.Locale; | |
| 42 | import org.eazegraph.lib.charts.PieChart; | 56 | |
| 43 | import org.eazegraph.lib.models.PieModel; | 57 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; |
| 44 | import org.json.JSONArray; | 58 | |
| 45 | import org.json.JSONObject; | 59 | |
| 46 | 60 | public class TopFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { | |
| 47 | import java.text.NumberFormat; | 61 | |
| 48 | import java.util.ArrayList; | 62 | private TextView stepsView; |
| 63 | private TextView tvStepGoal; | ||
| 49 | import java.util.Calendar; | 64 | private TextView tvDistance; |
| 50 | import java.util.Date; | 65 | private TextView tvStepRemain; |
| 51 | import java.util.List; | 66 | private TextView tvStepRateDone; |
| 52 | import java.util.Locale; | 67 | private boolean showSteps = true; |
| 53 | 68 | private PieModel sliceGoal, sliceCurrent; | |
| 54 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; | 69 | private PieChart pg; |
| 55 | 70 | private TextView tvDate; | |
| 56 | 71 | private ImageView ivBack; | |
| 57 | public class TopFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { | 72 | private ImageView ivNext; |
| 58 | 73 | private ImageView ivPlay; | |
| 59 | private TextView stepsView; | 74 | |
| 75 | private LinearLayout llBike; | ||
| 76 | private LinearLayout llWalking; | ||
| 77 | private LinearLayout llRunning; | ||
| 78 | private Const.STEP_TYPE stepType; | ||
| 60 | private TextView tvStepGoal; | 79 | |
| 61 | private TextView tvDistance; | 80 | private Date mAnaDate; |
| 62 | private TextView tvStepRemain; | 81 | private Calendar mCalendar; |
| 63 | private TextView tvStepRateDone; | 82 | |
| 64 | private boolean showSteps = true; | 83 | private int mAnaDay; |
| 65 | private PieModel sliceGoal, sliceCurrent; | 84 | private int mAnaMonth; |
| 66 | private PieChart pg; | 85 | private int mAnaYear; |
| 67 | private TextView tvDate; | 86 | |
| 68 | private ImageView ivBack; | ||
| 69 | private ImageView ivNext; | ||
| 70 | private ImageView ivPlay; | 87 | public static int STEP_SIZE = 75; |
| 71 | 88 | private StepModel mStepModel; | |
| 89 | private TextView tvSmallStepGoal; | ||
| 72 | private LinearLayout llBike; | 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 | private LinearLayout llWalking; | 108 | |
| 74 | private LinearLayout llRunning; | 109 | @Override |
| 75 | private Const.STEP_TYPE stepType; | 110 | public void onCreate(final Bundle savedInstanceState) { |
| 76 | 111 | super.onCreate(savedInstanceState); | |
| 77 | private Date mAnaDate; | 112 | setHasOptionsMenu(true); |
| 78 | private Calendar mCalendar; | 113 | } |
| 79 | 114 | ||
| 80 | private int mAnaDay; | 115 | @Override |
| 81 | private int mAnaMonth; | 116 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 82 | private int mAnaYear; | 117 | final Bundle savedInstanceState) { |
| 83 | 118 | final View v = inflater.inflate(R.layout.fragment_top, null); | |
| 84 | public static int STEP_SIZE = 75; | 119 | mContext = getActivity(); |
| 85 | private StepModel mStepModel; | 120 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); |
| 86 | private TextView tvSmallStepGoal; | ||
| 87 | private TextView tvSmallRemain; | ||
| 88 | private Context mContext; | ||
| 89 | |||
| 90 | private SensorManager sensorManager; | ||
| 91 | private boolean activityRunning; | ||
| 92 | private int stepTotal = 0; | ||
| 93 | private int stepRemain = 0; | 121 | |
| 94 | private int stepCount = 0; | 122 | initView(v); |
| 95 | |||
| 96 | private BarChart mChart; | 123 | |
| 97 | 124 | // slice for the steps taken today | |
| 98 | private List<String> dateList; | 125 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); |
| 99 | private String[] mParties; | 126 | pg.addPieSlice(sliceCurrent); |
| 100 | private Integer[] mStep; | 127 | |
| 101 | 128 | // slice for the "missing" steps until reaching the goal | |
| 102 | @Override | 129 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); |
| 103 | public void onCreate(final Bundle savedInstanceState) { | 130 | pg.addPieSlice(sliceGoal); |
| 104 | super.onCreate(savedInstanceState); | 131 | pg.setDrawValueInPie(false); |
| 105 | setHasOptionsMenu(true); | 132 | pg.setUsePieRotation(false); |
| 106 | } | 133 | pg.startAnimation(); |
| 107 | 134 | pg.setAutoCenterInSlice(false); | |
| 108 | @Override | 135 | |
| 109 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 136 | mCalendar = Calendar.getInstance(); |
| 110 | final Bundle savedInstanceState) { | 137 | mCalendar.setTime(new Date()); |
| 111 | final View v = inflater.inflate(R.layout.fragment_top, null); | 138 | mAnaDate = mCalendar.getTime(); |
| 112 | mContext = getActivity(); | 139 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 113 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); | 140 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 114 | 141 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | |
| 115 | initView(v); | 142 | |
| 116 | 143 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | |
| 117 | // slice for the steps taken today | 144 | |
| 118 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); | 145 | handleEvent(); |
| 119 | pg.addPieSlice(sliceCurrent); | 146 | |
| 120 | 147 | return v; | |
| 121 | // slice for the "missing" steps until reaching the goal | 148 | } |
| 122 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); | 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 | pg.addPieSlice(sliceGoal); | 167 | private void stepsDistanceChanged() { |
| 124 | pg.setDrawValueInPie(false); | 168 | updatePie(); |
| 125 | pg.setUsePieRotation(false); | 169 | updateBars(); |
| 126 | pg.startAnimation(); | 170 | } |
| 127 | pg.setAutoCenterInSlice(false); | 171 | |
| 128 | 172 | ||
| 129 | mCalendar = Calendar.getInstance(); | 173 | @Override |
| 130 | mCalendar.setTime(new Date()); | 174 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { |
| 131 | mAnaDate = mCalendar.getTime(); | 175 | inflater.inflate(R.menu.main, menu); |
| 132 | mAnaYear = mCalendar.get(Calendar.YEAR); | 176 | } |
| 133 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 177 | |
| 134 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 178 | |
| 135 | 179 | private void updatePie() { | |
| 136 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 180 | // todayOffset might still be Integer.MIN_VALUE on first start |
| 137 | 181 | int steps_today = Math.max(todayOffset + since_boot, 0); | |
| 138 | handleEvent(); | 182 | sliceCurrent.setValue(steps_today); |
| 139 | 183 | if (Const.STEP_GOAL - steps_today > 0) { | |
| 140 | return v; | 184 | // goal not reached yet |
| 141 | } | 185 | if (pg.getData().size() == 1) { |
| 142 | 186 | pg.addPieSlice(sliceGoal); | |
| 143 | private void initView(View v){ | 187 | } |
| 144 | stepsView = (TextView) v.findViewById(R.id.steps); | 188 | sliceGoal.setValue(Const.STEP_GOAL - steps_today); |
| 145 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); | 189 | } else { |
| 146 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); | 190 | // goal reached |
| 147 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); | 191 | pg.clearChart(); |
| 148 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); | 192 | pg.addPieSlice(sliceCurrent); |
| 149 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); | 193 | } |
| 150 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); | 194 | pg.update(); |
| 151 | tvDate = (TextView) v.findViewById(R.id.tv_date); | 195 | |
| 152 | ivBack = (ImageView) v.findViewById(R.id.iv_back); | 196 | stepsView.setText(formatter.format(steps_today)); |
| 153 | ivNext = (ImageView) v.findViewById(R.id.iv_next); | 197 | int remain = Const.STEP_GOAL - steps_today; |
| 154 | ivPlay = (ImageView) v.findViewById(R.id.iv_play); | 198 | tvStepRemain.setText(String.valueOf(remain)); |
| 155 | 199 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(steps_today *100/ Const.STEP_GOAL))); | |
| 156 | mChart = (BarChart) v.findViewById(R.id.chart); | 200 | tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, remain)); |
| 157 | pg = (PieChart) v.findViewById(R.id.graph); | 201 | |
| 158 | } | 202 | double distance_today = steps_today * STEP_SIZE; |
| 159 | 203 | distance_today /= 100000; | |
| 160 | private void stepsDistanceChanged() { | 204 | tvDistance.setText(Utils.convert2String2Decimal(distance_today)); |
| 161 | updatePie(); | 205 | |
| 162 | updateBars(); | 206 | } |
| 163 | } | 207 | |
| 164 | 208 | /** | |
| 165 | 209 | * Updates the bar graph to show the steps/distance of the last week. Should | |
| 166 | @Override | 210 | * be called when switching from step count to distance. |
| 167 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { | 211 | */ |
| 168 | inflater.inflate(R.menu.main, menu); | 212 | private void updateBars() { |
| 169 | } | 213 | |
| 170 | 214 | dateList = new ArrayList<>(); | |
| 171 | 215 | List<Integer> stepList = new ArrayList<>(); | |
| 172 | private void updatePie() { | 216 | |
| 173 | // todayOffset might still be Integer.MIN_VALUE on first start | 217 | Database db = Database.getInstance(getActivity()); |
| 174 | int steps_today = Math.max(todayOffset + since_boot, 0); | 218 | List<Pair<Long, Integer>> last = db.getLastEntries(8, mAnaDate); |
| 175 | sliceCurrent.setValue(steps_today); | 219 | db.close(); |
| 176 | if (Const.STEP_GOAL - steps_today > 0) { | 220 | for (int i = last.size() - 1; i > 0; i--) { |
| 177 | // goal not reached yet | 221 | Pair<Long, Integer> current = last.get(i); |
| 178 | if (pg.getData().size() == 1) { | 222 | int step = current.second; |
| 179 | pg.addPieSlice(sliceGoal); | 223 | Date date = new Date(current.first); |
| 180 | } | 224 | stepList.add(step); |
| 181 | sliceGoal.setValue(Const.STEP_GOAL - steps_today); | 225 | dateList.add(String.valueOf(Utils.getDay(date))); |
| 182 | } else { | 226 | } |
| 183 | // goal reached | 227 | |
| 184 | pg.clearChart(); | 228 | mStep = stepList.toArray(new Integer[0]); |
| 185 | pg.addPieSlice(sliceCurrent); | 229 | mParties = dateList.toArray(new String[0]); |
| 186 | } | 230 | |
| 187 | pg.update(); | 231 | initGraph(); |
| 188 | 232 | } | |
| 189 | stepsView.setText(formatter.format(steps_today)); | 233 | |
| 190 | int remain = Const.STEP_GOAL - steps_today; | ||
| 191 | tvStepRemain.setText(String.valueOf(remain)); | ||
| 192 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(steps_today *100/ Const.STEP_GOAL))); | ||
| 193 | tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, remain)); | ||
| 194 | |||
| 195 | double distance_today = steps_today * STEP_SIZE; | 234 | |
| 196 | distance_today /= 100000; | 235 | private void initGraph(){ |
| 197 | tvDistance.setText(Utils.convert2String2Decimal(distance_today)); | 236 | |
| 198 | 237 | mChart.setDrawBarShadow(false); | |
| 199 | } | 238 | mChart.setDrawValueAboveBar(true); |
| 200 | 239 | ||
| 201 | /** | 240 | // if more than 60 entries are displayed in the chart, no values will be |
| 202 | * Updates the bar graph to show the steps/distance of the last week. Should | 241 | // drawn |
| 203 | * be called when switching from step count to distance. | 242 | mChart.setMaxVisibleValueCount(60); |
| 204 | */ | 243 | |
| 205 | private void updateBars() { | 244 | mChart.getDescription().setEnabled(false); |
| 206 | 245 | // scaling can now only be done on x- and y-axis separately | |
| 207 | dateList = new ArrayList<>(); | 246 | mChart.setPinchZoom(false); |
| 208 | List<Integer> stepList = new ArrayList<>(); | 247 | |
| 209 | 248 | mChart.setDrawGridBackground(false); | |
| 210 | Database db = Database.getInstance(getActivity()); | 249 | // mChart.setDrawYLabels(false); |
| 211 | List<Pair<Long, Integer>> last = db.getLastEntries(8, mAnaDate); | 250 | |
| 212 | db.close(); | 251 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(dateList); |
| 213 | for (int i = last.size() - 1; i > 0; i--) { | 252 | |
| 214 | Pair<Long, Integer> current = last.get(i); | 253 | XAxis xAxis = mChart.getXAxis(); |
| 215 | int step = current.second; | 254 | xAxis.setLabelRotationAngle(0); |
| 216 | Date date = new Date(current.first); | 255 | xAxis.setPosition(XAxis.XAxisPosition.TOP); |
| 217 | stepList.add(step); | 256 | xAxis.setDrawGridLines(true); |
| 218 | dateList.add(String.valueOf(Utils.getDay(date))); | 257 | xAxis.setLabelCount(10); |
| 219 | } | 258 | xAxis.setTextColor(Color.WHITE); |
| 220 | 259 | xAxis.setValueFormatter(xValueFormatter); | |
| 221 | mStep = stepList.toArray(new Integer[0]); | 260 | |
| 222 | mParties = dateList.toArray(new String[0]); | 261 | |
| 223 | 262 | YAxis leftAxis = mChart.getAxisLeft(); | |
| 224 | initGraph(); | 263 | leftAxis.setDrawLabels(false); |
| 225 | } | 264 | leftAxis.setDrawGridLines(false); |
| 226 | 265 | leftAxis.setAxisMinimum(0f); | |
| 227 | 266 | leftAxis.setAxisMaximum(10000f); | |
| 228 | private void initGraph(){ | 267 | leftAxis.setDrawZeroLine(false); |
| 229 | 268 | ||
| 230 | mChart.setDrawBarShadow(false); | 269 | leftAxis.setEnabled(false); |
| 231 | mChart.setDrawValueAboveBar(true); | 270 | mChart.setDrawValueAboveBar(false); |
| 232 | 271 | mChart.getAxisRight().setEnabled(false); | |
| 233 | // if more than 60 entries are displayed in the chart, no values will be | 272 | |
| 234 | // drawn | 273 | // set auto scale min max |
| 235 | mChart.setMaxVisibleValueCount(60); | 274 | mChart.setAutoScaleMinMaxEnabled(true); |
| 236 | 275 | mChart.notifyDataSetChanged(); | |
| 237 | mChart.getDescription().setEnabled(false); | 276 | |
| 238 | // scaling can now only be done on x- and y-axis separately | 277 | // Set enimate y |
| 239 | mChart.setPinchZoom(false); | 278 | mChart.animateY(2000); |
| 240 | 279 | ||
| 241 | mChart.setDrawGridBackground(false); | 280 | setData(); |
| 242 | // mChart.setDrawYLabels(false); | 281 | |
| 243 | 282 | mChart.getLegend().setEnabled(false); | |
| 244 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(dateList); | 283 | } |
| 245 | 284 | ||
| 246 | XAxis xAxis = mChart.getXAxis(); | 285 | |
| 247 | xAxis.setLabelRotationAngle(0); | 286 | private void setData() { |
| 248 | xAxis.setPosition(XAxis.XAxisPosition.TOP); | 287 | |
| 249 | xAxis.setDrawGridLines(true); | 288 | ArrayList<String> xVals = new ArrayList<>(); |
| 250 | xAxis.setLabelCount(10); | 289 | for (int i = 0; i < mStep.length; i++) { |
| 251 | xAxis.setTextColor(Color.WHITE); | 290 | xVals.add(mParties[i % mStep.length]); |
| 252 | xAxis.setValueFormatter(xValueFormatter); | 291 | } |
| 253 | 292 | ||
| 254 | 293 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); | |
| 255 | YAxis leftAxis = mChart.getAxisLeft(); | 294 | for (int i = 0; i < mStep.length; i++) { |
| 256 | leftAxis.setDrawLabels(false); | 295 | float val = (float) (mStep[i]*1); |
| 257 | leftAxis.setDrawGridLines(false); | 296 | yVals1.add(new BarEntry(i, val)); |
| 258 | leftAxis.setAxisMinimum(0f); | 297 | } |
| 259 | leftAxis.setAxisMaximum(10000f); | 298 | |
| 260 | leftAxis.setDrawZeroLine(false); | 299 | BarDataSet set1; |
| 261 | 300 | ||
| 262 | leftAxis.setEnabled(false); | 301 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { |
| 263 | mChart.setDrawValueAboveBar(false); | 302 | set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); |
| 264 | mChart.getAxisRight().setEnabled(false); | 303 | set1.setValues(yVals1); |
| 265 | 304 | mChart.getData().notifyDataChanged(); | |
| 266 | // set auto scale min max | 305 | mChart.notifyDataSetChanged(); |
| 267 | mChart.setAutoScaleMinMaxEnabled(true); | 306 | } else { |
| 268 | mChart.notifyDataSetChanged(); | 307 | ArrayList<Integer> colors = new ArrayList<>(); |
| 269 | 308 | ||
| 270 | // Set enimate y | 309 | |
| 271 | mChart.animateY(2000); | 310 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; |
| 272 | 311 | ||
| 273 | setData(); | 312 | for (int c : MATERIAL_COLORS) |
| 274 | 313 | colors.add(c); | |
| 275 | mChart.getLegend().setEnabled(false); | 314 | |
| 276 | } | 315 | set1 = new BarDataSet(yVals1, null); |
| 277 | 316 | ||
| 278 | 317 | set1.setColors(colors); | |
| 279 | private void setData() { | 318 | |
| 280 | 319 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); | |
| 281 | ArrayList<String> xVals = new ArrayList<>(); | 320 | dataSets.add(set1); |
| 282 | for (int i = 0; i < mStep.length; i++) { | 321 | |
| 283 | xVals.add(mParties[i % mStep.length]); | 322 | BarData data = new BarData(dataSets); |
| 284 | } | 323 | data.setValueTextSize(10f); |
| 285 | 324 | ||
| 286 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); | 325 | mChart.setData(data); |
| 287 | for (int i = 0; i < mStep.length; i++) { | 326 | } |
| 288 | float val = (float) (mStep[i]*1); | 327 | } |
| 289 | yVals1.add(new BarEntry(i, val)); | 328 | |
| 290 | } | 329 | |
| 291 | 330 | ||
| 292 | BarDataSet set1; | 331 | private void handleEvent(){ |
| 293 | 332 | tvDate.setOnClickListener(new View.OnClickListener() { | |
| 294 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { | 333 | @Override |
| 295 | set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); | 334 | public void onClick(View view) { |
| 296 | set1.setValues(yVals1); | 335 | handleAnaDatePicker(); |
| 297 | mChart.getData().notifyDataChanged(); | 336 | } |
| 298 | mChart.notifyDataSetChanged(); | 337 | }); |
| 299 | } else { | 338 | |
| 300 | ArrayList<Integer> colors = new ArrayList<>(); | 339 | ivBack.setOnClickListener(new View.OnClickListener() { |
| 301 | 340 | @Override | |
| 302 | 341 | public void onClick(View view) { | |
| 303 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; | 342 | mCalendar = Calendar.getInstance(); |
| 304 | 343 | mCalendar.setTime(mAnaDate); | |
| 305 | for (int c : MATERIAL_COLORS) | 344 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 306 | colors.add(c); | 345 | Date date = mCalendar.getTime(); |
| 307 | 346 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | |
| 308 | set1 = new BarDataSet(yVals1, null); | 347 | mAnaDate = date; |
| 309 | 348 | } | |
| 310 | set1.setColors(colors); | 349 | }); |
| 311 | 350 | ||
| 312 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); | 351 | ivNext.setOnClickListener(new View.OnClickListener() { |
| 313 | dataSets.add(set1); | 352 | @Override |
| 314 | 353 | public void onClick(View view) { | |
| 315 | BarData data = new BarData(dataSets); | 354 | mCalendar = Calendar.getInstance(); |
| 316 | data.setValueTextSize(10f); | 355 | mCalendar.setTime(mAnaDate); |
| 317 | 356 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | |
| 318 | mChart.setData(data); | 357 | Date date = mCalendar.getTime(); |
| 319 | } | 358 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 320 | } | 359 | mAnaDate = date; |
| 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 | private void handleEvent(){ | 393 | |
| 325 | tvDate.setOnClickListener(new View.OnClickListener() { | 394 | } |
| 326 | @Override | 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 | public void onClick(View view) { | 402 | |
| 328 | handleAnaDatePicker(); | 403 | /** |
| 329 | } | 404 | * Show date picker dialog |
| 330 | }); | 405 | */ |
| 331 | 406 | private void handleAnaDatePicker() { | |
| 332 | ivBack.setOnClickListener(new View.OnClickListener() { | 407 | |
| 333 | @Override | 408 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { |
| 334 | public void onClick(View view) { | 409 | @Override |
| 335 | mCalendar = Calendar.getInstance(); | 410 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 336 | mCalendar.setTime(mAnaDate); | 411 | |
| 337 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 412 | mCalendar = Calendar.getInstance(); |
| 338 | Date date = mCalendar.getTime(); | 413 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 339 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 414 | mAnaYear = year; |
| 340 | mAnaDate = date; | 415 | mAnaMonth = monthOfYear; |
| 341 | } | 416 | mAnaDay = dayOfMonth; |
| 342 | }); | 417 | Date date = mCalendar.getTime(); |
| 343 | 418 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | |
| 344 | ivNext.setOnClickListener(new View.OnClickListener() { | 419 | mAnaDate = date; |
| 345 | @Override | 420 | } |
| 346 | public void onClick(View view) { | 421 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 347 | mCalendar = Calendar.getInstance(); | 422 | |
| 348 | mCalendar.setTime(mAnaDate); | 423 | } |
| 349 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 424 | |
| 425 | private void getTopData(Date date, Const.STEP_TYPE stepType){ | ||
| 350 | Date date = mCalendar.getTime(); | 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 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 519 | |
| 352 | mAnaDate = date; | 520 | @Override |
| 353 | } | 521 | public void onAttach(Context context) { |
| 354 | }); | 522 | super.onAttach(context); |
| 355 | 523 | ||
| 356 | llWalking.setOnClickListener(new View.OnClickListener() { | 524 | } |
| 357 | @Override | 525 | |
| 358 | public void onClick(View view) { | 526 | private void initData() { |
| 359 | stepType = Const.STEP_TYPE.WALKING; | 527 | |
| 360 | updateUiStepType(false, true, false); | 528 | } |
| 361 | // add data | 529 | |
| 362 | getTopData(mAnaDate, stepType); | 530 | @Override |
| 363 | } | 531 | public void onSaveData() { |
| 364 | }); | 532 | |
| 365 | 533 | } | |
| 366 | llRunning.setOnClickListener(new View.OnClickListener() { | 534 | |
| 367 | @Override | 535 | @Override |
| 368 | public void onClick(View view) { | 536 | public void onInvalidate(boolean isInit) { |
| 369 | stepType = Const.STEP_TYPE.RUNNING; | 537 | initData(); |
| 370 | updateUiStepType(false, false, true); | 538 | } |
| 371 | // add | 539 | |
| 372 | getTopData(mAnaDate, stepType); | 540 | @Override |
| 373 | } | 541 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { |
| 374 | }); | 542 | super.onViewStateRestored(savedInstanceState); |
| 375 | 543 | ||
| 376 | llBike.setOnClickListener(new View.OnClickListener() { | 544 | initData(); |
| 377 | @Override | 545 | } |
| 378 | public void onClick(View view) { | 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 | } |
app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/top/StepHourInfo.java
| File was created | 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 | } | ||
| 24 |
app/src/main/java/com/dinhcv/lifelogpedometer/model/structure/top/TagetTopInfo.java
| File was created | 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 | } | ||
| 84 |
app/src/main/java/com/dinhcv/lifelogpedometer/portal/LLAPIManager.java
| 1 | package com.dinhcv.lifelogpedometer.portal; | 1 | package com.dinhcv.lifelogpedometer.portal; |
| 2 | 2 | ||
| 3 | import android.content.Context; | 3 | import android.content.Context; |
| 4 | import android.content.res.AssetManager; | 4 | import android.content.res.AssetManager; |
| 5 | import android.graphics.Bitmap; | 5 | import android.graphics.Bitmap; |
| 6 | import android.graphics.BitmapFactory; | 6 | import android.graphics.BitmapFactory; |
| 7 | import android.os.AsyncTask; | 7 | import android.os.AsyncTask; |
| 8 | import android.provider.Settings; | 8 | import android.provider.Settings; |
| 9 | import android.support.annotation.NonNull; | 9 | import android.support.annotation.NonNull; |
| 10 | import android.util.Base64; | 10 | import android.util.Base64; |
| 11 | 11 | ||
| 12 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 12 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 13 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; | 13 | import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; |
| 14 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; | 14 | import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; |
| 15 | import com.dinhcv.lifelogpedometer.utils.Const; | 15 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 16 | import com.dinhcv.lifelogpedometer.utils.Debug; | 16 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 17 | import com.dinhcv.lifelogpedometer.utils.Utils; | 17 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 18 | 18 | ||
| 19 | import org.json.JSONArray; | 19 | import org.json.JSONArray; |
| 20 | import org.json.JSONException; | 20 | import org.json.JSONException; |
| 21 | import org.json.JSONObject; | 21 | import org.json.JSONObject; |
| 22 | 22 | ||
| 23 | import java.io.ByteArrayOutputStream; | 23 | import java.io.ByteArrayOutputStream; |
| 24 | import java.io.IOException; | 24 | import java.io.IOException; |
| 25 | import java.io.InputStream; | 25 | import java.io.InputStream; |
| 26 | import java.util.ArrayList; | 26 | import java.util.ArrayList; |
| 27 | import java.util.Arrays; | 27 | import java.util.Arrays; |
| 28 | import java.util.Date; | 28 | import java.util.Date; |
| 29 | import java.util.HashMap; | 29 | import java.util.HashMap; |
| 30 | import java.util.List; | 30 | import java.util.List; |
| 31 | import java.util.UUID; | 31 | import java.util.UUID; |
| 32 | import java.util.concurrent.TimeUnit; | 32 | import java.util.concurrent.TimeUnit; |
| 33 | 33 | ||
| 34 | import okhttp3.Call; | 34 | import okhttp3.Call; |
| 35 | import okhttp3.Callback; | 35 | import okhttp3.Callback; |
| 36 | import okhttp3.HttpUrl; | 36 | import okhttp3.HttpUrl; |
| 37 | import okhttp3.MediaType; | 37 | import okhttp3.MediaType; |
| 38 | import okhttp3.OkHttpClient; | 38 | import okhttp3.OkHttpClient; |
| 39 | import okhttp3.Request; | 39 | import okhttp3.Request; |
| 40 | import okhttp3.RequestBody; | 40 | import okhttp3.RequestBody; |
| 41 | import okhttp3.Response; | 41 | import okhttp3.Response; |
| 42 | import okhttp3.ResponseBody; | 42 | import okhttp3.ResponseBody; |
| 43 | 43 | ||
| 44 | public class LLAPIManager { | 44 | public class LLAPIManager { |
| 45 | public static String URL_ROOT = "http://clover.timesfun.jp:9001/"; | 45 | public static String URL_ROOT = "http://clover.timesfun.jp:9001/"; |
| 46 | //login info | 46 | //login info |
| 47 | public static String URL_LOGIN_INFO = "login"; | 47 | public static String URL_LOGIN_INFO = "login"; |
| 48 | //register info | 48 | //register info |
| 49 | public static String URL_REGISTER_INFO = "register"; | 49 | public static String URL_REGISTER_INFO = "register"; |
| 50 | //upload image info | 50 | //upload image info |
| 51 | public static String URL_UPLOAD_IMAGE_INFO = "upload-image"; | 51 | public static String URL_UPLOAD_IMAGE_INFO = "upload-image"; |
| 52 | //Search zipcode | 52 | //Search zipcode |
| 53 | public static String URL_FORGET_PASS_INFO = "forgetPass"; | 53 | public static String URL_FORGET_PASS_INFO = "forgetPass"; |
| 54 | //history | 54 | //history |
| 55 | public static String URL_HISTORE_INFO = "api/history"; | 55 | public static String URL_HISTORE_INFO = "api/history"; |
| 56 | //history detail | 56 | //history detail |
| 57 | public static String URL_HISTORE_DETAIL_INFO = "api/history/detail"; | 57 | public static String URL_HISTORE_DETAIL_INFO = "api/history/detail"; |
| 58 | // home | 58 | // home |
| 59 | public static String URL_HOME_INFO = "api/home"; | 59 | public static String URL_HOME_INFO = "api/home"; |
| 60 | //Search zipcode | 60 | //Search zipcode |
| 61 | public static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm"; | 61 | public static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm"; |
| 62 | // Refesh Token | 62 | // Refesh Token |
| 63 | public static String URL_REFESH_TOKEN_INFO = "refreshToken"; | 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 | private static int deviationValue = 1; | 71 | private static int deviationValue = 1; |
| 67 | 72 | ||
| 68 | public static void login(final Context context, final String email, final String pass, final LLAPIManagerListener action) { | 73 | public static void login(final Context context, final String email, final String pass, final LLAPIManagerListener action) { |
| 69 | new AsyncTask<Void, Void, String>() { | 74 | new AsyncTask<Void, Void, String>() { |
| 70 | @Override | 75 | @Override |
| 71 | protected void onPreExecute() { | 76 | protected void onPreExecute() { |
| 72 | super.onPreExecute(); | 77 | super.onPreExecute(); |
| 73 | } | 78 | } |
| 74 | 79 | ||
| 75 | @Override | 80 | @Override |
| 76 | protected String doInBackground(Void... voids) { | 81 | protected String doInBackground(Void... voids) { |
| 77 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_LOGIN_INFO); | 82 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_LOGIN_INFO); |
| 78 | JSONObject jsonObject = new JSONObject(); | 83 | JSONObject jsonObject = new JSONObject(); |
| 79 | 84 | ||
| 80 | try { | 85 | try { |
| 81 | jsonObject.put("email", email); | 86 | jsonObject.put("email", email); |
| 82 | jsonObject.put("password", pass); | 87 | jsonObject.put("password", pass); |
| 83 | 88 | ||
| 84 | Debug.warn("Json data: " + jsonObject.toString()); | 89 | Debug.warn("Json data: " + jsonObject.toString()); |
| 85 | } catch (JSONException e) { | 90 | } catch (JSONException e) { |
| 86 | Debug.normal("Error ", e.getMessage()); | 91 | Debug.normal("Error ", e.getMessage()); |
| 87 | } | 92 | } |
| 88 | 93 | ||
| 89 | MediaType JSON | 94 | MediaType JSON |
| 90 | = MediaType.parse("application/json"); | 95 | = MediaType.parse("application/json"); |
| 91 | Debug.normal("JSON STRING: %s", jsonObject.toString()); | 96 | Debug.normal("JSON STRING: %s", jsonObject.toString()); |
| 92 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 97 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 93 | 98 | ||
| 94 | final Request.Builder request = new Request.Builder() | 99 | final Request.Builder request = new Request.Builder() |
| 95 | .url(baseUrl) | 100 | .url(baseUrl) |
| 96 | .header("User-Agent", Utils.getCustomUA()) | 101 | .header("User-Agent", Utils.getCustomUA()) |
| 97 | .header("Content-Type", "application/json") | 102 | .header("Content-Type", "application/json") |
| 98 | .post(requestBody); | 103 | .post(requestBody); |
| 99 | 104 | ||
| 100 | OkHttpClient httpClient = new OkHttpClient.Builder() | 105 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 101 | .readTimeout(30, TimeUnit.SECONDS) | 106 | .readTimeout(30, TimeUnit.SECONDS) |
| 102 | .writeTimeout(30, TimeUnit.SECONDS) | 107 | .writeTimeout(30, TimeUnit.SECONDS) |
| 103 | .connectTimeout(30, TimeUnit.SECONDS) | 108 | .connectTimeout(30, TimeUnit.SECONDS) |
| 104 | .build(); | 109 | .build(); |
| 105 | 110 | ||
| 106 | String jsonString = null; | 111 | String jsonString = null; |
| 107 | try { | 112 | try { |
| 108 | Response response = httpClient.newCall(request.build()).execute(); | 113 | Response response = httpClient.newCall(request.build()).execute(); |
| 109 | if (response == null) { | 114 | if (response == null) { |
| 110 | action.onError(null); | 115 | action.onError(null); |
| 111 | Debug.error("Response is null"); | 116 | Debug.error("Response is null"); |
| 112 | return null; | 117 | return null; |
| 113 | } | 118 | } |
| 114 | jsonString = getResponseData(response.body()); | 119 | jsonString = getResponseData(response.body()); |
| 115 | 120 | ||
| 116 | } catch (IOException e) { | 121 | } catch (IOException e) { |
| 117 | Debug.normal("Error %s", e.getMessage()); | 122 | Debug.normal("Error %s", e.getMessage()); |
| 118 | } | 123 | } |
| 119 | return jsonString; | 124 | return jsonString; |
| 120 | } | 125 | } |
| 121 | 126 | ||
| 122 | @Override | 127 | @Override |
| 123 | protected void onCancelled() { | 128 | protected void onCancelled() { |
| 124 | super.onCancelled(); | 129 | super.onCancelled(); |
| 125 | action.onError(null); | 130 | action.onError(null); |
| 126 | } | 131 | } |
| 127 | 132 | ||
| 128 | @Override | 133 | @Override |
| 129 | protected void onPostExecute(String jsonString) { | 134 | protected void onPostExecute(String jsonString) { |
| 130 | super.onPostExecute(jsonString); | 135 | super.onPostExecute(jsonString); |
| 131 | 136 | ||
| 132 | if ((jsonString == null) || (jsonString.isEmpty())) { | 137 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 133 | action.onError(null); | 138 | action.onError(null); |
| 134 | return; | 139 | return; |
| 135 | } | 140 | } |
| 136 | Debug.normal("String body: "+jsonString); | 141 | Debug.normal("String body: "+jsonString); |
| 137 | 142 | ||
| 138 | try { | 143 | try { |
| 139 | JSONObject jsonObject = new JSONObject(jsonString); | 144 | JSONObject jsonObject = new JSONObject(jsonString); |
| 140 | int status = jsonObject.optInt("status"); | 145 | int status = jsonObject.optInt("status"); |
| 141 | if (status == 1){ | 146 | if (status == 1){ |
| 142 | JSONObject object = jsonObject.optJSONObject("result"); | 147 | JSONObject object = jsonObject.optJSONObject("result"); |
| 143 | JSONObject objUser = object.getJSONObject("user"); | 148 | JSONObject objUser = object.getJSONObject("user"); |
| 144 | String token = object.optString("token"); | 149 | String token = object.optString("token"); |
| 145 | // save data | 150 | // save data |
| 146 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); | 151 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); |
| 147 | APIResponse.getInstance().setToken(token); | 152 | APIResponse.getInstance().setToken(token); |
| 148 | Debug.normal("Token: "+ token); | 153 | Debug.normal("Token: "+ token); |
| 149 | action.onSuccess(objUser); | 154 | action.onSuccess(objUser); |
| 150 | }else { | 155 | }else { |
| 151 | action.onError(new Error(jsonObject.optString("message"))); | 156 | action.onError(new Error(jsonObject.optString("message"))); |
| 152 | } | 157 | } |
| 153 | } catch (JSONException e) { | 158 | } catch (JSONException e) { |
| 154 | e.printStackTrace(); | 159 | e.printStackTrace(); |
| 155 | } | 160 | } |
| 156 | } | 161 | } |
| 157 | }.execute(); | 162 | }.execute(); |
| 158 | } | 163 | } |
| 159 | 164 | ||
| 160 | public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) { | 165 | public static void uploadImage(final Bitmap bitmap, final LLAPIManagerListener action) { |
| 161 | new AsyncTask<Void, Void, String>() { | 166 | new AsyncTask<Void, Void, String>() { |
| 162 | @Override | 167 | @Override |
| 163 | protected void onPreExecute() { | 168 | protected void onPreExecute() { |
| 164 | super.onPreExecute(); | 169 | super.onPreExecute(); |
| 165 | } | 170 | } |
| 166 | 171 | ||
| 167 | @Override | 172 | @Override |
| 168 | protected String doInBackground(Void... voids) { | 173 | protected String doInBackground(Void... voids) { |
| 169 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_UPLOAD_IMAGE_INFO); | 174 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_UPLOAD_IMAGE_INFO); |
| 170 | JSONObject jsonObject = new JSONObject(); | 175 | JSONObject jsonObject = new JSONObject(); |
| 171 | byte[] bitmapByte = convertBitmapToByteArray(bitmap); | 176 | byte[] bitmapByte = convertBitmapToByteArray(bitmap); |
| 172 | String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT); | 177 | String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT); |
| 173 | String imageStr = imageBase64.replace("\n",""); | 178 | String imageStr = imageBase64.replace("\n",""); |
| 174 | 179 | ||
| 175 | String token = APIResponse.getInstance().getToken(); | 180 | String token = APIResponse.getInstance().getToken(); |
| 176 | try { | 181 | try { |
| 177 | if (token != null && !token.isEmpty()) { | 182 | if (token != null && !token.isEmpty()) { |
| 178 | Debug.normal("Token is not null"); | 183 | Debug.normal("Token is not null"); |
| 179 | jsonObject.put("token", token); | 184 | jsonObject.put("token", token); |
| 180 | } | 185 | } |
| 181 | jsonObject.put("img", imageStr); | 186 | jsonObject.put("img", imageStr); |
| 182 | 187 | ||
| 183 | Debug.warn("Json data: " + jsonObject.toString()); | 188 | Debug.warn("Json data: " + jsonObject.toString()); |
| 184 | } catch (JSONException e) { | 189 | } catch (JSONException e) { |
| 185 | Debug.normal("Error ", e.getMessage()); | 190 | Debug.normal("Error ", e.getMessage()); |
| 186 | } | 191 | } |
| 187 | 192 | ||
| 188 | MediaType JSON | 193 | MediaType JSON |
| 189 | = MediaType.parse("application/json; charset=utf-8"); | 194 | = MediaType.parse("application/json; charset=utf-8"); |
| 190 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 195 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 191 | 196 | ||
| 192 | final Request.Builder request = new Request.Builder() | 197 | final Request.Builder request = new Request.Builder() |
| 193 | .url(baseUrl) | 198 | .url(baseUrl) |
| 194 | .header("User-Agent", Utils.getCustomUA()) | 199 | .header("User-Agent", Utils.getCustomUA()) |
| 195 | .header("Content-Type", "application/json") | 200 | .header("Content-Type", "application/json") |
| 196 | .post(requestBody); | 201 | .post(requestBody); |
| 197 | 202 | ||
| 198 | OkHttpClient httpClient = new OkHttpClient.Builder() | 203 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 199 | .readTimeout(30, TimeUnit.SECONDS) | 204 | .readTimeout(30, TimeUnit.SECONDS) |
| 200 | .writeTimeout(30, TimeUnit.SECONDS) | 205 | .writeTimeout(30, TimeUnit.SECONDS) |
| 201 | .connectTimeout(30, TimeUnit.SECONDS) | 206 | .connectTimeout(30, TimeUnit.SECONDS) |
| 202 | .build(); | 207 | .build(); |
| 203 | String jsonString = null; | 208 | String jsonString = null; |
| 204 | try { | 209 | try { |
| 205 | Response response = httpClient.newCall(request.build()).execute(); | 210 | Response response = httpClient.newCall(request.build()).execute(); |
| 206 | if (response == null) { | 211 | if (response == null) { |
| 207 | action.onError(null); | 212 | action.onError(null); |
| 208 | Debug.error("Response is null"); | 213 | Debug.error("Response is null"); |
| 209 | return null; | 214 | return null; |
| 210 | } | 215 | } |
| 211 | jsonString = getResponseData(response.body()); | 216 | jsonString = getResponseData(response.body()); |
| 212 | 217 | ||
| 213 | } catch (IOException e) { | 218 | } catch (IOException e) { |
| 214 | Debug.normal("Error %s", e.getMessage()); | 219 | Debug.normal("Error %s", e.getMessage()); |
| 215 | } | 220 | } |
| 216 | 221 | ||
| 217 | return jsonString; | 222 | return jsonString; |
| 218 | } | 223 | } |
| 219 | 224 | ||
| 220 | @Override | 225 | @Override |
| 221 | protected void onCancelled() { | 226 | protected void onCancelled() { |
| 222 | super.onCancelled(); | 227 | super.onCancelled(); |
| 223 | action.onError(null); | 228 | action.onError(null); |
| 224 | } | 229 | } |
| 225 | 230 | ||
| 226 | @Override | 231 | @Override |
| 227 | protected void onPostExecute(String jsonString) { | 232 | protected void onPostExecute(String jsonString) { |
| 228 | super.onPostExecute(jsonString); | 233 | super.onPostExecute(jsonString); |
| 229 | if ((jsonString == null) || (jsonString.isEmpty())) { | 234 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 230 | action.onError(null); | 235 | action.onError(null); |
| 231 | return; | 236 | return; |
| 232 | } | 237 | } |
| 233 | Debug.normal("String body: "+jsonString); | 238 | Debug.normal("String body: "+jsonString); |
| 234 | 239 | ||
| 235 | try { | 240 | try { |
| 236 | JSONObject jsonObject = new JSONObject(jsonString); | 241 | JSONObject jsonObject = new JSONObject(jsonString); |
| 237 | int status = jsonObject.optInt("status"); | 242 | int status = jsonObject.optInt("status"); |
| 238 | if (status == 1){ | 243 | if (status == 1){ |
| 239 | action.onSuccess(new JSONObject()); | 244 | action.onSuccess(new JSONObject()); |
| 240 | }else { | 245 | }else { |
| 241 | action.onError(new Error(jsonObject.optString("message"))); | 246 | action.onError(new Error(jsonObject.optString("message"))); |
| 242 | } | 247 | } |
| 243 | } catch (JSONException e) { | 248 | } catch (JSONException e) { |
| 244 | e.printStackTrace(); | 249 | e.printStackTrace(); |
| 245 | } | 250 | } |
| 246 | } | 251 | } |
| 247 | }.execute(); | 252 | }.execute(); |
| 248 | } | 253 | } |
| 249 | 254 | ||
| 250 | public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) { | 255 | public static void register(final RegisterInfo registerInfo, final LLAPIManagerListener action) { |
| 251 | new AsyncTask<Void, Void, String>() { | 256 | new AsyncTask<Void, Void, String>() { |
| 252 | @Override | 257 | @Override |
| 253 | protected void onPreExecute() { | 258 | protected void onPreExecute() { |
| 254 | super.onPreExecute(); | 259 | super.onPreExecute(); |
| 255 | } | 260 | } |
| 256 | 261 | ||
| 257 | @Override | 262 | @Override |
| 258 | protected String doInBackground(Void... voids) { | 263 | protected String doInBackground(Void... voids) { |
| 259 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REGISTER_INFO); | 264 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REGISTER_INFO); |
| 260 | JSONObject jsonObject = new JSONObject(); | 265 | JSONObject jsonObject = new JSONObject(); |
| 261 | 266 | ||
| 262 | String token = APIResponse.getInstance().getToken(); | 267 | String token = APIResponse.getInstance().getToken(); |
| 263 | try { | 268 | try { |
| 264 | jsonObject.put("username", registerInfo.getUsername()); | 269 | jsonObject.put("username", registerInfo.getUsername()); |
| 265 | jsonObject.put("password", registerInfo.getPassword()); | 270 | jsonObject.put("password", registerInfo.getPassword()); |
| 266 | jsonObject.put("full_name", registerInfo.getFullName()); | 271 | jsonObject.put("full_name", registerInfo.getFullName()); |
| 267 | jsonObject.put("nickname", registerInfo.getNickname()); | 272 | jsonObject.put("nickname", registerInfo.getNickname()); |
| 268 | jsonObject.put("birthday", Utils.dateToStringFormatDayMonthYear(registerInfo.getBirthday())); | 273 | jsonObject.put("birthday", Utils.dateToStringFormatDayMonthYear(registerInfo.getBirthday())); |
| 269 | jsonObject.put("height", ""+registerInfo.getHeight()); | 274 | jsonObject.put("height", ""+registerInfo.getHeight()); |
| 270 | jsonObject.put("weight", ""+registerInfo.getWeight()); | 275 | jsonObject.put("weight", ""+registerInfo.getWeight()); |
| 271 | jsonObject.put("fat_rate", ""+registerInfo.getFatRate()); | 276 | jsonObject.put("fat_rate", ""+registerInfo.getFatRate()); |
| 272 | jsonObject.put("gender", ""+registerInfo.getGender()); | 277 | jsonObject.put("gender", ""+registerInfo.getGender()); |
| 273 | jsonObject.put("address", registerInfo.getAddress()); | 278 | jsonObject.put("address", registerInfo.getAddress()); |
| 274 | jsonObject.put("desciption", ""); | 279 | jsonObject.put("desciption", ""); |
| 275 | jsonObject.put("receive_notification", "0"); | 280 | jsonObject.put("receive_notification", "0"); |
| 276 | //jsonObject.put("phone", "+84986940999"); | 281 | //jsonObject.put("phone", "+84986940999"); |
| 277 | jsonObject.put("share_data", "1"); | 282 | jsonObject.put("share_data", "1"); |
| 278 | jsonObject.put("profile_image", ""+registerInfo.getProfileImage()); | 283 | jsonObject.put("profile_image", ""+registerInfo.getProfileImage()); |
| 279 | jsonObject.put("delete_flag", "0"); | 284 | jsonObject.put("delete_flag", "0"); |
| 280 | jsonObject.put("email", registerInfo.getEmail()); | 285 | jsonObject.put("email", registerInfo.getEmail()); |
| 281 | jsonObject.put("physical_activity", "0"); | 286 | jsonObject.put("physical_activity", "0"); |
| 282 | jsonObject.put("remember_me", "1"); | 287 | jsonObject.put("remember_me", "1"); |
| 283 | 288 | ||
| 284 | Debug.warn("Json data: " + jsonObject.toString()); | 289 | Debug.warn("Json data: " + jsonObject.toString()); |
| 285 | } catch (JSONException e) { | 290 | } catch (JSONException e) { |
| 286 | Debug.normal("Error ", e.getMessage()); | 291 | Debug.normal("Error ", e.getMessage()); |
| 287 | } | 292 | } |
| 288 | 293 | ||
| 289 | MediaType JSON | 294 | MediaType JSON |
| 290 | = MediaType.parse("application/json; charset=utf-8"); | 295 | = MediaType.parse("application/json; charset=utf-8"); |
| 291 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 296 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 292 | 297 | ||
| 293 | final Request.Builder request = new Request.Builder() | 298 | final Request.Builder request = new Request.Builder() |
| 294 | .url(baseUrl) | 299 | .url(baseUrl) |
| 295 | .header("User-Agent", Utils.getCustomUA()) | 300 | .header("User-Agent", Utils.getCustomUA()) |
| 296 | .header("Content-Type", "application/json") | 301 | .header("Content-Type", "application/json") |
| 297 | .post(requestBody); | 302 | .post(requestBody); |
| 298 | 303 | ||
| 299 | OkHttpClient httpClient = new OkHttpClient.Builder() | 304 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 300 | .readTimeout(30, TimeUnit.SECONDS) | 305 | .readTimeout(30, TimeUnit.SECONDS) |
| 301 | .writeTimeout(30, TimeUnit.SECONDS) | 306 | .writeTimeout(30, TimeUnit.SECONDS) |
| 302 | .connectTimeout(30, TimeUnit.SECONDS) | 307 | .connectTimeout(30, TimeUnit.SECONDS) |
| 303 | .build(); | 308 | .build(); |
| 304 | 309 | ||
| 305 | String jsonString = null; | 310 | String jsonString = null; |
| 306 | try { | 311 | try { |
| 307 | Response response = httpClient.newCall(request.build()).execute(); | 312 | Response response = httpClient.newCall(request.build()).execute(); |
| 308 | if (response == null) { | 313 | if (response == null) { |
| 309 | action.onError(null); | 314 | action.onError(null); |
| 310 | Debug.error("Response is null"); | 315 | Debug.error("Response is null"); |
| 311 | return null; | 316 | return null; |
| 312 | } | 317 | } |
| 313 | jsonString = getResponseData(response.body()); | 318 | jsonString = getResponseData(response.body()); |
| 314 | 319 | ||
| 315 | } catch (IOException e) { | 320 | } catch (IOException e) { |
| 316 | Debug.normal("Error %s", e.getMessage()); | 321 | Debug.normal("Error %s", e.getMessage()); |
| 317 | } | 322 | } |
| 318 | return jsonString; | 323 | return jsonString; |
| 319 | } | 324 | } |
| 320 | 325 | ||
| 321 | @Override | 326 | @Override |
| 322 | protected void onCancelled() { | 327 | protected void onCancelled() { |
| 323 | super.onCancelled(); | 328 | super.onCancelled(); |
| 324 | action.onError(null); | 329 | action.onError(null); |
| 325 | } | 330 | } |
| 326 | 331 | ||
| 327 | @Override | 332 | @Override |
| 328 | protected void onPostExecute(String jsonString) { | 333 | protected void onPostExecute(String jsonString) { |
| 329 | super.onPostExecute(jsonString); | 334 | super.onPostExecute(jsonString); |
| 330 | if ((jsonString == null) || (jsonString.isEmpty())) { | 335 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 331 | action.onError(null); | 336 | action.onError(null); |
| 332 | return; | 337 | return; |
| 333 | } | 338 | } |
| 334 | Debug.normal("String body: "+jsonString); | 339 | Debug.normal("String body: "+jsonString); |
| 335 | 340 | ||
| 336 | try { | 341 | try { |
| 337 | JSONObject jsonObject = new JSONObject(jsonString); | 342 | JSONObject jsonObject = new JSONObject(jsonString); |
| 338 | int status = jsonObject.optInt("status"); | 343 | int status = jsonObject.optInt("status"); |
| 339 | if (status == 1){ | 344 | if (status == 1){ |
| 340 | JSONObject object = jsonObject.optJSONObject("result"); | 345 | JSONObject object = jsonObject.optJSONObject("result"); |
| 341 | JSONObject objUser = object.getJSONObject("user"); | 346 | JSONObject objUser = object.getJSONObject("user"); |
| 342 | String token = object.optString("token"); | 347 | String token = object.optString("token"); |
| 343 | APIResponse.getInstance().setToken(token); | 348 | APIResponse.getInstance().setToken(token); |
| 344 | Debug.normal("Token: "+ token); | 349 | Debug.normal("Token: "+ token); |
| 345 | action.onSuccess(objUser); | 350 | action.onSuccess(objUser); |
| 346 | }else { | 351 | }else { |
| 347 | action.onError(new Error(jsonObject.optString("message"))); | 352 | action.onError(new Error(jsonObject.optString("message"))); |
| 348 | } | 353 | } |
| 349 | } catch (JSONException e) { | 354 | } catch (JSONException e) { |
| 350 | e.printStackTrace(); | 355 | e.printStackTrace(); |
| 351 | } | 356 | } |
| 352 | 357 | ||
| 353 | } | 358 | } |
| 354 | }.execute(); | 359 | }.execute(); |
| 355 | } | 360 | } |
| 356 | 361 | ||
| 357 | private static byte[] convertBitmapToByteArray(Bitmap bitmap) { | 362 | private static byte[] convertBitmapToByteArray(Bitmap bitmap) { |
| 358 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 363 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 359 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); | 364 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); |
| 360 | byte[] byteArray = byteArrayOutputStream.toByteArray(); | 365 | byte[] byteArray = byteArrayOutputStream.toByteArray(); |
| 361 | return byteArray; | 366 | return byteArray; |
| 362 | } | 367 | } |
| 363 | 368 | ||
| 364 | public static void forgetPass(final String email, final LLAPIManagerListener action) { | 369 | public static void forgetPass(final String email, final LLAPIManagerListener action) { |
| 365 | new AsyncTask<Void, Void, String>() { | 370 | new AsyncTask<Void, Void, String>() { |
| 366 | 371 | ||
| 367 | 372 | ||
| 368 | @Override | 373 | @Override |
| 369 | protected void onPreExecute() { | 374 | protected void onPreExecute() { |
| 370 | super.onPreExecute(); | 375 | super.onPreExecute(); |
| 371 | } | 376 | } |
| 372 | 377 | ||
| 373 | @Override | 378 | @Override |
| 374 | protected String doInBackground(Void... voids) { | 379 | protected String doInBackground(Void... voids) { |
| 375 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_INFO); | 380 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_INFO); |
| 376 | JSONObject jsonObject = new JSONObject(); | 381 | JSONObject jsonObject = new JSONObject(); |
| 377 | try { | 382 | try { |
| 378 | //Personal info | 383 | //Personal info |
| 379 | jsonObject.put("email", email); | 384 | jsonObject.put("email", email); |
| 380 | 385 | ||
| 381 | Debug.warn("Json data: " + jsonObject.toString()); | 386 | Debug.warn("Json data: " + jsonObject.toString()); |
| 382 | } catch (JSONException e) { | 387 | } catch (JSONException e) { |
| 383 | Debug.normal("Error ", e.getMessage()); | 388 | Debug.normal("Error ", e.getMessage()); |
| 384 | } | 389 | } |
| 385 | 390 | ||
| 386 | MediaType JSON | 391 | MediaType JSON |
| 387 | = MediaType.parse("application/json"); | 392 | = MediaType.parse("application/json"); |
| 388 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 393 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 389 | 394 | ||
| 390 | final Request.Builder request = new Request.Builder() | 395 | final Request.Builder request = new Request.Builder() |
| 391 | .url(baseUrl) | 396 | .url(baseUrl) |
| 392 | .header("User-Agent", Utils.getCustomUA()) | 397 | .header("User-Agent", Utils.getCustomUA()) |
| 393 | .header("Content-Type", "application/json") | 398 | .header("Content-Type", "application/json") |
| 394 | .post(requestBody); | 399 | .post(requestBody); |
| 395 | 400 | ||
| 396 | OkHttpClient httpClient = new OkHttpClient.Builder() | 401 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 397 | .readTimeout(30, TimeUnit.SECONDS) | 402 | .readTimeout(30, TimeUnit.SECONDS) |
| 398 | .writeTimeout(30, TimeUnit.SECONDS) | 403 | .writeTimeout(30, TimeUnit.SECONDS) |
| 399 | .connectTimeout(30, TimeUnit.SECONDS) | 404 | .connectTimeout(30, TimeUnit.SECONDS) |
| 400 | .build(); | 405 | .build(); |
| 401 | 406 | ||
| 402 | String jsonString = null; | 407 | String jsonString = null; |
| 403 | try { | 408 | try { |
| 404 | Response response = httpClient.newCall(request.build()).execute(); | 409 | Response response = httpClient.newCall(request.build()).execute(); |
| 405 | if (response == null) { | 410 | if (response == null) { |
| 406 | action.onError(null); | 411 | action.onError(null); |
| 407 | Debug.error("Response is null"); | 412 | Debug.error("Response is null"); |
| 408 | return null; | 413 | return null; |
| 409 | } | 414 | } |
| 410 | jsonString = getResponseData(response.body()); | 415 | jsonString = getResponseData(response.body()); |
| 411 | 416 | ||
| 412 | } catch (IOException e) { | 417 | } catch (IOException e) { |
| 413 | Debug.normal("Error %s", e.getMessage()); | 418 | Debug.normal("Error %s", e.getMessage()); |
| 414 | } | 419 | } |
| 415 | return jsonString; | 420 | return jsonString; |
| 416 | } | 421 | } |
| 417 | 422 | ||
| 418 | @Override | 423 | @Override |
| 419 | protected void onCancelled() { | 424 | protected void onCancelled() { |
| 420 | super.onCancelled(); | 425 | super.onCancelled(); |
| 421 | action.onError(null); | 426 | action.onError(null); |
| 422 | } | 427 | } |
| 423 | 428 | ||
| 424 | @Override | 429 | @Override |
| 425 | protected void onPostExecute(String jsonString) { | 430 | protected void onPostExecute(String jsonString) { |
| 426 | super.onPostExecute(jsonString); | 431 | super.onPostExecute(jsonString); |
| 427 | if ((jsonString == null) || (jsonString.isEmpty())) { | 432 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 428 | action.onError(null); | 433 | action.onError(null); |
| 429 | return; | 434 | return; |
| 430 | } | 435 | } |
| 431 | Debug.normal("String body: "+jsonString); | 436 | Debug.normal("String body: "+jsonString); |
| 432 | 437 | ||
| 433 | try { | 438 | try { |
| 434 | JSONObject jsonObject = new JSONObject(jsonString); | 439 | JSONObject jsonObject = new JSONObject(jsonString); |
| 435 | int status = jsonObject.optInt("status"); | 440 | int status = jsonObject.optInt("status"); |
| 436 | if (status == 1) { | 441 | if (status == 1) { |
| 437 | action.onSuccess(jsonString); | 442 | action.onSuccess(jsonString); |
| 438 | } else { | 443 | } else { |
| 439 | action.onError(new Error(jsonObject.getString("message"))); | 444 | action.onError(new Error(jsonObject.getString("message"))); |
| 440 | } | 445 | } |
| 441 | } catch (JSONException e) { | 446 | } catch (JSONException e) { |
| 442 | action.onError(null); | 447 | action.onError(null); |
| 443 | } | 448 | } |
| 444 | } | 449 | } |
| 445 | }.execute(); | 450 | }.execute(); |
| 446 | } | 451 | } |
| 447 | 452 | ||
| 448 | public static void forgetPassConfirm(final String email, final String codeConfirm, final LLAPIManagerListener action) { | 453 | public static void forgetPassConfirm(final String email, final String codeConfirm, final LLAPIManagerListener action) { |
| 449 | new AsyncTask<Void, Void, String>() { | 454 | new AsyncTask<Void, Void, String>() { |
| 450 | 455 | ||
| 451 | 456 | ||
| 452 | @Override | 457 | @Override |
| 453 | protected void onPreExecute() { | 458 | protected void onPreExecute() { |
| 454 | super.onPreExecute(); | 459 | super.onPreExecute(); |
| 455 | } | 460 | } |
| 456 | 461 | ||
| 457 | @Override | 462 | @Override |
| 458 | protected String doInBackground(Void... voids) { | 463 | protected String doInBackground(Void... voids) { |
| 459 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_CONFIRM_INFO); | 464 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_CONFIRM_INFO); |
| 460 | JSONObject jsonObject = new JSONObject(); | 465 | JSONObject jsonObject = new JSONObject(); |
| 461 | try { | 466 | try { |
| 462 | //Personal info | 467 | //Personal info |
| 463 | jsonObject.put("email", email); | 468 | jsonObject.put("email", email); |
| 464 | jsonObject.put("code_confirm", codeConfirm); | 469 | jsonObject.put("code_confirm", codeConfirm); |
| 465 | 470 | ||
| 466 | Debug.warn("Json data: " + jsonObject.toString()); | 471 | Debug.warn("Json data: " + jsonObject.toString()); |
| 467 | } catch (JSONException e) { | 472 | } catch (JSONException e) { |
| 468 | Debug.normal("Error ", e.getMessage()); | 473 | Debug.normal("Error ", e.getMessage()); |
| 469 | } | 474 | } |
| 470 | 475 | ||
| 471 | MediaType JSON | 476 | MediaType JSON |
| 472 | = MediaType.parse("application/json"); | 477 | = MediaType.parse("application/json"); |
| 473 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 478 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 474 | 479 | ||
| 475 | final Request.Builder request = new Request.Builder() | 480 | final Request.Builder request = new Request.Builder() |
| 476 | .url(baseUrl) | 481 | .url(baseUrl) |
| 477 | .header("User-Agent", Utils.getCustomUA()) | 482 | .header("User-Agent", Utils.getCustomUA()) |
| 478 | .header("Content-Type", "application/json") | 483 | .header("Content-Type", "application/json") |
| 479 | .post(requestBody); | 484 | .post(requestBody); |
| 480 | 485 | ||
| 481 | OkHttpClient httpClient = new OkHttpClient.Builder() | 486 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 482 | .readTimeout(30, TimeUnit.SECONDS) | 487 | .readTimeout(30, TimeUnit.SECONDS) |
| 483 | .writeTimeout(30, TimeUnit.SECONDS) | 488 | .writeTimeout(30, TimeUnit.SECONDS) |
| 484 | .connectTimeout(30, TimeUnit.SECONDS) | 489 | .connectTimeout(30, TimeUnit.SECONDS) |
| 485 | .build(); | 490 | .build(); |
| 486 | String jsonString = null; | 491 | String jsonString = null; |
| 487 | try { | 492 | try { |
| 488 | Response response = httpClient.newCall(request.build()).execute(); | 493 | Response response = httpClient.newCall(request.build()).execute(); |
| 489 | if (response == null) { | 494 | if (response == null) { |
| 490 | action.onError(null); | 495 | action.onError(null); |
| 491 | Debug.error("Response is null"); | 496 | Debug.error("Response is null"); |
| 492 | return null; | 497 | return null; |
| 493 | } | 498 | } |
| 494 | jsonString = getResponseData(response.body()); | 499 | jsonString = getResponseData(response.body()); |
| 495 | 500 | ||
| 496 | } catch (IOException e) { | 501 | } catch (IOException e) { |
| 497 | Debug.normal("Error %s", e.getMessage()); | 502 | Debug.normal("Error %s", e.getMessage()); |
| 498 | } | 503 | } |
| 499 | return jsonString; | 504 | return jsonString; |
| 500 | } | 505 | } |
| 501 | 506 | ||
| 502 | @Override | 507 | @Override |
| 503 | protected void onCancelled() { | 508 | protected void onCancelled() { |
| 504 | super.onCancelled(); | 509 | super.onCancelled(); |
| 505 | action.onError(null); | 510 | action.onError(null); |
| 506 | } | 511 | } |
| 507 | 512 | ||
| 508 | @Override | 513 | @Override |
| 509 | protected void onPostExecute(String jsonString) { | 514 | protected void onPostExecute(String jsonString) { |
| 510 | super.onPostExecute(jsonString); | 515 | super.onPostExecute(jsonString); |
| 511 | if ((jsonString == null) || (jsonString.isEmpty())) { | 516 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 512 | action.onError(null); | 517 | action.onError(null); |
| 513 | return; | 518 | return; |
| 514 | } | 519 | } |
| 515 | Debug.normal("String body: "+jsonString); | 520 | Debug.normal("String body: "+jsonString); |
| 516 | 521 | ||
| 517 | try { | 522 | try { |
| 518 | JSONObject jsonObject = new JSONObject(jsonString); | 523 | JSONObject jsonObject = new JSONObject(jsonString); |
| 519 | int status = jsonObject.optInt("status"); | 524 | int status = jsonObject.optInt("status"); |
| 520 | if (status == 1) { | 525 | if (status == 1) { |
| 521 | action.onSuccess(jsonString); | 526 | action.onSuccess(jsonString); |
| 522 | } else { | 527 | } else { |
| 523 | action.onError(new Error(jsonObject.getString("message"))); | 528 | action.onError(new Error(jsonObject.getString("message"))); |
| 524 | } | 529 | } |
| 525 | } catch (JSONException e) { | 530 | } catch (JSONException e) { |
| 526 | action.onError(null); | 531 | action.onError(null); |
| 527 | } | 532 | } |
| 528 | } | 533 | } |
| 529 | }.execute(); | 534 | }.execute(); |
| 530 | } | 535 | } |
| 531 | 536 | ||
| 532 | public static void history(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { | 537 | public static void history(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { |
| 533 | new AsyncTask<Void, Void, String>() { | 538 | new AsyncTask<Void, Void, String>() { |
| 534 | 539 | ||
| 535 | 540 | ||
| 536 | @Override | 541 | @Override |
| 537 | protected void onPreExecute() { | 542 | protected void onPreExecute() { |
| 538 | super.onPreExecute(); | 543 | super.onPreExecute(); |
| 539 | } | 544 | } |
| 540 | 545 | ||
| 541 | @Override | 546 | @Override |
| 542 | protected String doInBackground(Void... voids) { | 547 | protected String doInBackground(Void... voids) { |
| 543 | 548 | ||
| 544 | String fromStr = Utils.dateToStringFormatYearMonthDay(fromDate); | 549 | String fromStr = Utils.dateToStringFormatYearMonthDay(fromDate); |
| 545 | String toStr = Utils.dateToStringFormatYearMonthDay(toDate); | 550 | String toStr = Utils.dateToStringFormatYearMonthDay(toDate); |
| 546 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 551 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 547 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_INFO + "/"+ fromStr +"/"+ toStr); | 552 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_INFO + "/"+ fromStr +"/"+ toStr); |
| 548 | Debug.normal("URL: "+baseUrl.toString()); | 553 | Debug.normal("URL: "+baseUrl.toString()); |
| 549 | final Request.Builder request = new Request.Builder() | 554 | final Request.Builder request = new Request.Builder() |
| 550 | .url(baseUrl) | 555 | .url(baseUrl) |
| 551 | .header("User-Agent", Utils.getCustomUA()) | 556 | .header("User-Agent", Utils.getCustomUA()) |
| 552 | .header("Content-Type", "application/json") | 557 | .header("Content-Type", "application/json") |
| 553 | .addHeader("token", APIResponse.getInstance().getToken()) | 558 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 554 | .get(); | 559 | .get(); |
| 555 | 560 | ||
| 556 | OkHttpClient httpClient = new OkHttpClient.Builder() | 561 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 557 | .readTimeout(30, TimeUnit.SECONDS) | 562 | .readTimeout(30, TimeUnit.SECONDS) |
| 558 | .writeTimeout(30, TimeUnit.SECONDS) | 563 | .writeTimeout(30, TimeUnit.SECONDS) |
| 559 | .connectTimeout(30, TimeUnit.SECONDS) | 564 | .connectTimeout(30, TimeUnit.SECONDS) |
| 560 | .build(); | 565 | .build(); |
| 561 | 566 | ||
| 562 | String jsonString = null; | 567 | String jsonString = null; |
| 563 | try { | 568 | try { |
| 564 | Response response = httpClient.newCall(request.build()).execute(); | 569 | Response response = httpClient.newCall(request.build()).execute(); |
| 565 | if (response == null) { | 570 | if (response == null) { |
| 566 | action.onError(null); | 571 | action.onError(null); |
| 567 | Debug.error("Response is null"); | 572 | Debug.error("Response is null"); |
| 568 | return null; | 573 | return null; |
| 569 | } | 574 | } |
| 570 | jsonString = getResponseData(response.body()); | 575 | jsonString = getResponseData(response.body()); |
| 571 | 576 | ||
| 572 | } catch (IOException e) { | 577 | } catch (IOException e) { |
| 573 | Debug.normal("Error %s", e.getMessage()); | 578 | Debug.normal("Error %s", e.getMessage()); |
| 574 | } | 579 | } |
| 575 | return jsonString; | 580 | return jsonString; |
| 576 | } | 581 | } |
| 577 | 582 | ||
| 578 | @Override | 583 | @Override |
| 579 | protected void onCancelled() { | 584 | protected void onCancelled() { |
| 580 | super.onCancelled(); | 585 | super.onCancelled(); |
| 581 | action.onError(null); | 586 | action.onError(null); |
| 582 | } | 587 | } |
| 583 | 588 | ||
| 584 | @Override | 589 | @Override |
| 585 | protected void onPostExecute(String jsonString) { | 590 | protected void onPostExecute(String jsonString) { |
| 586 | super.onPostExecute(jsonString); | 591 | super.onPostExecute(jsonString); |
| 587 | if ((jsonString == null) || (jsonString.isEmpty())) { | 592 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 588 | action.onError(null); | 593 | action.onError(null); |
| 589 | return; | 594 | return; |
| 590 | } | 595 | } |
| 591 | Debug.normal("String body: "+jsonString); | 596 | Debug.normal("String body: "+jsonString); |
| 592 | 597 | ||
| 593 | try { | 598 | try { |
| 594 | JSONObject jsonObject = new JSONObject(jsonString); | 599 | JSONObject jsonObject = new JSONObject(jsonString); |
| 595 | int status = jsonObject.optInt("status"); | 600 | int status = jsonObject.optInt("status"); |
| 596 | if (status == 1) { | 601 | if (status == 1) { |
| 597 | action.onSuccess(jsonString); | 602 | action.onSuccess(jsonString); |
| 598 | } else { | 603 | } else { |
| 599 | action.onError(new Error(jsonObject.getString("message"))); | 604 | action.onError(new Error(jsonObject.getString("message"))); |
| 600 | } | 605 | } |
| 601 | } catch (JSONException e) { | 606 | } catch (JSONException e) { |
| 602 | action.onError(null); | 607 | action.onError(null); |
| 603 | } | 608 | } |
| 604 | } | 609 | } |
| 605 | }.execute(); | 610 | }.execute(); |
| 606 | } | 611 | } |
| 607 | 612 | ||
| 608 | public static void historyDetail(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { | 613 | public static void historyDetail(final Date fromDate, final Date toDate, final LLAPIManagerListener action) { |
| 609 | new AsyncTask<Void, Void, String>() { | 614 | new AsyncTask<Void, Void, String>() { |
| 610 | 615 | ||
| 611 | 616 | ||
| 612 | @Override | 617 | @Override |
| 613 | protected void onPreExecute() { | 618 | protected void onPreExecute() { |
| 614 | super.onPreExecute(); | 619 | super.onPreExecute(); |
| 615 | } | 620 | } |
| 616 | 621 | ||
| 617 | @Override | 622 | @Override |
| 618 | protected String doInBackground(Void... voids) { | 623 | protected String doInBackground(Void... voids) { |
| 619 | 624 | ||
| 620 | String fromStr = Utils.dateToStringFormatDayMonthYear(fromDate); | 625 | String fromStr = Utils.dateToStringFormatDayMonthYear(fromDate); |
| 621 | String toStr = Utils.dateToStringFormatDayMonthYear(toDate); | 626 | String toStr = Utils.dateToStringFormatDayMonthYear(toDate); |
| 622 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 627 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 623 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_DETAIL_INFO + "/"+ fromStr +"/"+ toStr); | 628 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_DETAIL_INFO + "/"+ fromStr +"/"+ toStr); |
| 624 | Debug.normal("URL: "+baseUrl.toString()); | 629 | Debug.normal("URL: "+baseUrl.toString()); |
| 625 | final Request.Builder request = new Request.Builder() | 630 | final Request.Builder request = new Request.Builder() |
| 626 | .url(baseUrl) | 631 | .url(baseUrl) |
| 627 | .header("User-Agent", Utils.getCustomUA()) | 632 | .header("User-Agent", Utils.getCustomUA()) |
| 628 | .header("Content-Type", "application/json") | 633 | .header("Content-Type", "application/json") |
| 629 | .addHeader("token", APIResponse.getInstance().getToken()) | 634 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 630 | .get(); | 635 | .get(); |
| 631 | 636 | ||
| 632 | OkHttpClient httpClient = new OkHttpClient.Builder() | 637 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 633 | .readTimeout(30, TimeUnit.SECONDS) | 638 | .readTimeout(30, TimeUnit.SECONDS) |
| 634 | .writeTimeout(30, TimeUnit.SECONDS) | 639 | .writeTimeout(30, TimeUnit.SECONDS) |
| 635 | .connectTimeout(30, TimeUnit.SECONDS) | 640 | .connectTimeout(30, TimeUnit.SECONDS) |
| 636 | .build(); | 641 | .build(); |
| 637 | 642 | ||
| 638 | String jsonString = null; | 643 | String jsonString = null; |
| 639 | try { | 644 | try { |
| 640 | Response response = httpClient.newCall(request.build()).execute(); | 645 | Response response = httpClient.newCall(request.build()).execute(); |
| 641 | if (response == null) { | 646 | if (response == null) { |
| 642 | action.onError(null); | 647 | action.onError(null); |
| 643 | Debug.error("Response is null"); | 648 | Debug.error("Response is null"); |
| 644 | return null; | 649 | return null; |
| 645 | } | 650 | } |
| 646 | jsonString = getResponseData(response.body()); | 651 | jsonString = getResponseData(response.body()); |
| 647 | 652 | ||
| 648 | } catch (IOException e) { | 653 | } catch (IOException e) { |
| 649 | Debug.normal("Error %s", e.getMessage()); | 654 | Debug.normal("Error %s", e.getMessage()); |
| 650 | } | 655 | } |
| 651 | return jsonString; | 656 | return jsonString; |
| 652 | } | 657 | } |
| 653 | 658 | ||
| 654 | @Override | 659 | @Override |
| 655 | protected void onCancelled() { | 660 | protected void onCancelled() { |
| 656 | super.onCancelled(); | 661 | super.onCancelled(); |
| 657 | action.onError(null); | 662 | action.onError(null); |
| 658 | } | 663 | } |
| 659 | 664 | ||
| 660 | @Override | 665 | @Override |
| 661 | protected void onPostExecute(String jsonString) { | 666 | protected void onPostExecute(String jsonString) { |
| 662 | super.onPostExecute(jsonString); | 667 | super.onPostExecute(jsonString); |
| 663 | if ((jsonString == null) || (jsonString.isEmpty())) { | 668 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 664 | action.onError(null); | 669 | action.onError(null); |
| 665 | return; | 670 | return; |
| 666 | } | 671 | } |
| 667 | Debug.normal("String body: "+jsonString); | 672 | Debug.normal("String body: "+jsonString); |
| 668 | 673 | ||
| 669 | try { | 674 | try { |
| 670 | JSONObject jsonObject = new JSONObject(jsonString); | 675 | JSONObject jsonObject = new JSONObject(jsonString); |
| 671 | int status = jsonObject.optInt("status"); | 676 | int status = jsonObject.optInt("status"); |
| 672 | if (status == 1) { | 677 | if (status == 1) { |
| 673 | action.onSuccess(jsonString); | 678 | action.onSuccess(jsonString); |
| 674 | } else { | 679 | } else { |
| 675 | action.onError(new Error(jsonObject.getString("message"))); | 680 | action.onError(new Error(jsonObject.getString("message"))); |
| 676 | } | 681 | } |
| 677 | } catch (JSONException e) { | 682 | } catch (JSONException e) { |
| 678 | action.onError(null); | 683 | action.onError(null); |
| 679 | } | 684 | } |
| 680 | } | 685 | } |
| 681 | }.execute(); | 686 | }.execute(); |
| 682 | } | 687 | } |
| 683 | 688 | ||
| 684 | public static void homePage(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) { | 689 | public static void homePage(final Date date, final Const.STEP_TYPE stepType, final LLAPIManagerListener action) { |
| 685 | new AsyncTask<Void, Void, String>() { | 690 | new AsyncTask<Void, Void, String>() { |
| 686 | 691 | ||
| 687 | 692 | ||
| 688 | @Override | 693 | @Override |
| 689 | protected void onPreExecute() { | 694 | protected void onPreExecute() { |
| 690 | super.onPreExecute(); | 695 | super.onPreExecute(); |
| 691 | } | 696 | } |
| 692 | 697 | ||
| 693 | @Override | 698 | @Override |
| 694 | protected String doInBackground(Void... voids) { | 699 | protected String doInBackground(Void... voids) { |
| 695 | 700 | ||
| 696 | String dateStr = Utils.dateToStringFormatDayMonthYear(date); | 701 | String dateStr = Utils.dateToStringFormatDayMonthYear(date); |
| 697 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); | 702 | Debug.normal("Token: "+ APIResponse.getInstance().getToken()); |
| 698 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HOME_INFO + "/"+ stepType.value +"/"+ dateStr); | 703 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HOME_INFO + "/"+ stepType.value +"/"+ dateStr); |
| 699 | Debug.normal("URL: "+baseUrl.toString()); | 704 | Debug.normal("URL: "+baseUrl.toString()); |
| 700 | final Request.Builder request = new Request.Builder() | 705 | final Request.Builder request = new Request.Builder() |
| 701 | .url(baseUrl) | 706 | .url(baseUrl) |
| 702 | .header("User-Agent", Utils.getCustomUA()) | 707 | .header("User-Agent", Utils.getCustomUA()) |
| 703 | .header("Content-Type", "application/json") | 708 | .header("Content-Type", "application/json") |
| 704 | .addHeader("token", APIResponse.getInstance().getToken()) | 709 | .addHeader("token", APIResponse.getInstance().getToken()) |
| 705 | .get(); | 710 | .get(); |
| 706 | 711 | ||
| 707 | OkHttpClient httpClient = new OkHttpClient.Builder() | 712 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 708 | .readTimeout(30, TimeUnit.SECONDS) | 713 | .readTimeout(30, TimeUnit.SECONDS) |
| 709 | .writeTimeout(30, TimeUnit.SECONDS) | 714 | .writeTimeout(30, TimeUnit.SECONDS) |
| 710 | .connectTimeout(30, TimeUnit.SECONDS) | 715 | .connectTimeout(30, TimeUnit.SECONDS) |
| 711 | .build(); | 716 | .build(); |
| 712 | 717 | ||
| 713 | String jsonString = null; | 718 | String jsonString = null; |
| 714 | try { | 719 | try { |
| 715 | Response response = httpClient.newCall(request.build()).execute(); | 720 | Response response = httpClient.newCall(request.build()).execute(); |
| 716 | if (response == null) { | 721 | if (response == null) { |
| 717 | action.onError(null); | 722 | action.onError(null); |
| 718 | Debug.error("Response is null"); | 723 | Debug.error("Response is null"); |
| 719 | return null; | 724 | return null; |
| 720 | } | 725 | } |
| 721 | jsonString = getResponseData(response.body()); | 726 | jsonString = getResponseData(response.body()); |
| 722 | 727 | ||
| 723 | } catch (IOException e) { | 728 | } catch (IOException e) { |
| 724 | Debug.normal("Error %s", e.getMessage()); | 729 | Debug.normal("Error %s", e.getMessage()); |
| 725 | } | 730 | } |
| 726 | return jsonString; | 731 | return jsonString; |
| 727 | } | 732 | } |
| 728 | 733 | ||
| 729 | @Override | 734 | @Override |
| 730 | protected void onCancelled() { | 735 | protected void onCancelled() { |
| 731 | super.onCancelled(); | 736 | super.onCancelled(); |
| 732 | action.onError(null); | 737 | action.onError(null); |
| 733 | } | 738 | } |
| 734 | 739 | ||
| 735 | @Override | 740 | @Override |
| 736 | protected void onPostExecute(String jsonString) { | 741 | protected void onPostExecute(String jsonString) { |
| 737 | super.onPostExecute(jsonString); | 742 | super.onPostExecute(jsonString); |
| 738 | if ((jsonString == null) || (jsonString.isEmpty())) { | 743 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 739 | action.onError(null); | 744 | action.onError(null); |
| 740 | return; | 745 | return; |
| 741 | } | 746 | } |
| 742 | Debug.normal("String body: "+jsonString); | 747 | Debug.normal("String body: "+jsonString); |
| 743 | 748 | ||
| 744 | try { | 749 | try { |
| 745 | JSONObject jsonObject = new JSONObject(jsonString); | 750 | JSONObject jsonObject = new JSONObject(jsonString); |
| 746 | int status = jsonObject.optInt("status"); | 751 | int status = jsonObject.optInt("status"); |
| 747 | if (status == 1) { | 752 | if (status == 1) { |
| 748 | action.onSuccess(jsonString); | 753 | action.onSuccess(jsonString); |
| 749 | } else { | 754 | } else { |
| 750 | action.onError(new Error(jsonObject.getString("message"))); | 755 | action.onError(new Error(jsonObject.getString("message"))); |
| 751 | } | 756 | } |
| 752 | } catch (JSONException e) { | 757 | } catch (JSONException e) { |
| 753 | action.onError(null); | 758 | action.onError(null); |
| 754 | } | 759 | } |
| 755 | } | 760 | } |
| 756 | }.execute(); | 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 | public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) { | 929 | public static void refreshToken(final Context context, final int userId, final LLAPIManagerListener action) { |
| 760 | new AsyncTask<Void, Void, String>() { | 930 | new AsyncTask<Void, Void, String>() { |
| 761 | 931 | ||
| 762 | 932 | ||
| 763 | @Override | 933 | @Override |
| 764 | protected void onPreExecute() { | 934 | protected void onPreExecute() { |
| 765 | super.onPreExecute(); | 935 | super.onPreExecute(); |
| 766 | } | 936 | } |
| 767 | 937 | ||
| 768 | @Override | 938 | @Override |
| 769 | protected String doInBackground(Void... voids) { | 939 | protected String doInBackground(Void... voids) { |
| 770 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REFESH_TOKEN_INFO); | 940 | HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REFESH_TOKEN_INFO); |
| 771 | JSONObject jsonObject = new JSONObject(); | 941 | JSONObject jsonObject = new JSONObject(); |
| 772 | try { | 942 | try { |
| 773 | //Personal info | 943 | //Personal info |
| 774 | jsonObject.put("userId", userId); | 944 | jsonObject.put("userId", userId); |
| 775 | 945 | ||
| 776 | Debug.warn("Json data: " + jsonObject.toString()); | 946 | Debug.warn("Json data: " + jsonObject.toString()); |
| 777 | } catch (JSONException e) { | 947 | } catch (JSONException e) { |
| 778 | Debug.normal("Error ", e.getMessage()); | 948 | Debug.normal("Error ", e.getMessage()); |
| 779 | } | 949 | } |
| 780 | 950 | ||
| 781 | MediaType JSON | 951 | MediaType JSON |
| 782 | = MediaType.parse("application/json"); | 952 | = MediaType.parse("application/json"); |
| 783 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); | 953 | RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); |
| 784 | 954 | ||
| 785 | final Request.Builder request = new Request.Builder() | 955 | final Request.Builder request = new Request.Builder() |
| 786 | .url(baseUrl) | 956 | .url(baseUrl) |
| 787 | .header("User-Agent", Utils.getCustomUA()) | 957 | .header("User-Agent", Utils.getCustomUA()) |
| 788 | .header("Content-Type", "application/json") | 958 | .header("Content-Type", "application/json") |
| 789 | .post(requestBody); | 959 | .post(requestBody); |
| 790 | 960 | ||
| 791 | OkHttpClient httpClient = new OkHttpClient.Builder() | 961 | OkHttpClient httpClient = new OkHttpClient.Builder() |
| 792 | .readTimeout(30, TimeUnit.SECONDS) | 962 | .readTimeout(30, TimeUnit.SECONDS) |
| 793 | .writeTimeout(30, TimeUnit.SECONDS) | 963 | .writeTimeout(30, TimeUnit.SECONDS) |
| 794 | .connectTimeout(30, TimeUnit.SECONDS) | 964 | .connectTimeout(30, TimeUnit.SECONDS) |
| 795 | .build(); | 965 | .build(); |
| 796 | 966 | ||
| 797 | String jsonString = null; | 967 | String jsonString = null; |
| 798 | try { | 968 | try { |
| 799 | Response response = httpClient.newCall(request.build()).execute(); | 969 | Response response = httpClient.newCall(request.build()).execute(); |
| 800 | if (response == null) { | 970 | if (response == null) { |
| 801 | action.onError(null); | 971 | action.onError(null); |
| 802 | Debug.error("Response is null"); | 972 | Debug.error("Response is null"); |
| 803 | return null; | 973 | return null; |
| 804 | } | 974 | } |
| 805 | jsonString = getResponseData(response.body()); | 975 | jsonString = getResponseData(response.body()); |
| 806 | 976 | ||
| 807 | } catch (IOException e) { | 977 | } catch (IOException e) { |
| 808 | Debug.normal("Error %s", e.getMessage()); | 978 | Debug.normal("Error %s", e.getMessage()); |
| 809 | } | 979 | } |
| 810 | return jsonString; | 980 | return jsonString; |
| 811 | } | 981 | } |
| 812 | 982 | ||
| 813 | @Override | 983 | @Override |
| 814 | protected void onCancelled() { | 984 | protected void onCancelled() { |
| 815 | super.onCancelled(); | 985 | super.onCancelled(); |
| 816 | action.onError(null); | 986 | action.onError(null); |
| 817 | } | 987 | } |
| 818 | 988 | ||
| 819 | @Override | 989 | @Override |
| 820 | protected void onPostExecute(String jsonString) { | 990 | protected void onPostExecute(String jsonString) { |
| 821 | super.onPostExecute(jsonString); | 991 | super.onPostExecute(jsonString); |
| 822 | if ((jsonString == null) || (jsonString.isEmpty())) { | 992 | if ((jsonString == null) || (jsonString.isEmpty())) { |
| 823 | action.onError(null); | 993 | action.onError(null); |
| 824 | return; | 994 | return; |
| 825 | } | 995 | } |
| 826 | Debug.normal("String body: "+jsonString); | 996 | Debug.normal("String body: "+jsonString); |
| 827 | 997 | ||
| 828 | try { | 998 | try { |
| 829 | JSONObject jsonObject = new JSONObject(jsonString); | 999 | JSONObject jsonObject = new JSONObject(jsonString); |
| 830 | int status = jsonObject.optInt("status"); | 1000 | int status = jsonObject.optInt("status"); |
| 831 | if (status == 1) { | 1001 | if (status == 1) { |
| 832 | JSONArray tokenArr = jsonObject.optJSONArray("result"); | 1002 | JSONArray tokenArr = jsonObject.optJSONArray("result"); |
| 833 | String token = tokenArr.get(0).toString(); | 1003 | String token = tokenArr.get(0).toString(); |
| 834 | Debug.normal("Refresh Token: "+ token); | 1004 | Debug.normal("Refresh Token: "+ token); |
| 835 | // save data | 1005 | // save data |
| 836 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); | 1006 | Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); |
| 837 | APIResponse.getInstance().setToken(token); | 1007 | APIResponse.getInstance().setToken(token); |
| 838 | action.onSuccess(jsonString); | 1008 | action.onSuccess(jsonString); |
| 839 | } else { | 1009 | } else { |
| 840 | action.onError(new Error(jsonObject.getString("message"))); | 1010 | action.onError(new Error(jsonObject.getString("message"))); |
| 841 | } | 1011 | } |
| 842 | } catch (JSONException e) { | 1012 | } catch (JSONException e) { |
| 843 | action.onError(null); | 1013 | action.onError(null); |
| 844 | } | 1014 | } |
| 845 | } | 1015 | } |
| 846 | }.execute(); | 1016 | }.execute(); |
| 847 | } | 1017 | } |
| 848 | 1018 | ||
| 849 | public static Bitmap getBitmapFromAsset(Context context, String filePath) { | 1019 | public static Bitmap getBitmapFromAsset(Context context, String filePath) { |
| 850 | AssetManager assetManager = context.getAssets(); | 1020 | AssetManager assetManager = context.getAssets(); |
| 851 | InputStream istr; | 1021 | InputStream istr; |
| 852 | Bitmap bitmap = null; | 1022 | Bitmap bitmap = null; |
| 853 | try { | 1023 | try { |
| 854 | istr = assetManager.open(filePath); | 1024 | istr = assetManager.open(filePath); |
| 855 | bitmap = BitmapFactory.decodeStream(istr); | 1025 | bitmap = BitmapFactory.decodeStream(istr); |
| 856 | } catch (IOException e) { | 1026 | } catch (IOException e) { |
| 857 | Debug.normal("error: %s", e.getMessage()); | 1027 | Debug.normal("error: %s", e.getMessage()); |
| 858 | } | 1028 | } |
| 859 | return bitmap; | 1029 | return bitmap; |
| 860 | } | 1030 | } |
| 861 | 1031 | ||
| 862 | public static String getResponseData(ResponseBody response) { | 1032 | public static String getResponseData(ResponseBody response) { |
| 863 | 1033 | ||
| 864 | String unzipString = ""; | 1034 | String unzipString = ""; |
| 865 | try { | 1035 | try { |
| 866 | unzipString = response.string(); | 1036 | unzipString = response.string(); |
| 867 | Debug.normal("RESPONSE: "+unzipString); | 1037 | Debug.normal("RESPONSE: "+unzipString); |
| 868 | } catch (IOException e) { | 1038 | } catch (IOException e) { |
| 869 | e.printStackTrace(); | 1039 | e.printStackTrace(); |
| 870 | } | 1040 | } |
| 871 | return unzipString; | 1041 | return unzipString; |
| 872 | } | 1042 | } |
| 873 | 1043 | ||
| 874 | } | 1044 | } |
| 875 | 1045 |
app/src/main/java/com/dinhcv/lifelogpedometer/utils/Utils.java
| 1 | package com.dinhcv.lifelogpedometer.utils; | 1 | package com.dinhcv.lifelogpedometer.utils; |
| 2 | 2 | ||
| 3 | import android.content.Context; | 3 | import android.content.Context; |
| 4 | import android.graphics.drawable.Drawable; | 4 | import android.graphics.drawable.Drawable; |
| 5 | import android.os.Build; | 5 | import android.os.Build; |
| 6 | 6 | ||
| 7 | import com.dinhcv.lifelogpedometer.LifeLogApplication; | 7 | import com.dinhcv.lifelogpedometer.LifeLogApplication; |
| 8 | 8 | ||
| 9 | import java.text.DateFormat; | 9 | import java.text.DateFormat; |
| 10 | import java.text.DecimalFormat; | 10 | import java.text.DecimalFormat; |
| 11 | import java.text.ParseException; | 11 | import java.text.ParseException; |
| 12 | import java.text.SimpleDateFormat; | 12 | import java.text.SimpleDateFormat; |
| 13 | import java.util.Calendar; | 13 | import java.util.Calendar; |
| 14 | import java.util.Date; | 14 | import java.util.Date; |
| 15 | import java.util.Locale; | 15 | import java.util.Locale; |
| 16 | import java.util.TimeZone; | 16 | import java.util.TimeZone; |
| 17 | import java.util.concurrent.TimeUnit; | 17 | import java.util.concurrent.TimeUnit; |
| 18 | import java.util.regex.Matcher; | 18 | import java.util.regex.Matcher; |
| 19 | import java.util.regex.Pattern; | 19 | import java.util.regex.Pattern; |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | public class Utils { | 22 | public class Utils { |
| 23 | private Utils() { | 23 | private Utils() { |
| 24 | 24 | ||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * Get color wrapper | 28 | * Get color wrapper |
| 29 | * | 29 | * |
| 30 | * @param context | 30 | * @param context |
| 31 | * @param id | 31 | * @param id |
| 32 | * @return: | 32 | * @return: |
| 33 | */ | 33 | */ |
| 34 | public static int getColorWrapper(Context context, int id) { | 34 | public static int getColorWrapper(Context context, int id) { |
| 35 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | 35 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 36 | return context.getColor(id); | 36 | return context.getColor(id); |
| 37 | } else { | 37 | } else { |
| 38 | //noinspection deprecation | 38 | //noinspection deprecation |
| 39 | return context.getResources().getColor(id); | 39 | return context.getResources().getColor(id); |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | /** | 43 | /** |
| 44 | * Get drawable wrapper | 44 | * Get drawable wrapper |
| 45 | * | 45 | * |
| 46 | * @param context | 46 | * @param context |
| 47 | * @param id | 47 | * @param id |
| 48 | * @return: | 48 | * @return: |
| 49 | */ | 49 | */ |
| 50 | public static Drawable getDrawableWrapper(Context context, int id) { | 50 | public static Drawable getDrawableWrapper(Context context, int id) { |
| 51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | 51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 52 | return context.getDrawable(id); | 52 | return context.getDrawable(id); |
| 53 | } else { | 53 | } else { |
| 54 | //noinspection deprecation | 54 | //noinspection deprecation |
| 55 | return context.getResources().getDrawable(id); | 55 | return context.getResources().getDrawable(id); |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | /** | 59 | /** |
| 60 | * Convert value to string | 60 | * Convert value to string |
| 61 | * | 61 | * |
| 62 | * @param value | 62 | * @param value |
| 63 | * @return | 63 | * @return |
| 64 | */ | 64 | */ |
| 65 | public static String convert2String2Decimal(double value) { | 65 | public static String convert2String2Decimal(double value) { |
| 66 | String valueStr = null; | 66 | String valueStr = null; |
| 67 | DecimalFormat dFormat = new DecimalFormat("####,###,##0.00"); | 67 | DecimalFormat dFormat = new DecimalFormat("####,###,##0.00"); |
| 68 | valueStr = dFormat.format(value); | 68 | valueStr = dFormat.format(value); |
| 69 | return valueStr; | 69 | return valueStr; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| 73 | * Convert value to string | 73 | * Convert value to string |
| 74 | * | 74 | * |
| 75 | * @param value | 75 | * @param value |
| 76 | * @return | 76 | * @return |
| 77 | */ | 77 | */ |
| 78 | public static String convert2StringAroundNum(double value) { | 78 | public static String convert2StringAroundNum(double value) { |
| 79 | String valueStr = null; | 79 | String valueStr = null; |
| 80 | DecimalFormat dFormat = new DecimalFormat("####,###,###"); | 80 | DecimalFormat dFormat = new DecimalFormat("####,###,###"); |
| 81 | valueStr = dFormat.format(value); | 81 | valueStr = dFormat.format(value); |
| 82 | return valueStr; | 82 | return valueStr; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | public static String convertDateToStringDialogSelect(Date input) { | 85 | public static String convertDateToStringDialogSelect(Date input) { |
| 86 | //昭和yyyy年MM月dd日 | 86 | //昭和yyyy年MM月dd日 |
| 87 | SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日", Locale.JAPAN); | 87 | SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日", Locale.JAPAN); |
| 88 | format.setTimeZone(TimeZone.getTimeZone("GMT+07:00")); | 88 | format.setTimeZone(TimeZone.getTimeZone("GMT+07:00")); |
| 89 | return format.format(input); | 89 | return format.format(input); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | /** | 92 | /** |
| 93 | * * Convert date to string with format date month year | 93 | * * Convert date to string with format date month year |
| 94 | * | 94 | * |
| 95 | * @param date date | 95 | * @param date date |
| 96 | * @return date string | 96 | * @return date string |
| 97 | */ | 97 | */ |
| 98 | public static String dateToStringFormatDayMonthYearJp(Date date) { | 98 | public static String dateToStringFormatDayMonthYearJp(Date date) { |
| 99 | String dateStr = null; | 99 | String dateStr = null; |
| 100 | if (date != null) { | 100 | if (date != null) { |
| 101 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日", Locale.JAPAN); | 101 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日", Locale.JAPAN); |
| 102 | dateStr = sdf.format(date); | 102 | dateStr = sdf.format(date); |
| 103 | } | 103 | } |
| 104 | return dateStr; | 104 | return dateStr; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /** | 107 | /** |
| 108 | * * Convert date to string with format date month year | 108 | * * Convert date to string with format date month year |
| 109 | * | 109 | * |
| 110 | * @param date date | 110 | * @param date date |
| 111 | * @return date string | 111 | * @return date string |
| 112 | */ | 112 | */ |
| 113 | public static String dateToStringFormatDayMonthYear(Date date) { | 113 | public static String dateToStringFormatDayMonthYear(Date date) { |
| 114 | String dateStr = null; | 114 | String dateStr = null; |
| 115 | if (date != null) { | 115 | if (date != null) { |
| 116 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.JAPAN); | 116 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.JAPAN); |
| 117 | dateStr = sdf.format(date); | 117 | dateStr = sdf.format(date); |
| 118 | } | 118 | } |
| 119 | return dateStr; | 119 | return dateStr; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | /** | 122 | /** |
| 123 | * * Convert date to string with format date month year | 123 | * * Convert date to string with format date month year |
| 124 | * @param date date | 124 | * @param date date |
| 125 | * @return date string | 125 | * @return date string |
| 126 | */ | 126 | */ |
| 127 | public static String dateToStringFormatYearMonthDay(Date date) { | 127 | public static String dateToStringFormatYearMonthDay(Date date) { |
| 128 | String dateStr = null; | 128 | String dateStr = null; |
| 129 | if ( date != null ) { | 129 | if ( date != null ) { |
| 130 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.JAPAN); | 130 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.JAPAN); |
| 131 | dateStr = sdf.format(date); | 131 | dateStr = sdf.format(date); |
| 132 | } | 132 | } |
| 133 | Debug.normal("DATE format: "+dateStr); | 133 | Debug.normal("DATE format: "+dateStr); |
| 134 | return dateStr; | 134 | return dateStr; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) { | 137 | public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) { |
| 138 | long diffInMillies = date2.getTime() - date1.getTime(); | 138 | long diffInMillies = date2.getTime() - date1.getTime(); |
| 139 | return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS); | 139 | return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS); |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | public static boolean checkMailFormat(String text) { | 142 | public static boolean checkMailFormat(String text) { |
| 143 | String regex = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"; | 143 | String regex = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"; |
| 144 | Pattern pattern = Pattern.compile(regex); | 144 | Pattern pattern = Pattern.compile(regex); |
| 145 | Matcher matcher = pattern.matcher(text); | 145 | Matcher matcher = pattern.matcher(text); |
| 146 | if (matcher.matches()) { | 146 | if (matcher.matches()) { |
| 147 | Debug.normal("String is Full width character"); | 147 | Debug.normal("String is Full width character"); |
| 148 | return true; | 148 | return true; |
| 149 | } else { | 149 | } else { |
| 150 | Debug.normal("String is not Full width character"); | 150 | Debug.normal("String is not Full width character"); |
| 151 | return false; | 151 | return false; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | public static long getToday() { | 156 | public static long getToday() { |
| 157 | Calendar c = Calendar.getInstance(); | 157 | Calendar c = Calendar.getInstance(); |
| 158 | c.setTimeInMillis(System.currentTimeMillis()); | 158 | c.setTimeInMillis(System.currentTimeMillis()); |
| 159 | c.set(Calendar.HOUR_OF_DAY, 0); | 159 | c.set(Calendar.HOUR_OF_DAY, 0); |
| 160 | c.set(Calendar.MINUTE, 0); | 160 | c.set(Calendar.MINUTE, 0); |
| 161 | c.set(Calendar.SECOND, 0); | 161 | c.set(Calendar.SECOND, 0); |
| 162 | c.set(Calendar.MILLISECOND, 0); | 162 | c.set(Calendar.MILLISECOND, 0); |
| 163 | return c.getTimeInMillis(); | 163 | return c.getTimeInMillis(); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | /** | 166 | /** |
| 167 | * @return milliseconds since 1.1.1970 for tomorrow 0:00:01 local timezone | 167 | * @return milliseconds since 1.1.1970 for tomorrow 0:00:01 local timezone |
| 168 | */ | 168 | */ |
| 169 | public static long getTomorrow() { | 169 | public static long getTomorrow() { |
| 170 | Calendar c = Calendar.getInstance(); | 170 | Calendar c = Calendar.getInstance(); |
| 171 | c.setTimeInMillis(System.currentTimeMillis()); | 171 | c.setTimeInMillis(System.currentTimeMillis()); |
| 172 | c.set(Calendar.HOUR_OF_DAY, 0); | 172 | c.set(Calendar.HOUR_OF_DAY, 0); |
| 173 | c.set(Calendar.MINUTE, 0); | 173 | c.set(Calendar.MINUTE, 0); |
| 174 | c.set(Calendar.SECOND, 1); | 174 | c.set(Calendar.SECOND, 1); |
| 175 | c.set(Calendar.MILLISECOND, 0); | 175 | c.set(Calendar.MILLISECOND, 0); |
| 176 | c.add(Calendar.DATE, 1); | 176 | c.add(Calendar.DATE, 1); |
| 177 | return c.getTimeInMillis(); | 177 | return c.getTimeInMillis(); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | public static long getStandarDate(Date date) { | 180 | public static long getStandarDate(Date date) { |
| 181 | Calendar c = Calendar.getInstance(); | 181 | Calendar c = Calendar.getInstance(); |
| 182 | c.setTime(date); | 182 | c.setTime(date); |
| 183 | c.set(Calendar.HOUR_OF_DAY, 0); | 183 | c.set(Calendar.HOUR_OF_DAY, 0); |
| 184 | c.set(Calendar.MINUTE, 0); | 184 | c.set(Calendar.MINUTE, 0); |
| 185 | c.set(Calendar.SECOND, 0); | 185 | c.set(Calendar.SECOND, 0); |
| 186 | c.set(Calendar.MILLISECOND, 0); | 186 | c.set(Calendar.MILLISECOND, 0); |
| 187 | return c.getTimeInMillis(); | 187 | return c.getTimeInMillis(); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | 190 | ||
| 191 | public static Date getFromDate(Date date, Const.DATA_TYPE dataType ) { | 191 | public static Date getFromDate(Date date, Const.DATA_TYPE dataType ) { |
| 192 | Calendar c = Calendar.getInstance(); | 192 | Calendar c = Calendar.getInstance(); |
| 193 | c.setTime(date); | 193 | c.setTime(date); |
| 194 | if (dataType == Const.DATA_TYPE.ONE_DAY){ | 194 | if (dataType == Const.DATA_TYPE.ONE_DAY){ |
| 195 | c.add(Calendar.DAY_OF_YEAR, -1); | 195 | c.add(Calendar.DAY_OF_YEAR, -1); |
| 196 | }else if (dataType == Const.DATA_TYPE.ONE_WEEK){ | 196 | }else if (dataType == Const.DATA_TYPE.ONE_WEEK){ |
| 197 | c.add(Calendar.DAY_OF_YEAR, -7); | 197 | c.add(Calendar.DAY_OF_YEAR, -7); |
| 198 | }else if (dataType == Const.DATA_TYPE.ONE_MONTH){ | 198 | }else if (dataType == Const.DATA_TYPE.ONE_MONTH){ |
| 199 | c.add(Calendar.DAY_OF_YEAR, -30); | 199 | c.add(Calendar.DAY_OF_YEAR, -30); |
| 200 | }else if (dataType == Const.DATA_TYPE.THREE_MONTH){ | 200 | }else if (dataType == Const.DATA_TYPE.THREE_MONTH){ |
| 201 | c.add(Calendar.DAY_OF_YEAR, - 30 * 3); | 201 | c.add(Calendar.DAY_OF_YEAR, - 30 * 3); |
| 202 | }else if (dataType == Const.DATA_TYPE.SIX_MONTH){ | 202 | }else if (dataType == Const.DATA_TYPE.SIX_MONTH){ |
| 203 | c.add(Calendar.DAY_OF_YEAR, - 30 * 6); | 203 | c.add(Calendar.DAY_OF_YEAR, - 30 * 6); |
| 204 | } | 204 | } |
| 205 | return c.getTime(); | 205 | return c.getTime(); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | public static int getMonth(Date date) { | 208 | public static int getMonth(Date date) { |
| 209 | 209 | ||
| 210 | int month = 0; | 210 | int month = 0; |
| 211 | if (date != null) { | 211 | if (date != null) { |
| 212 | SimpleDateFormat sdf = new SimpleDateFormat("MM", Locale.JAPAN); | 212 | SimpleDateFormat sdf = new SimpleDateFormat("MM", Locale.JAPAN); |
| 213 | String dateStr = sdf.format(date); | 213 | String dateStr = sdf.format(date); |
| 214 | if (dateStr != null) month = Integer.valueOf(dateStr); | 214 | if (dateStr != null) month = Integer.valueOf(dateStr); |
| 215 | } | 215 | } |
| 216 | Debug.normal("Month: " + month); | 216 | Debug.normal("Month: " + month); |
| 217 | return month; | 217 | return month; |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | public static int getDay(Date date) { | 220 | public static int getDay(Date date) { |
| 221 | int month = 0; | 221 | int month = 0; |
| 222 | if (date != null) { | 222 | if (date != null) { |
| 223 | SimpleDateFormat sdf = new SimpleDateFormat("dd", Locale.JAPAN); | 223 | SimpleDateFormat sdf = new SimpleDateFormat("dd", Locale.JAPAN); |
| 224 | String dateStr = sdf.format(date); | 224 | String dateStr = sdf.format(date); |
| 225 | if (dateStr != null) month = Integer.valueOf(dateStr); | 225 | if (dateStr != null) month = Integer.valueOf(dateStr); |
| 226 | } | 226 | } |
| 227 | Debug.normal("Month: " + month); | 227 | Debug.normal("Month: " + month); |
| 228 | return month; | 228 | return month; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | public static String userAgent = null; | 231 | public static String userAgent = null; |
| 232 | 232 | ||
| 233 | public static void setCustomUA(String ua) { | 233 | public static void setCustomUA(String ua) { |
| 234 | userAgent = ua; | 234 | userAgent = ua; |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | public static String getCustomUA() { | 237 | public static String getCustomUA() { |
| 238 | Context context = LifeLogApplication.context; | 238 | Context context = LifeLogApplication.context; |
| 239 | String packageName = context.getPackageName(); //{2} | 239 | String packageName = context.getPackageName(); //{2} |
| 240 | String appVersion = "Android" + "." + "1.0.1"; //{3} | 240 | String appVersion = "Android" + "." + "1.0.1"; //{3} |
| 241 | String osVersion = Build.VERSION.RELEASE; //{4} | 241 | String osVersion = Build.VERSION.RELEASE; //{4} |
| 242 | String modelName = Build.MODEL; //{6} | 242 | String modelName = Build.MODEL; //{6} |
| 243 | String uaString = packageName + "/" + appVersion + "(Android " + osVersion + ";" + modelName + ")" + " " + userAgent; | 243 | String uaString = packageName + "/" + appVersion + "(Android " + osVersion + ";" + modelName + ")" + " " + userAgent; |
| 244 | return uaString; | 244 | return uaString; |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | public static Date convertString2Date(String time) { | 247 | public static Date convertString2Date(String time) { |
| 248 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 248 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 249 | Date date = null; | 249 | Date date = null; |
| 250 | try { | 250 | try { |
| 251 | date = df.parse(time); | 251 | date = df.parse(time); |
| 252 | } catch (ParseException e) { | 252 | } catch (ParseException e) { |
| 253 | e.printStackTrace(); | 253 | e.printStackTrace(); |
| 254 | } | 254 | } |
| 255 | return date; | 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 | public static String convertDate2DayString(Date date) { | 263 | public static String convertDate2DayString(Date date) { |
| 259 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); | 264 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| 260 | return df.format(date); | 265 | return df.format(date); |
| 261 | } | 266 | } |
| 262 | 267 | ||
| 263 | public static String convertDate2TimeString(Date date) { | 268 | public static String convertDate2TimeString(Date date) { |
| 264 | DateFormat df = new SimpleDateFormat("HH:mm"); | 269 | DateFormat df = new SimpleDateFormat("HH:mm"); |
| 265 | return df.format(date); | 270 | return df.format(date); |
| 266 | } | 271 | } |
| 267 | 272 | ||
| 268 | 273 | ||
| 269 | public static String convertTimeStringFromString(int time){ | 274 | public static String convertTimeStringFromString(int time){ |
| 270 | String timeCv = null; | 275 | String timeCv = null; |
| 271 | String timeStr = String.valueOf(time); | 276 | String timeStr = String.valueOf(time); |
| 272 | int length = timeStr.length(); | 277 | int length = timeStr.length(); |
| 273 | switch (length){ | 278 | switch (length){ |
| 274 | case 0: | 279 | case 0: |
| 275 | timeCv = "00:00:00"; | 280 | timeCv = "00:00:00"; |
| 276 | break; | 281 | break; |
| 277 | case 1: | 282 | case 1: |
| 278 | timeCv = "00:00:0"+time; | 283 | timeCv = "00:00:0"+time; |
| 279 | break; | 284 | break; |
| 280 | case 2: | 285 | case 2: |
| 281 | timeCv = "00:00:"+time; | 286 | timeCv = "00:00:"+time; |
| 282 | break; | 287 | break; |
| 283 | case 3: | 288 | case 3: |
| 284 | timeCv = "00:0"+timeStr.substring(0, 1)+":"+ timeStr.substring(1, timeStr.length()); | 289 | timeCv = "00:0"+timeStr.substring(0, 1)+":"+ timeStr.substring(1, timeStr.length()); |
| 285 | break; | 290 | break; |
| 286 | case 4: | 291 | case 4: |
| 287 | timeCv = "00:"+timeStr.substring(0, 2)+":"+ timeStr.substring(2, timeStr.length()); | 292 | timeCv = "00:"+timeStr.substring(0, 2)+":"+ timeStr.substring(2, timeStr.length()); |
| 288 | break; | 293 | break; |
| 289 | case 5: | 294 | case 5: |
| 290 | timeCv = timeStr.substring(0, 1)+ ":"+timeStr.substring(1, 3)+":"+ timeStr.substring(3, timeStr.length()); | 295 | timeCv = timeStr.substring(0, 1)+ ":"+timeStr.substring(1, 3)+":"+ timeStr.substring(3, timeStr.length()); |
| 291 | break; | 296 | break; |
| 292 | case 6: | 297 | case 6: |
| 293 | timeCv = timeStr.substring(0, 2)+":"+timeStr.substring(2, 4)+":"+ timeStr.substring(4, timeStr.length()); | 298 | timeCv = timeStr.substring(0, 2)+":"+timeStr.substring(2, 4)+":"+ timeStr.substring(4, timeStr.length()); |
| 294 | break; | 299 | break; |
| 295 | default: | 300 | default: |
| 296 | timeCv = timeStr; | 301 | timeCv = timeStr; |
| 297 | break; | 302 | break; |
| 298 | } | 303 | } |
| 299 | 304 | ||
| 300 | return timeCv; | 305 | return timeCv; |
| 301 | } | 306 | } |
| 302 | 307 | ||
| 303 | public static String convertSecond2HourMinSecString(int total){ | 308 | public static String convertSecond2HourMinSecString(int total){ |
| 304 | int hours = total / 3600; | 309 | int hours = total / 3600; |
| 305 | int minutes = (total % 3600) / 60; | 310 | int minutes = (total % 3600) / 60; |
| 306 | int seconds = total % 60; | 311 | int seconds = total % 60; |
| 307 | 312 | ||
| 308 | return String.format("%02d:%02d:%02d", hours, minutes, seconds); | 313 | return String.format("%02d:%02d:%02d", hours, minutes, seconds); |
| 309 | } | 314 | } |
| 310 | 315 | ||
| 311 | public static String formatInt2LengthDefault(int value){ | 316 | public static String formatInt2LengthDefault(int value){ |
| 312 | DecimalFormat dFormat = new DecimalFormat("00"); | 317 | DecimalFormat dFormat = new DecimalFormat("00"); |
| 313 | String data = dFormat.format(value); | 318 | String data = dFormat.format(value); |
| 314 | return data; | 319 | return data; |
| 315 | } | 320 | } |
| 316 | 321 | ||
| 317 | public static String getWeekdayFromDate(Date date) { | 322 | public static String getWeekdayFromDate(Date date) { |
| 318 | SimpleDateFormat outFormat = new SimpleDateFormat("EEEE", Locale.JAPAN); | 323 | SimpleDateFormat outFormat = new SimpleDateFormat("EEEE", Locale.JAPAN); |
| 319 | String goal = outFormat.format(date); | 324 | String goal = outFormat.format(date); |
| 320 | Debug.normal("WEEKDAY: " + goal); | 325 | Debug.normal("WEEKDAY: " + goal); |
| 321 | return goal; | 326 | return goal; |
| 322 | } | 327 | } |
| 323 | public static int parseString2Int(String input, int defaul) { | 328 | public static int parseString2Int(String input, int defaul) { |
| 324 | try { | 329 | try { |
| 325 | return Integer.parseInt(input); | 330 | return Integer.parseInt(input); |
| 326 | } catch (NumberFormatException e) { | 331 | } catch (NumberFormatException e) { |
| 327 | return defaul; | 332 | return defaul; |
| 328 | } | 333 | } |
| 329 | 334 | ||
| 330 | } | 335 | } |
| 331 | } | 336 | } |
| 332 | /****************************************************************************** | 337 | /****************************************************************************** |
| 333 | * End of file | 338 | * End of file |
| 334 | *****************************************************************************/ | 339 | *****************************************************************************/ |
app/src/main/res/layout/fragment_top.xml
| 1 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | 1 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | xmlns:appNs="http://schemas.android.com/apk/res-auto" | 2 | xmlns:appNs="http://schemas.android.com/apk/res-auto" |
| 3 | android:layout_width="match_parent" | 3 | android:layout_width="match_parent" |
| 4 | android:layout_height="match_parent" | 4 | android:layout_height="match_parent" |
| 5 | android:background="@color/background_main"> | 5 | android:background="@color/background_main"> |
| 6 | 6 | ||
| 7 | <ScrollView | 7 | <ScrollView |
| 8 | android:layout_width="match_parent" | 8 | android:layout_width="match_parent" |
| 9 | android:layout_height="match_parent" | 9 | android:layout_height="match_parent" |
| 10 | android:layout_alignParentTop="true" | 10 | android:layout_alignParentTop="true" |
| 11 | android:layout_alignParentStart="true" | 11 | android:layout_alignParentStart="true" |
| 12 | android:layout_above="@+id/ll_stepType"> | 12 | android:layout_above="@+id/ll_stepType"> |
| 13 | 13 | ||
| 14 | <LinearLayout | 14 | <LinearLayout |
| 15 | android:layout_width="match_parent" | 15 | android:layout_width="match_parent" |
| 16 | android:layout_height="wrap_content" | 16 | android:layout_height="wrap_content" |
| 17 | android:orientation="vertical" | 17 | android:orientation="vertical" |
| 18 | android:padding="10dp"> | 18 | android:padding="10dp"> |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | <LinearLayout | 21 | <LinearLayout |
| 22 | android:layout_width="match_parent" | 22 | android:layout_width="match_parent" |
| 23 | android:layout_height="wrap_content" | 23 | android:layout_height="wrap_content" |
| 24 | android:orientation="horizontal" | 24 | android:orientation="horizontal" |
| 25 | android:paddingTop="10dp"> | 25 | android:paddingTop="10dp"> |
| 26 | 26 | ||
| 27 | <ImageView | 27 | <ImageView |
| 28 | android:id="@+id/iv_back" | 28 | android:id="@+id/iv_back" |
| 29 | android:layout_width="@dimen/next_date_height" | 29 | android:layout_width="@dimen/next_date_height" |
| 30 | android:layout_height="@dimen/next_date_height" | 30 | android:layout_height="@dimen/next_date_height" |
| 31 | android:src="@drawable/back_ic" /> | 31 | android:src="@drawable/back_ic" /> |
| 32 | 32 | ||
| 33 | <TextView | 33 | <TextView |
| 34 | android:id="@+id/tv_date" | 34 | android:id="@+id/tv_date" |
| 35 | android:layout_width="0dp" | 35 | android:layout_width="0dp" |
| 36 | android:layout_height="match_parent" | 36 | android:layout_height="match_parent" |
| 37 | android:layout_weight="1.0" | 37 | android:layout_weight="1.0" |
| 38 | android:gravity="center" | 38 | android:gravity="center" |
| 39 | android:text="2017年1月1日" | 39 | android:text="2017年1月1日" |
| 40 | android:textColor="@color/white" | 40 | android:textColor="@color/white" |
| 41 | android:textSize="23sp" /> | 41 | android:textSize="23sp" /> |
| 42 | 42 | ||
| 43 | <ImageView | 43 | <ImageView |
| 44 | android:id="@+id/iv_next" | 44 | android:id="@+id/iv_next" |
| 45 | android:layout_width="@dimen/next_date_height" | 45 | android:layout_width="@dimen/next_date_height" |
| 46 | android:layout_height="@dimen/next_date_height" | 46 | android:layout_height="@dimen/next_date_height" |
| 47 | android:src="@drawable/next_ic" /> | 47 | android:src="@drawable/next_ic" /> |
| 48 | 48 | ||
| 49 | </LinearLayout> | 49 | </LinearLayout> |
| 50 | 50 | ||
| 51 | <LinearLayout | 51 | <LinearLayout |
| 52 | android:layout_width="match_parent" | 52 | android:layout_width="match_parent" |
| 53 | android:layout_height="wrap_content" | 53 | android:layout_height="wrap_content" |
| 54 | android:orientation="horizontal" | 54 | android:orientation="horizontal" |
| 55 | android:paddingTop="10dp" | 55 | android:paddingTop="10dp" |
| 56 | android:weightSum="100"> | 56 | android:weightSum="100"> |
| 57 | 57 | ||
| 58 | <LinearLayout | 58 | <LinearLayout |
| 59 | android:layout_width="0dp" | 59 | android:layout_width="0dp" |
| 60 | android:layout_height="wrap_content" | 60 | android:layout_height="wrap_content" |
| 61 | android:layout_weight="15" | 61 | android:layout_weight="15" |
| 62 | android:orientation="vertical"> | 62 | android:orientation="vertical"> |
| 63 | 63 | ||
| 64 | <ImageView | 64 | <ImageView |
| 65 | android:layout_width="match_parent" | 65 | android:layout_width="match_parent" |
| 66 | android:layout_height="wrap_content" | 66 | android:layout_height="wrap_content" |
| 67 | android:src="@drawable/goout_ic" | 67 | android:src="@drawable/goout_ic" |
| 68 | android:adjustViewBounds="true"/> | 68 | android:adjustViewBounds="true"/> |
| 69 | 69 | ||
| 70 | <ImageView | 70 | <ImageView |
| 71 | android:layout_width="match_parent" | 71 | android:layout_width="match_parent" |
| 72 | android:layout_height="wrap_content" | 72 | android:layout_height="wrap_content" |
| 73 | android:src="@drawable/ic_face" | 73 | android:src="@drawable/ic_face" |
| 74 | android:adjustViewBounds="true" | 74 | android:adjustViewBounds="true" |
| 75 | android:paddingTop="6dp"/> | 75 | android:paddingTop="6dp"/> |
| 76 | 76 | ||
| 77 | <ImageView | 77 | <ImageView |
| 78 | android:layout_width="match_parent" | 78 | android:layout_width="match_parent" |
| 79 | android:layout_height="wrap_content" | 79 | android:layout_height="wrap_content" |
| 80 | android:src="@drawable/ic_line" | 80 | android:src="@drawable/ic_line" |
| 81 | android:adjustViewBounds="true" | 81 | android:adjustViewBounds="true" |
| 82 | android:paddingTop="10dp"/> | 82 | android:paddingTop="10dp"/> |
| 83 | 83 | ||
| 84 | </LinearLayout> | 84 | </LinearLayout> |
| 85 | 85 | ||
| 86 | <RelativeLayout | 86 | <RelativeLayout |
| 87 | android:layout_width="0dp" | 87 | android:layout_width="0dp" |
| 88 | android:layout_height="wrap_content" | 88 | android:layout_height="wrap_content" |
| 89 | android:layout_weight="60" | 89 | android:layout_weight="60" |
| 90 | android:paddingLeft="10dp"> | 90 | android:paddingLeft="10dp"> |
| 91 | 91 | ||
| 92 | <org.eazegraph.lib.charts.PieChart | 92 | <org.eazegraph.lib.charts.PieChart |
| 93 | xmlns:eaze="http://schemas.android.com/apk/res-auto" | 93 | xmlns:eaze="http://schemas.android.com/apk/res-auto" |
| 94 | android:id="@+id/graph" | 94 | android:id="@+id/graph" |
| 95 | android:layout_width="match_parent" | 95 | android:layout_width="match_parent" |
| 96 | android:layout_height="200dp" | 96 | android:layout_height="200dp" |
| 97 | android:layout_marginTop="10dp" | 97 | android:layout_marginTop="10dp" |
| 98 | eaze:egLegendHeight="0dp" | 98 | eaze:egLegendHeight="0dp" |
| 99 | eaze:egInnerPadding="93" | 99 | eaze:egInnerPadding="93" |
| 100 | eaze:egInnerPaddingColor="@color/background_main" | 100 | eaze:egInnerPaddingColor="@color/background_main" |
| 101 | eaze:egHighlightStrength="1"/> | 101 | eaze:egHighlightStrength="1"/> |
| 102 | 102 | ||
| 103 | <LinearLayout | 103 | <LinearLayout |
| 104 | android:layout_width="match_parent" | 104 | android:layout_width="match_parent" |
| 105 | android:layout_height="200dp" | 105 | android:layout_height="200dp" |
| 106 | android:layout_marginTop="10dp" | 106 | android:layout_marginTop="10dp" |
| 107 | android:orientation="vertical" | 107 | android:orientation="vertical" |
| 108 | android:gravity="center_horizontal"> | 108 | android:gravity="center_horizontal"> |
| 109 | 109 | ||
| 110 | <ImageView | 110 | <ImageView |
| 111 | android:layout_width="@dimen/walking_img_height" | 111 | android:layout_width="@dimen/walking_img_height" |
| 112 | android:layout_height="@dimen/walking_img_height" | 112 | android:layout_height="@dimen/walking_img_height" |
| 113 | android:layout_marginTop="25dp" | 113 | android:layout_marginTop="25dp" |
| 114 | android:gravity="center" | 114 | android:gravity="center" |
| 115 | android:src="@drawable/walking_ic"/> | 115 | android:src="@drawable/walking_ic"/> |
| 116 | 116 | ||
| 117 | <TextView | 117 | <TextView |
| 118 | android:id="@+id/steps" | 118 | android:id="@+id/steps" |
| 119 | android:layout_width="match_parent" | 119 | android:layout_width="match_parent" |
| 120 | android:layout_height="wrap_content" | 120 | android:layout_height="wrap_content" |
| 121 | android:gravity="center" | 121 | android:gravity="center" |
| 122 | android:textSize="45sp" | 122 | android:textSize="45sp" |
| 123 | android:text="10.000" | 123 | android:text="10.000" |
| 124 | android:textColor="@color/white"/> | 124 | android:textColor="@color/white"/> |
| 125 | 125 | ||
| 126 | <TextView | 126 | <TextView |
| 127 | android:id="@+id/tv_smallStepGoal" | ||
| 127 | android:id="@+id/tv_smallStepGoal" | 128 | android:layout_width="wrap_content" |
| 128 | android:layout_width="wrap_content" | 129 | android:layout_height="wrap_content" |
| 129 | android:layout_height="wrap_content" | 130 | android:text="@string/pie_text_content1" |
| 130 | android:text="@string/pie_text_content1" | 131 | android:textSize="14sp" |
| 131 | android:textSize="14sp" | 132 | android:padding="4dp" |
| 132 | android:padding="4dp" | 133 | android:textColor="@color/white"/> |
| 133 | android:textColor="@color/white"/> | 134 | |
| 134 | 135 | <TextView | |
| 135 | <TextView | 136 | android:layout_width="wrap_content" |
| 136 | android:layout_width="wrap_content" | 137 | android:layout_height="wrap_content" |
| 137 | android:layout_height="wrap_content" | 138 | android:text="@string/pie_text_content2" |
| 138 | android:text="@string/pie_text_content2" | 139 | android:textSize="14sp" |
| 139 | android:textSize="14sp" | 140 | android:textColor="@color/white"/> |
| 140 | android:textColor="@color/white"/> | 141 | |
| 141 | 142 | <TextView | |
| 142 | <TextView | 143 | android:id="@+id/tv_smallRemain" |
| 143 | android:id="@+id/tv_smallRemain" | 144 | android:layout_width="wrap_content" |
| 144 | android:layout_width="wrap_content" | 145 | android:layout_height="wrap_content" |
| 145 | android:layout_height="wrap_content" | 146 | android:layout_below="@+id/steps" |
| 146 | android:layout_below="@+id/steps" | 147 | android:layout_centerHorizontal="true" |
| 147 | android:layout_centerHorizontal="true" | 148 | android:text="@string/pie_text_content3" |
| 148 | android:text="@string/pie_text_content3" | 149 | android:textSize="14sp" |
| 149 | android:textSize="14sp" | 150 | android:textColor="@color/white"/> |
| 150 | android:textColor="@color/white"/> | 151 | |
| 151 | 152 | </LinearLayout> | |
| 152 | </LinearLayout> | 153 | |
| 153 | 154 | </RelativeLayout> | |
| 154 | </RelativeLayout> | 155 | |
| 155 | 156 | <LinearLayout | |
| 156 | <LinearLayout | 157 | android:layout_width="0dp" |
| 157 | android:layout_width="0dp" | 158 | android:layout_height="wrap_content" |
| 158 | android:layout_height="wrap_content" | 159 | android:layout_weight="25" |
| 159 | android:layout_weight="25" | 160 | android:gravity="center" |
| 160 | android:gravity="center" | 161 | android:orientation="vertical"> |
| 161 | android:orientation="vertical"> | 162 | |
| 162 | 163 | <TextView | |
| 163 | <TextView | 164 | android:layout_width="wrap_content" |
| 164 | android:layout_width="wrap_content" | 165 | android:layout_height="wrap_content" |
| 165 | android:layout_height="wrap_content" | 166 | android:text="@string/goal_jp" |
| 166 | android:text="@string/goal_jp" | 167 | android:textColor="@color/white" |
| 167 | android:textColor="@color/white" | 168 | android:textSize="16sp" /> |
| 168 | android:textSize="16sp" /> | 169 | |
| 169 | 170 | <TextView | |
| 170 | <TextView | 171 | android:id="@+id/tv_stepGoal" |
| 171 | android:id="@+id/tv_stepGoal" | 172 | android:layout_width="wrap_content" |
| 172 | android:layout_width="wrap_content" | 173 | android:layout_height="wrap_content" |
| 173 | android:layout_height="wrap_content" | 174 | android:paddingLeft="10dp" |
| 174 | android:paddingLeft="10dp" | 175 | android:text="10000歩" |
| 175 | android:text="10000歩" | 176 | android:textColor="@color/white" |
| 176 | android:textColor="@color/white" | 177 | android:textSize="16sp" /> |
| 177 | android:textSize="16sp" /> | 178 | |
| 178 | 179 | <TextView | |
| 179 | <TextView | 180 | android:layout_width="wrap_content" |
| 180 | android:layout_width="wrap_content" | 181 | android:layout_height="wrap_content" |
| 181 | android:layout_height="wrap_content" | 182 | android:paddingTop="10dp" |
| 182 | android:paddingTop="10dp" | 183 | android:text="@string/remaining_number_step" |
| 183 | android:text="@string/remaining_number_step" | 184 | android:textColor="@color/white" |
| 184 | android:textColor="@color/white" | 185 | android:textSize="16sp" /> |
| 185 | android:textSize="16sp" /> | 186 | |
| 186 | 187 | <TextView | |
| 187 | <TextView | 188 | android:id="@+id/tv_stepRemain" |
| 188 | android:id="@+id/tv_stepRemain" | 189 | android:layout_width="wrap_content" |
| 189 | android:layout_width="wrap_content" | 190 | android:layout_height="wrap_content" |
| 190 | android:layout_height="wrap_content" | 191 | android:paddingLeft="10dp" |
| 191 | android:paddingLeft="10dp" | 192 | android:text="3000歩" |
| 192 | android:text="3000歩" | 193 | android:textColor="@color/white" |
| 193 | android:textColor="@color/white" | 194 | android:textSize="16sp" /> |
| 194 | android:textSize="16sp" /> | 195 | |
| 195 | 196 | <TextView | |
| 196 | <TextView | 197 | android:layout_width="wrap_content" |
| 197 | android:layout_width="wrap_content" | 198 | android:layout_height="wrap_content" |
| 198 | android:layout_height="wrap_content" | 199 | android:paddingTop="10dp" |
| 199 | android:paddingTop="10dp" | 200 | android:text="@string/achiverment_rate" |
| 200 | android:text="@string/achiverment_rate" | 201 | android:textColor="@color/white" |
| 201 | android:textColor="@color/white" | 202 | android:textSize="16sp" /> |
| 202 | android:textSize="16sp" /> | 203 | |
| 203 | 204 | <TextView | |
| 204 | <TextView | 205 | android:id="@+id/tv_stepRateDone" |
| 205 | android:id="@+id/tv_stepRateDone" | 206 | android:layout_width="wrap_content" |
| 206 | android:layout_width="wrap_content" | 207 | android:layout_height="wrap_content" |
| 207 | android:layout_height="wrap_content" | 208 | android:paddingLeft="10dp" |
| 208 | android:paddingLeft="10dp" | 209 | android:text="78%" |
| 209 | android:text="78%" | 210 | android:textColor="@color/white" |
| 210 | android:textColor="@color/white" | 211 | android:textSize="16sp" /> |
| 211 | android:textSize="16sp" /> | 212 | |
| 212 | 213 | </LinearLayout> | |
| 213 | </LinearLayout> | 214 | |
| 214 | 215 | </LinearLayout> | |
| 215 | </LinearLayout> | 216 | |
| 216 | 217 | <LinearLayout | |
| 217 | <LinearLayout | 218 | android:layout_width="match_parent" |
| 218 | android:layout_width="match_parent" | 219 | android:layout_height="wrap_content" |
| 219 | android:layout_height="wrap_content" | 220 | android:weightSum="100" |
| 220 | android:weightSum="100" | 221 | android:paddingTop="20dp" |
| 221 | android:paddingTop="20dp" | 222 | android:orientation="horizontal"> |
| 222 | android:orientation="horizontal"> | 223 | |
| 223 | 224 | <LinearLayout | |
| 224 | <LinearLayout | 225 | android:layout_width="0dp" |
| 225 | android:layout_width="0dp" | 226 | android:layout_height="wrap_content" |
| 226 | android:layout_height="wrap_content" | 227 | android:layout_weight="20" |
| 227 | android:layout_weight="20" | 228 | android:gravity="center" |
| 228 | android:gravity="center" | 229 | android:orientation="vertical"> |
| 229 | android:orientation="vertical"> | 230 | |
| 230 | 231 | </LinearLayout> | |
| 231 | </LinearLayout> | 232 | |
| 232 | 233 | <LinearLayout | |
| 233 | <LinearLayout | 234 | android:layout_width="0dp" |
| 234 | android:layout_width="0dp" | 235 | android:layout_height="wrap_content" |
| 235 | android:layout_height="wrap_content" | 236 | android:layout_weight="20" |
| 236 | android:layout_weight="20" | 237 | android:gravity="center" |
| 237 | android:gravity="center" | 238 | android:orientation="vertical"> |
| 238 | android:orientation="vertical"> | 239 | |
| 239 | 240 | <ImageView | |
| 240 | <ImageView | 241 | android:layout_width="wrap_content" |
| 241 | android:layout_width="wrap_content" | 242 | android:layout_height="wrap_content" |
| 242 | android:layout_height="wrap_content" | 243 | android:src="@drawable/category" |
| 243 | android:src="@drawable/category" | 244 | android:adjustViewBounds="true"/> |
| 244 | android:adjustViewBounds="true"/> | 245 | |
| 245 | 246 | </LinearLayout> | |
| 246 | </LinearLayout> | 247 | |
| 247 | 248 | <LinearLayout | |
| 248 | <LinearLayout | 249 | android:layout_width="0dp" |
| 249 | android:layout_width="0dp" | 250 | android:layout_height="wrap_content" |
| 250 | android:layout_height="wrap_content" | 251 | android:layout_weight="20" |
| 251 | android:layout_weight="20" | 252 | android:gravity="center" |
| 252 | android:gravity="center" | 253 | android:orientation="vertical"> |
| 253 | android:orientation="vertical"> | 254 | |
| 254 | 255 | <TextView | |
| 255 | <TextView | 256 | android:id="@+id/tv_distance" |
| 256 | android:id="@+id/tv_distance" | 257 | android:layout_width="wrap_content" |
| 257 | android:layout_width="wrap_content" | 258 | android:layout_height="wrap_content" |
| 258 | android:layout_height="wrap_content" | 259 | android:text="4.9" |
| 259 | android:text="4.9" | 260 | android:textColor="@color/white" |
| 260 | android:textColor="@color/white" | 261 | android:textSize="30sp" /> |
| 261 | android:textSize="30sp" /> | 262 | |
| 262 | 263 | </LinearLayout> | |
| 263 | </LinearLayout> | 264 | |
| 264 | 265 | <LinearLayout | |
| 265 | <LinearLayout | 266 | android:layout_width="0dp" |
| 266 | android:layout_width="0dp" | 267 | android:layout_height="wrap_content" |
| 267 | android:layout_height="wrap_content" | 268 | android:layout_weight="20" |
| 268 | android:layout_weight="20" | 269 | android:gravity="center" |
| 269 | android:gravity="center" | 270 | android:orientation="vertical"> |
| 270 | android:orientation="vertical"> | 271 | |
| 271 | 272 | <TextView | |
| 273 | android:id="@+id/tv_time" | ||
| 272 | <TextView | 274 | android:layout_width="wrap_content" |
| 273 | android:id="@+id/tv_time" | 275 | android:layout_height="wrap_content" |
| 274 | android:layout_width="wrap_content" | 276 | android:text="1:09" |
| 275 | android:layout_height="wrap_content" | 277 | android:textColor="@color/white" |
| 276 | android:text="1:09" | 278 | android:textSize="30sp" /> |
| 277 | android:textColor="@color/white" | 279 | |
| 278 | android:textSize="30sp" /> | 280 | </LinearLayout> |
| 279 | 281 | ||
| 280 | </LinearLayout> | 282 | <LinearLayout |
| 281 | 283 | android:layout_width="0dp" | |
| 282 | <LinearLayout | 284 | android:layout_height="wrap_content" |
| 283 | android:layout_width="0dp" | 285 | android:layout_weight="20" |
| 284 | android:layout_height="wrap_content" | 286 | android:gravity="center" |
| 285 | android:layout_weight="20" | 287 | android:orientation="vertical"> |
| 286 | android:gravity="center" | 288 | |
| 287 | android:orientation="vertical"> | 289 | <ImageView |
| 288 | 290 | android:id="@+id/iv_play" | |
| 289 | <ImageView | 291 | android:layout_width="@dimen/next_date_height" |
| 290 | android:id="@+id/iv_play" | 292 | android:layout_height="wrap_content" |
| 291 | android:layout_width="@dimen/next_date_height" | 293 | android:src="@drawable/pause" |
| 292 | android:layout_height="wrap_content" | 294 | android:background="@color/white" |
| 293 | android:src="@drawable/pause" | 295 | android:adjustViewBounds="true" |
| 294 | android:background="@color/white" | 296 | android:visibility="gone"/> |
| 295 | android:adjustViewBounds="true" | 297 | |
| 296 | android:visibility="gone"/> | 298 | </LinearLayout> |
| 297 | 299 | </LinearLayout> | |
| 298 | </LinearLayout> | 300 | |
| 299 | </LinearLayout> | 301 | <LinearLayout |
| 300 | 302 | android:layout_width="match_parent" | |
| 301 | <LinearLayout | 303 | android:layout_height="wrap_content" |
| 302 | android:layout_width="match_parent" | 304 | android:weightSum="100" |
| 303 | android:layout_height="wrap_content" | 305 | android:orientation="horizontal"> |
| 304 | android:weightSum="100" | 306 | |
| 305 | android:orientation="horizontal"> | 307 | <LinearLayout |
| 306 | 308 | android:layout_width="0dp" | |
| 307 | <LinearLayout | 309 | android:layout_height="wrap_content" |
| 308 | android:layout_width="0dp" | 310 | android:layout_weight="20" |
| 309 | android:layout_height="wrap_content" | 311 | android:gravity="center" |
| 310 | android:layout_weight="20" | 312 | android:orientation="vertical"> |
| 311 | android:gravity="center" | 313 | |
| 312 | android:orientation="vertical"> | 314 | </LinearLayout> |
| 313 | 315 | ||
| 314 | </LinearLayout> | 316 | <LinearLayout |
| 315 | 317 | android:layout_width="0dp" | |
| 316 | <LinearLayout | 318 | android:layout_height="wrap_content" |
| 317 | android:layout_width="0dp" | 319 | android:layout_weight="20" |
| 318 | android:layout_height="wrap_content" | 320 | android:gravity="center" |
| 319 | android:layout_weight="20" | 321 | android:orientation="vertical"> |
| 320 | android:gravity="center" | 322 | |
| 321 | android:orientation="vertical"> | 323 | <TextView |
| 322 | 324 | android:layout_width="wrap_content" | |
| 323 | <TextView | 325 | android:layout_height="wrap_content" |
| 324 | android:layout_width="wrap_content" | 326 | android:text="@string/carori" |
| 325 | android:layout_height="wrap_content" | 327 | android:textColor="@color/white" |
| 326 | android:text="@string/carori" | 328 | android:textSize="16sp" /> |
| 327 | android:textColor="@color/white" | 329 | |
| 328 | android:textSize="16sp" /> | 330 | </LinearLayout> |
| 329 | 331 | ||
| 330 | </LinearLayout> | 332 | <LinearLayout |
| 331 | 333 | android:layout_width="0dp" | |
| 332 | <LinearLayout | 334 | android:layout_height="wrap_content" |
| 333 | android:layout_width="0dp" | 335 | android:layout_weight="20" |
| 334 | android:layout_height="wrap_content" | 336 | android:gravity="center" |
| 335 | android:layout_weight="20" | 337 | android:orientation="vertical"> |
| 336 | android:gravity="center" | 338 | |
| 337 | android:orientation="vertical"> | 339 | <TextView |
| 338 | |||
| 339 | <TextView | 340 | android:layout_width="wrap_content" |
| 340 | android:layout_width="wrap_content" | 341 | android:layout_height="wrap_content" |
| 341 | android:layout_height="wrap_content" | 342 | android:text="@string/km" |
| 342 | android:text="@string/km" | 343 | android:textColor="@color/white" |
| 343 | android:textColor="@color/white" | 344 | android:textSize="16sp" /> |
| 344 | android:textSize="16sp" /> | 345 | |
| 345 | 346 | </LinearLayout> | |
| 346 | </LinearLayout> | 347 | |
| 347 | 348 | <LinearLayout | |
| 348 | <LinearLayout | 349 | android:layout_width="0dp" |
| 349 | android:layout_width="0dp" | 350 | android:layout_height="wrap_content" |
| 350 | android:layout_height="wrap_content" | 351 | android:layout_weight="20" |
| 351 | android:layout_weight="20" | 352 | android:gravity="center" |
| 352 | android:gravity="center" | 353 | android:orientation="vertical"> |
| 353 | android:orientation="vertical"> | 354 | |
| 354 | 355 | <TextView | |
| 355 | <TextView | ||
| 356 | android:layout_width="wrap_content" | 356 | android:layout_width="wrap_content" |
| 357 | android:layout_height="wrap_content" | 357 | android:layout_height="wrap_content" |
| 358 | android:text="@string/time" | 358 | android:text="@string/time" |
| 359 | android:textColor="@color/white" | 359 | android:textColor="@color/white" |
| 360 | android:textSize="16sp" /> | 360 | android:textSize="16sp" /> |
| 361 | 361 | ||
| 362 | </LinearLayout> | 362 | </LinearLayout> |
| 363 | </LinearLayout> | 363 | </LinearLayout> |
| 364 | 364 | ||
| 365 | 365 | ||
| 366 | <LinearLayout | 366 | <LinearLayout |
| 367 | android:layout_width="match_parent" | 367 | android:layout_width="match_parent" |
| 368 | android:layout_height="120dp" | 368 | android:layout_height="120dp" |
| 369 | android:orientation="vertical" | 369 | android:orientation="vertical" |
| 370 | android:layout_marginTop="10dp"> | 370 | android:layout_marginTop="10dp"> |
| 371 | 371 | ||
| 372 | <!--<org.eazegraph.lib.charts.BarChart--> | 372 | <!--<org.eazegraph.lib.charts.BarChart--> |
| 373 | <!--xmlns:eaze="http://schemas.android.com/apk/res-auto"--> | 373 | <!--xmlns:eaze="http://schemas.android.com/apk/res-auto"--> |
| 374 | <!--android:id="@+id/bargraph"--> | 374 | <!--android:id="@+id/bargraph"--> |
| 375 | <!--android:layout_width="match_parent"--> | 375 | <!--android:layout_width="match_parent"--> |
| 376 | <!--android:layout_height="120dp"--> | 376 | <!--android:layout_height="120dp"--> |
| 377 | <!--android:layout_below="@+id/averageandtotaltext"--> | 377 | <!--android:layout_below="@+id/averageandtotaltext"--> |
| 378 | <!--eaze:egLegendHeight="0dp"--> | 378 | <!--eaze:egLegendHeight="0dp"--> |
| 379 | <!--eaze:egShowValues="false" />--> | 379 | <!--eaze:egShowValues="false" />--> |
| 380 | <com.github.mikephil.charting.charts.BarChart | 380 | <com.github.mikephil.charting.charts.BarChart |
| 381 | android:id="@+id/chart" | 381 | android:id="@+id/chart" |
| 382 | android:layout_width="match_parent" | 382 | android:layout_width="match_parent" |
| 383 | android:layout_height="match_parent" /> | 383 | android:layout_height="match_parent" /> |
| 384 | 384 | ||
| 385 | 385 | ||
| 386 | </LinearLayout> | 386 | </LinearLayout> |
| 387 | 387 | ||
| 388 | 388 | ||
| 389 | </LinearLayout> | 389 | </LinearLayout> |
| 390 | </ScrollView> | 390 | </ScrollView> |
| 391 | 391 | ||
| 392 | <include layout="@layout/type_step" /> | 392 | <include layout="@layout/type_step" /> |
app/src/main/res/values/strings.xml
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation"> | 2 | <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation"> |
| 3 | <string name="app_id">de.j4velin.pedometer</string> | 3 | <string name="app_id">de.j4velin.pedometer</string> |
| 4 | <string name="app_name">Pedometer</string> | 4 | <string name="app_name">Pedometer</string> |
| 5 | <string name="sns_fragment">コミュニティー</string> | 5 | <string name="sns_fragment">コミュニティー</string> |
| 6 | <string name="goal">Goal</string> | 6 | <string name="goal">Goal</string> |
| 7 | <string name="step_size">Step size</string> | 7 | <string name="step_size">Step size</string> |
| 8 | <string name="about">About</string> | 8 | <string name="about">About</string> |
| 9 | <string name="account">Account</string> | 9 | <string name="account">Account</string> |
| 10 | <string name="goal_summary">Current goal: %,d steps</string> | 10 | <string name="goal_summary">Current goal: %,d steps</string> |
| 11 | <string name="step_size_summary">Current step size: %1$.2f %2$s</string> | 11 | <string name="step_size_summary">Current step size: %1$.2f %2$s</string> |
| 12 | <string name="sign_in">Sign in with your Google account to use the Achievements and Leaderboards features</string> | 12 | <string name="sign_in">Sign in with your Google account to use the Achievements and Leaderboards features</string> |
| 13 | <string name="signed_in">Signed in as %s</string> | 13 | <string name="signed_in">Signed in as %s</string> |
| 14 | <string name="export_summary">Save your data in a .csv file</string> | 14 | <string name="export_summary">Save your data in a .csv file</string> |
| 15 | <string name="export_title">Export/Backup</string> | 15 | <string name="export_title">Export/Backup</string> |
| 16 | <string name="import_summary">Imports previously saved data</string> | 16 | <string name="import_summary">Imports previously saved data</string> |
| 17 | <string name="import_title">Import/Restore</string> | 17 | <string name="import_title">Import/Restore</string> |
| 18 | <string name="notification">Show notification</string> | 18 | <string name="notification">Show notification</string> |
| 19 | <string name="set_goal">Set goal</string> | 19 | <string name="set_goal">Set goal</string> |
| 20 | <string name="set_step_size">Set step size</string> | 20 | <string name="set_step_size">Set step size</string> |
| 21 | <string name="sign_out">Sign out</string> | 21 | <string name="sign_out">Sign out</string> |
| 22 | <string name="file_cant_read">Error: %s can not be read</string> | 22 | <string name="file_cant_read">Error: %s can not be read</string> |
| 23 | <string name="error_file">Error accessing the file: %s</string> | 23 | <string name="error_file">Error accessing the file: %s</string> |
| 24 | <string name="error_external_storage_not_available">Error: External storage not available</string> | 24 | <string name="error_external_storage_not_available">Error: External storage not available</string> |
| 25 | <string name="data_saved">Data saved in %s</string> | 25 | <string name="data_saved">Data saved in %s</string> |
| 26 | <string name="entries_imported">%d entries imported</string> | 26 | <string name="entries_imported">%d entries imported</string> |
| 27 | <string name="entries_ignored">%d entries were ignored as they did not contain valid data</string> | 27 | <string name="entries_ignored">%d entries were ignored as they did not contain valid data</string> |
| 28 | <string name="entries_skipped">%d entries were skipped as there already exists data for these days</string> | 28 | <string name="entries_skipped">%d entries were skipped as there already exists data for these days</string> |
| 29 | <string name="sign_in_necessary">Sign in necessary</string> | 29 | <string name="sign_in_necessary">Sign in necessary</string> |
| 30 | <string name="please_sign_in_with_your_google_account">Please sign in with your Google+ account to use this feature.</string> | 30 | <string name="please_sign_in_with_your_google_account">Please sign in with your Google+ account to use this feature.</string> |
| 31 | <string name="steps">steps</string> | 31 | <string name="steps">steps</string> |
| 32 | <string name="text_color">Text color:</string> | 32 | <string name="text_color">Text color:</string> |
| 33 | <string name="background_color">Background color:</string> | 33 | <string name="background_color">Background color:</string> |
| 34 | <string name="settings">Settings</string> | 34 | <string name="settings">Settings</string> |
| 35 | <string name="achievements">Achievements</string> | 35 | <string name="achievements">Achievements</string> |
| 36 | <string name="leaderboard">Leaderboard</string> | 36 | <string name="leaderboard">Leaderboard</string> |
| 37 | <string name="faq">FAQ</string> | 37 | <string name="faq">FAQ</string> |
| 38 | <string name="goal_reached_notification">Goal reached! %s steps and counting</string> | 38 | <string name="goal_reached_notification">Goal reached! %s steps and counting</string> |
| 39 | <string name="notification_text">%s steps to go</string> | 39 | <string name="notification_text">%s steps to go</string> |
| 40 | <string name="total">Total</string> | 40 | <string name="total">Total</string> |
| 41 | <string name="notification_title">Pedometer is counting</string> | 41 | <string name="notification_title">Pedometer is counting</string> |
| 42 | <string name="your_progress_will_be_shown_here_soon">Your progress will be shown here soon</string> | 42 | <string name="your_progress_will_be_shown_here_soon">Your progress will be shown here soon</string> |
| 43 | <string name="average">Average</string> | 43 | <string name="average">Average</string> |
| 44 | <string name="record">Record</string> | 44 | <string name="record">Record</string> |
| 45 | <string name="total_last_7_days">Total last 7 days</string> | 45 | <string name="total_last_7_days">Total last 7 days</string> |
| 46 | <string name="average_last_7_days">Average last 7 days</string> | 46 | <string name="average_last_7_days">Average last 7 days</string> |
| 47 | <string name="total_this_month">Total this month</string> | 47 | <string name="total_this_month">Total this month</string> |
| 48 | <string name="average_this_month">Average this month</string> | 48 | <string name="average_this_month">Average this month</string> |
| 49 | <string name="file_already_exists">File already exists. Are you sure you want to overwrite it?</string> | 49 | <string name="file_already_exists">File already exists. Are you sure you want to overwrite it?</string> |
| 50 | <string name="about_text_links">This app was created by Thomas Hoffmann (<a href="https://www.j4velin.de">www.j4velin.de</a>) and uses <a href="https://github.com/blackfizz/EazeGraph">EazeGraph</a> by Paul Cech and <a href="https://github.com/attenzione/android-ColorPickerPreference">ColorPickerPreference</a> by Sergey Margaritov.\n\nPedometer is open source! Get the code and the full list of contributors from <a href="https://github.com/j4velin/Pedometer">GitHub</a>.\n\n</string> | 50 | <string name="about_text_links">This app was created by Thomas Hoffmann (<a href="https://www.j4velin.de">www.j4velin.de</a>) and uses <a href="https://github.com/blackfizz/EazeGraph">EazeGraph</a> by Paul Cech and <a href="https://github.com/attenzione/android-ColorPickerPreference">ColorPickerPreference</a> by Sergey Margaritov.\n\nPedometer is open source! Get the code and the full list of contributors from <a href="https://github.com/j4velin/Pedometer">GitHub</a>.\n\n</string> |
| 51 | <string name="about_app_version">App version: %s</string> | 51 | <string name="about_app_version">App version: %s</string> |
| 52 | <string name="since">Since %s</string> | 52 | <string name="since">Since %s</string> |
| 53 | <string name="start">Start</string> | 53 | <string name="start">Start</string> |
| 54 | <string name="stop">Stop</string> | 54 | <string name="stop">Stop</string> |
| 55 | <string name="close">close</string> | 55 | <string name="close">close</string> |
| 56 | <string name="no_split_active">No split counter active. Click start to count the steps from now on</string> | 56 | <string name="no_split_active">No split counter active. Click start to count the steps from now on</string> |
| 57 | <string name="split_count">Split count</string> | 57 | <string name="split_count">Split count</string> |
| 58 | <string name="pause">Pause</string> | 58 | <string name="pause">Pause</string> |
| 59 | <string name="resume">Resume</string> | 59 | <string name="resume">Resume</string> |
| 60 | <string name="ispaused">Pedometer is paused</string> | 60 | <string name="ispaused">Pedometer is paused</string> |
| 61 | <string name="pause_on_power_title">Pause while charging</string> | 61 | <string name="pause_on_power_title">Pause while charging</string> |
| 62 | <string name="pause_on_power_summary">Pause Pedometer while device is charging</string> | 62 | <string name="pause_on_power_summary">Pause Pedometer while device is charging</string> |
| 63 | <string name="no_sensor">Sensor not found</string> | 63 | <string name="no_sensor">Sensor not found</string> |
| 64 | <string name="no_sensor_explain">This app requires a dedicated hardware step sensor - which your device does not have. This app won\'t run on your device.</string> | 64 | <string name="no_sensor_explain">This app requires a dedicated hardware step sensor - which your device does not have. This app won\'t run on your device.</string> |
| 65 | <string name="setting">設定</string> | 65 | <string name="setting">設定</string> |
| 66 | <string name="profile_change">プロフェイール変更</string> | 66 | <string name="profile_change">プロフェイール変更</string> |
| 67 | <string name="step">step</string> | 67 | <string name="step">step</string> |
| 68 | <string name="remaining_number_step">残歩数</string> | 68 | <string name="remaining_number_step">残歩数</string> |
| 69 | <string name="achiverment_rate">達成率</string> | 69 | <string name="achiverment_rate">達成率</string> |
| 70 | <string name="notify">お知らせ</string> | 70 | <string name="notify">お知らせ</string> |
| 71 | <string name="data">●●●●●●●</string> | 71 | <string name="data">●●●●●●●</string> |
| 72 | <string name="bike">BIKE</string> | 72 | <string name="bike">BIKE</string> |
| 73 | <string name="walking">WALKING</string> | 73 | <string name="walking">WALKING</string> |
| 74 | <string name="running">RUNNING</string> | 74 | <string name="running">RUNNING</string> |
| 75 | <string name="home">HOME</string> | 75 | <string name="home">HOME</string> |
| 76 | <string name="today">TODAY</string> | 76 | <string name="today">TODAY</string> |
| 77 | <string name="date">日付</string> | 77 | <string name="date">日付</string> |
| 78 | <string name="today_jp">今日</string> | 78 | <string name="today_jp">今日</string> |
| 79 | <string name="history">履歴</string> | 79 | <string name="history">履歴</string> |
| 80 | <string name="ranking">ランキング</string> | 80 | <string name="ranking">ランキング</string> |
| 81 | <string name="map">MAP</string> | 81 | <string name="map">MAP</string> |
| 82 | <string name="sns">SNS</string> | 82 | <string name="sns">SNS</string> |
| 83 | <string name="step_further">目標まであと %$d 歩です</string> | 83 | <string name="step_further">目標まであと %$d 歩です</string> |
| 84 | <string name="goal_jp">目標</string> | 84 | <string name="goal_jp">目標</string> |
| 85 | <string name="step_jp">歩</string> | 85 | <string name="step_jp">歩</string> |
| 86 | <string name="km">KM</string> | 86 | <string name="km">KM</string> |
| 87 | <string name="time">時間</string> | 87 | <string name="time">時間</string> |
| 88 | <string name="carori">カロリー</string> | 88 | <string name="carori">カロリー</string> |
| 89 | 89 | ||
| 90 | <string name="pie_text_content1">/10.000</string> | 90 | <string name="pie_text_content1">/10.000</string> |
| 91 | <string name="pie_text_content2">目標まであと</string> | 91 | <string name="pie_text_content2">目標まであと</string> |
| 92 | <string name="pie_text_content3">3487歩です</string> | 92 | <string name="pie_text_content3">3487歩です</string> |
| 93 | <string name="pie_text_content3a">%d歩です</string> | 93 | <string name="pie_text_content3a">%d歩です</string> |
| 94 | <string name="percent">%s%</string> | 94 | <string name="percent">%s%</string> |
| 95 | <string name="percent_unit">%s%</string> | 95 | <string name="percent_unit">%s%</string> |
| 96 | <string name="step_unit">%d step</string> | 96 | <string name="step_unit">%d step</string> |
| 97 | <string name="step_unit_1">%d stepです</string> | 97 | <string name="step_unit_1">%d stepです</string> |
| 98 | <string name="kcal_unit">%s kcal</string> | 98 | <string name="kcal_unit">%s kcal</string> |
| 99 | <string name="distance_unit">%s KM</string> | 99 | <string name="distance_unit">%s KM</string> |
| 100 | <string name="time_unit">%s 時間</string> | 100 | <string name="time_unit">%s 時間</string> |
| 101 | 101 | ||
| 102 | <string name="login">ライフログ</string> | 102 | <string name="login">ライフログ</string> |
| 103 | <string name="email">メールアドレス</string> | 103 | <string name="email">メールアドレス</string> |
| 104 | <string name="password">パスワード</string> | 104 | <string name="password">パスワード</string> |
| 105 | <string name="forget_pass"><u>パスワードをお忘れの方</u></string> | 105 | <string name="forget_pass"><u>パスワードをお忘れの方</u></string> |
| 106 | <string name="register">登録がまだの方</string> | 106 | <string name="register">登録がまだの方</string> |
| 107 | <string name="register_button">新規登録</string> | 107 | <string name="register_button">新規登録</string> |
| 108 | <string name="username">ユーザー名</string> | 108 | <string name="username">ユーザー名</string> |
| 109 | <string name="name">氏名</string> | 109 | <string name="name">氏名</string> |
| 110 | <string name="nickname">ニックネーム</string> | 110 | <string name="nickname">ニックネーム</string> |
| 111 | <string name="confirm_pass">確認用パスワード</string> | 111 | <string name="confirm_pass">確認用パスワード</string> |
| 112 | <string name="sex">性別</string> | 112 | <string name="sex">性別</string> |
| 113 | <string name="birthday">生年月日</string> | 113 | <string name="birthday">生年月日</string> |
| 114 | <string name="height">身長</string> | 114 | <string name="height">身長</string> |
| 115 | <string name="weight">体重</string> | 115 | <string name="weight">体重</string> |
| 116 | <string name="level_active">1日の身体活動レベル</string> | 116 | <string name="level_active">1日の身体活動レベル</string> |
| 117 | <string name="low">低い</string> | 117 | <string name="low">低い</string> |
| 118 | <string name="usually">普通</string> | 118 | <string name="usually">普通</string> |
| 119 | <string name="hight">高い</string> | 119 | <string name="hight">高い</string> |
| 120 | <string name="body_fat_percent">体脂肪率</string> | 120 | <string name="body_fat_percent">体脂肪率</string> |
| 121 | <string name="address">お住いの地域</string> | 121 | <string name="address">お住いの地域</string> |
| 122 | <string name="comment">コメント</string> | 122 | <string name="comment">コメント</string> |
| 123 | <string name="member_registration">会員登録</string> | 123 | <string name="member_registration">会員登録</string> |
| 124 | <string name="send_push_notify">プッシュ通知を送信します。\nよろしいでしょうか?</string> | 124 | <string name="send_push_notify">プッシュ通知を送信します。\nよろしいでしょうか?</string> |
| 125 | <string name="not_allowed">許可しない</string> | 125 | <string name="not_allowed">許可しない</string> |
| 126 | <string name="allowed">許可</string> | 126 | <string name="allowed">許可</string> |
| 127 | <string name="please_select">選択してください</string> | 127 | <string name="please_select">選択してください</string> |
| 128 | 128 | ||
| 129 | <string name="prefecture">都道府県</string> | 129 | <string name="prefecture">都道府県</string> |
| 130 | 130 | ||
| 131 | <string name="login_error_title">ログインエラー</string> | 131 | <string name="login_error_title">ログインエラー</string> |
| 132 | <string name="login_error">ログインできません。</string> | 132 | <string name="login_error">ログインできません。</string> |
| 133 | <string name="ok">OK</string> | 133 | <string name="ok">OK</string> |
| 134 | <string name="error_title">エラー</string> | 134 | <string name="error_title">エラー</string> |
| 135 | <string name="password_is_null">パスワードはnullです。</string> | 135 | <string name="password_is_null">パスワードはnullです。</string> |
| 136 | <string name="account_is_null">メールはヌルです。</string> | 136 | <string name="account_is_null">メールはヌルです。</string> |
| 137 | <string name="uploading">アップロード中</string> | 137 | <string name="uploading">アップロード中</string> |
| 138 | <string name="register_err">レジスタエラー</string> | 138 | <string name="register_err">レジスタエラー</string> |
| 139 | <string name="err_exception">エラー例外</string> | 139 | <string name="err_exception">エラー例外</string> |
| 140 | <string name="cm">cm</string> | 140 | <string name="cm">cm</string> |
| 141 | <string name="kg">kg</string> | 141 | <string name="kg">kg</string> |
| 142 | <string name="percen">%</string> | 142 | <string name="percen">%</string> |
| 143 | <string name="waite_some_minute">しばらくお待ちください。</string> | 143 | <string name="waite_some_minute">しばらくお待ちください。</string> |
| 144 | <string name="request_pass_error">要求を送信できないため、パスワードを取得できません。</string> | 144 | <string name="request_pass_error">要求を送信できないため、パスワードを取得できません。</string> |
| 145 | <string name="password_not_send">パスワードが送信されていません。もう一度お試しください。</string> | 145 | <string name="password_not_send">パスワードが送信されていません。もう一度お試しください。</string> |
| 146 | <string name="password_have_send">パスワードが送られてきました、メールをチェックしてください。</string> | 146 | <string name="password_have_send">パスワードが送られてきました、メールをチェックしてください。</string> |
| 147 | <string name="register_success">登録成功</string> | 147 | <string name="register_success">登録成功</string> |
| 148 | 148 | ||
| 149 | <!-- message error register --> | 149 | <!-- message error register --> |
| 150 | <string name="username_null">ユーザー名はnullです。</string> | 150 | <string name="username_null">ユーザー名はnullです。</string> |
| 151 | <string name="name_null">名前はnullです。</string> | 151 | <string name="name_null">名前はnullです。</string> |
| 152 | <string name="nickname_null">ニックネームはnullです。</string> | 152 | <string name="nickname_null">ニックネームはnullです。</string> |
| 153 | <string name="mail_null">メールはヌルです。</string> | 153 | <string name="mail_null">メールはヌルです。</string> |
| 154 | <string name="mail_invalid">電子メールが無効です。</string> | 154 | <string name="mail_invalid">電子メールが無効です。</string> |
| 155 | <string name="password_null">パスワードはnullです。</string> | 155 | <string name="password_null">パスワードはnullです。</string> |
| 156 | <string name="confirm_pass_null">パスワードの確認はnullです。</string> | 156 | <string name="confirm_pass_null">パスワードの確認はnullです。</string> |
| 157 | <string name="password_less_6">パスワードの長さは6文字以上です。</string> | 157 | <string name="password_less_6">パスワードの長さは6文字以上です。</string> |
| 158 | <string name="confirm_pass_wrong">パスワードの確認が間違っています。</string> | 158 | <string name="confirm_pass_wrong">パスワードの確認が間違っています。</string> |
| 159 | <string name="sex_not_select">性別は選択されていません。</string> | 159 | <string name="sex_not_select">性別は選択されていません。</string> |
| 160 | <string name="birthday_not_select">誕生日は選択されていません。</string> | 160 | <string name="birthday_not_select">誕生日は選択されていません。</string> |
| 161 | <string name="height_null">Hightはnullです。</string> | 161 | <string name="height_null">Hightはnullです。</string> |
| 162 | <string name="weight_null">重量はnullです。</string> | 162 | <string name="weight_null">重量はnullです。</string> |
| 163 | <string name="body_fat_percent_null">体脂肪率はnullです。</string> | 163 | <string name="body_fat_percent_null">体脂肪率はnullです。</string> |
| 164 | <string name="comment_null">コメントはnullです。</string> | 164 | <string name="comment_null">コメントはnullです。</string> |
| 165 | <string name="level_not_select">レベルは選択されていません。</string> | 165 | <string name="level_not_select">レベルは選択されていません。</string> |
| 166 | <string name="province_not_select">州は選択されていません。</string> | 166 | <string name="province_not_select">州は選択されていません。</string> |
| 167 | 167 | ||
| 168 | <string name="please_input_email">メールを入力してください。</string> | 168 | <string name="please_input_email">メールを入力してください。</string> |
| 169 | <string name="please_input_confirm">確認コードを入力してください。</string> | 169 | <string name="please_input_confirm">確認コードを入力してください。</string> |
| 170 | <string name="send_confirm">送信確認</string> | 170 | <string name="send_confirm">送信確認</string> |
| 171 | 171 | ||
| 172 | <!--string relationship--> | 172 | <!--string relationship--> |
| 173 | <string name="male">男</string> | 173 | <string name="male">男</string> |
| 174 | <string name="female">女</string> | 174 | <string name="female">女</string> |
| 175 | 175 | ||
| 176 | <!--string host family job --> | 176 | <!--string host family job --> |
| 177 | <string name="job1">上場会社役員</string> | 177 | <string name="job1">上場会社役員</string> |
| 178 | <string name="job2">非上場会社役員</string> | 178 | <string name="job2">非上場会社役員</string> |
| 179 | <string name="job3">上場会社幹部社員</string> | 179 | <string name="job3">上場会社幹部社員</string> |
| 180 | <string name="job4">上場会社社員</string> | 180 | <string name="job4">上場会社社員</string> |
| 181 | <string name="job5">非上場会社社員</string> | 181 | <string name="job5">非上場会社社員</string> |
| 182 | <string name="job6">団体の役員</string> | 182 | <string name="job6">団体の役員</string> |
| 183 | <string name="job7">団体の職員</string> | 183 | <string name="job7">団体の職員</string> |
| 184 | <string name="job8">国家公務員</string> | 184 | <string name="job8">国家公務員</string> |
| 185 | <string name="job9">地方公務員</string> | 185 | <string name="job9">地方公務員</string> |
| 186 | <string name="job10">農林水産業</string> | 186 | <string name="job10">農林水産業</string> |
| 187 | <string name="job11">医師その他医療関係</string> | 187 | <string name="job11">医師その他医療関係</string> |
| 188 | <string name="job12">弁護士・会計士・税理士</string> | 188 | <string name="job12">弁護士・会計士・税理士</string> |
| 189 | <string name="job13">教職員</string> | 189 | <string name="job13">教職員</string> |
| 190 | <string name="job14">自営業</string> | 190 | <string name="job14">自営業</string> |
| 191 | <string name="job15">パート・アルバイト</string> | 191 | <string name="job15">パート・アルバイト</string> |
| 192 | <string name="job16">主婦</string> | 192 | <string name="job16">主婦</string> |
| 193 | <string name="job17">学生</string> | 193 | <string name="job17">学生</string> |
| 194 | <string name="job18">無職</string> | 194 | <string name="job18">無職</string> |
| 195 | <string name="job19">その他</string> | 195 | <string name="job19">その他</string> |
| 196 | 196 | ||
| 197 | 197 | ||
| 198 | <string name="tokutei_err_m">特定口座の開設有無をお選びください。</string> | 198 | <string name="tokutei_err_m">特定口座の開設有無をお選びください。</string> |
| 199 | 199 | ||
| 200 | <!--SNS screen--> | 200 | <!--SNS screen--> |
| 201 | <string name="error_empty_text">Empty</string> | 201 | <string name="error_empty_text">Empty</string> |
| 202 | <string name="msg_create_group_title">Create group</string> | 202 | <string name="msg_create_group_title">Create group</string> |
| 203 | <string name="msg_join_group_title">Join group</string> | 203 | <string name="msg_join_group_title">Join group</string> |
| 204 | <string name="msg_create_group_success">Success</string> | 204 | <string name="msg_create_group_success">Success</string> |
| 205 | <string name="msg_create_group_fail">Fail</string> | 205 | <string name="msg_create_group_fail">Fail</string> |
| 206 | <string name="msg_ok">OK</string> | 206 | <string name="msg_ok">OK</string> |
| 207 | <string name="sns_btn_view_member_title">メンバーを見る</string> | 207 | <string name="sns_btn_view_member_title">メンバーを見る</string> |
| 208 | <string name="sns_btn_view_tweet_title">ツイートを見る</string> | 208 | <string name="sns_btn_view_tweet_title">ツイートを見る</string> |
| 209 | <!-- City list --> | 209 | <!-- City list --> |
| 210 | <string name="please_search">検索してください</string> | 210 | <string name="please_search">検索してください</string> |
| 211 | 211 | ||
| 212 | <string name="city_item_1">北海道</string> | 212 | <string name="city_item_1">北海道</string> |
| 213 | <string name="city_item_2">青森県</string> | 213 | <string name="city_item_2">青森県</string> |
| 214 | <string name="city_item_3">岩手県</string> | 214 | <string name="city_item_3">岩手県</string> |
| 215 | <string name="city_item_4">宮城県</string> | 215 | <string name="city_item_4">宮城県</string> |
| 216 | <string name="city_item_5">秋田県</string> | 216 | <string name="city_item_5">秋田県</string> |
| 217 | <string name="city_item_6">山形県</string> | 217 | <string name="city_item_6">山形県</string> |
| 218 | <string name="city_item_7">福島県</string> | 218 | <string name="city_item_7">福島県</string> |
| 219 | <string name="city_item_8">茨城県</string> | 219 | <string name="city_item_8">茨城県</string> |
| 220 | <string name="city_item_9">栃木県</string> | 220 | <string name="city_item_9">栃木県</string> |
| 221 | <string name="city_item_10">群馬県</string> | 221 | <string name="city_item_10">群馬県</string> |
| 222 | <string name="city_item_11">埼玉県</string> | 222 | <string name="city_item_11">埼玉県</string> |
| 223 | <string name="city_item_12">千葉県</string> | 223 | <string name="city_item_12">千葉県</string> |
| 224 | <string name="city_item_13">東京都</string> | 224 | <string name="city_item_13">東京都</string> |
| 225 | <string name="city_item_14">神奈川県</string> | 225 | <string name="city_item_14">神奈川県</string> |
| 226 | <string name="city_item_15">新潟県</string> | 226 | <string name="city_item_15">新潟県</string> |
| 227 | <string name="city_item_16">富山県</string> | 227 | <string name="city_item_16">富山県</string> |
| 228 | <string name="city_item_17">石川県</string> | 228 | <string name="city_item_17">石川県</string> |
| 229 | <string name="city_item_18">福井県</string> | 229 | <string name="city_item_18">福井県</string> |
| 230 | <string name="city_item_19">山梨県</string> | 230 | <string name="city_item_19">山梨県</string> |
| 231 | <string name="city_item_20">長野県</string> | 231 | <string name="city_item_20">長野県</string> |
| 232 | <string name="city_item_21">岐阜県</string> | 232 | <string name="city_item_21">岐阜県</string> |
| 233 | <string name="city_item_22">静岡県</string> | 233 | <string name="city_item_22">静岡県</string> |
| 234 | <string name="city_item_23">愛知県</string> | 234 | <string name="city_item_23">愛知県</string> |
| 235 | <string name="city_item_24">三重県</string> | 235 | <string name="city_item_24">三重県</string> |
| 236 | <string name="city_item_25">滋賀県</string> | 236 | <string name="city_item_25">滋賀県</string> |
| 237 | <string name="city_item_26">京都府</string> | 237 | <string name="city_item_26">京都府</string> |
| 238 | <string name="city_item_27">大阪府</string> | 238 | <string name="city_item_27">大阪府</string> |
| 239 | <string name="city_item_28">兵庫県</string> | 239 | <string name="city_item_28">兵庫県</string> |
| 240 | <string name="city_item_29">奈良県</string> | 240 | <string name="city_item_29">奈良県</string> |
| 241 | <string name="city_item_30">和歌山県</string> | 241 | <string name="city_item_30">和歌山県</string> |
| 242 | <string name="city_item_31">鳥取県</string> | 242 | <string name="city_item_31">鳥取県</string> |
| 243 | <string name="city_item_32">島根県</string> | 243 | <string name="city_item_32">島根県</string> |
| 244 | <string name="city_item_33">岡山県</string> | 244 | <string name="city_item_33">岡山県</string> |
| 245 | <string name="city_item_34">広島県</string> | 245 | <string name="city_item_34">広島県</string> |
| 246 | <string name="city_item_35">山口県</string> | 246 | <string name="city_item_35">山口県</string> |
| 247 | <string name="city_item_36">徳島県</string> | 247 | <string name="city_item_36">徳島県</string> |
| 248 | <string name="city_item_37">香川県</string> | 248 | <string name="city_item_37">香川県</string> |
| 249 | <string name="city_item_38">愛媛県</string> | 249 | <string name="city_item_38">愛媛県</string> |
| 250 | <string name="city_item_39">高知県</string> | 250 | <string name="city_item_39">高知県</string> |
| 251 | <string name="city_item_40">福岡県</string> | 251 | <string name="city_item_40">福岡県</string> |
| 252 | <string name="city_item_41">佐賀県</string> | 252 | <string name="city_item_41">佐賀県</string> |
| 253 | <string name="city_item_42">長崎県</string> | 253 | <string name="city_item_42">長崎県</string> |
| 254 | <string name="city_item_43">熊本県</string> | 254 | <string name="city_item_43">熊本県</string> |
| 255 | <string name="city_item_44">大分県</string> | 255 | <string name="city_item_44">大分県</string> |
| 256 | <string name="city_item_45">宮崎県</string> | 256 | <string name="city_item_45">宮崎県</string> |
| 257 | <string name="city_item_46">鹿児島県</string> | 257 | <string name="city_item_46">鹿児島県</string> |
| 258 | <string name="city_item_47">沖縄県</string> | 258 | <string name="city_item_47">沖縄県</string> |
| 259 | 259 | ||
| 260 | <string name="one_day">1日</string> | 260 | <string name="one_day">1日</string> |
| 261 | <string name="one_week">1週間</string> | 261 | <string name="one_week">1週間</string> |
| 262 | <string name="one_month">1ヶ月</string> | 262 | <string name="one_month">1ヶ月</string> |
| 263 | <string name="three_month">3ヶ月</string> | 263 | <string name="three_month">3ヶ月</string> |
| 264 | <string name="six_month">6ヶ月</string> | 264 | <string name="six_month">6ヶ月</string> |
| 265 | <string name="calo_consume">消費カロリー</string> | 265 | <string name="calo_consume">消費カロリー</string> |
| 266 | <string name="distance">距離</string> | 266 | <string name="distance">距離</string> |
| 267 | 267 | ||
| 268 | <string name="sunday">日曜日</string> | 268 | <string name="sunday">日曜日</string> |
| 269 | <string name="monday">月曜日</string> | 269 | <string name="monday">月曜日</string> |
| 270 | <string name="tuesday">火曜日</string> | 270 | <string name="tuesday">火曜日</string> |
| 271 | <string name="wednesday">水曜日</string> | 271 | <string name="wednesday">水曜日</string> |
| 272 | <string name="thursday">木曜日</string> | 272 | <string name="thursday">木曜日</string> |
| 273 | <string name="friday">金曜日</string> | 273 | <string name="friday">金曜日</string> |
| 274 | <string name="saturday">土曜日</string> | 274 | <string name="saturday">土曜日</string> |
| 275 | 275 | ||
| 276 | <string name="facebook">facebook</string> | 276 | <string name="facebook">facebook</string> |
| 277 | <string name="twitter">twitter</string> | 277 | <string name="twitter">twitter</string> |
| 278 | <string name="line">line</string> | 278 | <string name="line">line</string> |
| 279 | <string name="mail">メール</string> | 279 | <string name="mail">メール</string> |
| 280 | <string name="other">その他</string> | 280 | <string name="other">その他</string> |
| 281 | <string name="kcal">kcal</string> | 281 | <string name="kcal">kcal</string> |
| 282 | <string name="favorable">好調</string> | 282 | <string name="favorable">好調</string> |
| 283 | <string name="little_more">もう少し</string> | 283 | <string name="little_more">もう少し</string> |
| 284 | 284 | ||
| 285 | <string name="mon">(月)</string> | 285 | <string name="mon">(月)</string> |
| 286 | <string name="tues">(火)</string> | 286 | <string name="tues">(火)</string> |
| 287 | <string name="wed">(水)</string> | 287 | <string name="wed">(水)</string> |
| 288 | <string name="thus">(木)</string> | 288 | <string name="thus">(木)</string> |
| 289 | <string name="fir">(金)</string> | 289 | <string name="fir">(金)</string> |
| 290 | <string name="sat">(土)</string> | 290 | <string name="sat">(土)</string> |
| 291 | <string name="sun">(日)</string> | 291 | <string name="sun">(日)</string> |
| 292 | 292 | ||
| 293 | <string name="weather">天気</string> | 293 | <string name="weather">天気</string> |
| 294 | 294 | ||
| 295 | <string name="calo_consumed">消費カロリー</string> | 295 | <string name="calo_consumed">消費カロリー</string> |
| 296 | <string name="can_not_get_data">データを取得できません。</string> | 296 | <string name="can_not_get_data">データを取得できません。</string> |
| 297 | <string name="loading">読み込み中</string> | 297 | <string name="loading">読み込み中</string> |
| 298 | 298 | ||
| 299 | <string name="sensor_available">カウントセンサーが使用できません。</string> | ||
| 300 | |||
| 299 | <string name="sensor_available">カウントセンサーが使用できません。</string> | 301 | </resources> |