Skip to content

Commit 3ae7efd

Browse files
committed
Added Proper Route Shape to Carris Metropolitana and something more rudimentar to the other sources
1 parent 9294270 commit 3ae7efd

18 files changed

+531
-102
lines changed

app/src/main/java/kevin/carrismobile/adaptors/RouteImageListAdaptor.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,29 @@ public View getView(int i, View view, ViewGroup viewGroup) {
106106
}
107107

108108
private Drawable getImageId(String string){
109-
if (string.equals("#ED1944")){
110-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_ed1944, null);
111-
}else if (string.equals("#C61D23")){
112-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_c61d23, null);
113-
}else if (string.equals("#BB3E96")){
114-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_bb3e96, null);
115-
}else if (string.equals("#3D85C6")){
116-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_3d85c6, null);
117-
}else if (string.equals("#2A9057")){
118-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_2a9057, null);
119-
}else if (string.equals("#FDB71A")){
120-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_fdb71a, null);
121-
}else{
122-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_00b8b0, null);
109+
switch (string) {
110+
case "#ED1944":
111+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_ed1944, null);
112+
case "#C61D23":
113+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_c61d23, null);
114+
case "#BB3E96":
115+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_bb3e96, null);
116+
case "#3D85C6":
117+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_3d85c6, null);
118+
case "#2A9057":
119+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_2a9057, null);
120+
case "#FDB71A":
121+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_fdb71a, null);
122+
case "color_cascais":
123+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_cascais, null);
124+
case "color_carris":
125+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_carris, null);
126+
case "color_cp":
127+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_cp, null);
128+
case "color_fertagus":
129+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_fertagus, null);
130+
default:
131+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.color_00b8b0, null);
123132
}
124133
}
125134
}

app/src/main/java/kevin/carrismobile/adaptors/StopImageListAdaptor.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public StopImageListAdaptor(Activity activity, List<Stop> stopList){
3737
this.stopList = stopList;
3838
for (Stop s : stopList){
3939
textList.add(s.getTts_name());
40-
imageList.add(getImageId(s.getFacilities(), s.getTts_name()));
40+
imageList.add(getImageId(s.getFacilities(), s.getTts_name(), s.getAgency_id(), activity));
4141
}
4242
}
4343

@@ -75,22 +75,33 @@ public View getView(int i, View view, ViewGroup viewGroup) {
7575
return view;
7676
}
7777

78-
private Drawable getImageId(List<String> facilities, String tts_name){
79-
if (facilities.contains("subway")){
80-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_metro_logo, null);
81-
}else if(facilities.contains("train")){
78+
public static Drawable getImageId(List<String> facilities, String tts_name, String agency_id, Activity activity){
79+
if(agency_id.equals("-1")) {
80+
if (facilities.contains("subway")) {
81+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_metro_logo, null);
82+
} else if (facilities.contains("train")) {
83+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_train_logo, null);
84+
} else if (facilities.contains("light_rail")) {
85+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_lightrail_logo, null);
86+
} else if (facilities.contains("boat")) {
87+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_boat_logo, null);
88+
} else if (facilities.contains("hospital")) {
89+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_hospital_logo, null);
90+
} else if (doesTextContain(tts_name, "escola")) {
91+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_school_logo, null);
92+
}else{
93+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_stop_logo, null);
94+
}
95+
}else if(agency_id.equals("0")){
96+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_carris_min, null);
97+
} else if (agency_id.equals("1")) {
8298
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_train_logo, null);
83-
}else if(facilities.contains("light_rail")){
84-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_lightrail_logo, null);
85-
}else if(facilities.contains("boat")){
86-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_boat_logo, null);
87-
}else if(facilities.contains("hospital")){
88-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_hospital_logo, null);
89-
}else if(doesTextContain(tts_name, "escola")){
90-
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_school_logo, null);
91-
}else {
99+
}else if(agency_id.equals("2")){
100+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_train_logo, null);
101+
}else if(agency_id.equals("3")){
92102
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_stop_logo, null);
93103
}
104+
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.stop_stop_logo, null);
94105
}
95106

96107
public static boolean doesTextContain(String text1, String text2) {

app/src/main/java/kevin/carrismobile/api/Api.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Api {
1919
public static final String DIRECTIONURL = "https://api.carrismetropolitana.pt/patterns/";
2020
public static final String REALTIMESTOPURL = "https://api.carrismetropolitana.pt/stops/";
2121
public static final String REALTIMELISTSTOPURL = "https://api.carrismetropolitana.pt/stops";
22-
22+
public static final String SHAPELISTURL = "https://api.carrismetropolitana.pt/shapes/";
2323
public static final String BUSREALTIMESTOPURL = "https://api.carrismetropolitana.pt/vehicles";
2424

2525
public static String getJson(String url){
@@ -48,6 +48,14 @@ public static Direction getDirection(String pattern, String routeId, int directi
4848
return null;
4949
}
5050

51+
public static List<Point> getPoints(String shape_id){
52+
try{
53+
Shape shape = new Gson().fromJson(getJson(SHAPELISTURL + shape_id), Shape.class);
54+
return shape.getPoints();
55+
}catch (Exception ignore){}
56+
return null;
57+
}
58+
5159
public static Carreira getCarreira(String id){
5260
try {
5361
Gson gson = new Gson();

app/src/main/java/kevin/carrismobile/api/OfflineCP.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static List<CarreiraBasic> getCarreiraList(){
7373
String[] lastLine;
7474
String carreiraId = null;
7575
String long_name = "";
76-
String color = "0x00FF00";
76+
String color = "color_cp";
7777
List<String> patternList = new ArrayList<>();
7878
List<Direction> directionList = new ArrayList<>();
7979
try{
@@ -156,7 +156,7 @@ public static Carreira getCarreira(String id){
156156
Carreira carreira = null;
157157
String carreiraId = null;
158158
String long_name = "";
159-
String color = "0x00FF00";
159+
String color = "color_cp";
160160
List<String> patternList = new ArrayList<>();
161161
List<Direction> directionList = new ArrayList<>();
162162
try{

app/src/main/java/kevin/carrismobile/api/OfflineCarris.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static Carreira getCarreira(String id){
5656
Carreira carreira = null;
5757
String carreiraId = null;
5858
String long_name = "";
59-
String color = "0x0000FF";
59+
String color = "color_carris";
6060
List<String> patternList = new ArrayList<>();
6161
List<Direction> directionList = new ArrayList<>();
6262
try{
@@ -134,7 +134,7 @@ public static List<CarreiraBasic> getCarreiraList(){
134134
String[] lastLine;
135135
String carreiraId = null;
136136
String long_name = "";
137-
String color = "0x0000FF";
137+
String color = "color_carris";
138138
List<String> patternList = new ArrayList<>();
139139
List<Direction> directionList = new ArrayList<>();
140140
try{

app/src/main/java/kevin/carrismobile/api/OfflineFerTagus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static List<CarreiraBasic> getCarreiraList(){
7373
String[] lastLine;
7474
String carreiraId = null;
7575
String long_name = "";
76-
String color = "0x00FF00";
76+
String color = "color_fertagus";
7777
List<String> patternList = new ArrayList<>();
7878
List<Direction> directionList = new ArrayList<>();
7979
try{
@@ -156,7 +156,7 @@ public static Carreira getCarreira(String id){
156156
Carreira carreira = null;
157157
String carreiraId = null;
158158
String long_name = "";
159-
String color = "0x00FF00";
159+
String color = "color_fertagus";
160160
List<String> patternList = new ArrayList<>();
161161
List<Direction> directionList = new ArrayList<>();
162162
try{

app/src/main/java/kevin/carrismobile/api/OfflineMobiCascais.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static Carreira getCarreira(String id){
5656
Carreira carreira = null;
5757
String carreiraId = null;
5858
String long_name = "";
59-
String color = "0x000FF0";
59+
String color = "color_cascais";
6060
List<String> patternList = new ArrayList<>();
6161
List<Direction> directionList = new ArrayList<>();
6262
try{
@@ -128,7 +128,7 @@ public static List<CarreiraBasic> getCarreiraList(){
128128
String[] lastLine;
129129
String carreiraId = null;
130130
String long_name = "";
131-
String color = "0x000FF0";
131+
String color = "color_cascais";
132132
List<String> patternList = new ArrayList<>();
133133
List<Direction> directionList = new ArrayList<>();
134134
try{

app/src/main/java/kevin/carrismobile/data/Direction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Direction implements Serializable {
1212

1313
private String id;
1414
private String headsign;
15+
private String shape_id;
1516
private List<Path> path = new ArrayList<>();
1617
private List<Trip> trips = new ArrayList<>();
1718

@@ -70,6 +71,10 @@ public List<Trip> getTrips() {
7071
return trips;
7172
}
7273

74+
public String getShape_id() {
75+
return shape_id;
76+
}
77+
7378
@Override
7479
public String toString() {
7580
return headsign + " - " + id;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package kevin.carrismobile.data;
2+
3+
public class Point {
4+
5+
double shape_pt_lat;
6+
double shape_pt_lon;
7+
8+
public Point(double lat, double lon){
9+
shape_pt_lat = lat;
10+
shape_pt_lon = lon;
11+
}
12+
public double getLat() {
13+
return shape_pt_lat;
14+
}
15+
16+
public double getLon() {
17+
return shape_pt_lon;
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kevin.carrismobile.data;
2+
3+
import java.util.List;
4+
5+
public class Shape {
6+
7+
String id;
8+
List<Point> points;
9+
10+
public Shape(String id){
11+
this.id = id;
12+
}
13+
14+
public List<Point> getPoints() {
15+
return points;
16+
}
17+
}

0 commit comments

Comments
 (0)