Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
5
5711403296
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paded
5711403296
Commits
c4d7463f
Commit
c4d7463f
authored
Jan 25, 2018
by
Paded
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return bus success
parent
396711c0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
220 additions
and
78 deletions
+220
-78
CreateAccountActivity.java
...er/paded/com/ubontransitdriver/CreateAccountActivity.java
+39
-6
MainActivity.java
...ansitdriver/paded/com/ubontransitdriver/MainActivity.java
+152
-69
ProfileSettingActivity.java
...r/paded/com/ubontransitdriver/ProfileSettingActivity.java
+6
-1
TrackerService.java
...sitdriver/paded/com/ubontransitdriver/TrackerService.java
+13
-1
TrackerService3.java
...itdriver/paded/com/ubontransitdriver/TrackerService3.java
+10
-1
No files found.
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/CreateAccountActivity.java
View file @
c4d7463f
...
...
@@ -55,6 +55,8 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
BottomSheetBehavior
behavior
;
ArrayList
<
String
>
items
;
Map
<
String
,
String
>
myLine
;
String
start_busstop_id
;
String
stop_busstop_id
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -269,8 +271,9 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
}
public
void
insertData
(
String
uid
,
String
name
,
String
select_bus
){
public
void
insertData
(
final
String
uid
,
final
String
name
,
String
select_bus
){
String
busid
=
""
;
if
(
select_bus
.
equalsIgnoreCase
(
"สาย ม."
)){
busid
=
"B00"
;
}
else
if
(
select_bus
.
equalsIgnoreCase
(
"สาย 1"
)){
...
...
@@ -293,11 +296,41 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
busid
=
"B012"
;
}
FirebaseDatabase
database
=
FirebaseDatabase
.
getInstance
();
DatabaseReference
myRef
=
database
.
getReference
(
"users/"
+
uid
);
myRef
.
child
(
"name"
).
setValue
(
name
);
myRef
.
child
(
"bus_id"
).
setValue
(
busid
);
myRef
.
child
(
"status"
).
setValue
(
"on"
);
DatabaseReference
keyReference
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
busid
);
final
String
finalBusid
=
busid
;
keyReference
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
String
x
=
dataSnapshot
.
child
(
"bus_stop"
).
getValue
(
String
.
class
);
// String string = dataSnapshot.getValue(String.class);
String
[]
bus_stop
=
x
.
split
(
","
);
int
bus_stop_size
=
bus_stop
.
length
;
// String start_stop_busstop[] = new String[2];
// start_stop_busstop[0] = bus_stop[0];
// start_stop_busstop[1] = bus_stop[bus_stop_size - 1];
start_busstop_id
=
bus_stop
[
0
];
stop_busstop_id
=
bus_stop
[
bus_stop_size
-
1
];
FirebaseDatabase
database
=
FirebaseDatabase
.
getInstance
();
DatabaseReference
myRef
=
database
.
getReference
(
"users/"
+
uid
);
myRef
.
child
(
"name"
).
setValue
(
name
);
myRef
.
child
(
"bus_id"
).
setValue
(
finalBusid
);
myRef
.
child
(
"status"
).
setValue
(
"off"
);
myRef
.
child
(
"start_busstop"
).
setValue
(
start_busstop_id
);
myRef
.
child
(
"stop_busstop"
).
setValue
(
stop_busstop_id
);
}
@Override
public
void
onCancelled
(
DatabaseError
databaseError
)
{
Log
.
d
(
TAG
,
"Read failed"
);
}
});
Log
.
d
(
TAG
,
"insertData: "
+
start_busstop_id
);
Log
.
d
(
TAG
,
"insertData: "
+
stop_busstop_id
);
}
@Override
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/MainActivity.java
View file @
c4d7463f
package
ubontransitdriver
.
paded
.
com
.
ubontransitdriver
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
...
...
@@ -41,7 +42,7 @@ public class MainActivity extends AppCompatActivity {
private
ProgressBar
progressBar
;
private
Button
btn_endtrip
,
btn_endtrip_cancel
,
btn_active_bus
,
btn_return
,
btn_endtrip_yes
;
// private Boolean user_status = true;
private
TextView
txt_user_status_on
,
txt_user_status_off
,
txt_stop
,
txt_start
;
private
TextView
txt_user_status_on
,
txt_user_status_off
,
txt_stop
,
txt_start
;
BottomSheetDialog
bottomSheetDialog
;
BottomSheetBehavior
bottomSheetBehavior
;
private
FrameLayout
view_cover
;
...
...
@@ -51,10 +52,12 @@ public class MainActivity extends AppCompatActivity {
String
bus_id
;
String
user_status
;
String
user_id
;
String
start_busstop
;
String
stop_busstop
;
int
k
=
0
;
String
start_busstop_name
;
String
stop_busstop_name
;
String
start_busstop_id
;
String
stop_busstop_id
;
int
k
=
0
;
NotificationManager
mNotificationManager
;
...
...
@@ -77,8 +80,8 @@ public class MainActivity extends AppCompatActivity {
btn_active_bus
=
(
Button
)
findViewById
(
R
.
id
.
btn_active_bus
);
btn_return
=
(
Button
)
findViewById
(
R
.
id
.
btn_return
);
txt_start
=
(
TextView
)
findViewById
(
R
.
id
.
txt_start
);
txt_stop
=
(
TextView
)
findViewById
(
R
.
id
.
txt_stop
);
txt_start
=
(
TextView
)
findViewById
(
R
.
id
.
txt_start
);
txt_stop
=
(
TextView
)
findViewById
(
R
.
id
.
txt_stop
);
// view_cover = (FrameLayout) findViewById(R.id.view_cover);
...
...
@@ -100,52 +103,52 @@ public class MainActivity extends AppCompatActivity {
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
FirebaseUser
user
=
auth
.
getCurrentUser
();
Log
.
d
(
TAG
,
"onDataChange: "
+
dataSnapshot
.
child
(
"name"
).
getValue
(
String
.
class
));
Log
.
d
(
TAG
,
"onDataChange: "
+
dataSnapshot
.
child
(
"bus_id"
).
getValue
(
String
.
class
));
Log
.
d
(
TAG
,
"onDataChange: "
+
dataSnapshot
.
child
(
"status"
).
getValue
(
String
.
class
));
//
Log.d(TAG, "onDataChange: " + dataSnapshot.child("name").getValue(String.class));
//
Log.d(TAG, "onDataChange: " + dataSnapshot.child("bus_id").getValue(String.class));
//
Log.d(TAG, "onDataChange: " + dataSnapshot.child("status").getValue(String.class));
user_status
=
dataSnapshot
.
child
(
"status"
).
getValue
(
String
.
class
);
bus_id
=
dataSnapshot
.
child
(
"bus_id"
).
getValue
(
String
.
class
);
user_id
=
user
.
getUid
();
DatabaseReference
keyReference
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
bus_id
+
"/bus_stop"
);
keyReference
.
addValueEventListener
(
new
ValueEventListener
()
{
start_busstop_id
=
dataSnapshot
.
child
(
"start_busstop"
).
getValue
(
String
.
class
);
stop_busstop_id
=
dataSnapshot
.
child
(
"stop_busstop"
).
getValue
(
String
.
class
);
DatabaseReference
keyReference_start
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"all_busstop/"
+
start_busstop_id
);
keyReference_start
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
String
string
=
dataSnapshot
.
getValue
(
String
.
class
);
String
[]
bus_stop
=
string
.
split
(
","
);
int
bus_stop_size
=
bus_stop
.
length
;
String
start_stop_busstop
[]
=
new
String
[
2
];
start_stop_busstop
[
0
]
=
bus_stop
[
0
];
start_stop_busstop
[
1
]
=
bus_stop
[
bus_stop_size
-
1
];
for
(
int
i
=
0
;
i
<
start_stop_busstop
.
length
;
i
++)
{
k
=
0
;
DatabaseReference
keyReference
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"all_busstop/"
+
start_stop_busstop
[
i
]);
keyReference
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
Log
.
d
(
TAG
,
"onDataChange: "
+
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
));
if
(
k
==
0
)
{
start_busstop
=
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
);
txt_start
.
setText
(
start_busstop
);
// updateCARD(start_busstop);
}
else
{
stop_busstop
=
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
);
txt_stop
.
setText
(
stop_busstop
);
progressBar
.
setVisibility
(
View
.
GONE
);
}
k
+=
1
;
}
@Override
public
void
onCancelled
(
DatabaseError
databaseError
)
{
Log
.
d
(
TAG
,
"Read failed"
);
}
});
}
start_busstop_name
=
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
);
txt_start
.
setText
(
start_busstop_name
);
}
@Override
public
void
onCancelled
(
DatabaseError
databaseError
)
{
Log
.
d
(
TAG
,
"Read failed"
);
}
});
DatabaseReference
keyReference_stop
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"all_busstop/"
+
stop_busstop_id
);
keyReference_stop
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
stop_busstop_name
=
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
);
txt_stop
.
setText
(
stop_busstop_name
);
if
(
user_status
.
equalsIgnoreCase
(
"on"
))
{
buildNotification
();
trackBus
(
user_id
,
bus_id
);
}
// if(user_status.equalsIgnoreCase("on")){
// Log.d("dddd", "onDataChange: "+stop_busstop_id);
// FirebaseDatabase database = FirebaseDatabase.getInstance();
// DatabaseReference myRef2 = database.getReference("active_bus/"+bus_id+"/"+user_id);
// myRef2.child("s").setValue("s");
// myRef2.child("destination").setValue(stop_busstop_id);
// }
progressBar
.
setVisibility
(
View
.
GONE
);
}
@Override
...
...
@@ -154,14 +157,73 @@ public class MainActivity extends AppCompatActivity {
}
});
// DatabaseReference keyReference = FirebaseDatabase.getInstance().getReference().child("allbus/" + bus_id + "/bus_stop");
// keyReference.addValueEventListener(new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// String string = dataSnapshot.getValue(String.class);
// String[] bus_stop = string.split(",");
// int bus_stop_size = bus_stop.length;
// String start_stop_busstop[] = new String[2];
// start_stop_busstop[0] = bus_stop[0];
// start_stop_busstop[1] = bus_stop[bus_stop_size - 1];
//
// for(int i=0; i<start_stop_busstop.length; i++) {
// k=0;
// DatabaseReference keyReference = FirebaseDatabase.getInstance().getReference().child("all_busstop/" + start_stop_busstop[i]);
// keyReference.addValueEventListener(new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
//
// if((txt_stop.getText()+"").equalsIgnoreCase(dataSnapshot.child("nameEN").getValue(String.class))){
// if (k == 0) {
// stop_busstop = dataSnapshot.child("nameEN").getValue(String.class);
// txt_start.setText(stop_busstop);
//// updateCARD(start_busstop);
// }else{
// start_busstop = dataSnapshot.child("nameEN").getValue(String.class);
// txt_stop.setText(start_busstop);
// progressBar.setVisibility(View.GONE);
// }
// k+=1;
// Log.d("equu", "onDataChange: INDIDE TEXT NOT SAME ");
// }else{
// if (k == 0) {
// start_busstop = dataSnapshot.child("nameEN").getValue(String.class);
// txt_start.setText(start_busstop);
//// updateCARD(start_busstop);
// }else{
// stop_busstop = dataSnapshot.child("nameEN").getValue(String.class);
// txt_stop.setText(stop_busstop);
// progressBar.setVisibility(View.GONE);
// }
// k+=1;
// }
//// Log.d(TAG, "onDataChange: INSIDE"+dataSnapshot.child("nameEN").getValue(String.class));
//
// }
//
// @Override
// public void onCancelled(DatabaseError databaseError) {
// Log.d(TAG, "Read failed");
// }
// });
// }
//
//
//
// }
//
// @Override
// public void onCancelled(DatabaseError databaseError) {
// Log.d(TAG, "Read failed");
// }
// });
updateUI
(
user_status
);
if
(
user_status
.
equalsIgnoreCase
(
"on"
))
{
buildNotification
();
trackBus
(
user_id
,
bus_id
);
}
}
@Override
...
...
@@ -171,13 +233,11 @@ public class MainActivity extends AppCompatActivity {
});
btn_profile
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
MainActivity
.
this
,
ProfileSettingActivity
.
class
);
startActivity
(
intent
);
startActivity
ForResult
(
intent
,
1
);
}
});
...
...
@@ -232,18 +292,31 @@ public class MainActivity extends AppCompatActivity {
btn_return
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
if
(
user_status
.
equalsIgnoreCase
(
"on"
)){
start_busstop
=
txt_start
.
getText
()+
""
;
stop_busstop
=
txt_stop
.
getText
()+
""
;
txt_start
.
setText
(
stop_busstop
);
txt_stop
.
setText
(
start_busstop
);
}
else
{
start_busstop
=
txt_start
.
getText
()+
""
;
stop_busstop
=
txt_stop
.
getText
()+
""
;
txt_start
.
setText
(
stop_busstop
);
txt_stop
.
setText
(
start_busstop
);
}
Log
.
d
(
TAG
,
"onClick: RETURN"
+
user_status
+
" start"
+
start_busstop
+
" stop:"
+
stop_busstop
);
FirebaseDatabase
database
=
FirebaseDatabase
.
getInstance
();
DatabaseReference
myRef
=
database
.
getReference
(
"users/"
+
user_id
);
myRef
.
child
(
"start_busstop"
).
setValue
(
stop_busstop_id
);
myRef
.
child
(
"stop_busstop"
).
setValue
(
start_busstop_id
);
// if(user_status.equalsIgnoreCase("on")){
// FirebaseDatabase database = FirebaseDatabase.getInstance();
// DatabaseReference myRef = database.getReference("active_bus/"+bus_id+"/"+user_id);
// myRef.child("destination").setValue(stop_busstop_name);
// }
// progressBar.setVisibility(View.GONE);
// if (user_status.equalsIgnoreCase("on")) {
// start_busstop = txt_start.getText() + "";
// stop_busstop = txt_stop.getText() + "";
// txt_start.setText(stop_busstop);
// txt_stop.setText(start_busstop);
// } else {
// start_busstop = txt_start.getText() + "";
// stop_busstop = txt_stop.getText() + "";
// txt_start.setText(stop_busstop);
// txt_stop.setText(start_busstop);
// }
// Log.d(TAG, "onClick: RETURN" + user_status + " start" + start_busstop + " stop:" + stop_busstop);
}
});
...
...
@@ -272,10 +345,23 @@ public class MainActivity extends AppCompatActivity {
progressBar
.
setVisibility
(
View
.
GONE
);
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
requestCode
==
1
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
){
boolean
result
=
data
.
getBooleanExtra
(
"logout"
,
false
);
if
(
result
){
startActivity
(
new
Intent
(
MainActivity
.
this
,
LoginActivity
.
class
));
finish
();
}
}
if
(
resultCode
==
Activity
.
RESULT_CANCELED
)
{
//Write your code if there's no result
}
}
}
public
void
updateUI
(
String
user_status
)
{
// txt_start.setText(start_busstop);
// txt_stop.setText(stop_busstop);
if
(
user_status
.
equalsIgnoreCase
(
"off"
))
{
btn_active_bus
.
setVisibility
(
View
.
VISIBLE
);
txt_user_status_off
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -322,11 +408,8 @@ public class MainActivity extends AppCompatActivity {
}
private
void
startTrackerService
(
String
user_id
,
String
bus_id
)
{
// txt_start.setText(stop_busstop);
// txt_stop.setText(start_busstop);
String
destination
=
txt_stop
.
getText
()+
""
;
Log
.
d
(
TAG
,
"startTrackerService: "
+
start_busstop
+
" "
+
stop_busstop
);
Log
.
d
(
"dddd"
,
"startTrackerService: "
+
stop_busstop_name
);
String
destination
=
stop_busstop_name
;
Intent
intent
=
new
Intent
(
this
,
TrackerService3
.
class
);
intent
.
putExtra
(
"user_id"
,
user_id
);
intent
.
putExtra
(
"bus_id"
,
bus_id
);
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/ProfileSettingActivity.java
View file @
c4d7463f
package
ubontransitdriver
.
paded
.
com
.
ubontransitdriver
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.support.annotation.NonNull
;
import
android.support.v7.app.AppCompatActivity
;
...
...
@@ -44,8 +45,12 @@ public class ProfileSettingActivity extends AppCompatActivity {
progressBar
.
setVisibility
(
View
.
GONE
);
// user auth state is changed - user is null
// launch login activity
startActivity
(
new
Intent
(
ProfileSettingActivity
.
this
,
LoginActivity
.
class
));
Intent
returnIntent
=
new
Intent
();
returnIntent
.
putExtra
(
"logout"
,
true
);
setResult
(
Activity
.
RESULT_OK
,
returnIntent
);
finish
();
// startActivity(new Intent(ProfileSettingActivity.this, LoginActivity.class));
// finish();
}
}
};
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService.java
View file @
c4d7463f
...
...
@@ -28,6 +28,12 @@ import com.google.android.gms.location.LocationServices;
import
com.google.firebase.database.DatabaseReference
;
import
com.google.firebase.database.FirebaseDatabase
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.TimeZone
;
public
class
TrackerService
extends
Service
{
private
static
final
String
TAG
=
"GPS2"
;
private
boolean
isRunning
=
false
;
...
...
@@ -144,7 +150,13 @@ public class TrackerService extends Service {
Log
.
d
(
TAG
,
"location update "
+
location
);
ref
.
child
(
"latitude"
).
setValue
(
location
.
getLatitude
());
ref
.
child
(
"longitude"
).
setValue
(
location
.
getLongitude
());
ref
.
child
(
"time"
).
setValue
(
location
.
getTime
());
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
formattedDate
=
df
.
format
(
c
.
getTime
());
Log
.
d
(
"dddd"
,
"onLocationResult: "
+
formattedDate
);
ref
.
child
(
"time"
).
setValue
(
formattedDate
);
}
}
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService3.java
View file @
c4d7463f
...
...
@@ -23,6 +23,7 @@ import com.google.android.gms.location.LocationServices;
import
com.google.firebase.database.DatabaseReference
;
import
com.google.firebase.database.FirebaseDatabase
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
...
...
@@ -44,6 +45,7 @@ public class TrackerService3 extends Service implements
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Log
.
d
(
"dddd"
,
"onStartCommand: "
);
user_id
=
intent
.
getStringExtra
(
"user_id"
);
bus_id
=
intent
.
getStringExtra
(
"bus_id"
);
destination
=
intent
.
getStringExtra
(
"destination"
);
...
...
@@ -96,7 +98,14 @@ public class TrackerService3 extends Service implements
DatabaseReference
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
path
);
ref
.
child
(
"latitude"
).
setValue
(
location
.
getLatitude
());
ref
.
child
(
"longitude"
).
setValue
(
location
.
getLongitude
());
ref
.
child
(
"time"
).
setValue
(
location
.
getTime
());
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
formattedDate
=
df
.
format
(
c
.
getTime
());
Log
.
d
(
"dddd"
,
"onLocationResult: "
+
formattedDate
);
ref
.
child
(
"time"
).
setValue
(
formattedDate
);
ref
.
child
(
"destination"
).
setValue
(
destination
);
// Date currentTime = Calendar.getInstance().getTime();
// Log.d(TAG, "Location: " + location.getLatitude() + " " + location.getLongitude()+" "+location.getTime()+" "+currentTime);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment