Example #1
0
  /** {@inheritDoc} */
  @Override
  protected void onResume() {
    // Make sure that when the activity has been
    // suspended to background,
    // the device starts getting locations again
    // temporeaneamente disabilitato
    // registerLocationListeners();

    super.onResume();
  }
Example #2
0
 @Override
 protected void onPause() {
   // Make sure that when the activity goes to
   // background, the device stops getting locations
   // to save battery life.
   // temporeaneamente disabilitato
   // Log.w(TAG, "remove location listeners");
   // locationManager.removeUpdates(listenerFine);
   // locationManager.removeUpdates(listenerCoarse);
   super.onPause();
 }
Example #3
0
  @Override
  protected void onStart() {
    super.onStart();

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    comuniView = (AutoCompleteTextView) findViewById(R.id.sceltaComune);

    if (comuniView.getText().toString().equals("")) {
      String comuneDefault = sharedPrefs.getString("preference_comune_default", "");
      // Log.w(TAG, "comuneDefault" + comuneDefault);
      comuniView.setText(comuneDefault);
    }
  }
Example #4
0
  @Override
  protected void onDestroy() {

    super.onDestroy();
  }
Example #5
0
 @Override
 protected void onStop() {
   super.onStop();
 }
Example #6
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    super.onCreate(savedInstanceState);

    // Create the adView
    AdView adView = new AdView(this, AdSize.BANNER, "a14db7ec5158eb6");

    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout) this.findViewById(R.id.adviewLinearLayout);
    // Add the adView to it
    layout.addView(adView);
    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if ((locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
        || (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))) {
      registerLocationListeners();
    }

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    this.dh = new DataHelper(this);

    this.comune = (TextView) this.findViewById(R.id.DettaglioNomeComune);
    this.comuneProvincia = (TextView) this.findViewById(R.id.DettaglioProvinciaComune);
    this.lat_gradi_dec = (TextView) this.findViewById(R.id.latitudine);
    this.long_gradi_dec = (TextView) this.findViewById(R.id.longitudine);

    List<String> comuniList = this.dh.elencoComuni();
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, comuniList);
    // comuniView = (AutoCompleteTextView) findViewById(R.id.sceltaComune);
    comuniView = (AutoCompleteTextView) findViewById(R.id.sceltaComune);
    comuniView.setThreshold(1);
    comuniView.setAdapter(adapter);
    String comuneDefault = sharedPrefs.getString("preference_comune_default", "");
    comuniView.setText(comuneDefault.trim());

    /* pulsante cerca */

    cercaButton = ((Button) findViewById(R.id.cercaButton));

    cercaButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View arg0) {

            Comune comuneDett = new Comune();
            comuneDett = dh.getComuneByName(comuniView.getText().toString());
            Acqua gd = (Acqua) getApplication();

            gd.setComuneCorrente(comuneDett);
            try {

              String nomeComune = comuneDett.getNomecomune();

              if (nomeComune.length() > 40) {
                nomeComune = nomeComune.substring(0, 40);
                nomeComune = nomeComune + "...";
              }
              comune.setText(nomeComune);
              comuneProvincia.setText(" (" + comuneDett.getProvincia() + ")");
              lat_gradi_dec.setText(comuneDett.getLatitudine_display().toString());

              long_gradi_dec.setText(comuneDett.getLatitudine_display().toString());
              lat_gradi_dec.setTextColor(Color.CYAN);
              long_gradi_dec.setTextColor(Color.CYAN);
              handleFonti(comuneDett.getLatitudine(), comuneDett.getLongitudine());

            } catch (Exception e) {
              comune.setText("Comune non trovato, riprova!");
            }
          }
        });

    Button mappaButton = ((Button) findViewById(R.id.ElencoFontiMappaButton));
    mappaButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View arg0) {

            startActivity(new Intent(AcquaActivity.this, MappaActivity.class));
          }
        });

    Button rilevaPosizioneButton = ((Button) findViewById(R.id.rileva_posizione));

    rilevaPosizioneButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View arg0) {
            comune.setText("");
            comuniView.setText("");
            comuneProvincia.setText("");
            if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
              // Log.w(TAG, "abilitato networkprovider");

            }
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
              // Log.w(TAG, "abilitato gpsworkprovider");
            }

            if ((!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
                && (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))) {
              Builder builder = new AlertDialog.Builder(AcquaActivity.this);

              builder.setTitle(R.string.ElencoFontiNoLocationManagerTitle);
              ;

              builder.setMessage(R.string.ElencoFontiNoLocationManagerMessage);
              builder.setPositiveButton(
                  R.string.ElencoFontiNoLocationManagerOk,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                      startActivityForResult(intent, REQUEST_CODE);
                    }
                  });
              builder.setNegativeButton(R.string.ElencoFontiNoLocationManagerAnnulla, null);

              builder.show();
            }

            // preso da
            // http://stackoverflow.com/questions/1608632/android-locationmanager-getlastknownlocation-returns-null
            Acqua gd = (Acqua) getApplication();

            if (currentLocation == null) {
              Toast.makeText(
                      getApplicationContext(),
                      R.string.ElencoFontiStoAspettandoWifiText,
                      Toast.LENGTH_SHORT)
                  .show();

              return;
            }

            current_latitude = currentLocation.getLatitude();
            current_longitude = currentLocation.getLongitude();
            Comune c = getComuneFromLocation(current_latitude, current_longitude);

            Acqua gdata = (Acqua) getApplication();

            Log.d(TAG, "latitudine display" + c.getLatitudine_display());
            lat_gradi_dec.setText(Double.toString(c.getLatitudine_display()));

            long_gradi_dec.setText(Double.toString(c.getLongitudine_display()));
            lat_gradi_dec.setTextColor(Color.CYAN);
            long_gradi_dec.setTextColor(Color.CYAN);
            comune.setText(c.getNomecomune());

            comuneProvincia.setText(" (" + c.getProvincia() + ") ");

            gd.setComuneCorrente(c);
            handleFonti(current_latitude, current_longitude);
          }
        });
  }