Exemplo n.º 1
0
  private void fillData(boolean all) {

    if (mNDBAdapter.isConfigured()) {
      Bundle data = new Bundle();
      if (!all) {
        GeoPoint center = stations.getHome().getPoint();
        data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6());
        data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6());
        data.putInt(StationsDBAdapter.RADIUS_KEY, stations.getHome().getRadius());
      }

      progressDialog = new ProgressDialog(this);
      progressDialog.setTitle("");
      progressDialog.setMessage(getString(R.string.loading));
      progressDialog.show();
      try {
        mDbHelper.sync(all, data);
      } catch (Exception e) {
        //// Log.i("openBicing", "Error Updating?");
        e.printStackTrace();
        progressDialog.dismiss();
      }
      ;
    } else {
      // Log.i("CityBikes","First time!!! :D");
      try {
        mNDBAdapter.update();
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setIcon(R.drawable.icon_cool);
        alertDialog.setIcon(android.R.drawable.ic_dialog_map);
        alertDialog.setTitle(R.string.bike_network_alert_title);
        alertDialog.setMessage(getString(R.string.bike_network_alert_text));
        alertDialog.setButton(
            getString(R.string.automatic),
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

              }
            });
        alertDialog.setButton(
            AlertDialog.BUTTON_POSITIVE,
            getString(R.string.automatic),
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {

                showAutoNetworkDialog(0);
              }
            });
        alertDialog.setButton(
            AlertDialog.BUTTON_NEGATIVE,
            getString(R.string.manual),
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                showBikeNetworks();
              }
            });
        alertDialog.show();
      } catch (Exception e) {
        e.printStackTrace();
        Toast toast =
            Toast.makeText(
                getApplicationContext(), getString(R.string.network_error), Toast.LENGTH_LONG);
        toast.show();
      }
    }
  }
Exemplo n.º 2
0
  private void showAutoNetworkDialog(int method) {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setIcon(android.R.drawable.ic_dialog_map);
    final int mth = method;
    try {
      mNDBAdapter.update();
      final JSONObject network = mNDBAdapter.getAutomaticNetwork(hOverlay.getPoint(), method);
      alertDialog.setTitle(R.string.bike_network_alert_success_title);
      alertDialog.setMessage(
          getString(R.string.bike_network_alert_success_text0)
              + ":\n- ("
              + network.getString("city")
              + ") "
              + network.getString("name")
              + "\n"
              + getString(R.string.bike_network_alert_success_text1));
      alertDialog.setButton(
          AlertDialog.BUTTON_POSITIVE,
          getString(R.string.sure),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              try {
                mNDBAdapter.setManualNetwork(network.getInt("id"));
                fillData(view_all);
              } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
          });
      alertDialog.setButton(
          AlertDialog.BUTTON_NEUTRAL,
          getString(R.string.try_again),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              if (mth == 0) showAutoNetworkDialog(1);
              else showAutoNetworkDialog(0);
            }
          });
      alertDialog.setButton(
          AlertDialog.BUTTON_NEGATIVE,
          getString(R.string.manual),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              showBikeNetworks();
            }
          });

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

      alertDialog.setTitle(R.string.bike_network_alert_error_title);

      alertDialog.setMessage(getString(R.string.bike_network_alert_error_text));
      alertDialog.setButton(
          AlertDialog.BUTTON_POSITIVE,
          getString(R.string.try_again),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              if (mth == 0) showAutoNetworkDialog(1);
              else showAutoNetworkDialog(0);
            }
          });
      alertDialog.setButton(
          AlertDialog.BUTTON_NEGATIVE,
          getString(R.string.manual),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              showBikeNetworks();
            }
          });
    }
    alertDialog.show();
  }