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
17eedad4
Commit
17eedad4
authored
Jan 28, 2018
by
Paded
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
popup error fixed
parent
c4d7463f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
268 additions
and
314 deletions
+268
-314
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-1
MainActivity.java
...ansitdriver/paded/com/ubontransitdriver/MainActivity.java
+236
-12
ProfileSettingActivity.java
...r/paded/com/ubontransitdriver/ProfileSettingActivity.java
+26
-3
TrackerService.java
...sitdriver/paded/com/ubontransitdriver/TrackerService.java
+0
-166
TrackerService2.java
...itdriver/paded/com/ubontransitdriver/TrackerService2.java
+0
-128
TrackerService3.java
...itdriver/paded/com/ubontransitdriver/TrackerService3.java
+0
-1
profile_setting_layout.xml
app/src/main/res/layout/profile_setting_layout.xml
+4
-3
No files found.
.idea/caches/build_file_checksums.ser
View file @
17eedad4
No preview for this file type
app/src/main/AndroidManifest.xml
View file @
17eedad4
...
...
@@ -3,7 +3,8 @@
package=
"ubontransitdriver.paded.com.ubontransitdriver"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
<application
android:allowBackup=
"true"
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/MainActivity.java
View file @
17eedad4
...
...
@@ -2,14 +2,20 @@ package ubontransitdriver.paded.com.ubontransitdriver;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.IntentSender
;
import
android.content.pm.PackageManager
;
import
android.location.Location
;
import
android.location.LocationListener
;
import
android.location.LocationManager
;
import
android.net.Uri
;
import
android.provider.Settings
;
import
android.support.design.widget.BottomSheetBehavior
;
import
android.support.design.widget.BottomSheetDialog
;
import
android.support.v4.app.ActivityCompat
;
...
...
@@ -26,6 +32,16 @@ import android.widget.ProgressBar;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.gms.common.api.GoogleApiClient
;
import
com.google.android.gms.common.api.PendingResult
;
import
com.google.android.gms.common.api.ResultCallback
;
import
com.google.android.gms.common.api.Status
;
import
com.google.android.gms.location.LocationRequest
;
import
com.google.android.gms.location.LocationServices
;
import
com.google.android.gms.location.LocationSettingsRequest
;
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.DataSnapshot
;
...
...
@@ -35,7 +51,9 @@ import com.google.firebase.database.FirebaseDatabase;
import
com.google.firebase.database.ValueEventListener
;
import
com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView
;
public
class
MainActivity
extends
AppCompatActivity
{
import
java.util.List
;
public
class
MainActivity
extends
AppCompatActivity
implements
LocationListener
{
private
FirebaseAuth
auth
;
private
ImageButton
btn_profile
;
private
String
TAG
=
"mainAC"
;
...
...
@@ -48,6 +66,10 @@ public class MainActivity extends AppCompatActivity {
private
FrameLayout
view_cover
;
private
boolean
active_status
=
true
;
private
static
final
int
PERMISSIONS_REQUEST
=
1
;
private
GoogleApiClient
googleApiClient
;
final
static
int
REQUEST_LOCATION
=
199
;
static
AlertDialog
alert
;
LocationManager
lm
;
String
bus_id
;
String
user_status
;
...
...
@@ -68,6 +90,35 @@ public class MainActivity extends AppCompatActivity {
setContentView
(
R
.
layout
.
main_layout
);
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
);
// if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER) && hasGPSDevice(MainActivity.this)) {
// Toast.makeText(MainActivity.this,"Gps already enabled",Toast.LENGTH_SHORT).show();
// }
if
(!
hasGPSDevice
(
MainActivity
.
this
))
{
Toast
.
makeText
(
MainActivity
.
this
,
"Gps not Supported"
,
Toast
.
LENGTH_SHORT
).
show
();
}
// if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) && hasGPSDevice(MainActivity.this)) {
// Log.e(TAG,"Gps already enabled");
// Toast.makeText(MainActivity.this,"Gps not enabled",Toast.LENGTH_SHORT).show();
// enableLoc();
// }else{
// Log.e(TAG,"Gps already enabled");
// Toast.makeText(MainActivity.this,"Gps already enabled",Toast.LENGTH_SHORT).show();
// }
auth
=
FirebaseAuth
.
getInstance
();
final
FirebaseUser
user
=
auth
.
getCurrentUser
();
...
...
@@ -118,8 +169,8 @@ public class MainActivity extends AppCompatActivity {
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
start_busstop_name
=
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
);
txt_start
.
setText
(
start_busstop_name
);
start_busstop_name
=
dataSnapshot
.
child
(
"nameEN"
).
getValue
(
String
.
class
);
txt_start
.
setText
(
start_busstop_name
);
}
@Override
...
...
@@ -236,7 +287,9 @@ 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
);
intent
.
putExtra
(
"user_status"
,
user_status
);
startActivityForResult
(
intent
,
1
);
}
});
...
...
@@ -282,10 +335,17 @@ public class MainActivity extends AppCompatActivity {
btn_active_bus
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
progressBar
.
setVisibility
(
View
.
VISIBLE
);
FirebaseUser
user
=
auth
.
getCurrentUser
();
active_status
=
true
;
UpdateUserStatus
(
user
.
getUid
(),
active_status
);
if
(!
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
)
&&
hasGPSDevice
(
MainActivity
.
this
))
{
showDialogGPS
();
}
else
{
progressBar
.
setVisibility
(
View
.
VISIBLE
);
FirebaseUser
user
=
auth
.
getCurrentUser
();
active_status
=
true
;
UpdateUserStatus
(
user
.
getUid
(),
active_status
);
}
}
});
...
...
@@ -293,7 +353,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public
void
onClick
(
View
view
)
{
FirebaseDatabase
database
=
FirebaseDatabase
.
getInstance
();
DatabaseReference
myRef
=
database
.
getReference
(
"users/"
+
user_id
);
DatabaseReference
myRef
=
database
.
getReference
(
"users/"
+
user_id
);
myRef
.
child
(
"start_busstop"
).
setValue
(
stop_busstop_id
);
myRef
.
child
(
"stop_busstop"
).
setValue
(
start_busstop_id
);
...
...
@@ -347,10 +407,11 @@ public class MainActivity extends AppCompatActivity {
@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
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
boolean
result
=
data
.
getBooleanExtra
(
"logout"
,
false
);
if
(
result
)
{
startActivity
(
new
Intent
(
MainActivity
.
this
,
LoginActivity
.
class
));
finish
();
}
...
...
@@ -408,7 +469,7 @@ public class MainActivity extends AppCompatActivity {
}
private
void
startTrackerService
(
String
user_id
,
String
bus_id
)
{
Log
.
d
(
"dddd"
,
"startTrackerService: "
+
stop_busstop_name
);
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
);
...
...
@@ -461,4 +522,167 @@ public class MainActivity extends AppCompatActivity {
super
.
onDestroy
();
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
// LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// boolean enabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//
// if(!enabled) {
// showDialogGPS();
// }
}
@Override
public
void
onLocationChanged
(
Location
location
)
{
Log
.
d
(
TAG
,
"onLocationChanged: "
);
}
@Override
public
void
onStatusChanged
(
String
s
,
int
i
,
Bundle
bundle
)
{
}
@Override
public
void
onProviderEnabled
(
String
s
)
{
if
(!
alert
.
isShowing
())
{
//if its visibility is not showing then show here
}
else
{
alert
.
hide
();
//do something here... if already showing
}
Toast
.
makeText
(
MainActivity
.
this
,
"Gps already enabled"
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
onProviderDisabled
(
String
s
)
{
Toast
.
makeText
(
MainActivity
.
this
,
"Gps not enabled"
,
Toast
.
LENGTH_SHORT
).
show
();
// enableLoc();
// createLocationServiceError(MainActivity.this);
if
(!
isFinishing
()){
showDialogGPS
();
}
}
private
boolean
hasGPSDevice
(
Context
context
)
{
final
LocationManager
mgr
=
(
LocationManager
)
context
.
getSystemService
(
Context
.
LOCATION_SERVICE
);
if
(
mgr
==
null
)
return
false
;
final
List
<
String
>
providers
=
mgr
.
getAllProviders
();
if
(
providers
==
null
)
return
false
;
return
providers
.
contains
(
LocationManager
.
GPS_PROVIDER
);
}
private
void
enableLoc
()
{
if
(
googleApiClient
==
null
)
{
googleApiClient
=
new
GoogleApiClient
.
Builder
(
MainActivity
.
this
)
.
addApi
(
LocationServices
.
API
)
.
addConnectionCallbacks
(
new
GoogleApiClient
.
ConnectionCallbacks
()
{
@Override
public
void
onConnected
(
Bundle
bundle
)
{
}
@Override
public
void
onConnectionSuspended
(
int
i
)
{
googleApiClient
.
connect
();
}
})
.
addOnConnectionFailedListener
(
new
GoogleApiClient
.
OnConnectionFailedListener
()
{
@Override
public
void
onConnectionFailed
(
ConnectionResult
connectionResult
)
{
Log
.
d
(
"Location error"
,
"Location error "
+
connectionResult
.
getErrorCode
());
}
}).
build
();
googleApiClient
.
connect
();
LocationRequest
locationRequest
=
LocationRequest
.
create
();
locationRequest
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
);
locationRequest
.
setInterval
(
30
*
1000
);
locationRequest
.
setFastestInterval
(
5
*
1000
);
LocationSettingsRequest
.
Builder
builder
=
new
LocationSettingsRequest
.
Builder
()
.
addLocationRequest
(
locationRequest
);
builder
.
setAlwaysShow
(
true
);
PendingResult
<
LocationSettingsResult
>
result
=
LocationServices
.
SettingsApi
.
checkLocationSettings
(
googleApiClient
,
builder
.
build
());
result
.
setResultCallback
(
new
ResultCallback
<
LocationSettingsResult
>()
{
@Override
public
void
onResult
(
LocationSettingsResult
result
)
{
final
Status
status
=
result
.
getStatus
();
switch
(
status
.
getStatusCode
())
{
case
LocationSettingsStatusCodes
.
RESOLUTION_REQUIRED
:
try
{
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status
.
startResolutionForResult
(
MainActivity
.
this
,
REQUEST_LOCATION
);
// finish();
}
catch
(
IntentSender
.
SendIntentException
e
)
{
// Ignore the error.
}
break
;
}
}
});
}
}
public
void
createLocationServiceError
(
final
Activity
activityObj
)
{
// show alert dialog if Internet is not connected
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
activityObj
);
builder
.
setMessage
(
"You need to activate location service to use this feature. Please turn on network or GPS mode in location settings"
)
.
setTitle
(
"LostyFound"
)
.
setCancelable
(
false
)
.
setPositiveButton
(
"Settings"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
Intent
intent
=
new
Intent
(
Settings
.
ACTION_LOCATION_SOURCE_SETTINGS
);
activityObj
.
startActivity
(
intent
);
dialog
.
dismiss
();
}
})
.
setNegativeButton
(
"Cancel"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
dialog
.
dismiss
();
}
});
alert
=
builder
.
create
();
alert
.
show
();
}
private
void
showDialogGPS
()
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setCancelable
(
false
);
builder
.
setTitle
(
"Enable GPS"
);
builder
.
setMessage
(
"Please enable GPS"
);
builder
.
setInverseBackgroundForced
(
true
);
builder
.
setPositiveButton
(
"Enable"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
startActivity
(
new
Intent
(
android
.
provider
.
Settings
.
ACTION_LOCATION_SOURCE_SETTINGS
));
}
});
builder
.
setNegativeButton
(
"Ignore"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
}
});
alert
=
builder
.
create
();
alert
.
show
();
}
}
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/ProfileSettingActivity.java
View file @
17eedad4
...
...
@@ -2,7 +2,11 @@ package ubontransitdriver.paded.com.ubontransitdriver;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.support.annotation.NonNull
;
import
android.support.constraint.ConstraintLayout
;
import
android.support.design.widget.CoordinatorLayout
;
import
android.support.design.widget.Snackbar
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.util.Log
;
...
...
@@ -10,6 +14,7 @@ import android.view.View;
import
android.widget.Button
;
import
android.widget.ImageButton
;
import
android.widget.ProgressBar
;
import
android.widget.TextView
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
...
...
@@ -21,19 +26,26 @@ public class ProfileSettingActivity extends AppCompatActivity {
private
String
TAG
=
"PST11"
;
private
ProgressBar
progressBar
;
private
FirebaseAuth
.
AuthStateListener
authListener
;
CoordinatorLayout
coordinatorLayout
;
String
user_status
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
profile_setting_layout
);
Intent
intent
=
getIntent
();
btn_back
=
(
ImageButton
)
findViewById
(
R
.
id
.
btn_back
);
btn_logout
=
(
Button
)
findViewById
(
R
.
id
.
btn_logout
);
progressBar
=
(
ProgressBar
)
findViewById
(
R
.
id
.
progressBar
);
coordinatorLayout
=
(
CoordinatorLayout
)
findViewById
(
R
.
id
.
coordinatorLayout
);
//Get Firebase auth instance
auth
=
FirebaseAuth
.
getInstance
();
user_status
=
intent
.
getStringExtra
(
"user_status"
);
//get current user
final
FirebaseUser
user
=
FirebaseAuth
.
getInstance
().
getCurrentUser
();
...
...
@@ -70,7 +82,18 @@ public class ProfileSettingActivity extends AppCompatActivity {
@Override
public
void
onClick
(
View
view
)
{
progressBar
.
setVisibility
(
View
.
VISIBLE
);
auth
.
signOut
();
if
(
user_status
.
equalsIgnoreCase
(
"on"
)){
Snackbar
snackbar
=
Snackbar
.
make
(
coordinatorLayout
,
"Failed to Logout End your trip and try again."
,
Snackbar
.
LENGTH_LONG
);
TextView
mainTextView
=
(
TextView
)
(
snackbar
.
getView
()).
findViewById
(
android
.
support
.
design
.
R
.
id
.
snackbar_text
);
snackbar
.
getView
().
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
red
));
mainTextView
.
setTextColor
(
Color
.
WHITE
);
snackbar
.
show
();
progressBar
.
setVisibility
(
View
.
GONE
);
}
else
{
auth
.
signOut
();
}
}
});
}
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService.java
deleted
100644 → 0
View file @
c4d7463f
package
ubontransitdriver
.
paded
.
com
.
ubontransitdriver
;
import
android.Manifest
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.PackageManager
;
import
android.location.Location
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.os.IBinder
;
import
android.os.Looper
;
import
android.os.Message
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.util.Log
;
import
android.widget.Toast
;
import
android.os.Process
;
import
com.google.android.gms.location.FusedLocationProviderClient
;
import
com.google.android.gms.location.LocationCallback
;
import
com.google.android.gms.location.LocationRequest
;
import
com.google.android.gms.location.LocationResult
;
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
;
private
Looper
looper
;
private
MyServiceHandler
myServiceHandler
;
@Override
public
void
onCreate
()
{
HandlerThread
handlerthread
=
new
HandlerThread
(
"MyThread"
,
Process
.
THREAD_PRIORITY_BACKGROUND
);
handlerthread
.
start
();
looper
=
handlerthread
.
getLooper
();
myServiceHandler
=
new
MyServiceHandler
(
looper
);
isRunning
=
true
;
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
String
user_id
=
intent
.
getStringExtra
(
"user_id"
);
String
bus_id
=
intent
.
getStringExtra
(
"bus_id"
);
// buildNotification();
requestLocationUpdates
(
user_id
,
bus_id
);
Toast
.
makeText
(
this
,
"MyService Started."
,
Toast
.
LENGTH_SHORT
).
show
();
//If service is killed while starting, it restarts.
return
START_STICKY
;
}
public
TrackerService
()
{
}
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
}
@Override
public
void
onDestroy
()
{
isRunning
=
false
;
Toast
.
makeText
(
this
,
"MyService Completed or Stopped."
,
Toast
.
LENGTH_SHORT
).
show
();
}
private
final
class
MyServiceHandler
extends
Handler
{
public
MyServiceHandler
(
Looper
looper
)
{
super
(
looper
);
}
@Override
public
void
handleMessage
(
Message
msg
)
{
synchronized
(
this
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
{
Log
.
i
(
TAG
,
"MyService running..."
);
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
Log
.
i
(
TAG
,
e
.
getMessage
());
}
if
(!
isRunning
){
break
;
}
}
}
//stops the service for the start id.
stopSelfResult
(
msg
.
arg1
);
}
}
private
void
buildNotification
()
{
String
stop
=
"stop"
;
registerReceiver
(
stopReceiver
,
new
IntentFilter
(
stop
));
PendingIntent
broadcastIntent
=
PendingIntent
.
getBroadcast
(
this
,
0
,
new
Intent
(
stop
),
PendingIntent
.
FLAG_UPDATE_CURRENT
);
// Create the persistent notification
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
this
)
.
setContentTitle
(
getString
(
R
.
string
.
app_name
))
.
setContentText
(
getString
(
R
.
string
.
notification_text
))
.
setOngoing
(
true
)
.
setContentIntent
(
broadcastIntent
)
.
setSmallIcon
(
R
.
drawable
.
ic_frontal_bus_silhouette
);
startForeground
(
1
,
builder
.
build
());
}
protected
BroadcastReceiver
stopReceiver
=
new
BroadcastReceiver
()
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
Log
.
d
(
TAG
,
"received stop broadcast"
);
// Stop the service when the notification is tapped
unregisterReceiver
(
stopReceiver
);
stopSelf
();
}
};
private
void
requestLocationUpdates
(
String
user_id
,
String
bus_id
)
{
LocationRequest
request
=
new
LocationRequest
();
request
.
setInterval
(
10000
);
request
.
setFastestInterval
(
5000
);
request
.
setPriority
(
LocationRequest
.
PRIORITY_HIGH_ACCURACY
);
FusedLocationProviderClient
client
=
LocationServices
.
getFusedLocationProviderClient
(
this
);
final
String
path
=
"active_bus/"
+
bus_id
+
"/"
+
user_id
;
Log
.
d
(
TAG
,
"requestLocationUpdates: "
+
path
);
int
permission
=
ContextCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
);
if
(
permission
==
PackageManager
.
PERMISSION_GRANTED
)
{
// Request location updates and when an update is
// received, store the location in Firebase
client
.
requestLocationUpdates
(
request
,
new
LocationCallback
()
{
@Override
public
void
onLocationResult
(
LocationResult
locationResult
)
{
DatabaseReference
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
path
);
Location
location
=
locationResult
.
getLastLocation
();
if
(
location
!=
null
)
{
Log
.
d
(
TAG
,
"location update "
+
location
);
ref
.
child
(
"latitude"
).
setValue
(
location
.
getLatitude
());
ref
.
child
(
"longitude"
).
setValue
(
location
.
getLongitude
());
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
);
}
}
},
null
);
}
}
}
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService2.java
deleted
100644 → 0
View file @
c4d7463f
package
ubontransitdriver
.
paded
.
com
.
ubontransitdriver
;
import
android.app.Service
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.location.Location
;
import
android.location.LocationManager
;
import
android.os.Bundle
;
import
android.os.IBinder
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.ActivityCompat
;
import
android.util.Log
;
public
class
TrackerService2
extends
Service
{
private
static
final
String
TAG
=
"MyLocationService"
;
private
LocationManager
mLocationManager
=
null
;
private
static
final
int
LOCATION_INTERVAL
=
50000
;
private
static
final
float
LOCATION_DISTANCE
=
10
;
private
class
LocationListener
implements
android
.
location
.
LocationListener
{
Location
mLastLocation
;
public
LocationListener
(
String
provider
)
{
Log
.
e
(
TAG
,
"LocationListener "
+
provider
);
mLastLocation
=
new
Location
(
provider
);
}
@Override
public
void
onLocationChanged
(
Location
location
)
{
Log
.
e
(
TAG
,
"onLocationChanged: "
+
location
);
mLastLocation
.
set
(
location
);
Log
.
d
(
TAG
,
"onLocationChanged Lat Lng: "
+
location
.
getLatitude
()+
" "
+
location
.
getLongitude
());
}
@Override
public
void
onProviderDisabled
(
String
provider
)
{
Log
.
e
(
TAG
,
"onProviderDisabled: "
+
provider
);
}
@Override
public
void
onProviderEnabled
(
String
provider
)
{
Log
.
e
(
TAG
,
"onProviderEnabled: "
+
provider
);
}
@Override
public
void
onStatusChanged
(
String
provider
,
int
status
,
Bundle
extras
)
{
Log
.
e
(
TAG
,
"onStatusChanged: "
+
provider
);
}
}
LocationListener
[]
mLocationListeners
=
new
LocationListener
[]{
new
LocationListener
(
LocationManager
.
PASSIVE_PROVIDER
)
};
@Override
public
IBinder
onBind
(
Intent
arg0
)
{
return
null
;
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Log
.
e
(
TAG
,
"onStartCommand"
);
super
.
onStartCommand
(
intent
,
flags
,
startId
);
return
START_STICKY
;
}
@Override
public
void
onCreate
()
{
Log
.
e
(
TAG
,
"onCreate"
);
initializeLocationManager
();
try
{
mLocationManager
.
requestLocationUpdates
(
LocationManager
.
PASSIVE_PROVIDER
,
LOCATION_INTERVAL
,
LOCATION_DISTANCE
,
mLocationListeners
[
0
]
);
}
catch
(
java
.
lang
.
SecurityException
ex
)
{
Log
.
i
(
TAG
,
"fail to request location update, ignore"
,
ex
);
}
catch
(
IllegalArgumentException
ex
)
{
Log
.
d
(
TAG
,
"network provider does not exist, "
+
ex
.
getMessage
());
}
/*try {
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
LOCATION_INTERVAL,
LOCATION_DISTANCE,
mLocationListeners[1]
);
} catch (java.lang.SecurityException ex) {
Log.i(TAG, "fail to request location update, ignore", ex);
} catch (IllegalArgumentException ex) {
Log.d(TAG, "gps provider does not exist " + ex.getMessage());
}*/
}
@Override
public
void
onDestroy
()
{
Log
.
e
(
TAG
,
"onDestroy"
);
super
.
onDestroy
();
if
(
mLocationManager
!=
null
)
{
for
(
int
i
=
0
;
i
<
mLocationListeners
.
length
;
i
++)
{
try
{
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
android
.
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
&&
ActivityCompat
.
checkSelfPermission
(
this
,
android
.
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
return
;
}
mLocationManager
.
removeUpdates
(
mLocationListeners
[
i
]);
}
catch
(
Exception
ex
)
{
Log
.
i
(
TAG
,
"fail to remove location listener, ignore"
,
ex
);
}
}
}
}
private
void
initializeLocationManager
()
{
Log
.
e
(
TAG
,
"initializeLocationManager - LOCATION_INTERVAL: "
+
LOCATION_INTERVAL
+
" LOCATION_DISTANCE: "
+
LOCATION_DISTANCE
);
if
(
mLocationManager
==
null
)
{
mLocationManager
=
(
LocationManager
)
getApplicationContext
().
getSystemService
(
Context
.
LOCATION_SERVICE
);
}
}
}
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/TrackerService3.java
View file @
17eedad4
...
...
@@ -102,7 +102,6 @@ public class TrackerService3 extends Service implements
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/res/layout/profile_setting_layout.xml
View file @
17eedad4
<?xml version="1.0" encoding="utf-8"?>
<android.support.
constraint.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<android.support.
design.widget.Coordinator
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:id=
"@+id/coordinatorLayout"
android:layout_height=
"match_parent"
android:background=
"@color/white"
tools:context=
".ProfileSettingActivity"
>
...
...
@@ -82,4 +83,4 @@
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
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