Skip to content

Commit a625ae9

Browse files
committed
BusDroid RJ - Versão 1.1 - Verifique o CHANGELOG.txt para maiores informações!
1 parent f525277 commit a625ae9

File tree

11 files changed

+271
-25
lines changed

11 files changed

+271
-25
lines changed

CHANGELOG.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BusDroid RJ
2+
===========
3+
4+
Um simples aplicativo que permite localizar as linhas de ônibus no município do Rio de Janeiro!
5+
-----------------------------------------------------------------------------------------------
6+
7+
CHANGELOG:
8+
==========
9+
10+
VERSÃO 1.1:
11+
- Alterado layout da janela de informações do marcador, permitindo adicionar mais informações futuramente.
12+
- Adicionado trajeto das linhas de ônibus na janela de informações do marcador.
13+
- Adicionada novas informações sobre o aplicativo no menu "Sobre".
14+
- Pequenas alterações de layout e bugfixes.
15+
16+
#-------------------------------------------------------------------------------------------------------------------
17+
18+
VERSÃO 1.0:
19+
- Versão inicial do aplicativo.
20+
21+
#-------------------------------------------------------------------------------------------------------------------

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdkVersion 14
1313
targetSdkVersion 25
1414
versionCode 1
15-
versionName "1.0"
15+
versionName "1.1"
1616
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1717
}
1818
buildTypes {
@@ -33,5 +33,6 @@ dependencies {
3333
compile 'com.android.support:appcompat-v7:25.3.1'
3434
compile 'com.android.support.constraint:constraint-layout:1.0.2'
3535
compile 'com.google.android.gms:play-services-maps:10.2.6'
36+
compile 'com.opencsv:opencsv:3.10'
3637
testCompile 'junit:junit:4.12'
3738
}

app/src/main/java/io/github/wolfterro/busdroidrj/GetBusLineThread.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ public void handleMessage(Message msg) {
179179
bLine);
180180

181181
intent.putExtra("BUSLINE", markerTitle);
182+
183+
GetCSV csv = new GetCSV(c, bLine);
184+
csv.start();
185+
186+
try {
187+
csv.join();
188+
intent.putExtra("ROUTE", csv.getRoute());
189+
}
190+
catch (InterruptedException e) {
191+
e.printStackTrace();
192+
intent.putExtra("ROUTE", c.getString(R.string.notAvailable));
193+
}
194+
182195
c.startActivity(intent);
183196
}
184197
else {

app/src/main/java/io/github/wolfterro/busdroidrj/GetBusOrderThread.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ public void handleMessage(Message msg) {
173173
bLine);
174174

175175
intent.putExtra("BUSLINE", markerTitle);
176+
177+
GetCSV csv = new GetCSV(c, bLine);
178+
csv.start();
179+
180+
try {
181+
csv.join();
182+
intent.putExtra("ROUTE", csv.getRoute());
183+
}
184+
catch (InterruptedException e) {
185+
e.printStackTrace();
186+
intent.putExtra("ROUTE", c.getString(R.string.notAvailable));
187+
}
188+
176189
c.startActivity(intent);
177190
}
178191
else {
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2017 Wolfgang Almeida
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package io.github.wolfterro.busdroidrj;
26+
27+
import android.content.Context;
28+
29+
import java.net.*;
30+
import java.io.*;
31+
32+
import com.opencsv.CSVReader;
33+
34+
public class GetCSV extends Thread {
35+
36+
// Propriedades privadas
37+
// =====================
38+
private Context c = null;
39+
40+
private String busLine = "";
41+
private String route = "";
42+
43+
// Construtor da classe
44+
// ====================
45+
public GetCSV(Context c, String busLine) {
46+
this.c = c;
47+
48+
this.busLine = busLine;
49+
}
50+
51+
// Métodos privados da classe
52+
// ==========================
53+
54+
// Iniciando resgate de valores sobre a linha de ônibus escolhida
55+
// ==============================================================
56+
@Override
57+
public void run() {
58+
try {
59+
// Retirando as letras da linha atual do ônibus
60+
// --------------------------------------------
61+
String busLineNoLetters = busLine.replaceAll("[^\\d]", "");
62+
63+
URL u = new URL(String.format(GlobalVars.busRouteAPI, busLineNoLetters));
64+
BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
65+
66+
CSVReader reader = new CSVReader(in);
67+
68+
// Adicionando zeros para a busca de linhas com menos de 3 números
69+
// ---------------------------------------------------------------
70+
if(busLineNoLetters.length() == 1) {
71+
busLineNoLetters = String.format("00%s", busLineNoLetters);
72+
}
73+
else if(busLineNoLetters.length() == 2) {
74+
busLineNoLetters = String.format("0%s", busLineNoLetters);
75+
}
76+
77+
String[] nextLine;
78+
while ((nextLine = reader.readNext()) != null) {
79+
80+
// Imprime o trajeto da linha de ônibus, sem a linha atual do ônibus ao lado
81+
// -------------------------------------------------------------------------
82+
if(nextLine[1].startsWith(busLineNoLetters)) {
83+
route = nextLine[1].replace(busLineNoLetters + "-", "");
84+
break;
85+
}
86+
else {
87+
route = c.getString(R.string.notAvailable);
88+
continue;
89+
}
90+
}
91+
92+
reader.close();
93+
}
94+
catch(MalformedURLException e) {
95+
e.printStackTrace();
96+
route = c.getString(R.string.notAvailable);
97+
}
98+
catch(IOException e) {
99+
e.printStackTrace();
100+
route = c.getString(R.string.notAvailable);
101+
}
102+
}
103+
104+
// Métodos públicos da classe
105+
// ==========================
106+
107+
// Resgatando o trajeto da linha de ônibus
108+
// =======================================
109+
public String getRoute() {
110+
return route;
111+
}
112+
}

app/src/main/java/io/github/wolfterro/busdroidrj/GlobalVars.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ of this software and associated documentation files (the "Software"), to deal
3030

3131
public class GlobalVars {
3232
public static String busAPI = "http://dadosabertos.rio.rj.gov.br/apiTransporte/apresentacao/rest/index.cfm/obterTodasPosicoes.json";
33+
public static String busRouteAPI = "http://dadosabertos.rio.rj.gov.br/apiTransporte/Apresentacao/csv/gtfs/onibus/percursos/gtfs_linha%s-shapes.csv";
3334
}

app/src/main/java/io/github/wolfterro/busdroidrj/MapsActivity.java

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,31 @@ of this software and associated documentation files (the "Software"), to deal
3030
import android.support.v4.app.FragmentActivity;
3131
import android.os.Bundle;
3232
import android.support.v4.content.ContextCompat;
33+
import android.view.View;
34+
import android.widget.TextView;
3335

3436
import com.google.android.gms.maps.CameraUpdateFactory;
3537
import com.google.android.gms.maps.GoogleMap;
3638
import com.google.android.gms.maps.OnMapReadyCallback;
3739
import com.google.android.gms.maps.SupportMapFragment;
3840
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
3941
import com.google.android.gms.maps.model.LatLng;
42+
import com.google.android.gms.maps.model.Marker;
4043
import com.google.android.gms.maps.model.MarkerOptions;
4144

4245
import java.util.ArrayList;
4346
import java.util.Random;
4447

4548
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
4649

50+
// Propriedades da Activity
51+
// ========================
4752
private GoogleMap mMap;
53+
4854
private String busLine = "";
4955
private ArrayList<String> results = new ArrayList<String>();
5056
private LatLng busOrderLocation = null;
57+
private String route = "";
5158

5259
@Override
5360
protected void onCreate(Bundle savedInstanceState) {
@@ -57,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
5764
Intent i = getIntent();
5865
busLine = i.getStringExtra("BUSLINE");
5966
results = i.getStringArrayListExtra("RESULTS");
67+
route = i.getStringExtra("ROUTE");
6068

6169
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
6270
.findFragmentById(R.id.map);
@@ -74,33 +82,59 @@ public void onMapReady(GoogleMap googleMap) {
7482
mMap.setMyLocationEnabled(true);
7583
}
7684

77-
// Adicionando marcadores no mapa
78-
// ------------------------------
85+
// Adicionando marcadores customizados no mapa
86+
// -------------------------------------------
7987
for(int x = 0; x < results.size(); x++) {
8088
Random random = new Random(); // So much random...
8189

8290
String[] info = results.get(x).split(" -//- ");
8391
String ll = info[0];
8492
String order = info[1];
85-
String hora = info[2];
86-
String velocidade = info[3];
93+
String lastUpdate = info[2];
94+
String speed = info[3];
8795

8896
double lat = Double.parseDouble(ll.split(",")[0]);
8997
double lng = Double.parseDouble(ll.split(",")[1]);
9098

9199
LatLng loc = new LatLng(lat, lng);
92100

93101
int selectedColor = random.nextInt(360);
94-
mMap.addMarker(new MarkerOptions()
95-
.position(loc)
96-
.title(String.format("%s - %s", busLine, order))
97-
.snippet(String.format("%s: %s - %s: %s %s",
98-
getString(R.string.hour),
99-
hora,
100-
getString(R.string.velocity),
101-
velocidade,
102-
getString(R.string.kmh)))
103-
.icon(BitmapDescriptorFactory.defaultMarker(selectedColor)));
102+
103+
MarkerOptions options = new MarkerOptions();
104+
options.position(loc);
105+
options.title(String.format("%s - %s", busLine, order));
106+
options.snippet(String.format("%s: %s\n%s: %s\n%s: %s %s",
107+
getString(R.string.route),
108+
route,
109+
getString(R.string.lastUpdate),
110+
lastUpdate,
111+
getString(R.string.speed),
112+
speed,
113+
getString(R.string.kmh)));
114+
options.icon(BitmapDescriptorFactory.defaultMarker(selectedColor));
115+
116+
Marker marker = mMap.addMarker(options);
117+
118+
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
119+
@Override
120+
public View getInfoWindow(Marker marker) {
121+
return null;
122+
}
123+
124+
@Override
125+
public View getInfoContents(Marker marker) {
126+
View contentView = getLayoutInflater()
127+
.inflate(R.layout.custom_markerinfo, null);
128+
129+
TextView tvTitle = (TextView)contentView.findViewById(R.id.titleInfoWindow);
130+
TextView tvSnippet = (TextView)contentView.findViewById(R.id.snippetInfoWindow);
131+
132+
tvTitle.setText(marker.getTitle());
133+
tvSnippet.setText(marker.getSnippet());
134+
135+
return contentView;
136+
}
137+
});
104138

105139
busOrderLocation = loc;
106140
}

app/src/main/res/layout/activity_about.xml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
android:layout_height="wrap_content"
3333
android:adjustViewBounds="true"
3434
android:cropToPadding="false"
35-
android:maxWidth="200dp"
36-
android:maxHeight="200dp"
35+
android:maxWidth="180dp"
36+
android:maxHeight="180dp"
3737
android:scaleType="fitCenter"
38-
app:srcCompat="@drawable/busdroidrj_icon" />
38+
app:srcCompat="@drawable/busdroidrj_icon"
39+
android:contentDescription="@string/app_name" />
3940

4041
<TextView
4142
android:id="@+id/textViewAppName"
@@ -78,7 +79,16 @@
7879
android:layout_marginBottom="20dp"
7980
android:text="@string/aboutText"
8081
android:textColor="@android:color/white"
81-
android:textSize="16dp" />
82+
android:textSize="16sp" />
83+
84+
<TextView
85+
android:id="@+id/textViewAbout2"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"
88+
android:layout_marginBottom="20dp"
89+
android:text="@string/aboutText2"
90+
android:textColor="@android:color/white"
91+
android:textSize="16sp" />
8292

8393
<TextView
8494
android:id="@+id/textViewLicense"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:gravity="center_vertical|center_horizontal"
7+
android:layout_gravity="center_vertical|center_horizontal">
8+
9+
<TextView
10+
android:id="@+id/titleInfoWindow"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:padding="5dp"
14+
android:textColor="@android:color/black"
15+
android:textSize="16sp"
16+
android:textStyle="bold"
17+
android:text="Título da InfoWindow" />
18+
19+
<View
20+
android:layout_width="match_parent"
21+
android:layout_height="1dp"
22+
android:layout_marginBottom="5dp"
23+
android:layout_marginTop="5dp"
24+
android:background="@android:color/darker_gray" />
25+
26+
<TextView
27+
android:id="@+id/snippetInfoWindow"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:padding="5dp"
31+
android:textColor="@android:color/black"
32+
android:textSize="14sp"
33+
android:text="Snippet da InfoWindow" />
34+
35+
</LinearLayout>

0 commit comments

Comments
 (0)