Commit 54e5fcd562171a4e4441eb6eb480c2f5a558835f
1 parent
c25bb19fce
Exists in
master
and in
1 other branch
handle top api
Showing 8 changed files with 291 additions and 266 deletions Side-by-side 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/res/layout/fragment_top.xml
- app/src/main/res/values/strings.xml
app/src/main/java/com/dinhcv/lifelogpedometer/activity/DateFragment.java
| ... | ... | @@ -4,6 +4,10 @@ |
| 4 | 4 | import android.content.Context; |
| 5 | 5 | import android.content.Intent; |
| 6 | 6 | import android.content.SharedPreferences; |
| 7 | +import android.hardware.Sensor; | |
| 8 | +import android.hardware.SensorEvent; | |
| 9 | +import android.hardware.SensorEventListener; | |
| 10 | +import android.hardware.SensorManager; | |
| 7 | 11 | import android.os.Bundle; |
| 8 | 12 | import android.support.annotation.Nullable; |
| 9 | 13 | import android.support.v4.app.Fragment; |
| ... | ... | @@ -14,6 +18,7 @@ |
| 14 | 18 | import android.widget.ImageView; |
| 15 | 19 | import android.widget.LinearLayout; |
| 16 | 20 | import android.widget.TextView; |
| 21 | +import android.widget.Toast; | |
| 17 | 22 | |
| 18 | 23 | import com.dinhcv.lifelogpedometer.R; |
| 19 | 24 | import com.dinhcv.lifelogpedometer.adapter.NoticeAdapter; |
| 20 | 25 | |
| ... | ... | @@ -280,14 +285,13 @@ |
| 280 | 285 | mTagetInfo = new TagetInfo();; |
| 281 | 286 | } |
| 282 | 287 | |
| 283 | - updateUI(); | |
| 288 | + loadUI(); | |
| 284 | 289 | } |
| 285 | 290 | |
| 286 | 291 | |
| 287 | - private void updateUI(){ | |
| 288 | - | |
| 289 | - tvStep.setText(mTagetInfo.getSteps()); | |
| 290 | - tvRemain.setText(mTagetInfo.getStepRemain()); | |
| 292 | + private void loadUI(){ | |
| 293 | + tvStep.setText(String.valueOf(mTagetInfo.getSteps())); | |
| 294 | + tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); | |
| 291 | 295 | tvRateDone.setText(getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); |
| 292 | 296 | |
| 293 | 297 | List<NoticeInfo> infoLists = mTagetInfo.getNoticeList(); |
| ... | ... | @@ -334,5 +338,6 @@ |
| 334 | 338 | super.onActivityResult(requestCode, resultCode, data); |
| 335 | 339 | |
| 336 | 340 | } |
| 341 | + | |
| 337 | 342 | } |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/MainActivity.java
| 1 | -package com.dinhcv.lifelogpedometer.activity; | |
| 2 | - | |
| 3 | -import android.hardware.Sensor; | |
| 4 | -import android.hardware.SensorEvent; | |
| 5 | -import android.hardware.SensorEventListener; | |
| 6 | -import android.hardware.SensorManager; | |
| 7 | -import android.support.v7.app.AppCompatActivity; | |
| 8 | -import android.os.Bundle; | |
| 9 | -import android.view.View; | |
| 10 | -import android.widget.Button; | |
| 11 | -import android.widget.TextView; | |
| 12 | - | |
| 13 | -import com.dinhcv.lifelogpedometer.R; | |
| 14 | - | |
| 15 | -public class MainActivity extends AppCompatActivity implements SensorEventListener, StepListener { | |
| 16 | - private TextView tvSteps; | |
| 17 | - private Button btnStart; | |
| 18 | - private Button btnStop; | |
| 19 | - private StepDetector simpleStepDetector; | |
| 20 | - private SensorManager sensorManager; | |
| 21 | - private Sensor accel; | |
| 22 | - private static final String TEXT_NUM_STEPS = "Number of Steps: "; | |
| 23 | - private int numSteps; | |
| 24 | - | |
| 25 | - @Override | |
| 26 | - protected void onCreate(Bundle savedInstanceState) { | |
| 27 | - super.onCreate(savedInstanceState); | |
| 28 | - setContentView(R.layout.activity_main); | |
| 29 | - | |
| 30 | - | |
| 31 | - // Get an instance of the SensorManager | |
| 32 | - sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); | |
| 33 | - accel = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); | |
| 34 | - simpleStepDetector = new StepDetector(); | |
| 35 | - simpleStepDetector.registerListener(this); | |
| 36 | - | |
| 37 | - tvSteps = (TextView) findViewById(R.id.tv_steps); | |
| 38 | - btnStart = (Button) findViewById(R.id.btn_start); | |
| 39 | - btnStop = (Button) findViewById(R.id.btn_stop); | |
| 40 | - | |
| 41 | - | |
| 42 | - | |
| 43 | - btnStart.setOnClickListener(new View.OnClickListener() { | |
| 44 | - | |
| 45 | - @Override | |
| 46 | - public void onClick(View arg0) { | |
| 47 | - | |
| 48 | - numSteps = 0; | |
| 49 | - sensorManager.registerListener(MainActivity.this, accel, SensorManager.SENSOR_DELAY_FASTEST); | |
| 50 | - | |
| 51 | - } | |
| 52 | - }); | |
| 53 | - | |
| 54 | - | |
| 55 | - btnStop.setOnClickListener(new View.OnClickListener() { | |
| 56 | - | |
| 57 | - @Override | |
| 58 | - public void onClick(View arg0) { | |
| 59 | - | |
| 60 | - sensorManager.unregisterListener(MainActivity.this); | |
| 61 | - | |
| 62 | - } | |
| 63 | - }); | |
| 64 | - } | |
| 65 | - | |
| 66 | - | |
| 67 | - | |
| 68 | - @Override | |
| 69 | - public void onAccuracyChanged(Sensor sensor, int accuracy) { | |
| 70 | - } | |
| 71 | - | |
| 72 | - @Override | |
| 73 | - public void onSensorChanged(SensorEvent event) { | |
| 74 | - if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { | |
| 75 | - simpleStepDetector.updateAccel( | |
| 76 | - event.timestamp, event.values[0], event.values[1], event.values[2]); | |
| 77 | - } | |
| 78 | - } | |
| 79 | - | |
| 80 | - @Override | |
| 81 | - public void step(long timeNs) { | |
| 82 | - numSteps++; | |
| 83 | - tvSteps.setText(TEXT_NUM_STEPS + numSteps); | |
| 84 | - } | |
| 85 | - | |
| 86 | -} |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/SensorFilter.java
| 1 | -package com.dinhcv.lifelogpedometer.activity; | |
| 2 | - | |
| 3 | -public class SensorFilter { | |
| 4 | - | |
| 5 | - private SensorFilter() { | |
| 6 | - } | |
| 7 | - | |
| 8 | - public static float sum(float[] array) { | |
| 9 | - float retval = 0; | |
| 10 | - for (int i = 0; i < array.length; i++) { | |
| 11 | - retval += array[i]; | |
| 12 | - } | |
| 13 | - return retval; | |
| 14 | - } | |
| 15 | - | |
| 16 | - public static float[] cross(float[] arrayA, float[] arrayB) { | |
| 17 | - float[] retArray = new float[3]; | |
| 18 | - retArray[0] = arrayA[1] * arrayB[2] - arrayA[2] * arrayB[1]; | |
| 19 | - retArray[1] = arrayA[2] * arrayB[0] - arrayA[0] * arrayB[2]; | |
| 20 | - retArray[2] = arrayA[0] * arrayB[1] - arrayA[1] * arrayB[0]; | |
| 21 | - return retArray; | |
| 22 | - } | |
| 23 | - | |
| 24 | - public static float norm(float[] array) { | |
| 25 | - float retval = 0; | |
| 26 | - for (int i = 0; i < array.length; i++) { | |
| 27 | - retval += array[i] * array[i]; | |
| 28 | - } | |
| 29 | - return (float) Math.sqrt(retval); | |
| 30 | - } | |
| 31 | - | |
| 32 | - | |
| 33 | - public static float dot(float[] a, float[] b) { | |
| 34 | - float retval = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; | |
| 35 | - return retval; | |
| 36 | - } | |
| 37 | - | |
| 38 | - public static float[] normalize(float[] a) { | |
| 39 | - float[] retval = new float[a.length]; | |
| 40 | - float norm = norm(a); | |
| 41 | - for (int i = 0; i < a.length; i++) { | |
| 42 | - retval[i] = a[i] / norm; | |
| 43 | - } | |
| 44 | - return retval; | |
| 45 | - } | |
| 46 | - | |
| 47 | -} |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/StepDetector.java
| 1 | -package com.dinhcv.lifelogpedometer.activity; | |
| 2 | - | |
| 3 | -public class StepDetector { | |
| 4 | - | |
| 5 | - private static final int ACCEL_RING_SIZE = 50; | |
| 6 | - private static final int VEL_RING_SIZE = 10; | |
| 7 | - | |
| 8 | - // change this threshold according to your sensitivity preferences | |
| 9 | - private static final float STEP_THRESHOLD = 50f; | |
| 10 | - | |
| 11 | - private static final int STEP_DELAY_NS = 250000000; | |
| 12 | - | |
| 13 | - private int accelRingCounter = 0; | |
| 14 | - private float[] accelRingX = new float[ACCEL_RING_SIZE]; | |
| 15 | - private float[] accelRingY = new float[ACCEL_RING_SIZE]; | |
| 16 | - private float[] accelRingZ = new float[ACCEL_RING_SIZE]; | |
| 17 | - private int velRingCounter = 0; | |
| 18 | - private float[] velRing = new float[VEL_RING_SIZE]; | |
| 19 | - private long lastStepTimeNs = 0; | |
| 20 | - private float oldVelocityEstimate = 0; | |
| 21 | - | |
| 22 | - private StepListener listener; | |
| 23 | - | |
| 24 | - public void registerListener(StepListener listener) { | |
| 25 | - this.listener = listener; | |
| 26 | - } | |
| 27 | - | |
| 28 | - | |
| 29 | - public void updateAccel(long timeNs, float x, float y, float z) { | |
| 30 | - float[] currentAccel = new float[3]; | |
| 31 | - currentAccel[0] = x; | |
| 32 | - currentAccel[1] = y; | |
| 33 | - currentAccel[2] = z; | |
| 34 | - | |
| 35 | - // First step is to update our guess of where the global z vector is. | |
| 36 | - accelRingCounter++; | |
| 37 | - accelRingX[accelRingCounter % ACCEL_RING_SIZE] = currentAccel[0]; | |
| 38 | - accelRingY[accelRingCounter % ACCEL_RING_SIZE] = currentAccel[1]; | |
| 39 | - accelRingZ[accelRingCounter % ACCEL_RING_SIZE] = currentAccel[2]; | |
| 40 | - | |
| 41 | - float[] worldZ = new float[3]; | |
| 42 | - worldZ[0] = SensorFilter.sum(accelRingX) / Math.min(accelRingCounter, ACCEL_RING_SIZE); | |
| 43 | - worldZ[1] = SensorFilter.sum(accelRingY) / Math.min(accelRingCounter, ACCEL_RING_SIZE); | |
| 44 | - worldZ[2] = SensorFilter.sum(accelRingZ) / Math.min(accelRingCounter, ACCEL_RING_SIZE); | |
| 45 | - | |
| 46 | - float normalization_factor = SensorFilter.norm(worldZ); | |
| 47 | - | |
| 48 | - worldZ[0] = worldZ[0] / normalization_factor; | |
| 49 | - worldZ[1] = worldZ[1] / normalization_factor; | |
| 50 | - worldZ[2] = worldZ[2] / normalization_factor; | |
| 51 | - | |
| 52 | - float currentZ = SensorFilter.dot(worldZ, currentAccel) - normalization_factor; | |
| 53 | - velRingCounter++; | |
| 54 | - velRing[velRingCounter % VEL_RING_SIZE] = currentZ; | |
| 55 | - | |
| 56 | - float velocityEstimate = SensorFilter.sum(velRing); | |
| 57 | - | |
| 58 | - if (velocityEstimate > STEP_THRESHOLD && oldVelocityEstimate <= STEP_THRESHOLD | |
| 59 | - && (timeNs - lastStepTimeNs > STEP_DELAY_NS)) { | |
| 60 | - listener.step(timeNs); | |
| 61 | - lastStepTimeNs = timeNs; | |
| 62 | - } | |
| 63 | - oldVelocityEstimate = velocityEstimate; | |
| 64 | - } | |
| 65 | -} |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/StepListener.java
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
| ... | ... | @@ -3,6 +3,10 @@ |
| 3 | 3 | import android.app.DatePickerDialog; |
| 4 | 4 | import android.content.Context; |
| 5 | 5 | import android.graphics.Color; |
| 6 | +import android.hardware.Sensor; | |
| 7 | +import android.hardware.SensorEvent; | |
| 8 | +import android.hardware.SensorEventListener; | |
| 9 | +import android.hardware.SensorManager; | |
| 6 | 10 | import android.os.Bundle; |
| 7 | 11 | import android.support.annotation.Nullable; |
| 8 | 12 | import android.util.Pair; |
| 9 | 13 | |
| 10 | 14 | |
| 11 | 15 | |
| 12 | 16 | |
| ... | ... | @@ -13,13 +17,18 @@ |
| 13 | 17 | import android.view.ViewGroup; |
| 14 | 18 | import android.widget.DatePicker; |
| 15 | 19 | import android.widget.ImageView; |
| 20 | +import android.widget.LinearLayout; | |
| 16 | 21 | import android.widget.TextView; |
| 22 | +import android.widget.Toast; | |
| 17 | 23 | |
| 18 | 24 | import com.dinhcv.lifelogpedometer.R; |
| 19 | 25 | import com.dinhcv.lifelogpedometer.feature.Database; |
| 26 | +import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | |
| 20 | 27 | import com.dinhcv.lifelogpedometer.model.StepModel; |
| 28 | +import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | |
| 21 | 29 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 22 | 30 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; |
| 31 | +import com.dinhcv.lifelogpedometer.utils.Debug; | |
| 23 | 32 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 24 | 33 | import com.github.mikephil.charting.components.XAxis; |
| 25 | 34 | import com.github.mikephil.charting.components.YAxis; |
| ... | ... | @@ -32,6 +41,8 @@ |
| 32 | 41 | |
| 33 | 42 | import org.eazegraph.lib.charts.PieChart; |
| 34 | 43 | import org.eazegraph.lib.models.PieModel; |
| 44 | +import org.json.JSONArray; | |
| 45 | +import org.json.JSONObject; | |
| 35 | 46 | |
| 36 | 47 | import java.text.NumberFormat; |
| 37 | 48 | import java.util.ArrayList; |
| 38 | 49 | |
| ... | ... | @@ -43,9 +54,10 @@ |
| 43 | 54 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; |
| 44 | 55 | |
| 45 | 56 | |
| 46 | -public class TopFragment extends FragmentBase implements SettingFragmentPresenter { | |
| 57 | +public class TopFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { | |
| 47 | 58 | |
| 48 | 59 | private TextView stepsView; |
| 60 | + private TextView tvStepGoal; | |
| 49 | 61 | private TextView tvDistance; |
| 50 | 62 | private TextView tvStepRemain; |
| 51 | 63 | private TextView tvStepRateDone; |
| ... | ... | @@ -57,6 +69,10 @@ |
| 57 | 69 | private ImageView ivNext; |
| 58 | 70 | private ImageView ivPlay; |
| 59 | 71 | |
| 72 | + private LinearLayout llBike; | |
| 73 | + private LinearLayout llWalking; | |
| 74 | + private LinearLayout llRunning; | |
| 75 | + private Const.STEP_TYPE stepType; | |
| 60 | 76 | |
| 61 | 77 | private Date mAnaDate; |
| 62 | 78 | private Calendar mCalendar; |
| 63 | 79 | |
| 64 | 80 | |
| 65 | 81 | |
| ... | ... | @@ -65,12 +81,24 @@ |
| 65 | 81 | private int mAnaMonth; |
| 66 | 82 | private int mAnaYear; |
| 67 | 83 | |
| 68 | - private int todayOffset, total_start, since_boot; | |
| 69 | - public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); | |
| 70 | 84 | public static int STEP_SIZE = 75; |
| 71 | 85 | private StepModel mStepModel; |
| 86 | + private TextView tvSmallStepGoal; | |
| 72 | 87 | private TextView tvSmallRemain; |
| 88 | + private Context mContext; | |
| 73 | 89 | |
| 90 | + private SensorManager sensorManager; | |
| 91 | + private boolean activityRunning; | |
| 92 | + private int stepTotal = 0; | |
| 93 | + private int stepRemain = 0; | |
| 94 | + private int stepCount = 0; | |
| 95 | + | |
| 96 | + private BarChart mChart; | |
| 97 | + | |
| 98 | + private List<String> dateList; | |
| 99 | + private String[] mParties; | |
| 100 | + private Integer[] mStep; | |
| 101 | + | |
| 74 | 102 | @Override |
| 75 | 103 | public void onCreate(final Bundle savedInstanceState) { |
| 76 | 104 | super.onCreate(savedInstanceState); |
| 77 | 105 | |
| ... | ... | @@ -80,19 +108,11 @@ |
| 80 | 108 | @Override |
| 81 | 109 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 82 | 110 | final Bundle savedInstanceState) { |
| 83 | - final View v = inflater.inflate(com.dinhcv.lifelogpedometer.R.layout.fragment_top, null); | |
| 84 | - stepsView = (TextView) v.findViewById(R.id.steps); | |
| 85 | - tvDistance = (TextView) v.findViewById(R.id.tv_distance); | |
| 86 | - tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); | |
| 87 | - tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); | |
| 88 | - tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); | |
| 89 | - tvDate = (TextView) v.findViewById(R.id.tv_date); | |
| 90 | - ivBack = (ImageView) v.findViewById(R.id.iv_back); | |
| 91 | - ivNext = (ImageView) v.findViewById(R.id.iv_next); | |
| 92 | - ivPlay = (ImageView) v.findViewById(R.id.iv_play); | |
| 111 | + final View v = inflater.inflate(R.layout.fragment_top, null); | |
| 112 | + mContext = getActivity(); | |
| 113 | + sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); | |
| 93 | 114 | |
| 94 | - mChart = (BarChart) v.findViewById(R.id.chart); | |
| 95 | - pg = (PieChart) v.findViewById(R.id.graph); | |
| 115 | + initView(v); | |
| 96 | 116 | |
| 97 | 117 | // slice for the steps taken today |
| 98 | 118 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); |
| ... | ... | @@ -120,6 +140,23 @@ |
| 120 | 140 | return v; |
| 121 | 141 | } |
| 122 | 142 | |
| 143 | + private void initView(View v){ | |
| 144 | + stepsView = (TextView) v.findViewById(R.id.steps); | |
| 145 | + tvDistance = (TextView) v.findViewById(R.id.tv_distance); | |
| 146 | + tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); | |
| 147 | + tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); | |
| 148 | + tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); | |
| 149 | + tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); | |
| 150 | + tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); | |
| 151 | + tvDate = (TextView) v.findViewById(R.id.tv_date); | |
| 152 | + ivBack = (ImageView) v.findViewById(R.id.iv_back); | |
| 153 | + ivNext = (ImageView) v.findViewById(R.id.iv_next); | |
| 154 | + ivPlay = (ImageView) v.findViewById(R.id.iv_play); | |
| 155 | + | |
| 156 | + mChart = (BarChart) v.findViewById(R.id.chart); | |
| 157 | + pg = (PieChart) v.findViewById(R.id.graph); | |
| 158 | + } | |
| 159 | + | |
| 123 | 160 | private void stepsDistanceChanged() { |
| 124 | 161 | updatePie(); |
| 125 | 162 | updateBars(); |
| 126 | 163 | |
| ... | ... | @@ -187,12 +224,7 @@ |
| 187 | 224 | initGraph(); |
| 188 | 225 | } |
| 189 | 226 | |
| 190 | - private BarChart mChart; | |
| 191 | 227 | |
| 192 | - private List<String> dateList; | |
| 193 | - private String[] mParties; | |
| 194 | - private Integer[] mStep; | |
| 195 | - | |
| 196 | 228 | private void initGraph(){ |
| 197 | 229 | |
| 198 | 230 | mChart.setDrawBarShadow(false); |
| 199 | 231 | |
| 200 | 232 | |
| 201 | 233 | |
| ... | ... | @@ -321,10 +353,46 @@ |
| 321 | 353 | } |
| 322 | 354 | }); |
| 323 | 355 | |
| 356 | + llWalking.setOnClickListener(new View.OnClickListener() { | |
| 357 | + @Override | |
| 358 | + public void onClick(View view) { | |
| 359 | + stepType = Const.STEP_TYPE.WALKING; | |
| 360 | + updateUiStepType(false, true, false); | |
| 361 | + // add data | |
| 362 | + getTopData(mAnaDate, stepType); | |
| 363 | + } | |
| 364 | + }); | |
| 324 | 365 | |
| 366 | + llRunning.setOnClickListener(new View.OnClickListener() { | |
| 367 | + @Override | |
| 368 | + public void onClick(View view) { | |
| 369 | + stepType = Const.STEP_TYPE.RUNNING; | |
| 370 | + updateUiStepType(false, false, true); | |
| 371 | + // add | |
| 372 | + getTopData(mAnaDate, stepType); | |
| 373 | + } | |
| 374 | + }); | |
| 375 | + | |
| 376 | + llBike.setOnClickListener(new View.OnClickListener() { | |
| 377 | + @Override | |
| 378 | + public void onClick(View view) { | |
| 379 | + stepType = Const.STEP_TYPE.BIKE; | |
| 380 | + updateUiStepType(true, false, false); | |
| 381 | + // add data | |
| 382 | + getTopData(mAnaDate, stepType); | |
| 383 | + } | |
| 384 | + }); | |
| 385 | + | |
| 386 | + | |
| 325 | 387 | } |
| 326 | 388 | |
| 389 | + private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | |
| 390 | + llBike.setSelected(b1); | |
| 391 | + llWalking.setSelected(b2); | |
| 392 | + llRunning.setSelected(b3); | |
| 393 | + } | |
| 327 | 394 | |
| 395 | + | |
| 328 | 396 | /** |
| 329 | 397 | * Show date picker dialog |
| 330 | 398 | */ |
| 331 | 399 | |
| 332 | 400 | |
| ... | ... | @@ -347,8 +415,101 @@ |
| 347 | 415 | |
| 348 | 416 | } |
| 349 | 417 | |
| 418 | + private void getTopData(Date date, Const.STEP_TYPE stepType){ | |
| 350 | 419 | |
| 420 | + showDialog(mContext); | |
| 421 | + LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() { | |
| 422 | + @Override | |
| 423 | + public void onError(Error error) { | |
| 424 | + Debug.error("Get data history error"); | |
| 425 | + hiddenDialog(); | |
| 426 | + showDialogNotData(); | |
| 427 | + } | |
| 351 | 428 | |
| 429 | + @Override | |
| 430 | + public void onSuccess(String json) { | |
| 431 | + Debug.error("Get data history success"); | |
| 432 | + hiddenDialog(); | |
| 433 | + loadDataDone(json); | |
| 434 | + } | |
| 435 | + | |
| 436 | + @Override | |
| 437 | + public void onSuccess(JSONObject object) { | |
| 438 | + Debug.error("Get data history success"); | |
| 439 | + hiddenDialog(); | |
| 440 | + } | |
| 441 | + }); | |
| 442 | + } | |
| 443 | + | |
| 444 | + private void showDialogNotData(){ | |
| 445 | + showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | |
| 446 | + } | |
| 447 | + | |
| 448 | + private void loadDataDone(String jsonString) { | |
| 449 | + JSONObject jsonObject = null; | |
| 450 | + try { | |
| 451 | + jsonObject = new JSONObject(jsonString); | |
| 452 | + int status = jsonObject.optInt("status"); | |
| 453 | + if (status == 1) { | |
| 454 | + JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | |
| 455 | + JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); | |
| 456 | + JSONArray listNotice = jsonObject1.getJSONArray("listNotice"); | |
| 457 | + | |
| 458 | + if (targetInf != null){ | |
| 459 | + String target = targetInf.optString("target_step"); | |
| 460 | + Debug.normal("Target: "+ target); | |
| 461 | + mTagetInfo.setTaget(targetInf.optString("target_step")); | |
| 462 | + mTagetInfo.setSteps(targetInf.optString("num_step")); | |
| 463 | + mTagetInfo.setStepRemain(targetInf.optString("remaining_step")); | |
| 464 | + mTagetInfo.setCompletePercent(targetInf.optString("complete_percent")); | |
| 465 | + } | |
| 466 | + | |
| 467 | + if (listNotice != null && listNotice.length() > 0) { | |
| 468 | + List<NoticeInfo> infoLists = new ArrayList<>(); | |
| 469 | + for (int i = 0; i < listNotice.length(); i++){ | |
| 470 | + NoticeInfo noticeInfo = new NoticeInfo(); | |
| 471 | + JSONObject ob = (JSONObject) listNotice.get(i); | |
| 472 | + noticeInfo.setId(ob.optInt("id")); | |
| 473 | + noticeInfo.setContent(ob.optString("notice_content")); | |
| 474 | + infoLists.add(noticeInfo); | |
| 475 | + } | |
| 476 | + | |
| 477 | + mTagetInfo.setNoticeList(infoLists); | |
| 478 | + } | |
| 479 | + | |
| 480 | + } | |
| 481 | + } catch (JSONException e) { | |
| 482 | + e.printStackTrace(); | |
| 483 | + mTagetInfo = new TagetInfo();; | |
| 484 | + } | |
| 485 | + | |
| 486 | + loadUI(); | |
| 487 | + } | |
| 488 | + | |
| 489 | + | |
| 490 | + private void loadUI(){ | |
| 491 | + tvStep.setText(String.valueOf(mTagetInfo.getSteps())); | |
| 492 | + tvRemain.setText(String.valueOf(mTagetInfo.getStepRemain())); | |
| 493 | + tvRateDone.setText(getResources().getString(R.string.percent_unit, mTagetInfo.getCompletePercent())); | |
| 494 | + | |
| 495 | + List<NoticeInfo> infoLists = mTagetInfo.getNoticeList(); | |
| 496 | + if (infoLists != null && infoLists.size() >0){ | |
| 497 | + mNoticeAdapter = new NoticeAdapter(mContext, infoLists); | |
| 498 | + lvNotice.setAdapter(mNoticeAdapter); | |
| 499 | + lvNotice.setExpanded(true); | |
| 500 | + } | |
| 501 | + | |
| 502 | + } | |
| 503 | + | |
| 504 | + private void updateUI(){ | |
| 505 | + stepTotal = stepTotal + stepCount; | |
| 506 | + stepRemain = stepRemain - stepCount; | |
| 507 | + double percentDone = stepTotal *100.0 / (stepTotal + stepRemain); | |
| 508 | + tvStep.setText(String.valueOf(stepTotal)); | |
| 509 | + tvRemain.setText(mTagetInfo.getStepRemain()); | |
| 510 | + tvRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone))); | |
| 511 | + } | |
| 512 | + | |
| 352 | 513 | @Override |
| 353 | 514 | public void onAttach(Context context) { |
| 354 | 515 | super.onAttach(context); |
| ... | ... | @@ -374,6 +535,68 @@ |
| 374 | 535 | super.onViewStateRestored(savedInstanceState); |
| 375 | 536 | |
| 376 | 537 | initData(); |
| 538 | + } | |
| 539 | + | |
| 540 | + | |
| 541 | + @Override | |
| 542 | + public void onResume() { | |
| 543 | + super.onResume(); | |
| 544 | + activityRunning = true; | |
| 545 | + Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); | |
| 546 | + if (countSensor != null) { | |
| 547 | + sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); | |
| 548 | + } else { | |
| 549 | + Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show(); | |
| 550 | + } | |
| 551 | + } | |
| 552 | + | |
| 553 | + @Override | |
| 554 | + public void onSensorChanged(SensorEvent event) { | |
| 555 | + if (activityRunning){ | |
| 556 | + stepCount = (int) event.values[0]; | |
| 557 | + // update UI | |
| 558 | + updateUI(); | |
| 559 | + } | |
| 560 | + } | |
| 561 | + | |
| 562 | + @Override | |
| 563 | + public void onAccuracyChanged(Sensor sensor, int accuracy) { | |
| 564 | + | |
| 565 | + } | |
| 566 | + | |
| 567 | + @Override | |
| 568 | + public void onPause() { | |
| 569 | + super.onPause(); | |
| 570 | + activityRunning = false; | |
| 571 | + } | |
| 572 | + | |
| 573 | + @Override | |
| 574 | + public void onDestroy() { | |
| 575 | + super.onDestroy(); | |
| 576 | + | |
| 577 | + | |
| 578 | + } | |
| 579 | + | |
| 580 | + private void creatLogStep(Date date, Const.STEP_TYPE stepType){ | |
| 581 | + | |
| 582 | + LLAPIManager.homePage(date, stepType, new LLAPIManagerListener() { | |
| 583 | + @Override | |
| 584 | + public void onError(Error error) { | |
| 585 | + Debug.error("Get data history error"); | |
| 586 | + } | |
| 587 | + | |
| 588 | + @Override | |
| 589 | + public void onSuccess(String json) { | |
| 590 | + Debug.error("Get data history success"); | |
| 591 | + hiddenDialog(); | |
| 592 | + loadDataDone(json); | |
| 593 | + } | |
| 594 | + | |
| 595 | + @Override | |
| 596 | + public void onSuccess(JSONObject object) { | |
| 597 | + Debug.error("Get data history success"); | |
| 598 | + } | |
| 599 | + }); | |
| 377 | 600 | } |
| 378 | 601 | |
| 379 | 602 | } |
app/src/main/res/layout/fragment_top.xml
| ... | ... | @@ -124,6 +124,7 @@ |
| 124 | 124 | android:textColor="@color/white"/> |
| 125 | 125 | |
| 126 | 126 | <TextView |
| 127 | + android:id="@+id/tv_smallStepGoal" | |
| 127 | 128 | android:layout_width="wrap_content" |
| 128 | 129 | android:layout_height="wrap_content" |
| 129 | 130 | android:text="@string/pie_text_content1" |
| ... | ... | @@ -269,6 +270,7 @@ |
| 269 | 270 | android:orientation="vertical"> |
| 270 | 271 | |
| 271 | 272 | <TextView |
| 273 | + android:id="@+id/tv_time" | |
| 272 | 274 | android:layout_width="wrap_content" |
| 273 | 275 | android:layout_height="wrap_content" |
| 274 | 276 | android:text="1:09" |
| ... | ... | @@ -335,7 +337,6 @@ |
| 335 | 337 | android:orientation="vertical"> |
| 336 | 338 | |
| 337 | 339 | <TextView |
| 338 | - android:id="@+id/tv_remainingStep" | |
| 339 | 340 | android:layout_width="wrap_content" |
| 340 | 341 | android:layout_height="wrap_content" |
| 341 | 342 | android:text="@string/km" |
| ... | ... | @@ -352,7 +353,6 @@ |
| 352 | 353 | android:orientation="vertical"> |
| 353 | 354 | |
| 354 | 355 | <TextView |
| 355 | - android:id="@+id/tv_time" | |
| 356 | 356 | android:layout_width="wrap_content" |
| 357 | 357 | android:layout_height="wrap_content" |
| 358 | 358 | android:text="@string/time" |
app/src/main/res/values/strings.xml
| ... | ... | @@ -128,46 +128,46 @@ |
| 128 | 128 | |
| 129 | 129 | <string name="prefecture">都道府県</string> |
| 130 | 130 | |
| 131 | - <string name="login_error_title">Login error</string> | |
| 132 | - <string name="login_error">Can not login</string> | |
| 131 | + <string name="login_error_title">ログインエラー</string> | |
| 132 | + <string name="login_error">ログインできません。</string> | |
| 133 | 133 | <string name="ok">OK</string> |
| 134 | - <string name="error_title">Error</string> | |
| 135 | - <string name="password_is_null">Password is nulll</string> | |
| 136 | - <string name="account_is_null">Email is null</string> | |
| 137 | - <string name="uploading">Uploading</string> | |
| 138 | - <string name="register_err">Register error</string> | |
| 139 | - <string name="err_exception">Error exception</string> | |
| 134 | + <string name="error_title">エラー</string> | |
| 135 | + <string name="password_is_null">パスワードはnullです。</string> | |
| 136 | + <string name="account_is_null">メールはヌルです。</string> | |
| 137 | + <string name="uploading">アップロード中</string> | |
| 138 | + <string name="register_err">レジスタエラー</string> | |
| 139 | + <string name="err_exception">エラー例外</string> | |
| 140 | 140 | <string name="cm">cm</string> |
| 141 | 141 | <string name="kg">kg</string> |
| 142 | 142 | <string name="percen">%</string> |
| 143 | - <string name="waite_some_minute">Please waite some minute</string> | |
| 144 | - <string name="request_pass_error">Can not sent request get password</string> | |
| 145 | - <string name="password_not_send">Password have not send, please try it again</string> | |
| 146 | - <string name="password_have_send">Password have send, please check mail</string> | |
| 147 | - <string name="register_success">Register success</string> | |
| 143 | + <string name="waite_some_minute">しばらくお待ちください。</string> | |
| 144 | + <string name="request_pass_error">要求を送信できないため、パスワードを取得できません。</string> | |
| 145 | + <string name="password_not_send">パスワードが送信されていません。もう一度お試しください。</string> | |
| 146 | + <string name="password_have_send">パスワードが送られてきました、メールをチェックしてください。</string> | |
| 147 | + <string name="register_success">登録成功</string> | |
| 148 | 148 | |
| 149 | 149 | <!-- message error register --> |
| 150 | - <string name="username_null">Username is null</string> | |
| 151 | - <string name="name_null">Name is null</string> | |
| 152 | - <string name="nickname_null">Nickname is null</string> | |
| 153 | - <string name="mail_null">Email is null</string> | |
| 154 | - <string name="mail_invalid">Email invalid</string> | |
| 155 | - <string name="password_null">Password is null</string> | |
| 156 | - <string name="confirm_pass_null">Confirm password is null</string> | |
| 157 | - <string name="password_less_6">Password length is more than 6 character</string> | |
| 158 | - <string name="confirm_pass_wrong">Confirm password is wrong</string> | |
| 159 | - <string name="sex_not_select">Sex is not select</string> | |
| 160 | - <string name="birthday_not_select">Birthday is not select</string> | |
| 161 | - <string name="height_null">Hight is null</string> | |
| 162 | - <string name="weight_null">Weight is null</string> | |
| 163 | - <string name="body_fat_percent_null">Body fat percent is null</string> | |
| 164 | - <string name="comment_null">Comment is null</string> | |
| 165 | - <string name="level_not_select">Level is not select</string> | |
| 166 | - <string name="province_not_select">Province is not select</string> | |
| 150 | + <string name="username_null">ユーザー名はnullです。</string> | |
| 151 | + <string name="name_null">名前はnullです。</string> | |
| 152 | + <string name="nickname_null">ニックネームはnullです。</string> | |
| 153 | + <string name="mail_null">メールはヌルです。</string> | |
| 154 | + <string name="mail_invalid">電子メールが無効です。</string> | |
| 155 | + <string name="password_null">パスワードはnullです。</string> | |
| 156 | + <string name="confirm_pass_null">パスワードの確認はnullです。</string> | |
| 157 | + <string name="password_less_6">パスワードの長さは6文字以上です。</string> | |
| 158 | + <string name="confirm_pass_wrong">パスワードの確認が間違っています。</string> | |
| 159 | + <string name="sex_not_select">性別は選択されていません。</string> | |
| 160 | + <string name="birthday_not_select">誕生日は選択されていません。</string> | |
| 161 | + <string name="height_null">Hightはnullです。</string> | |
| 162 | + <string name="weight_null">重量はnullです。</string> | |
| 163 | + <string name="body_fat_percent_null">体脂肪率はnullです。</string> | |
| 164 | + <string name="comment_null">コメントはnullです。</string> | |
| 165 | + <string name="level_not_select">レベルは選択されていません。</string> | |
| 166 | + <string name="province_not_select">州は選択されていません。</string> | |
| 167 | 167 | |
| 168 | - <string name="please_input_email">Please input email</string> | |
| 169 | - <string name="please_input_confirm">Please input confirm code</string> | |
| 170 | - <string name="send_confirm">Send confirm</string> | |
| 168 | + <string name="please_input_email">メールを入力してください。</string> | |
| 169 | + <string name="please_input_confirm">確認コードを入力してください。</string> | |
| 170 | + <string name="send_confirm">送信確認</string> | |
| 171 | 171 | |
| 172 | 172 | <!--string relationship--> |
| 173 | 173 | <string name="male">男</string> |
| 174 | 174 | |
| ... | ... | @@ -293,8 +293,10 @@ |
| 293 | 293 | <string name="weather">天気</string> |
| 294 | 294 | |
| 295 | 295 | <string name="calo_consumed">消費カロリー</string> |
| 296 | - <string name="can_not_get_data">Can not get data</string> | |
| 296 | + <string name="can_not_get_data">データを取得できません。</string> | |
| 297 | 297 | <string name="loading">読み込み中</string> |
| 298 | + | |
| 299 | + <string name="sensor_available">カウントセンサーが使用できません。</string> | |
| 298 | 300 | |
| 299 | 301 | </resources> |