Commit 396711c0 authored by Paded's avatar Paded

add return button

parent 7959a8fa
......@@ -33,6 +33,7 @@ dependencies {
compile 'com.h6ah4i.android.materialshadowninepatch:materialshadowninepatch:0.6.5'
compile 'com.loopeer.lib:shadow:0.0.4-beta1'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.elyeproj.libraries:loaderviewlibrary:1.3.0'
}
apply plugin: 'com.google.gms.google-services'
......@@ -41,7 +41,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;
private TextView txt_user_status_on, txt_user_status_off,txt_stop,txt_start;
BottomSheetDialog bottomSheetDialog;
BottomSheetBehavior bottomSheetBehavior;
private FrameLayout view_cover;
......@@ -51,6 +51,11 @@ public class MainActivity extends AppCompatActivity {
String bus_id;
String user_status;
String user_id;
String start_busstop;
String stop_busstop;
int k=0;
NotificationManager mNotificationManager;
......@@ -61,7 +66,7 @@ public class MainActivity extends AppCompatActivity {
auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();
final FirebaseUser user = auth.getCurrentUser();
progressBar = (ProgressBar) findViewById(R.id.progressBar);
......@@ -72,6 +77,9 @@ 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);
// view_cover = (FrameLayout) findViewById(R.id.view_cover);
progressBar.setVisibility(View.VISIBLE);
......@@ -99,14 +107,61 @@ public class MainActivity extends AppCompatActivity {
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() {
@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");
}
});
}
}
@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
......@@ -116,9 +171,6 @@ public class MainActivity extends AppCompatActivity {
});
// if(!user_status){
// txt_user_status.setVisibility(View.GONE);
// }
btn_profile.setOnClickListener(new View.OnClickListener() {
......@@ -177,6 +229,24 @@ 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);
}
});
//
// MaterialShadowContainerView shadowView =
......@@ -202,13 +272,15 @@ public class MainActivity extends AppCompatActivity {
progressBar.setVisibility(View.GONE);
}
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);
btn_endtrip.setVisibility(View.GONE);
btn_return.setVisibility(View.GONE);
btn_return.setVisibility(View.VISIBLE);
txt_user_status_on.setVisibility(View.GONE);
} else {
btn_active_bus.setVisibility(View.GONE);
......@@ -218,7 +290,6 @@ public class MainActivity extends AppCompatActivity {
btn_return.setVisibility(View.VISIBLE);
txt_user_status_on.setVisibility(View.VISIBLE);
}
progressBar.setVisibility(View.GONE);
// view_cover.getForeground().setAlpha(0);
Log.d(TAG, "updateUI: " + user_status);
}
......@@ -251,9 +322,15 @@ 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);
Intent intent = new Intent(this, TrackerService3.class);
intent.putExtra("user_id", user_id);
intent.putExtra("bus_id", bus_id);
intent.putExtra("destination", destination);
startService(intent);
}
......@@ -273,17 +350,10 @@ public class MainActivity extends AppCompatActivity {
private void buildNotification() {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_wifi_bus)
.setContentTitle("On Going")
.setContentText("Tracking, tap to open")
.setOngoing(true);
//Create the intent that’ll fire when the user taps the notification//
// Intent intent = new Intent(this, MainActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
//
// mBuilder.setContentIntent(pendingIntent);
.setSmallIcon(R.drawable.ic_wifi_bus)
.setContentTitle("On Going")
.setContentText("Tracking, tap to open")
.setOngoing(true);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
......@@ -292,7 +362,7 @@ public class MainActivity extends AppCompatActivity {
mBuilder.setContentIntent(contentIntent);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(001, mBuilder.build());
}
......@@ -300,16 +370,12 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onPause() {
super.onPause();
// if(user_status.equalsIgnoreCase("on")){
// buildNotification();
// }
}
@Override
protected void onDestroy() {
super.onDestroy();
// NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
// notificationManager.cancel(001);
}
}
......@@ -35,6 +35,7 @@ public class TrackerService3 extends Service implements
String TAG = "trackService";
private String user_id;
private String bus_id;
private String destination;
@Nullable
@Override
public IBinder onBind(Intent intent) {
......@@ -45,6 +46,7 @@ public class TrackerService3 extends Service implements
public int onStartCommand(Intent intent, int flags, int startId) {
user_id = intent.getStringExtra("user_id");
bus_id = intent.getStringExtra("bus_id");
destination = intent.getStringExtra("destination");
Log.d(TAG, "onStartCommand: "+user_id+" "+bus_id);
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
if (mGoogleApiClient != null && mFusedLocationClient != null) {
......@@ -95,6 +97,7 @@ public class TrackerService3 extends Service implements
ref.child("latitude").setValue(location.getLatitude());
ref.child("longitude").setValue(location.getLongitude());
ref.child("time").setValue(location.getTime());
ref.child("destination").setValue(destination);
// Date currentTime = Calendar.getInstance().getTime();
// Log.d(TAG, "Location: " + location.getLatitude() + " " + location.getLongitude()+" "+location.getTime()+" "+currentTime);
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/green" />
<solid android:color="@color/off_green" />
<corners android:radius="8dp" />
<padding
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/white" />
<solid android:color="@color/green" />
<corners android:radius="8dp" />
<stroke
android:width = "1.5dp"
android:color="@color/green"
/>
<!--<stroke-->
<!--android:width = "1.5dp"-->
<!--android:color="@color/green"-->
<!--/>-->
<padding
android:bottom="7dip"
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/gray_100" />
<solid android:color="@color/off_red" />
<corners android:radius="8dp" />
<padding
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/white" />
<solid android:color="@color/red" />
<corners android:radius="8dp" />
<stroke
android:width="1dp"
android:color="#e7e8ea" >
</stroke>
<!--<stroke-->
<!--android:width="1dp"-->
<!--android:color="#e7e8ea" >-->
<!--</stroke>-->
<padding
android:bottom="7dip"
android:left="7dip"
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/off_blue" />
<solid android:color="@color/gray_100" />
<corners android:radius="8dp" />
<padding
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/blue" />
<solid android:color="@color/white" />
<corners android:radius="8dp" />
<stroke
android:width="1dp"
android:color="#e7e8ea" >
</stroke>
<padding
android:bottom="7dip"
android:left="7dip"
......
<vector android:height="24dp" android:viewportHeight="479.71"
android:viewportWidth="479.71" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/gray_500" android:pathData="M469.936,328.847c-0.96,-0.927 -1.977,-1.792 -3.045,-2.592c-13.381,-8.971 -31.276,-7.013 -42.4,4.64l-10.08,10.08c-3.469,3.481 -6.383,7.474 -8.64,11.84l-6.24,12V66.575c0.634,-16.247 -10.62,-30.552 -26.56,-33.76c-17.486,-2.564 -33.74,9.534 -36.303,27.02c-0.242,1.649 -0.354,3.314 -0.337,4.98v299.52l-4.32,-9.44c-2.335,-5.046 -5.529,-9.648 -9.44,-13.6l-10.56,-10.56c-11.124,-11.653 -29.019,-13.611 -42.4,-4.64c-14.259,10.441 -17.355,30.464 -6.914,44.724c0.844,1.152 1.764,2.247 2.754,3.276l80,80c12.49,12.504 32.751,12.515 45.255,0.025c0.008,-0.008 0.017,-0.017 0.025,-0.025l80,-80C483.006,361.38 482.65,341.122 469.936,328.847z"/>
<path android:fillColor="@color/gray_500" android:pathData="M214.411,104.655l-78.88,-79.04C123.041,13.111 102.78,13.1 90.276,25.59c-0.008,0.008 -0.017,0.017 -0.025,0.025l-80,80c-11.653,11.124 -13.611,29.019 -4.64,42.4c10.441,14.259 30.464,17.355 44.724,6.914c1.152,-0.844 2.247,-1.764 3.276,-2.754l10.88,-10.88c5.215,-5.219 9.158,-11.57 11.52,-18.56l4.32,-9.92v302.24c-0.607,16.347 10.812,30.689 26.88,33.76c17.445,2.829 33.881,-9.019 36.71,-26.465c0.297,-1.83 0.434,-3.682 0.41,-5.535v-304l3.2,9.12c2.403,6.746 6.284,12.869 11.36,17.92l11.52,11.52c12.492,12.501 32.753,12.509 45.255,0.017c0.621,-0.621 1.217,-1.267 1.785,-1.937C228.183,135.984 226.864,116.552 214.411,104.655z"/>
</vector>
<vector android:height="24dp" android:viewportHeight="51.976"
android:viewportWidth="51.976" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/gray_500" android:pathData="M44.373,7.603c-10.137,-10.137 -26.632,-10.138 -36.77,0c-10.138,10.138 -10.137,26.632 0,36.77s26.632,10.138 36.77,0C54.51,34.235 54.51,17.74 44.373,7.603zM36.241,36.241c-0.781,0.781 -2.047,0.781 -2.828,0l-7.425,-7.425l-7.778,7.778c-0.781,0.781 -2.047,0.781 -2.828,0c-0.781,-0.781 -0.781,-2.047 0,-2.828l7.778,-7.778l-7.425,-7.425c-0.781,-0.781 -0.781,-2.048 0,-2.828c0.781,-0.781 2.047,-0.781 2.828,0l7.425,7.425l7.071,-7.071c0.781,-0.781 2.047,-0.781 2.828,0c0.781,0.781 0.781,2.047 0,2.828l-7.071,7.071l7.425,7.425C37.022,34.194 37.022,35.46 36.241,36.241z"/>
<path android:fillColor="@color/white" android:pathData="M44.373,7.603c-10.137,-10.137 -26.632,-10.138 -36.77,0c-10.138,10.138 -10.137,26.632 0,36.77s26.632,10.138 36.77,0C54.51,34.235 54.51,17.74 44.373,7.603zM36.241,36.241c-0.781,0.781 -2.047,0.781 -2.828,0l-7.425,-7.425l-7.778,7.778c-0.781,0.781 -2.047,0.781 -2.828,0c-0.781,-0.781 -0.781,-2.047 0,-2.828l7.778,-7.778l-7.425,-7.425c-0.781,-0.781 -0.781,-2.048 0,-2.828c0.781,-0.781 2.047,-0.781 2.828,0l7.425,7.425l7.071,-7.071c0.781,-0.781 2.047,-0.781 2.828,0c0.781,0.781 0.781,2.047 0,2.828l-7.071,7.071l7.425,7.425C37.022,34.194 37.022,35.46 36.241,36.241z"/>
</vector>
......@@ -33,7 +33,7 @@
android:id="@+id/btn_endtrip_yes"
android:layout_marginTop="18dp"
style="?android:attr/borderlessButtonStyle"
android:background="@drawable/bg_return_bus"
android:background="@drawable/bg_endtrip_bus"
android:textStyle="bold"
android:text="End Trip"
android:textSize="18dp"
......@@ -49,7 +49,7 @@
android:text="Cancel"
android:textSize="18dp"
android:textColor="@color/gray_500"
android:background="@drawable/bg_endtrip_bus"
android:background="@drawable/bg_return_bus"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
......
......@@ -151,9 +151,9 @@
android:textStyle="bold" />
<TextView
android:id="@+id/txt_stop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ubon Terminal"
android:textColor="@color/gray_800"
android:textSize="26dp"
android:textStyle="bold" />
......@@ -190,9 +190,9 @@
android:textSize="17dp" />
<TextView
android:id="@+id/txt_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ubon Ratchathani"
android:textColor="@color/blue"
android:textSize="17dp" />
......@@ -475,11 +475,11 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/bg_return_bus"
android:drawableRight="@drawable/ic_return"
android:drawableRight="@drawable/ic_arrows"
android:gravity="left|center_vertical"
android:padding="15dp"
android:text="Return"
android:textColor="@color/white"
android:textColor="@color/gray_500"
android:textSize="20dp"
android:textStyle="bold"
android:visibility="gone" />
......@@ -495,7 +495,7 @@
android:gravity="left|center_vertical"
android:padding="15dp"
android:text="End Trip"
android:textColor="@color/gray_500"
android:textColor="@color/white"
android:textSize="20dp"
android:textStyle="bold"
android:visibility="gone" />
......@@ -507,11 +507,11 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/bg_btn_activebus"
android:drawableRight="@drawable/icon_active_clicked"
android:drawableRight="@drawable/ic_track_changes_white_24dp"
android:gravity="left|center_vertical"
android:padding="15dp"
android:text="Active Bus"
android:textColor="@drawable/text_active_color"
android:textColor="@color/white"
android:textSize="20dp"
android:textStyle="bold"
android:visibility="gone" />
......
......@@ -15,6 +15,7 @@
<color name="green">#4cd964</color>
<color name="off_green">#47c75d</color>
<color name="red">#ff2d55</color>
<color name="off_red">#ea294d</color>
<color name="black">#000000</color>
<color name="half_black">#303030</color>
<color name="gray">#ececec</color>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment