Commit ba7d7409b25a35210c313f81991d73c2404e9e28
1 parent
5520a4b27d
Exists in
master
and in
1 other branch
update fix
Showing 3 changed files with 2 additions and 4 deletions Inline Diff
app/build.gradle
| 1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
| 2 | 2 | ||
| 3 | android { | 3 | android { |
| 4 | compileSdkVersion 25 | 4 | compileSdkVersion 25 |
| 5 | buildToolsVersion '26.0.2' | 5 | buildToolsVersion '26.0.2' |
| 6 | defaultConfig { | 6 | defaultConfig { |
| 7 | applicationId "com.dinhcv.lifelogpedometer" | 7 | applicationId "com.dinhcv.lifelogpedometer" |
| 8 | minSdkVersion 19 | 8 | minSdkVersion 19 |
| 9 | targetSdkVersion 25 | 9 | targetSdkVersion 25 |
| 10 | versionCode 1 | 10 | versionCode 1 |
| 11 | versionName "1.0" | 11 | versionName "1.0" |
| 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
| 13 | // Enabling multidex support. | 13 | // Enabling multidex support. |
| 14 | multiDexEnabled true | 14 | multiDexEnabled true |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | flavorDimensions "default" | 17 | //flavorDimensions "default" |
| 18 | 18 | ||
| 19 | buildTypes { | 19 | buildTypes { |
| 20 | release { | 20 | release { |
| 21 | minifyEnabled false | 21 | minifyEnabled false |
| 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | signingConfigs { | 26 | signingConfigs { |
| 27 | dev { | 27 | dev { |
| 28 | storeFile file("../keystores/...") | 28 | storeFile file("../keystores/...") |
| 29 | storePassword 'android' | 29 | storePassword 'android' |
| 30 | keyAlias 'androiddebugkey' | 30 | keyAlias 'androiddebugkey' |
| 31 | keyPassword 'android' | 31 | keyPassword 'android' |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | product { | 34 | product { |
| 35 | storeFile file("..keystores/...") | 35 | storeFile file("..keystores/...") |
| 36 | storePassword 'android' | 36 | storePassword 'android' |
| 37 | keyAlias 'androiddebugkey' | 37 | keyAlias 'androiddebugkey' |
| 38 | keyPassword 'android' | 38 | keyPassword 'android' |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | productFlavors { | 42 | productFlavors { |
| 43 | 43 | ||
| 44 | dev { | 44 | dev { |
| 45 | applicationId "com.dinhcv.lifelogpedometer" | 45 | applicationId "com.dinhcv.lifelogpedometer" |
| 46 | applicationIdSuffix "dev" | 46 | applicationIdSuffix "dev" |
| 47 | minSdkVersion 19 | 47 | minSdkVersion 19 |
| 48 | buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"' | 48 | buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"' |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | product { | 51 | product { |
| 52 | applicationId "com.dinhcv.lifelogpedometer" | 52 | applicationId "com.dinhcv.lifelogpedometer" |
| 53 | minSdkVersion 19 | 53 | minSdkVersion 19 |
| 54 | buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"' | 54 | buildConfigField 'String', 'BASE_URL', '"http://clover.timesfun.jp:9001/"' |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | dependencies { | 59 | dependencies { |
| 60 | compile fileTree(include: ['*.jar'], dir: 'libs') | 60 | compile fileTree(include: ['*.jar'], dir: 'libs') |
| 61 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | 61 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { |
| 62 | exclude group: 'com.android.support', module: 'support-annotations' | 62 | exclude group: 'com.android.support', module: 'support-annotations' |
| 63 | }) | 63 | }) |
| 64 | 64 | ||
| 65 | // Retrofit | 65 | // Retrofit |
| 66 | // JSON Parsing | 66 | // JSON Parsing |
| 67 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' | 67 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' |
| 68 | compile 'com.android.support:appcompat-v7:25.3.1' | 68 | compile 'com.android.support:appcompat-v7:25.3.1' |
| 69 | compile 'com.github.j4velin.colorpicker:colorpicker:1.2.3' | 69 | compile 'com.github.j4velin.colorpicker:colorpicker:1.2.3' |
| 70 | compile 'com.github.j4velin.EazeGraph:EazeGraph:1.0.2' | 70 | compile 'com.github.j4velin.EazeGraph:EazeGraph:1.0.2' |
| 71 | compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0' | 71 | compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0' |
| 72 | compile 'com.android.support:design:25.3.1' | 72 | compile 'com.android.support:design:25.3.1' |
| 73 | compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' | 73 | compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' |
| 74 | compile 'com.google.android.gms:play-services:11.0.4' | 74 | compile 'com.google.android.gms:play-services:11.0.4' |
| 75 | compile 'com.google.code.gson:gson:2.7' | 75 | compile 'com.google.code.gson:gson:2.7' |
| 76 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' | 76 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' |
| 77 | compile 'de.hdodenhof:circleimageview:2.1.0' | 77 | compile 'de.hdodenhof:circleimageview:2.1.0' |
| 78 | compile 'com.jakewharton:butterknife:8.6.0' | 78 | compile 'com.jakewharton:butterknife:8.6.0' |
| 79 | testCompile 'junit:junit:4.12' | 79 | testCompile 'junit:junit:4.12' |
| 80 | // Retrofit | 80 | // Retrofit |
| 81 | compile 'com.squareup.retrofit2:retrofit:2.1.0' | 81 | compile 'com.squareup.retrofit2:retrofit:2.1.0' |
| 82 | compile 'com.squareup.picasso:picasso:2.5.2' | 82 | compile 'com.squareup.picasso:picasso:2.5.2' |
| 83 | compile 'de.hdodenhof:circleimageview:2.1.0' | 83 | compile 'de.hdodenhof:circleimageview:2.1.0' |
| 84 | compile 'com.jakewharton:butterknife:8.6.0' | 84 | compile 'com.jakewharton:butterknife:8.6.0' |
| 85 | compile 'com.squareup.retrofit2:retrofit:2.1.0' | 85 | compile 'com.squareup.retrofit2:retrofit:2.1.0' |
| 86 | compile 'com.squareup.picasso:picasso:2.5.2' | 86 | compile 'com.squareup.picasso:picasso:2.5.2' |
| 87 | compile 'com.android.support:support-v4:25.3.1' | 87 | compile 'com.android.support:support-v4:25.3.1' |
| 88 | testCompile 'junit:junit:4.12' | 88 | testCompile 'junit:junit:4.12' |
| 89 | 89 | ||
| 90 | compile 'com.android.support:multidex:1.0.1' | 90 | compile 'com.android.support:multidex:1.0.1' |
| 91 | 91 | ||
| 92 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' | 92 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' |
| 93 | } | 93 | } |
| 94 | 94 |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopTodayFragment.java
| 1 | package com.dinhcv.lifelogpedometer.activity; | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | ||
| 3 | import android.app.DatePickerDialog; | 3 | import android.app.DatePickerDialog; |
| 4 | import android.app.ProgressDialog; | 4 | import android.app.ProgressDialog; |
| 5 | import android.content.Context; | 5 | import android.content.Context; |
| 6 | import android.graphics.Color; | 6 | import android.graphics.Color; |
| 7 | import android.hardware.Sensor; | 7 | import android.hardware.Sensor; |
| 8 | import android.hardware.SensorEvent; | 8 | import android.hardware.SensorEvent; |
| 9 | import android.hardware.SensorEventListener; | 9 | import android.hardware.SensorEventListener; |
| 10 | import android.hardware.SensorManager; | 10 | import android.hardware.SensorManager; |
| 11 | import android.os.Bundle; | 11 | import android.os.Bundle; |
| 12 | import android.support.annotation.Nullable; | 12 | import android.support.annotation.Nullable; |
| 13 | import android.view.LayoutInflater; | 13 | import android.view.LayoutInflater; |
| 14 | import android.view.Menu; | 14 | import android.view.Menu; |
| 15 | import android.view.MenuInflater; | 15 | import android.view.MenuInflater; |
| 16 | import android.view.View; | 16 | import android.view.View; |
| 17 | import android.view.ViewGroup; | 17 | import android.view.ViewGroup; |
| 18 | import android.widget.DatePicker; | 18 | import android.widget.DatePicker; |
| 19 | import android.widget.ImageView; | 19 | import android.widget.ImageView; |
| 20 | import android.widget.LinearLayout; | 20 | import android.widget.LinearLayout; |
| 21 | import android.widget.TextView; | 21 | import android.widget.TextView; |
| 22 | import android.widget.Toast; | 22 | import android.widget.Toast; |
| 23 | 23 | ||
| 24 | import com.dinhcv.lifelogpedometer.R; | 24 | import com.dinhcv.lifelogpedometer.R; |
| 25 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; | 25 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 26 | import com.dinhcv.lifelogpedometer.model.StepModel; | 26 | import com.dinhcv.lifelogpedometer.model.StepModel; |
| 27 | import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo; | 27 | import com.dinhcv.lifelogpedometer.model.structure.top.StepItemInfo; |
| 28 | import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo; | 28 | import com.dinhcv.lifelogpedometer.model.structure.top.TopInfo; |
| 29 | import com.dinhcv.lifelogpedometer.portal.ApiServices; | 29 | import com.dinhcv.lifelogpedometer.portal.ApiServices; |
| 30 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; | 30 | import com.dinhcv.lifelogpedometer.portal.LLAPIManager; |
| 31 | import com.dinhcv.lifelogpedometer.utils.Const; | 31 | import com.dinhcv.lifelogpedometer.utils.Const; |
| 32 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; | 32 | import com.dinhcv.lifelogpedometer.utils.DayAxisValueFormatter; |
| 33 | import com.dinhcv.lifelogpedometer.utils.Debug; | 33 | import com.dinhcv.lifelogpedometer.utils.Debug; |
| 34 | import com.dinhcv.lifelogpedometer.utils.Utils; | 34 | import com.dinhcv.lifelogpedometer.utils.Utils; |
| 35 | import com.github.mikephil.charting.components.XAxis; | 35 | import com.github.mikephil.charting.components.XAxis; |
| 36 | import com.github.mikephil.charting.components.YAxis; | 36 | import com.github.mikephil.charting.components.YAxis; |
| 37 | 37 | ||
| 38 | import com.github.mikephil.charting.charts.BarChart; | 38 | import com.github.mikephil.charting.charts.BarChart; |
| 39 | import com.github.mikephil.charting.data.BarData; | 39 | import com.github.mikephil.charting.data.BarData; |
| 40 | import com.github.mikephil.charting.data.BarDataSet; | 40 | import com.github.mikephil.charting.data.BarDataSet; |
| 41 | import com.github.mikephil.charting.data.BarEntry; | 41 | import com.github.mikephil.charting.data.BarEntry; |
| 42 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; | 42 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; |
| 43 | 43 | ||
| 44 | import org.eazegraph.lib.charts.PieChart; | 44 | import org.eazegraph.lib.charts.PieChart; |
| 45 | import org.eazegraph.lib.models.PieModel; | 45 | import org.eazegraph.lib.models.PieModel; |
| 46 | import org.json.JSONArray; | 46 | import org.json.JSONArray; |
| 47 | import org.json.JSONException; | 47 | import org.json.JSONException; |
| 48 | import org.json.JSONObject; | 48 | import org.json.JSONObject; |
| 49 | 49 | ||
| 50 | import java.text.NumberFormat; | 50 | import java.text.NumberFormat; |
| 51 | import java.util.ArrayList; | 51 | import java.util.ArrayList; |
| 52 | import java.util.Arrays; | 52 | import java.util.Arrays; |
| 53 | import java.util.Calendar; | 53 | import java.util.Calendar; |
| 54 | import java.util.Date; | 54 | import java.util.Date; |
| 55 | import java.util.List; | 55 | import java.util.List; |
| 56 | import java.util.Locale; | 56 | import java.util.Locale; |
| 57 | 57 | ||
| 58 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; | 58 | import static com.github.mikephil.charting.utils.ColorTemplate.rgb; |
| 59 | 59 | ||
| 60 | 60 | ||
| 61 | public class TopTodayFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { | 61 | public class TopTodayFragment extends FragmentBase implements SettingFragmentPresenter, SensorEventListener { |
| 62 | 62 | ||
| 63 | private TextView stepsView; | 63 | private TextView stepsView; |
| 64 | private TextView tvStepGoal; | 64 | private TextView tvStepGoal; |
| 65 | private TextView tvDistance; | 65 | private TextView tvDistance; |
| 66 | private TextView tvTime; | 66 | private TextView tvTime; |
| 67 | private TextView tvStepRemain; | 67 | private TextView tvStepRemain; |
| 68 | private TextView tvStepRateDone; | 68 | private TextView tvStepRateDone; |
| 69 | private boolean showSteps = true; | 69 | private boolean showSteps = true; |
| 70 | private PieModel sliceGoal, sliceCurrent; | 70 | private PieModel sliceGoal, sliceCurrent; |
| 71 | private PieChart pg; | 71 | private PieChart pg; |
| 72 | private TextView tvDate; | 72 | private TextView tvDate; |
| 73 | private ImageView ivBack; | 73 | private ImageView ivBack; |
| 74 | private ImageView ivNext; | 74 | private ImageView ivNext; |
| 75 | 75 | ||
| 76 | private LinearLayout llBike; | 76 | private LinearLayout llBike; |
| 77 | private LinearLayout llWalking; | 77 | private LinearLayout llWalking; |
| 78 | private LinearLayout llRunning; | 78 | private LinearLayout llRunning; |
| 79 | private Const.STEP_TYPE stepType; | 79 | private Const.STEP_TYPE stepType; |
| 80 | 80 | ||
| 81 | private Date mAnaDate; | 81 | private Date mAnaDate; |
| 82 | private Calendar mCalendar; | 82 | private Calendar mCalendar; |
| 83 | 83 | ||
| 84 | private int mAnaDay; | 84 | private int mAnaDay; |
| 85 | private int mAnaMonth; | 85 | private int mAnaMonth; |
| 86 | private int mAnaYear; | 86 | private int mAnaYear; |
| 87 | 87 | ||
| 88 | public static int STEP_SIZE = 75; | 88 | public static int STEP_SIZE = 75; |
| 89 | private StepModel mStepModel; | 89 | private StepModel mStepModel; |
| 90 | private TextView tvSmallStepGoal; | 90 | private TextView tvSmallStepGoal; |
| 91 | private TextView tvSmallRemain; | 91 | private TextView tvSmallRemain; |
| 92 | private Context mContext; | 92 | private Context mContext; |
| 93 | 93 | ||
| 94 | public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); | 94 | public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault()); |
| 95 | private SensorManager sensorManager; | 95 | private SensorManager sensorManager; |
| 96 | private boolean activityRunning; | 96 | private boolean activityRunning; |
| 97 | private int stepTotal = 0; | 97 | private int stepTotal = 0; |
| 98 | private int stepGoal = 0; | 98 | private int stepGoal = 0; |
| 99 | private int stepCount = 0; | 99 | private int stepCount = 0; |
| 100 | 100 | ||
| 101 | private Date mFromDate; | 101 | private Date mFromDate; |
| 102 | private Date mToDate; | 102 | private Date mToDate; |
| 103 | 103 | ||
| 104 | private TopInfo mTopInfo = new TopInfo(); | 104 | private TopInfo mTopInfo = new TopInfo(); |
| 105 | private BarChart mChart; | 105 | private BarChart mChart; |
| 106 | 106 | ||
| 107 | private List<String> dateList; | 107 | private List<String> dateList; |
| 108 | private String[] mParties; | 108 | private String[] mParties; |
| 109 | private Integer[] mStep; | 109 | private Integer[] mStep; |
| 110 | private ProgressDialog progress; | 110 | private ProgressDialog progress; |
| 111 | 111 | ||
| 112 | private TopFragment mTopFragment; | 112 | private TopFragment mTopFragment; |
| 113 | public void setRootFragment(TopFragment frag) { | 113 | public void setRootFragment(TopFragment frag) { |
| 114 | this.mTopFragment = frag; | 114 | this.mTopFragment = frag; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | @Override | 117 | @Override |
| 118 | public void onCreate(final Bundle savedInstanceState) { | 118 | public void onCreate(final Bundle savedInstanceState) { |
| 119 | super.onCreate(savedInstanceState); | 119 | super.onCreate(savedInstanceState); |
| 120 | setHasOptionsMenu(true); | 120 | setHasOptionsMenu(true); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | @Override | 123 | @Override |
| 124 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 124 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 125 | final Bundle savedInstanceState) { | 125 | final Bundle savedInstanceState) { |
| 126 | final View v = inflater.inflate(R.layout.fragment_top_today, null); | 126 | final View v = inflater.inflate(R.layout.fragment_top_today, null); |
| 127 | mContext = getActivity(); | 127 | mContext = getActivity(); |
| 128 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); | 128 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); |
| 129 | 129 | ||
| 130 | initView(v); | 130 | initView(v); |
| 131 | 131 | ||
| 132 | // slice for the steps taken today | 132 | // slice for the steps taken today |
| 133 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); | 133 | sliceCurrent = new PieModel("", 0, Color.parseColor("#6FE7F7")); |
| 134 | pg.addPieSlice(sliceCurrent); | 134 | pg.addPieSlice(sliceCurrent); |
| 135 | 135 | ||
| 136 | // slice for the "missing" steps until reaching the goal | 136 | // slice for the "missing" steps until reaching the goal |
| 137 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); | 137 | sliceGoal = new PieModel("", Const.STEP_GOAL, Color.parseColor("#B7B8B6")); |
| 138 | pg.addPieSlice(sliceGoal); | 138 | pg.addPieSlice(sliceGoal); |
| 139 | 139 | ||
| 140 | pg.setDrawValueInPie(false); | 140 | pg.setDrawValueInPie(false); |
| 141 | pg.setUsePieRotation(false); | 141 | pg.setUsePieRotation(false); |
| 142 | pg.setInnerPadding(93); | ||
| 143 | pg.setInnerPaddingColor(R.color.background_main); | ||
| 144 | pg.startAnimation(); | 142 | pg.startAnimation(); |
| 145 | pg.setAutoCenterInSlice(false); | 143 | pg.setAutoCenterInSlice(false); |
| 146 | 144 | ||
| 147 | mCalendar = Calendar.getInstance(); | 145 | mCalendar = Calendar.getInstance(); |
| 148 | mCalendar.setTime(new Date()); | 146 | mCalendar.setTime(new Date()); |
| 149 | mAnaDate = mCalendar.getTime(); | 147 | mAnaDate = mCalendar.getTime(); |
| 150 | mAnaYear = mCalendar.get(Calendar.YEAR); | 148 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 151 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 149 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 152 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 150 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 153 | 151 | ||
| 154 | mFromDate = new Date(); | 152 | mFromDate = new Date(); |
| 155 | 153 | ||
| 156 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 154 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 157 | 155 | ||
| 158 | initData(); | 156 | initData(); |
| 159 | 157 | ||
| 160 | handleEvent(); | 158 | handleEvent(); |
| 161 | 159 | ||
| 162 | getTopPage(mAnaDate, stepType); | 160 | getTopPage(mAnaDate, stepType); |
| 163 | 161 | ||
| 164 | return v; | 162 | return v; |
| 165 | } | 163 | } |
| 166 | 164 | ||
| 167 | private void initView(View v){ | 165 | private void initView(View v){ |
| 168 | stepsView = (TextView) v.findViewById(R.id.steps); | 166 | stepsView = (TextView) v.findViewById(R.id.steps); |
| 169 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); | 167 | tvDistance = (TextView) v.findViewById(R.id.tv_distance); |
| 170 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); | 168 | tvStepGoal = (TextView) v.findViewById(R.id.tv_stepGoal); |
| 171 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); | 169 | tvStepRemain = (TextView) v.findViewById(R.id.tv_stepRemain); |
| 172 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); | 170 | tvStepRateDone = (TextView) v.findViewById(R.id.tv_stepRateDone); |
| 173 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); | 171 | tvSmallStepGoal = (TextView) v.findViewById(R.id.tv_smallStepGoal); |
| 174 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); | 172 | tvSmallRemain = (TextView) v.findViewById(R.id.tv_smallRemain); |
| 175 | tvTime = (TextView) v.findViewById(R.id.tv_time); | 173 | tvTime = (TextView) v.findViewById(R.id.tv_time); |
| 176 | tvDate = (TextView) v.findViewById(R.id.tv_date); | 174 | tvDate = (TextView) v.findViewById(R.id.tv_date); |
| 177 | ivBack = (ImageView) v.findViewById(R.id.iv_back); | 175 | ivBack = (ImageView) v.findViewById(R.id.iv_back); |
| 178 | ivNext = (ImageView) v.findViewById(R.id.iv_next); | 176 | ivNext = (ImageView) v.findViewById(R.id.iv_next); |
| 179 | 177 | ||
| 180 | mChart = (BarChart) v.findViewById(R.id.chart); | 178 | mChart = (BarChart) v.findViewById(R.id.chart); |
| 181 | pg = (PieChart) v.findViewById(R.id.graph); | 179 | pg = (PieChart) v.findViewById(R.id.graph); |
| 182 | 180 | ||
| 183 | llRunning = (LinearLayout) v.findViewById(R.id.ll_running); | 181 | llRunning = (LinearLayout) v.findViewById(R.id.ll_running); |
| 184 | llWalking = (LinearLayout) v.findViewById(R.id.ll_walking); | 182 | llWalking = (LinearLayout) v.findViewById(R.id.ll_walking); |
| 185 | llBike = (LinearLayout) v.findViewById(R.id.ll_bike); | 183 | llBike = (LinearLayout) v.findViewById(R.id.ll_bike); |
| 186 | } | 184 | } |
| 187 | 185 | ||
| 188 | private void initData(){ | 186 | private void initData(){ |
| 189 | mCalendar = Calendar.getInstance(); | 187 | mCalendar = Calendar.getInstance(); |
| 190 | mCalendar.setTime(new Date()); | 188 | mCalendar.setTime(new Date()); |
| 191 | mAnaDate = mCalendar.getTime(); | 189 | mAnaDate = mCalendar.getTime(); |
| 192 | mAnaYear = mCalendar.get(Calendar.YEAR); | 190 | mAnaYear = mCalendar.get(Calendar.YEAR); |
| 193 | mAnaMonth = mCalendar.get(Calendar.MONTH); | 191 | mAnaMonth = mCalendar.get(Calendar.MONTH); |
| 194 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); | 192 | mAnaDay = mCalendar.get(Calendar.DAY_OF_MONTH); |
| 195 | 193 | ||
| 196 | 194 | ||
| 197 | stepType = Const.STEP_TYPE.WALKING; | 195 | stepType = Const.STEP_TYPE.WALKING; |
| 198 | updateUiStepType(false, true, false); | 196 | updateUiStepType(false, true, false); |
| 199 | 197 | ||
| 200 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); | 198 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(mAnaDate)); |
| 201 | } | 199 | } |
| 202 | 200 | ||
| 203 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { | 201 | private void updateUiStepType(boolean b1, boolean b2, boolean b3) { |
| 204 | llBike.setSelected(b1); | 202 | llBike.setSelected(b1); |
| 205 | llWalking.setSelected(b2); | 203 | llWalking.setSelected(b2); |
| 206 | llRunning.setSelected(b3); | 204 | llRunning.setSelected(b3); |
| 207 | } | 205 | } |
| 208 | 206 | ||
| 209 | private void stepsDistanceChanged() { | 207 | private void stepsDistanceChanged() { |
| 210 | if (progress != null){ | 208 | if (progress != null){ |
| 211 | progress.dismiss(); | 209 | progress.dismiss(); |
| 212 | } | 210 | } |
| 213 | updatePie(); | 211 | updatePie(); |
| 214 | updateBars(); | 212 | updateBars(); |
| 215 | } | 213 | } |
| 216 | 214 | ||
| 217 | 215 | ||
| 218 | @Override | 216 | @Override |
| 219 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { | 217 | public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { |
| 220 | inflater.inflate(R.menu.main, menu); | 218 | inflater.inflate(R.menu.main, menu); |
| 221 | } | 219 | } |
| 222 | 220 | ||
| 223 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ | 221 | private void getTopPage(Date date, Const.STEP_TYPE stepType){ |
| 224 | 222 | ||
| 225 | progress = new ProgressDialog(mContext); | 223 | progress = new ProgressDialog(mContext); |
| 226 | progress.setMessage(getString(R.string.loading)); | 224 | progress.setMessage(getString(R.string.loading)); |
| 227 | progress.setCancelable(false); | 225 | progress.setCancelable(false); |
| 228 | progress.show(); | 226 | progress.show(); |
| 229 | ApiServices.topInfo(date, stepType, new LLAPIManagerListener() { | 227 | ApiServices.topInfo(date, stepType, new LLAPIManagerListener() { |
| 230 | @Override | 228 | @Override |
| 231 | public void onError(Error error) { | 229 | public void onError(Error error) { |
| 232 | Debug.error("Get data history error"); | 230 | Debug.error("Get data history error"); |
| 233 | hiddenDialog(); | 231 | hiddenDialog(); |
| 234 | showDialogNotData(); | 232 | showDialogNotData(); |
| 235 | } | 233 | } |
| 236 | 234 | ||
| 237 | @Override | 235 | @Override |
| 238 | public void onSuccess(String json) { | 236 | public void onSuccess(String json) { |
| 239 | Debug.error("Get data history success"); | 237 | Debug.error("Get data history success"); |
| 240 | loadDataDone(json); | 238 | loadDataDone(json); |
| 241 | } | 239 | } |
| 242 | 240 | ||
| 243 | @Override | 241 | @Override |
| 244 | public void onSuccess(JSONObject object) { | 242 | public void onSuccess(JSONObject object) { |
| 245 | Debug.error("Get data history success"); | 243 | Debug.error("Get data history success"); |
| 246 | hiddenDialog(); | 244 | hiddenDialog(); |
| 247 | } | 245 | } |
| 248 | }); | 246 | }); |
| 249 | } | 247 | } |
| 250 | 248 | ||
| 251 | private void showDialogNotData(){ | 249 | private void showDialogNotData(){ |
| 252 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); | 250 | showAlerDialog(mContext, getResources().getString(R.string.can_not_get_data)); |
| 253 | } | 251 | } |
| 254 | 252 | ||
| 255 | private void loadDataDone(String jsonString) { | 253 | private void loadDataDone(String jsonString) { |
| 256 | JSONObject jsonObject = null; | 254 | JSONObject jsonObject = null; |
| 257 | try { | 255 | try { |
| 258 | jsonObject = new JSONObject(jsonString); | 256 | jsonObject = new JSONObject(jsonString); |
| 259 | int status = jsonObject.optInt("status"); | 257 | int status = jsonObject.optInt("status"); |
| 260 | if (status == 1) { | 258 | if (status == 1) { |
| 261 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); | 259 | JSONObject jsonObject1 = jsonObject.optJSONObject("result"); |
| 262 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); | 260 | JSONObject targetInf = jsonObject1.getJSONObject("targetInf"); |
| 263 | 261 | ||
| 264 | if (targetInf != null){ | 262 | if (targetInf != null){ |
| 265 | String target = targetInf.optString("target_step"); | 263 | String target = targetInf.optString("target_step"); |
| 266 | Debug.normal("Target: "+ target); | 264 | Debug.normal("Target: "+ target); |
| 267 | mTopInfo.setTaget(targetInf.optString("target_step")); | 265 | mTopInfo.setTaget(targetInf.optString("target_step")); |
| 268 | mTopInfo.setSteps(targetInf.optString("num_step")); | 266 | mTopInfo.setSteps(targetInf.optString("num_step")); |
| 269 | mTopInfo.setStepRemain(targetInf.optString("remaining_step")); | 267 | mTopInfo.setStepRemain(targetInf.optString("remaining_step")); |
| 270 | mTopInfo.setCompletePercent(targetInf.optString("complete_percent")); | 268 | mTopInfo.setCompletePercent(targetInf.optString("complete_percent")); |
| 271 | } | 269 | } |
| 272 | 270 | ||
| 273 | mTopInfo.setKcalo(jsonObject1.optString("kcal")); | 271 | mTopInfo.setKcalo(jsonObject1.optString("kcal")); |
| 274 | mTopInfo.setDistance(jsonObject1.optString("distance")); | 272 | mTopInfo.setDistance(jsonObject1.optString("distance")); |
| 275 | mTopInfo.setTime(jsonObject1.optString("time")); | 273 | mTopInfo.setTime(jsonObject1.optString("time")); |
| 276 | JSONArray stepArr = jsonObject1.optJSONArray("dataChart"); | 274 | JSONArray stepArr = jsonObject1.optJSONArray("dataChart"); |
| 277 | 275 | ||
| 278 | 276 | ||
| 279 | if (stepArr != null && stepArr.length() > 0) { | 277 | if (stepArr != null && stepArr.length() > 0) { |
| 280 | List<StepItemInfo> infoLists = new ArrayList<>(); | 278 | List<StepItemInfo> infoLists = new ArrayList<>(); |
| 281 | for (int i = 0; i < stepArr.length(); i++){ | 279 | for (int i = 0; i < stepArr.length(); i++){ |
| 282 | StepItemInfo stepItemInfo = new StepItemInfo(); | 280 | StepItemInfo stepItemInfo = new StepItemInfo(); |
| 283 | JSONObject ob = (JSONObject) stepArr.get(i); | 281 | JSONObject ob = (JSONObject) stepArr.get(i); |
| 284 | stepItemInfo.setHour(ob.optInt("hour")); | 282 | stepItemInfo.setHour(ob.optInt("hour")); |
| 285 | stepItemInfo.setNumStep(ob.optInt("numStep")); | 283 | stepItemInfo.setNumStep(ob.optInt("numStep")); |
| 286 | infoLists.add(stepItemInfo); | 284 | infoLists.add(stepItemInfo); |
| 287 | } | 285 | } |
| 288 | 286 | ||
| 289 | mTopInfo.setStepList(infoLists); | 287 | mTopInfo.setStepList(infoLists); |
| 290 | } | 288 | } |
| 291 | 289 | ||
| 292 | } | 290 | } |
| 293 | } catch (JSONException e) { | 291 | } catch (JSONException e) { |
| 294 | e.printStackTrace(); | 292 | e.printStackTrace(); |
| 295 | mTopInfo = new TopInfo();; | 293 | mTopInfo = new TopInfo();; |
| 296 | } | 294 | } |
| 297 | 295 | ||
| 298 | stepsDistanceChanged(); | 296 | stepsDistanceChanged(); |
| 299 | } | 297 | } |
| 300 | 298 | ||
| 301 | private void updatePie() { | 299 | private void updatePie() { |
| 302 | // todayOffset might still be Integer.MIN_VALUE on first start | 300 | // todayOffset might still be Integer.MIN_VALUE on first start |
| 303 | int stepsToday = 0; | 301 | int stepsToday = 0; |
| 304 | int stepTarget = 0; | 302 | int stepTarget = 0; |
| 305 | if (mTopInfo != null) { | 303 | if (mTopInfo != null) { |
| 306 | if (mTopInfo.getSteps().contains(",")){ | 304 | if (mTopInfo.getSteps().contains(",")){ |
| 307 | stepsToday = Integer.valueOf(mTopInfo.getSteps().replace(",", "")); | 305 | stepsToday = Integer.valueOf(mTopInfo.getSteps().replace(",", "")); |
| 308 | }else { | 306 | }else { |
| 309 | stepsToday = Integer.valueOf(mTopInfo.getSteps()); | 307 | stepsToday = Integer.valueOf(mTopInfo.getSteps()); |
| 310 | } | 308 | } |
| 311 | 309 | ||
| 312 | if (mTopInfo.getTaget().contains(",")) { | 310 | if (mTopInfo.getTaget().contains(",")) { |
| 313 | stepTarget = Integer.valueOf(mTopInfo.getTaget().replace(",", "")); | 311 | stepTarget = Integer.valueOf(mTopInfo.getTaget().replace(",", "")); |
| 314 | }else { | 312 | }else { |
| 315 | stepTarget = Integer.valueOf(mTopInfo.getTaget()); | 313 | stepTarget = Integer.valueOf(mTopInfo.getTaget()); |
| 316 | } | 314 | } |
| 317 | } | 315 | } |
| 318 | sliceCurrent.setValue(stepsToday); | 316 | sliceCurrent.setValue(stepsToday); |
| 319 | if (stepTarget - stepsToday > 0) { | 317 | if (stepTarget - stepsToday > 0) { |
| 320 | // goal not reached yet | 318 | // goal not reached yet |
| 321 | if (pg.getData().size() == 1) { | 319 | if (pg.getData().size() == 1) { |
| 322 | pg.addPieSlice(sliceGoal); | 320 | pg.addPieSlice(sliceGoal); |
| 323 | } | 321 | } |
| 324 | sliceGoal.setValue(stepTarget - stepsToday); | 322 | sliceGoal.setValue(stepTarget - stepsToday); |
| 325 | } else { | 323 | } else { |
| 326 | // goal reached | 324 | // goal reached |
| 327 | pg.clearChart(); | 325 | pg.clearChart(); |
| 328 | pg.addPieSlice(sliceCurrent); | 326 | pg.addPieSlice(sliceCurrent); |
| 329 | } | 327 | } |
| 330 | pg.update(); | 328 | pg.update(); |
| 331 | stepGoal = stepTarget; | 329 | stepGoal = stepTarget; |
| 332 | stepTotal = stepsToday; | 330 | stepTotal = stepsToday; |
| 333 | stepsView.setText(formatter.format(stepsToday)); | 331 | stepsView.setText(formatter.format(stepsToday)); |
| 334 | int stepRemain = stepTarget - stepsToday; | 332 | int stepRemain = stepTarget - stepsToday; |
| 335 | tvStepRemain.setText(String.valueOf(stepRemain)); | 333 | tvStepRemain.setText(String.valueOf(stepRemain)); |
| 336 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(stepsToday *100/ stepTarget))); | 334 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(stepsToday *100/ stepTarget))); |
| 337 | tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, stepRemain)); | 335 | tvSmallRemain.setText(getResources().getString(R.string.pie_text_content3a, stepRemain)); |
| 338 | tvStepGoal.setText(mTopInfo.getTaget()); | 336 | tvStepGoal.setText(mTopInfo.getTaget()); |
| 339 | tvSmallStepGoal.setText(mTopInfo.getTaget()); | 337 | tvSmallStepGoal.setText(mTopInfo.getTaget()); |
| 340 | 338 | ||
| 341 | tvDistance.setText(mTopInfo.getDistance()); | 339 | tvDistance.setText(mTopInfo.getDistance()); |
| 342 | tvTime.setText(mTopInfo.getTime()); | 340 | tvTime.setText(mTopInfo.getTime()); |
| 343 | 341 | ||
| 344 | double distanceToday = stepsToday * STEP_SIZE; | 342 | double distanceToday = stepsToday * STEP_SIZE; |
| 345 | distanceToday /= 100000; | 343 | distanceToday /= 100000; |
| 346 | tvDistance.setText(Utils.convert2String2Decimal(distanceToday)); | 344 | tvDistance.setText(Utils.convert2String2Decimal(distanceToday)); |
| 347 | 345 | ||
| 348 | } | 346 | } |
| 349 | 347 | ||
| 350 | /** | 348 | /** |
| 351 | * Updates the bar graph to show the steps/distance of the last week. Should | 349 | * Updates the bar graph to show the steps/distance of the last week. Should |
| 352 | * be called when switching from step count to distance. | 350 | * be called when switching from step count to distance. |
| 353 | */ | 351 | */ |
| 354 | private void updateBars() { | 352 | private void updateBars() { |
| 355 | 353 | ||
| 356 | dateList = new ArrayList<>(); | 354 | dateList = new ArrayList<>(); |
| 357 | List<String> dateList = new ArrayList<>(); | 355 | List<String> dateList = new ArrayList<>(); |
| 358 | List<Integer> stepList = new ArrayList<>(); | 356 | List<Integer> stepList = new ArrayList<>(); |
| 359 | List<StepItemInfo> stepItemInfos = mTopInfo.getStepList(); | 357 | List<StepItemInfo> stepItemInfos = mTopInfo.getStepList(); |
| 360 | if (stepItemInfos != null && stepItemInfos.size() >0) { | 358 | if (stepItemInfos != null && stepItemInfos.size() >0) { |
| 361 | for (int i = 0; i < stepItemInfos.size(); i++){ | 359 | for (int i = 0; i < stepItemInfos.size(); i++){ |
| 362 | dateList.add(String.valueOf(stepItemInfos.get(i).getHour())); | 360 | dateList.add(String.valueOf(stepItemInfos.get(i).getHour())); |
| 363 | stepList.add(stepItemInfos.get(i).getNumStep()); | 361 | stepList.add(stepItemInfos.get(i).getNumStep()); |
| 364 | } | 362 | } |
| 365 | } | 363 | } |
| 366 | 364 | ||
| 367 | mStep = stepList.toArray(new Integer[0]); | 365 | mStep = stepList.toArray(new Integer[0]); |
| 368 | mParties = dateList.toArray(new String[0]); | 366 | mParties = dateList.toArray(new String[0]); |
| 369 | 367 | ||
| 370 | initGraph(); | 368 | initGraph(); |
| 371 | } | 369 | } |
| 372 | 370 | ||
| 373 | private void initGraph(){ | 371 | private void initGraph(){ |
| 374 | 372 | ||
| 375 | mChart.setDrawBarShadow(false); | 373 | mChart.setDrawBarShadow(false); |
| 376 | mChart.setDrawValueAboveBar(true); | 374 | mChart.setDrawValueAboveBar(true); |
| 377 | 375 | ||
| 378 | // if more than 60 entries are displayed in the chart, no values will be | 376 | // if more than 60 entries are displayed in the chart, no values will be |
| 379 | // drawn | 377 | // drawn |
| 380 | mChart.setMaxVisibleValueCount(60); | 378 | mChart.setMaxVisibleValueCount(60); |
| 381 | 379 | ||
| 382 | mChart.getDescription().setEnabled(false); | 380 | mChart.getDescription().setEnabled(false); |
| 383 | // scaling can now only be done on x- and y-axis separately | 381 | // scaling can now only be done on x- and y-axis separately |
| 384 | mChart.setPinchZoom(false); | 382 | mChart.setPinchZoom(false); |
| 385 | 383 | ||
| 386 | mChart.setDrawGridBackground(false); | 384 | mChart.setDrawGridBackground(false); |
| 387 | // mChart.setDrawYLabels(false); | 385 | // mChart.setDrawYLabels(false); |
| 388 | List<String> listx = Arrays.asList(mParties); | 386 | List<String> listx = Arrays.asList(mParties); |
| 389 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(listx); | 387 | DayAxisValueFormatter xValueFormatter = new DayAxisValueFormatter(listx); |
| 390 | 388 | ||
| 391 | XAxis xAxis = mChart.getXAxis(); | 389 | XAxis xAxis = mChart.getXAxis(); |
| 392 | xAxis.setLabelRotationAngle(0); | 390 | xAxis.setLabelRotationAngle(0); |
| 393 | xAxis.setPosition(XAxis.XAxisPosition.TOP); | 391 | xAxis.setPosition(XAxis.XAxisPosition.TOP); |
| 394 | xAxis.setDrawGridLines(true); | 392 | xAxis.setDrawGridLines(true); |
| 395 | xAxis.setLabelCount(10); | 393 | xAxis.setLabelCount(10); |
| 396 | xAxis.setTextColor(Color.WHITE); | 394 | xAxis.setTextColor(Color.WHITE); |
| 397 | xAxis.setValueFormatter(xValueFormatter); | 395 | xAxis.setValueFormatter(xValueFormatter); |
| 398 | 396 | ||
| 399 | 397 | ||
| 400 | YAxis leftAxis = mChart.getAxisLeft(); | 398 | YAxis leftAxis = mChart.getAxisLeft(); |
| 401 | leftAxis.setDrawLabels(false); | 399 | leftAxis.setDrawLabels(false); |
| 402 | leftAxis.setDrawGridLines(false); | 400 | leftAxis.setDrawGridLines(false); |
| 403 | leftAxis.setAxisMinimum(0f); | 401 | leftAxis.setAxisMinimum(0f); |
| 404 | leftAxis.setAxisMaximum(10000f); | 402 | leftAxis.setAxisMaximum(10000f); |
| 405 | leftAxis.setDrawZeroLine(false); | 403 | leftAxis.setDrawZeroLine(false); |
| 406 | 404 | ||
| 407 | leftAxis.setEnabled(false); | 405 | leftAxis.setEnabled(false); |
| 408 | mChart.setDrawValueAboveBar(false); | 406 | mChart.setDrawValueAboveBar(false); |
| 409 | mChart.getAxisRight().setEnabled(false); | 407 | mChart.getAxisRight().setEnabled(false); |
| 410 | 408 | ||
| 411 | // set auto scale min max | 409 | // set auto scale min max |
| 412 | mChart.setAutoScaleMinMaxEnabled(true); | 410 | mChart.setAutoScaleMinMaxEnabled(true); |
| 413 | mChart.notifyDataSetChanged(); | 411 | mChart.notifyDataSetChanged(); |
| 414 | 412 | ||
| 415 | // Set enimate y | 413 | // Set enimate y |
| 416 | mChart.animateY(2000); | 414 | mChart.animateY(2000); |
| 417 | 415 | ||
| 418 | setData(); | 416 | setData(); |
| 419 | 417 | ||
| 420 | mChart.getLegend().setEnabled(false); | 418 | mChart.getLegend().setEnabled(false); |
| 421 | } | 419 | } |
| 422 | 420 | ||
| 423 | 421 | ||
| 424 | private void setData() { | 422 | private void setData() { |
| 425 | 423 | ||
| 426 | ArrayList<String> xVals = new ArrayList<>(); | 424 | ArrayList<String> xVals = new ArrayList<>(); |
| 427 | for (int i = 0; i < mStep.length; i++) { | 425 | for (int i = 0; i < mStep.length; i++) { |
| 428 | xVals.add(mParties[i % mStep.length]); | 426 | xVals.add(mParties[i % mStep.length]); |
| 429 | } | 427 | } |
| 430 | 428 | ||
| 431 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); | 429 | ArrayList<BarEntry> yVals1 = new ArrayList<>(); |
| 432 | for (int i = 0; i < mStep.length; i++) { | 430 | for (int i = 0; i < mStep.length; i++) { |
| 433 | float val = (float) (mStep[i]*1); | 431 | float val = (float) (mStep[i]*1); |
| 434 | yVals1.add(new BarEntry(i, val)); | 432 | yVals1.add(new BarEntry(i, val)); |
| 435 | } | 433 | } |
| 436 | 434 | ||
| 437 | BarDataSet set1; | 435 | BarDataSet set1; |
| 438 | 436 | ||
| 439 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { | 437 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { |
| 440 | set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); | 438 | set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); |
| 441 | set1.setValues(yVals1); | 439 | set1.setValues(yVals1); |
| 442 | mChart.getData().notifyDataChanged(); | 440 | mChart.getData().notifyDataChanged(); |
| 443 | mChart.notifyDataSetChanged(); | 441 | mChart.notifyDataSetChanged(); |
| 444 | } else { | 442 | } else { |
| 445 | ArrayList<Integer> colors = new ArrayList<>(); | 443 | ArrayList<Integer> colors = new ArrayList<>(); |
| 446 | 444 | ||
| 447 | 445 | ||
| 448 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; | 446 | int[] MATERIAL_COLORS = {rgb("#40CDEF")}; |
| 449 | 447 | ||
| 450 | for (int c : MATERIAL_COLORS) | 448 | for (int c : MATERIAL_COLORS) |
| 451 | colors.add(c); | 449 | colors.add(c); |
| 452 | 450 | ||
| 453 | set1 = new BarDataSet(yVals1, null); | 451 | set1 = new BarDataSet(yVals1, null); |
| 454 | 452 | ||
| 455 | set1.setColors(colors); | 453 | set1.setColors(colors); |
| 456 | 454 | ||
| 457 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); | 455 | ArrayList<IBarDataSet> dataSets = new ArrayList<>(); |
| 458 | dataSets.add(set1); | 456 | dataSets.add(set1); |
| 459 | 457 | ||
| 460 | BarData data = new BarData(dataSets); | 458 | BarData data = new BarData(dataSets); |
| 461 | data.setValueTextSize(10f); | 459 | data.setValueTextSize(10f); |
| 462 | 460 | ||
| 463 | mChart.setData(data); | 461 | mChart.setData(data); |
| 464 | } | 462 | } |
| 465 | } | 463 | } |
| 466 | 464 | ||
| 467 | 465 | ||
| 468 | 466 | ||
| 469 | private void handleEvent(){ | 467 | private void handleEvent(){ |
| 470 | tvDate.setOnClickListener(new View.OnClickListener() { | 468 | tvDate.setOnClickListener(new View.OnClickListener() { |
| 471 | @Override | 469 | @Override |
| 472 | public void onClick(View view) { | 470 | public void onClick(View view) { |
| 473 | handleAnaDatePicker(); | 471 | handleAnaDatePicker(); |
| 474 | } | 472 | } |
| 475 | }); | 473 | }); |
| 476 | 474 | ||
| 477 | ivBack.setOnClickListener(new View.OnClickListener() { | 475 | ivBack.setOnClickListener(new View.OnClickListener() { |
| 478 | @Override | 476 | @Override |
| 479 | public void onClick(View view) { | 477 | public void onClick(View view) { |
| 480 | mCalendar = Calendar.getInstance(); | 478 | mCalendar = Calendar.getInstance(); |
| 481 | mCalendar.setTime(mAnaDate); | 479 | mCalendar.setTime(mAnaDate); |
| 482 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); | 480 | mCalendar.add(Calendar.DAY_OF_MONTH, -1); |
| 483 | Date date = mCalendar.getTime(); | 481 | Date date = mCalendar.getTime(); |
| 484 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 482 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 485 | mAnaDate = date; | 483 | mAnaDate = date; |
| 486 | } | 484 | } |
| 487 | }); | 485 | }); |
| 488 | 486 | ||
| 489 | ivNext.setOnClickListener(new View.OnClickListener() { | 487 | ivNext.setOnClickListener(new View.OnClickListener() { |
| 490 | @Override | 488 | @Override |
| 491 | public void onClick(View view) { | 489 | public void onClick(View view) { |
| 492 | mCalendar = Calendar.getInstance(); | 490 | mCalendar = Calendar.getInstance(); |
| 493 | mCalendar.setTime(mAnaDate); | 491 | mCalendar.setTime(mAnaDate); |
| 494 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); | 492 | mCalendar.add(Calendar.DAY_OF_MONTH, +1); |
| 495 | Date date = mCalendar.getTime(); | 493 | Date date = mCalendar.getTime(); |
| 496 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 494 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 497 | mAnaDate = date; | 495 | mAnaDate = date; |
| 498 | } | 496 | } |
| 499 | }); | 497 | }); |
| 500 | 498 | ||
| 501 | llBike.setOnClickListener(new View.OnClickListener() { | 499 | llBike.setOnClickListener(new View.OnClickListener() { |
| 502 | @Override | 500 | @Override |
| 503 | public void onClick(View view) { | 501 | public void onClick(View view) { |
| 504 | stepType = Const.STEP_TYPE.BIKE; | 502 | stepType = Const.STEP_TYPE.BIKE; |
| 505 | updateUiStepType(true, false, false); | 503 | updateUiStepType(true, false, false); |
| 506 | getTopPage(mAnaDate, stepType); | 504 | getTopPage(mAnaDate, stepType); |
| 507 | } | 505 | } |
| 508 | }); | 506 | }); |
| 509 | 507 | ||
| 510 | llRunning.setOnClickListener(new View.OnClickListener() { | 508 | llRunning.setOnClickListener(new View.OnClickListener() { |
| 511 | @Override | 509 | @Override |
| 512 | public void onClick(View view) { | 510 | public void onClick(View view) { |
| 513 | stepType = Const.STEP_TYPE.RUNNING; | 511 | stepType = Const.STEP_TYPE.RUNNING; |
| 514 | updateUiStepType(false, false, true); | 512 | updateUiStepType(false, false, true); |
| 515 | getTopPage(mAnaDate, stepType); | 513 | getTopPage(mAnaDate, stepType); |
| 516 | } | 514 | } |
| 517 | }); | 515 | }); |
| 518 | 516 | ||
| 519 | llWalking.setOnClickListener(new View.OnClickListener() { | 517 | llWalking.setOnClickListener(new View.OnClickListener() { |
| 520 | @Override | 518 | @Override |
| 521 | public void onClick(View view) { | 519 | public void onClick(View view) { |
| 522 | stepType = Const.STEP_TYPE.WALKING; | 520 | stepType = Const.STEP_TYPE.WALKING; |
| 523 | updateUiStepType(false, true, false); | 521 | updateUiStepType(false, true, false); |
| 524 | getTopPage(mAnaDate, stepType); | 522 | getTopPage(mAnaDate, stepType); |
| 525 | } | 523 | } |
| 526 | }); | 524 | }); |
| 527 | 525 | ||
| 528 | 526 | ||
| 529 | } | 527 | } |
| 530 | 528 | ||
| 531 | 529 | ||
| 532 | /** | 530 | /** |
| 533 | * Show date picker dialog | 531 | * Show date picker dialog |
| 534 | */ | 532 | */ |
| 535 | private void handleAnaDatePicker() { | 533 | private void handleAnaDatePicker() { |
| 536 | 534 | ||
| 537 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { | 535 | new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { |
| 538 | @Override | 536 | @Override |
| 539 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { | 537 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { |
| 540 | 538 | ||
| 541 | mCalendar = Calendar.getInstance(); | 539 | mCalendar = Calendar.getInstance(); |
| 542 | mCalendar.set(year, monthOfYear, dayOfMonth); | 540 | mCalendar.set(year, monthOfYear, dayOfMonth); |
| 543 | mAnaYear = year; | 541 | mAnaYear = year; |
| 544 | mAnaMonth = monthOfYear; | 542 | mAnaMonth = monthOfYear; |
| 545 | mAnaDay = dayOfMonth; | 543 | mAnaDay = dayOfMonth; |
| 546 | Date date = mCalendar.getTime(); | 544 | Date date = mCalendar.getTime(); |
| 547 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); | 545 | tvDate.setText(Utils.dateToStringFormatDayMonthYearJp(date)); |
| 548 | mAnaDate = date; | 546 | mAnaDate = date; |
| 549 | getTopPage(mAnaDate, stepType); | 547 | getTopPage(mAnaDate, stepType); |
| 550 | } | 548 | } |
| 551 | }, mAnaYear, mAnaMonth, mAnaDay).show(); | 549 | }, mAnaYear, mAnaMonth, mAnaDay).show(); |
| 552 | 550 | ||
| 553 | } | 551 | } |
| 554 | 552 | ||
| 555 | 553 | ||
| 556 | private void updateUI(){ | 554 | private void updateUI(){ |
| 557 | Debug.normal("Step total================ "+ stepTotal); | 555 | Debug.normal("Step total================ "+ stepTotal); |
| 558 | int stepRemain = stepGoal - stepTotal; | 556 | int stepRemain = stepGoal - stepTotal; |
| 559 | double percentDone = stepTotal *100.0 / stepGoal; | 557 | double percentDone = stepTotal *100.0 / stepGoal; |
| 560 | stepsView.setText(String.valueOf(stepTotal)); | 558 | stepsView.setText(String.valueOf(stepTotal)); |
| 561 | tvStepRemain.setText(String.valueOf(stepRemain)); | 559 | tvStepRemain.setText(String.valueOf(stepRemain)); |
| 562 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone))); | 560 | tvStepRateDone.setText(getResources().getString(R.string.percent_unit, Utils.convert2String2Decimal(percentDone))); |
| 563 | tvSmallRemain.setText(String.valueOf(stepRemain)); | 561 | tvSmallRemain.setText(String.valueOf(stepRemain)); |
| 564 | } | 562 | } |
| 565 | 563 | ||
| 566 | @Override | 564 | @Override |
| 567 | public void onAttach(Context context) { | 565 | public void onAttach(Context context) { |
| 568 | super.onAttach(context); | 566 | super.onAttach(context); |
| 569 | 567 | ||
| 570 | } | 568 | } |
| 571 | 569 | ||
| 572 | @Override | 570 | @Override |
| 573 | public void onSaveData() { | 571 | public void onSaveData() { |
| 574 | 572 | ||
| 575 | } | 573 | } |
| 576 | 574 | ||
| 577 | @Override | 575 | @Override |
| 578 | public void onInvalidate(boolean isInit) { | 576 | public void onInvalidate(boolean isInit) { |
| 579 | initData(); | 577 | initData(); |
| 580 | } | 578 | } |
| 581 | 579 | ||
| 582 | @Override | 580 | @Override |
| 583 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { | 581 | public void onViewStateRestored(@Nullable Bundle savedInstanceState) { |
| 584 | super.onViewStateRestored(savedInstanceState); | 582 | super.onViewStateRestored(savedInstanceState); |
| 585 | 583 | ||
| 586 | initData(); | 584 | initData(); |
| 587 | } | 585 | } |
| 588 | 586 | ||
| 589 | 587 | ||
| 590 | @Override | 588 | @Override |
| 591 | public void onResume() { | 589 | public void onResume() { |
| 592 | super.onResume(); | 590 | super.onResume(); |
| 593 | activityRunning = true; | 591 | activityRunning = true; |
| 594 | Debug.normal("Today: "+ "Onresume "); | 592 | Debug.normal("Today: "+ "Onresume "); |
| 595 | Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); | 593 | Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); |
| 596 | if (countSensor != null) { | 594 | if (countSensor != null) { |
| 597 | Debug.normal("Today: "+ "countSensor not null "); | 595 | Debug.normal("Today: "+ "countSensor not null "); |
| 598 | sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); | 596 | sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); |
| 599 | } else { | 597 | } else { |
| 600 | Debug.normal("Today: "+ "countSensor is null "); | 598 | Debug.normal("Today: "+ "countSensor is null "); |
| 601 | Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show(); | 599 | Toast.makeText(mContext, getResources().getString(R.string.sensor_available), Toast.LENGTH_SHORT).show(); |
| 602 | } | 600 | } |
| 603 | } | 601 | } |
| 604 | 602 | ||
| 605 | @Override | 603 | @Override |
| 606 | public void onSensorChanged(SensorEvent event) { | 604 | public void onSensorChanged(SensorEvent event) { |
| 607 | Debug.normal("Sensor count step active"); | 605 | Debug.normal("Sensor count step active"); |
| 608 | if (activityRunning){ | 606 | if (activityRunning){ |
| 609 | stepCount = (int) event.values[0]; | 607 | stepCount = (int) event.values[0]; |
| 610 | Debug.normal("Step change: "+ stepCount); | 608 | Debug.normal("Step change: "+ stepCount); |
| 611 | stepTotal++; | 609 | stepTotal++; |
| 612 | // update UI | 610 | // update UI |
| 613 | updateUI(); | 611 | updateUI(); |
| 614 | } | 612 | } |
| 615 | } | 613 | } |
| 616 | 614 | ||
| 617 | @Override | 615 | @Override |
| 618 | public void onAccuracyChanged(Sensor sensor, int accuracy) { | 616 | public void onAccuracyChanged(Sensor sensor, int accuracy) { |
| 619 | 617 | ||
| 620 | } | 618 | } |
| 621 | 619 | ||
| 622 | @Override | 620 | @Override |
| 623 | public void onPause() { | 621 | public void onPause() { |
| 624 | super.onPause(); | 622 | super.onPause(); |
| 625 | activityRunning = false; | 623 | activityRunning = false; |
| 626 | Debug.normal("Start create log"); | 624 | Debug.normal("Start create log"); |
| 627 | mToDate = new Date(); | 625 | mToDate = new Date(); |
| 628 | if (sensorManager != null) { | 626 | if (sensorManager != null) { |
| 629 | sensorManager.unregisterListener(this); | 627 | sensorManager.unregisterListener(this); |
| 630 | } | 628 | } |
| 631 | // create log step | 629 | // create log step |
| 632 | creatLogStep(); | 630 | creatLogStep(); |
| 633 | } | 631 | } |
| 634 | 632 | ||
| 635 | @Override | 633 | @Override |
| 636 | public void onDestroy() { | 634 | public void onDestroy() { |
| 637 | super.onDestroy(); | 635 | super.onDestroy(); |
| 638 | } | 636 | } |
| 639 | 637 | ||
| 640 | private void creatLogStep(){ | 638 | private void creatLogStep(){ |
| 641 | Debug.normal("Today: "+ "Create log "+ stepCount); | 639 | Debug.normal("Today: "+ "Create log "+ stepCount); |
| 642 | 640 | ||
| 643 | ApiServices.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() { | 641 | ApiServices.createLog(stepType, stepCount, mFromDate, mToDate, new LLAPIManagerListener() { |
| 644 | @Override | 642 | @Override |
| 645 | public void onError(Error error) { | 643 | public void onError(Error error) { |
| 646 | Debug.error("Get data history error"); | 644 | Debug.error("Get data history error"); |
| 647 | } | 645 | } |
| 648 | 646 | ||
| 649 | @Override | 647 | @Override |
| 650 | public void onSuccess(String json) { | 648 | public void onSuccess(String json) { |
| 651 | Debug.error("Get data history success"); | 649 | Debug.error("Get data history success"); |
| 652 | } | 650 | } |
| 653 | 651 | ||
| 654 | @Override | 652 | @Override |
| 655 | public void onSuccess(JSONObject object) { | 653 | public void onSuccess(JSONObject object) { |
| 656 | Debug.error("Get data history success"); | 654 | Debug.error("Get data history success"); |
| 657 | } | 655 | } |
| 658 | }); | 656 | }); |
| 659 | } | 657 | } |
| 660 | 658 | ||
| 661 | 659 | ||
| 662 | 660 | ||
| 663 | } | 661 | } |
| 664 | 662 |
build.gradle
| 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. | 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. |
| 2 | 2 | ||
| 3 | buildscript { | 3 | buildscript { |
| 4 | repositories { | 4 | repositories { |
| 5 | jcenter() | 5 | jcenter() |
| 6 | maven { | 6 | maven { |
| 7 | url 'https://maven.google.com/' | 7 | url 'https://maven.google.com/' |
| 8 | name 'Google' | 8 | name 'Google' |
| 9 | } | 9 | } |
| 10 | } | 10 | } |
| 11 | dependencies { | 11 | dependencies { |
| 12 | classpath 'com.android.tools.build:gradle:3.0.0' | 12 | classpath 'com.android.tools.build:gradle:2.3.3' |
| 13 | 13 | ||
| 14 | // NOTE: Do not place your application dependencies here; they belong | 14 | // NOTE: Do not place your application dependencies here; they belong |
| 15 | // in the individual module build.gradle files | 15 | // in the individual module build.gradle files |
| 16 | } | 16 | } |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | allprojects { | 19 | allprojects { |
| 20 | repositories { | 20 | repositories { |
| 21 | jcenter() | 21 | jcenter() |
| 22 | maven { url "https://jitpack.io" } | 22 | maven { url "https://jitpack.io" } |
| 23 | maven { | 23 | maven { |
| 24 | url 'https://maven.google.com/' | 24 | url 'https://maven.google.com/' |
| 25 | name 'Google' | 25 | name 'Google' |
| 26 | } | 26 | } |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | task clean(type: Delete) { | 30 | task clean(type: Delete) { |
| 31 | delete rootProject.buildDir | 31 | delete rootProject.buildDir |
| 32 | } | 32 | } |
| 33 | 33 |