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
a18edafa
Commit
a18edafa
authored
Mar 08, 2018
by
Paded
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first commit
parent
17eedad4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
311 additions
and
16 deletions
+311
-16
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
build.gradle
app/build.gradle
+2
-1
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+12
-0
Constants.java
...river/paded/com/ubontransitdriver/GEOFENCE/Constants.java
+32
-0
GeofenceRegistrationService.java
...ontransitdriver/GEOFENCE/GeofenceRegistrationService.java
+133
-0
MainActivity.java
...ansitdriver/paded/com/ubontransitdriver/MainActivity.java
+81
-15
TrackerService3.java
...itdriver/paded/com/ubontransitdriver/TrackerService3.java
+0
-0
styles.xml
app/src/main/res/values-v23/styles.xml
+14
-0
strings.xml
app/src/main/res/values/strings.xml
+37
-0
No files found.
.idea/caches/build_file_checksums.ser
View file @
a18edafa
No preview for this file type
app/build.gradle
View file @
a18edafa
...
...
@@ -19,7 +19,7 @@ android {
}
dependencies
{
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
]
)
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
'com.android.support:appcompat-v7:26.1.0'
implementation
'com.android.support:cardview-v7:26.1.0'
compile
'com.android.support:design:26.1.0'
...
...
@@ -27,6 +27,7 @@ dependencies {
implementation
'com.google.firebase:firebase-auth:11.6.0'
implementation
'com.google.firebase:firebase-database:11.6.0'
implementation
'com.google.android.gms:play-services-location:11.6.0'
implementation
'com.google.android.gms:play-services-maps:11.6.0'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.1'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.1'
...
...
app/src/main/AndroidManifest.xml
View file @
a18edafa
...
...
@@ -5,6 +5,7 @@
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<application
android:allowBackup=
"true"
...
...
@@ -13,6 +14,11 @@
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
<meta-data
android:name=
"com.google.android.gms.version"
android:value=
"@integer/google_play_services_version"
/>
<activity
android:launchMode=
"singleTop"
android:name=
".MainActivity"
...
...
@@ -39,6 +45,11 @@
android:name=
".TrackerService3"
android:enabled=
"true"
android:exported=
"true"
></service>
<service
android:name=
".GEOFENCE.GeofenceRegistrationService"
android:enabled=
"true"
android:exported=
"true"
></service>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/GEOFENCE/Constants.java
0 → 100644
View file @
a18edafa
package
ubontransitdriver
.
paded
.
com
.
ubontransitdriver
.
GEOFENCE
;
import
com.google.android.gms.maps.model.LatLng
;
import
java.util.HashMap
;
/**
* Created by brijesh on 15/4/17.
*/
public
class
Constants
{
public
static
final
String
GEOFENCE_ID_STAN_UNI
=
"STAN_UNI"
;
public
static
final
String
GEOFENCE_ID_UBU
=
"BS00"
;
public
static
final
float
GEOFENCE_RADIUS_IN_METERS
=
100
;
/**
* Map for storing information about stanford university in the Stanford.
*/
public
static
final
HashMap
<
String
,
LatLng
>
AREA_LANDMARKS
=
new
HashMap
<
String
,
LatLng
>();
static
{
// stanford university.
AREA_LANDMARKS
.
put
(
GEOFENCE_ID_STAN_UNI
,
new
LatLng
(
37.427476
,
-
122.170262
));
// San Francisco International Airport.
AREA_LANDMARKS
.
put
(
GEOFENCE_ID_UBU
,
new
LatLng
(
15.122239
,
104.906372
));
}
}
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/GEOFENCE/GeofenceRegistrationService.java
0 → 100644
View file @
a18edafa
package
ubontransitdriver
.
paded
.
com
.
ubontransitdriver
.
GEOFENCE
;
import
android.app.IntentService
;
import
android.content.Intent
;
import
android.support.annotation.Nullable
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.google.android.gms.location.Geofence
;
import
com.google.android.gms.location.GeofencingEvent
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
import
com.google.firebase.database.DatabaseReference
;
import
com.google.firebase.database.FirebaseDatabase
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
public
class
GeofenceRegistrationService
extends
IntentService
{
private
static
final
String
TAG
=
"GeoIntentService"
;
private
FirebaseAuth
auth
;
private
int
bus_stop_size
;
private
String
[]
bus_stop_list
;
private
HashMap
<
String
,
Integer
>
AREA_LANDMARKS
;
public
GeofenceRegistrationService
()
{
super
(
TAG
);
}
@Override
public
int
onStartCommand
(
@Nullable
Intent
intent
,
int
flags
,
int
startId
)
{
bus_stop_size
=
intent
.
getIntExtra
(
"bus_stop_size"
,
0
);
bus_stop_list
=
intent
.
getStringArrayExtra
(
"bus_stop_list"
);
AREA_LANDMARKS
=
new
HashMap
<
String
,
Integer
>();
Log
.
d
(
TAG
,
"onStartCommand: "
+
bus_stop_size
);
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
@Override
protected
void
onHandleIntent
(
@Nullable
Intent
intent
)
{
auth
=
FirebaseAuth
.
getInstance
();
GeofencingEvent
geofencingEvent
=
GeofencingEvent
.
fromIntent
(
intent
);
Log
.
d
(
TAG
,
"onHandleIntent: "
+
geofencingEvent
.
getTriggeringLocation
());
if
(
geofencingEvent
.
hasError
())
{
Log
.
d
(
TAG
,
"GeofencingEvent error "
+
geofencingEvent
.
getErrorCode
());
}
else
{
int
transaction
=
geofencingEvent
.
getGeofenceTransition
();
List
<
Geofence
>
geofences
=
geofencingEvent
.
getTriggeringGeofences
();
// Get the transition details as a String.
String
geofenceTransitionDetails
=
getGeofenceTransitionDetails
(
transaction
,
geofences
);
Log
.
d
(
TAG
,
"onHandleIntent: "
+
geofenceTransitionDetails
);
// Log.d(TAG, "onHandleIntent: "+geofences.size());
// Geofence geofence = geofences.get(0);
// if (transaction == Geofence.GEOFENCE_TRANSITION_ENTER && geofence.getRequestId().equals(Constants.GEOFENCE_ID_UBU)) {
// Log.d(TAG, "You are inside Stanford University");
// } else {
// Log.d(TAG, "You are outside Stanford University");
// }
}
}
private
String
getGeofenceTransitionDetails
(
int
geofenceTransition
,
List
<
Geofence
>
triggeringGeofences
)
{
String
geofenceTransitionString
=
getTransitionString
(
geofenceTransition
);
Log
.
d
(
TAG
,
"getGeofenceTransitionTYPE "
+
geofenceTransition
);
// Get the Ids of each geofence that was triggered.
ArrayList
<
String
>
triggeringGeofencesIdsList
=
new
ArrayList
<>();
for
(
Geofence
geofence
:
triggeringGeofences
)
{
AREA_LANDMARKS
.
put
(
geofence
.
getRequestId
(),
geofenceTransition
);
triggeringGeofencesIdsList
.
add
(
geofence
.
getRequestId
());
}
String
triggeringGeofencesIdsString
=
TextUtils
.
join
(
", "
,
triggeringGeofencesIdsList
);
changeBusstopStatus
();
return
geofenceTransitionString
+
": "
+
triggeringGeofencesIdsString
;
}
private
String
getTransitionString
(
int
transitionType
)
{
switch
(
transitionType
)
{
case
Geofence
.
GEOFENCE_TRANSITION_ENTER
:
return
"Entered"
;
case
Geofence
.
GEOFENCE_TRANSITION_EXIT
:
return
"Exited"
;
default
:
return
"Unknown Transition"
;
}
}
private
void
changeBusstopStatus
(){
Log
.
d
(
TAG
,
"changeBusstopStatus: "
+
AREA_LANDMARKS
);
FirebaseUser
user
=
auth
.
getCurrentUser
();
for
(
int
i
=
0
;
i
<
bus_stop_size
;
i
++){
final
String
path
=
"active_bus/"
+
user
.
getUid
()+
"/busstop/"
+
i
+
"/"
+
bus_stop_list
[
i
];
DatabaseReference
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
path
);
if
(
AREA_LANDMARKS
.
containsKey
(
bus_stop_list
[
i
])&&
AREA_LANDMARKS
.
get
(
bus_stop_list
[
i
])==
1
){
Log
.
d
(
TAG
,
"changeBusstopStatus: CONTAIN IN"
);
ref
.
child
(
"on_busstop_status"
).
setValue
(
true
);
}
else
if
(
AREA_LANDMARKS
.
containsKey
(
bus_stop_list
[
i
])&&
AREA_LANDMARKS
.
get
(
bus_stop_list
[
i
])==
2
){
Log
.
d
(
TAG
,
"changeBusstopStatus: CONTAIN OUT"
);
ref
.
child
(
"on_busstop_status"
).
setValue
(
false
);
ref
.
child
(
"path_status"
).
setValue
(
true
);
}
else
{
}
// Log.d(TAG, "changeBusstopStatus: "+AREA_LANDMARKS.get(bus_stop_list[i]));
//
// if(AREA_LANDMARKS.containsKey(bus_stop_list[i])&&AREA_LANDMARKS.get(bus_stop_list[i])==1){
// Log.d(TAG, "changeBusstopStatus: "+bus_stop_list[i]+" TYPE"+AREA_LANDMARKS.get(bus_stop_list[i]));
// ref.child("status").setValue(true);
// }else {
// ref.child("status").setValue(false);
// }
}
}
}
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/MainActivity.java
View file @
a18edafa
...
...
@@ -44,6 +44,7 @@ import com.google.android.gms.location.LocationSettingsResult;
import
com.google.android.gms.location.LocationSettingsStatusCodes
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
import
com.google.firebase.database.ChildEventListener
;
import
com.google.firebase.database.DataSnapshot
;
import
com.google.firebase.database.DatabaseError
;
import
com.google.firebase.database.DatabaseReference
;
...
...
@@ -76,29 +77,30 @@ public class MainActivity extends AppCompatActivity implements LocationListener
String
user_id
;
String
start_busstop_name
;
String
stop_busstop_name
;
String
allbusStop
;
String
start_busstop_id
;
String
stop_busstop_id
;
int
k
=
0
;
public
static
Context
currentContext
;
NotificationManager
mNotificationManager
;
private
ValueEventListener
eventListener1
;
private
DatabaseReference
database
;
DatabaseReference
ref1
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
main_layout
);
MainActivity
.
currentContext
=
this
;
database
=
FirebaseDatabase
.
getInstance
().
getReference
();
lm
=
(
LocationManager
)
getSystemService
(
Context
.
LOCATION_SERVICE
);
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
&&
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return
;
}
lm
.
requestLocationUpdates
(
LocationManager
.
GPS_PROVIDER
,
1000
,
10
,
this
);
...
...
@@ -148,7 +150,7 @@ public class MainActivity extends AppCompatActivity implements LocationListener
bottomSheetBehavior
=
BottomSheetBehavior
.
from
((
View
)
bottomSheetView
.
getParent
());
btn_endtrip_cancel
=
(
Button
)
bottomSheetView
.
findViewById
(
R
.
id
.
btn_endtrip_cancel
);
btn_endtrip_yes
=
(
Button
)
bottomSheetView
.
findViewById
(
R
.
id
.
btn_endtrip_yes
);
DatabaseReference
database
=
FirebaseDatabase
.
getInstance
().
getReference
();
// Attach a listener to read the data at our posts reference
database
.
child
(
"users/"
+
user
.
getUid
()).
addValueEventListener
(
new
ValueEventListener
()
{
@Override
...
...
@@ -179,6 +181,23 @@ public class MainActivity extends AppCompatActivity implements LocationListener
}
});
DatabaseReference
keyReference1
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
bus_id
+
"/direction/"
+
start_busstop_id
);
keyReference1
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
allbusStop
=
dataSnapshot
.
getValue
(
String
.
class
);
if
(
user_status
.
equalsIgnoreCase
(
"on"
))
{
startTrackerService
(
user_id
,
bus_id
);
}
Log
.
d
(
TAG
,
"onDataChange: "
+
allbusStop
);
Log
.
d
(
TAG
,
"onDataChange: USER Start bus"
+
start_busstop_id
);
}
@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
...
...
@@ -208,6 +227,8 @@ public class MainActivity extends AppCompatActivity implements LocationListener
}
});
// DatabaseReference keyReference = FirebaseDatabase.getInstance().getReference().child("allbus/" + bus_id + "/bus_stop");
// keyReference.addValueEventListener(new ValueEventListener() {
// @Override
...
...
@@ -311,7 +332,7 @@ public class MainActivity extends AppCompatActivity implements LocationListener
if
(
bus_id
!=
null
)
{
Intent
intent
=
new
Intent
(
MainActivity
.
this
,
TrackerService3
.
class
);
FirebaseDatabase
database
=
FirebaseDatabase
.
getInstance
();
DatabaseReference
myRef
=
database
.
getReference
(
"active_bus
/"
+
bus_id
);
DatabaseReference
myRef
=
database
.
getReference
(
"active_bus
"
);
myRef
.
child
(
user
.
getUid
()).
removeValue
();
stopService
(
intent
);
mNotificationManager
.
cancel
(
001
);
...
...
@@ -390,7 +411,7 @@ public class MainActivity extends AppCompatActivity implements LocationListener
// shadowView.setShadowTranslationZ(density * 2.0f); // 2.0 dp
// shadowView.setShadowElevation(density * 4.0f); // 4.0 dp
onBusPositionChangeWatch
();
}
public
void
UpdateUserStatus
(
String
user_id
,
boolean
active_status
)
{
...
...
@@ -469,12 +490,15 @@ public class MainActivity extends AppCompatActivity implements LocationListener
}
private
void
startTrackerService
(
String
user_id
,
String
bus_id
)
{
Log
.
d
(
"dddd"
,
"startTrackerService: "
+
stop_busstop_name
);
Log
.
d
(
TAG
,
"startTrackerService: "
+
allbusStop
);
String
destination
=
stop_busstop_name
;
Intent
intent
=
new
Intent
(
this
,
TrackerService3
.
class
);
intent
.
putExtra
(
"user_id"
,
user_id
);
intent
.
putExtra
(
"bus_id"
,
bus_id
);
intent
.
putExtra
(
"destination"
,
destination
);
intent
.
putExtra
(
"allbusStop"
,
allbusStop
);
intent
.
putExtra
(
"start_busstop_id"
,
start_busstop_id
);
intent
.
putExtra
(
"stop_busstop_id"
,
stop_busstop_id
);
startService
(
intent
);
}
...
...
@@ -499,11 +523,18 @@ public class MainActivity extends AppCompatActivity implements LocationListener
.
setContentText
(
"Tracking, tap to open"
)
.
setOngoing
(
true
);
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
new
Intent
(
this
,
MainActivity
.
class
),
PendingIntent
.
FLAG_UPDATE_CURRENT
);
mBuilder
.
setContentIntent
(
contentIntent
);
Intent
intent
=
new
Intent
(
this
,
MainActivity
.
currentContext
.
getClass
());
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
this
,
(
int
)
System
.
currentTimeMillis
(),
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
// PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
// new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder
.
setContentIntent
(
pendingIntent
);
mNotificationManager
=
(
NotificationManager
)
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
...
...
@@ -514,6 +545,8 @@ public class MainActivity extends AppCompatActivity implements LocationListener
@Override
protected
void
onPause
()
{
super
.
onPause
();
bottomSheetDialog
.
dismiss
();
MainActivity
.
currentContext
=
this
;
}
...
...
@@ -523,9 +556,19 @@ public class MainActivity extends AppCompatActivity implements LocationListener
}
@Override
public
void
onBackPressed
()
{
if
(
user_status
.
equalsIgnoreCase
(
"on"
)){
Toast
.
makeText
(
MainActivity
.
this
,
"End your trip before close app"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
super
.
onBackPressed
();
}
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
MainActivity
.
currentContext
=
this
;
// LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// boolean enabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//
...
...
@@ -685,4 +728,27 @@ public class MainActivity extends AppCompatActivity implements LocationListener
alert
=
builder
.
create
();
alert
.
show
();
}
public
void
onBusPositionChangeWatch
()
{
FirebaseUser
user
=
auth
.
getCurrentUser
();
ref1
=
database
.
child
(
"active_bus/"
+
user
.
getUid
());
eventListener1
=
ref1
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
Log
.
d
(
"ddddd"
,
"onDataChange: "
+
dataSnapshot
.
child
(
"time"
).
getValue
(
String
.
class
));
// for (DataSnapshot ds : dataSnapshot.getChildren()) {
// Log.d("ddddd", "onDataChange: "+ds.getKey());
// }
}
@Override
public
void
onCancelled
(
DatabaseError
databaseError
)
{
}
});
}
}
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService3.java
View file @
a18edafa
This diff is collapsed.
Click to expand it.
app/src/main/res/values-v23/styles.xml
0 → 100644
View file @
a18edafa
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name=
"AppTheme"
parent=
"Theme.AppCompat.Light.NoActionBar"
>
<!-- Customize your theme here. -->
<item
name=
"colorPrimary"
>
@color/white
</item>
<item
name=
"colorPrimaryDark"
>
@color/white
</item>
<item
name=
"android:windowLightStatusBar"
>
true
</item>
<!--<item name="android:windowTranslucentStatus">true</item>-->
<!--<item name="android:windowTranslucentNavigation">true</item>-->
</style>
</resources>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
a18edafa
...
...
@@ -41,4 +41,41 @@
<string
name=
"firebase_password"
translatable=
"false"
>
password
</string>
<!--Geofence-->
<!-- Buttons strings -->
<string
name=
"add_geofences"
>
Add geofences
</string>
<string
name=
"remove_geofences"
>
Remove geofences
</string>
<string
name=
"geofences_added"
>
Geofences added
</string>
<string
name=
"geofences_removed"
>
Geofences removed
</string>
<!-- Error strings -->
<string
name=
"geofence_not_available"
>
Geofence service is not available now
</string>
<string
name=
"geofence_too_many_geofences"
>
Your app has registered too many geofences
</string>
<string
name=
"geofence_too_many_pending_intents"
>
You have provided too many PendingIntents to the addGeofences() call
</string>
<string
name=
"unknown_geofence_error"
>
Unknown error: the Geofence service is not available now
</string>
<string
name=
"geofence_transition_invalid_type"
>
Geofence transition error: invalid transition type %1$d
</string>
<!-- Transition type strings -->
<string
name=
"geofence_transition_entered"
>
Entered
</string>
<string
name=
"geofence_transition_exited"
>
Exited
</string>
<string
name=
"unknown_geofence_transition"
>
Unknown Transition
</string>
<string
name=
"geofence_transition_notification_text"
>
Click notification to return to app
</string>
<string
name=
"insufficient_permissions"
>
Insufficient permissions.
</string>
<string
name=
"permission_rationale"
>
Location permission is needed for core functionality
</string>
<string
name=
"permission_denied_explanation"
>
Permission was denied, but is needed for core
functionality.
</string>
<string
name=
"settings"
>
Settings
</string>
</resources>
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