Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit d88b618

Browse files
committed
Include electric bikes into GUI
This commit handles display of electric bikes by adding an 'ebikes' area to the 'free bikes' and 'empty slots' legacy areas of the GUI. By default this additional area is non visible, and it shows up only if the bike system supports it. In this case, the 'free bikes' area is turned into a 'regular bikes' area : it displays the number of non-electric bikes only, and the icon is replaced by a green one. This update is done on 4 pieces of GUI's code : - StationActivity.java which inflates activity_station.xml - StationsListAdapter.java which inflates station_list_item.xml - MapActivity.java which inflates bonuspack_bubble.xml - StationsListAppWidgetService.java which inflates app_widget_item.xml
1 parent 365a175 commit d88b618

File tree

17 files changed

+142
-8
lines changed

17 files changed

+142
-8
lines changed

app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/MapActivity.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.view.View;
3636
import android.widget.ImageView;
3737
import android.widget.LinearLayout;
38+
import android.widget.TextView;
3839
import android.widget.Toast;
3940

4041
import org.osmdroid.api.IMapController;
@@ -289,6 +290,23 @@ public void onOpen(Object item) {
289290
ImageView emptySlotsLogo = (ImageView) getView().findViewById(R.id.bubble_emptyslots_logo);
290291
emptySlotsLogo.setVisibility(View.GONE);
291292
}
293+
294+
ImageView regularBikesLogo = (ImageView) getView().findViewById(R.id.bubble_freebikes_logo);
295+
TextView regularBikesValue = (TextView) getView().findViewById(R.id.bubble_description);
296+
ImageView eBikesLogo = (ImageView) getView().findViewById(R.id.bubble_ebikes_logo);
297+
TextView eBikesValue = (TextView) getView().findViewById(R.id.bubble_ebikes_value);
298+
299+
int bikes = markerStation.getFreeBikes();
300+
if(markerStation.getEBikes() != null && regularBikesLogo != null
301+
&& eBikesLogo != null && regularBikesValue!= null && eBikesValue != null ) {
302+
int ebikes = markerStation.getEBikes();
303+
regularBikesValue.setText(String.valueOf(bikes-ebikes));
304+
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
305+
eBikesLogo.setVisibility(View.VISIBLE);
306+
eBikesValue.setVisibility(View.VISIBLE);
307+
eBikesValue.setText(String.valueOf(ebikes));
308+
}
309+
292310
layout.setClickable(true);
293311
layout.setOnClickListener(new View.OnClickListener() {
294312
@Override

app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/StationActivity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public boolean onMarkerClick(Marker marker, MapView mapView) {
171171
Boolean isBankingStation = station.isBanking();
172172
Boolean isBonusStation = station.isBonus();
173173
StationStatus stationStatus = station.getStatus();
174+
Integer stationEBikes = station.getEBikes();
174175

175176
if (isBankingStation != null) {
176177
ImageView stationBanking = (ImageView) findViewById(R.id.stationBanking);
@@ -208,6 +209,19 @@ public void onClick(View view) {
208209
stationName.setPaintFlags(stationName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
209210
}
210211

212+
if (stationEBikes != null) {
213+
ImageView eBikesLogo = (ImageView) findViewById(R.id.stationEBikesLogo);
214+
ImageView regularBikesLogo = (ImageView) findViewById(R.id.stationFreeBikesLogo);
215+
TextView stationEBikesValue = (TextView) findViewById(R.id.stationEBikesValue);
216+
int ebikes = station.getEBikes();
217+
218+
eBikesLogo.setVisibility(View.VISIBLE);
219+
stationEBikesValue.setVisibility(View.VISIBLE);
220+
stationEBikesValue.setText(String.valueOf(ebikes));
221+
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
222+
stationFreeBikes.setText(String.valueOf(freeBikes - ebikes)); //display regular bikes only
223+
}
224+
211225
mapController.setCenter(stationLocation);
212226
}
213227

app/src/main/java/be/brunoparmentier/openbikesharing/app/adapters/StationsListAdapter.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
5757
if (station != null) {
5858
TextView stationNameTitle = (TextView) v.findViewById(R.id.stationNameTitle);
5959
TextView freeBikesValue = (TextView) v.findViewById(R.id.freeBikesValue);
60+
ImageView regularBikesLogo = (ImageView) v.findViewById(R.id.freeBikesLogo);
61+
TextView freeEBikesValue = (TextView) v.findViewById(R.id.freeEBikesValue);
62+
ImageView eBikesLogo = (ImageView) v.findViewById(R.id.freeEBikesLogo);
6063
TextView emptySlotsValue = (TextView) v.findViewById(R.id.emptySlotsValue);
6164
StationStatus stationStatus = station.getStatus();
6265

@@ -72,7 +75,17 @@ public View getView(int position, View convertView, ViewGroup parent) {
7275

7376
if (freeBikesValue != null) {
7477
int bikes = station.getFreeBikes();
75-
freeBikesValue.setText(String.valueOf(bikes));
78+
if(station.getEBikes() != null && regularBikesLogo != null
79+
&& eBikesLogo != null && freeEBikesValue != null ) {
80+
int ebikes = station.getEBikes();
81+
freeBikesValue.setText(String.valueOf(bikes-ebikes));
82+
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
83+
eBikesLogo.setVisibility(View.VISIBLE);
84+
freeEBikesValue.setVisibility(View.VISIBLE);
85+
freeEBikesValue.setText(String.valueOf(ebikes));
86+
} else {
87+
freeBikesValue.setText(String.valueOf(bikes));
88+
}
7689
}
7790

7891
if (emptySlotsValue != null) {
@@ -91,4 +104,4 @@ public View getView(int position, View convertView, ViewGroup parent) {
91104

92105
return v;
93106
}
94-
}
107+
}

app/src/main/java/be/brunoparmentier/openbikesharing/app/widgets/StationsListAppWidgetService.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.content.Context;
2222
import android.content.Intent;
2323
import android.os.Bundle;
24+
import android.view.View;
2425
import android.widget.RemoteViews;
2526
import android.widget.RemoteViewsService;
2627

@@ -88,9 +89,19 @@ public RemoteViews getViewAt(int position) {
8889
// We construct a remote views item based on our widget item xml file, and set the
8990
// text based on the position.
9091
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.app_widget_item);
91-
rv.setTextViewText(R.id.widgetStationNameTitle, stations.get(position).getName());
92-
rv.setTextViewText(R.id.widgetFreeBikesValue, String.valueOf(stations.get(position).getFreeBikes()));
93-
rv.setTextViewText(R.id.widgetEmptySlotsValue, String.valueOf(stations.get(position).getEmptySlots()));
92+
Station mStation = stations.get(position);
93+
rv.setTextViewText(R.id.widgetStationNameTitle, mStation.getName());
94+
int bikes = mStation.getFreeBikes();
95+
if(mStation.getEBikes() != null) {
96+
int ebikes = mStation.getEBikes();
97+
rv.setImageViewResource(R.id.widgetFreeBikesLogo, R.drawable.ic_regular_bike);
98+
rv.setViewVisibility(R.id.widgetEBikesLogo, View.VISIBLE);
99+
rv.setViewVisibility(R.id.widgetEBikesValue, View.VISIBLE);
100+
rv.setTextViewText(R.id.widgetEBikesValue, String.valueOf(ebikes));
101+
bikes = bikes - ebikes;
102+
}
103+
rv.setTextViewText(R.id.widgetFreeBikesValue, String.valueOf(bikes));
104+
rv.setTextViewText(R.id.widgetEmptySlotsValue, String.valueOf(mStation.getEmptySlots()));
94105

95106
// Next, we set a fill-intent which will be used to fill-in the pending intent template
96107
// which is set on the collection view in StationsListAppWidgetProvider.
3.35 KB
Loading
3.11 KB
Loading
1.91 KB
Loading
1.81 KB
Loading
4.97 KB
Loading
4.72 KB
Loading

0 commit comments

Comments
 (0)