From d0ff6ee0615773888bc72c27beb466a737367c47 Mon Sep 17 00:00:00 2001 From: jddeep Date: Thu, 4 Apr 2019 07:37:19 +0530 Subject: [PATCH 1/5] Ask for Location Perms enabled --- .../stardroid/LocationManagerCheck.java | 75 +++++++++++ .../stardroid/StardroidApplication.java | 125 ++++++++++++------ 2 files changed, 157 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java diff --git a/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java b/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java new file mode 100644 index 000000000..309bb86ab --- /dev/null +++ b/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java @@ -0,0 +1,75 @@ +package com.google.android.stardroid; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.location.LocationManager; +import android.provider.Settings; + +public class LocationManagerCheck { + + LocationManager locationManager; + Boolean locationServiceBoolean = false; + int providerType = 0; + static AlertDialog alert; + + public LocationManagerCheck(Context context) { + locationManager = (LocationManager) context + .getSystemService(Context.LOCATION_SERVICE); + boolean gpsIsEnabled = locationManager + .isProviderEnabled(LocationManager.GPS_PROVIDER); + boolean networkIsEnabled = locationManager + .isProviderEnabled(LocationManager.NETWORK_PROVIDER); + + if (networkIsEnabled == true && gpsIsEnabled == true) { + locationServiceBoolean = true; + providerType = 1; + + } else if (networkIsEnabled != true && gpsIsEnabled == true) { + locationServiceBoolean = true; + providerType = 2; + + } else if (networkIsEnabled == true && gpsIsEnabled != true) { + locationServiceBoolean = true; + providerType = 1; + } + } + + public Boolean isLocationServiceAvailable() { + return locationServiceBoolean; + } + + public int getProviderType() { + return providerType; + } + + public void createLocationServiceError(final Context activityObj) { + + // show alert dialog if Internet is not connected + AlertDialog.Builder builder = new AlertDialog.Builder(activityObj); + + builder.setMessage( + "You need to activate location service to use this feature. Please turn on network or GPS mode in location settings") + .setTitle("LostyFound") + .setCancelable(false) + .setPositiveButton("Settings", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent( + Settings.ACTION_LOCATION_SOURCE_SETTINGS); + activityObj.startActivity(intent); + dialog.dismiss(); + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + alert = builder.create(); + alert.show(); + } +} diff --git a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java index 182c35029..c59941713 100644 --- a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java +++ b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java @@ -13,7 +13,10 @@ // limitations under the License. package com.google.android.stardroid; +import android.Manifest; +import android.app.Activity; import android.app.Application; +import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -22,8 +25,11 @@ import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; +import android.location.Location; +import android.location.LocationManager; import android.os.Build; import android.preference.PreferenceManager; +import android.support.v4.app.ActivityCompat; import android.util.Log; import com.google.android.stardroid.layers.LayerManager; @@ -46,51 +52,84 @@ * @author John Taylor */ public class StardroidApplication extends Application { - private static final String TAG = MiscUtil.getTag(StardroidApplication.class); - private static final String PREVIOUS_APP_VERSION_PREF = "previous_app_version"; - private static final String NONE = "Clean install"; - private static final String UNKNOWN = "Unknown previous version"; - - @Inject SharedPreferences preferences; - // We keep a reference to this just to start it initializing. - @Inject LayerManager layerManager; - @Inject Analytics analytics; - @Inject SensorManager sensorManager; - - // We need to maintain references to this object to keep it from - // getting gc'd. - @Inject PreferenceChangeAnalyticsTracker preferenceChangeAnalyticsTracker; - private ApplicationComponent component; - - @Override - public void onCreate() { - Log.d(TAG, "StardroidApplication: onCreate"); - super.onCreate(); - - component = DaggerApplicationComponent.builder() - .applicationModule(new ApplicationModule(this)) - .build(); - component.inject(this); - - Log.i(TAG, "OS Version: " + android.os.Build.VERSION.RELEASE - + "(" + android.os.Build.VERSION.SDK_INT + ")"); - String versionName = getVersionName(); - Log.i(TAG, "Sky Map version " + versionName + " build " + getVersion()); - - // This populates the default values from the preferences XML file. See - // {@link DefaultValues} for more details. - PreferenceManager.setDefaultValues(this, R.xml.preference_screen, false); - - setUpAnalytics(versionName); - - performFeatureCheck(); + private static final String TAG = MiscUtil.getTag(StardroidApplication.class); + private static final String PREVIOUS_APP_VERSION_PREF = "previous_app_version"; + private static final String NONE = "Clean install"; + private static final String UNKNOWN = "Unknown previous version"; + + @Inject + SharedPreferences preferences; + // We keep a reference to this just to start it initializing. + @Inject + LayerManager layerManager; + @Inject + Analytics analytics; + @Inject + SensorManager sensorManager; + + // We need to maintain references to this object to keep it from + // getting gc'd. + @Inject + PreferenceChangeAnalyticsTracker preferenceChangeAnalyticsTracker; + private ApplicationComponent component; + + @Override + public void onCreate() { + Log.d(TAG, "StardroidApplication: onCreate"); + super.onCreate(); + + component = DaggerApplicationComponent.builder() + .applicationModule(new ApplicationModule(this)) + .build(); + component.inject(this); + + Log.i(TAG, "OS Version: " + android.os.Build.VERSION.RELEASE + + "(" + android.os.Build.VERSION.SDK_INT + ")"); + String versionName = getVersionName(); + Log.i(TAG, "Sky Map version " + versionName + " build " + getVersion()); + + // This populates the default values from the preferences XML file. See + // {@link DefaultValues} for more details. + PreferenceManager.setDefaultValues(this, R.xml.preference_screen, false); + + setUpAnalytics(versionName); + + checkLocationPerms(); + + performFeatureCheck(); + + Log.d(TAG, "StardroidApplication: -onCreate"); + } - Log.d(TAG, "StardroidApplication: -onCreate"); - } + public ApplicationComponent getApplicationComponent() { + return component; + } - public ApplicationComponent getApplicationComponent() { - return component; - } + private void checkLocationPerms() { + LocationManagerCheck locationManagerCheck = new LocationManagerCheck(this); + Location location = null; + LocationManager locationManager = + (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + + if (locationManagerCheck.isLocationServiceAvailable()) { + + if (locationManagerCheck.getProviderType() == 1) { + if (ActivityCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager + .PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager + .PERMISSION_GRANTED) { + location = locationManager + .getLastKnownLocation(LocationManager.GPS_PROVIDER); + return; + }else if (locationManagerCheck.getProviderType() == 2) + location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + } + } else { + locationManagerCheck.createLocationServiceError(getApplicationContext()); + } + } private void setUpAnalytics(String versionName) { analytics.setCustomVar(Slice.ANDROID_OS, Integer.toString(Build.VERSION.SDK_INT)); From 600040a2b51bc0897ced3582f6c6d1801d3e1618 Mon Sep 17 00:00:00 2001 From: Jaideep Prasad Date: Thu, 4 Apr 2019 07:41:47 +0530 Subject: [PATCH 2/5] updated title text --- .../java/com/google/android/stardroid/LocationManagerCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java b/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java index 309bb86ab..5048e8c17 100644 --- a/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java +++ b/app/src/main/java/com/google/android/stardroid/LocationManagerCheck.java @@ -52,7 +52,7 @@ public void createLocationServiceError(final Context activityObj) { builder.setMessage( "You need to activate location service to use this feature. Please turn on network or GPS mode in location settings") - .setTitle("LostyFound") + .setTitle("Enable Location") .setCancelable(false) .setPositiveButton("Settings", new DialogInterface.OnClickListener() { From eeb1646916468aae225e8407dd07a5a9c2e538ad Mon Sep 17 00:00:00 2001 From: Jaideep Prasad Date: Mon, 29 Apr 2019 19:23:37 +0530 Subject: [PATCH 3/5] reverted-1 --- .../stardroid/StardroidApplication.java | 83 +++++++++---------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java index c59941713..9c9986389 100644 --- a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java +++ b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java @@ -52,51 +52,44 @@ * @author John Taylor */ public class StardroidApplication extends Application { - private static final String TAG = MiscUtil.getTag(StardroidApplication.class); - private static final String PREVIOUS_APP_VERSION_PREF = "previous_app_version"; - private static final String NONE = "Clean install"; - private static final String UNKNOWN = "Unknown previous version"; - - @Inject - SharedPreferences preferences; - // We keep a reference to this just to start it initializing. - @Inject - LayerManager layerManager; - @Inject - Analytics analytics; - @Inject - SensorManager sensorManager; - - // We need to maintain references to this object to keep it from - // getting gc'd. - @Inject - PreferenceChangeAnalyticsTracker preferenceChangeAnalyticsTracker; - private ApplicationComponent component; - - @Override - public void onCreate() { - Log.d(TAG, "StardroidApplication: onCreate"); - super.onCreate(); - - component = DaggerApplicationComponent.builder() - .applicationModule(new ApplicationModule(this)) - .build(); - component.inject(this); - - Log.i(TAG, "OS Version: " + android.os.Build.VERSION.RELEASE - + "(" + android.os.Build.VERSION.SDK_INT + ")"); - String versionName = getVersionName(); - Log.i(TAG, "Sky Map version " + versionName + " build " + getVersion()); - - // This populates the default values from the preferences XML file. See - // {@link DefaultValues} for more details. - PreferenceManager.setDefaultValues(this, R.xml.preference_screen, false); - - setUpAnalytics(versionName); - - checkLocationPerms(); - - performFeatureCheck(); + private static final String TAG = MiscUtil.getTag(StardroidApplication.class); + private static final String PREVIOUS_APP_VERSION_PREF = "previous_app_version"; + private static final String NONE = "Clean install"; + private static final String UNKNOWN = "Unknown previous version"; + + @Inject SharedPreferences preferences; + // We keep a reference to this just to start it initializing. + @Inject LayerManager layerManager; + @Inject Analytics analytics; + @Inject SensorManager sensorManager; + + // We need to maintain references to this object to keep it from + // getting gc'd. + @Inject PreferenceChangeAnalyticsTracker preferenceChangeAnalyticsTracker; + private ApplicationComponent component; + + @Override + public void onCreate() { + Log.d(TAG, "StardroidApplication: onCreate"); + super.onCreate(); + + component = DaggerApplicationComponent.builder() + .applicationModule(new ApplicationModule(this)) + .build(); + component.inject(this); + + Log.i(TAG, "OS Version: " + android.os.Build.VERSION.RELEASE + + "(" + android.os.Build.VERSION.SDK_INT + ")"); + String versionName = getVersionName(); + Log.i(TAG, "Sky Map version " + versionName + " build " + getVersion()); + + // This populates the default values from the preferences XML file. See + // {@link DefaultValues} for more details. + PreferenceManager.setDefaultValues(this, R.xml.preference_screen, false); + + setUpAnalytics(versionName); + + performFeatureCheck(); Log.d(TAG, "StardroidApplication: -onCreate"); } From b034257747530143c0917e59b1806d05f4f45590 Mon Sep 17 00:00:00 2001 From: Jaideep Prasad Date: Mon, 29 Apr 2019 19:24:44 +0530 Subject: [PATCH 4/5] reverted-2 --- .../com/google/android/stardroid/StardroidApplication.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java index 9c9986389..c8a8b73a4 100644 --- a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java +++ b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java @@ -91,12 +91,12 @@ public void onCreate() { performFeatureCheck(); - Log.d(TAG, "StardroidApplication: -onCreate"); - } + Log.d(TAG, "StardroidApplication: -onCreate"); + } public ApplicationComponent getApplicationComponent() { return component; - } + } private void checkLocationPerms() { LocationManagerCheck locationManagerCheck = new LocationManagerCheck(this); From 6fe9084a93e21e8a2f563fffb8294d0605f9f540 Mon Sep 17 00:00:00 2001 From: Jaideep Prasad Date: Mon, 29 Apr 2019 19:25:32 +0530 Subject: [PATCH 5/5] reverted-3 --- .../com/google/android/stardroid/StardroidApplication.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java index c8a8b73a4..aa25a354c 100644 --- a/app/src/main/java/com/google/android/stardroid/StardroidApplication.java +++ b/app/src/main/java/com/google/android/stardroid/StardroidApplication.java @@ -94,8 +94,8 @@ public void onCreate() { Log.d(TAG, "StardroidApplication: -onCreate"); } - public ApplicationComponent getApplicationComponent() { - return component; + public ApplicationComponent getApplicationComponent() { + return component; } private void checkLocationPerms() {