Subversion Repository Public Repository

Nextrek

Diff Revisions 522 vs 542 for /Android/SmartCharging/SmartCharging/app/src/main/java/it/fedeloper/smartcharging/Manager/MyLocation.java

Diff revisions: vs.
  @@ -5,12 +5,14 @@
5 5 */
6 6
7 7 import android.content.Context;
8 + import android.content.Intent;
8 9 import android.location.Address;
9 10 import android.location.Geocoder;
10 11 import android.location.Location;
11 12 import android.location.LocationListener;
12 13 import android.location.LocationManager;
13 14 import android.os.Bundle;
15 + import android.os.Handler;
14 16 import android.widget.Toast;
15 17 import it.fedeloper.smartcharging.R;
16 18
  @@ -28,18 +30,40 @@
28 30 static boolean gps_enabled = false;
29 31 static boolean network_enabled = false;
30 32 static boolean passive_enabled = false;
31 -
33 + static boolean first =true;
32 34 /**
33 35 * Check if gps is enabled, show a toast when disabled
34 36 *
35 37 * @param context context (this in Activity / getActivity() in Fragment)
36 38 * @return true if gps is enabled
37 39 */
38 - public static boolean isGpsEnabled(Context context){
40 + public static boolean isGpsEnabled(final Context context){
39 41 LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
40 42 Boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
41 43 if(isGpsEnabled)
42 - Toast.makeText(context, R.string.enable_gps_toast, Toast.LENGTH_LONG).show();
44 + {
45 +
46 + }else{
47 + Utils.toast(context, R.string.enable_gps_toast);
48 + if (first==true)
49 + first=false;
50 + else
51 + {
52 + final int interval = 2000;
53 + Handler handler = new Handler();
54 + Runnable runnable = new Runnable(){
55 + public void run() {
56 + Intent gpsOptionsIntent = new Intent(
57 + android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
58 + context.startActivity(gpsOptionsIntent);
59 + }
60 + };
61 + handler.postDelayed(runnable, interval);
62 +
63 + }
64 +
65 + }
66 +
43 67 return isGpsEnabled;
44 68 }
45 69
  @@ -97,6 +121,8 @@
97 121 };
98 122
99 123 public static boolean getLocation(Context context, LocationResult result) {
124 +
125 + isGpsEnabled(context);
100 126 if (mylocation == null) {
101 127 //I use LocationResult callback class to pass location value from MyLocation to user code.
102 128 locationResult = result;