Commit 022ad6460225bf3e74a402b87d43463c793a2270
Exists in
master
Merge branch 'master' of http://timesfun.net/chudinhbka/lifelog_android
Showing 8 changed files Side-by-side Diff
- .idea/modules.xml
- app/src/main/AndroidManifest.xml
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/MapFragment.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/PedometerActivity.java
- app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
- app/src/main/res/drawable/test_selector.xml
- app/src/main/res/layout/customtab.xml
- app/src/main/res/layout/notice_list_item.xml
.idea/modules.xml
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | <component name="ProjectModuleManager"> |
| 4 | 4 | <modules> |
| 5 | 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 | 7 | <module fileurl="file://D:\Project\Git\lifelog_android\lifelogpedometer.iml" filepath="D:\Project\Git\lifelog_android\lifelogpedometer.iml" /> |
| 8 | 8 | </modules> |
| 9 | 9 | </component> |
app/src/main/AndroidManifest.xml
| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
| 13 | 13 | <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> |
| 14 | 14 | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> |
| 15 | + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
| 15 | 16 | |
| 16 | 17 | <application |
| 17 | 18 | android:name=".LifeLogApplication" |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/MapFragment.java
| 1 | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | |
| 3 | +import android.Manifest; | |
| 3 | 4 | import android.app.Activity; |
| 4 | 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 | 10 | import android.os.Bundle; |
| 6 | 11 | import android.support.annotation.Nullable; |
| 12 | +import android.support.v4.app.ActivityCompat; | |
| 13 | +import android.support.v4.content.ContextCompat; | |
| 7 | 14 | import android.support.v4.app.Fragment; |
| 8 | 15 | import android.util.Log; |
| 9 | 16 | import android.view.LayoutInflater; |
| 10 | 17 | |
| 11 | 18 | |
| 12 | 19 | |
| 13 | 20 | |
| ... | ... | @@ -11,12 +18,32 @@ |
| 11 | 18 | import android.view.ViewGroup; |
| 12 | 19 | |
| 13 | 20 | import com.dinhcv.lifelogpedometer.R; |
| 21 | +import com.google.android.gms.maps.CameraUpdateFactory; | |
| 14 | 22 | import com.google.android.gms.maps.GoogleMap; |
| 15 | 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 | 31 | public class MapFragment extends Fragment implements SettingFragmentPresenter, OnMapReadyCallback { |
| 18 | 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 | 47 | @Override |
| 21 | 48 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle |
| 22 | 49 | savedInstanceState) { |
| 23 | 50 | |
| 24 | 51 | |
| 25 | 52 | |
| 26 | 53 | |
| 27 | 54 | |
| ... | ... | @@ -36,17 +63,71 @@ |
| 36 | 63 | * @param rootView view |
| 37 | 64 | */ |
| 38 | 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 | 74 | * Init data |
| 44 | 75 | */ |
| 45 | 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 | 131 | @Override |
| 51 | 132 | public void onAttach(Context context) { |
| 52 | 133 | super.onAttach(context); |
| 53 | 134 | |
| ... | ... | @@ -77,8 +158,17 @@ |
| 77 | 158 | } |
| 78 | 159 | |
| 79 | 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 | 169 | Log.i("SonLT","Readdy"); |
| 170 | + | |
| 171 | + //updateLine(); | |
| 82 | 172 | } |
| 83 | 173 | } |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/PedometerActivity.java
| 1 | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | |
| 3 | 3 | import android.Manifest; |
| 4 | +import android.content.Context; | |
| 4 | 5 | import android.content.Intent; |
| 5 | 6 | import android.os.Build; |
| 6 | 7 | import android.os.Bundle; |
| 7 | 8 | |
| ... | ... | @@ -13,12 +14,14 @@ |
| 13 | 14 | import android.support.v7.widget.PopupMenu; |
| 14 | 15 | import android.support.v7.widget.Toolbar; |
| 15 | 16 | import android.view.Gravity; |
| 17 | +import android.view.LayoutInflater; | |
| 16 | 18 | import android.view.MenuItem; |
| 17 | 19 | import android.view.View; |
| 18 | 20 | import android.view.Window; |
| 19 | 21 | import android.view.WindowManager; |
| 20 | 22 | import android.widget.ImageView; |
| 21 | 23 | import android.widget.PopupWindow; |
| 24 | +import android.widget.TabHost; | |
| 22 | 25 | import android.widget.TextView; |
| 23 | 26 | import android.widget.Toast; |
| 24 | 27 | |
| 25 | 28 | |
| 26 | 29 | |
| ... | ... | @@ -101,9 +104,40 @@ |
| 101 | 104 | if (tab != null) { |
| 102 | 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 | 139 | changeColorStatusBar(); |
| 106 | - setupTabIcons(); | |
| 140 | + //setupTabIcons(); | |
| 107 | 141 | |
| 108 | 142 | //SonLT Add |
| 109 | 143 | ivHome.setOnClickListener(new View.OnClickListener() { |
| 110 | 144 | |
| ... | ... | @@ -161,8 +195,16 @@ |
| 161 | 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 | 206 | private void setupTabIcons() { |
| 165 | - mTabLayout.getTabAt(0).setIcon(tabIcons[0]); | |
| 207 | + mTabLayout.getTabAt(0).setCustomView(tabIcons[0]); | |
| 166 | 208 | mTabLayout.getTabAt(1).setIcon(tabIcons[1]); |
| 167 | 209 | mTabLayout.getTabAt(2).setIcon(tabIcons[2]); |
| 168 | 210 | mTabLayout.getTabAt(3).setIcon(tabIcons[3]); |
app/src/main/java/com/dinhcv/lifelogpedometer/activity/WelcomeActivity.java
| 1 | 1 | package com.dinhcv.lifelogpedometer.activity; |
| 2 | 2 | |
| 3 | +import android.Manifest; | |
| 3 | 4 | import android.app.ProgressDialog; |
| 4 | 5 | import android.content.DialogInterface; |
| 5 | 6 | import android.content.Intent; |
| 7 | +import android.content.pm.PackageManager; | |
| 6 | 8 | import android.net.Uri; |
| 9 | +import android.os.Build; | |
| 7 | 10 | import android.os.Bundle; |
| 8 | 11 | import android.os.Handler; |
| 12 | +import android.support.v4.app.ActivityCompat; | |
| 13 | +import android.support.v4.content.ContextCompat; | |
| 9 | 14 | import android.support.v7.app.AlertDialog; |
| 15 | +import android.widget.Toast; | |
| 10 | 16 | |
| 11 | 17 | import com.dinhcv.lifelogpedometer.R; |
| 12 | 18 | import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener; |
| 13 | 19 | |
| ... | ... | @@ -21,11 +27,13 @@ |
| 21 | 27 | |
| 22 | 28 | public class WelcomeActivity extends ActivityBase implements Runnable { |
| 23 | 29 | private boolean isRefresh = false; |
| 30 | + private static final int PERMISSIONS_REQUEST = 999; | |
| 31 | + | |
| 24 | 32 | @Override |
| 25 | 33 | protected void onCreate(Bundle savedInstanceState) { |
| 26 | 34 | super.onCreate(savedInstanceState); |
| 27 | 35 | setContentView(R.layout.activity_welcome); |
| 28 | - checkRefreshToken(); | |
| 36 | + checkPermission(); | |
| 29 | 37 | } |
| 30 | 38 | |
| 31 | 39 | private void checkRefreshToken(){ |
| ... | ... | @@ -101,6 +109,60 @@ |
| 101 | 109 | @Override |
| 102 | 110 | protected void onResume() { |
| 103 | 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 | } |
app/src/main/res/drawable/test_selector.xml
app/src/main/res/layout/customtab.xml
| 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