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

Commit

Permalink
Include electric bikes into GUI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
francoisfds committed Jun 14, 2020
1 parent 4f1e5e7 commit fa1f5c9
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.osmdroid.api.IMapController;
Expand Down Expand Up @@ -296,6 +297,23 @@ public void onOpen(Object item) {
ImageView emptySlotsLogo = (ImageView) getView().findViewById(R.id.bubble_emptyslots_logo);
emptySlotsLogo.setVisibility(View.GONE);
}

ImageView regularBikesLogo = (ImageView) getView().findViewById(R.id.bubble_freebikes_logo);
TextView regularBikesValue = (TextView) getView().findViewById(R.id.bubble_description);
ImageView eBikesLogo = (ImageView) getView().findViewById(R.id.bubble_ebikes_logo);
TextView eBikesValue = (TextView) getView().findViewById(R.id.bubble_ebikes_value);

int bikes = markerStation.getFreeBikes();
if(markerStation.getEBikes() != null && regularBikesLogo != null
&& eBikesLogo != null && regularBikesValue!= null && eBikesValue != null ) {
int ebikes = markerStation.getEBikes();
regularBikesValue.setText(String.valueOf(bikes-ebikes));
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
eBikesLogo.setVisibility(View.VISIBLE);
eBikesValue.setVisibility(View.VISIBLE);
eBikesValue.setText(String.valueOf(ebikes));
}

layout.setClickable(true);
layout.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public boolean onMarkerClick(Marker marker, MapView mapView) {
Boolean isBankingStation = station.isBanking();
Boolean isBonusStation = station.isBonus();
StationStatus stationStatus = station.getStatus();
Integer stationEBikes = station.getEBikes();

if (isBankingStation != null) {
ImageView stationBanking = (ImageView) findViewById(R.id.stationBanking);
Expand Down Expand Up @@ -214,6 +215,19 @@ public void onClick(View view) {
stationName.setPaintFlags(stationName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}

if (stationEBikes != null) {
ImageView eBikesLogo = (ImageView) findViewById(R.id.stationEBikesLogo);
ImageView regularBikesLogo = (ImageView) findViewById(R.id.stationFreeBikesLogo);
TextView stationEBikesValue = (TextView) findViewById(R.id.stationEBikesValue);
int ebikes = station.getEBikes();

eBikesLogo.setVisibility(View.VISIBLE);
stationEBikesValue.setVisibility(View.VISIBLE);
stationEBikesValue.setText(String.valueOf(ebikes));
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
stationFreeBikes.setText(String.valueOf(freeBikes - ebikes)); //display regular bikes only
}

mapController.setCenter(stationLocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (station != null) {
TextView stationNameTitle = (TextView) v.findViewById(R.id.stationNameTitle);
TextView freeBikesValue = (TextView) v.findViewById(R.id.freeBikesValue);
ImageView regularBikesLogo = (ImageView) v.findViewById(R.id.freeBikesLogo);
TextView freeEBikesValue = (TextView) v.findViewById(R.id.freeEBikesValue);
ImageView eBikesLogo = (ImageView) v.findViewById(R.id.freeEBikesLogo);
TextView emptySlotsValue = (TextView) v.findViewById(R.id.emptySlotsValue);
StationStatus stationStatus = station.getStatus();

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

if (freeBikesValue != null) {
int bikes = station.getFreeBikes();
freeBikesValue.setText(String.valueOf(bikes));
if(station.getEBikes() != null && regularBikesLogo != null
&& eBikesLogo != null && freeEBikesValue != null ) {
int ebikes = station.getEBikes();
freeBikesValue.setText(String.valueOf(bikes-ebikes));
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
eBikesLogo.setVisibility(View.VISIBLE);
freeEBikesValue.setVisibility(View.VISIBLE);
freeEBikesValue.setText(String.valueOf(ebikes));
} else {
freeBikesValue.setText(String.valueOf(bikes));
}
}

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

return v;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

Expand Down Expand Up @@ -88,9 +89,19 @@ public RemoteViews getViewAt(int position) {
// We construct a remote views item based on our widget item xml file, and set the
// text based on the position.
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.app_widget_item);
rv.setTextViewText(R.id.widgetStationNameTitle, stations.get(position).getName());
rv.setTextViewText(R.id.widgetFreeBikesValue, String.valueOf(stations.get(position).getFreeBikes()));
rv.setTextViewText(R.id.widgetEmptySlotsValue, String.valueOf(stations.get(position).getEmptySlots()));
Station mStation = stations.get(position);
rv.setTextViewText(R.id.widgetStationNameTitle, mStation.getName());
int bikes = mStation.getFreeBikes();
if(mStation.getEBikes() != null) {
int ebikes = mStation.getEBikes();
rv.setImageViewResource(R.id.widgetFreeBikesLogo, R.drawable.ic_regular_bike);
rv.setViewVisibility(R.id.widgetEBikesLogo, View.VISIBLE);
rv.setViewVisibility(R.id.widgetEBikesValue, View.VISIBLE);
rv.setTextViewText(R.id.widgetEBikesValue, String.valueOf(ebikes));
bikes = bikes - ebikes;
}
rv.setTextViewText(R.id.widgetFreeBikesValue, String.valueOf(bikes));
rv.setTextViewText(R.id.widgetEmptySlotsValue, String.valueOf(mStation.getEmptySlots()));

// Next, we set a fill-intent which will be used to fill-in the pending intent template
// which is set on the collection view in StationsListAppWidgetProvider.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 24 additions & 2 deletions app/src/main/res/layout/activity_station.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,35 @@
android:textAppearance="?android:attr/textAppearanceMedium" />

<ImageView
android:id="@+id/stationEmptySlotsLogo"
android:id="@+id/stationEBikesLogo"
android:layout_width="22sp"
android:layout_height="22sp"
android:layout_column="0"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_row="2"
android:src="@drawable/ic_electric_bike"
android:contentDescription="@string/free_ebikes"
android:visibility="gone" />

<TextView
android:id="@+id/stationEBikesValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:text="5"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />

<ImageView
android:id="@+id/stationEmptySlotsLogo"
android:layout_width="22sp"
android:layout_height="22sp"
android:layout_column="0"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_row="3"
android:src="@drawable/ic_parking"
android:contentDescription="@string/empty_slots" />

Expand All @@ -116,7 +138,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_row="3"
android:text="5"
android:textAppearance="?android:attr/textAppearanceMedium" />

Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/layout/app_widget_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@
android:textColor="@android:color/primary_text_light"
android:textAppearance="?android:attr/textAppearanceMedium" />

<ImageView
android:id="@+id/widgetEBikesLogo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:padding="@dimen/station_list_item_logo_padding"
android:contentDescription="@string/free_ebikes"
android:src="@drawable/ic_electric_bike"
android:visibility="gone" />

<TextView
android:id="@+id/widgetEBikesValue"
android:layout_width="25dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="@android:color/primary_text_light"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />

<ImageView
android:id="@+id/widgetEmptySlotsLogo"
android:layout_width="40dp"
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/res/layout/bonuspack_bubble.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="2"
android:rowCount="2">
android:rowCount="3">

<ImageView
android:id="@+id/bubble_freebikes_logo"
Expand All @@ -69,6 +69,24 @@
android:textColor="#000000"
android:textSize="14sp" />

<ImageView
android:id="@+id/bubble_ebikes_logo"
android:layout_width="22sp"
android:layout_height="22sp"
android:layout_marginRight="5dp"
android:src="@drawable/ic_electric_bike"
android:visibility="gone" />

<TextView
android:id="@+id/bubble_ebikes_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="17"
android:text="Address"
android:textColor="#000000"
android:textSize="14sp"
android:visibility="gone" />

<ImageView
android:id="@+id/bubble_emptyslots_logo"
android:layout_width="22sp"
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/station_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />

<ImageView
android:id="@+id/freeEBikesLogo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:padding="@dimen/station_list_item_logo_padding"
android:contentDescription="@string/free_ebikes"
android:src="@drawable/ic_electric_bike"
android:visibility="gone" />

<TextView
android:id="@+id/freeEBikesValue"
android:layout_width="25dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />

<ImageView
android:id="@+id/emptySlotsLogo"
android:layout_width="40dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

<!-- Various -->
<string name="free_bikes">Free bikes:\u00A0</string>
<string name="free_ebikes">Electric bikes:\u00A0</string>
<string name="empty_slots">Empty slots:\u00A0</string>
<string name="all_stations">All stations</string>
<string name="favorite_stations">Favorites</string>
Expand Down

0 comments on commit fa1f5c9

Please sign in to comment.