Commit 022ad6460225bf3e74a402b87d43463c793a2270

Authored by Dinh Chu
Exists in master

Merge branch 'master' of http://timesfun.net/chudinhbka/lifelog_android

Showing 8 changed files Inline Diff

1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 <component name="ProjectModuleManager"> 3 <component name="ProjectModuleManager">
4 <modules> 4 <modules>
5 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> 5 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
6 <module fileurl="file://$PROJECT_DIR$/lifelog_android.iml" filepath="$PROJECT_DIR$/lifelog_android.iml" /> 6 <module fileurl="file://$PROJECT_DIR$/lifelog_new.iml" filepath="$PROJECT_DIR$/lifelog_new.iml" />
7 <module fileurl="file://D:\Project\Git\lifelog_android\lifelogpedometer.iml" filepath="D:\Project\Git\lifelog_android\lifelogpedometer.iml" /> 7 <module fileurl="file://D:\Project\Git\lifelog_android\lifelogpedometer.iml" filepath="D:\Project\Git\lifelog_android\lifelogpedometer.iml" />
8 </modules> 8 </modules>
9 </component> 9 </component>
10 </project> 10 </project>
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="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 13 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
14 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 14 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
15 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
15 16
16 <application 17 <application
17 android:name=".LifeLogApplication" 18 android:name=".LifeLogApplication"
18 android:allowBackup="true" 19 android:allowBackup="true"
19 android:icon="@mipmap/ic_launcher" 20 android:icon="@mipmap/ic_launcher"
20 android:label="@string/app_name" 21 android:label="@string/app_name"
21 android:roundIcon="@mipmap/ic_launcher_round" 22 android:roundIcon="@mipmap/ic_launcher_round"
22 android:supportsRtl="true" 23 android:supportsRtl="true"
23 android:largeHeap="true" 24 android:largeHeap="true"
24 android:theme="@style/AppTheme"> 25 android:theme="@style/AppTheme">
25 <meta-data 26 <meta-data
26 android:name="com.google.android.maps.v2.API_KEY" 27 android:name="com.google.android.maps.v2.API_KEY"
27 android:value="AIzaSyCDKYsvb0iDXSRm9YnQ8kh5Gzpbpzcpz4s" /> 28 android:value="AIzaSyCDKYsvb0iDXSRm9YnQ8kh5Gzpbpzcpz4s" />
28 29
29 <activity 30 <activity
30 android:name=".activity.WelcomeActivity" 31 android:name=".activity.WelcomeActivity"
31 android:screenOrientation="portrait" 32 android:screenOrientation="portrait"
32 android:theme="@style/AppNoActionBar"> 33 android:theme="@style/AppNoActionBar">
33 <intent-filter> 34 <intent-filter>
34 <action android:name="android.intent.action.MAIN" /> 35 <action android:name="android.intent.action.MAIN" />
35 36
36 <category android:name="android.intent.category.LAUNCHER" /> 37 <category android:name="android.intent.category.LAUNCHER" />
37 </intent-filter> 38 </intent-filter>
38 </activity> 39 </activity>
39 <activity 40 <activity
40 android:name=".activity.LoginActivity" 41 android:name=".activity.LoginActivity"
41 android:screenOrientation="portrait" 42 android:screenOrientation="portrait"
42 android:theme="@style/AppNoActionBar"/> 43 android:theme="@style/AppNoActionBar"/>
43 44
44 <activity 45 <activity
45 android:name=".activity.PedometerActivity" 46 android:name=".activity.PedometerActivity"
46 android:screenOrientation="portrait" 47 android:screenOrientation="portrait"
47 android:theme="@style/AppNoActionBar"/> 48 android:theme="@style/AppNoActionBar"/>
48 <activity 49 <activity
49 android:name=".activity.RegisterActivity" 50 android:name=".activity.RegisterActivity"
50 android:screenOrientation="portrait" 51 android:screenOrientation="portrait"
51 android:theme="@style/AppNoActionBar"/> 52 android:theme="@style/AppNoActionBar"/>
52 <activity 53 <activity
53 android:name=".activity.InputConfirmCodeActivity" 54 android:name=".activity.InputConfirmCodeActivity"
54 android:screenOrientation="portrait" 55 android:screenOrientation="portrait"
55 android:theme="@style/AppNoActionBar"/> 56 android:theme="@style/AppNoActionBar"/>
56 57
57 58
58 <!--<activity--> 59 <!--<activity-->
59 <!--android:name=".activity.HistoryFragment"--> 60 <!--android:name=".activity.HistoryFragment"-->
60 <!--android:screenOrientation="portrait"--> 61 <!--android:screenOrientation="portrait"-->
61 <!--android:theme="@style/AppNoActionBar"></activity>--> 62 <!--android:theme="@style/AppNoActionBar"></activity>-->
62 63
63 </application> 64 </application>
64 65
65 </manifest> 66 </manifest>
app/src/main/java/com/dinhcv/lifelogpedometer/activity/MapFragment.java
1 package com.dinhcv.lifelogpedometer.activity; 1 package com.dinhcv.lifelogpedometer.activity;
2 2
3 import android.Manifest;
3 import android.app.Activity; 4 import android.app.Activity;
4 import android.content.Context; 5 import android.content.Context;
6 import android.content.pm.PackageManager;
7 import android.location.Location;
8 import android.location.LocationListener;
9 import android.location.LocationManager;
5 import android.os.Bundle; 10 import android.os.Bundle;
6 import android.support.annotation.Nullable; 11 import android.support.annotation.Nullable;
12 import android.support.v4.app.ActivityCompat;
13 import android.support.v4.content.ContextCompat;
7 import android.support.v4.app.Fragment; 14 import android.support.v4.app.Fragment;
8 import android.util.Log; 15 import android.util.Log;
9 import android.view.LayoutInflater; 16 import android.view.LayoutInflater;
10 import android.view.View; 17 import android.view.View;
11 import android.view.ViewGroup; 18 import android.view.ViewGroup;
12 19
13 import com.dinhcv.lifelogpedometer.R; 20 import com.dinhcv.lifelogpedometer.R;
21 import com.google.android.gms.maps.CameraUpdateFactory;
14 import com.google.android.gms.maps.GoogleMap; 22 import com.google.android.gms.maps.GoogleMap;
15 import com.google.android.gms.maps.OnMapReadyCallback; 23 import com.google.android.gms.maps.OnMapReadyCallback;
24 import com.google.android.gms.maps.SupportMapFragment;
25 import com.google.android.gms.maps.model.LatLng;
26 import com.google.android.gms.maps.model.MarkerOptions;
27 import com.google.android.gms.maps.model.PolylineOptions;
16 28
29 import static android.content.Context.LOCATION_SERVICE;
30
17 public class MapFragment extends Fragment implements SettingFragmentPresenter, OnMapReadyCallback { 31 public class MapFragment extends Fragment implements SettingFragmentPresenter, OnMapReadyCallback {
18 private View mRootView; 32 private View mRootView;
33 private PolylineOptions polylineOptions = new PolylineOptions();
34 private LocationManager mLocationManager;
35 // The minimum distance to change Updates in meters
36 private static final long LOCATION_REFRESH_DISTANCE = 10;
19 37
38 // The minimum time between updates in milliseconds
39 private static final long LOCATION_REFRESH_TIME = 10000;
40
41 private double lat = 0;
42 private double log = 0;
43
44 private SupportMapFragment mapFragment;
45 private GoogleMap googleMap;
46
20 @Override 47 @Override
21 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle 48 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
22 savedInstanceState) { 49 savedInstanceState) {
23 // Inflate the layout for this fragment 50 // Inflate the layout for this fragment
24 mRootView = inflater.inflate(R.layout.fragment_map, container, false); 51 mRootView = inflater.inflate(R.layout.fragment_map, container, false);
25 52
26 initView(mRootView); 53 initView(mRootView);
27 54
28 initData(); 55 initData();
29 56
30 return mRootView; 57 return mRootView;
31 } 58 }
32 59
33 /** 60 /**
34 * init view 61 * init view
35 * 62 *
36 * @param rootView view 63 * @param rootView view
37 */ 64 */
38 private void initView(View rootView) { 65 private void initView(View rootView) {
66 mapFragment = (SupportMapFragment) getChildFragmentManager()
67 .findFragmentById(R.id.map);
39 68
69 polylineOptions.color(ContextCompat.getColor(getActivity(),android.R.color.holo_red_dark));
70
40 } 71 }
41 72
42 /** 73 /**
43 * Init data 74 * Init data
44 */ 75 */
45 private void initData() { 76 private void initData() {
77 mLocationManager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
46 78
79 if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
80 return;
81 }
82 mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_REFRESH_TIME,
83 LOCATION_REFRESH_DISTANCE, mLocationListener);
47 } 84 }
48 85
86 private final LocationListener mLocationListener = new LocationListener() {
87 @Override
88 public void onLocationChanged(final Location location) {
89 //your code here
90 lat = location.getLatitude();
91 log = location.getLongitude();
92 polylineOptions.add(new LatLng(lat, log));
93 if (googleMap!= null) {
94 googleMap.addPolyline(polylineOptions);
95 }
96 //update
97 update();
98 }
49 99
100 @Override
101 public void onStatusChanged(String s, int i, Bundle bundle) {
102
103 }
104
105 @Override
106 public void onProviderEnabled(String s) {
107
108 }
109
110 @Override
111 public void onProviderDisabled(String s) {
112
113 }
114 };
115
116 private void update(){
117 mapFragment.getMapAsync(this);
118 }
119
120 private void updateLine(){
121 LatLng sydney = new LatLng(-34, 151);
122 LatLng melbourne=new LatLng(37.813, 144.9631);
123 LatLng auckland=new LatLng(36.8485, 174.7633);
124
125 polylineOptions.add(new LatLng[]{sydney,melbourne,auckland});
126 if (googleMap!= null) {
127 googleMap.addPolyline(polylineOptions);
128 }
129 }
130
50 @Override 131 @Override
51 public void onAttach(Context context) { 132 public void onAttach(Context context) {
52 super.onAttach(context); 133 super.onAttach(context);
53 if (context instanceof Activity) { 134 if (context instanceof Activity) {
54 135
55 } 136 }
56 } 137 }
57 138
58 139
59 /** 140 /**
60 * Save data 141 * Save data
61 */ 142 */
62 @Override 143 @Override
63 public void onSaveData() { 144 public void onSaveData() {
64 } 145 }
65 146
66 @Override 147 @Override
67 public void onInvalidate(boolean isInit) { 148 public void onInvalidate(boolean isInit) {
68 initData(); 149 initData();
69 } 150 }
70 151
71 152
72 @Override 153 @Override
73 public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 154 public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
74 super.onViewStateRestored(savedInstanceState); 155 super.onViewStateRestored(savedInstanceState);
75 156
76 initData(); 157 initData();
77 } 158 }
78 159
79 @Override 160 @Override
80 public void onMapReady(GoogleMap googleMap) { 161 public void onMapReady(GoogleMap gm) {
162
163 googleMap = gm;
164 LatLng pos=new LatLng(lat, log);
165 googleMap.addMarker(new MarkerOptions()
166 .position(pos));
167 googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(pos, 15.0f));
168
81 Log.i("SonLT","Readdy"); 169 Log.i("SonLT","Readdy");
170
171 //updateLine();
82 } 172 }
83 } 173 }
84 174
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.Intent; 5 import android.content.Intent;
5 import android.os.Build; 6 import android.os.Build;
6 import android.os.Bundle; 7 import android.os.Bundle;
7 import android.support.design.widget.TabLayout; 8 import android.support.design.widget.TabLayout;
8 import android.support.v4.app.Fragment; 9 import android.support.v4.app.Fragment;
9 import android.support.v4.app.FragmentManager; 10 import android.support.v4.app.FragmentManager;
10 import android.support.v4.app.FragmentPagerAdapter; 11 import android.support.v4.app.FragmentPagerAdapter;
11 import android.support.v4.content.PermissionChecker; 12 import android.support.v4.content.PermissionChecker;
12 import android.support.v4.view.ViewPager; 13 import android.support.v4.view.ViewPager;
13 import android.support.v7.widget.PopupMenu; 14 import android.support.v7.widget.PopupMenu;
14 import android.support.v7.widget.Toolbar; 15 import android.support.v7.widget.Toolbar;
15 import android.view.Gravity; 16 import android.view.Gravity;
17 import android.view.LayoutInflater;
16 import android.view.MenuItem; 18 import android.view.MenuItem;
17 import android.view.View; 19 import android.view.View;
18 import android.view.Window; 20 import android.view.Window;
19 import android.view.WindowManager; 21 import android.view.WindowManager;
20 import android.widget.ImageView; 22 import android.widget.ImageView;
21 import android.widget.PopupWindow; 23 import android.widget.PopupWindow;
24 import android.widget.TabHost;
22 import android.widget.TextView; 25 import android.widget.TextView;
23 import android.widget.Toast; 26 import android.widget.Toast;
24 27
25 import com.dinhcv.lifelogpedometer.R; 28 import com.dinhcv.lifelogpedometer.R;
26 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; 29 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
27 import com.dinhcv.lifelogpedometer.utils.Debug; 30 import com.dinhcv.lifelogpedometer.utils.Debug;
28 import com.dinhcv.lifelogpedometer.utils.Utils; 31 import com.dinhcv.lifelogpedometer.utils.Utils;
29 32
30 import java.util.ArrayList; 33 import java.util.ArrayList;
31 import java.util.List; 34 import java.util.List;
32 35
33 public class PedometerActivity extends ActivityBase { 36 public class PedometerActivity extends ActivityBase {
34 private Toolbar mToolBar; 37 private Toolbar mToolBar;
35 private ViewPager mViewPager; 38 private ViewPager mViewPager;
36 private int mCurrentTab = 0; 39 private int mCurrentTab = 0;
37 private TabLayout mTabLayout; 40 private TabLayout mTabLayout;
38 private TextView tvPageTitle; 41 private TextView tvPageTitle;
39 private ImageView ivHome; 42 private ImageView ivHome;
40 private ImageView imvMenu; 43 private ImageView imvMenu;
41 44
42 private TopFragment mTopFragment; 45 private TopFragment mTopFragment;
43 private HistoryFragment mHistoryFragment; 46 private HistoryFragment mHistoryFragment;
44 private SnsFragment mSnsFragment; 47 private SnsFragment mSnsFragment;
45 48
46 private int[] tabIcons = { 49 private int[] tabIcons = {
47 R.drawable.today_ic, 50 R.drawable.today_ic,
48 R.drawable.history_ic, 51 R.drawable.history_ic,
49 R.drawable.rank_ic, 52 R.drawable.rank_ic,
50 R.drawable.map_ic, 53 R.drawable.map_ic,
51 R.drawable.sns_ic 54 R.drawable.sns_ic
52 }; 55 };
53 56
54 public enum TAB { 57 public enum TAB {
55 DATE_TAB(0), 58 DATE_TAB(0),
56 HISTORY_TAB(1), 59 HISTORY_TAB(1),
57 RANK_TAB(2), 60 RANK_TAB(2),
58 MAP_TAB(3), 61 MAP_TAB(3),
59 SNS_TAB(4); 62 SNS_TAB(4);
60 63
61 private final int index; 64 private final int index;
62 65
63 TAB(int index) { 66 TAB(int index) {
64 this.index = index; 67 this.index = index;
65 } 68 }
66 69
67 public int getValue() { 70 public int getValue() {
68 return index; 71 return index;
69 } 72 }
70 } 73 }
71 74
72 @Override 75 @Override
73 protected void onCreate(Bundle savedInstanceState) { 76 protected void onCreate(Bundle savedInstanceState) {
74 super.onCreate(savedInstanceState); 77 super.onCreate(savedInstanceState);
75 78
76 setContentView(R.layout.activity_pedometer); 79 setContentView(R.layout.activity_pedometer);
77 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 80 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
78 81
79 initView(); 82 initView();
80 83
81 if (android.support.v4.BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker 84 if (android.support.v4.BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker
82 .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != 85 .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
83 PermissionChecker.PERMISSION_GRANTED) { 86 PermissionChecker.PERMISSION_GRANTED) {
84 requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); 87 requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
85 } 88 }
86 } 89 }
87 90
88 private void initView() { 91 private void initView() {
89 92
90 tvPageTitle = (TextView) findViewById(R.id.tv_pageTitle); 93 tvPageTitle = (TextView) findViewById(R.id.tv_pageTitle);
91 ivHome = (ImageView) findViewById(R.id.iv_home); 94 ivHome = (ImageView) findViewById(R.id.iv_home);
92 imvMenu = (ImageView) findViewById(R.id.imv_menu); 95 imvMenu = (ImageView) findViewById(R.id.imv_menu);
93 96
94 mViewPager = (ViewPager) findViewById(R.id.viewpager); 97 mViewPager = (ViewPager) findViewById(R.id.viewpager);
95 mViewPager.setOffscreenPageLimit(5); 98 mViewPager.setOffscreenPageLimit(5);
96 setupViewPager(mViewPager); 99 setupViewPager(mViewPager);
97 mTabLayout = (TabLayout) findViewById(R.id.tabs); 100 mTabLayout = (TabLayout) findViewById(R.id.tabs);
98 mTabLayout.setupWithViewPager(mViewPager); 101 mTabLayout.setupWithViewPager(mViewPager);
99 //Set tab selected 102 //Set tab selected
100 TabLayout.Tab tab = mTabLayout.getTabAt(mCurrentTab); 103 TabLayout.Tab tab = mTabLayout.getTabAt(mCurrentTab);
101 if (tab != null) { 104 if (tab != null) {
102 tab.select(); 105 tab.select();
103 } 106 }
107 //mTabLayout.addTab();
108 View view1 = getLayoutInflater().inflate(R.layout.customtab, null);
109 view1.findViewById(R.id.icon).setBackgroundResource(R.drawable.today_ic);
110 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view1));
104 111
112
113 View view2 = getLayoutInflater().inflate(R.layout.customtab, null);
114 view2.findViewById(R.id.icon).setBackgroundResource(R.drawable.history_ic);
115 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view2));
116
117
118 View view3 = getLayoutInflater().inflate(R.layout.customtab, null);
119 view3.findViewById(R.id.icon).setBackgroundResource(R.drawable.rank_ic);
120 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view3));
121
122
123 View view4 = getLayoutInflater().inflate(R.layout.customtab, null);
124 view4.findViewById(R.id.icon).setBackgroundResource(R.drawable.map_ic);
125 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view4));
126
127
128 View view5 = getLayoutInflater().inflate(R.layout.customtab, null);
129 view5.findViewById(R.id.icon).setBackgroundResource(R.drawable.sns_ic);
130 //mTabLayout.addTab(mTabLayout.newTab().setCustomView(view5));
131
132
133 mTabLayout.getTabAt(0).setCustomView(view1);
134 mTabLayout.getTabAt(1).setCustomView(view2);
135 mTabLayout.getTabAt(2).setCustomView(view3);
136 mTabLayout.getTabAt(3).setCustomView(view4);
137 mTabLayout.getTabAt(4).setCustomView(view5);
138
105 changeColorStatusBar(); 139 changeColorStatusBar();
106 setupTabIcons(); 140 //setupTabIcons();
107 141
108 //SonLT Add 142 //SonLT Add
109 ivHome.setOnClickListener(new View.OnClickListener() { 143 ivHome.setOnClickListener(new View.OnClickListener() {
110 @Override 144 @Override
111 public void onClick(View v) { 145 public void onClick(View v) {
112 switch (mCurrentTab){ 146 switch (mCurrentTab){
113 case 0: mTopFragment.clickBackToHome(); break; 147 case 0: mTopFragment.clickBackToHome(); break;
114 case 1: mHistoryFragment.clickBackToHome(); break; 148 case 1: mHistoryFragment.clickBackToHome(); break;
115 case 4: mSnsFragment.handleToolbarClick(0); break; 149 case 4: mSnsFragment.handleToolbarClick(0); break;
116 default: break; 150 default: break;
117 } 151 }
118 } 152 }
119 }); 153 });
120 154
121 imvMenu.setOnClickListener(new View.OnClickListener() { 155 imvMenu.setOnClickListener(new View.OnClickListener() {
122 @Override 156 @Override
123 public void onClick(View v) { 157 public void onClick(View v) {
124 //Creating the instance of PopupMenu 158 //Creating the instance of PopupMenu
125 PopupMenu popup = new PopupMenu(PedometerActivity.this, imvMenu); 159 PopupMenu popup = new PopupMenu(PedometerActivity.this, imvMenu);
126 //Inflating the Popup using xml file 160 //Inflating the Popup using xml file
127 popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); 161 popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
128 162
129 //registering popup with OnMenuItemClickListener 163 //registering popup with OnMenuItemClickListener
130 popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 164 popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
131 public boolean onMenuItemClick(MenuItem item) { 165 public boolean onMenuItemClick(MenuItem item) {
132 switch (item.getItemId()){ 166 switch (item.getItemId()){
133 case R.id.action_setting: 167 case R.id.action_setting:
134 Toast.makeText( 168 Toast.makeText(
135 PedometerActivity.this, 169 PedometerActivity.this,
136 "Have not spec : " + item.getTitle(), 170 "Have not spec : " + item.getTitle(),
137 Toast.LENGTH_SHORT 171 Toast.LENGTH_SHORT
138 ).show(); 172 ).show();
139 break; 173 break;
140 case R.id.action_profile: 174 case R.id.action_profile:
141 Toast.makeText( 175 Toast.makeText(
142 PedometerActivity.this, 176 PedometerActivity.this,
143 "Have not spec : " + item.getTitle(), 177 "Have not spec : " + item.getTitle(),
144 Toast.LENGTH_SHORT 178 Toast.LENGTH_SHORT
145 ).show(); 179 ).show();
146 break; 180 break;
147 case R.id.action_logout: 181 case R.id.action_logout:
148 logout(); 182 logout();
149 break; 183 break;
150 default: 184 default:
151 Debug.warn("Not run here"); 185 Debug.warn("Not run here");
152 break; 186 break;
153 } 187 }
154 188
155 return true; 189 return true;
156 } 190 }
157 }); 191 });
158 192
159 popup.show(); //showing popup menu 193 popup.show(); //showing popup menu
160 } 194 }
161 }); //closing the setOnClickListener method 195 }); //closing the setOnClickListener method
162 } 196 }
163 197
198 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 ImageView imgTab = (ImageView) v.findViewById(viewId);
201 imgTab.setImageDrawable(getResources().getDrawable(resId));
202
203 return spec.setIndicator(v);
204 }
205
164 private void setupTabIcons() { 206 private void setupTabIcons() {
165 mTabLayout.getTabAt(0).setIcon(tabIcons[0]); 207 mTabLayout.getTabAt(0).setCustomView(tabIcons[0]);
166 mTabLayout.getTabAt(1).setIcon(tabIcons[1]); 208 mTabLayout.getTabAt(1).setIcon(tabIcons[1]);
167 mTabLayout.getTabAt(2).setIcon(tabIcons[2]); 209 mTabLayout.getTabAt(2).setIcon(tabIcons[2]);
168 mTabLayout.getTabAt(3).setIcon(tabIcons[3]); 210 mTabLayout.getTabAt(3).setIcon(tabIcons[3]);
169 mTabLayout.getTabAt(4).setIcon(tabIcons[4]); 211 mTabLayout.getTabAt(4).setIcon(tabIcons[4]);
170 } 212 }
171 213
172 214
173 private void setTabView() { 215 private void setTabView() {
174 216
175 for (int i = 0; i < mTabLayout.getTabCount(); i++) { 217 for (int i = 0; i < mTabLayout.getTabCount(); i++) {
176 TextView tv = (TextView) mTabLayout.getChildAt(0).findViewById(android.R.id.title); 218 TextView tv = (TextView) mTabLayout.getChildAt(0).findViewById(android.R.id.title);
177 //tv.setTextColor(Color.BLACK); 219 //tv.setTextColor(Color.BLACK);
178 tv.setPadding(10, 10, 10, 15); 220 tv.setPadding(10, 10, 10, 15);
179 tv.setTextSize((float) 20.0); 221 tv.setTextSize((float) 20.0);
180 //tv.setTypeface(null, Typeface.BOLD); 222 //tv.setTypeface(null, Typeface.BOLD);
181 //tv.setBackgroundResource(R.drawable.icon); 223 //tv.setBackgroundResource(R.drawable.icon);
182 tv.setHeight(100); 224 tv.setHeight(100);
183 tv.setWidth(100); 225 tv.setWidth(100);
184 } 226 }
185 227
186 } 228 }
187 229
188 private void changeColorStatusBar() { 230 private void changeColorStatusBar() {
189 if (android.os.Build.VERSION.SDK_INT >= 21) { 231 if (android.os.Build.VERSION.SDK_INT >= 21) {
190 Window window = this.getWindow(); 232 Window window = this.getWindow();
191 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 233 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
192 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 234 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
193 // window.setStatusBarColor(Utils.getColorWrapper(this, R.color.white)); 235 // window.setStatusBarColor(Utils.getColorWrapper(this, R.color.white));
194 } 236 }
195 } 237 }
196 238
197 // @Override 239 // @Override
198 // public boolean onCreateOptionsMenu(Menu menu) { 240 // public boolean onCreateOptionsMenu(Menu menu) {
199 // getMenuInflater().inflate(R.menu.setting_menu, menu); 241 // getMenuInflater().inflate(R.menu.setting_menu, menu);
200 // return true; 242 // return true;
201 // } 243 // }
202 244
203 @Override 245 @Override
204 public boolean onOptionsItemSelected(MenuItem item) { 246 public boolean onOptionsItemSelected(MenuItem item) {
205 return super.onOptionsItemSelected(item); 247 return super.onOptionsItemSelected(item);
206 } 248 }
207 249
208 /** 250 /**
209 * Setup pager 251 * Setup pager
210 * 252 *
211 * @param viewPager: view pager 253 * @param viewPager: view pager
212 */ 254 */
213 private void setupViewPager(ViewPager viewPager) { 255 private void setupViewPager(ViewPager viewPager) {
214 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 256 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
215 mTopFragment = new TopFragment(); 257 mTopFragment = new TopFragment();
216 adapter.addFragment(mTopFragment, getString(R.string.date)); 258 adapter.addFragment(mTopFragment, getString(R.string.date));
217 mHistoryFragment = new HistoryFragment(); 259 mHistoryFragment = new HistoryFragment();
218 adapter.addFragment(mHistoryFragment, getString(R.string.history)); 260 adapter.addFragment(mHistoryFragment, getString(R.string.history));
219 adapter.addFragment(new RankFragment(), getString(R.string.ranking)); 261 adapter.addFragment(new RankFragment(), getString(R.string.ranking));
220 adapter.addFragment(new MapFragment(), getString(R.string.map)); 262 adapter.addFragment(new MapFragment(), getString(R.string.map));
221 mSnsFragment = new SnsFragment(); 263 mSnsFragment = new SnsFragment();
222 adapter.addFragment(mSnsFragment, getString(R.string.sns)); 264 adapter.addFragment(mSnsFragment, getString(R.string.sns));
223 viewPager.setAdapter(adapter); 265 viewPager.setAdapter(adapter);
224 } 266 }
225 267
226 /** 268 /**
227 * Class FragmentPagerAdapter 269 * Class FragmentPagerAdapter
228 */ 270 */
229 class ViewPagerAdapter extends FragmentPagerAdapter { 271 class ViewPagerAdapter extends FragmentPagerAdapter {
230 private final List<Fragment> mFragmentList = new ArrayList<>(); 272 private final List<Fragment> mFragmentList = new ArrayList<>();
231 private final List<String> mFragmentTitleList = new ArrayList<>(); 273 private final List<String> mFragmentTitleList = new ArrayList<>();
232 274
233 public ViewPagerAdapter(FragmentManager manager) { 275 public ViewPagerAdapter(FragmentManager manager) {
234 super(manager); 276 super(manager);
235 } 277 }
236 278
237 @Override 279 @Override
238 public Fragment getItem(int position) { 280 public Fragment getItem(int position) {
239 return mFragmentList.get(position); 281 return mFragmentList.get(position);
240 } 282 }
241 283
242 @Override 284 @Override
243 public int getCount() { 285 public int getCount() {
244 return mFragmentList.size(); 286 return mFragmentList.size();
245 } 287 }
246 288
247 private void addFragment(Fragment fragment, String title) { 289 private void addFragment(Fragment fragment, String title) {
248 mFragmentList.add(fragment); 290 mFragmentList.add(fragment);
249 mFragmentTitleList.add(title); 291 mFragmentTitleList.add(title);
250 } 292 }
251 293
252 @Override 294 @Override
253 public CharSequence getPageTitle(int position) { 295 public CharSequence getPageTitle(int position) {
254 //return mFragmentTitleList.get(position); 296 //return mFragmentTitleList.get(position);
255 return null; 297 return null;
256 } 298 }
257 } 299 }
258 300
259 @Override 301 @Override
260 protected void onResume() { 302 protected void onResume() {
261 super.onResume(); 303 super.onResume();
262 mViewPager.addOnPageChangeListener(mPageChangeListener); 304 mViewPager.addOnPageChangeListener(mPageChangeListener);
263 } 305 }
264 306
265 @Override 307 @Override
266 protected void onPause() { 308 protected void onPause() {
267 super.onPause(); 309 super.onPause();
268 mViewPager.removeOnPageChangeListener(mPageChangeListener); 310 mViewPager.removeOnPageChangeListener(mPageChangeListener);
269 } 311 }
270 312
271 private int mLastTab = 0; 313 private int mLastTab = 0;
272 private final ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager 314 private final ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager
273 .OnPageChangeListener 315 .OnPageChangeListener
274 () { 316 () {
275 @Override 317 @Override
276 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 318 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
277 //Nothing here 319 //Nothing here
278 } 320 }
279 321
280 @Override 322 @Override
281 public void onPageSelected(int position) { 323 public void onPageSelected(int position) {
282 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter(); 324 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
283 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter.getItem 325 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter.getItem
284 (position); 326 (position);
285 327
286 switch (position) { 328 switch (position) {
287 case 4: 329 case 4:
288 tvPageTitle.setText(getString(R.string.sns_fragment)); 330 tvPageTitle.setText(getString(R.string.sns_fragment));
289 ivHome.setVisibility(View.VISIBLE); 331 ivHome.setVisibility(View.VISIBLE);
290 break; 332 break;
291 case 1: 333 case 1:
292 tvPageTitle.setText(getString(R.string.today)); 334 tvPageTitle.setText(getString(R.string.today));
293 ivHome.setVisibility(View.VISIBLE); 335 ivHome.setVisibility(View.VISIBLE);
294 break; 336 break;
295 337
296 case 0: 338 case 0:
297 tvPageTitle.setText(getString(R.string.home)); 339 tvPageTitle.setText(getString(R.string.home));
298 ivHome.setVisibility(View.GONE); 340 ivHome.setVisibility(View.GONE);
299 break; 341 break;
300 342
301 default: 343 default:
302 tvPageTitle.setText(getString(R.string.home)); 344 tvPageTitle.setText(getString(R.string.home));
303 ivHome.setVisibility(View.GONE); 345 ivHome.setVisibility(View.GONE);
304 break; 346 break;
305 } 347 }
306 // if (position == 1){ 348 // if (position == 1){
307 // tvPageTitle.setText(getString(R.string.today)); 349 // tvPageTitle.setText(getString(R.string.today));
308 // ivHome.setVisibility(View.VISIBLE); 350 // ivHome.setVisibility(View.VISIBLE);
309 // }else { 351 // }else {
310 // tvPageTitle.setText(getString(R.string.home)); 352 // tvPageTitle.setText(getString(R.string.home));
311 // ivHome.setVisibility(View.GONE); 353 // ivHome.setVisibility(View.GONE);
312 // } 354 // }
313 355
314 presenter.onInvalidate(false); 356 presenter.onInvalidate(false);
315 mLastTab = position; 357 mLastTab = position;
316 mCurrentTab = position; 358 mCurrentTab = position;
317 } 359 }
318 360
319 @Override 361 @Override
320 public void onPageScrollStateChanged(int state) { 362 public void onPageScrollStateChanged(int state) {
321 //Nothing here 363 //Nothing here
322 if (state == ViewPager.SCROLL_STATE_SETTLING) { 364 if (state == ViewPager.SCROLL_STATE_SETTLING) {
323 if (mLastTab >= 0) { 365 if (mLastTab >= 0) {
324 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter(); 366 ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
325 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter 367 SettingFragmentPresenter presenter = (SettingFragmentPresenter) adapter
326 .getItem(mLastTab); 368 .getItem(mLastTab);
327 369
328 Debug.normal("Save data in tab:" + mLastTab); 370 Debug.normal("Save data in tab:" + mLastTab);
329 presenter.onSaveData(); 371 presenter.onSaveData();
330 } 372 }
331 } 373 }
332 } 374 }
333 }; 375 };
334 376
335 public void setVisibleIconHome(boolean isVisible){ 377 public void setVisibleIconHome(boolean isVisible){
336 if (isVisible) { 378 if (isVisible) {
337 ivHome.setVisibility(View.VISIBLE); 379 ivHome.setVisibility(View.VISIBLE);
338 }else { 380 }else {
339 ivHome.setVisibility(View.GONE); 381 ivHome.setVisibility(View.GONE);
340 } 382 }
341 383
342 setTitleTop(isVisible); 384 setTitleTop(isVisible);
343 } 385 }
344 386
345 public void setTitleTop(boolean isVisible){ 387 public void setTitleTop(boolean isVisible){
346 if (isVisible) { 388 if (isVisible) {
347 tvPageTitle.setText(getString(R.string.today)); 389 tvPageTitle.setText(getString(R.string.today));
348 }else { 390 }else {
349 tvPageTitle.setText(getString(R.string.home)); 391 tvPageTitle.setText(getString(R.string.home));
350 } 392 }
351 } 393 }
352 394
353 395
354 396
355 private void logout(){ 397 private void logout(){
356 // clear data 398 // clear data
357 Setting.clearUserIdSharepre(PedometerActivity.this); 399 Setting.clearUserIdSharepre(PedometerActivity.this);
358 // go to login 400 // go to login
359 Intent intent = new Intent(PedometerActivity.this, LoginActivity.class); 401 Intent intent = new Intent(PedometerActivity.this, LoginActivity.class);
360 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 402 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
361 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 403 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
362 startActivity(intent); 404 startActivity(intent);
363 } 405 }
364 406
365 } 407 }
366 408
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.app.ProgressDialog; 4 import android.app.ProgressDialog;
4 import android.content.DialogInterface; 5 import android.content.DialogInterface;
5 import android.content.Intent; 6 import android.content.Intent;
7 import android.content.pm.PackageManager;
6 import android.net.Uri; 8 import android.net.Uri;
9 import android.os.Build;
7 import android.os.Bundle; 10 import android.os.Bundle;
8 import android.os.Handler; 11 import android.os.Handler;
12 import android.support.v4.app.ActivityCompat;
13 import android.support.v4.content.ContextCompat;
9 import android.support.v7.app.AlertDialog; 14 import android.support.v7.app.AlertDialog;
15 import android.widget.Toast;
10 16
11 import com.dinhcv.lifelogpedometer.R; 17 import com.dinhcv.lifelogpedometer.R;
12 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; 18 import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
13 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting; 19 import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
14 import com.dinhcv.lifelogpedometer.portal.ApiServices; 20 import com.dinhcv.lifelogpedometer.portal.ApiServices;
15 import com.dinhcv.lifelogpedometer.portal.LLAPIManager; 21 import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
16 import com.dinhcv.lifelogpedometer.utils.Debug; 22 import com.dinhcv.lifelogpedometer.utils.Debug;
17 23
18 import org.json.JSONArray; 24 import org.json.JSONArray;
19 import org.json.JSONObject; 25 import org.json.JSONObject;
20 26
21 27
22 public class WelcomeActivity extends ActivityBase implements Runnable { 28 public class WelcomeActivity extends ActivityBase implements Runnable {
23 private boolean isRefresh = false; 29 private boolean isRefresh = false;
30 private static final int PERMISSIONS_REQUEST = 999;
31
24 @Override 32 @Override
25 protected void onCreate(Bundle savedInstanceState) { 33 protected void onCreate(Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState); 34 super.onCreate(savedInstanceState);
27 setContentView(R.layout.activity_welcome); 35 setContentView(R.layout.activity_welcome);
28 checkRefreshToken(); 36 checkPermission();
29 } 37 }
30 38
31 private void checkRefreshToken(){ 39 private void checkRefreshToken(){
32 int id = Setting.getUserIdSharepre(WelcomeActivity.this); 40 int id = Setting.getUserIdSharepre(WelcomeActivity.this);
33 Debug.normal("String id: "+ id); 41 Debug.normal("String id: "+ id);
34 if (id != 0){ 42 if (id != 0){
35 handleRefreshToken(id); 43 handleRefreshToken(id);
36 }else { 44 }else {
37 refeshDone(); 45 refeshDone();
38 } 46 }
39 } 47 }
40 48
41 49
42 private void handleRefreshToken(int id) { 50 private void handleRefreshToken(int id) {
43 51
44 ApiServices.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() { 52 ApiServices.refreshToken(WelcomeActivity.this, id, new LLAPIManagerListener() {
45 @Override 53 @Override
46 public void onError(Error error) { 54 public void onError(Error error) {
47 Debug.error("Version JSON result: ERROR " + error); 55 Debug.error("Version JSON result: ERROR " + error);
48 String err = getResources().getString(R.string.login_error); 56 String err = getResources().getString(R.string.login_error);
49 isRefresh = false; 57 isRefresh = false;
50 refeshDone(); 58 refeshDone();
51 } 59 }
52 60
53 @Override 61 @Override
54 public void onSuccess(String json) { 62 public void onSuccess(String json) {
55 Debug.warn("Version JSON result: " + json.toString()); 63 Debug.warn("Version JSON result: " + json.toString());
56 isRefresh = true; 64 isRefresh = true;
57 refeshDone(); 65 refeshDone();
58 } 66 }
59 67
60 @Override 68 @Override
61 public void onSuccess(JSONObject object) { 69 public void onSuccess(JSONObject object) {
62 Debug.warn("Version JSON object result: Success"); 70 Debug.warn("Version JSON object result: Success");
63 isRefresh = true; 71 isRefresh = true;
64 refeshDone(); 72 refeshDone();
65 } 73 }
66 }); 74 });
67 } 75 }
68 76
69 private void refeshDone(){ 77 private void refeshDone(){
70 Handler handler = new Handler(); 78 Handler handler = new Handler();
71 handler.postDelayed(WelcomeActivity.this, 2000); 79 handler.postDelayed(WelcomeActivity.this, 2000);
72 } 80 }
73 81
74 private void notifyErr(String err){ 82 private void notifyErr(String err){
75 AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this); 83 AlertDialog.Builder alertDialog = new AlertDialog.Builder(WelcomeActivity.this);
76 alertDialog.setMessage(err); 84 alertDialog.setMessage(err);
77 alertDialog.setCancelable(false); 85 alertDialog.setCancelable(false);
78 alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 86 alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
79 @Override 87 @Override
80 public void onClick(DialogInterface dialog, int which) { 88 public void onClick(DialogInterface dialog, int which) {
81 finish(); 89 finish();
82 } 90 }
83 }); 91 });
84 AlertDialog alert = alertDialog.create(); 92 AlertDialog alert = alertDialog.create();
85 alert.show(); 93 alert.show();
86 } 94 }
87 95
88 @Override 96 @Override
89 public void run() { 97 public void run() {
90 // go to main screen 98 // go to main screen
91 if ( isRefresh) { 99 if ( isRefresh) {
92 gotoActivity(PedometerActivity.class); 100 gotoActivity(PedometerActivity.class);
93 } else { 101 } else {
94 // Bundle bundle = new Bundle(); 102 // Bundle bundle = new Bundle();
95 // bundle.putString(Const.URL, url); 103 // bundle.putString(Const.URL, url);
96 gotoActivity(LoginActivity.class); 104 gotoActivity(LoginActivity.class);
97 } 105 }
98 finish(); 106 finish();
99 } 107 }
100 108
101 @Override 109 @Override
102 protected void onResume() { 110 protected void onResume() {
103 super.onResume(); 111 super.onResume();
112 }
113
114 private void checkPermission() {
115 // Check all permission in android 6.0
116 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
117 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
118 == PackageManager.PERMISSION_GRANTED) && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
119 == PackageManager.PERMISSION_GRANTED)) {
120 checkRefreshToken();
121
122 } else {
123 // Requset permisson of device
124 if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission
125 .ACCESS_COARSE_LOCATION)
126 && ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest
127 .permission.ACCESS_FINE_LOCATION)) {
128 ActivityCompat.requestPermissions(this,
129 new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
130 Manifest.permission.ACCESS_FINE_LOCATION},
131 PERMISSIONS_REQUEST);
132
133 } else {
134 ActivityCompat.requestPermissions(this,
135 new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
136 Manifest.permission.ACCESS_FINE_LOCATION},
137 PERMISSIONS_REQUEST);
138 }
139 }
140
141 } else {
142 checkRefreshToken();
143 }
144 }
145
146 @Override
147 public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]
148 grantResults) {
149 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
150
151 if (requestCode == PERMISSIONS_REQUEST) {
152 if (grantResults.length > 0) {
153 if (grantResults[0] == PackageManager.PERMISSION_GRANTED
154 && grantResults[1] == PackageManager.PERMISSION_GRANTED
155 && grantResults[2] == PackageManager.PERMISSION_GRANTED) {
156 checkRefreshToken();
157 return;
158 }
159 } else {
160 Toast.makeText(this, "Permission was not granted ", Toast.LENGTH_SHORT).show();
161 finish();
162 }
163 } else {
164 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
165 }
104 } 166 }
105 } 167 }
106 168
app/src/main/res/drawable/test_selector.xml
File was created 1 <?xml version="1.0" encoding="utf-8"?>
2 <selector xmlns:android="http://schemas.android.com/apk/res/android">
3 <item android:drawable="@drawable/history_ic" android:state_selected="true"/>
4 <item android:drawable="@drawable/today_ic"/>
5 </selector>
app/src/main/res/layout/customtab.xml
File was created 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:padding="3dp">
7
8 <ImageView
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:adjustViewBounds="true"
12 android:src="@drawable/tab_ic"
13 android:id="@+id/icon"
14 android:layout_gravity="center" />
15 </LinearLayout>
app/src/main/res/layout/notice_list_item.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical" 3 android:orientation="vertical"
4 android:layout_width="match_parent" 4 android:layout_width="match_parent"
5 android:layout_height="wrap_content" 5 android:layout_height="wrap_content"
6 android:background="@color/background_main"
7 android:padding="4dp"> 6 android:padding="4dp">
8 7
9 <TextView 8 <TextView
10 android:id="@+id/tv_content" 9 android:id="@+id/tv_content"
11 android:layout_width="match_parent" 10 android:layout_width="match_parent"
12 android:layout_height="wrap_content" 11 android:layout_height="wrap_content"
13 android:gravity="left" 12 android:gravity="left"
14 android:paddingLeft="20dp" 13 android:paddingLeft="20dp"
15 android:textColor="@color/white" 14 android:textColor="@color/white"
16 android:text="description" /> 15 android:text="description" />
17 16
18 17
19 </LinearLayout> 18 </LinearLayout>
20 19