Example #1
0
 public void updateHome() {
   try {
     stations.updateHome();
     mapView.getController().setCenter(stations.getHome().getPoint());
     mapView.getController().setZoom(16);
   } catch (Exception e) {
     //// Log.i("openBicing", "center is null..");
   }
 }
Example #2
0
  public void view_near() {
    try {
      mDbHelper.populateStations(stations.getHome().getPoint(), stations.getHome().getRadius());
      populateList(false);
      if (!infoLayer.isPopulated()) {
        StationOverlay current = stations.getCurrent();
        if (current != null) {
          infoLayer.inflateStation(current);
          current.setSelected(true, this.getBike);
        } else {
          infoLayer.inflateMessage(getString(R.string.no_bikes_around));
        }
      }
    } catch (Exception e) {

    }
    ;
  }
Example #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    fl = (FrameLayout) findViewById(R.id.content);
    mSlidingDrawer = (SlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    // Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
              infoLayer.inflateStation(stations.get(msg.arg1));
            }
          }
        };

    RelativeLayout.LayoutParams zoomControlsLayoutParams =
        new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            changeMode(!getBike);
          }
        });

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    stations =
        new StationOverlayList(
            this,
            mapOverlays,
            new Handler() {
              @Override
              public void handleMessage(Message msg) {
                if (msg.what == hOverlay.MOTION_CIRCLE_STOP && !view_all) {
                  // Home Circle has changed its radius
                  try {
                    view_near();
                  } catch (Exception e) {

                  }
                } else if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                  // One station has been touched
                  stations.setCurrent(msg.arg1, getBike);
                  infoLayer.inflateStation(stations.getCurrent());
                } else if (msg.what == hOverlay.LOCATION_CHANGED) {
                  // Location has changed
                  mDbHelper.setCenter(hOverlay.getPoint());

                  try {
                    mDbHelper.updateDistances(hOverlay.getPoint());
                    infoLayer.update();

                    if (view_all) {
                      view_all();
                    } else {
                      view_near();
                    }
                  } catch (Exception e) {

                  }
                  ;
                }
              }
            });
    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper =
        new StationsDBAdapter(
            this,
            mapView,
            new Handler() {
              @Override
              public void handleMessage(Message msg) {
                switch (msg.what) {
                  case StationsDBAdapter.FETCH:
                    ////// Log.i("openBicing", "Data fetched");
                    break;
                  case StationsDBAdapter.UPDATE_MAP:
                    ////// Log.i("openBicing", "Map Updated");
                    progressDialog.dismiss();
                    SharedPreferences settings =
                        getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putBoolean("reload_network", false);
                    editor.commit();
                    StationOverlay current = stations.getCurrent();
                    if (current == null) {
                      infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                    }
                    if (current != null) {
                      current.setSelected(true, getBike);
                      infoLayer.inflateStation(current);
                      if (view_all) view_all();
                      else view_near();
                    } else {
                      //// Log.i("openBicing", "Error getting an station..");
                    }
                    mapView.invalidate();
                    break;
                  case StationsDBAdapter.UPDATE_DATABASE:

                    //// Log.i("openBicing", "Database updated");
                    break;
                  case StationsDBAdapter.NETWORK_ERROR:
                    //// Log.i("openBicing", "Network error, last update from " +
                    // mDbHelper.getLastUpdated());
                    Toast toast =
                        Toast.makeText(
                            getApplicationContext(),
                            getString(R.string.network_error) + mDbHelper.getLastUpdated(),
                            Toast.LENGTH_LONG);
                    toast.show();
                    break;
                }
              }
            },
            stations);

    mDbHelper.setCenter(stations.getHome().getPoint());

    if (savedInstanceState != null) {
      stations.updateHome();
      stations.getHome().setRadius(savedInstanceState.getInt("homeRadius"));
      this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
      updateHome();
    }

    try {
      mDbHelper.loadStations();
      if (savedInstanceState == null) {
        String strUpdated = mDbHelper.getLastUpdated();

        SharedPreferences settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);
        Boolean dirty = settings.getBoolean("reload_network", false);

        if (strUpdated == null || dirty) {
          this.fillData(view_all);
        } else {
          Toast toast =
              Toast.makeText(
                  this.getApplicationContext(),
                  "Last Updated: " + mDbHelper.getLastUpdated(),
                  Toast.LENGTH_LONG);
          toast.show();
        }
      }

    } catch (Exception e) {
      //// Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all) view_all();
    else view_near();
    hOverlay = stations.getHome();
    //// Log.i("openBicing", "CREATE!");
  }
Example #4
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   //// Log.i("openBicing", "SaveInstanceState!");
   outState.putInt("homeRadius", stations.getHome().getRadius());
   outState.putBoolean("view_all", view_all);
 }
Example #5
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();
      }
    }
  }