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
3b02697b
Commit
3b02697b
authored
May 29, 2018
by
Paded
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit register
parent
76c859c0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
35 deletions
+120
-35
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
CreateAccountActivity.java
...er/paded/com/ubontransitdriver/CreateAccountActivity.java
+23
-18
MainActivity.java
...ansitdriver/paded/com/ubontransitdriver/MainActivity.java
+88
-17
main_layout.xml
app/src/main/res/layout/main_layout.xml
+2
-0
colors.xml
app/src/main/res/values/colors.xml
+7
-0
No files found.
.idea/caches/build_file_checksums.ser
View file @
3b02697b
No preview for this file type
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/CreateAccountActivity.java
View file @
3b02697b
...
...
@@ -296,28 +296,33 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
busid
=
"B012"
;
}
DatabaseReference
keyReference
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
busid
);
DatabaseReference
keyReference
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
busid
+
"/direction"
);
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
);
if
(
dataSnapshot
.
getValue
().
toString
()!=
null
){
String
x
=
dataSnapshot
.
getValue
().
toString
();
Log
.
d
(
TAG
,
"insertData: "
+
x
);
//
String
[]
x2
=
x
.
split
(
" "
);
String
[]
x3
=
x2
[
0
].
split
(
"="
);
String
[]
bus_stop
=
x3
[
1
].
split
(
","
);
int
bus_stop_size
=
bus_stop
.
length
;
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
...
...
app/src/main/java/ubontransitdriver/paded/com/ubontransitdriver/MainActivity.java
View file @
3b02697b
...
...
@@ -11,6 +11,7 @@ import android.content.Intent;
import
android.content.IntentFilter
;
import
android.content.IntentSender
;
import
android.content.pm.PackageManager
;
import
android.graphics.drawable.GradientDrawable
;
import
android.location.Location
;
import
android.location.LocationListener
;
import
android.location.LocationManager
;
...
...
@@ -28,7 +29,9 @@ import android.view.View;
import
android.widget.Button
;
import
android.widget.FrameLayout
;
import
android.widget.ImageButton
;
import
android.widget.LinearLayout
;
import
android.widget.ProgressBar
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
...
...
@@ -61,7 +64,7 @@ public class MainActivity extends AppCompatActivity implements LocationListener
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
,
bus_name_txt
;
BottomSheetDialog
bottomSheetDialog
;
BottomSheetBehavior
bottomSheetBehavior
;
private
FrameLayout
view_cover
;
...
...
@@ -72,6 +75,13 @@ public class MainActivity extends AppCompatActivity implements LocationListener
static
AlertDialog
alert
;
LocationManager
lm
;
private
static
final
String
FINE_LOCATION
=
Manifest
.
permission
.
ACCESS_FINE_LOCATION
;
private
static
final
String
COURSE_LOCATION
=
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
;
private
static
final
int
LOCATION_PERMISSION_REQUEST_CODE
=
1234
;
RelativeLayout
bus_icon_layout
;
GradientDrawable
drawable
;
String
bus_id
;
String
user_status
;
String
user_id
;
...
...
@@ -98,15 +108,38 @@ public class MainActivity extends AppCompatActivity implements LocationListener
setContentView
(
R
.
layout
.
main_layout
);
MainActivity
.
currentContext
=
this
;
Log
.
d
(
TAG
,
"onCreate: "
);
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
)
{
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 (ActivityCompat.checkSelfPermission(this,
// Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
// ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
// != PackageManager.PERMISSION_GRANTED) {
//
// Log.d(TAG, "onCreate: per");
// return;
// }
String
[]
permission
=
{
Manifest
.
permission
.
ACCESS_FINE_LOCATION
,
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
};
if
(
ContextCompat
.
checkSelfPermission
(
this
.
getApplicationContext
(),
FINE_LOCATION
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ContextCompat
.
checkSelfPermission
(
this
.
getApplicationContext
(),
COURSE_LOCATION
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
// mLocationPermissionGranted = true;
// initMap();
lm
.
requestLocationUpdates
(
LocationManager
.
GPS_PROVIDER
,
1000
,
10
,
this
);
}
else
{
ActivityCompat
.
requestPermissions
(
this
,
permission
,
LOCATION_PERMISSION_REQUEST_CODE
);
}
}
else
{
ActivityCompat
.
requestPermissions
(
this
,
permission
,
LOCATION_PERMISSION_REQUEST_CODE
);
}
// 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
();
}
...
...
@@ -136,6 +169,9 @@ public class MainActivity extends AppCompatActivity implements LocationListener
txt_start
=
(
TextView
)
findViewById
(
R
.
id
.
txt_start
);
txt_stop
=
(
TextView
)
findViewById
(
R
.
id
.
txt_stop
);
bus_name_txt
=
(
TextView
)
findViewById
(
R
.
id
.
bus_name_txt
);
bus_icon_layout
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
bus_icon_layout
);
drawable
=
(
GradientDrawable
)
bus_icon_layout
.
getBackground
();
// view_cover = (FrameLayout) findViewById(R.id.view_cover);
progressBar
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -163,6 +199,8 @@ public class MainActivity extends AppCompatActivity implements LocationListener
bus_id
=
dataSnapshot
.
child
(
"bus_id"
).
getValue
(
String
.
class
);
user_id
=
user
.
getUid
();
Log
.
d
(
TAG
,
"onDataChange: "
+
user_status
);
start_busstop_id
=
dataSnapshot
.
child
(
"start_busstop"
).
getValue
(
String
.
class
);
stop_busstop_id
=
dataSnapshot
.
child
(
"stop_busstop"
).
getValue
(
String
.
class
);
...
...
@@ -181,6 +219,39 @@ public class MainActivity extends AppCompatActivity implements LocationListener
}
});
//set Infomation to Display
DatabaseReference
keyReference11
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
bus_id
);
keyReference11
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
public
void
onDataChange
(
DataSnapshot
dataSnapshot
)
{
bus_name_txt
.
setText
(
dataSnapshot
.
child
(
"name"
).
getValue
(
String
.
class
));
if
(
bus_id
.
equalsIgnoreCase
(
"B00"
)){
drawable
.
setColor
(
getResources
().
getColor
(
R
.
color
.
red3
));
}
else
if
(
bus_id
.
equalsIgnoreCase
(
"B01"
)){
drawable
.
setColor
(
getResources
().
getColor
(
R
.
color
.
purple
));
}
else
if
(
bus_id
.
equalsIgnoreCase
(
"B02"
)){
drawable
.
setColor
(
getResources
().
getColor
(
R
.
color
.
gray_300
));
}
else
if
(
bus_id
.
equalsIgnoreCase
(
"B03"
)){
drawable
.
setColor
(
getResources
().
getColor
(
R
.
color
.
pink
));
}
else
if
(
bus_id
.
equalsIgnoreCase
(
"B07"
)
||
bus_id
.
equalsIgnoreCase
(
"B08"
)
||
bus_id
.
equalsIgnoreCase
(
"B09"
)
||
bus_id
.
equalsIgnoreCase
(
"B10"
)
||
bus_id
.
equalsIgnoreCase
(
"B11"
)
||
bus_id
.
equalsIgnoreCase
(
"B12"
)){
drawable
.
setColor
(
getResources
().
getColor
(
R
.
color
.
sky_blue
));
}
}
@Override
public
void
onCancelled
(
DatabaseError
databaseError
)
{
Log
.
d
(
TAG
,
"Read failed"
);
}
});
DatabaseReference
keyReference1
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"allbus/"
+
bus_id
+
"/direction/"
+
start_busstop_id
);
keyReference1
.
addValueEventListener
(
new
ValueEventListener
()
{
@Override
...
...
@@ -503,16 +574,16 @@ public class MainActivity extends AppCompatActivity implements LocationListener
}
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
)
{
if
(
requestCode
==
PERMISSIONS_REQUEST
&&
grantResults
.
length
==
1
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
// Start the service when the permission is granted
startTrackerService
(
user_id
,
bus_id
);
Log
.
d
(
TAG
,
"onRequestPermissionsResult: Start"
);
}
else
{
finish
();
}
public
void
onRequestPermissionsResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
)
{
Log
.
d
(
TAG
,
"onRequestPermissionsResult: "
);
//
if (requestCode == PERMISSIONS_REQUEST && grantResults.length == 1
//
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//
// Start the service when the permission is granted
//
startTrackerService(user_id, bus_id);
//
Log.d(TAG, "onRequestPermissionsResult: Start");
//
} else {
//
finish();
//
}
}
private
void
buildNotification
()
{
...
...
app/src/main/res/layout/main_layout.xml
View file @
3b02697b
...
...
@@ -205,6 +205,7 @@
android:orientation=
"horizontal"
>
<RelativeLayout
android:id=
"@+id/bus_icon_layout"
android:layout_width=
"25dp"
android:layout_height=
"25dp"
android:layout_marginRight=
"6dp"
...
...
@@ -224,6 +225,7 @@
<TextView
android:id=
"@+id/bus_name_txt"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"สาย ม."
...
...
app/src/main/res/values/colors.xml
View file @
3b02697b
...
...
@@ -27,6 +27,13 @@
<color
name=
"gray_800"
>
#424242
</color>
<color
name=
"gray_900"
>
#212121
</color>
<color
name=
"purple"
>
#3f51b5
</color>
<color
name=
"sky_blue"
>
#5ac8fa
</color>
<color
name=
"pink"
>
#fe5273
</color>
<color
name=
"gray_300"
>
#E0E0E0
</color>
<color
name=
"red3"
>
#f23333
</color>
...
...
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