/**
   * @param activity The context (normally the UI context)
   * @return boolean True if successfully connected
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private final boolean servicesConnected(Activity activity) {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
      Dialog errorDialog =
          GooglePlayServicesUtil.getErrorDialog(
              resultCode, activity, CONNECTION_FAILURE_RESOLUTION_REQUEST);
      // Can Google Play service provide an error dialog
      if (errorDialog != null) {

        PackageInfo pInfo;
        try {
          pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
          // only version 11 and above support ErrorDialogFragment
          if (pInfo.versionCode >= Build.VERSION_CODES.HONEYCOMB) {
            ErrorDialogFragment errorFragment = new ErrorDialogFragment();
            // Set the dialog in the DialogFragment
            errorFragment.setDialog(errorDialog);
            // Show the error dialog in the DialogFragment
            errorFragment.show(activity.getFragmentManager(), serviceDescription_);
          }
        } catch (NameNotFoundException e) {
          Log.w(serviceDescription_, "Unable to determine version", e);
        }
      } else {
        Log.e(serviceDescription_, "Failed to get Map Service" + resultCode);
      }
      return false;
    } else {
      Log.d(serviceDescription_, "Google Play services is available.");
      return true;
    }
  }
  /**
   * Ensures that the device has the correct version of the Google Play Services.
   *
   * @return true if the Google Play Services binary is valid
   */
  private boolean isGooglePlayServicesValid(boolean showErrorDialog) {
    // Check for the google play services is available
    final int playStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext());
    final boolean isValid = playStatus == ConnectionResult.SUCCESS;

    if (!isValid && showErrorDialog) {
      final Dialog errorDialog =
          GooglePlayServicesUtil.getErrorDialog(
              playStatus,
              getActivity(),
              GOOGLE_PLAY_SERVICES_REQUEST_CODE,
              new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                  if (isAdded()) {
                    getActivity().finish();
                  }
                }
              });

      if (errorDialog != null) errorDialog.show();
    }

    return isValid;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //	Toast.makeText(this, "onCreate ", Toast.LENGTH_SHORT).show();
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_map);
    // Show the Up button in the action bar.
    setupActionBar();

    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    // Showing status
    if (status != ConnectionResult.SUCCESS) { // Google Play Services are
      // not available

      int requestCode = 10;
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
      dialog.show();

    } else { // Google Play Services are available
      // Getting reference to the SupportMapFragment of activity_main.xml
      SupportMapFragment fm =
          (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

      // Getting GoogleMap object from the fragment
      googleMap = fm.getMap();

      // Enabling MyLocation Layer of Google Map
      googleMap.setMyLocationEnabled(true);

      googleMap.setOnInfoWindowClickListener(this);
    }
  }
  private boolean isGooglePlayServicesAvailable() {
    // Check that Google Play services is available
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    // If Google Play services is available
    if (ConnectionResult.SUCCESS == resultCode) {
      // In debug mode, log the status
      Log.d("Location Updates", "Google Play services is available.");
      return true;
    } else {
      // Get the error dialog from Google Play services
      Dialog errorDialog =
          GooglePlayServicesUtil.getErrorDialog(
              resultCode, this, CONNECTION_FAILURE_RESOLUTION_REQUEST);

      // If Google Play services can provide an error dialog
      if (errorDialog != null) {
        // Create a new DialogFragment for the error dialog
        ErrorDialogFragment errorFragment = new ErrorDialogFragment();
        errorFragment.setDialog(errorDialog);
        errorFragment.show(getSupportFragmentManager(), "Location Updates");
      }

      return false;
    }
  }
  public void connect() {
    int playServiceAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    switch (playServiceAvailable) {
      case ConnectionResult.SUCCESS:
        client =
            new GoogleApiClient.Builder(this)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

        if (!isResolvingError) client.connect();

        break;

      case ConnectionResult.SERVICE_MISSING:
      case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
      case ConnectionResult.SERVICE_DISABLED:
        System.out.println("-------------- FAILURE --------------");
        GooglePlayServicesUtil.getErrorDialog(
            playServiceAvailable, this, DH_REQUEST_CODE_ERROR_DIALOG);
        break;
    }
  }
  /**
   * To check if Google Play Services is installed and up to date ! Propose to update if needed
   *
   * @return boolean if is really connected
   */
  private boolean servicesConnected() {
    // Check that Google Play services is available
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(MainActivity.baseContext);
    // If Google Play services is available
    if (ConnectionResult.SUCCESS == resultCode) {
      // In debug mode, log the status
      Log.d("Location Updates", "Google Play services is available.");
      // Continue
      return true;
      // Google Play services was not available for some reason
    } else {
      // Get the error code
      // Get the error dialog from Google Play services
      Dialog errorDialog =
          GooglePlayServicesUtil.getErrorDialog(
              resultCode, this, CONNECTION_FAILURE_RESOLUTION_REQUEST);

      // If Google Play services can provide an error dialog
      if (errorDialog != null) {
        // Create a new DialogFragment for the error dialog
        ErrorDialogFragment errorFragment = new ErrorDialogFragment();
        // Set the dialog in the DialogFragment
        errorFragment.setDialog(errorDialog);
        // Show the error dialog in the DialogFragment
        errorFragment.show(getFragmentManager(), "Location Updates");
      }
    }
    return false;
  }
 @Test
 public void isGooglePlayServicesAvailable_shouldGetSet() {
   assertThat(GooglePlayServicesUtil.isGooglePlayServicesAvailable(RuntimeEnvironment.application))
       .isEqualTo(ConnectionResult.SERVICE_MISSING);
   ShadowGooglePlayServicesUtil.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);
   assertThat(GooglePlayServicesUtil.isGooglePlayServicesAvailable(RuntimeEnvironment.application))
       .isEqualTo(ConnectionResult.SUCCESS);
 }
Exemple #8
0
 /** Check that Google Play services APK is installed and up to date. */
 private boolean checkGooglePlayServicesAvailable() {
   final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
     showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
     return false;
   }
   return true;
 }
 private boolean isGooglePlayServicesAvailable() {
   int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (ConnectionResult.SUCCESS == status) {
     return true;
   } else {
     GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
     return false;
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_layout);

    bar = (ProgressBar) findViewById(R.id.progressBar);

    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    // Showing status
    if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available

      int requestCode = 10;
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
      dialog.show();

    } else { // Google Play Services are available

      mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
      mapFragment.getMapAsync(this);
      // Getting GoogleMap object from the fragment
      mMap = mapFragment.getMap();

      // Enabling MyLocation Layer of Google Map
      mMap.setMyLocationEnabled(true);

      // Getting LocationManager object from System Service LOCATION_SERVICE
      LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

      //        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 200000, 0,
      // this);
      //        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 200000, 0,
      // this);
      //        locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 200000, 0,
      // this);

      // Creating a criteria object to retrieve provider
      Criteria criteria = new Criteria();

      // Getting the name of the best provider
      String provider = locationManager.getBestProvider(criteria, true);

      // Getting Current Location
      location = locationManager.getLastKnownLocation(provider);

      if (location != null) {
        onLocationChanged(location);
      }
    }

    setUpClusterer();
    // Add cluster items (markers) to the cluster manager.
    ShelterListAsync shelterListTask = new ShelterListAsync();
    shelterListTask.execute();
  }
  private void checkGooglePlayService() {

    int isGooglePlayServiceAvilable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (isGooglePlayServiceAvilable == ConnectionResult.SUCCESS) {
      googleApiClient.connect();
    } else {
      String errorText = GooglePlayServicesUtil.getErrorString(isGooglePlayServiceAvilable);
      Toast.makeText(this, errorText, Toast.LENGTH_SHORT).show();
    }
  }
Exemple #12
0
 /**
  * Verify that Google Play services is available before making a request.
  *
  * @return true if Google Play services is available, otherwise false
  */
 private boolean servicesConnected() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (ConnectionResult.SUCCESS == resultCode) {
     Log.d(ActivityUtils.APPTAG, getString(R.string.play_services_available));
     return true;
   } else {
     GooglePlayServicesUtil.getErrorDialog(resultCode, this, 0).show();
     return false;
   }
 }
 /**
  * Utility method that checks whether Google Play Services is installed and up to date, and
  * displays a notification for the user to update if no.
  *
  * @return true if installed
  */
 private boolean checkGooglePlayServicesAvailable() {
   final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
     Dialog dialog =
         GooglePlayServicesUtil.getErrorDialog(
             connectionStatusCode, this, REQ_GOOGLE_PLAY_SERVICES);
     dialog.show();
     return false;
   }
   return true;
 }
 private boolean isPlayServicesConfigured() {
   int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(MapActivity.this);
   if (status == ConnectionResult.SUCCESS) return true;
   else {
     // Log.d("STATUS", "Error connecting with Google Play services. Code: " +
     // String.valueOf(status));
     Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, MapActivity.this, status);
     dialog.show();
     return false;
   }
 }
 /**
  * Vérifie que Google Play services APK est installé et à jour. Lancera un message d'erreur
  * demandant la mise à jour si nécessaire et possible.
  *
  * @return true si Google Play Services est dipo et à jour, sinon retourne false
  */
 private boolean isGooglePlayServicesAvailable() {
   final int connectionStatusCode =
       GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext());
   if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
     showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
     return false;
   } else if (connectionStatusCode != ConnectionResult.SUCCESS) {
     return false;
   }
   return true;
 }
Exemple #16
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // Getting status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    // Showing status
    if (status == ConnectionResult.SUCCESS) {

    } else {

      int requestCode = 10;
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
      dialog.show();
      return;
    }

    // requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    if (savedInstanceState != null) {
      allTapItem = (ArrayList<OSMNode>) savedInstanceState.get("allTapItem");
      allToiletItem = (ArrayList<OSMNode>) savedInstanceState.get("allToiletItem");
      allFoodItem = (ArrayList<OSMNode>) savedInstanceState.get("allFoodItem");
    }
    // TODO Semi-Transparent Action Bar
    // requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    // getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));

    setContentView(R.layout.activity_main);
    configureActionBar();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    mMapFragment = getSupportFragmentManager().findFragmentByTag("map");
    if (mMapFragment == null) {
      // If not, instantiate and add it to the activity
      mMapFragment = new ViewMapFragment_();
      ft.add(R.id.container, mMapFragment, "map").commit();
    } else {
      // If it exists, simply attach it in order to show it
      ft.show(mMapFragment).commit();
    }
    TapForTap.initialize(this, "ef3209aec5ac8e0eb9682b8890b20a78");
    adview = (AdView) findViewById(R.id.adView);
    adview.setAdListener(this);
    ImageButton imgbtn = (ImageButton) findViewById(R.id.closeadbtn);
    imgbtn.setVisibility(View.GONE);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    adview.loadAd(request);

    // Search markers
    searchMarkers = new ArrayList<Marker>();
  }
 /**
  * Check the device to make sure it has the Google Play Services APK. If it doesn't, display a
  * dialog that allows users to download the APK from the Google Play Store or enable it in the
  * device's system settings.
  */
 private boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST)
           .show();
     }
     return false;
   }
   return true;
 }
 public boolean serviceOK() {
   int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (isAvailable == ConnectionResult.SUCCESS) {
     return true;
   } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
     Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, 100);
     dialog.show();
   } else {
     Toast.makeText(this, "Something wrong!", Toast.LENGTH_LONG).show();
   }
   return false;
 }
 /**
  * Checks if the GooglePlayServices is installed
  *
  * @return true if playServices is installed or false if note
  */
 private boolean checkPlayServices() {
   int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (status != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
       showErrorDialog(status);
     } else {
       Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show();
       finish();
     }
     return false;
   }
   return true;
 }
Exemple #20
0
 private static boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(resultCode, context, PLAY_SERVICES_RESOLUTION_REQUEST)
           .show();
     } else {
       Log.i(TAG, "This device is not supported.");
     }
     return false;
   }
   return true;
 }
 /**
  * This function checks for GooglePlay Service availability
  *
  * @param activity
  * @return
  */
 public static boolean isPlayServiceAvailable(Activity activity) {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(resultCode, activity, PlayServiceResolutionRequest)
           .show();
     } else {
       Log.i(Tag, "This device is not supported.");
     }
     return false;
   }
   return true;
 }
Exemple #22
0
 private boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1).show();
     } else {
       Log.i("CheckPlayServices", "Dispositivo no soportado.");
       finish();
     }
     return false;
   }
   return true;
 }
  public void setMapView() {
    campusMap =
        ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    // Con el fin de comprobar si el dispositivo cuenta con Google Play Services.
    if (campusMap != null) {
      // Setup your map...
    } else {
      int isEnabled = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
      if (isEnabled != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(isEnabled, this, 0);
      }
    }
    //

    campusMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    campusMap.moveCamera(CameraUpdateFactory.newLatLngZoom(UniEafit, minZoom));

    campusMap.setMyLocationEnabled(true);

    // Se comprueba sí es necesario que el usuario aparezca en el mapa.
    Location userLocation = campusMap.getMyLocation();
    if (userLocation != null) {
      if (!campusMapBounds.contains(
          new LatLng(userLocation.getLatitude(), userLocation.getLongitude()))) {
        campusMap.setMyLocationEnabled(false);
      }
    }

    campusMap.getUiSettings().setZoomControlsEnabled(false);
    campusMap.getUiSettings().setCompassEnabled(true);
    Bundle paramsBag = getIntent().getExtras(); // 	Aquí estarían los parámetros recibidos.
    if (paramsBag != null && paramsBag.getBoolean("storeInfo")) { // La app viene del Log in.
      clearSharedPreferences();
      saveSharedPreferences();
    } else {
      checkUserData();
    }
    if (isInternetConnectionAvailable()) {
      wantedService = "Add main markers";
      POST_URL = "http://campusmovilapp.herokuapp.com/api/v1/markers";
      // Para dar autorización al acceso de los marcadores.
      new POSTConnection().execute(POST_URL);
    } else {
      Toast.makeText(
              getApplicationContext(),
              getResources().getString(R.string.internet_connection_required),
              Toast.LENGTH_SHORT)
          .show();
    }
  }
Exemple #24
0
 private boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST)
           .show();
     } else {
       Logger.getInstance().w("This device is not supported.");
       finish();
     }
     return false;
   }
   return true;
 }
Exemple #25
0
  // check for google services is available or not
  public boolean servicesOK() {
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {
      return true;
    } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
      Dialog dialog =
          GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
      dialog.show();
    } else {
      Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
    }
    return false;
  }
 private boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1000).show();
     } else {
       Toast.makeText(getApplicationContext(), "This device is not supported.", Toast.LENGTH_LONG)
           .show();
       finish();
     }
     return false;
   }
   return true;
 }
  /** Checks to see if Google Play Services is installed on the phone, which is required. */
  private void checkGooglePlayServices() {
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (status != ConnectionResult.SUCCESS) {
      if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
        Dialog googlePlayError = GooglePlayServicesUtil.getErrorDialog(status, this, 0);
        googlePlayError.setCancelable(false);
        googlePlayError.setCanceledOnTouchOutside(false);
        googlePlayError.show();
      } else {
        Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show();
        finish();
      }
    }
  }
 private boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(
               resultCode, activity, PLAY_SERVICES_RESOLUTION_REQUEST)
           .show();
     } else {
       Toast.makeText(activity, "This device is not supported.", Toast.LENGTH_LONG).show();
       activity.finish();
     }
     return false;
   }
   return true;
 }
 private boolean isGooglePlayServicesAvailable() {
   int availability = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
   switch (availability) {
     case ConnectionResult.SUCCESS:
       return true;
     case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
     case ConnectionResult.SERVICE_DISABLED:
     case ConnectionResult.SERVICE_INVALID:
       GooglePlayServicesUtil.getErrorDialog(availability, activity, REQUEST_CODE_AVAILABILITY)
           .show();
       return false;
     default:
       return false;
   }
 }
 private boolean checkPlayServices() {
   int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
   if (resultCode != ConnectionResult.SUCCESS) {
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
       GooglePlayServicesUtil.getErrorDialog(
               resultCode, this.cordova.getActivity(), PLAY_SERVICES_RESOLUTION_REQUEST)
           .show();
     } else {
       Log.i(TAG, "This device does not support Play Services.");
       // finish();
     }
     return false;
   }
   return true;
 }