Commit 9c431985f72992e326242adb85697b35bb2a132b

Authored by Dinh Chu
1 parent 260f822ff9
Exists in master

ipdate

Showing 8 changed files with 266 additions and 52 deletions Inline Diff

app/src/main/AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.dinhcv.lifelogpedometer"> 3 package="com.dinhcv.lifelogpedometer">
4 4
5 <uses-feature 5 <uses-feature
6 android:name="android.hardware.sensor.stepcounter" 6 android:name="android.hardware.sensor.stepcounter"
7 android:required="true" /> 7 android:required="true" />
8 8
9 <uses-permission android:name="android.permission.INTERNET" /> 9 <uses-permission android:name="android.permission.INTERNET" />
10 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 10 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
11 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 11 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
12 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 12 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
13 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
13 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 14 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
14 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 15 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
15 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 16 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
16 17
17 <application 18 <application
18 android:name=".LifeLogApplication" 19 android:name=".LifeLogApplication"
19 android:allowBackup="true" 20 android:allowBackup="true"
20 android:icon="@mipmap/ic_launcher" 21 android:icon="@mipmap/ic_launcher"
21 android:label="@string/app_name" 22 android:label="@string/app_name"
22 android:roundIcon="@mipmap/ic_launcher_round" 23 android:roundIcon="@mipmap/ic_launcher_round"
23 android:supportsRtl="true" 24 android:supportsRtl="true"
24 android:largeHeap="true" 25 android:largeHeap="true"
25 android:theme="@style/AppTheme"> 26 android:theme="@style/AppTheme">
26 <meta-data 27 <meta-data
27 android:name="com.google.android.maps.v2.API_KEY" 28 android:name="com.google.android.maps.v2.API_KEY"
28 android:value="AIzaSyCDKYsvb0iDXSRm9YnQ8kh5Gzpbpzcpz4s" /> 29 android:value="AIzaSyCDKYsvb0iDXSRm9YnQ8kh5Gzpbpzcpz4s" />
29 30
30 <activity 31 <activity
31 android:name=".activity.WelcomeActivity" 32 android:name=".activity.WelcomeActivity"
32 android:screenOrientation="portrait" 33 android:screenOrientation="portrait"
33 android:theme="@style/AppNoActionBar"> 34 android:theme="@style/AppNoActionBar">
34 <intent-filter> 35 <intent-filter>
35 <action android:name="android.intent.action.MAIN" /> 36 <action android:name="android.intent.action.MAIN" />
36 37
37 <category android:name="android.intent.category.LAUNCHER" /> 38 <category android:name="android.intent.category.LAUNCHER" />
38 </intent-filter> 39 </intent-filter>
39 </activity> 40 </activity>
40 <activity 41 <activity
41 android:name=".activity.LoginActivity" 42 android:name=".activity.LoginActivity"
42 android:screenOrientation="portrait" 43 android:screenOrientation="portrait"
43 android:theme="@style/AppNoActionBar"/> 44 android:theme="@style/AppNoActionBar"/>
44 45
45 <activity 46 <activity
46 android:name=".activity.PedometerActivity" 47 android:name=".activity.PedometerActivity"
47 android:screenOrientation="portrait" 48 android:screenOrientation="portrait"
48 android:theme="@style/AppNoActionBar"/> 49 android:theme="@style/AppNoActionBar"/>
49 <activity 50 <activity
50 android:name=".activity.RegisterActivity" 51 android:name=".activity.RegisterActivity"
51 android:screenOrientation="portrait" 52 android:screenOrientation="portrait"
52 android:theme="@style/AppNoActionBar"/> 53 android:theme="@style/AppNoActionBar"/>
53 <activity 54 <activity
54 android:name=".activity.InputConfirmCodeActivity" 55 android:name=".activity.InputConfirmCodeActivity"
55 android:screenOrientation="portrait" 56 android:screenOrientation="portrait"
56 android:theme="@style/AppNoActionBar"/> 57 android:theme="@style/AppNoActionBar"/>
57 58
58 59
59 <!--<activity--> 60 <!--<activity-->
60 <!--android:name=".activity.HistoryFragment"--> 61 <!--android:name=".activity.HistoryFragment"-->
61 <!--android:screenOrientation="portrait"--> 62 <!--android:screenOrientation="portrait"-->
62 <!--android:theme="@style/AppNoActionBar"></activity>--> 63 <!--android:theme="@style/AppNoActionBar"></activity>-->
63 64
64 </application> 65 </application>
65 66
66 </manifest> 67 </manifest>
app/src/main/java/com/dinhcv/lifelogpedometer/activity/PedometerActivity.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.Manifest; 3 import android.Manifest;
4 import android.content.Context; 4 import android.content.Context;
5 import android.content.Intent; 5 import android.content.Intent;
6 import android.os.Build; 6 import android.os.Build;
7 import android.os.Bundle; 7 import android.os.Bundle;
8 import android.support.design.widget.TabLayout; 8 import android.support.design.widget.TabLayout;
9 import android.support.v4.app.Fragment; 9 import android.support.v4.app.Fragment;
10 import android.support.v4.app.FragmentManager; 10 import android.support.v4.app.FragmentManager;
11 import android.support.v4.app.FragmentPagerAdapter; 11 import android.support.v4.app.FragmentPagerAdapter;
12 import android.support.v4.content.PermissionChecker; 12 import android.support.v4.content.PermissionChecker;
13 import android.support.v4.view.ViewPager; 13 import android.support.v4.view.ViewPager;
14 import android.support.v7.widget.PopupMenu; 14 import android.support.v7.widget.PopupMenu;
15 import android.support.v7.widget.Toolbar; 15 import android.support.v7.widget.Toolbar;
16 import android.view.Gravity; 16 import android.view.Gravity;
17 import android.view.LayoutInflater; 17 import android.view.LayoutInflater;
18 import android.view.MenuItem; 18 import android.view.MenuItem;
19 import android.view.View; 19 import android.view.View;
20 import android.view.Window; 20 import android.view.Window;
21 import android.view.WindowManager; 21 import android.view.WindowManager;
22 import android.widget.ImageView; 22 import android.widget.ImageView;
23 import android.widget.PopupWindow; 23 import android.widget.PopupWindow;
24 import android.widget.TabHost; 24 import android.widget.TabHost;
25 import android.widget.TextView; 25 import android.widget.TextView;
26 import android.widget.Toast; 26 import android.widget.Toast;
27 27
28 import com.dinhcv.lifelogpedometer.R; 28 import com.dinhcv.lifelogpedometer.R;
29 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; 29 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
30 import com.dinhcv.lifelogpedometer.portal.APIResponse;
30 import com.dinhcv.lifelogpedometer.utils.Debug; 31 import com.dinhcv.lifelogpedometer.utils.Debug;
31 import com.dinhcv.lifelogpedometer.utils.Utils; 32 import com.dinhcv.lifelogpedometer.utils.Utils;
32 33
33 import java.util.ArrayList; 34 import java.util.ArrayList;
34 import java.util.List; 35 import java.util.List;
35 36
36 public class PedometerActivity extends ActivityBase { 37 public class PedometerActivity extends ActivityBase {
37 private Toolbar mToolBar; 38 private Toolbar mToolBar;
38 private ViewPager mViewPager; 39 private ViewPager mViewPager;
39 private int mCurrentTab = 0; 40 private int mCurrentTab = 0;
40 private TabLayout mTabLayout; 41 private TabLayout mTabLayout;
41 private TextView tvPageTitle; 42 private TextView tvPageTitle;
42 private ImageView ivHome; 43 private ImageView ivHome;
43 private ImageView imvMenu; 44 private ImageView imvMenu;
44 45
45 private TopFragment mTopFragment; 46 private TopFragment mTopFragment;
46 private HistoryFragment mHistoryFragment; 47 private HistoryFragment mHistoryFragment;
47 private SnsFragment mSnsFragment; 48 private SnsFragment mSnsFragment;
48 49
49 private int[] tabIcons = { 50 private int[] tabIcons = {
50 R.drawable.today_ic, 51 R.drawable.today_ic,
51 R.drawable.history_ic, 52 R.drawable.history_ic,
52 R.drawable.rank_ic, 53 R.drawable.rank_ic,
53 R.drawable.map_ic, 54 R.drawable.map_ic,
54 R.drawable.sns_ic 55 R.drawable.sns_ic
55 }; 56 };
56 57
57 public enum TAB { 58 public enum TAB {
58 DATE_TAB(0), 59 DATE_TAB(0),
59 HISTORY_TAB(1), 60 HISTORY_TAB(1),
60 RANK_TAB(2), 61 RANK_TAB(2),
61 MAP_TAB(3), 62 MAP_TAB(3),
62 SNS_TAB(4); 63 SNS_TAB(4);
63 64
64 private final int index; 65 private final int index;
65 66
66 TAB(int index) { 67 TAB(int index) {
67 this.index = index; 68 this.index = index;
68 } 69 }
69 70
70 public int getValue() { 71 public int getValue() {
71 return index; 72 return index;
72 } 73 }
73 } 74 }
74 75
75 @Override 76 @Override
76 protected void onCreate(Bundle savedInstanceState) { 77 protected void onCreate(Bundle savedInstanceState) {
77 super.onCreate(savedInstanceState); 78 super.onCreate(savedInstanceState);
78 79
79 setContentView(R.layout.activity_pedometer); 80 setContentView(R.layout.activity_pedometer);
80 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 81 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
81 82
82 initView(); 83 initView();
83 84
84 if (android.support.v4.BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker 85 if (android.support.v4.BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker
85 .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != 86 .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
86 PermissionChecker.PERMISSION_GRANTED) { 87 PermissionChecker.PERMISSION_GRANTED) {
87 requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); 88 requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
88 } 89 }
89 } 90 }
90 91
91 private void initView() { 92 private void initView() {
92 93
93 tvPageTitle = (TextView) findViewById(R.id.tv_pageTitle); 94 tvPageTitle = (TextView) findViewById(R.id.tv_pageTitle);
94 ivHome = (ImageView) findViewById(R.id.iv_home); 95 ivHome = (ImageView) findViewById(R.id.iv_home);
95 imvMenu = (ImageView) findViewById(R.id.imv_menu); 96 imvMenu = (ImageView) findViewById(R.id.imv_menu);
96 97
97 mViewPager = (ViewPager) findViewById(R.id.viewpager); 98 mViewPager = (ViewPager) findViewById(R.id.viewpager);
98 mViewPager.setOffscreenPageLimit(5); 99 mViewPager.setOffscreenPageLimit(5);
99 setupViewPager(mViewPager); 100 setupViewPager(mViewPager);
100 mTabLayout = (TabLayout) findViewById(R.id.tabs); 101 mTabLayout = (TabLayout) findViewById(R.id.tabs);
101 mTabLayout.setupWithViewPager(mViewPager); 102 mTabLayout.setupWithViewPager(mViewPager);
102 //Set tab selected 103 //Set tab selected
103 TabLayout.Tab tab = mTabLayout.getTabAt(mCurrentTab); 104 TabLayout.Tab tab = mTabLayout.getTabAt(mCurrentTab);
104 if (tab != null) { 105 if (tab != null) {
105 tab.select(); 106 tab.select();
106 } 107 }
107 //mTabLayout.addTab(); 108 //mTabLayout.addTab();
108 View view1 = getLayoutInflater().inflate(R.layout.customtab, null); 109 View view1 = getLayoutInflater().inflate(R.layout.customtab, null);
109 view1.findViewById(R.id.icon).setBackgroundResource(R.drawable.today_ic); 110 view1.findViewById(R.id.icon).setBackgroundResource(R.drawable.today_ic);
110 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view1)); 111 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view1));
111 112
112 113
113 View view2 = getLayoutInflater().inflate(R.layout.customtab, null); 114 View view2 = getLayoutInflater().inflate(R.layout.customtab, null);
114 view2.findViewById(R.id.icon).setBackgroundResource(R.drawable.history_ic); 115 view2.findViewById(R.id.icon).setBackgroundResource(R.drawable.history_ic);
115 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view2)); 116 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view2));
116 117
117 118
118 View view3 = getLayoutInflater().inflate(R.layout.customtab, null); 119 View view3 = getLayoutInflater().inflate(R.layout.customtab, null);
119 view3.findViewById(R.id.icon).setBackgroundResource(R.drawable.rank_ic); 120 view3.findViewById(R.id.icon).setBackgroundResource(R.drawable.rank_ic);
120 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view3)); 121 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view3));
121 122
122 123
123 View view4 = getLayoutInflater().inflate(R.layout.customtab, null); 124 View view4 = getLayoutInflater().inflate(R.layout.customtab, null);
124 view4.findViewById(R.id.icon).setBackgroundResource(R.drawable.map_ic); 125 view4.findViewById(R.id.icon).setBackgroundResource(R.drawable.map_ic);
125 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view4)); 126 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view4));
126 127
127 128
128 View view5 = getLayoutInflater().inflate(R.layout.customtab, null); 129 View view5 = getLayoutInflater().inflate(R.layout.customtab, null);
129 view5.findViewById(R.id.icon).setBackgroundResource(R.drawable.sns_ic); 130 view5.findViewById(R.id.icon).setBackgroundResource(R.drawable.sns_ic);
130 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view5)); 131 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view5));
131 132
132 133
133 mTabLayout.getTabAt(0).setCustomView(view1); 134 mTabLayout.getTabAt(0).setCustomView(view1);
134 mTabLayout.getTabAt(1).setCustomView(view2); 135 mTabLayout.getTabAt(1).setCustomView(view2);
135 mTabLayout.getTabAt(2).setCustomView(view3); 136 mTabLayout.getTabAt(2).setCustomView(view3);
136 mTabLayout.getTabAt(3).setCustomView(view4); 137 mTabLayout.getTabAt(3).setCustomView(view4);
137 mTabLayout.getTabAt(4).setCustomView(view5); 138 mTabLayout.getTabAt(4).setCustomView(view5);
138 139
139 changeColorStatusBar(); 140 changeColorStatusBar();
140 //setupTabIcons(); 141 //setupTabIcons();
141 142
142 //SonLT Add 143 //SonLT Add
143 ivHome.setOnClickListener(new View.OnClickListener() { 144 ivHome.setOnClickListener(new View.OnClickListener() {
144 @Override 145 @Override
145 public void onClick(View v) { 146 public void onClick(View v) {
146 switch (mCurrentTab){ 147 switch (mCurrentTab){
147 case 0: mTopFragment.clickBackToHome(); break; 148 case 0: mTopFragment.clickBackToHome(); break;
148 case 1: mHistoryFragment.clickBackToHome(); break; 149 case 1: mHistoryFragment.clickBackToHome(); break;
149 case 4: mSnsFragment.handleToolbarClick(0); break; 150 case 4: mSnsFragment.handleToolbarClick(0); break;
150 default: break; 151 default: break;
151 } 152 }
152 } 153 }
153 }); 154 });
154 155
155 imvMenu.setOnClickListener(new View.OnClickListener() { 156 imvMenu.setOnClickListener(new View.OnClickListener() {
156 @Override 157 @Override
157 public void onClick(View v) { 158 public void onClick(View v) {
158 //Creating the instance of PopupMenu 159 //Creating the instance of PopupMenu
159 PopupMenu popup = new PopupMenu(PedometerActivity.this, imvMenu); 160 PopupMenu popup = new PopupMenu(PedometerActivity.this, imvMenu);
160 //Inflating the Popup using xml file 161 //Inflating the Popup using xml file
161 popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); 162 popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
162 163
163 //registering popup with OnMenuItemClickListener 164 //registering popup with OnMenuItemClickListener
164 popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 165 popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
165 public boolean onMenuItemClick(MenuItem item) { 166 public boolean onMenuItemClick(MenuItem item) {
166 switch (item.getItemId()){ 167 switch (item.getItemId()){
167 case R.id.action_setting: 168 case R.id.action_setting:
168 Toast.makeText( 169 Toast.makeText(
169 PedometerActivity.this, 170 PedometerActivity.this,
170 "Have not spec : " + item.getTitle(), 171 "Have not spec : " + item.getTitle(),
171 Toast.LENGTH_SHORT 172 Toast.LENGTH_SHORT
172 ).show(); 173 ).show();
173 break; 174 break;
174 case R.id.action_profile: 175 case R.id.action_profile:
175 Toast.makeText( 176 Toast.makeText(
176 PedometerActivity.this, 177 PedometerActivity.this,
177 "Have not spec : " + item.getTitle(), 178 "Have not spec : " + item.getTitle(),
178 Toast.LENGTH_SHORT 179 Toast.LENGTH_SHORT
179 ).show(); 180 ).show();
180 break; 181 break;
181 case R.id.action_logout: 182 case R.id.action_logout:
182 logout(); 183 logout();
183 break; 184 break;
184 default: 185 default:
185 Debug.warn("Not run here"); 186 Debug.warn("Not run here");
186 break; 187 break;
187 } 188 }
188 189
189 return true; 190 return true;
190 } 191 }
191 }); 192 });
192 193
193 popup.show(); //showing popup menu 194 popup.show(); //showing popup menu
194 } 195 }
195 }); //closing the setOnClickListener method 196 }); //closing the setOnClickListener method
196 } 197 }
197 198
198 public TabHost.TabSpec setIndicator(Context ctx, TabHost.TabSpec spec, int viewId, int resId, String name) { 199 public TabHost.TabSpec setIndicator(Context ctx, TabHost.TabSpec spec, int viewId, int resId, String name) {
199 View v = LayoutInflater.from(ctx).inflate(R.layout.customtab, null); 200 View v = LayoutInflater.from(ctx).inflate(R.layout.customtab, null);
200 ImageView imgTab = (ImageView) v.findViewById(viewId); 201 ImageView imgTab = (ImageView) v.findViewById(viewId);
201 imgTab.setImageDrawable(getResources().getDrawable(resId)); 202 imgTab.setImageDrawable(getResources().getDrawable(resId));
202 203
203 return spec.setIndicator(v); 204 return spec.setIndicator(v);
204 } 205 }
205 206
206 private void setupTabIcons() { 207 private void setupTabIcons() {
207 mTabLayout.getTabAt(0).setCustomView(tabIcons[0]); 208 mTabLayout.getTabAt(0).setCustomView(tabIcons[0]);
208 mTabLayout.getTabAt(1).setIcon(tabIcons[1]); 209 mTabLayout.getTabAt(1).setIcon(tabIcons[1]);
209 mTabLayout.getTabAt(2).setIcon(tabIcons[2]); 210 mTabLayout.getTabAt(2).setIcon(tabIcons[2]);
210 mTabLayout.getTabAt(3).setIcon(tabIcons[3]); 211 mTabLayout.getTabAt(3).setIcon(tabIcons[3]);
211 mTabLayout.getTabAt(4).setIcon(tabIcons[4]); 212 mTabLayout.getTabAt(4).setIcon(tabIcons[4]);
212 } 213 }
213 214
214 215
215 private void setTabView() { 216 private void setTabView() {
216 217
217 for (int i = 0; i < mTabLayout.getTabCount(); i++) { 218 for (int i = 0; i < mTabLayout.getTabCount(); i++) {
218 TextView tv = (TextView) mTabLayout.getChildAt(0).findViewById(android.R.id.title); 219 TextView tv = (TextView) mTabLayout.getChildAt(0).findViewById(android.R.id.title);
219 //tv.setTextColor(Color.BLACK); 220 //tv.setTextColor(Color.BLACK);
220 tv.setPadding(10, 10, 10, 15); 221 tv.setPadding(10, 10, 10, 15);
221 tv.setTextSize((float) 20.0); 222 tv.setTextSize((float) 20.0);
222 //tv.setTypeface(null, Typeface.BOLD); 223 //tv.setTypeface(null, Typeface.BOLD);
223 //tv.setBackgroundResource(R.drawable.icon); 224 //tv.setBackgroundResource(R.drawable.icon);
224 tv.setHeight(100); 225 tv.setHeight(100);
225 tv.setWidth(100); 226 tv.setWidth(100);
226 } 227 }
227 228
228 } 229 }
229 230
230 private void changeColorStatusBar() { 231 private void changeColorStatusBar() {
231 if (android.os.Build.VERSION.SDK_INT >= 21) { 232 if (android.os.Build.VERSION.SDK_INT >= 21) {
232 Window window = this.getWindow(); 233 Window window = this.getWindow();
233 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 234 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
234 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 235 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
235 // window.setStatusBarColor(Utils.getColorWrapper(this, R.color.white)); 236 // window.setStatusBarColor(Utils.getColorWrapper(this, R.color.white));
236 } 237 }
237 } 238 }
238 239
239 // @Override 240 // @Override
240 // public boolean onCreateOptionsMenu(Menu menu) { 241 // public boolean onCreateOptionsMenu(Menu menu) {
241 // getMenuInflater().inflate(R.menu.setting_menu, menu); 242 // getMenuInflater().inflate(R.menu.setting_menu, menu);
242 // return true; 243 // return true;
243 // } 244 // }
244 245
245 @Override 246 @Override
246 public boolean onOptionsItemSelected(MenuItem item) { 247 public boolean onOptionsItemSelected(MenuItem item) {
247 return super.onOptionsItemSelected(item); 248 return super.onOptionsItemSelected(item);
248 } 249 }
249 250
250 /** 251 /**
251 * Setup pager 252 * Setup pager
252 * 253 *
253 * @param viewPager: view pager 254 * @param viewPager: view pager
254 */ 255 */
255 private void setupViewPager(ViewPager viewPager) { 256 private void setupViewPager(ViewPager viewPager) {
256 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 257 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
257 mTopFragment = new TopFragment(); 258 mTopFragment = new TopFragment();
258 adapter.addFragment(mTopFragment, getString(R.string.date)); 259 adapter.addFragment(mTopFragment, getString(R.string.date));
259 mHistoryFragment = new HistoryFragment(); 260 mHistoryFragment = new HistoryFragment();
260 adapter.addFragment(mHistoryFragment, getString(R.string.history)); 261 adapter.addFragment(mHistoryFragment, getString(R.string.history));
261 adapter.addFragment(new RankFragment(), getString(R.string.ranking)); 262 adapter.addFragment(new RankFragment(), getString(R.string.ranking));
262 adapter.addFragment(new MapFragment(), getString(R.string.map)); 263 adapter.addFragment(new MapFragment(), getString(R.string.map));
263 mSnsFragment = new SnsFragment(); 264 mSnsFragment = new SnsFragment();
264 adapter.addFragment(mSnsFragment, getString(R.string.sns)); 265 adapter.addFragment(mSnsFragment, getString(R.string.sns));
265 viewPager.setAdapter(adapter); 266 viewPager.setAdapter(adapter);
266 } 267 }
267 268
268 /** 269 /**
269 * Class FragmentPagerAdapter 270 * Class FragmentPagerAdapter
270 */ 271 */
271 class ViewPagerAdapter extends FragmentPagerAdapter { 272 class ViewPagerAdapter extends FragmentPagerAdapter {
272 private final List<Fragment> mFragmentList = new ArrayList<>(); 273 private final List<Fragment> mFragmentList = new ArrayList<>();
273 private final List<String> mFragmentTitleList = new ArrayList<>(); 274 private final List<String> mFragmentTitleList = new ArrayList<>();
274 275
275 public ViewPagerAdapter(FragmentManager manager) { 276 public ViewPagerAdapter(FragmentManager manager) {
276 super(manager); 277 super(manager);
277 } 278 }
278 279
279 @Override 280 @Override
280 public Fragment getItem(int position) { 281 public Fragment getItem(int position) {
281 return mFragmentList.get(position); 282 return mFragmentList.get(position);
282 } 283 }
283 284
284 @Override 285 @Override
285 public int getCount() { 286 public int getCount() {
286 return mFragmentList.size(); 287 return mFragmentList.size();
287 } 288 }
288 289
289 private void addFragment(Fragment fragment, String title) { 290 private void addFragment(Fragment fragment, String title) {
290 mFragmentList.add(fragment); 291 mFragmentList.add(fragment);
291 mFragmentTitleList.add(title); 292 mFragmentTitleList.add(title);
292 } 293 }
293 294
294 @Override 295 @Override
295 public CharSequence getPageTitle(int position) { 296 public CharSequence getPageTitle(int position) {
296 //return mFragmentTitleList.get(position); 297 //return mFragmentTitleList.get(position);
297 return null; 298 return null;
298 } 299 }
299 } 300 }
300 301
301 @Override 302 @Override
302 protected void onResume() { 303 protected void onResume() {
303 super.onResume(); 304 super.onResume();
304 mViewPager.addOnPageChangeListener(mPageChangeListener); 305 mViewPager.addOnPageChangeListener(mPageChangeListener);
305 } 306 }
306 307
307 @Override 308 @Override
308 protected void onPause() { 309 protected void onPause() {
309 super.onPause(); 310 super.onPause();
310 mViewPager.removeOnPageChangeListener(mPageChangeListener); 311 mViewPager.removeOnPageChangeListener(mPageChangeListener);
311 } 312 }
312 313
313 private int mLastTab = 0; 314 private int mLastTab = 0;
314 private final ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager 315 private final ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager
315 .OnPageChangeListener 316 .OnPageChangeListener
316 () { 317 () {
317 @Override 318 @Override
318 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 319 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
319 //Nothing here 320 //Nothing here
320 } 321 }
321 322
322 @Override 323 @Override
323 public void onPageSelected(int position) { 324 public void onPageSelected(int position) {
324 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter(); 325 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
325 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter.getItem 326 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter.getItem
326 (position); 327 (position);
327 328
328 switch (position) { 329 switch (position) {
329 case 4: 330 case 4:
330 tvPageTitle.setText(getString(R.string.sns_fragment)); 331 tvPageTitle.setText(getString(R.string.sns_fragment));
331 ivHome.setVisibility(View.VISIBLE); 332 ivHome.setVisibility(View.VISIBLE);
332 break; 333 break;
333 case 1: 334 case 1:
334 tvPageTitle.setText(getString(R.string.today)); 335 tvPageTitle.setText(getString(R.string.today));
335 ivHome.setVisibility(View.VISIBLE); 336 ivHome.setVisibility(View.VISIBLE);
336 break; 337 break;
337 338
338 case 0: 339 case 0:
339 tvPageTitle.setText(getString(R.string.home)); 340 tvPageTitle.setText(getString(R.string.home));
340 ivHome.setVisibility(View.GONE); 341 ivHome.setVisibility(View.GONE);
341 break; 342 break;
342 343
343 default: 344 default:
344 tvPageTitle.setText(getString(R.string.home)); 345 tvPageTitle.setText(getString(R.string.home));
345 ivHome.setVisibility(View.GONE); 346 ivHome.setVisibility(View.GONE);
346 break; 347 break;
347 } 348 }
348 // if (position == 1){ 349 // if (position == 1){
349 // tvPageTitle.setText(getString(R.string.today)); 350 // tvPageTitle.setText(getString(R.string.today));
350 // ivHome.setVisibility(View.VISIBLE); 351 // ivHome.setVisibility(View.VISIBLE);
351 // }else { 352 // }else {
352 // tvPageTitle.setText(getString(R.string.home)); 353 // tvPageTitle.setText(getString(R.string.home));
353 // ivHome.setVisibility(View.GONE); 354 // ivHome.setVisibility(View.GONE);
354 // } 355 // }
355 356
356 presenter.onInvalidate(false); 357 presenter.onInvalidate(false);
357 mLastTab = position; 358 mLastTab = position;
358 mCurrentTab = position; 359 mCurrentTab = position;
359 } 360 }
360 361
361 @Override 362 @Override
362 public void onPageScrollStateChanged(int state) { 363 public void onPageScrollStateChanged(int state) {
363 //Nothing here 364 //Nothing here
364 if (state == ViewPager.SCROLL_STATE_SETTLING) { 365 if (state == ViewPager.SCROLL_STATE_SETTLING) {
365 if (mLastTab >= 0) { 366 if (mLastTab >= 0) {
366 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter(); 367 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
367 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter 368 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter
368 .getItem(mLastTab); 369 .getItem(mLastTab);
369 370
370 Debug.normal("Save data in tab:" + mLastTab); 371 Debug.normal("Save data in tab:" + mLastTab);
371 presenter.onSaveData(); 372 presenter.onSaveData();
372 } 373 }
373 } 374 }
374 } 375 }
375 }; 376 };
376 377
377 public void setVisibleIconHome(boolean isVisible){ 378 public void setVisibleIconHome(boolean isVisible){
378 if (isVisible) { 379 if (isVisible) {
379 ivHome.setVisibility(View.VISIBLE); 380 ivHome.setVisibility(View.VISIBLE);
380 }else { 381 }else {
381 ivHome.setVisibility(View.GONE); 382 ivHome.setVisibility(View.GONE);
382 } 383 }
383 384
384 setTitleTop(isVisible); 385 setTitleTop(isVisible);
385 } 386 }
386 387
387 public void setTitleTop(boolean isVisible){ 388 public void setTitleTop(boolean isVisible){
388 if (isVisible) { 389 if (isVisible) {
389 tvPageTitle.setText(getString(R.string.today)); 390 tvPageTitle.setText(getString(R.string.today));
390 }else { 391 }else {
391 tvPageTitle.setText(getString(R.string.home)); 392 tvPageTitle.setText(getString(R.string.home));
392 } 393 }
393 } 394 }
394 395
395 396
396 397
397 private void logout(){ 398 private void logout(){
398 // clear data 399 // clear data
399 Setting.clearUserIdSharepre(PedometerActivity.this); 400 Setting.clearUserIdSharepre(PedometerActivity.this);
401 APIResponse.getInstance().setToken(null);
400 // go to login 402 // go to login
401 Intent intent = new Intent(PedometerActivity.this, LoginActivity.class); 403 Intent intent = new Intent(PedometerActivity.this, LoginActivity.class);
402 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 404 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
403 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 405 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
404 startActivity(intent); 406 startActivity(intent);
405 } 407 }
406 408
407 } 409 }
408 410
app/src/main/java/com/dinhcv/lifelogpedometer/activity/RegisterActivity.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.app.AlertDialog; 3 import android.app.AlertDialog;
4 import android.app.DatePickerDialog; 4 import android.app.DatePickerDialog;
5 import android.app.ProgressDialog; 5 import android.app.ProgressDialog;
6 import android.content.DialogInterface; 6 import android.content.DialogInterface;
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.graphics.BitmapFactory; 9 import android.graphics.BitmapFactory;
10 import android.net.Uri; 10 import android.net.Uri;
11 import android.os.AsyncTask; 11 import android.os.AsyncTask;
12 import android.os.Bundle; 12 import android.os.Bundle;
13 import android.view.View; 13 import android.view.View;
14 import android.view.WindowManager; 14 import android.view.WindowManager;
15 import android.widget.DatePicker; 15 import android.widget.DatePicker;
16 import android.widget.EditText; 16 import android.widget.EditText;
17 import android.widget.LinearLayout; 17 import android.widget.LinearLayout;
18 import android.widget.TextView; 18 import android.widget.TextView;
19 import android.widget.Toast; 19 import android.widget.Toast;
20 20
21 import com.dinhcv.lifelogpedometer.LifeLogApplication; 21 import com.dinhcv.lifelogpedometer.LifeLogApplication;
22 import com.dinhcv.lifelogpedometer.R; 22 import com.dinhcv.lifelogpedometer.R;
23 import com.dinhcv.lifelogpedometer.customview.SimpleSelectBoxDialogBuilder; 23 import com.dinhcv.lifelogpedometer.customview.SimpleSelectBoxDialogBuilder;
24 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; 24 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
25 import com.dinhcv.lifelogpedometer.interfaces.OnSelectResultListener; 25 import com.dinhcv.lifelogpedometer.interfaces.OnSelectResultListener;
26 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; 26 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
27 import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo; 27 import com.dinhcv.lifelogpedometer.model.structure.RegisterInfo;
28 import com.dinhcv.lifelogpedometer.model.structure.SelectItemInfo; 28 import com.dinhcv.lifelogpedometer.model.structure.SelectItemInfo;
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.Debug; 31 import com.dinhcv.lifelogpedometer.utils.Debug;
32 import com.dinhcv.lifelogpedometer.utils.Utils; 32 import com.dinhcv.lifelogpedometer.utils.Utils;
33 33
34 import org.json.JSONArray; 34 import org.json.JSONArray;
35 import org.json.JSONObject; 35 import org.json.JSONObject;
36 36
37 import java.io.FileNotFoundException; 37 import java.io.FileNotFoundException;
38 import java.io.InputStream; 38 import java.io.InputStream;
39 import java.util.Calendar; 39 import java.util.Calendar;
40 import java.util.Date; 40 import java.util.Date;
41 import java.util.List; 41 import java.util.List;
42 42
43 import butterknife.BindView; 43 import butterknife.BindView;
44 import butterknife.ButterKnife; 44 import butterknife.ButterKnife;
45 import butterknife.OnClick; 45 import butterknife.OnClick;
46 import de.hdodenhof.circleimageview.CircleImageView; 46 import de.hdodenhof.circleimageview.CircleImageView;
47 47
48 public class RegisterActivity extends ActivityBase { 48 public class RegisterActivity extends ActivityBase {
49 49
50 @BindView(R.id.edt_user) 50 @BindView(R.id.edt_user)
51 EditText edtUsername; 51 EditText edtUsername;
52 @BindView(R.id.edt_name) 52 @BindView(R.id.edt_name)
53 EditText edtName; 53 EditText edtName;
54 @BindView(R.id.edt_nickName) 54 @BindView(R.id.edt_nickName)
55 EditText edtNickName; 55 EditText edtNickName;
56 @BindView(R.id.edt_email) 56 @BindView(R.id.edt_email)
57 EditText edtEmail; 57 EditText edtEmail;
58 @BindView(R.id.edt_password) 58 @BindView(R.id.edt_password)
59 EditText edtPassword; 59 EditText edtPassword;
60 @BindView(R.id.edt_confirmPass) 60 @BindView(R.id.edt_confirmPass)
61 EditText edtConfirmPass; 61 EditText edtConfirmPass;
62 @BindView(R.id.tv_sex) 62 @BindView(R.id.tv_sex)
63 TextView tvSex; 63 TextView tvSex;
64 @BindView(R.id.tv_birthday) 64 @BindView(R.id.tv_birthday)
65 TextView tvBirthday; 65 TextView tvBirthday;
66 @BindView(R.id.edt_height) 66 @BindView(R.id.edt_height)
67 EditText edtHeight; 67 EditText edtHeight;
68 @BindView(R.id.edt_weight) 68 @BindView(R.id.edt_weight)
69 EditText edtWeight; 69 EditText edtWeight;
70 @BindView(R.id.edt_bodyFat) 70 @BindView(R.id.edt_bodyFat)
71 EditText edtBodyFat; 71 EditText edtBodyFat;
72 @BindView(R.id.tv_address) 72 @BindView(R.id.tv_address)
73 TextView tvAddress; 73 TextView tvAddress;
74 @BindView(R.id.edt_comment) 74 @BindView(R.id.edt_comment)
75 EditText edtComment; 75 EditText edtComment;
76 76
77 @BindView(R.id.ll_low) 77 @BindView(R.id.ll_low)
78 LinearLayout llLow; 78 LinearLayout llLow;
79 @BindView(R.id.tv_low) 79 @BindView(R.id.tv_low)
80 TextView tvLow; 80 TextView tvLow;
81 @BindView(R.id.ll_mid) 81 @BindView(R.id.ll_mid)
82 LinearLayout llMid; 82 LinearLayout llMid;
83 @BindView(R.id.tv_mid) 83 @BindView(R.id.tv_mid)
84 TextView tvMid; 84 TextView tvMid;
85 @BindView(R.id.ll_hight) 85 @BindView(R.id.ll_hight)
86 LinearLayout llHight; 86 LinearLayout llHight;
87 @BindView(R.id.tv_hight) 87 @BindView(R.id.tv_hight)
88 TextView tvHight; 88 TextView tvHight;
89 @BindView(R.id.profile_image) 89 @BindView(R.id.profile_image)
90 CircleImageView profileImage; 90 CircleImageView profileImage;
91 91
92 private List<SelectItemInfo> sexList; 92 private List<SelectItemInfo> sexList;
93 private List<SelectItemInfo> provinceList; 93 private List<SelectItemInfo> provinceList;
94 private LifeLogApplication mLifeLogApplication; 94 private LifeLogApplication mLifeLogApplication;
95 private SelectItemInfo sexInfo; 95 private SelectItemInfo sexInfo;
96 private SelectItemInfo provinceInfo; 96 private SelectItemInfo provinceInfo;
97 97
98 private Calendar mCalendar; 98 private Calendar mCalendar;
99 private int mDay; 99 private int mDay;
100 private int mMonth; 100 private int mMonth;
101 private int mYear; 101 private int mYear;
102 private Date mBirthDay; 102 private Date mBirthDay;
103 103
104 private int level = 0; 104 private int level = 0;
105 private static final int RESULT_LOAD_IMG = 99; 105 private static final int RESULT_LOAD_IMG = 99;
106 private RegisterInfo mRegisterInfo; 106 private RegisterInfo mRegisterInfo;
107 private String profileImagePath; 107 private String profileImagePath;
108 private ProgressDialog progressDialog; 108 private ProgressDialog progressDialog;
109 109
110 @Override 110 @Override
111 protected void onCreate(Bundle savedInstanceState) { 111 protected void onCreate(Bundle savedInstanceState) {
112 super.onCreate(savedInstanceState); 112 super.onCreate(savedInstanceState);
113 setContentView(R.layout.activity_register); 113 setContentView(R.layout.activity_register);
114 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 114 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
115 115
116 ButterKnife.bind(this); 116 ButterKnife.bind(this);
117 mLifeLogApplication = (LifeLogApplication) getApplication(); 117 mLifeLogApplication = (LifeLogApplication) getApplication();
118 118
119 initData(); 119 initData();
120 120
121 initView(); 121 initView();
122 122
123 } 123 }
124 124
125 private void initData() { 125 private void initData() {
126 sexList = mLifeLogApplication.getSexList(); 126 sexList = mLifeLogApplication.getSexList();
127 provinceList = mLifeLogApplication.getProvinceList(); 127 provinceList = mLifeLogApplication.getProvinceList();
128 128
129 mCalendar = Calendar.getInstance(); 129 mCalendar = Calendar.getInstance();
130 mDay = mCalendar.get(Calendar.DAY_OF_MONTH); 130 mDay = mCalendar.get(Calendar.DAY_OF_MONTH);
131 mMonth = mCalendar.get(Calendar.MONTH); 131 mMonth = mCalendar.get(Calendar.MONTH);
132 mYear = mCalendar.get(Calendar.YEAR); 132 mYear = mCalendar.get(Calendar.YEAR);
133 } 133 }
134 134
135 135
136 private void initView() { 136 private void initView() {
137 137
138 138
139 } 139 }
140 140
141 private boolean checkData() { 141 private boolean checkData() {
142 String userName = edtUsername.getText().toString(); 142 String userName = edtUsername.getText().toString();
143 String name = edtName.getText().toString(); 143 String name = edtName.getText().toString();
144 String nickName = edtNickName.getText().toString(); 144 String nickName = edtNickName.getText().toString();
145 String email = edtEmail.getText().toString(); 145 String email = edtEmail.getText().toString();
146 String pass = edtPassword.getText().toString(); 146 String pass = edtPassword.getText().toString();
147 String confirmPass = edtConfirmPass.getText().toString(); 147 String confirmPass = edtConfirmPass.getText().toString();
148 //sexInfo 148 //sexInfo
149 //birthday 149 //birthday
150 String height = edtHeight.getText().toString(); 150 String height = edtHeight.getText().toString();
151 String weight = edtWeight.getText().toString(); 151 String weight = edtWeight.getText().toString();
152 String bodyFat = edtBodyFat.getText().toString(); 152 String bodyFat = edtBodyFat.getText().toString();
153 // address 153 // address
154 String comment = edtComment.getText().toString(); 154 String comment = edtComment.getText().toString();
155 155
156 156
157 if (userName.isEmpty()) { 157 if (userName.isEmpty()) {
158 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.username_null)); 158 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.username_null));
159 return false; 159 return false;
160 } 160 }
161 161
162 if (name.isEmpty()) { 162 if (name.isEmpty()) {
163 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.name_null)); 163 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.name_null));
164 return false; 164 return false;
165 } 165 }
166 166
167 if (nickName.isEmpty()) { 167 if (nickName.isEmpty()) {
168 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.nickname_null)); 168 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.nickname_null));
169 return false; 169 return false;
170 } 170 }
171 171
172 if (email.isEmpty()) { 172 if (email.isEmpty()) {
173 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_null)); 173 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_null));
174 return false; 174 return false;
175 } else { 175 } else {
176 if (!Utils.checkMailFormat(email)) { 176 if (!Utils.checkMailFormat(email)) {
177 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_invalid)); 177 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.mail_invalid));
178 return false; 178 return false;
179 } 179 }
180 } 180 }
181 181
182 if (pass.isEmpty()) { 182 if (pass.isEmpty()) {
183 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_null)); 183 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_null));
184 return false; 184 return false;
185 }else { 185 }else {
186 if (pass.length() < 6) { 186 if (pass.length() < 6) {
187 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_less_6)); 187 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.password_less_6));
188 return false; 188 return false;
189 } 189 }
190 } 190 }
191 191
192 if (confirmPass.isEmpty()) { 192 if (confirmPass.isEmpty()) {
193 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_null)); 193 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_null));
194 return false; 194 return false;
195 } 195 }
196 196
197 if (!pass.equals(confirmPass)) { 197 if (!pass.equals(confirmPass)) {
198 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_wrong)); 198 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.confirm_pass_wrong));
199 return false; 199 return false;
200 } 200 }
201 201
202 if (sexInfo == null) { 202 if (sexInfo == null) {
203 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.sex_not_select)); 203 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.sex_not_select));
204 return false; 204 return false;
205 } 205 }
206 206
207 if (mBirthDay == null) { 207 if (mBirthDay == null) {
208 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.birthday_not_select)); 208 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.birthday_not_select));
209 return false; 209 return false;
210 } 210 }
211 211
212 if (height.isEmpty()) { 212 if (height.isEmpty()) {
213 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.height_null)); 213 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.height_null));
214 return false; 214 return false;
215 } 215 }
216 216
217 if (weight.isEmpty()) { 217 if (weight.isEmpty()) {
218 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.weight_null)); 218 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.weight_null));
219 return false; 219 return false;
220 } 220 }
221 221
222 if (bodyFat.isEmpty()) { 222 if (bodyFat.isEmpty()) {
223 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.body_fat_percent_null)); 223 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.body_fat_percent_null));
224 return false; 224 return false;
225 } 225 }
226 226
227 if (provinceInfo == null) { 227 if (provinceInfo == null) {
228 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.province_not_select)); 228 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.province_not_select));
229 return false; 229 return false;
230 } 230 }
231 231
232 if (level == 0) { 232 if (level == 0) {
233 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.level_not_select)); 233 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.level_not_select));
234 return false; 234 return false;
235 } 235 }
236 236
237 if (comment.isEmpty()) { 237 if (comment.isEmpty()) {
238 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.comment_null)); 238 showAlerDialog(RegisterActivity.this, getResources().getString(R.string.comment_null));
239 return false; 239 return false;
240 } 240 }
241 241
242 mRegisterInfo = new RegisterInfo(); 242 mRegisterInfo = new RegisterInfo();
243 mRegisterInfo.setUsername(userName); 243 mRegisterInfo.setUsername(userName);
244 mRegisterInfo.setFullName(name); 244 mRegisterInfo.setFullName(name);
245 mRegisterInfo.setNickname(nickName); 245 mRegisterInfo.setNickname(nickName);
246 mRegisterInfo.setPassword(pass); 246 mRegisterInfo.setPassword(pass);
247 mRegisterInfo.setBirthday(mBirthDay); 247 mRegisterInfo.setBirthday(mBirthDay);
248 mRegisterInfo.setHeight(Integer.valueOf(height)); 248 mRegisterInfo.setHeight(Integer.valueOf(height));
249 mRegisterInfo.setWeight(Integer.valueOf(weight)); 249 mRegisterInfo.setWeight(Integer.valueOf(weight));
250 mRegisterInfo.setFatRate(Integer.valueOf(bodyFat)); 250 mRegisterInfo.setFatRate(Integer.valueOf(bodyFat));
251 mRegisterInfo.setGender(sexInfo.getId()); 251 mRegisterInfo.setGender(sexInfo.getId());
252 mRegisterInfo.setAddress(provinceInfo.getName()); 252 mRegisterInfo.setAddress(provinceInfo.getName());
253 mRegisterInfo.setEmail(email); 253 mRegisterInfo.setEmail(email);
254 mRegisterInfo.setProfileImage(profileImagePath); 254 mRegisterInfo.setProfileImage(profileImagePath);
255 255
256 return true; 256 return true;
257 } 257 }
258 258
259 private void handleRegister() { 259 private void handleRegister() {
260 progressDialog = new ProgressDialog(RegisterActivity.this); 260 progressDialog = new ProgressDialog(RegisterActivity.this);
261 progressDialog.setMessage(getResources().getString(R.string.uploading)); 261 progressDialog.setMessage(getResources().getString(R.string.uploading));
262 progressDialog.setCancelable(false); 262 progressDialog.setCancelable(false);
263 progressDialog.show(); 263 progressDialog.show();
264 264
265 ApiServices.register(mRegisterInfo, new LLAPIManagerListener() { 265 ApiServices.register(mRegisterInfo, new LLAPIManagerListener() {
266 @Override 266 @Override
267 public void onError(Error error) { 267 public void onError(Error error) {
268 progressDialog.dismiss(); 268 progressDialog.dismiss();
269 Debug.error(" Can not upload data"); 269 Debug.error(" Can not upload data");
270 if (error != null) { 270 if (error != null) {
271 String err = getResources().getString(R.string.register_err); 271 String err = getResources().getString(R.string.register_err);
272 notifyErr(err); 272 notifyErr(err);
273 } 273 }
274 } 274 }
275 275
276 @Override 276 @Override
277 public void onSuccess(String json) { 277 public void onSuccess(String json) {
278 progressDialog.dismiss(); 278 progressDialog.dismiss();
279 if (json != null) { 279 if (json != null) {
280 Debug.warn(" Upload data success success"); 280 Debug.warn(" Upload data success success");
281 Debug.warn("DATA JSON result: " + json.toString()); 281 Debug.warn("DATA JSON result: " + json.toString());
282 registerDone(); 282 registerDone();
283 } else { 283 } else {
284 Debug.warn(" Upload data fail: response null"); 284 Debug.warn(" Upload data fail: response null");
285 String err = getResources().getString(R.string.err_exception); 285 String err = getResources().getString(R.string.err_exception);
286 notifyErr(err); 286 notifyErr(err);
287 } 287 }
288 } 288 }
289 289
290 @Override 290 @Override
291 public void onSuccess(JSONObject object) { 291 public void onSuccess(JSONObject object) {
292 Debug.warn("Version JSON object result: Success"); 292 Debug.warn("Version JSON object result: Success");
293 progressDialog.dismiss(); 293 progressDialog.dismiss();
294 294
295 String email = object.optString("email"); 295 String email = object.optString("email");
296 String username = object.optString("username"); 296 String username = object.optString("username");
297 String pass = object.optString("password"); 297 String pass = object.optString("password");
298 Debug.normal("Email: "+email +"\n"+ "Username: "+username); 298 Debug.normal("Email: "+email +"\n"+ "Username: "+username);
299 // save data 299 // save data
300 Setting.setUserDataSharepre(RegisterActivity.this, Setting.EMAIL_SHAREPRE, email); 300 Setting.setUserDataSharepre(RegisterActivity.this, Setting.EMAIL_SHAREPRE, email);
301 Setting.setUserDataSharepre(RegisterActivity.this, Setting.USER_SHAREPRE, username); 301 Setting.setUserDataSharepre(RegisterActivity.this, Setting.USER_SHAREPRE, username);
302 Setting.setUserDataSharepre(RegisterActivity.this, Setting.PASS_SHAREPRE, pass); 302 Setting.setUserDataSharepre(RegisterActivity.this, Setting.PASS_SHAREPRE, pass);
303 registerDone(); 303 registerDone();
304 } 304 }
305 }); 305 });
306 } 306 }
307 307
308 private void hanleGetImagePath(Bitmap bitmap){ 308 private void hanleGetImagePath(Bitmap bitmap){
309 progressDialog = new ProgressDialog(RegisterActivity.this); 309 progressDialog = new ProgressDialog(RegisterActivity.this);
310 progressDialog.setMessage(getResources().getString(R.string.uploading)); 310 progressDialog.setMessage(getResources().getString(R.string.uploading));
311 progressDialog.setCancelable(false); 311 progressDialog.setCancelable(false);
312 progressDialog.show(); 312 progressDialog.show();
313 313
314 ApiServices.uploadImage(bitmap, new LLAPIManagerListener() { 314 ApiServices.uploadImage(bitmap, new LLAPIManagerListener() {
315 @Override 315 @Override
316 public void onError(Error error) { 316 public void onError(Error error) {
317 progressDialog.dismiss(); 317 progressDialog.dismiss();
318 Debug.error(" Can not upload data"); 318 Debug.error(" Can not upload data");
319 if (error != null) { 319 if (error != null) {
320 String err = getResources().getString(R.string.register_err); 320 String err = getResources().getString(R.string.register_err);
321 notifyErr(err); 321 notifyErr(err);
322 } 322 }
323 } 323 }
324 324
325 @Override 325 @Override
326 public void onSuccess(String json) { 326 public void onSuccess(String urlImage) {
327 if (json != null) { 327 if (urlImage != null) {
328 progressDialog.dismiss();
328 Debug.warn(" Upload data success success"); 329 Debug.warn(" Upload data success success");
329 Debug.warn("DATA JSON result: " + json.toString()); 330 Debug.warn("DATA JSON result: " + urlImage);
330 uploadImageDone(json); 331 uploadImageDone(urlImage);
331 } else { 332 } else {
332 progressDialog.dismiss(); 333 progressDialog.dismiss();
333 Debug.warn(" Upload data fail: response null"); 334 Debug.warn(" Upload data fail: response null");
334 String err = getResources().getString(R.string.err_exception); 335 String err = getResources().getString(R.string.err_exception);
335 notifyErr(err); 336 notifyErr(err);
336 } 337 }
337 } 338 }
338 339
339 @Override 340 @Override
340 public void onSuccess(JSONObject array) { 341 public void onSuccess(JSONObject array) {
341 progressDialog.dismiss(); 342 progressDialog.dismiss();
342 Debug.warn(" Upload data success array"); 343 Debug.warn(" Upload data success array");
343 } 344 }
344 }); 345 });
345 } 346 }
346 347
347 private void registerDone(){ 348 private void registerDone(){
348 Toast.makeText(RegisterActivity.this, R.string.register_success, Toast.LENGTH_SHORT).show(); 349 Toast.makeText(RegisterActivity.this, R.string.register_success, Toast.LENGTH_SHORT).show();
349 finish(); 350 finish();
350 } 351 }
351 352
352 private void uploadImageDone(String path){ 353 private void uploadImageDone(String path){
353 profileImagePath = path; 354 profileImagePath = path;
354 } 355 }
355 356
356 private void notifyErr(String err) { 357 private void notifyErr(String err) {
357 AlertDialog.Builder alertDialog = new AlertDialog.Builder(RegisterActivity.this); 358 AlertDialog.Builder alertDialog = new AlertDialog.Builder(RegisterActivity.this);
358 alertDialog.setMessage(err); 359 alertDialog.setMessage(err);
359 alertDialog.setCancelable(false); 360 alertDialog.setCancelable(false);
360 alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 361 alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
361 @Override 362 @Override
362 public void onClick(DialogInterface dialog, int which) { 363 public void onClick(DialogInterface dialog, int which) {
363 finish(); 364 finish();
364 } 365 }
365 }); 366 });
366 alertDialog.show(); 367 alertDialog.show();
367 } 368 }
368 369
369 private void doSelectSex() { 370 private void doSelectSex() {
370 String title = getResources().getString(R.string.sex); 371 String title = getResources().getString(R.string.sex);
371 new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, sexList, new OnSelectResultListener() { 372 new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, sexList, new OnSelectResultListener() {
372 @Override 373 @Override
373 public void onSelectedItem(SelectItemInfo selectItemInfo) { 374 public void onSelectedItem(SelectItemInfo selectItemInfo) {
374 if (selectItemInfo != null) { 375 if (selectItemInfo != null) {
375 Debug.normal("Item selected: " + selectItemInfo.getName()); 376 Debug.normal("Item selected: " + selectItemInfo.getName());
376 sexInfo = selectItemInfo; 377 sexInfo = selectItemInfo;
377 tvSex.setText(sexInfo.getName()); 378 tvSex.setText(sexInfo.getName());
378 } else { 379 } else {
379 Debug.normal("Have not item selected"); 380 Debug.normal("Have not item selected");
380 } 381 }
381 } 382 }
382 }).show(); 383 }).show();
383 } 384 }
384 385
385 private void doSelectProvince() { 386 private void doSelectProvince() {
386 String title = getResources().getString(R.string.prefecture); 387 String title = getResources().getString(R.string.prefecture);
387 new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, provinceList, new OnSelectResultListener() { 388 new SimpleSelectBoxDialogBuilder().create(RegisterActivity.this, title, provinceList, new OnSelectResultListener() {
388 @Override 389 @Override
389 public void onSelectedItem(SelectItemInfo selectItemInfo) { 390 public void onSelectedItem(SelectItemInfo selectItemInfo) {
390 if (selectItemInfo != null) { 391 if (selectItemInfo != null) {
391 Debug.normal("Item selected: " + selectItemInfo.getName()); 392 Debug.normal("Item selected: " + selectItemInfo.getName());
392 provinceInfo = selectItemInfo; 393 provinceInfo = selectItemInfo;
393 tvAddress.setText(provinceInfo.getName()); 394 tvAddress.setText(provinceInfo.getName());
394 } else { 395 } else {
395 Debug.normal("Have not item selected"); 396 Debug.normal("Have not item selected");
396 } 397 }
397 } 398 }
398 }).show(); 399 }).show();
399 } 400 }
400 401
401 private void hanleSelectDate() { 402 private void hanleSelectDate() {
402 403
403 DatePickerDialog datePicker = new DatePickerDialog(RegisterActivity.this, new DatePickerDialog.OnDateSetListener() { 404 DatePickerDialog datePicker = new DatePickerDialog(RegisterActivity.this, new DatePickerDialog.OnDateSetListener() {
404 @Override 405 @Override
405 public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { 406 public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
406 407
407 mDay = dayOfMonth; 408 mDay = dayOfMonth;
408 mMonth = month; 409 mMonth = month;
409 mYear = year; 410 mYear = year;
410 mCalendar = Calendar.getInstance(); 411 mCalendar = Calendar.getInstance();
411 mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); 412 mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
412 mCalendar.set(Calendar.MONTH, month); 413 mCalendar.set(Calendar.MONTH, month);
413 mCalendar.set(Calendar.YEAR, year); 414 mCalendar.set(Calendar.YEAR, year);
414 mBirthDay = mCalendar.getTime(); 415 mBirthDay = mCalendar.getTime();
415 416
416 String dateStr = Utils.convertDateToStringDialogSelect(mBirthDay); 417 String dateStr = Utils.convertDateToStringDialogSelect(mBirthDay);
417 tvBirthday.setText(dateStr); 418 tvBirthday.setText(dateStr);
418 } 419 }
419 }, mYear, mMonth, mDay); 420 }, mYear, mMonth, mDay);
420 datePicker.getDatePicker().setMaxDate(new Date().getTime()); 421 datePicker.getDatePicker().setMaxDate(new Date().getTime());
421 datePicker.show(); 422 datePicker.show();
422 } 423 }
423 424
424 private void updateUILevel() { 425 private void updateUILevel() {
425 if (level == 1) { 426 if (level == 1) {
426 setLowButtonSelected(true); 427 setLowButtonSelected(true);
427 setMidButtonSelected(false); 428 setMidButtonSelected(false);
428 setHightButtonSelected(false); 429 setHightButtonSelected(false);
429 } else if (level == 2) { 430 } else if (level == 2) {
430 setLowButtonSelected(false); 431 setLowButtonSelected(false);
431 setMidButtonSelected(true); 432 setMidButtonSelected(true);
432 setHightButtonSelected(false); 433 setHightButtonSelected(false);
433 } else if (level == 3) { 434 } else if (level == 3) {
434 setLowButtonSelected(false); 435 setLowButtonSelected(false);
435 setMidButtonSelected(false); 436 setMidButtonSelected(false);
436 setHightButtonSelected(true); 437 setHightButtonSelected(true);
437 } else { 438 } else {
438 setLowButtonSelected(false); 439 setLowButtonSelected(false);
439 setMidButtonSelected(false); 440 setMidButtonSelected(false);
440 setHightButtonSelected(false); 441 setHightButtonSelected(false);
441 } 442 }
442 } 443 }
443 444
444 private void setLowButtonSelected(boolean b) { 445 private void setLowButtonSelected(boolean b) {
445 if (b) { 446 if (b) {
446 llLow.setBackgroundResource(R.drawable.left_selected_lev_bg); 447 llLow.setBackgroundResource(R.drawable.left_selected_lev_bg);
447 tvLow.setTextColor(getResources().getColor(R.color.white)); 448 tvLow.setTextColor(getResources().getColor(R.color.white));
448 } else { 449 } else {
449 llLow.setBackgroundResource(R.drawable.left_unselected_lev_bg); 450 llLow.setBackgroundResource(R.drawable.left_unselected_lev_bg);
450 tvLow.setTextColor(getResources().getColor(R.color.black)); 451 tvLow.setTextColor(getResources().getColor(R.color.black));
451 } 452 }
452 } 453 }
453 454
454 private void setMidButtonSelected(boolean b) { 455 private void setMidButtonSelected(boolean b) {
455 if (b) { 456 if (b) {
456 llMid.setBackgroundResource(R.drawable.mid_selected_lev_bg); 457 llMid.setBackgroundResource(R.drawable.mid_selected_lev_bg);
457 tvMid.setTextColor(getResources().getColor(R.color.white)); 458 tvMid.setTextColor(getResources().getColor(R.color.white));
458 } else { 459 } else {
459 llMid.setBackgroundResource(R.drawable.mid_unselected_lev_bg); 460 llMid.setBackgroundResource(R.drawable.mid_unselected_lev_bg);
460 tvMid.setTextColor(getResources().getColor(R.color.black)); 461 tvMid.setTextColor(getResources().getColor(R.color.black));
461 } 462 }
462 } 463 }
463 464
464 private void setHightButtonSelected(boolean b) { 465 private void setHightButtonSelected(boolean b) {
465 if (b) { 466 if (b) {
466 llHight.setBackgroundResource(R.drawable.right_selected_lev_bg); 467 llHight.setBackgroundResource(R.drawable.right_selected_lev_bg);
467 tvHight.setTextColor(getResources().getColor(R.color.white)); 468 tvHight.setTextColor(getResources().getColor(R.color.white));
468 } else { 469 } else {
469 llHight.setBackgroundResource(R.drawable.right_unselected_lev_bg); 470 llHight.setBackgroundResource(R.drawable.right_unselected_lev_bg);
470 tvHight.setTextColor(getResources().getColor(R.color.black)); 471 tvHight.setTextColor(getResources().getColor(R.color.black));
471 } 472 }
472 } 473 }
473 474
474 private void getImageBrower() { 475 private void getImageBrower() {
475 Intent intent = new Intent(Intent.ACTION_PICK); 476 Intent intent = new Intent(Intent.ACTION_PICK);
476 intent.setType("image/*"); 477 intent.setType("image/*");
477 startActivityForResult(intent, RESULT_LOAD_IMG); 478 startActivityForResult(intent, RESULT_LOAD_IMG);
478 } 479 }
479 480
480 481
481 @OnClick({R.id.btn_register, R.id.rl_sex, R.id.rl_birthday, R.id.rl_address, R.id.ll_low, 482 @OnClick({R.id.btn_register, R.id.rl_sex, R.id.rl_birthday, R.id.rl_address, R.id.ll_low,
482 R.id.ll_mid, R.id.ll_hight, R.id.profile_image}) 483 R.id.ll_mid, R.id.ll_hight, R.id.profile_image})
483 public void onClick(View v) { 484 public void onClick(View v) {
484 switch (v.getId()) { 485 switch (v.getId()) {
485 case R.id.btn_register: 486 case R.id.btn_register:
486 if (checkData()) { 487 if (checkData()) {
487 handleRegister(); 488 handleRegister();
488 } 489 }
489 break; 490 break;
490 491
491 case R.id.rl_sex: 492 case R.id.rl_sex:
492 doSelectSex(); 493 doSelectSex();
493 break; 494 break;
494 495
495 496
496 case R.id.rl_birthday: 497 case R.id.rl_birthday:
497 hanleSelectDate(); 498 hanleSelectDate();
498 break; 499 break;
499 500
500 case R.id.rl_address: 501 case R.id.rl_address:
501 doSelectProvince(); 502 doSelectProvince();
502 break; 503 break;
503 504
504 case R.id.ll_low: 505 case R.id.ll_low:
505 level = 1; 506 level = 1;
506 updateUILevel(); 507 updateUILevel();
507 break; 508 break;
508 case R.id.ll_mid: 509 case R.id.ll_mid:
509 level = 2; 510 level = 2;
510 updateUILevel(); 511 updateUILevel();
511 break; 512 break;
512 case R.id.ll_hight: 513 case R.id.ll_hight:
513 level = 3; 514 level = 3;
514 updateUILevel(); 515 updateUILevel();
515 break; 516 break;
516 case R.id.profile_image: 517 case R.id.profile_image:
517 getImageBrower(); 518 getImageBrower();
518 break; 519 break;
519 520
520 default: 521 default:
521 break; 522 break;
522 } 523 }
523 } 524 }
524 525
525 @Override 526 @Override
526 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 527 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
527 super.onActivityResult(requestCode, resultCode, data); 528 super.onActivityResult(requestCode, resultCode, data);
528 529
529 if (resultCode == RESULT_OK) { 530 if (resultCode == RESULT_OK) {
530 if (requestCode == RESULT_LOAD_IMG) { 531 if (requestCode == RESULT_LOAD_IMG) {
531 try { 532 try {
532 final Uri imageUri = data.getData(); 533 final Uri imageUri = data.getData();
533 final InputStream imageStream = getContentResolver().openInputStream(imageUri); 534 final InputStream imageStream = getContentResolver().openInputStream(imageUri);
534 final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); 535 final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
535 hanleGetImagePath(selectedImage); 536 hanleGetImagePath(selectedImage);
536 profileImage.setImageBitmap(selectedImage); 537 profileImage.setImageBitmap(selectedImage);
537 } catch (FileNotFoundException e) { 538 } catch (FileNotFoundException e) {
538 e.printStackTrace(); 539 e.printStackTrace();
539 Toast.makeText(RegisterActivity.this, "Something went wrong", Toast.LENGTH_LONG).show(); 540 Toast.makeText(RegisterActivity.this, "Something went wrong", Toast.LENGTH_LONG).show();
540 } 541 }
541 542
542 } else { 543 } else {
543 Toast.makeText(RegisterActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show(); 544 Toast.makeText(RegisterActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show();
544 } 545 }
545 546
546 } 547 }
547 } 548 }
548 } 549 }
app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.Manifest; 3 import android.Manifest;
4 import android.app.ProgressDialog; 4 import android.app.ProgressDialog;
5 import android.content.DialogInterface; 5 import android.content.DialogInterface;
6 import android.content.Intent; 6 import android.content.Intent;
7 import android.content.pm.PackageManager; 7 import android.content.pm.PackageManager;
8 import android.net.Uri; 8 import android.net.Uri;
9 import android.os.Build; 9 import android.os.Build;
10 import android.os.Bundle; 10 import android.os.Bundle;
11 import android.os.Handler; 11 import android.os.Handler;
12 import android.support.v4.app.ActivityCompat; 12 import android.support.v4.app.ActivityCompat;
13 import android.support.v4.content.ContextCompat; 13 import android.support.v4.content.ContextCompat;
14 import android.support.v7.app.AlertDialog; 14 import android.support.v7.app.AlertDialog;
15 import android.widget.Toast; 15 import android.widget.Toast;
16 16
17 import com.dinhcv.lifelogpedometer.R; 17 import com.dinhcv.lifelogpedometer.R;
18 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; 18 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
19 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; 19 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
20 import com.dinhcv.lifelogpedometer.portal.ApiServices; 20 import com.dinhcv.lifelogpedometer.portal.ApiServices;
21 import com.dinhcv.lifelogpedometer.portal.LLAPIManager; 21 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
22 import com.dinhcv.lifelogpedometer.utils.Debug; 22 import com.dinhcv.lifelogpedometer.utils.Debug;
23 23
24 import org.json.JSONArray; 24 import org.json.JSONArray;
25 import org.json.JSONObject; 25 import org.json.JSONObject;
26 26
27 27
28 public class WelcomeActivity extends ActivityBase implements Runnable { 28 public class WelcomeActivity extends ActivityBase implements Runnable {
29 private boolean isRefresh = false; 29 private boolean isRefresh = false;
30 private static final int PERMISSIONS_REQUEST = 999; 30 private static final int PERMISSIONS_REQUEST = 999;
31 31
32 @Override 32 @Override
33 protected void onCreate(Bundle savedInstanceState) { 33 protected void onCreate(Bundle savedInstanceState) {
34 super.onCreate(savedInstanceState); 34 super.onCreate(savedInstanceState);
35 setContentView(R.layout.activity_welcome); 35 setContentView(R.layout.activity_welcome);
36 checkPermission(); 36 checkPermission();
37 } 37 }
38 38
39 private void checkRefreshToken(){ 39 private void checkRefreshToken(){
40 int id = Setting.getUserIdSharepre(WelcomeActivity.this); 40 int id = Setting.getUserIdSharepre(WelcomeActivity.this);
41 Debug.normal("String id: "+ id); 41 Debug.normal("String id: "+ id);
42 if (id != 0){ 42 if (id != 0){
43 handleRefreshToken(id); 43 handleRefreshToken(id);
44 }else { 44 }else {
45 refeshDone(); 45 refeshDone();
46 } 46 }
47 } 47 }
48 48
49 49
50 private void handleRefreshToken(int id) { 50 private void handleRefreshToken(int id) {
51 51
52 ApiServices.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() { 52 ApiServices.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() {
53 @Override 53 @Override
54 public void onError(Error error) { 54 public void onError(Error error) {
55 Debug.error("Version JSON result: ERROR " + error); 55 Debug.error("Version JSON result: ERROR " + error);
56 String err = getResources().getString(R.string.login_error); 56 String err = getResources().getString(R.string.login_error);
57 isRefresh = false; 57 isRefresh = false;
58 refeshDone(); 58 refeshDone();
59 } 59 }
60 60
61 @Override 61 @Override
62 public void onSuccess(String json) { 62 public void onSuccess(String json) {
63 Debug.warn("Version JSON result: " + json.toString()); 63 Debug.warn("Version JSON result: " + json.toString());
64 isRefresh = true; 64 isRefresh = true;
65 refeshDone(); 65 refeshDone();
66 } 66 }
67 67
68 @Override 68 @Override
69 public void onSuccess(JSONObject object) { 69 public void onSuccess(JSONObject object) {
70 Debug.warn("Version JSON object result: Success"); 70 Debug.warn("Version JSON object result: Success");
71 isRefresh = true; 71 isRefresh = true;
72 refeshDone(); 72 refeshDone();
73 } 73 }
74 }); 74 });
75 } 75 }
76 76
77 private void refeshDone(){ 77 private void refeshDone(){
78 Handler handler = new Handler(); 78 Handler handler = new Handler();
79 handler.postDelayed(WelcomeActivity.this, 2000); 79 handler.postDelayed(WelcomeActivity.this, 2000);
80 } 80 }
81 81
82 private void notifyErr(String err){ 82 private void notifyErr(String err){
83 AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this); 83 AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this);
84 alertDialog.setMessage(err); 84 alertDialog.setMessage(err);
85 alertDialog.setCancelable(false); 85 alertDialog.setCancelable(false);
86 alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 86 alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
87 @Override 87 @Override
88 public void onClick(DialogInterface dialog, int which) { 88 public void onClick(DialogInterface dialog, int which) {
89 finish(); 89 finish();
90 } 90 }
91 }); 91 });
92 AlertDialog alert = alertDialog.create(); 92 AlertDialog alert = alertDialog.create();
93 alert.show(); 93 alert.show();
94 } 94 }
95 95
96 @Override 96 @Override
97 public void run() { 97 public void run() {
98 // go to main screen 98 // go to main screen
99 if ( isRefresh) { 99 if ( isRefresh) {
100 gotoActivity(PedometerActivity.class); 100 gotoActivity(PedometerActivity.class);
101 } else { 101 } else {
102 // Bundle bundle = new Bundle(); 102 // Bundle bundle = new Bundle();
103 // bundle.putString(Const.URL, url); 103 // bundle.putString(Const.URL, url);
104 gotoActivity(LoginActivity.class); 104 gotoActivity(LoginActivity.class);
105 } 105 }
106 finish(); 106 finish();
107 } 107 }
108 108
109 @Override 109 @Override
110 protected void onResume() { 110 protected void onResume() {
111 super.onResume(); 111 super.onResume();
112 } 112 }
113 113
114 private void checkPermission() { 114 private void checkPermission() {
115 // Check all permission in android 6.0 115 // Check all permission in android 6.0
116 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 116 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
117 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) 117 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
118 == PackageManager.PERMISSION_GRANTED) && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) 118 == PackageManager.PERMISSION_GRANTED) && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
119 == PackageManager.PERMISSION_GRANTED)&& (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
119 == PackageManager.PERMISSION_GRANTED)) { 120 == PackageManager.PERMISSION_GRANTED)) {
120 checkRefreshToken(); 121 checkRefreshToken();
121 122
122 } else { 123 } else {
123 // Requset permisson of device 124 // Requset permisson of device
124 if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission 125 if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission
125 .ACCESS_COARSE_LOCATION) 126 .ACCESS_COARSE_LOCATION)
126 && ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest 127 && ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest
128 .permission.ACCESS_FINE_LOCATION) && ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest
127 .permission.ACCESS_FINE_LOCATION)) { 129 .permission.ACCESS_FINE_LOCATION)) {
128 ActivityCompat.requestPermissions(this, 130 ActivityCompat.requestPermissions(this,
129 new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, 131 new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
130 Manifest.permission.ACCESS_FINE_LOCATION}, 132 Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE},
131 PERMISSIONS_REQUEST); 133 PERMISSIONS_REQUEST);
132 134
133 } else { 135 } else {
134 ActivityCompat.requestPermissions(this, 136 ActivityCompat.requestPermissions(this,
135 new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, 137 new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
136 Manifest.permission.ACCESS_FINE_LOCATION}, 138 Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE},
137 PERMISSIONS_REQUEST); 139 PERMISSIONS_REQUEST);
138 } 140 }
139 } 141 }
140 142
141 } else { 143 } else {
142 checkRefreshToken(); 144 checkRefreshToken();
143 } 145 }
144 } 146 }
145 147
146 @Override 148 @Override
147 public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] 149 public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]
148 grantResults) { 150 grantResults) {
149 super.onRequestPermissionsResult(requestCode, permissions, grantResults); 151 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
150 152
151 if (requestCode == PERMISSIONS_REQUEST) { 153 if (requestCode == PERMISSIONS_REQUEST) {
152 if (grantResults.length > 0) { 154 if (grantResults.length > 0) {
153 if (grantResults[0] == PackageManager.PERMISSION_GRANTED 155 if (grantResults[0] == PackageManager.PERMISSION_GRANTED
154 && grantResults[1] == PackageManager.PERMISSION_GRANTED 156 && grantResults[1] == PackageManager.PERMISSION_GRANTED
155 && grantResults[2] == PackageManager.PERMISSION_GRANTED) { 157 && grantResults[2] == PackageManager.PERMISSION_GRANTED) {
156 checkRefreshToken(); 158 checkRefreshToken();
157 return; 159 return;
158 } 160 }
159 } else { 161 } else {
160 Toast.makeText(this, "Permission was not granted ", Toast.LENGTH_SHORT).show(); 162 Toast.makeText(this, "Permission was not granted ", Toast.LENGTH_SHORT).show();
161 finish(); 163 finish();
162 } 164 }
163 } else { 165 } else {
164 super.onRequestPermissionsResult(requestCode, permissions, grantResults); 166 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
165 } 167 }
166 } 168 }
167 } 169 }
168 170
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.os.Environment;
9 import android.support.annotation.NonNull;
10 import android.util.Base64; 9 import android.util.Base64;
10 import android.util.Log;
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.File;
25 import java.io.FileOutputStream;
24 import java.io.IOException; 26 import java.io.IOException;
25 import java.io.InputStream; 27 import java.io.InputStream;
28 import java.io.OutputStreamWriter;
29 import java.io.UnsupportedEncodingException;
30 import java.net.URLEncoder;
26 import java.util.Date; 31 import java.util.Date;
32 import java.util.HashMap;
33 import java.util.Map;
27 import java.util.concurrent.TimeUnit; 34 import java.util.concurrent.TimeUnit;
28 35
29 import okhttp3.HttpUrl; 36 import okhttp3.HttpUrl;
30 import okhttp3.MediaType; 37 import okhttp3.MediaType;
31 import okhttp3.OkHttpClient; 38 import okhttp3.OkHttpClient;
32 import okhttp3.Request; 39 import okhttp3.Request;
33 import okhttp3.RequestBody; 40 import okhttp3.RequestBody;
34 import okhttp3.Response; 41 import okhttp3.Response;
35 import okhttp3.ResponseBody; 42 import okhttp3.ResponseBody;
36 43
37 public class LLAPIManager { 44 public class LLAPIManager {
38 private static String URL_ROOT = "http://clover.timesfun.jp:9001/"; 45 private static String URL_ROOT = "http://clover.timesfun.jp:9001/";
39 //login info 46 //login info
40 private static String URL_LOGIN_INFO = "login"; 47 private static String URL_LOGIN_INFO = "login";
41 //register info 48 //register info
42 private static String URL_REGISTER_INFO = "register"; 49 private static String URL_REGISTER_INFO = "register";
43 //upload image info 50 //upload image info
44 private static String URL_UPLOAD_IMAGE_INFO = "upload-image"; 51 private static String URL_UPLOAD_IMAGE_INFO = "upload-image";
45 //Search zipcode 52 //Search zipcode
46 private static String URL_FORGET_PASS_INFO = "forgetPass"; 53 private static String URL_FORGET_PASS_INFO = "forgetPass";
47 //history 54 //history
48 private static String URL_HISTORE_INFO = "api/history"; 55 private static String URL_HISTORE_INFO = "api/history";
49 //history detail 56 //history detail
50 private static String URL_HISTORE_DETAIL_INFO = "api/history/detail"; 57 private static String URL_HISTORE_DETAIL_INFO = "api/history/detail";
51 // home 58 // home
52 private static String URL_HOME_INFO = "api/home"; 59 private static String URL_HOME_INFO = "api/home";
53 //Search zipcode 60 //Search zipcode
54 private static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm"; 61 private static String URL_FORGET_PASS_CONFIRM_INFO = "forgetPass/confirm";
55 // Refesh Token 62 // Refesh Token
56 private static String URL_REFESH_TOKEN_INFO = "refreshToken"; 63 private static String URL_REFESH_TOKEN_INFO = "refreshToken";
57 // Top info 64 // Top info
58 private static String URL_TOP_INFO = "api/top"; 65 private static String URL_TOP_INFO = "api/top";
59 // Refesh Token 66 // Refesh Token
60 private static String URL_CREATE_LOG_INFO = "api/createLog"; 67 private static String URL_CREATE_LOG_INFO = "api/createLog";
61 // Get news 68 // Get news
62 private static String URL_GET_NEWS_INFO = "api/getnoticesbydate"; 69 private static String URL_GET_NEWS_INFO = "api/getnoticesbydate";
63 70
64 71
65 private static int deviationValue = 1; 72 private static int deviationValue = 1;
66 73
67 public static class Login extends AsyncTask<Void, Void, String>{ 74 public static class Login extends AsyncTask<Void, Void, String>{
68 private Context context; 75 private Context context;
69 private String email; 76 private String email;
70 private String pass; 77 private String pass;
71 private LLAPIManagerListener action; 78 private LLAPIManagerListener action;
72 79
73 public Login(Context context, String email, String pass, LLAPIManagerListener action) { 80 public Login(Context context, String email, String pass, LLAPIManagerListener action) {
74 this.context = context; 81 this.context = context;
75 this.email = email; 82 this.email = email;
76 this.pass = pass; 83 this.pass = pass;
77 this.action = action; 84 this.action = action;
78 } 85 }
79 86
80 @Override 87 @Override
81 protected void onPreExecute() { 88 protected void onPreExecute() {
82 super.onPreExecute(); 89 super.onPreExecute();
83 } 90 }
84 91
85 @Override 92 @Override
86 protected String doInBackground(Void... voids) { 93 protected String doInBackground(Void... voids) {
87 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_LOGIN_INFO); 94 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_LOGIN_INFO);
88 JSONObject jsonObject = new JSONObject(); 95 JSONObject jsonObject = new JSONObject();
89 96
90 try { 97 try {
91 jsonObject.put("email", email); 98 jsonObject.put("email", email);
92 jsonObject.put("password", pass); 99 jsonObject.put("password", pass);
93 100
94 Debug.warn("Json data: " + jsonObject.toString()); 101 Debug.warn("Json data: " + jsonObject.toString());
95 } catch (JSONException e) { 102 } catch (JSONException e) {
96 Debug.normal("Error ", e.getMessage()); 103 Debug.normal("Error ", e.getMessage());
97 } 104 }
98 105
99 MediaType JSON 106 MediaType JSON
100 = MediaType.parse("application/json"); 107 = MediaType.parse("application/json");
101 Debug.normal("JSON STRING: %s", jsonObject.toString()); 108 Debug.normal("JSON STRING: %s", jsonObject.toString());
102 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); 109 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
103 110
104 final Request.Builder request = new Request.Builder() 111 final Request.Builder request = new Request.Builder()
105 .url(baseUrl) 112 .url(baseUrl)
106 .header("User-Agent", Utils.getCustomUA()) 113 .header("User-Agent", Utils.getCustomUA())
107 .header("Content-Type", "application/json") 114 .header("Content-Type", "application/json")
108 .post(requestBody); 115 .post(requestBody);
109 116
110 OkHttpClient httpClient = new OkHttpClient.Builder() 117 OkHttpClient httpClient = new OkHttpClient.Builder()
111 .readTimeout(30, TimeUnit.SECONDS) 118 .readTimeout(30, TimeUnit.SECONDS)
112 .writeTimeout(30, TimeUnit.SECONDS) 119 .writeTimeout(30, TimeUnit.SECONDS)
113 .connectTimeout(30, TimeUnit.SECONDS) 120 .connectTimeout(30, TimeUnit.SECONDS)
114 .build(); 121 .build();
115 122
116 String jsonString = null; 123 String jsonString = null;
117 try { 124 try {
118 Response response = httpClient.newCall(request.build()).execute(); 125 Response response = httpClient.newCall(request.build()).execute();
119 if (response == null) { 126 if (response == null) {
120 action.onError(null); 127 action.onError(null);
121 Debug.error("Response is null"); 128 Debug.error("Response is null");
122 return null; 129 return null;
123 } 130 }
124 jsonString = getResponseData(response.body()); 131 jsonString = getResponseData(response.body());
125 132
126 } catch (IOException e) { 133 } catch (IOException e) {
127 Debug.normal("Error %s", e.getMessage()); 134 Debug.normal("Error %s", e.getMessage());
128 } 135 }
129 return jsonString; 136 return jsonString;
130 } 137 }
131 138
132 @Override 139 @Override
133 protected void onCancelled() { 140 protected void onCancelled() {
134 super.onCancelled(); 141 super.onCancelled();
135 action.onError(null); 142 action.onError(null);
136 } 143 }
137 144
138 @Override 145 @Override
139 protected void onPostExecute(String jsonString) { 146 protected void onPostExecute(String jsonString) {
140 super.onPostExecute(jsonString); 147 super.onPostExecute(jsonString);
141 148
142 if ((jsonString == null) || (jsonString.isEmpty())) { 149 if ((jsonString == null) || (jsonString.isEmpty())) {
143 action.onError(null); 150 action.onError(null);
144 return; 151 return;
145 } 152 }
146 Debug.normal("String body: "+jsonString); 153 Debug.normal("String body: "+jsonString);
147 154
148 try { 155 try {
149 JSONObject jsonObject = new JSONObject(jsonString); 156 JSONObject jsonObject = new JSONObject(jsonString);
150 int status = jsonObject.optInt("status"); 157 int status = jsonObject.optInt("status");
151 if (status == 1){ 158 if (status == 1){
152 JSONObject object = jsonObject.optJSONObject("result"); 159 JSONObject object = jsonObject.optJSONObject("result");
153 JSONObject objUser = object.getJSONObject("user"); 160 JSONObject objUser = object.getJSONObject("user");
154 String token = object.optString("token"); 161 String token = object.optString("token");
155 // save data 162 // save data
156 Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); 163 Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token);
157 APIResponse.getInstance().setToken(token); 164 APIResponse.getInstance().setToken(token);
158 Debug.normal("Token: "+ token); 165 Debug.normal("Token: "+ token);
159 action.onSuccess(objUser); 166 action.onSuccess(objUser);
160 }else { 167 }else {
161 action.onError(new Error(jsonObject.optString("message"))); 168 action.onError(new Error(jsonObject.optString("message")));
162 } 169 }
163 } catch (JSONException e) { 170 } catch (JSONException e) {
164 e.printStackTrace(); 171 e.printStackTrace();
165 } 172 }
166 } 173 }
167 } 174 }
168 175
169 public static class UploadImage extends AsyncTask<Void, Void, String>{ 176 public static class UploadImage extends AsyncTask<Void, Void, String>{
170 private Bitmap bitmap; 177 private Bitmap bitmap;
171 private LLAPIManagerListener action; 178 private LLAPIManagerListener action;
172 179
173 public UploadImage(Bitmap bitmap, LLAPIManagerListener action) { 180 public UploadImage(Bitmap bitmap, LLAPIManagerListener action) {
174 this.bitmap = bitmap; 181 this.bitmap = bitmap;
175 this.action = action; 182 this.action = action;
176 } 183 }
177 184
178 @Override 185 @Override
179 protected void onPreExecute() { 186 protected void onPreExecute() {
180 super.onPreExecute(); 187 super.onPreExecute();
181 } 188 }
182 189
183 @Override 190 @Override
184 protected String doInBackground(Void... voids) { 191 protected String doInBackground(Void... voids) {
185 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_UPLOAD_IMAGE_INFO); 192 String baseUrl = URL_ROOT + URL_UPLOAD_IMAGE_INFO;
186 JSONObject jsonObject = new JSONObject(); 193
187 byte[] bitmapByte = convertBitmapToByteArray(bitmap); 194 Bitmap b = Bitmap.createScaledBitmap(bitmap, 120, 120, false);
195 byte[] bitmapByte = convertBitmapToByteArray(b);
188 String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT); 196 String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT);
189 String imageStr = imageBase64.replace("\n","");
190 197
191 String token = APIResponse.getInstance().getToken(); 198 String token = APIResponse.getInstance().getToken();
192 try { 199 //generate hashMap to store encodedImage and the name
193 if (token != null && !token.isEmpty()) { 200 HashMap<String,String> detail = new HashMap<>();
194 Debug.normal("Token is not null"); 201 detail.put("img", imageBase64);
195 jsonObject.put("token", token); 202 if (token != null && !token.isEmpty()) {
196 } 203 Debug.normal("Token is not null");
197 jsonObject.put("img", imageStr); 204 detail.put("token", token);
198
199 Debug.warn("Json data: " + jsonObject.toString());
200 } catch (JSONException e) {
201 Debug.normal("Error ", e.getMessage());
202 } 205 }
203 206
204 MediaType JSON
205 = MediaType.parse("application/json; charset=utf-8");
206 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
207
208 final Request.Builder request = new Request.Builder()
209 .url(baseUrl)
210 .header("User-Agent", Utils.getCustomUA())
211 .header("Content-Type", "application/json")
212 .post(requestBody);
213
214 OkHttpClient httpClient = new OkHttpClient.Builder()
215 .readTimeout(30, TimeUnit.SECONDS)
216 .writeTimeout(30, TimeUnit.SECONDS)
217 .connectTimeout(30, TimeUnit.SECONDS)
218 .build();
219 String jsonString = null;
220 try { 207 try {
221 Response response = httpClient.newCall(request.build()).execute(); 208 String dataToSend = hashMapToUrl(detail);
209
210 String response = RequestPostImage.post(baseUrl,dataToSend);
222 if (response == null) { 211 if (response == null) {
223 action.onError(null); 212 action.onError(null);
224 Debug.error("Response is null"); 213 Debug.error("Response is null");
225 return null; 214 return null;
226 } 215 }
227 jsonString = getResponseData(response.body());
228 216
217 Debug.normal("Response: "+response);
218 return response;
229 } catch (IOException e) { 219 } catch (IOException e) {
230 Debug.normal("Error %s", e.getMessage()); 220 Debug.normal("Error %s", e.getMessage());
221 return null;
231 } 222 }
232
233 return jsonString;
234 } 223 }
235 224
236 @Override 225 @Override
237 protected void onCancelled() { 226 protected void onCancelled() {
238 super.onCancelled(); 227 super.onCancelled();
239 action.onError(null); 228 action.onError(null);
240 } 229 }
241 230
242 @Override 231 @Override
243 protected void onPostExecute(String jsonString) { 232 protected void onPostExecute(String jsonString) {
244 super.onPostExecute(jsonString); 233 super.onPostExecute(jsonString);
245 if ((jsonString == null) || (jsonString.isEmpty())) { 234 if ((jsonString == null) || (jsonString.isEmpty())) {
246 action.onError(null); 235 action.onError(null);
247 return; 236 return;
248 } 237 }
249 Debug.normal("String body: "+jsonString); 238 Debug.normal("String body: "+jsonString);
250 239
251 try { 240 try {
252 JSONObject jsonObject = new JSONObject(jsonString); 241 JSONObject jsonObject = new JSONObject(jsonString);
253 int status = jsonObject.optInt("status"); 242 int status = jsonObject.optInt("httpCode");
254 if (status == 1){ 243 if (status != 0){
255 action.onSuccess(new JSONObject()); 244 action.onSuccess(jsonObject.optString("message"));
256 }else { 245 }else {
257 action.onError(new Error(jsonObject.optString("message"))); 246 action.onError(new Error(jsonObject.optString("message")));
258 } 247 }
259 } catch (JSONException e) { 248 } catch (JSONException e) {
260 e.printStackTrace(); 249 e.printStackTrace();
261 } 250 }
262 } 251 }
263 } 252 }
264 253
254 public static class UploadImage1 extends AsyncTask<Void, Void, String>{
255 private Bitmap bitmap;
256 private LLAPIManagerListener action;
257
258 public UploadImage1(Bitmap bitmap, LLAPIManagerListener action) {
259 this.bitmap = bitmap;
260 this.action = action;
261 }
262
263 @Override
264 protected void onPreExecute() {
265 super.onPreExecute();
266 }
267
268 @Override
269 protected String doInBackground(Void... voids) {
270 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_UPLOAD_IMAGE_INFO);
271 JSONObject jsonObject = new JSONObject();
272 Bitmap b = Bitmap.createScaledBitmap(bitmap, 120, 120, false);
273 byte[] bitmapByte = convertBitmapToByteArray(b);
274 String imageBase64 = Base64.encodeToString(bitmapByte, Base64.DEFAULT);
275 //String imageStr = imageBase64.replace("\n","");
276 //writeToFile(imageBase64);
277
278 String token = APIResponse.getInstance().getToken();
279 try {
280 if (token != null && !token.isEmpty()) {
281 Debug.normal("Token is not null");
282 jsonObject.put("token", token);
283 }
284 jsonObject.put("img", imageBase64);
285
286 //Debug.warn("Json data: " + jsonObject.toString());
287 } catch (JSONException e) {
288 Debug.normal("Error ", e.getMessage());
289 }
290
291 MediaType JSON
292 = MediaType.parse("application/json; charset=utf-8");
293 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
294
295 final Request.Builder request = new Request.Builder()
296 .url(baseUrl)
297 .header("Content-Type", "application/json")
298 .post(requestBody);
299
300 OkHttpClient httpClient = new OkHttpClient.Builder()
301 .readTimeout(30, TimeUnit.SECONDS)
302 .writeTimeout(30, TimeUnit.SECONDS)
303 .connectTimeout(30, TimeUnit.SECONDS)
304 .build();
305 String jsonString = null;
306 try {
307 Response response = httpClient.newCall(request.build()).execute();
308 if (response == null) {
309 action.onError(null);
310 Debug.error("Response is null");
311 return null;
312 }
313 jsonString = getResponseData(response.body());
314
315 } catch (IOException e) {
316 Debug.normal("Error %s", e.getMessage());
317 }
318
319 return jsonString;
320 }
321
322 @Override
323 protected void onCancelled() {
324 super.onCancelled();
325 action.onError(null);
326 }
327
328 @Override
329 protected void onPostExecute(String jsonString) {
330 super.onPostExecute(jsonString);
331 if ((jsonString == null) || (jsonString.isEmpty())) {
332 action.onError(null);
333 return;
334 }
335 Debug.normal("String body: "+jsonString);
336
337 try {
338 JSONObject jsonObject = new JSONObject(jsonString);
339 int status = jsonObject.optInt("status");
340 if (status == 1){
341 action.onSuccess(new JSONObject());
342 }else {
343 action.onError(new Error(jsonObject.optString("message")));
344 }
345 } catch (JSONException e) {
346 e.printStackTrace();
347 }
348 }
349 }
350
351
265 public static class Register extends AsyncTask<Void, Void, String>{ 352 public static class Register extends AsyncTask<Void, Void, String>{
266 private RegisterInfo registerInfo; 353 private RegisterInfo registerInfo;
267 private LLAPIManagerListener action; 354 private LLAPIManagerListener action;
268 355
269 public Register(RegisterInfo registerInfo, LLAPIManagerListener action) { 356 public Register(RegisterInfo registerInfo, LLAPIManagerListener action) {
270 this.registerInfo = registerInfo; 357 this.registerInfo = registerInfo;
271 this.action = action; 358 this.action = action;
272 } 359 }
273 360
274 @Override 361 @Override
275 protected void onPreExecute() { 362 protected void onPreExecute() {
276 super.onPreExecute(); 363 super.onPreExecute();
277 } 364 }
278 365
279 @Override 366 @Override
280 protected String doInBackground(Void... voids) { 367 protected String doInBackground(Void... voids) {
281 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REGISTER_INFO); 368 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REGISTER_INFO);
282 JSONObject jsonObject = new JSONObject(); 369 JSONObject jsonObject = new JSONObject();
283 370
284 String token = APIResponse.getInstance().getToken(); 371 String token = APIResponse.getInstance().getToken();
285 try { 372 try {
286 jsonObject.put("username", registerInfo.getUsername()); 373 jsonObject.put("username", registerInfo.getUsername());
287 jsonObject.put("password", registerInfo.getPassword()); 374 jsonObject.put("password", registerInfo.getPassword());
375 jsonObject.put("password_confirmation", registerInfo.getPassword());
288 jsonObject.put("full_name", registerInfo.getFullName()); 376 jsonObject.put("full_name", registerInfo.getFullName());
289 jsonObject.put("nickname", registerInfo.getNickname()); 377 //jsonObject.put("nickname", registerInfo.getNickname());
290 jsonObject.put("birthday", Utils.dateToStringFormatDayMonthYear(registerInfo.getBirthday())); 378 jsonObject.put("birthday", Utils.dateToStringFormatDayMonthYear(registerInfo.getBirthday()));
291 jsonObject.put("height", ""+registerInfo.getHeight()); 379 jsonObject.put("height", ""+registerInfo.getHeight());
292 jsonObject.put("weight", ""+registerInfo.getWeight()); 380 jsonObject.put("weight", ""+registerInfo.getWeight());
293 jsonObject.put("fat_rate", ""+registerInfo.getFatRate()); 381 jsonObject.put("fat_rate", ""+registerInfo.getFatRate());
294 jsonObject.put("gender", ""+registerInfo.getGender()); 382 jsonObject.put("gender", ""+registerInfo.getGender());
295 jsonObject.put("address", registerInfo.getAddress()); 383 //jsonObject.put("address", registerInfo.getAddress());
296 jsonObject.put("desciption", ""); 384 //jsonObject.put("desciption", "");
297 jsonObject.put("receive_notification", "0"); 385 jsonObject.put("receive_notification", "0");
298 //jsonObject.put("phone", "+84986940999"); 386 //jsonObject.put("phone", "+84986940999");
299 jsonObject.put("share_data", "1"); 387 jsonObject.put("share_data", "1");
300 jsonObject.put("profile_image", ""+registerInfo.getProfileImage()); 388 jsonObject.put("profile_image", ""+registerInfo.getProfileImage());
301 jsonObject.put("delete_flag", "0"); 389 //jsonObject.put("delete_flag", "0");
302 jsonObject.put("email", registerInfo.getEmail()); 390 jsonObject.put("email", registerInfo.getEmail());
303 jsonObject.put("physical_activity", "0"); 391 jsonObject.put("physical_activity", "0");
304 jsonObject.put("remember_me", "1"); 392 //jsonObject.put("remember", "1");
305 393
306 Debug.warn("Json data: " + jsonObject.toString()); 394 Debug.warn("Json data: " + jsonObject.toString());
307 } catch (JSONException e) { 395 } catch (JSONException e) {
308 Debug.normal("Error ", e.getMessage()); 396 Debug.normal("Error ", e.getMessage());
309 } 397 }
310 398
311 MediaType JSON 399 MediaType JSON
312 = MediaType.parse("application/json; charset=utf-8"); 400 = MediaType.parse("application/json; charset=utf-8");
313 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); 401 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
314 402
315 final Request.Builder request = new Request.Builder() 403 final Request.Builder request = new Request.Builder()
316 .url(baseUrl) 404 .url(baseUrl)
317 .header("User-Agent", Utils.getCustomUA()) 405 .header("User-Agent", Utils.getCustomUA())
318 .header("Content-Type", "application/json") 406 .header("Content-Type", "application/json")
319 .post(requestBody); 407 .post(requestBody);
320 408
321 OkHttpClient httpClient = new OkHttpClient.Builder() 409 OkHttpClient httpClient = new OkHttpClient.Builder()
322 .readTimeout(30, TimeUnit.SECONDS) 410 .readTimeout(30, TimeUnit.SECONDS)
323 .writeTimeout(30, TimeUnit.SECONDS) 411 .writeTimeout(30, TimeUnit.SECONDS)
324 .connectTimeout(30, TimeUnit.SECONDS) 412 .connectTimeout(30, TimeUnit.SECONDS)
325 .build(); 413 .build();
326 414
327 String jsonString = null; 415 String jsonString = null;
328 try { 416 try {
329 Response response = httpClient.newCall(request.build()).execute(); 417 Response response = httpClient.newCall(request.build()).execute();
330 if (response == null) { 418 if (response == null) {
331 action.onError(null); 419 action.onError(null);
332 Debug.error("Response is null"); 420 Debug.error("Response is null");
333 return null; 421 return null;
334 } 422 }
335 jsonString = getResponseData(response.body()); 423 jsonString = getResponseData(response.body());
336 424
337 } catch (IOException e) { 425 } catch (IOException e) {
338 Debug.normal("Error %s", e.getMessage()); 426 Debug.normal("Error %s", e.getMessage());
339 } 427 }
340 return jsonString; 428 return jsonString;
341 } 429 }
342 430
343 @Override 431 @Override
344 protected void onCancelled() { 432 protected void onCancelled() {
345 super.onCancelled(); 433 super.onCancelled();
346 action.onError(null); 434 action.onError(null);
347 } 435 }
348 436
349 @Override 437 @Override
350 protected void onPostExecute(String jsonString) { 438 protected void onPostExecute(String jsonString) {
351 super.onPostExecute(jsonString); 439 super.onPostExecute(jsonString);
352 if ((jsonString == null) || (jsonString.isEmpty())) { 440 if ((jsonString == null) || (jsonString.isEmpty())) {
353 action.onError(null); 441 action.onError(null);
354 return; 442 return;
355 } 443 }
356 Debug.normal("String body: "+jsonString); 444 Debug.normal("String body: "+jsonString);
357 445
358 try { 446 try {
359 JSONObject jsonObject = new JSONObject(jsonString); 447 JSONObject jsonObject = new JSONObject(jsonString);
360 int status = jsonObject.optInt("status"); 448 int status = jsonObject.optInt("status");
361 if (status == 1){ 449 if (status == 1){
362 JSONObject object = jsonObject.optJSONObject("result"); 450 JSONObject object = jsonObject.optJSONObject("result");
363 JSONObject objUser = object.getJSONObject("user"); 451 JSONObject objUser = object.getJSONObject("user");
364 String token = object.optString("token"); 452 String token = object.optString("token");
365 APIResponse.getInstance().setToken(token); 453 APIResponse.getInstance().setToken(token);
366 Debug.normal("Token: "+ token); 454 Debug.normal("Token: "+ token);
367 action.onSuccess(objUser); 455 action.onSuccess(objUser);
368 }else { 456 }else {
369 action.onError(new Error(jsonObject.optString("message"))); 457 action.onError(new Error(jsonObject.optString("message")));
370 } 458 }
371 } catch (JSONException e) { 459 } catch (JSONException e) {
372 e.printStackTrace(); 460 e.printStackTrace();
373 } 461 }
374 462
375 } 463 }
376 } 464 }
377 465
378 private static byte[] convertBitmapToByteArray(Bitmap bitmap) { 466 private static byte[] convertBitmapToByteArray(Bitmap bitmap) {
379 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 467 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
380 bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); 468 bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
381 byte[] byteArray = byteArrayOutputStream.toByteArray(); 469 byte[] byteArray = byteArrayOutputStream.toByteArray();
382 return byteArray; 470 return byteArray;
383 } 471 }
384 472
385 public static class ForgetPass extends AsyncTask<Void, Void, String>{ 473 public static class ForgetPass extends AsyncTask<Void, Void, String>{
386 private String email; 474 private String email;
387 private LLAPIManagerListener action; 475 private LLAPIManagerListener action;
388 476
389 public ForgetPass(String email, LLAPIManagerListener action) { 477 public ForgetPass(String email, LLAPIManagerListener action) {
390 this.email = email; 478 this.email = email;
391 this.action = action; 479 this.action = action;
392 } 480 }
393 481
394 @Override 482 @Override
395 protected void onPreExecute() { 483 protected void onPreExecute() {
396 super.onPreExecute(); 484 super.onPreExecute();
397 } 485 }
398 486
399 @Override 487 @Override
400 protected String doInBackground(Void... voids) { 488 protected String doInBackground(Void... voids) {
401 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_INFO); 489 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_INFO);
402 JSONObject jsonObject = new JSONObject(); 490 JSONObject jsonObject = new JSONObject();
403 try { 491 try {
404 //Personal info 492 //Personal info
405 jsonObject.put("email", email); 493 jsonObject.put("email", email);
406 494
407 Debug.warn("Json data: " + jsonObject.toString()); 495 Debug.warn("Json data: " + jsonObject.toString());
408 } catch (JSONException e) { 496 } catch (JSONException e) {
409 Debug.normal("Error ", e.getMessage()); 497 Debug.normal("Error ", e.getMessage());
410 } 498 }
411 499
412 MediaType JSON 500 MediaType JSON
413 = MediaType.parse("application/json"); 501 = MediaType.parse("application/json");
414 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); 502 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
415 503
416 final Request.Builder request = new Request.Builder() 504 final Request.Builder request = new Request.Builder()
417 .url(baseUrl) 505 .url(baseUrl)
418 .header("User-Agent", Utils.getCustomUA()) 506 .header("User-Agent", Utils.getCustomUA())
419 .header("Content-Type", "application/json") 507 .header("Content-Type", "application/json")
420 .post(requestBody); 508 .post(requestBody);
421 509
422 OkHttpClient httpClient = new OkHttpClient.Builder() 510 OkHttpClient httpClient = new OkHttpClient.Builder()
423 .readTimeout(30, TimeUnit.SECONDS) 511 .readTimeout(30, TimeUnit.SECONDS)
424 .writeTimeout(30, TimeUnit.SECONDS) 512 .writeTimeout(30, TimeUnit.SECONDS)
425 .connectTimeout(30, TimeUnit.SECONDS) 513 .connectTimeout(30, TimeUnit.SECONDS)
426 .build(); 514 .build();
427 515
428 String jsonString = null; 516 String jsonString = null;
429 try { 517 try {
430 Response response = httpClient.newCall(request.build()).execute(); 518 Response response = httpClient.newCall(request.build()).execute();
431 if (response == null) { 519 if (response == null) {
432 action.onError(null); 520 action.onError(null);
433 Debug.error("Response is null"); 521 Debug.error("Response is null");
434 return null; 522 return null;
435 } 523 }
436 jsonString = getResponseData(response.body()); 524 jsonString = getResponseData(response.body());
437 525
438 } catch (IOException e) { 526 } catch (IOException e) {
439 Debug.normal("Error %s", e.getMessage()); 527 Debug.normal("Error %s", e.getMessage());
440 } 528 }
441 return jsonString; 529 return jsonString;
442 } 530 }
443 531
444 @Override 532 @Override
445 protected void onCancelled() { 533 protected void onCancelled() {
446 super.onCancelled(); 534 super.onCancelled();
447 action.onError(null); 535 action.onError(null);
448 } 536 }
449 537
450 @Override 538 @Override
451 protected void onPostExecute(String jsonString) { 539 protected void onPostExecute(String jsonString) {
452 super.onPostExecute(jsonString); 540 super.onPostExecute(jsonString);
453 if ((jsonString == null) || (jsonString.isEmpty())) { 541 if ((jsonString == null) || (jsonString.isEmpty())) {
454 action.onError(null); 542 action.onError(null);
455 return; 543 return;
456 } 544 }
457 Debug.normal("String body: "+jsonString); 545 Debug.normal("String body: "+jsonString);
458 546
459 try { 547 try {
460 JSONObject jsonObject = new JSONObject(jsonString); 548 JSONObject jsonObject = new JSONObject(jsonString);
461 int status = jsonObject.optInt("status"); 549 int status = jsonObject.optInt("status");
462 if (status == 1) { 550 if (status == 1) {
463 action.onSuccess(jsonString); 551 action.onSuccess(jsonString);
464 } else { 552 } else {
465 action.onError(new Error(jsonObject.getString("message"))); 553 action.onError(new Error(jsonObject.getString("message")));
466 } 554 }
467 } catch (JSONException e) { 555 } catch (JSONException e) {
468 action.onError(null); 556 action.onError(null);
469 } 557 }
470 } 558 }
471 559
472 } 560 }
473 561
474 public static class ForgetPassConfirm extends AsyncTask<Void, Void, String>{ 562 public static class ForgetPassConfirm extends AsyncTask<Void, Void, String>{
475 private String email; 563 private String email;
476 private String codeConfirm; 564 private String codeConfirm;
477 private LLAPIManagerListener action; 565 private LLAPIManagerListener action;
478 566
479 public ForgetPassConfirm(String email, String codeConfirm, LLAPIManagerListener action) { 567 public ForgetPassConfirm(String email, String codeConfirm, LLAPIManagerListener action) {
480 this.email = email; 568 this.email = email;
481 this.codeConfirm = codeConfirm; 569 this.codeConfirm = codeConfirm;
482 this.action = action; 570 this.action = action;
483 } 571 }
484 572
485 @Override 573 @Override
486 protected void onPreExecute() { 574 protected void onPreExecute() {
487 super.onPreExecute(); 575 super.onPreExecute();
488 } 576 }
489 577
490 @Override 578 @Override
491 protected String doInBackground(Void... voids) { 579 protected String doInBackground(Void... voids) {
492 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_CONFIRM_INFO); 580 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_FORGET_PASS_CONFIRM_INFO);
493 JSONObject jsonObject = new JSONObject(); 581 JSONObject jsonObject = new JSONObject();
494 try { 582 try {
495 //Personal info 583 //Personal info
496 jsonObject.put("email", email); 584 jsonObject.put("email", email);
497 jsonObject.put("code_confirm", codeConfirm); 585 jsonObject.put("code_confirm", codeConfirm);
498 586
499 Debug.warn("Json data: " + jsonObject.toString()); 587 Debug.warn("Json data: " + jsonObject.toString());
500 } catch (JSONException e) { 588 } catch (JSONException e) {
501 Debug.normal("Error ", e.getMessage()); 589 Debug.normal("Error ", e.getMessage());
502 } 590 }
503 591
504 MediaType JSON 592 MediaType JSON
505 = MediaType.parse("application/json"); 593 = MediaType.parse("application/json");
506 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); 594 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
507 595
508 final Request.Builder request = new Request.Builder() 596 final Request.Builder request = new Request.Builder()
509 .url(baseUrl) 597 .url(baseUrl)
510 .header("User-Agent", Utils.getCustomUA()) 598 .header("User-Agent", Utils.getCustomUA())
511 .header("Content-Type", "application/json") 599 .header("Content-Type", "application/json")
512 .post(requestBody); 600 .post(requestBody);
513 601
514 OkHttpClient httpClient = new OkHttpClient.Builder() 602 OkHttpClient httpClient = new OkHttpClient.Builder()
515 .readTimeout(30, TimeUnit.SECONDS) 603 .readTimeout(30, TimeUnit.SECONDS)
516 .writeTimeout(30, TimeUnit.SECONDS) 604 .writeTimeout(30, TimeUnit.SECONDS)
517 .connectTimeout(30, TimeUnit.SECONDS) 605 .connectTimeout(30, TimeUnit.SECONDS)
518 .build(); 606 .build();
519 String jsonString = null; 607 String jsonString = null;
520 try { 608 try {
521 Response response = httpClient.newCall(request.build()).execute(); 609 Response response = httpClient.newCall(request.build()).execute();
522 if (response == null) { 610 if (response == null) {
523 action.onError(null); 611 action.onError(null);
524 Debug.error("Response is null"); 612 Debug.error("Response is null");
525 return null; 613 return null;
526 } 614 }
527 jsonString = getResponseData(response.body()); 615 jsonString = getResponseData(response.body());
528 616
529 } catch (IOException e) { 617 } catch (IOException e) {
530 Debug.normal("Error %s", e.getMessage()); 618 Debug.normal("Error %s", e.getMessage());
531 } 619 }
532 return jsonString; 620 return jsonString;
533 } 621 }
534 622
535 @Override 623 @Override
536 protected void onCancelled() { 624 protected void onCancelled() {
537 super.onCancelled(); 625 super.onCancelled();
538 action.onError(null); 626 action.onError(null);
539 } 627 }
540 628
541 @Override 629 @Override
542 protected void onPostExecute(String jsonString) { 630 protected void onPostExecute(String jsonString) {
543 super.onPostExecute(jsonString); 631 super.onPostExecute(jsonString);
544 if ((jsonString == null) || (jsonString.isEmpty())) { 632 if ((jsonString == null) || (jsonString.isEmpty())) {
545 action.onError(null); 633 action.onError(null);
546 return; 634 return;
547 } 635 }
548 Debug.normal("String body: "+jsonString); 636 Debug.normal("String body: "+jsonString);
549 637
550 try { 638 try {
551 JSONObject jsonObject = new JSONObject(jsonString); 639 JSONObject jsonObject = new JSONObject(jsonString);
552 int status = jsonObject.optInt("status"); 640 int status = jsonObject.optInt("status");
553 if (status == 1) { 641 if (status == 1) {
554 action.onSuccess(jsonString); 642 action.onSuccess(jsonString);
555 } else { 643 } else {
556 action.onError(new Error(jsonObject.getString("message"))); 644 action.onError(new Error(jsonObject.getString("message")));
557 } 645 }
558 } catch (JSONException e) { 646 } catch (JSONException e) {
559 action.onError(null); 647 action.onError(null);
560 } 648 }
561 } 649 }
562 } 650 }
563 651
564 public static class History extends AsyncTask<Void, Void, String>{ 652 public static class History extends AsyncTask<Void, Void, String>{
565 private Date fromDate; 653 private Date fromDate;
566 private Date toDate; 654 private Date toDate;
567 private LLAPIManagerListener action; 655 private LLAPIManagerListener action;
568 656
569 public History(Date fromDate, Date toDate, LLAPIManagerListener action) { 657 public History(Date fromDate, Date toDate, LLAPIManagerListener action) {
570 this.fromDate = fromDate; 658 this.fromDate = fromDate;
571 this.toDate = toDate; 659 this.toDate = toDate;
572 this.action = action; 660 this.action = action;
573 } 661 }
574 662
575 @Override 663 @Override
576 protected void onPreExecute() { 664 protected void onPreExecute() {
577 super.onPreExecute(); 665 super.onPreExecute();
578 } 666 }
579 667
580 @Override 668 @Override
581 protected String doInBackground(Void... voids) { 669 protected String doInBackground(Void... voids) {
582 670
583 String fromStr = Utils.dateToStringFormatYearMonthDay(fromDate); 671 String fromStr = Utils.dateToStringFormatYearMonthDay(fromDate);
584 String toStr = Utils.dateToStringFormatYearMonthDay(toDate); 672 String toStr = Utils.dateToStringFormatYearMonthDay(toDate);
585 Debug.normal("Token: "+ APIResponse.getInstance().getToken()); 673 Debug.normal("Token: "+ APIResponse.getInstance().getToken());
586 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_INFO + "/"+ fromStr +"/"+ toStr); 674 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_INFO + "/"+ fromStr +"/"+ toStr);
587 Debug.normal("URL: "+baseUrl.toString()); 675 Debug.normal("URL: "+baseUrl.toString());
588 final Request.Builder request = new Request.Builder() 676 final Request.Builder request = new Request.Builder()
589 .url(baseUrl) 677 .url(baseUrl)
590 .header("User-Agent", Utils.getCustomUA()) 678 .header("User-Agent", Utils.getCustomUA())
591 .header("Content-Type", "application/json") 679 .header("Content-Type", "application/json")
592 .addHeader("token", APIResponse.getInstance().getToken()) 680 .addHeader("token", APIResponse.getInstance().getToken())
593 .get(); 681 .get();
594 682
595 OkHttpClient httpClient = new OkHttpClient.Builder() 683 OkHttpClient httpClient = new OkHttpClient.Builder()
596 .readTimeout(30, TimeUnit.SECONDS) 684 .readTimeout(30, TimeUnit.SECONDS)
597 .writeTimeout(30, TimeUnit.SECONDS) 685 .writeTimeout(30, TimeUnit.SECONDS)
598 .connectTimeout(30, TimeUnit.SECONDS) 686 .connectTimeout(30, TimeUnit.SECONDS)
599 .build(); 687 .build();
600 688
601 String jsonString = null; 689 String jsonString = null;
602 try { 690 try {
603 Response response = httpClient.newCall(request.build()).execute(); 691 Response response = httpClient.newCall(request.build()).execute();
604 if (response == null) { 692 if (response == null) {
605 action.onError(null); 693 action.onError(null);
606 Debug.error("Response is null"); 694 Debug.error("Response is null");
607 return null; 695 return null;
608 } 696 }
609 jsonString = getResponseData(response.body()); 697 jsonString = getResponseData(response.body());
610 698
611 } catch (IOException e) { 699 } catch (IOException e) {
612 Debug.normal("Error %s", e.getMessage()); 700 Debug.normal("Error %s", e.getMessage());
613 } 701 }
614 return jsonString; 702 return jsonString;
615 } 703 }
616 704
617 @Override 705 @Override
618 protected void onCancelled() { 706 protected void onCancelled() {
619 super.onCancelled(); 707 super.onCancelled();
620 action.onError(null); 708 action.onError(null);
621 } 709 }
622 710
623 @Override 711 @Override
624 protected void onPostExecute(String jsonString) { 712 protected void onPostExecute(String jsonString) {
625 super.onPostExecute(jsonString); 713 super.onPostExecute(jsonString);
626 if ((jsonString == null) || (jsonString.isEmpty())) { 714 if ((jsonString == null) || (jsonString.isEmpty())) {
627 action.onError(null); 715 action.onError(null);
628 return; 716 return;
629 } 717 }
630 Debug.normal("String body: "+jsonString); 718 Debug.normal("String body: "+jsonString);
631 719
632 try { 720 try {
633 JSONObject jsonObject = new JSONObject(jsonString); 721 JSONObject jsonObject = new JSONObject(jsonString);
634 int status = jsonObject.optInt("status"); 722 int status = jsonObject.optInt("status");
635 if (status == 1) { 723 if (status == 1) {
636 action.onSuccess(jsonString); 724 action.onSuccess(jsonString);
637 } else { 725 } else {
638 action.onError(new Error(jsonObject.getString("message"))); 726 action.onError(new Error(jsonObject.getString("message")));
639 } 727 }
640 } catch (JSONException e) { 728 } catch (JSONException e) {
641 action.onError(null); 729 action.onError(null);
642 } 730 }
643 } 731 }
644 } 732 }
645 733
646 public static class HistoryDetail extends AsyncTask<Void, Void, String>{ 734 public static class HistoryDetail extends AsyncTask<Void, Void, String>{
647 private Date fromDate; 735 private Date fromDate;
648 private Date toDate; 736 private Date toDate;
649 private LLAPIManagerListener action; 737 private LLAPIManagerListener action;
650 738
651 public HistoryDetail(Date fromDate, Date toDate, LLAPIManagerListener action) { 739 public HistoryDetail(Date fromDate, Date toDate, LLAPIManagerListener action) {
652 this.fromDate = fromDate; 740 this.fromDate = fromDate;
653 this.toDate = toDate; 741 this.toDate = toDate;
654 this.action = action; 742 this.action = action;
655 } 743 }
656 744
657 @Override 745 @Override
658 protected void onPreExecute() { 746 protected void onPreExecute() {
659 super.onPreExecute(); 747 super.onPreExecute();
660 } 748 }
661 749
662 @Override 750 @Override
663 protected String doInBackground(Void... voids) { 751 protected String doInBackground(Void... voids) {
664 752
665 String fromStr = Utils.dateToStringFormatDayMonthYear(fromDate); 753 String fromStr = Utils.dateToStringFormatDayMonthYear(fromDate);
666 String toStr = Utils.dateToStringFormatDayMonthYear(toDate); 754 String toStr = Utils.dateToStringFormatDayMonthYear(toDate);
667 Debug.normal("Token: "+ APIResponse.getInstance().getToken()); 755 Debug.normal("Token: "+ APIResponse.getInstance().getToken());
668 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_DETAIL_INFO + "/"+ fromStr +"/"+ toStr); 756 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HISTORE_DETAIL_INFO + "/"+ fromStr +"/"+ toStr);
669 Debug.normal("URL: "+baseUrl.toString()); 757 Debug.normal("URL: "+baseUrl.toString());
670 final Request.Builder request = new Request.Builder() 758 final Request.Builder request = new Request.Builder()
671 .url(baseUrl) 759 .url(baseUrl)
672 .header("User-Agent", Utils.getCustomUA()) 760 .header("User-Agent", Utils.getCustomUA())
673 .header("Content-Type", "application/json") 761 .header("Content-Type", "application/json")
674 .addHeader("token", APIResponse.getInstance().getToken()) 762 .addHeader("token", APIResponse.getInstance().getToken())
675 .get(); 763 .get();
676 764
677 OkHttpClient httpClient = new OkHttpClient.Builder() 765 OkHttpClient httpClient = new OkHttpClient.Builder()
678 .readTimeout(30, TimeUnit.SECONDS) 766 .readTimeout(30, TimeUnit.SECONDS)
679 .writeTimeout(30, TimeUnit.SECONDS) 767 .writeTimeout(30, TimeUnit.SECONDS)
680 .connectTimeout(30, TimeUnit.SECONDS) 768 .connectTimeout(30, TimeUnit.SECONDS)
681 .build(); 769 .build();
682 770
683 String jsonString = null; 771 String jsonString = null;
684 try { 772 try {
685 Response response = httpClient.newCall(request.build()).execute(); 773 Response response = httpClient.newCall(request.build()).execute();
686 if (response == null) { 774 if (response == null) {
687 action.onError(null); 775 action.onError(null);
688 Debug.error("Response is null"); 776 Debug.error("Response is null");
689 return null; 777 return null;
690 } 778 }
691 jsonString = getResponseData(response.body()); 779 jsonString = getResponseData(response.body());
692 780
693 } catch (IOException e) { 781 } catch (IOException e) {
694 Debug.normal("Error %s", e.getMessage()); 782 Debug.normal("Error %s", e.getMessage());
695 } 783 }
696 return jsonString; 784 return jsonString;
697 } 785 }
698 786
699 @Override 787 @Override
700 protected void onCancelled() { 788 protected void onCancelled() {
701 super.onCancelled(); 789 super.onCancelled();
702 action.onError(null); 790 action.onError(null);
703 } 791 }
704 792
705 @Override 793 @Override
706 protected void onPostExecute(String jsonString) { 794 protected void onPostExecute(String jsonString) {
707 super.onPostExecute(jsonString); 795 super.onPostExecute(jsonString);
708 if ((jsonString == null) || (jsonString.isEmpty())) { 796 if ((jsonString == null) || (jsonString.isEmpty())) {
709 action.onError(null); 797 action.onError(null);
710 return; 798 return;
711 } 799 }
712 Debug.normal("String body: "+jsonString); 800 Debug.normal("String body: "+jsonString);
713 801
714 try { 802 try {
715 JSONObject jsonObject = new JSONObject(jsonString); 803 JSONObject jsonObject = new JSONObject(jsonString);
716 int status = jsonObject.optInt("status"); 804 int status = jsonObject.optInt("status");
717 if (status == 1) { 805 if (status == 1) {
718 action.onSuccess(jsonString); 806 action.onSuccess(jsonString);
719 } else { 807 } else {
720 action.onError(new Error(jsonObject.getString("message"))); 808 action.onError(new Error(jsonObject.getString("message")));
721 } 809 }
722 } catch (JSONException e) { 810 } catch (JSONException e) {
723 action.onError(null); 811 action.onError(null);
724 } 812 }
725 } 813 }
726 814
727 } 815 }
728 816
729 public static class HomePage extends AsyncTask<Void, Void, String>{ 817 public static class HomePage extends AsyncTask<Void, Void, String>{
730 private Date date; 818 private Date date;
731 private Const.STEP_TYPE stepType; 819 private Const.STEP_TYPE stepType;
732 private LLAPIManagerListener action; 820 private LLAPIManagerListener action;
733 821
734 public HomePage(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) { 822 public HomePage(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) {
735 this.date = date; 823 this.date = date;
736 this.stepType = stepType; 824 this.stepType = stepType;
737 this.action = action; 825 this.action = action;
738 } 826 }
739 827
740 @Override 828 @Override
741 protected void onPreExecute() { 829 protected void onPreExecute() {
742 super.onPreExecute(); 830 super.onPreExecute();
743 } 831 }
744 832
745 @Override 833 @Override
746 protected String doInBackground(Void... voids) { 834 protected String doInBackground(Void... voids) {
747 835
748 String dateStr = Utils.dateToStringFormatDayMonthYear(date); 836 String dateStr = Utils.dateToStringFormatDayMonthYear(date);
749 Debug.normal("Token: "+ APIResponse.getInstance().getToken()); 837 Debug.normal("Token: "+ APIResponse.getInstance().getToken());
750 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HOME_INFO + "/"+ stepType.value +"/"+ dateStr); 838 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_HOME_INFO + "/"+ stepType.value +"/"+ dateStr);
751 Debug.normal("URL: "+baseUrl.toString()); 839 Debug.normal("URL: "+baseUrl.toString());
752 final Request.Builder request = new Request.Builder() 840 final Request.Builder request = new Request.Builder()
753 .url(baseUrl) 841 .url(baseUrl)
754 .header("User-Agent", Utils.getCustomUA()) 842 .header("User-Agent", Utils.getCustomUA())
755 .header("Content-Type", "application/json") 843 .header("Content-Type", "application/json")
756 .addHeader("token", APIResponse.getInstance().getToken()) 844 .addHeader("token", APIResponse.getInstance().getToken())
757 .get(); 845 .get();
758 846
759 OkHttpClient httpClient = new OkHttpClient.Builder() 847 OkHttpClient httpClient = new OkHttpClient.Builder()
760 .readTimeout(30, TimeUnit.SECONDS) 848 .readTimeout(30, TimeUnit.SECONDS)
761 .writeTimeout(30, TimeUnit.SECONDS) 849 .writeTimeout(30, TimeUnit.SECONDS)
762 .connectTimeout(30, TimeUnit.SECONDS) 850 .connectTimeout(30, TimeUnit.SECONDS)
763 .build(); 851 .build();
764 852
765 String jsonString = null; 853 String jsonString = null;
766 try { 854 try {
767 Response response = httpClient.newCall(request.build()).execute(); 855 Response response = httpClient.newCall(request.build()).execute();
768 if (response == null) { 856 if (response == null) {
769 action.onError(null); 857 action.onError(null);
770 Debug.error("Response is null"); 858 Debug.error("Response is null");
771 return null; 859 return null;
772 } 860 }
773 jsonString = getResponseData(response.body()); 861 jsonString = getResponseData(response.body());
774 862
775 } catch (IOException e) { 863 } catch (IOException e) {
776 Debug.normal("Error %s", e.getMessage()); 864 Debug.normal("Error %s", e.getMessage());
777 } 865 }
778 return jsonString; 866 return jsonString;
779 } 867 }
780 868
781 @Override 869 @Override
782 protected void onCancelled() { 870 protected void onCancelled() {
783 super.onCancelled(); 871 super.onCancelled();
784 action.onError(null); 872 action.onError(null);
785 } 873 }
786 874
787 @Override 875 @Override
788 protected void onPostExecute(String jsonString) { 876 protected void onPostExecute(String jsonString) {
789 super.onPostExecute(jsonString); 877 super.onPostExecute(jsonString);
790 if ((jsonString == null) || (jsonString.isEmpty())) { 878 if ((jsonString == null) || (jsonString.isEmpty())) {
791 action.onError(null); 879 action.onError(null);
792 return; 880 return;
793 } 881 }
794 Debug.normal("String body: "+jsonString); 882 Debug.normal("String body: "+jsonString);
795 883
796 try { 884 try {
797 JSONObject jsonObject = new JSONObject(jsonString); 885 JSONObject jsonObject = new JSONObject(jsonString);
798 int status = jsonObject.optInt("status"); 886 int status = jsonObject.optInt("status");
799 if (status == 1) { 887 if (status == 1) {
800 action.onSuccess(jsonString); 888 action.onSuccess(jsonString);
801 } else { 889 } else {
802 action.onError(new Error(jsonObject.getString("message"))); 890 action.onError(new Error(jsonObject.getString("message")));
803 } 891 }
804 } catch (JSONException e) { 892 } catch (JSONException e) {
805 action.onError(null); 893 action.onError(null);
806 } 894 }
807 } 895 }
808 896
809 } 897 }
810 898
811 public static class TopInfo extends AsyncTask<Void, Void, String>{ 899 public static class TopInfo extends AsyncTask<Void, Void, String>{
812 private Date date; 900 private Date date;
813 private Const.STEP_TYPE stepType; 901 private Const.STEP_TYPE stepType;
814 private LLAPIManagerListener action; 902 private LLAPIManagerListener action;
815 903
816 public TopInfo(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) { 904 public TopInfo(Date date, Const.STEP_TYPE stepType, LLAPIManagerListener action) {
817 this.date = date; 905 this.date = date;
818 this.stepType = stepType; 906 this.stepType = stepType;
819 this.action = action; 907 this.action = action;
820 } 908 }
821 909
822 @Override 910 @Override
823 protected void onPreExecute() { 911 protected void onPreExecute() {
824 super.onPreExecute(); 912 super.onPreExecute();
825 } 913 }
826 914
827 @Override 915 @Override
828 protected String doInBackground(Void... voids) { 916 protected String doInBackground(Void... voids) {
829 917
830 String dateStr = Utils.dateToStringFormatDayMonthYear(date); 918 String dateStr = Utils.dateToStringFormatDayMonthYear(date);
831 Debug.normal("Token: "+ APIResponse.getInstance().getToken()); 919 Debug.normal("Token: "+ APIResponse.getInstance().getToken());
832 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_TOP_INFO + "/"+ stepType.value +"/"+ dateStr); 920 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_TOP_INFO + "/"+ stepType.value +"/"+ dateStr);
833 Debug.normal("URL: "+baseUrl.toString()); 921 Debug.normal("URL: "+baseUrl.toString());
834 final Request.Builder request = new Request.Builder() 922 final Request.Builder request = new Request.Builder()
835 .url(baseUrl) 923 .url(baseUrl)
836 .header("User-Agent", Utils.getCustomUA()) 924 .header("User-Agent", Utils.getCustomUA())
837 .header("Content-Type", "application/json") 925 .header("Content-Type", "application/json")
838 .addHeader("token", APIResponse.getInstance().getToken()) 926 .addHeader("token", APIResponse.getInstance().getToken())
839 .get(); 927 .get();
840 928
841 OkHttpClient httpClient = new OkHttpClient.Builder() 929 OkHttpClient httpClient = new OkHttpClient.Builder()
842 .readTimeout(30, TimeUnit.SECONDS) 930 .readTimeout(30, TimeUnit.SECONDS)
843 .writeTimeout(30, TimeUnit.SECONDS) 931 .writeTimeout(30, TimeUnit.SECONDS)
844 .connectTimeout(30, TimeUnit.SECONDS) 932 .connectTimeout(30, TimeUnit.SECONDS)
845 .build(); 933 .build();
846 934
847 String jsonString = null; 935 String jsonString = null;
848 try { 936 try {
849 Response response = httpClient.newCall(request.build()).execute(); 937 Response response = httpClient.newCall(request.build()).execute();
850 if (response == null) { 938 if (response == null) {
851 action.onError(null); 939 action.onError(null);
852 Debug.error("Response is null"); 940 Debug.error("Response is null");
853 return null; 941 return null;
854 } 942 }
855 jsonString = getResponseData(response.body()); 943 jsonString = getResponseData(response.body());
856 944
857 } catch (IOException e) { 945 } catch (IOException e) {
858 Debug.normal("Error %s", e.getMessage()); 946 Debug.normal("Error %s", e.getMessage());
859 } 947 }
860 return jsonString; 948 return jsonString;
861 } 949 }
862 950
863 @Override 951 @Override
864 protected void onCancelled() { 952 protected void onCancelled() {
865 super.onCancelled(); 953 super.onCancelled();
866 action.onError(null); 954 action.onError(null);
867 } 955 }
868 956
869 @Override 957 @Override
870 protected void onPostExecute(String jsonString) { 958 protected void onPostExecute(String jsonString) {
871 super.onPostExecute(jsonString); 959 super.onPostExecute(jsonString);
872 if ((jsonString == null) || (jsonString.isEmpty())) { 960 if ((jsonString == null) || (jsonString.isEmpty())) {
873 action.onError(null); 961 action.onError(null);
874 return; 962 return;
875 } 963 }
876 Debug.normal("String body: "+jsonString); 964 Debug.normal("String body: "+jsonString);
877 965
878 try { 966 try {
879 JSONObject jsonObject = new JSONObject(jsonString); 967 JSONObject jsonObject = new JSONObject(jsonString);
880 int status = jsonObject.optInt("status"); 968 int status = jsonObject.optInt("status");
881 if (status == 1) { 969 if (status == 1) {
882 action.onSuccess(jsonString); 970 action.onSuccess(jsonString);
883 } else { 971 } else {
884 action.onError(new Error(jsonObject.getString("message"))); 972 action.onError(new Error(jsonObject.getString("message")));
885 } 973 }
886 } catch (JSONException e) { 974 } catch (JSONException e) {
887 action.onError(null); 975 action.onError(null);
888 } 976 }
889 } 977 }
890 978
891 } 979 }
892 980
893 public static class CreateLog extends AsyncTask<Void, Void, String>{ 981 public static class CreateLog extends AsyncTask<Void, Void, String>{
894 private int stepCount; 982 private int stepCount;
895 private Const.STEP_TYPE stepType; 983 private Const.STEP_TYPE stepType;
896 private Date startTime; 984 private Date startTime;
897 private Date endTime; 985 private Date endTime;
898 private LLAPIManagerListener action; 986 private LLAPIManagerListener action;
899 987
900 public CreateLog(Const.STEP_TYPE stepType, int stepCount, Date startTime, Date endTime, LLAPIManagerListener action) { 988 public CreateLog(Const.STEP_TYPE stepType, int stepCount, Date startTime, Date endTime, LLAPIManagerListener action) {
901 this.stepCount = stepCount; 989 this.stepCount = stepCount;
902 this.stepType = stepType; 990 this.stepType = stepType;
903 this.startTime = startTime; 991 this.startTime = startTime;
904 this.endTime = endTime; 992 this.endTime = endTime;
905 this.action = action; 993 this.action = action;
906 } 994 }
907 995
908 996
909 @Override 997 @Override
910 protected void onPreExecute() { 998 protected void onPreExecute() {
911 super.onPreExecute(); 999 super.onPreExecute();
912 } 1000 }
913 1001
914 @Override 1002 @Override
915 protected String doInBackground(Void... voids) { 1003 protected String doInBackground(Void... voids) {
916 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_CREATE_LOG_INFO); 1004 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_CREATE_LOG_INFO);
917 JSONObject jsonObject = new JSONObject(); 1005 JSONObject jsonObject = new JSONObject();
918 String startT = Utils.convertDate2DateTimeString(startTime); 1006 String startT = Utils.convertDate2DateTimeString(startTime);
919 String endT = Utils.convertDate2DateTimeString(endTime); 1007 String endT = Utils.convertDate2DateTimeString(endTime);
920 try { 1008 try {
921 jsonObject.put("mode", stepType.value); 1009 jsonObject.put("mode", stepType.value);
922 jsonObject.put("numStep", stepCount); 1010 jsonObject.put("numStep", stepCount);
923 jsonObject.put("startTime", startT); 1011 jsonObject.put("startTime", startT);
924 jsonObject.put("endTime", endT); 1012 jsonObject.put("endTime", endT);
925 1013
926 Debug.warn("Json data: " + jsonObject.toString()); 1014 Debug.warn("Json data: " + jsonObject.toString());
927 } catch (JSONException e) { 1015 } catch (JSONException e) {
928 Debug.normal("Error ", e.getMessage()); 1016 Debug.normal("Error ", e.getMessage());
929 } 1017 }
930 1018
931 MediaType JSON 1019 MediaType JSON
932 = MediaType.parse("application/json"); 1020 = MediaType.parse("application/json");
933 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); 1021 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
934 1022
935 final Request.Builder request = new Request.Builder() 1023 final Request.Builder request = new Request.Builder()
936 .url(baseUrl) 1024 .url(baseUrl)
937 .header("User-Agent", Utils.getCustomUA()) 1025 .header("User-Agent", Utils.getCustomUA())
938 .header("Content-Type", "application/json") 1026 .header("Content-Type", "application/json")
939 .addHeader("token", APIResponse.getInstance().getToken()) 1027 .addHeader("token", APIResponse.getInstance().getToken())
940 .post(requestBody); 1028 .post(requestBody);
941 1029
942 OkHttpClient httpClient = new OkHttpClient.Builder() 1030 OkHttpClient httpClient = new OkHttpClient.Builder()
943 .readTimeout(30, TimeUnit.SECONDS) 1031 .readTimeout(30, TimeUnit.SECONDS)
944 .writeTimeout(30, TimeUnit.SECONDS) 1032 .writeTimeout(30, TimeUnit.SECONDS)
945 .connectTimeout(30, TimeUnit.SECONDS) 1033 .connectTimeout(30, TimeUnit.SECONDS)
946 .build(); 1034 .build();
947 1035
948 String jsonString = null; 1036 String jsonString = null;
949 try { 1037 try {
950 Response response = httpClient.newCall(request.build()).execute(); 1038 Response response = httpClient.newCall(request.build()).execute();
951 if (response == null) { 1039 if (response == null) {
952 action.onError(null); 1040 action.onError(null);
953 Debug.error("Response is null"); 1041 Debug.error("Response is null");
954 return null; 1042 return null;
955 } 1043 }
956 jsonString = getResponseData(response.body()); 1044 jsonString = getResponseData(response.body());
957 1045
958 } catch (IOException e) { 1046 } catch (IOException e) {
959 Debug.normal("Error %s", e.getMessage()); 1047 Debug.normal("Error %s", e.getMessage());
960 } 1048 }
961 return jsonString; 1049 return jsonString;
962 } 1050 }
963 1051
964 @Override 1052 @Override
965 protected void onCancelled() { 1053 protected void onCancelled() {
966 super.onCancelled(); 1054 super.onCancelled();
967 action.onError(null); 1055 action.onError(null);
968 } 1056 }
969 1057
970 @Override 1058 @Override
971 protected void onPostExecute(String jsonString) { 1059 protected void onPostExecute(String jsonString) {
972 super.onPostExecute(jsonString); 1060 super.onPostExecute(jsonString);
973 if ((jsonString == null) || (jsonString.isEmpty())) { 1061 if ((jsonString == null) || (jsonString.isEmpty())) {
974 action.onError(null); 1062 action.onError(null);
975 return; 1063 return;
976 } 1064 }
977 Debug.normal("String body: "+jsonString); 1065 Debug.normal("String body: "+jsonString);
978 1066
979 try { 1067 try {
980 JSONObject jsonObject = new JSONObject(jsonString); 1068 JSONObject jsonObject = new JSONObject(jsonString);
981 int status = jsonObject.optInt("status"); 1069 int status = jsonObject.optInt("status");
982 if (status == 1) { 1070 if (status == 1) {
983 action.onSuccess(jsonString); 1071 action.onSuccess(jsonString);
984 } else { 1072 } else {
985 action.onError(new Error(jsonObject.getString("message"))); 1073 action.onError(new Error(jsonObject.getString("message")));
986 } 1074 }
987 } catch (JSONException e) { 1075 } catch (JSONException e) {
988 action.onError(null); 1076 action.onError(null);
989 } 1077 }
990 } 1078 }
991 } 1079 }
992 1080
993 public static class RefreshToken extends AsyncTask<Void, Void, String>{ 1081 public static class RefreshToken extends AsyncTask<Void, Void, String>{
994 private Context context; 1082 private Context context;
995 private int userId; 1083 private int userId;
996 private LLAPIManagerListener action; 1084 private LLAPIManagerListener action;
997 1085
998 public RefreshToken(Context context, int userId, LLAPIManagerListener action) { 1086 public RefreshToken(Context context, int userId, LLAPIManagerListener action) {
999 this.context = context; 1087 this.context = context;
1000 this.userId = userId; 1088 this.userId = userId;
1001 this.action = action; 1089 this.action = action;
1002 } 1090 }
1003 1091
1004 @Override 1092 @Override
1005 protected void onPreExecute() { 1093 protected void onPreExecute() {
1006 super.onPreExecute(); 1094 super.onPreExecute();
1007 } 1095 }
1008 1096
1009 @Override 1097 @Override
1010 protected String doInBackground(Void... voids) { 1098 protected String doInBackground(Void... voids) {
1011 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REFESH_TOKEN_INFO); 1099 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_REFESH_TOKEN_INFO);
1012 JSONObject jsonObject = new JSONObject(); 1100 JSONObject jsonObject = new JSONObject();
1013 try { 1101 try {
1014 //Personal info 1102 //Personal info
1015 jsonObject.put("userId", userId); 1103 jsonObject.put("userId", userId);
1016 1104
1017 Debug.warn("Json data: " + jsonObject.toString()); 1105 Debug.warn("Json data: " + jsonObject.toString());
1018 } catch (JSONException e) { 1106 } catch (JSONException e) {
1019 Debug.normal("Error ", e.getMessage()); 1107 Debug.normal("Error ", e.getMessage());
1020 } 1108 }
1021 1109
1022 MediaType JSON 1110 MediaType JSON
1023 = MediaType.parse("application/json"); 1111 = MediaType.parse("application/json");
1024 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString()); 1112 RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
1025 1113
1026 final Request.Builder request = new Request.Builder() 1114 final Request.Builder request = new Request.Builder()
1027 .url(baseUrl) 1115 .url(baseUrl)
1028 .header("User-Agent", Utils.getCustomUA()) 1116 .header("User-Agent", Utils.getCustomUA())
1029 .header("Content-Type", "application/json") 1117 .header("Content-Type", "application/json")
1030 .post(requestBody); 1118 .post(requestBody);
1031 1119
1032 OkHttpClient httpClient = new OkHttpClient.Builder() 1120 OkHttpClient httpClient = new OkHttpClient.Builder()
1033 .readTimeout(30, TimeUnit.SECONDS) 1121 .readTimeout(30, TimeUnit.SECONDS)
1034 .writeTimeout(30, TimeUnit.SECONDS) 1122 .writeTimeout(30, TimeUnit.SECONDS)
1035 .connectTimeout(30, TimeUnit.SECONDS) 1123 .connectTimeout(30, TimeUnit.SECONDS)
1036 .build(); 1124 .build();
1037 1125
1038 String jsonString = null; 1126 String jsonString = null;
1039 try { 1127 try {
1040 Response response = httpClient.newCall(request.build()).execute(); 1128 Response response = httpClient.newCall(request.build()).execute();
1041 if (response == null) { 1129 if (response == null) {
1042 action.onError(null); 1130 action.onError(null);
1043 Debug.error("Response is null"); 1131 Debug.error("Response is null");
1044 return null; 1132 return null;
1045 } 1133 }
1046 jsonString = getResponseData(response.body()); 1134 jsonString = getResponseData(response.body());
1047 1135
1048 } catch (IOException e) { 1136 } catch (IOException e) {
1049 Debug.normal("Error %s", e.getMessage()); 1137 Debug.normal("Error %s", e.getMessage());
1050 } 1138 }
1051 return jsonString; 1139 return jsonString;
1052 } 1140 }
1053 1141
1054 @Override 1142 @Override
1055 protected void onCancelled() { 1143 protected void onCancelled() {
1056 super.onCancelled(); 1144 super.onCancelled();
1057 action.onError(null); 1145 action.onError(null);
1058 } 1146 }
1059 1147
1060 @Override 1148 @Override
1061 protected void onPostExecute(String jsonString) { 1149 protected void onPostExecute(String jsonString) {
1062 super.onPostExecute(jsonString); 1150 super.onPostExecute(jsonString);
1063 if ((jsonString == null) || (jsonString.isEmpty())) { 1151 if ((jsonString == null) || (jsonString.isEmpty())) {
1064 action.onError(null); 1152 action.onError(null);
1065 return; 1153 return;
1066 } 1154 }
1067 Debug.normal("String body: "+jsonString); 1155 Debug.normal("String body: "+jsonString);
1068 1156
1069 try { 1157 try {
1070 JSONObject jsonObject = new JSONObject(jsonString); 1158 JSONObject jsonObject = new JSONObject(jsonString);
1071 int status = jsonObject.optInt("status"); 1159 int status = jsonObject.optInt("status");
1072 if (status == 1) { 1160 if (status == 1) {
1073 JSONArray tokenArr = jsonObject.optJSONArray("result"); 1161 JSONArray tokenArr = jsonObject.optJSONArray("result");
1074 String token = tokenArr.get(0).toString(); 1162 String token = tokenArr.get(0).toString();
1075 Debug.normal("Refresh Token: "+ token); 1163 Debug.normal("Refresh Token: "+ token);
1076 // save data 1164 // save data
1077 Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token); 1165 Setting.setUserDataSharepre(context, Setting.TOKEN_SHAREPRE, token);
1078 APIResponse.getInstance().setToken(token); 1166 APIResponse.getInstance().setToken(token);
1079 action.onSuccess(jsonString); 1167 action.onSuccess(jsonString);
1080 } else { 1168 } else {
1081 action.onError(new Error(jsonObject.getString("message"))); 1169 action.onError(new Error(jsonObject.getString("message")));
1082 } 1170 }
1083 } catch (JSONException e) { 1171 } catch (JSONException e) {
1084 action.onError(null); 1172 action.onError(null);
1085 } 1173 }
1086 } 1174 }
1087 } 1175 }
1088 1176
1089 public static class GetNews extends AsyncTask<Void, Void, String>{ 1177 public static class GetNews extends AsyncTask<Void, Void, String>{
1090 private Date date; 1178 private Date date;
1091 private LLAPIManagerListener action; 1179 private LLAPIManagerListener action;
1092 1180
1093 public GetNews(Date date, LLAPIManagerListener action) { 1181 public GetNews(Date date, LLAPIManagerListener action) {
1094 this.date = date; 1182 this.date = date;
1095 this.action = action; 1183 this.action = action;
1096 } 1184 }
1097 1185
1098 @Override 1186 @Override
1099 protected void onPreExecute() { 1187 protected void onPreExecute() {
1100 super.onPreExecute(); 1188 super.onPreExecute();
1101 } 1189 }
1102 1190
1103 @Override 1191 @Override
1104 protected String doInBackground(Void... voids) { 1192 protected String doInBackground(Void... voids) {
1105 String fromStr = Utils.dateToStringFormatDayMonthYear(date); 1193 String fromStr = Utils.dateToStringFormatDayMonthYear(date);
1106 Debug.normal("Token: "+ APIResponse.getInstance().getToken()); 1194 Debug.normal("Token: "+ APIResponse.getInstance().getToken());
1107 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_GET_NEWS_INFO + "/"+ fromStr); 1195 HttpUrl baseUrl = HttpUrl.parse(URL_ROOT + URL_GET_NEWS_INFO + "/"+ fromStr);
1108 Debug.normal("URL: "+baseUrl.toString()); 1196 Debug.normal("URL: "+baseUrl.toString());
1109 final Request.Builder request = new Request.Builder() 1197 final Request.Builder request = new Request.Builder()
1110 .url(baseUrl) 1198 .url(baseUrl)
1111 .header("User-Agent", Utils.getCustomUA()) 1199 .header("User-Agent", Utils.getCustomUA())
1112 .header("Content-Type", "application/json") 1200 .header("Content-Type", "application/json")
1113 .addHeader("token", APIResponse.getInstance().getToken()) 1201 .addHeader("token", APIResponse.getInstance().getToken())
1114 .get(); 1202 .get();
1115 1203
1116 OkHttpClient httpClient = new OkHttpClient.Builder() 1204 OkHttpClient httpClient = new OkHttpClient.Builder()
1117 .readTimeout(30, TimeUnit.SECONDS) 1205 .readTimeout(30, TimeUnit.SECONDS)
1118 .writeTimeout(30, TimeUnit.SECONDS) 1206 .writeTimeout(30, TimeUnit.SECONDS)
1119 .connectTimeout(30, TimeUnit.SECONDS) 1207 .connectTimeout(30, TimeUnit.SECONDS)
1120 .build(); 1208 .build();
1121 1209
1122 String jsonString = null; 1210 String jsonString = null;
1123 try { 1211 try {
1124 Response response = httpClient.newCall(request.build()).execute(); 1212 Response response = httpClient.newCall(request.build()).execute();
1125 if (response == null) { 1213 if (response == null) {
1126 action.onError(null); 1214 action.onError(null);
1127 Debug.error("Response is null"); 1215 Debug.error("Response is null");
1128 return null; 1216 return null;
1129 } 1217 }
1130 jsonString = getResponseData(response.body()); 1218 jsonString = getResponseData(response.body());
1131 1219
1132 } catch (IOException e) { 1220 } catch (IOException e) {
1133 Debug.normal("Error %s", e.getMessage()); 1221 Debug.normal("Error %s", e.getMessage());
1134 } 1222 }
1135 return jsonString; 1223 return jsonString;
1136 } 1224 }
1137 1225
1138 @Override 1226 @Override
1139 protected void onCancelled() { 1227 protected void onCancelled() {
1140 super.onCancelled(); 1228 super.onCancelled();
1141 action.onError(null); 1229 action.onError(null);
1142 } 1230 }
1143 1231
1144 @Override 1232 @Override
1145 protected void onPostExecute(String jsonString) { 1233 protected void onPostExecute(String jsonString) {
1146 super.onPostExecute(jsonString); 1234 super.onPostExecute(jsonString);
1147 if ((jsonString == null) || (jsonString.isEmpty())) { 1235 if ((jsonString == null) || (jsonString.isEmpty())) {
1148 action.onError(null); 1236 action.onError(null);
1149 return; 1237 return;
1150 } 1238 }
1151 Debug.normal("String body: "+jsonString); 1239 Debug.normal("String body: "+jsonString);
1152 1240
1153 try { 1241 try {
1154 JSONObject jsonObject = new JSONObject(jsonString); 1242 JSONObject jsonObject = new JSONObject(jsonString);
1155 int status = jsonObject.optInt("status"); 1243 int status = jsonObject.optInt("status");
1156 if (status == 1) { 1244 if (status == 1) {
1157 // save data 1245 // save data
1158 action.onSuccess(jsonString); 1246 action.onSuccess(jsonString);
1159 } else { 1247 } else {
1160 action.onError(new Error(jsonObject.getString("message"))); 1248 action.onError(new Error(jsonObject.getString("message")));
1161 } 1249 }
1162 } catch (JSONException e) { 1250 } catch (JSONException e) {
1163 action.onError(null); 1251 action.onError(null);
1164 } 1252 }
1165 } 1253 }
1166 } 1254 }
1167 1255
1168 public static Bitmap getBitmapFromAsset(Context context, String filePath) { 1256 public static Bitmap getBitmapFromAsset(Context context, String filePath) {
1169 AssetManager assetManager = context.getAssets(); 1257 AssetManager assetManager = context.getAssets();
1170 InputStream istr; 1258 InputStream istr;
1171 Bitmap bitmap = null; 1259 Bitmap bitmap = null;
1172 try { 1260 try {
1173 istr = assetManager.open(filePath); 1261 istr = assetManager.open(filePath);
1174 bitmap = BitmapFactory.decodeStream(istr); 1262 bitmap = BitmapFactory.decodeStream(istr);
1175 } catch (IOException e) { 1263 } catch (IOException e) {
1176 Debug.normal("error: %s", e.getMessage()); 1264 Debug.normal("error: %s", e.getMessage());
1177 } 1265 }
1178 return bitmap; 1266 return bitmap;
1179 } 1267 }
1180 1268
1181 public static String getResponseData(ResponseBody response) { 1269 public static String getResponseData(ResponseBody response) {
1182 1270
1183 String unzipString = ""; 1271 String unzipString = "";
1184 try { 1272 try {
1185 unzipString = response.string(); 1273 unzipString = response.string();
1186 Debug.normal("RESPONSE: "+unzipString); 1274 Debug.normal("RESPONSE: "+unzipString);
1187 } catch (IOException e) { 1275 } catch (IOException e) {
1188 e.printStackTrace(); 1276 e.printStackTrace();
1189 } 1277 }
1190 return unzipString; 1278 return unzipString;
1191 } 1279 }
1192 1280
1281
1282 public static void writeToFile(String data)
1283 {
1284 String path =
1285 Environment.getExternalStorageDirectory() + File.separator + "yourFolder";
1286 // Create the folder.
1287 File folder = new File(path);
1288 folder.mkdirs();
1289
1290 // Create the file.
1291 File file = new File(folder, "config.txt");
1292 // Save your stream, don't forget to flush() it before closing it.
1293
1294 try
1295 {
1296 file.createNewFile();
1297 FileOutputStream fOut = new FileOutputStream(file);
1298 OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
1299 myOutWriter.append(data);
1300
1301 myOutWriter.close();
1302
1303 fOut.flush();
1304 fOut.close();
app/src/main/java/com/dinhcv/lifelogpedometer/portal/RequestPostImage.java
File was created 1 package com.dinhcv.lifelogpedometer.portal;
2
3 /**
4 * Created by Administrator on 25/12/2017.
5 */
6 import android.util.Log;
7
8 import java.io.BufferedReader;
9 import java.io.BufferedWriter;
10 import java.io.IOException;
11 import java.io.InputStreamReader;
12 import java.io.OutputStream;
13 import java.io.OutputStreamWriter;
14 import java.net.HttpURLConnection;
15 import java.net.URL;
16
17 /**
18 * class to make Http RequestPostImage to the web
19 */
20 public class RequestPostImage {
21
22 private static final String TAG = RequestPostImage.class.getSimpleName();
23
24 public static String post(String serverUrl,String dataToSend){
25 try {
26 URL url = new URL(serverUrl);
27 HttpURLConnection con = (HttpURLConnection) url.openConnection();
28 //set timeout of 30 seconds
29 con.setConnectTimeout(1000 * 30);
30 con.setReadTimeout(1000 * 30);
31 //method
32 con.setRequestMethod("POST");
33 con.setDoOutput(true);
34
35 OutputStream os = con.getOutputStream();
36 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
37
38 //make request
39 writer.write(dataToSend);
40 writer.flush();
41 writer.close();
42 os.close();
43
44 //get the response
45 int responseCode = con.getResponseCode();
46
47 if(responseCode == HttpURLConnection.HTTP_OK){
48 //read the response
49 StringBuilder sb = new StringBuilder();
50
51 BufferedReader reader = new BufferedReader(
52 new InputStreamReader(con.getInputStream()));
53 String line;
54
55 //loop through the response from the server
56 while ((line = reader.readLine()) != null){
57 sb.append(line).append("\n");
58 }
59
60 //return the response
61 return sb.toString();
62 }else{
63 Log.e(TAG,"ERROR - Invalid response code from server "+ responseCode);
64 return null;
65 }
66
67 } catch (IOException e) {
68 e.printStackTrace();
69 Log.e(TAG,"ERROR "+e);
70 return null;
71 }
72 }
73 }
app/src/main/res/drawable/add_ic.PNG

2.33 KB | W: | H:

838 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/layout/activity_register.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:tools="http://schemas.android.com/tools" 2 xmlns:tools="http://schemas.android.com/tools"
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:gravity="center_horizontal" 5 android:gravity="center_horizontal"
6 android:orientation="vertical" 6 android:orientation="vertical"
7 android:background="@drawable/bg"
7 tools:context="com.dinhcv.lifelogpedometer.activity.LoginActivity"> 8 tools:context="com.dinhcv.lifelogpedometer.activity.LoginActivity">
8 9
9 <include layout="@layout/layout_toolbar" /> 10 <include layout="@layout/layout_toolbar" />
10 11
11 <ScrollView 12 <ScrollView
12 android:id="@+id/login_form" 13 android:id="@+id/login_form"
13 android:layout_width="match_parent" 14 android:layout_width="match_parent"
14 android:layout_height="match_parent" 15 android:layout_height="match_parent"
15 android:layout_above="@+id/ll_bot" 16 android:layout_above="@+id/ll_bot"
16 android:layout_below="@+id/ll_toolBar"> 17 android:layout_below="@+id/ll_toolBar">
17 18
18 <LinearLayout 19 <LinearLayout
19 android:id="@+id/email_login_form" 20 android:id="@+id/email_login_form"
20 android:layout_width="match_parent" 21 android:layout_width="match_parent"
21 android:layout_height="wrap_content" 22 android:layout_height="wrap_content"
22 android:background="@color/background_main"
23 android:orientation="vertical" 23 android:orientation="vertical"
24 android:paddingTop="30dp"> 24 android:paddingTop="30dp">
25 25
26 <LinearLayout 26 <LinearLayout
27 android:layout_width="match_parent" 27 android:layout_width="match_parent"
28 android:layout_height="wrap_content" 28 android:layout_height="wrap_content"
29 android:orientation="horizontal" 29 android:orientation="horizontal"
30 android:paddingLeft="10dp"> 30 android:paddingLeft="10dp">
31 31
32 <de.hdodenhof.circleimageview.CircleImageView 32 <de.hdodenhof.circleimageview.CircleImageView
33 xmlns:app="http://schemas.android.com/apk/res-auto" 33 xmlns:app="http://schemas.android.com/apk/res-auto"
34 android:id="@+id/profile_image" 34 android:id="@+id/profile_image"
35 android:layout_width="@dimen/add_img_height" 35 android:layout_width="@dimen/add_img_height"
36 android:layout_height="@dimen/add_img_height" 36 android:layout_height="@dimen/add_img_height"
37 android:src="@drawable/add_ic" 37 android:src="@drawable/add_ic"
38 app:civ_border_width="2dp" 38 app:civ_border_width="2dp"
39 app:civ_border_color="#FF000000"/> 39 app:civ_border_color="#FFFFFF"/>
40 40
41 <LinearLayout 41 <LinearLayout
42 android:layout_width="match_parent" 42 android:layout_width="match_parent"
43 android:layout_height="wrap_content" 43 android:layout_height="wrap_content"
44 android:layout_marginTop="10dp" 44 android:layout_marginTop="10dp"
45 android:orientation="vertical" 45 android:orientation="vertical"
46 android:paddingLeft="10dp" 46 android:paddingLeft="10dp"
47 android:paddingRight="20dp"> 47 android:paddingRight="20dp">
48 48
49 <TextView 49 <TextView
50 style="@style/text_content_style" 50 style="@style/text_content_style"
51 android:layout_width="match_parent" 51 android:layout_width="match_parent"
52 android:layout_height="wrap_content" 52 android:layout_height="wrap_content"
53 android:text="@string/username" /> 53 android:text="@string/username" />
54 54
55 <EditText 55 <EditText
56 android:id="@+id/edt_user" 56 android:id="@+id/edt_user"
57 style="@style/edit_text_single_line" 57 style="@style/edit_text_single_line"
58 android:layout_width="match_parent" 58 android:layout_width="match_parent"
59 android:layout_height="wrap_content" 59 android:layout_height="wrap_content"
60 android:layout_marginTop="8dp" 60 android:layout_marginTop="8dp"
61 android:gravity="left" 61 android:gravity="left"
62 android:hint="" 62 android:hint=""
63 android:padding="8dp" /> 63 android:padding="8dp" />
64 64
65 </LinearLayout> 65 </LinearLayout>
66 66
67 </LinearLayout> 67 </LinearLayout>
68 68
69 <LinearLayout 69 <LinearLayout
70 android:layout_width="match_parent" 70 android:layout_width="match_parent"
71 android:layout_height="wrap_content" 71 android:layout_height="wrap_content"
72 android:layout_marginTop="10dp" 72 android:layout_marginTop="10dp"
73 android:orientation="vertical" 73 android:orientation="vertical"
74 android:paddingLeft="20dp" 74 android:paddingLeft="20dp"
75 android:paddingRight="20dp"> 75 android:paddingRight="20dp">
76 76
77 <TextView 77 <TextView
78 style="@style/text_content_style" 78 style="@style/text_content_style"
79 android:layout_width="match_parent" 79 android:layout_width="match_parent"
80 android:layout_height="wrap_content" 80 android:layout_height="wrap_content"
81 android:text="@string/name" /> 81 android:text="@string/name" />
82 82
83 <EditText 83 <EditText
84 android:id="@+id/edt_name" 84 android:id="@+id/edt_name"
85 style="@style/edit_text_single_line" 85 style="@style/edit_text_single_line"
86 android:layout_width="match_parent" 86 android:layout_width="match_parent"
87 android:layout_height="wrap_content" 87 android:layout_height="wrap_content"
88 android:layout_marginTop="8dp" 88 android:layout_marginTop="8dp"
89 android:gravity="left" 89 android:gravity="left"
90 android:hint="" 90 android:hint=""
91 android:padding="8dp" /> 91 android:padding="8dp" />
92 92
93 </LinearLayout> 93 </LinearLayout>
94 94
95 <LinearLayout 95 <LinearLayout
96 android:layout_width="match_parent" 96 android:layout_width="match_parent"
97 android:layout_height="wrap_content" 97 android:layout_height="wrap_content"
98 android:layout_marginTop="10dp" 98 android:layout_marginTop="10dp"
99 android:orientation="vertical" 99 android:orientation="vertical"
100 android:paddingLeft="20dp" 100 android:paddingLeft="20dp"
101 android:paddingRight="20dp"> 101 android:paddingRight="20dp">
102 102
103 <TextView 103 <TextView
104 style="@style/text_content_style" 104 style="@style/text_content_style"
105 android:layout_width="match_parent" 105 android:layout_width="match_parent"
106 android:layout_height="wrap_content" 106 android:layout_height="wrap_content"
107 android:text="@string/nickname" /> 107 android:text="@string/nickname" />
108 108
109 <EditText 109 <EditText
110 android:id="@+id/edt_nickName" 110 android:id="@+id/edt_nickName"
111 style="@style/edit_text_single_line" 111 style="@style/edit_text_single_line"
112 android:layout_width="match_parent" 112 android:layout_width="match_parent"
113 android:layout_height="wrap_content" 113 android:layout_height="wrap_content"
114 android:layout_marginTop="8dp" 114 android:layout_marginTop="8dp"
115 android:gravity="left" 115 android:gravity="left"
116 android:hint="" 116 android:hint=""
117 android:padding="8dp" /> 117 android:padding="8dp" />
118 118
119 </LinearLayout> 119 </LinearLayout>
120 120
121 <LinearLayout 121 <LinearLayout
122 android:layout_width="match_parent" 122 android:layout_width="match_parent"
123 android:layout_height="wrap_content" 123 android:layout_height="wrap_content"
124 android:layout_marginTop="10dp" 124 android:layout_marginTop="10dp"
125 android:orientation="vertical" 125 android:orientation="vertical"
126 android:paddingLeft="20dp" 126 android:paddingLeft="20dp"
127 android:paddingRight="20dp"> 127 android:paddingRight="20dp">
128 128
129 <TextView 129 <TextView
130 style="@style/text_content_style" 130 style="@style/text_content_style"
131 android:layout_width="match_parent" 131 android:layout_width="match_parent"
132 android:layout_height="wrap_content" 132 android:layout_height="wrap_content"
133 android:text="@string/email" /> 133 android:text="@string/email" />
134 134
135 <EditText 135 <EditText
136 android:id="@+id/edt_email" 136 android:id="@+id/edt_email"
137 style="@style/edit_text_single_line" 137 style="@style/edit_text_single_line"
138 android:layout_width="match_parent" 138 android:layout_width="match_parent"
139 android:layout_height="wrap_content" 139 android:layout_height="wrap_content"
140 android:layout_marginTop="8dp" 140 android:layout_marginTop="8dp"
141 android:gravity="left" 141 android:gravity="left"
142 android:hint="" 142 android:hint=""
143 android:inputType="textEmailAddress" 143 android:inputType="textEmailAddress"
144 android:padding="8dp" /> 144 android:padding="8dp" />
145 145
146 </LinearLayout> 146 </LinearLayout>
147 147
148 <LinearLayout 148 <LinearLayout
149 android:layout_width="match_parent" 149 android:layout_width="match_parent"
150 android:layout_height="wrap_content" 150 android:layout_height="wrap_content"
151 android:layout_marginTop="10dp" 151 android:layout_marginTop="10dp"
152 android:orientation="vertical" 152 android:orientation="vertical"
153 android:paddingLeft="20dp" 153 android:paddingLeft="20dp"
154 android:paddingRight="20dp"> 154 android:paddingRight="20dp">
155 155
156 <TextView 156 <TextView
157 style="@style/text_content_style" 157 style="@style/text_content_style"
158 android:layout_width="match_parent" 158 android:layout_width="match_parent"
159 android:layout_height="wrap_content" 159 android:layout_height="wrap_content"
160 android:text="@string/password" /> 160 android:text="@string/password" />
161 161
162 <EditText 162 <EditText
163 android:id="@+id/edt_password" 163 android:id="@+id/edt_password"
164 style="@style/edit_text_single_line" 164 style="@style/edit_text_single_line"
165 android:layout_width="match_parent" 165 android:layout_width="match_parent"
166 android:layout_height="wrap_content" 166 android:layout_height="wrap_content"
167 android:layout_marginTop="8dp" 167 android:layout_marginTop="8dp"
168 android:gravity="left" 168 android:gravity="left"
169 android:hint="" 169 android:hint=""
170 android:inputType="textPassword" 170 android:inputType="textPassword"
171 android:padding="8dp" /> 171 android:padding="8dp" />
172 172
173 </LinearLayout> 173 </LinearLayout>
174 174
175 <LinearLayout 175 <LinearLayout
176 android:layout_width="match_parent" 176 android:layout_width="match_parent"
177 android:layout_height="wrap_content" 177 android:layout_height="wrap_content"
178 android:layout_marginTop="10dp" 178 android:layout_marginTop="10dp"
179 android:orientation="vertical" 179 android:orientation="vertical"
180 android:paddingLeft="20dp" 180 android:paddingLeft="20dp"
181 android:paddingRight="20dp"> 181 android:paddingRight="20dp">
182 182
183 <TextView 183 <TextView
184 style="@style/text_content_style" 184 style="@style/text_content_style"
185 android:layout_width="match_parent" 185 android:layout_width="match_parent"
186 android:layout_height="wrap_content" 186 android:layout_height="wrap_content"
187 android:text="@string/confirm_pass" /> 187 android:text="@string/confirm_pass" />
188 188
189 <EditText 189 <EditText
190 android:id="@+id/edt_confirmPass" 190 android:id="@+id/edt_confirmPass"
191 style="@style/edit_text_single_line" 191 style="@style/edit_text_single_line"
192 android:layout_width="match_parent" 192 android:layout_width="match_parent"
193 android:layout_height="wrap_content" 193 android:layout_height="wrap_content"
194 android:layout_marginTop="8dp" 194 android:layout_marginTop="8dp"
195 android:gravity="left" 195 android:gravity="left"
196 android:hint="" 196 android:hint=""
197 android:padding="8dp" 197 android:padding="8dp"
198 android:inputType="textPassword"/> 198 android:inputType="textPassword"/>
199 199
200 </LinearLayout> 200 </LinearLayout>
201 201
202 <LinearLayout 202 <LinearLayout
203 android:layout_width="match_parent" 203 android:layout_width="match_parent"
204 android:layout_height="wrap_content" 204 android:layout_height="wrap_content"
205 android:layout_marginTop="10dp" 205 android:layout_marginTop="10dp"
206 android:orientation="vertical" 206 android:orientation="vertical"
207 android:paddingLeft="20dp" 207 android:paddingLeft="20dp"
208 android:paddingRight="20dp"> 208 android:paddingRight="20dp">
209 209
210 <TextView 210 <TextView
211 style="@style/text_content_style" 211 style="@style/text_content_style"
212 android:layout_width="match_parent" 212 android:layout_width="match_parent"
213 android:layout_height="wrap_content" 213 android:layout_height="wrap_content"
214 android:text="@string/sex" /> 214 android:text="@string/sex" />
215 215
216 <RelativeLayout 216 <RelativeLayout
217 android:id="@+id/rl_sex" 217 android:id="@+id/rl_sex"
218 style="@style/edit_text_single_line" 218 style="@style/edit_text_single_line"
219 android:layout_width="match_parent" 219 android:layout_width="match_parent"
220 android:layout_height="wrap_content" 220 android:layout_height="wrap_content"
221 android:orientation="horizontal" 221 android:orientation="horizontal"
222 android:padding="12dp"> 222 android:padding="12dp">
223 223
224 <TextView 224 <TextView
225 android:id="@+id/tv_sex" 225 android:id="@+id/tv_sex"
226 style="@style/text_edtext_style" 226 style="@style/text_edtext_style"
227 android:layout_width="wrap_content" 227 android:layout_width="wrap_content"
228 android:layout_height="wrap_content" 228 android:layout_height="wrap_content"
229 android:text="@string/please_select" /> 229 android:text="@string/please_select" />
230 230
231 <ImageView 231 <ImageView
232 android:id="@+id/img_expan_1" 232 android:id="@+id/img_expan_1"
233 android:layout_width="@dimen/image_down" 233 android:layout_width="@dimen/image_down"
234 android:layout_height="@dimen/image_down" 234 android:layout_height="@dimen/image_down"
235 android:layout_alignParentRight="true" 235 android:layout_alignParentRight="true"
236 android:src="@drawable/ic_down" /> 236 android:src="@drawable/ic_down" />
237 237
238 </RelativeLayout> 238 </RelativeLayout>
239 239
240 </LinearLayout> 240 </LinearLayout>
241 241
242 <LinearLayout 242 <LinearLayout
243 android:layout_width="match_parent" 243 android:layout_width="match_parent"
244 android:layout_height="wrap_content" 244 android:layout_height="wrap_content"
245 android:layout_marginTop="10dp" 245 android:layout_marginTop="10dp"
246 android:orientation="vertical" 246 android:orientation="vertical"
247 android:paddingLeft="20dp" 247 android:paddingLeft="20dp"
248 android:paddingRight="20dp"> 248 android:paddingRight="20dp">
249 249
250 <TextView 250 <TextView
251 style="@style/text_content_style" 251 style="@style/text_content_style"
252 android:layout_width="match_parent" 252 android:layout_width="match_parent"
253 android:layout_height="wrap_content" 253 android:layout_height="wrap_content"
254 android:text="@string/birthday" /> 254 android:text="@string/birthday" />
255 255
256 <RelativeLayout 256 <RelativeLayout
257 android:id="@+id/rl_birthday" 257 android:id="@+id/rl_birthday"
258 style="@style/edit_text_single_line" 258 style="@style/edit_text_single_line"
259 android:layout_width="match_parent" 259 android:layout_width="match_parent"
260 android:layout_height="wrap_content" 260 android:layout_height="wrap_content"
261 android:orientation="horizontal" 261 android:orientation="horizontal"
262 android:padding="12dp"> 262 android:padding="12dp">
263 263
264 <TextView 264 <TextView
265 android:id="@+id/tv_birthday" 265 android:id="@+id/tv_birthday"
266 style="@style/text_edtext_style" 266 style="@style/text_edtext_style"
267 android:layout_width="wrap_content" 267 android:layout_width="wrap_content"
268 android:layout_height="wrap_content" 268 android:layout_height="wrap_content"
269 android:text="@string/please_select" /> 269 android:text="@string/please_select" />
270 270
271 <ImageView 271 <ImageView
272 android:layout_width="@dimen/image_down" 272 android:layout_width="@dimen/image_down"
273 android:layout_height="@dimen/image_down" 273 android:layout_height="@dimen/image_down"
274 android:layout_alignParentRight="true" 274 android:layout_alignParentRight="true"
275 android:src="@drawable/ic_down" /> 275 android:src="@drawable/ic_down" />
276 276
277 </RelativeLayout> 277 </RelativeLayout>
278 278
279 </LinearLayout> 279 </LinearLayout>
280 280
281 <LinearLayout 281 <LinearLayout
282 android:layout_width="match_parent" 282 android:layout_width="match_parent"
283 android:layout_height="wrap_content" 283 android:layout_height="wrap_content"
284 android:layout_marginTop="10dp" 284 android:layout_marginTop="10dp"
285 android:orientation="vertical" 285 android:orientation="vertical"
286 android:paddingLeft="20dp" 286 android:paddingLeft="20dp"
287 android:paddingRight="20dp"> 287 android:paddingRight="20dp">
288 288
289 <TextView 289 <TextView
290 style="@style/text_content_style" 290 style="@style/text_content_style"
291 android:layout_width="match_parent" 291 android:layout_width="match_parent"
292 android:layout_height="wrap_content" 292 android:layout_height="wrap_content"
293 android:text="@string/height" /> 293 android:text="@string/height" />
294 294
295 <LinearLayout 295 <LinearLayout
296 android:layout_width="match_parent" 296 android:layout_width="match_parent"
297 android:layout_height="wrap_content" 297 android:layout_height="wrap_content"
298 android:orientation="horizontal" 298 android:orientation="horizontal"
299 android:layout_marginTop="8dp" 299 android:layout_marginTop="8dp"
300 android:gravity="center_vertical" 300 android:gravity="center_vertical"
301 android:weightSum="100"> 301 android:weightSum="100">
302 302
303 <EditText 303 <EditText
304 android:id="@+id/edt_height" 304 android:id="@+id/edt_height"
305 style="@style/edit_text_single_line" 305 style="@style/edit_text_single_line"
306 android:layout_width="0dp" 306 android:layout_width="0dp"
307 android:layout_height="wrap_content" 307 android:layout_height="wrap_content"
308 android:layout_weight="50" 308 android:layout_weight="50"
309 android:gravity="left" 309 android:gravity="left"
310 android:hint="" 310 android:hint=""
311 android:padding="8dp" 311 android:padding="8dp"
312 android:inputType="number"/> 312 android:inputType="number"/>
313 313
314 <TextView 314 <TextView
315 android:layout_width="wrap_content" 315 android:layout_width="wrap_content"
316 android:layout_height="wrap_content" 316 android:layout_height="wrap_content"
317 android:text="@string/cm" 317 android:text="@string/cm"
318 android:paddingLeft="10dp" 318 android:paddingLeft="10dp"
319 style="@style/text_content_style" /> 319 style="@style/text_content_style" />
320 320
321 </LinearLayout> 321 </LinearLayout>
322 322
323 323
324 </LinearLayout> 324 </LinearLayout>
325 325
326 <LinearLayout 326 <LinearLayout
327 android:layout_width="match_parent" 327 android:layout_width="match_parent"
328 android:layout_height="wrap_content" 328 android:layout_height="wrap_content"
329 android:layout_marginTop="10dp" 329 android:layout_marginTop="10dp"
330 android:orientation="vertical" 330 android:orientation="vertical"
331 android:paddingLeft="20dp" 331 android:paddingLeft="20dp"
332 android:paddingRight="20dp"> 332 android:paddingRight="20dp">
333 333
334 <TextView 334 <TextView
335 style="@style/text_content_style" 335 style="@style/text_content_style"
336 android:layout_width="match_parent" 336 android:layout_width="match_parent"
337 android:layout_height="wrap_content" 337 android:layout_height="wrap_content"
338 android:text="@string/weight" /> 338 android:text="@string/weight" />
339 339
340 <LinearLayout 340 <LinearLayout
341 android:layout_width="match_parent" 341 android:layout_width="match_parent"
342 android:layout_height="wrap_content" 342 android:layout_height="wrap_content"
343 android:orientation="horizontal" 343 android:orientation="horizontal"
344 android:layout_marginTop="8dp" 344 android:layout_marginTop="8dp"
345 android:gravity="center_vertical" 345 android:gravity="center_vertical"
346 android:weightSum="100"> 346 android:weightSum="100">
347 347
348 <EditText 348 <EditText
349 android:id="@+id/edt_weight" 349 android:id="@+id/edt_weight"
350 style="@style/edit_text_single_line" 350 style="@style/edit_text_single_line"
351 android:layout_width="0dp" 351 android:layout_width="0dp"
352 android:layout_height="wrap_content" 352 android:layout_height="wrap_content"
353 android:layout_weight="50" 353 android:layout_weight="50"
354 android:gravity="left" 354 android:gravity="left"
355 android:hint="" 355 android:hint=""
356 android:padding="8dp" 356 android:padding="8dp"
357 android:inputType="number" /> 357 android:inputType="number" />
358 358
359 <TextView 359 <TextView
360 android:layout_width="wrap_content" 360 android:layout_width="wrap_content"
361 android:layout_height="wrap_content" 361 android:layout_height="wrap_content"
362 android:text="@string/kg" 362 android:text="@string/kg"
363 android:paddingLeft="10dp" 363 android:paddingLeft="10dp"
364 style="@style/text_content_style" /> 364 style="@style/text_content_style" />
365 </LinearLayout> 365 </LinearLayout>
366 366
367 </LinearLayout> 367 </LinearLayout>
368 368
369 <LinearLayout 369 <LinearLayout
370 android:layout_width="match_parent" 370 android:layout_width="match_parent"
371 android:layout_height="wrap_content" 371 android:layout_height="wrap_content"
372 android:layout_marginTop="10dp" 372 android:layout_marginTop="10dp"
373 android:orientation="vertical" 373 android:orientation="vertical"
374 android:paddingLeft="20dp" 374 android:paddingLeft="20dp"
375 android:paddingRight="20dp"> 375 android:paddingRight="20dp">
376 376
377 <TextView 377 <TextView
378 style="@style/text_content_style" 378 style="@style/text_content_style"
379 android:layout_width="match_parent" 379 android:layout_width="match_parent"
380 android:layout_height="wrap_content" 380 android:layout_height="wrap_content"
381 android:text="@string/body_fat_percent" /> 381 android:text="@string/body_fat_percent" />
382 382
383 <LinearLayout 383 <LinearLayout
384 android:layout_width="match_parent" 384 android:layout_width="match_parent"
385 android:layout_height="wrap_content" 385 android:layout_height="wrap_content"
386 android:orientation="horizontal" 386 android:orientation="horizontal"
387 android:layout_marginTop="8dp" 387 android:layout_marginTop="8dp"
388 android:gravity="center_vertical" 388 android:gravity="center_vertical"
389 android:weightSum="100"> 389 android:weightSum="100">
390 390
391 <EditText 391 <EditText
392 android:id="@+id/edt_bodyFat" 392 android:id="@+id/edt_bodyFat"
393 style="@style/edit_text_single_line" 393 style="@style/edit_text_single_line"
394 android:layout_width="0dp" 394 android:layout_width="0dp"
395 android:layout_height="wrap_content" 395 android:layout_height="wrap_content"
396 android:layout_weight="50" 396 android:layout_weight="50"
397 android:gravity="left" 397 android:gravity="left"
398 android:hint="" 398 android:hint=""
399 android:padding="8dp" 399 android:padding="8dp"
400 android:inputType="number" /> 400 android:inputType="number" />
401 401
402 <TextView 402 <TextView
403 android:layout_width="wrap_content" 403 android:layout_width="wrap_content"
404 android:layout_height="wrap_content" 404 android:layout_height="wrap_content"
405 android:text="@string/percen" 405 android:text="@string/percen"
406 android:paddingLeft="10dp" 406 android:paddingLeft="10dp"
407 style="@style/text_content_style" 407 style="@style/text_content_style"
408 /> 408 />
409 </LinearLayout> 409 </LinearLayout>
410 410
411 </LinearLayout> 411 </LinearLayout>
412 412
413 <LinearLayout 413 <LinearLayout
414 android:layout_width="match_parent" 414 android:layout_width="match_parent"
415 android:layout_height="wrap_content" 415 android:layout_height="wrap_content"
416 android:layout_marginTop="10dp" 416 android:layout_marginTop="10dp"
417 android:orientation="vertical" 417 android:orientation="vertical"
418 android:paddingLeft="20dp" 418 android:paddingLeft="20dp"
419 android:paddingRight="20dp"> 419 android:paddingRight="20dp">
420 420
421 <TextView 421 <TextView
422 style="@style/text_content_style" 422 style="@style/text_content_style"
423 android:layout_width="match_parent" 423 android:layout_width="match_parent"
424 android:layout_height="wrap_content" 424 android:layout_height="wrap_content"
425 android:text="@string/level_active" /> 425 android:text="@string/level_active" />
426 426
427 </LinearLayout> 427 </LinearLayout>
428 428
429 <LinearLayout 429 <LinearLayout
430 android:layout_width="match_parent" 430 android:layout_width="match_parent"
431 android:layout_height="wrap_content" 431 android:layout_height="wrap_content"
432 android:orientation="horizontal" 432 android:orientation="horizontal"
433 android:weightSum="90" 433 android:weightSum="90"
434 android:layout_margin="20dp"> 434 android:layout_margin="20dp">
435 435
436 <LinearLayout 436 <LinearLayout
437 android:id="@+id/ll_low" 437 android:id="@+id/ll_low"
438 android:layout_width="0dp" 438 android:layout_width="0dp"
439 android:layout_height="wrap_content" 439 android:layout_height="wrap_content"
440 android:background="@drawable/left_unselected_lev_bg" 440 android:background="@drawable/left_unselected_lev_bg"
441 android:layout_weight="30" 441 android:layout_weight="30"
442 android:gravity="center" 442 android:gravity="center"
443 android:padding="12dp"> 443 android:padding="12dp">
444 444
445 <TextView 445 <TextView
446 android:id="@+id/tv_low" 446 android:id="@+id/tv_low"
447 android:layout_width="wrap_content" 447 android:layout_width="wrap_content"
448 android:layout_height="wrap_content" 448 android:layout_height="wrap_content"
449 android:text="@string/low" 449 android:text="@string/low"
450 android:textColor="@color/black"/> 450 android:textColor="@color/black"/>
451 451
452 </LinearLayout> 452 </LinearLayout>
453 453
454 <LinearLayout 454 <LinearLayout
455 android:id="@+id/ll_mid" 455 android:id="@+id/ll_mid"
456 android:layout_width="0dp" 456 android:layout_width="0dp"
457 android:layout_height="wrap_content" 457 android:layout_height="wrap_content"
458 android:background="@drawable/mid_unselected_lev_bg" 458 android:background="@drawable/mid_unselected_lev_bg"
459 android:layout_weight="30" 459 android:layout_weight="30"
460 android:padding="12dp" 460 android:padding="12dp"
461 android:gravity="center"> 461 android:gravity="center">
462 462
463 <TextView 463 <TextView
464 android:id="@+id/tv_mid" 464 android:id="@+id/tv_mid"
465 android:layout_width="wrap_content" 465 android:layout_width="wrap_content"
466 android:layout_height="wrap_content" 466 android:layout_height="wrap_content"
467 android:text="@string/low" 467 android:text="@string/low"
468 android:textColor="@color/black"/> 468 android:textColor="@color/black"/>
469 469
470 </LinearLayout> 470 </LinearLayout>
471 471
472 <LinearLayout 472 <LinearLayout
473 android:id="@+id/ll_hight" 473 android:id="@+id/ll_hight"
474 android:layout_width="0dp" 474 android:layout_width="0dp"
475 android:layout_height="wrap_content" 475 android:layout_height="wrap_content"
476 android:background="@drawable/right_unselected_lev_bg" 476 android:background="@drawable/right_unselected_lev_bg"
477 android:layout_weight="30" 477 android:layout_weight="30"
478 android:padding="12dp" 478 android:padding="12dp"
479 android:gravity="center"> 479 android:gravity="center">
480 480
481 <TextView 481 <TextView
482 android:id="@+id/tv_hight" 482 android:id="@+id/tv_hight"
483 android:layout_width="wrap_content" 483 android:layout_width="wrap_content"
484 android:layout_height="wrap_content" 484 android:layout_height="wrap_content"
485 android:text="@string/low" 485 android:text="@string/low"
486 android:textColor="@color/black"/> 486 android:textColor="@color/black"/>
487 487
488 </LinearLayout> 488 </LinearLayout>
489 489
490 </LinearLayout> 490 </LinearLayout>
491 491
492 <LinearLayout 492 <LinearLayout
493 android:layout_width="match_parent" 493 android:layout_width="match_parent"
494 android:layout_height="wrap_content" 494 android:layout_height="wrap_content"
495 android:layout_marginTop="10dp" 495 android:layout_marginTop="10dp"
496 android:orientation="vertical" 496 android:orientation="vertical"
497 android:paddingLeft="20dp" 497 android:paddingLeft="20dp"
498 android:paddingRight="20dp"> 498 android:paddingRight="20dp">
499 499
500 <TextView 500 <TextView
501 style="@style/text_content_style" 501 style="@style/text_content_style"
502 android:layout_width="match_parent" 502 android:layout_width="match_parent"
503 android:layout_height="wrap_content" 503 android:layout_height="wrap_content"
504 android:text="@string/address" /> 504 android:text="@string/address" />
505 505
506 <RelativeLayout 506 <RelativeLayout
507 android:id="@+id/rl_address" 507 android:id="@+id/rl_address"
508 style="@style/edit_text_single_line" 508 style="@style/edit_text_single_line"
509 android:layout_width="match_parent" 509 android:layout_width="match_parent"
510 android:layout_height="wrap_content" 510 android:layout_height="wrap_content"
511 android:orientation="horizontal" 511 android:orientation="horizontal"
512 android:padding="12dp"> 512 android:padding="12dp">
513 513
514 <TextView 514 <TextView
515 android:id="@+id/tv_address" 515 android:id="@+id/tv_address"
516 style="@style/text_edtext_style" 516 style="@style/text_edtext_style"
517 android:layout_width="wrap_content" 517 android:layout_width="wrap_content"
518 android:layout_height="wrap_content" 518 android:layout_height="wrap_content"
519 android:text="@string/please_select" /> 519 android:text="@string/please_select" />
520 520
521 <ImageView 521 <ImageView
522 android:layout_width="@dimen/image_down" 522 android:layout_width="@dimen/image_down"
523 android:layout_height="@dimen/image_down" 523 android:layout_height="@dimen/image_down"
524 android:layout_alignParentRight="true" 524 android:layout_alignParentRight="true"
525 android:src="@drawable/ic_down" /> 525 android:src="@drawable/ic_down" />
526 526
527 </RelativeLayout> 527 </RelativeLayout>
528 528
529 </LinearLayout> 529 </LinearLayout>
530 530
531 <LinearLayout 531 <LinearLayout
532 android:layout_width="match_parent" 532 android:layout_width="match_parent"
533 android:layout_height="wrap_content" 533 android:layout_height="wrap_content"
534 android:layout_marginTop="10dp" 534 android:layout_marginTop="10dp"
535 android:orientation="vertical" 535 android:orientation="vertical"
536 android:paddingLeft="20dp" 536 android:paddingLeft="20dp"
537 android:paddingRight="20dp"> 537 android:paddingRight="20dp">
538 538
539 <TextView 539 <TextView
540 style="@style/text_content_style" 540 style="@style/text_content_style"
541 android:layout_width="match_parent" 541 android:layout_width="match_parent"
542 android:layout_height="wrap_content" 542 android:layout_height="wrap_content"
543 android:text="@string/comment" /> 543 android:text="@string/comment" />
544 544
545 <EditText 545 <EditText
546 android:id="@+id/edt_comment" 546 android:id="@+id/edt_comment"
547 style="@style/edit_text_multi_line" 547 style="@style/edit_text_multi_line"
548 android:layout_width="match_parent" 548 android:layout_width="match_parent"
549 android:layout_height="wrap_content" 549 android:layout_height="wrap_content"
550 android:layout_marginTop="8dp" 550 android:layout_marginTop="8dp"
551 android:gravity="left" 551 android:gravity="left"
552 android:hint="" 552 android:hint=""
553 android:padding="8dp" /> 553 android:padding="8dp" />
554 554
555 </LinearLayout> 555 </LinearLayout>
556 556
557 <LinearLayout 557 <LinearLayout
558 android:layout_width="match_parent" 558 android:layout_width="match_parent"
559 android:layout_height="wrap_content" 559 android:layout_height="wrap_content"
560 android:layout_marginTop="30dp" 560 android:layout_marginTop="30dp"
561 android:orientation="vertical" 561 android:orientation="vertical"
562 android:paddingLeft="50dp" 562 android:paddingLeft="50dp"
563 android:paddingRight="50dp" 563 android:paddingRight="50dp"
564 android:layout_marginBottom="10dp"> 564 android:layout_marginBottom="10dp">
565 565
566 <Button 566 <Button
567 android:id="@+id/btn_register" 567 android:id="@+id/btn_register"
568 style="@style/btn_login_style" 568 style="@style/btn_login_style"
569 android:layout_width="match_parent" 569 android:layout_width="match_parent"
570 android:layout_height="wrap_content" 570 android:layout_height="wrap_content"
571 android:layout_marginLeft="30dp" 571 android:layout_marginLeft="30dp"
572 android:layout_marginRight="30dp" 572 android:layout_marginRight="30dp"
573 android:layout_marginTop="8dp" 573 android:layout_marginTop="8dp"
574 android:gravity="center" 574 android:gravity="center"
575 android:text="@string/register_button" 575 android:text="@string/register_button"
576 android:textColor="@color/white" /> 576 android:textColor="@color/white" />
577 577
578 </LinearLayout> 578 </LinearLayout>
579 579
580 580
581 </LinearLayout> 581 </LinearLayout>
582 </ScrollView> 582 </ScrollView>
583 583
584 </RelativeLayout> 584 </RelativeLayout>