@Override protected void onStop() { super.onStop(); //// Log.i("openBicing", "STOP!"); hOverlay.stopUpdates(); if (this.isFinishing()) this.finish(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Log.i("CityBikes", "Activity Result"); if (requestCode == SETTINGS_ACTIVITY) { if (resultCode == RESULT_OK) { hOverlay.restartUpdates(); } } SharedPreferences settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0); Boolean dirty = settings.getBoolean("reload_network", false); if (dirty) { this.fillData(view_all); } }
public void populateList(boolean all) { try { ListView lv = new ListView(this); List sts; if (all) { sts = mDbHelper.getMemory(); } else { sts = mDbHelper.getMemory(hOverlay.getRadius()); } green = R.drawable.green_gradient; yellow = R.drawable.yellow_gradient; red = R.drawable.red_gradient; ArrayAdapter adapter = new ArrayAdapter(this, R.layout.stations_list_item, sts) { LayoutInflater mInflater = getLayoutInflater(); @Override public View getView(int position, View convertView, ViewGroup parent) { View row; if (convertView == null) { row = mInflater.inflate(R.layout.stations_list_item, null); } else { row = convertView; } StationOverlay tmp = (StationOverlay) getItem(position); TextView stId = (TextView) row.findViewById(R.id.station_list_item_id); stId.setText(tmp.getStation().getName()); TextView stOc = (TextView) row.findViewById(R.id.station_list_item_ocupation); stOc.setText(tmp.getStation().getOcupation()); TextView stDst = (TextView) row.findViewById(R.id.station_list_item_distance); stDst.setText(tmp.getStation().getDistance()); TextView stWk = (TextView) row.findViewById(R.id.station_list_item_walking_time); stWk.setText(tmp.getStation().getWalking()); int bg; switch (tmp.getState()) { case StationOverlay.GREEN_STATE: bg = green; break; case StationOverlay.RED_STATE: bg = red; break; case StationOverlay.YELLOW_STATE: bg = yellow; break; default: bg = R.drawable.fancy_gradient; } LinearLayout sq = (LinearLayout) row.findViewById(R.id.station_list_item_square); sq.setBackgroundResource(bg); row.setId(tmp.getStation().getId()); return row; } }; lv.setAdapter(adapter); lv.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int position, long id) { int pos = v.getId(); if (pos != -1) { StationOverlay selected = stations.findById(pos); if (selected != null) { stations.setCurrent(selected.getPosition(), getBike); Message tmp = new Message(); tmp.what = InfoLayer.POPULATE; tmp.arg1 = selected.getPosition(); infoLayerPopulator.dispatchMessage(tmp); mapView.getController().animateTo(selected.getCenter()); int height = arg0.getHeight(); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int w_height = dm.heightPixels; if (height > w_height / 2) { mSlidingDrawer.animateClose(); } } } } }); lv.setBackgroundColor(Color.BLACK); lv.setLayoutParams( new LayoutParams( android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); fl.setBackgroundColor(Color.BLACK); fl.removeAllViews(); fl.addView(lv); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int height = dm.heightPixels; int calc = (lv.getCount() * 50) + 45; if (calc > height - 145) calc = height - 145; else if (lv.getCount() == 0) calc = 0; mSlidingDrawer.setLayoutParams( new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, calc)); //// Log.i("openBicing", Integer.toString(fl.getHeight())); } catch (Exception e) { ////// Log.i("openBicing", "SHIT THIS SUCKS MEN ARGH F**K IT!"); // TODO Auto-generated catch block e.printStackTrace(); } }
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(); }