Commit 73d8fd25 authored by A.P.R.C. Abeyrathna's avatar A.P.R.C. Abeyrathna

Destination location selector added

Bus live tracker added V1
parent acd7e607
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
id 'com.google.gms.google-services'
} }
android { android {
...@@ -42,6 +43,7 @@ dependencies { ...@@ -42,6 +43,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-maps:18.1.0' implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0' implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-location:20.0.0' implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.google.firebase:firebase-database:20.0.4'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
......
...@@ -14,17 +14,11 @@ ...@@ -14,17 +14,11 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:screenOrientation="sensorPortrait"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Travelle" android:theme="@style/Theme.Travelle"
android:screenOrientation="sensorPortrait"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".InitialMap"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<!-- <!--
TODO: Before you run your application, you need a Google Maps API key. TODO: Before you run your application, you need a Google Maps API key.
...@@ -38,8 +32,19 @@ ...@@ -38,8 +32,19 @@
--> -->
<meta-data <meta-data
android:name="com.google.android.geo.API_KEY" android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyD7LBGU3enFRU4u2is65UDT5jRGeIcx4_Q" /> android:value="YOUR_API_KEY" />
<activity
android:name=".RetrieveBusMap"
android:exported="false"
android:label="@string/title_activity_retrieve_bus_map" />
<activity
android:name=".InitialMap"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity <activity
android:name=".HomeMap" android:name=".HomeMap"
android:exported="false" android:exported="false"
......
...@@ -6,13 +6,17 @@ import androidx.core.app.ActivityCompat; ...@@ -6,13 +6,17 @@ import androidx.core.app.ActivityCompat;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color; import android.graphics.Color;
import android.location.Location; import android.location.Location;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
...@@ -28,10 +32,18 @@ import com.google.android.gms.maps.model.Polyline; ...@@ -28,10 +32,18 @@ import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions; import com.google.android.gms.maps.model.PolylineOptions;
import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import android.view.View;
import java.util.HashMap;
import java.util.Map;
public class InitialMap extends AppCompatActivity { public class InitialMap extends AppCompatActivity {
//Initialize variable private static final String[] CITIES = new String[]{
"Viharamahadevi Park","House Of Fashion","Castle Street","Rajagiriya","HSBC Rajagiriya","Ethulkotte New","Parliament Junction","Battaramulla Junction","Ganahena","Koswatta","Kotte-Bope"
,"Thalahena Junction","Malabe","Fort_TR","Kompannavidiya_TR","Kollupitiya_TR","Bambalapitiya_TR","Wellawatte_TR","Dehiwala_TR"
};
//Initialize variable
SupportMapFragment supportMapFragment; SupportMapFragment supportMapFragment;
FusedLocationProviderClient client; FusedLocationProviderClient client;
GoogleMap map; GoogleMap map;
...@@ -44,6 +56,12 @@ public class InitialMap extends AppCompatActivity { ...@@ -44,6 +56,12 @@ public class InitialMap extends AppCompatActivity {
getSupportActionBar().hide(); getSupportActionBar().hide();
setContentView(R.layout.activity_initial_map); setContentView(R.layout.activity_initial_map);
//Where to declaration
AutoCompleteTextView editText = findViewById(R.id.where_to);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this , android.R.layout.simple_list_item_1, CITIES);
editText.setAdapter(adapter);
//Assign variable //Assign variable
...@@ -67,6 +85,12 @@ public class InitialMap extends AppCompatActivity { ...@@ -67,6 +85,12 @@ public class InitialMap extends AppCompatActivity {
} }
} }
public void btnRetrieveLocation(View view) {
startActivity(new Intent(getApplicationContext(),RetrieveBusMap.class));
}
private void getCurrentLocation() { private void getCurrentLocation() {
//Initialize task location //Initialize task location
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
......
package com.app.travelle;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.app.travelle.databinding.ActivityRetrieveBusMapBinding;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class RetrieveBusMap extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private ActivityRetrieveBusMapBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityRetrieveBusMapBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("/");
ValueEventListener listener = databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Double latitude = dataSnapshot.child("latitude").getValue(Double.class);
Double longitude = dataSnapshot.child("longitude").getValue(Double.class);
LatLng location = new LatLng(latitude,longitude);
mMap.addMarker(new MarkerOptions().position(location).title("117"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,14F));
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
\ No newline at end of file
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/rectangle_16" /> app:srcCompat="@drawable/rectangle_16" />
<com.google.android.material.textfield.TextInputLayout <!-- <com.google.android.material.textfield.TextInputLayout
android:id="@+id/search_destination" android:id="@+id/search_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="340dp" android:layout_width="340dp"
...@@ -54,15 +54,16 @@ ...@@ -54,15 +54,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/sans_bold" android:fontFamily="@font/sans_bold"
android:hint="Where to?" /> android:hint="Where to?" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout> -->
<Button <Button
android:id="@+id/button2" android:id="@+id/findbus"
android:layout_width="124dp" android:layout_width="124dp"
android:layout_height="58dp" android:layout_height="58dp"
android:layout_marginStart="140dp" android:layout_marginStart="140dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:backgroundTint="#262730" android:backgroundTint="#262730"
android:onClick="btnRetrieveLocation"
android:text="FIND " android:text="FIND "
app:cornerRadius="60px" app:cornerRadius="60px"
android:textSize="60px" android:textSize="60px"
...@@ -94,4 +95,21 @@ ...@@ -94,4 +95,21 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<AutoCompleteTextView
android:id="@+id/where_to"
android:layout_width="340dp"
android:layout_height="59dp"
android:layout_marginStart="32dp"
android:layout_marginBottom="156dp"
android:hint="Where to"
android:textAlignment="center"
android:completionThreshold="1"
android:completionHint="Select a city"
android:background="#FFFFFF"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RetrieveBusMap" />
\ No newline at end of file
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
android:text="Where to" android:text="Where to"
android:textAlignment="center" android:textAlignment="center"
android:completionThreshold="3" android:completionThreshold="3"
android:popupTheme="#FFFFFF"
android:background="#FFFFFF" android:background="#FFFFFF"
app:layout_constraintBottom_toTopOf="@+id/button2" app:layout_constraintBottom_toTopOf="@+id/button2"
......
...@@ -11,4 +11,5 @@ ...@@ -11,4 +11,5 @@
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string> <string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<string name="title_activity_homemap">homemap</string> <string name="title_activity_homemap">homemap</string>
<string name="title_activity_home_map">HomeMap</string> <string name="title_activity_home_map">HomeMap</string>
<string name="title_activity_retrieve_bus_map">RetrieveBusMap</string>
</resources> </resources>
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id 'com.android.application' version '7.3.0' apply false id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false id 'com.android.library' version '7.3.0' apply false
......
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