public void populateFields() { if (this.station != null) { this.station_id.setText(this.station.getStation().getName()); this.ocupation.setText(this.station.getStation().getOcupation()); this.walking_time.setText(this.station.getStation().getWalking()); this.distance.setText(this.station.getStation().getDistance()); int bg; switch (station.getState()) { case StationOverlay.BLACK_STATE: bg = this.black; break; case StationOverlay.GREEN_STATE: bg = this.green; break; case StationOverlay.RED_STATE: bg = this.red; break; case StationOverlay.YELLOW_STATE: bg = this.yellow; break; default: bg = R.drawable.fancy_gradient; } this.setBackgroundResource(bg); } }
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) { } ; }
public void inflateStation(StationOverlay tmp) { if (tmp != null) { this.station = tmp; this.removeAllViews(); inflater.inflate(R.layout.infolayer, this); TextView stId = (TextView) findViewById(R.id.station_list_item_id); stId.setText(tmp.getStation().getName()); TextView stOc = (TextView) findViewById(R.id.station_list_item_ocupation); stOc.setText(tmp.getStation().getOcupation()); TextView stDst = (TextView) findViewById(R.id.station_list_item_distance); stDst.setText(tmp.getStation().getDistance()); TextView stWk = (TextView) findViewById(R.id.station_list_item_walking_time); stWk.setText(tmp.getStation().getWalking()); int bg; switch (tmp.getState()) { case StationOverlay.BLACK_STATE: bg = black; break; 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) findViewById(R.id.station_list_item_square); sq.setBackgroundResource(bg); // //Log.i("openBicing", "Inflated: " + this.station.getName()); populated = true; vf = (ViewFlipper) findViewById(R.id.stationViewFlipper); bookmarkButton = (ToggleButton) findViewById(R.id.bookmark_station); alarmButton = (Button) findViewById(R.id.alarm_station); unalarmButton = (Button) findViewById(R.id.unalarm_station); flingTooltip = (FlingTooltip) findViewById(R.id.FlingTooltip); flingTooltip.setVisibility(View.INVISIBLE); if (bookmarkButton != null) { bookmarkButton.setChecked(station.getStation().isBookmarked()); bookmarkButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub station.getStation().setBookmarked(!station.getStation().isBookmarked()); Message msg = new Message(); msg.what = CityBikes.BOOKMARK_CHANGE; msg.arg1 = station.getStation().getId(); if (station.getStation().isBookmarked()) msg.arg2 = 1; else msg.arg2 = 0; handler.sendMessage(msg); } }); } if (alarmButton != null) { alarmButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); registrationIntent.putExtra( "app", PendingIntent.getBroadcast(ctx, 0, new Intent(), 0)); // boilerplate registrationIntent.putExtra("sender", "*****@*****.**"); ctx.startService(registrationIntent); String deviceId = Secure.getString(ctx.getContentResolver(), Secure.ANDROID_ID); Map<String, String> data = new HashMap<String, String>(); data.put("devId", deviceId); data.put("station_id", Integer.toString(station.getStation().getId())); data.put("action", "callStation"); try { Log.i("C2DM", "Sending station to laika"); if (rHelper.restPOST("http://laika.citybik.es:8181", data) == null) { Log.i("C2DM", "Error sending station to laika. Exception already catched."); Toast t = Toast.makeText(ctx, "Unable to set alarm", Toast.LENGTH_SHORT); t.show(); } } catch (Exception e) { Log.i("C2DM", "Error sending station to laika: " + e.getMessage()); } } }); } if (unalarmButton != null) { unalarmButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER"); unregIntent.putExtra("app", PendingIntent.getBroadcast(ctx, 0, new Intent(), 0)); ctx.startService(unregIntent); } }); } checkFirstTime(); } }