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
7 years ago
by
Paded
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
popup error fixed
parent
c4d7463f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
302 deletions
+32
-302
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
+0
-0
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
This diff is collapsed.
Click to expand it.
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"
...
...
This diff is collapsed.
Click to expand it.
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/MainActivity.java
View file @
17eedad4
This diff is collapsed.
Click to expand it.
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
();
}
}
});
}
...
...
This diff is collapsed.
Click to expand it.
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
);
}
}
}
This diff is collapsed.
Click to expand it.
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
);
}
}
}
This diff is collapsed.
Click to expand it.
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
);
...
...
This diff is collapsed.
Click to expand it.
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
This diff is collapsed.
Click to expand it.
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