From 2bea34982e995b791066760206c4916e8863f1ff Mon Sep 17 00:00:00 2001 From: krishnam Date: Sun, 3 May 2020 20:31:30 +0530 Subject: [PATCH] A Taxi application clone --- Taxi app clone/ubersachin/.gitignore | 14 + Taxi app clone/ubersachin/.idea/.name | 1 + .../ubersachin/.idea/codeStyles/Project.xml | 116 +++++ Taxi app clone/ubersachin/.idea/gradle.xml | 20 + .../inspectionProfiles/Project_Default.xml | 7 + Taxi app clone/ubersachin/.idea/misc.xml | 9 + .../ubersachin/.idea/runConfigurations.xml | 12 + Taxi app clone/ubersachin/app/.gitignore | 1 + Taxi app clone/ubersachin/app/build.gradle | 52 +++ .../ubersachin/app/google-services.json | 48 ++ .../ubersachin/app/proguard-rules.pro | 21 + .../ubersachin/ExampleInstrumentedTest.java | 27 ++ .../src/debug/res/values/google_maps_api.xml | 24 + .../app/src/main/AndroidManifest.xml | 48 ++ .../ubersachin/CustomerLoginActivity.java | 97 +++++ .../ubersachin/CustomerMapActivity.java | 352 +++++++++++++++ .../ubersachin/CustomerSettingsActivity.java | 160 +++++++ .../ubersachin/DriverLoginActivity.java | 93 ++++ .../example/ubersachin/DriverMapActivity.java | 411 ++++++++++++++++++ .../com/example/ubersachin/MainActivity.java | 42 ++ .../drawable-v24/ic_launcher_foreground.xml | 30 ++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++ .../res/layout/activity_customer_login.xml | 71 +++ .../main/res/layout/activity_customer_map.xml | 46 ++ .../res/layout/activity_customer_settings.xml | 49 +++ .../main/res/layout/activity_driver_login.xml | 83 ++++ .../main/res/layout/activity_driver_map.xml | 76 ++++ .../app/src/main/res/layout/activity_main.xml | 69 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../app/src/main/res/mipmap-hdpi/123pic.png | Bin 0 -> 3590 bytes .../app/src/main/res/mipmap-hdpi/download.jpg | Bin 0 -> 5197 bytes .../app/src/main/res/mipmap-hdpi/download.png | Bin 0 -> 3590 bytes .../main/res/mipmap-hdpi/ic_default_user.png | Bin 0 -> 1590 bytes .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes .../app/src/main/res/mipmap-hdpi/images.png | Bin 0 -> 6244 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/strings.xml | 4 + .../app/src/main/res/values/styles.xml | 11 + .../release/res/values/google_maps_api.xml | 20 + .../example/ubersachin/ExampleUnitTest.java | 17 + Taxi app clone/ubersachin/build.gradle | 30 ++ Taxi app clone/ubersachin/gradle.properties | 20 + .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + Taxi app clone/ubersachin/gradlew | 172 ++++++++ Taxi app clone/ubersachin/gradlew.bat | 84 ++++ Taxi app clone/ubersachin/settings.gradle | 2 + 57 files changed, 2531 insertions(+) create mode 100644 Taxi app clone/ubersachin/.gitignore create mode 100644 Taxi app clone/ubersachin/.idea/.name create mode 100644 Taxi app clone/ubersachin/.idea/codeStyles/Project.xml create mode 100644 Taxi app clone/ubersachin/.idea/gradle.xml create mode 100644 Taxi app clone/ubersachin/.idea/inspectionProfiles/Project_Default.xml create mode 100644 Taxi app clone/ubersachin/.idea/misc.xml create mode 100644 Taxi app clone/ubersachin/.idea/runConfigurations.xml create mode 100644 Taxi app clone/ubersachin/app/.gitignore create mode 100644 Taxi app clone/ubersachin/app/build.gradle create mode 100644 Taxi app clone/ubersachin/app/google-services.json create mode 100644 Taxi app clone/ubersachin/app/proguard-rules.pro create mode 100644 Taxi app clone/ubersachin/app/src/androidTest/java/com/example/ubersachin/ExampleInstrumentedTest.java create mode 100644 Taxi app clone/ubersachin/app/src/debug/res/values/google_maps_api.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/AndroidManifest.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerLoginActivity.java create mode 100644 Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerMapActivity.java create mode 100644 Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerSettingsActivity.java create mode 100644 Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverLoginActivity.java create mode 100644 Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverMapActivity.java create mode 100644 Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/MainActivity.java create mode 100644 Taxi app clone/ubersachin/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/layout/activity_customer_login.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/layout/activity_customer_map.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/layout/activity_customer_settings.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/layout/activity_driver_login.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/layout/activity_driver_map.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/layout/activity_main.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/123pic.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/download.jpg create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/download.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/ic_default_user.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-hdpi/images.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 Taxi app clone/ubersachin/app/src/main/res/values/colors.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/values/strings.xml create mode 100644 Taxi app clone/ubersachin/app/src/main/res/values/styles.xml create mode 100644 Taxi app clone/ubersachin/app/src/release/res/values/google_maps_api.xml create mode 100644 Taxi app clone/ubersachin/app/src/test/java/com/example/ubersachin/ExampleUnitTest.java create mode 100644 Taxi app clone/ubersachin/build.gradle create mode 100644 Taxi app clone/ubersachin/gradle.properties create mode 100644 Taxi app clone/ubersachin/gradle/wrapper/gradle-wrapper.jar create mode 100644 Taxi app clone/ubersachin/gradle/wrapper/gradle-wrapper.properties create mode 100644 Taxi app clone/ubersachin/gradlew create mode 100644 Taxi app clone/ubersachin/gradlew.bat create mode 100644 Taxi app clone/ubersachin/settings.gradle diff --git a/Taxi app clone/ubersachin/.gitignore b/Taxi app clone/ubersachin/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/Taxi app clone/ubersachin/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/Taxi app clone/ubersachin/.idea/.name b/Taxi app clone/ubersachin/.idea/.name new file mode 100644 index 0000000..ac07623 --- /dev/null +++ b/Taxi app clone/ubersachin/.idea/.name @@ -0,0 +1 @@ +uber sachin \ No newline at end of file diff --git a/Taxi app clone/ubersachin/.idea/codeStyles/Project.xml b/Taxi app clone/ubersachin/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/Taxi app clone/ubersachin/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/Taxi app clone/ubersachin/.idea/gradle.xml b/Taxi app clone/ubersachin/.idea/gradle.xml new file mode 100644 index 0000000..5cd135a --- /dev/null +++ b/Taxi app clone/ubersachin/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/Taxi app clone/ubersachin/.idea/inspectionProfiles/Project_Default.xml b/Taxi app clone/ubersachin/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..43e37dd --- /dev/null +++ b/Taxi app clone/ubersachin/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/Taxi app clone/ubersachin/.idea/misc.xml b/Taxi app clone/ubersachin/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/Taxi app clone/ubersachin/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/Taxi app clone/ubersachin/.idea/runConfigurations.xml b/Taxi app clone/ubersachin/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/Taxi app clone/ubersachin/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Taxi app clone/ubersachin/app/.gitignore b/Taxi app clone/ubersachin/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/Taxi app clone/ubersachin/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/Taxi app clone/ubersachin/app/build.gradle b/Taxi app clone/ubersachin/app/build.gradle new file mode 100644 index 0000000..e288404 --- /dev/null +++ b/Taxi app clone/ubersachin/app/build.gradle @@ -0,0 +1,52 @@ +apply plugin: 'com.android.application' + + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + applicationId "com.example.ubersachin" + minSdkVersion 23 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.google.android.gms:play-services-maps:17.0.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation 'com.google.firebase:firebase-analytics:17.2.2' + implementation 'com.google.firebase:firebase-analytics:17.3.0' + implementation 'com.google.firebase:firebase-auth:19.3.0' + implementation 'com.google.firebase:firebase-storage:19.1.1' + implementation 'com.google.firebase:firebase-storage-ktx:19.1.1' + implementation 'com.github.bumptech.glide:glide:4.11.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' + implementation 'com.google.firebase:firebase-core:17.2.3' + implementation 'com.google.firebase:firebase-database:19.2.1' + implementation 'com.google.android.gms:play-services-location:17.0.0' + implementation 'com.firebase:geofire-java:3.0.0' + implementation 'com.android.support:cardview-v7:28.0.0' + implementation 'com.google.android.libraries.places:places:2.2.0' + implementation 'com.github.jd-alexander:library:1.1.0' + +} +apply plugin: 'com.google.gms.google-services' diff --git a/Taxi app clone/ubersachin/app/google-services.json b/Taxi app clone/ubersachin/app/google-services.json new file mode 100644 index 0000000..edb8b74 --- /dev/null +++ b/Taxi app clone/ubersachin/app/google-services.json @@ -0,0 +1,48 @@ +{ + "project_info": { + "project_number": "494657388959", + "firebase_url": "https://uber-sachin-82ddf.firebaseio.com", + "project_id": "uber-sachin-82ddf", + "storage_bucket": "uber-sachin-82ddf.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:494657388959:android:faf577dff0bc8c574a7daa", + "android_client_info": { + "package_name": "com.example.ubersachin" + } + }, + "oauth_client": [ + { + "client_id": "494657388959-ebcoaioos5fo33ho1c70t3t8o6h56h3a.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.example.ubersachin", + "certificate_hash": "6db7111d5bdaad7b0d931c94169d9c4103b264e7" + } + }, + { + "client_id": "494657388959-7p3irkdsnsdms0jo25e7nfhtlquqtccd.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyDi0bUEQDUtK_ewpzzKYp5bSFb1pKbSDjs" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "494657388959-7p3irkdsnsdms0jo25e7nfhtlquqtccd.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/Taxi app clone/ubersachin/app/proguard-rules.pro b/Taxi app clone/ubersachin/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/Taxi app clone/ubersachin/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/Taxi app clone/ubersachin/app/src/androidTest/java/com/example/ubersachin/ExampleInstrumentedTest.java b/Taxi app clone/ubersachin/app/src/androidTest/java/com/example/ubersachin/ExampleInstrumentedTest.java new file mode 100644 index 0000000..de6bd18 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/androidTest/java/com/example/ubersachin/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.example.ubersachin; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.example.ubersachin", appContext.getPackageName()); + } +} diff --git a/Taxi app clone/ubersachin/app/src/debug/res/values/google_maps_api.xml b/Taxi app clone/ubersachin/app/src/debug/res/values/google_maps_api.xml new file mode 100644 index 0000000..c63a261 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,24 @@ + + + AIzaSyCndmznM6wBjnRssApDPH8-eYRU38zb7mI + diff --git a/Taxi app clone/ubersachin/app/src/main/AndroidManifest.xml b/Taxi app clone/ubersachin/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ecd28d7 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/AndroidManifest.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerLoginActivity.java b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerLoginActivity.java new file mode 100644 index 0000000..d66e599 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerLoginActivity.java @@ -0,0 +1,97 @@ +package com.example.ubersachin; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; + +public class CustomerLoginActivity extends AppCompatActivity { + + private EditText mEmail, mPassword; + private Button mLogin, mRegistration; + + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener firebaseAuthListener; + + public void onClick1(View v) { + final String email = mEmail.getText().toString(); + final String password = mPassword.getText().toString(); + mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(CustomerLoginActivity.this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if(!task.isSuccessful()){ + Toast.makeText(CustomerLoginActivity.this, "sign up error", Toast.LENGTH_SHORT).show(); + }else{ + String user_id = mAuth.getCurrentUser().getUid(); + DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child("Customers").child(user_id); + current_user_db.setValue(true); + } + } + }); + } + public void onClick2(View v) { + final String email = mEmail.getText().toString(); + final String password = mPassword.getText().toString(); + mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(CustomerLoginActivity.this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if(!task.isSuccessful()){ + Toast.makeText(CustomerLoginActivity.this, "sign in error", Toast.LENGTH_SHORT).show(); + } + } + }); + + } + @SuppressLint("WrongViewCast") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_customer_login); + mAuth = FirebaseAuth.getInstance(); + + firebaseAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); + if(user!=null){ + Intent intent = new Intent(CustomerLoginActivity.this, CustomerMapActivity.class); + startActivity(intent); + finish(); + } + } + }; + + mEmail = (EditText) findViewById(R.id.email); + mPassword = (EditText) findViewById(R.id.password); + + mLogin = (Button) findViewById(R.id.login); + mRegistration = (Button) findViewById(R.id.registration); + } + + + + @Override + protected void onStart() { + super.onStart(); + mAuth.addAuthStateListener(firebaseAuthListener); + } + @Override + protected void onStop() { + super.onStop(); + mAuth.removeAuthStateListener(firebaseAuthListener); + } +} diff --git a/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerMapActivity.java b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerMapActivity.java new file mode 100644 index 0000000..3c299b4 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerMapActivity.java @@ -0,0 +1,352 @@ +package com.example.ubersachin; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentActivity; + +import android.Manifest; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Build; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; + +import com.firebase.geofire.GeoFire; +import com.firebase.geofire.GeoLocation; +import com.firebase.geofire.GeoQuery; +import com.firebase.geofire.GeoQueryEventListener; +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.BitmapDescriptorFactory; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.Marker; +import com.google.android.gms.maps.model.MarkerOptions; +import com.google.firebase.auth.FirebaseAuth; +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; + +import java.util.HashMap; +import java.util.List; + +public class CustomerMapActivity extends FragmentActivity implements OnMapReadyCallback { + private int radius = 1; + private Boolean driverFound = false; + private String driverFoundID; + private Button mRequest; private Marker pickupMarker; + Location mLastLocation; + private LatLng pickupLocation; + private GoogleMap mMap; + LocationManager locationManager; + private Boolean requestBol=false; + + + android.location.LocationListener locationListener; + + public void Settings(View view){ + Intent intent = new Intent(CustomerMapActivity.this, CustomerSettingsActivity.class); + startActivity(intent); + return; + } + public void logout(View view) { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(CustomerMapActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + + if (requestCode == 1) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); + } + } + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_customer_map); + // 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); + + + mRequest = findViewById(R.id.calluber); + } + private GeoQuery geoQuery; + public void calluber(final View view) { + + if (requestBol){ + requestBol = false; + + + + if (driverFoundID != null){ + DatabaseReference driverRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverFoundID); + driverRef.setValue(true); + driverFoundID = null; + geoQuery.removeAllListeners(); + driverLocationRef.removeEventListener(driverLocationRefListener); + + } + driverFound = false; + radius = 1; + String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); + + DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest"); + GeoFire geoFire = new GeoFire(ref); + geoFire.removeLocation(userId, new GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + if (error != null) { + System.err.println("There was an error removing the location from GeoFire: " + error); + + } else { + System.out.println("Location removed on server successfully!"); + + } + } + }); + + if(pickupMarker != null){ + pickupMarker.remove(); + } + mRequest.setText("call Uber"); + + } + else { + requestBol = true; + locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + locationListener = new LocationListener() { + @Override + public void onLocationChanged(Location location) { + + mMap.clear(); + String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); + + DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest"); + GeoFire geoFire = new GeoFire(ref); + geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new + GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + //Do some stuff if you want to + if (error != null) { + System.err.println("There was an error saving the location to GeoFire: " + error); + } else { + System.out.println("Location saved on server successfully!"); + } + } + }); + + pickupLocation = new LatLng(location.getLatitude(), location.getLongitude()); + pickupMarker=mMap.addMarker(new MarkerOptions().position(pickupLocation).title("Pickup Here")); + DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference().child("driversAvailable"); + + GeoFire geoFire1 = new GeoFire(driverLocation); + pickupLocation = new LatLng(location.getLatitude(), location.getLongitude()); + pickupMarker=mMap.addMarker(new MarkerOptions().position(pickupLocation).title("Pickup Here")); + + geoQuery = geoFire1.queryAtLocation(new GeoLocation(pickupLocation.latitude, pickupLocation.longitude), radius); + geoQuery.removeAllListeners(); + geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { + @Override + public void onKeyEntered(String key, GeoLocation location) { + if (!driverFound) { + driverFound = true; + driverFoundID = key; + + DatabaseReference driverRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverFoundID); + String customerId = FirebaseAuth.getInstance().getCurrentUser().getUid(); + HashMap map = new HashMap(); + map.put("customerRideId", customerId); + driverRef.updateChildren(map); + + + mRequest.setText("Looking for Driver Location...."); + getDriverLocation(); + + } + } + + @Override + public void onKeyExited(String key) { + + } + + @Override + public void onKeyMoved(String key, GeoLocation location) { + + } + + @Override + public void onGeoQueryReady() { + if (!driverFound) { + radius++; + System.out.println("radius is" + radius); + calluber(view); + } + else + getDriverLocation(); + } + + @Override + public void onGeoQueryError(DatabaseError error) { + + } + }); + + + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + + } + + @Override + public void onProviderEnabled(String provider) { + + } + + @Override + public void onProviderDisabled(String provider) { + + } + }; + + + if (Build.VERSION.SDK_INT < 23) { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); + } else { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1); + } else { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); + Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + + mMap.clear(); + LatLng userLocation = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()); + Log.i("location", userLocation.toString()); + pickupMarker=mMap.addMarker(new MarkerOptions().position(userLocation).title("pickup")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); + + } + } + } + } + + + private DatabaseReference driverLocationRef; + private Marker mDriverMarker; + private ValueEventListener driverLocationRefListener ; + private void getDriverLocation() { + driverLocationRef = FirebaseDatabase.getInstance().getReference().child("driversWorking").child(driverFoundID).child("l"); + driverLocationRefListener =driverLocationRef.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if(dataSnapshot.exists()){ + List map = (List) dataSnapshot.getValue(); + double locationLat = 0; + double locationLng = 0; + mRequest.setText("Driver Found"); + if(map.get(0) != null){ + locationLat = Double.parseDouble(map.get(0).toString()); + } + if(map.get(1) != null){ + locationLng = Double.parseDouble(map.get(1).toString()); + } + LatLng driverLatLng = new LatLng(locationLat,locationLng); + if(mDriverMarker != null){ + mDriverMarker.remove(); + } + Location loc1 = new Location(""); + loc1.setLatitude(pickupLocation.latitude); + loc1.setLongitude(pickupLocation.longitude); + + Location loc2 = new Location(""); + loc2.setLatitude(driverLatLng.latitude); + loc2.setLongitude(driverLatLng.longitude); + + float distance = loc1.distanceTo(loc2); + + mRequest.setText("Driver Found: " + String.valueOf(distance)); + if(radius <100) + mRequest.setText("driver has arrived"); + + mDriverMarker = mMap.addMarker(new MarkerOptions().position(driverLatLng).title("your driver")); + } + + } + + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + } + + + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + + + locationManager =(LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + locationListener = new LocationListener() { + @Override + public void onLocationChanged(Location location) { + mLastLocation = location; + mMap.clear(); + LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude()); + mMap.addMarker(new MarkerOptions().position(userLocation).title("Your Location")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); + } + + @Override + public void onStatusChanged(String s, int i, Bundle bundle) { + + } + + @Override + public void onProviderEnabled(String s) { + + } + + @Override + public void onProviderDisabled(String s) { + + } + + }; + + } + + + + @Override + protected void onStop() { + super.onStop(); + + } +} + diff --git a/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerSettingsActivity.java b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerSettingsActivity.java new file mode 100644 index 0000000..4b86651 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/CustomerSettingsActivity.java @@ -0,0 +1,160 @@ +package com.example.ubersachin; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Bundle; +import android.provider.MediaStore; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; + +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.FirebaseAuth; +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; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; +import com.google.firebase.storage.UploadTask; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class CustomerSettingsActivity extends AppCompatActivity { + private EditText mNameField, mPhoneField; + + private Button mBack, mConfirm; + + private ImageView mProfileImage; + + private FirebaseAuth mAuth; + private DatabaseReference mCustomerDatabase; + + private String userID; + private String mName; + private String mPhone; + private String mProfileImageUrl; + + private Uri resultUri; + + + public void back(View view) { + finish(); + return; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_customer_settings); + + mNameField = (EditText) findViewById(R.id.name); + mPhoneField = (EditText) findViewById(R.id.phone); + mBack = (Button) findViewById(R.id.back); + mConfirm = (Button) findViewById(R.id.confirm); + mProfileImage = (ImageView) findViewById(R.id.profileImage); + mAuth = FirebaseAuth.getInstance(); + userID = mAuth.getCurrentUser().getUid(); + mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Customers").child(userID); + + getUserInfo(); + } + + private void getUserInfo() { + mCustomerDatabase.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (dataSnapshot.exists() && dataSnapshot.getChildrenCount() > 0) { + Map map = (Map) dataSnapshot.getValue(); + if (map.get("name") != null) { + mName = map.get("name").toString(); + mNameField.setText(mName); + } + if (map.get("phone") != null) { + mPhone = map.get("phone").toString(); + mPhoneField.setText(mPhone); + } + + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + } +public void savprofileimage(View view){ + Intent intent = new Intent(Intent.ACTION_PICK); + intent.setType("image/*"); + startActivityForResult(intent, 1); +} + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(requestCode == 1 && resultCode == Activity.RESULT_OK){ + final Uri imageUri = data.getData(); + resultUri = imageUri; + mProfileImage.setImageURI(resultUri); + } + } + public void saveUserInformation(View view) { + + mName = mNameField.getText().toString(); + mPhone = mPhoneField.getText().toString(); + + Map userInfo = new HashMap(); + userInfo.put("name", mName); + userInfo.put("phone", mPhone); + mCustomerDatabase.updateChildren(userInfo); + if(resultUri != null) { + + StorageReference filePath = FirebaseStorage.getInstance().getReference().child("profile_images").child(userID); + Bitmap bitmap = null; + try { + bitmap = MediaStore.Images.Media.getBitmap(getApplication().getContentResolver(), resultUri); + } catch (IOException e) { + e.printStackTrace(); + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos); + byte[] data = baos.toByteArray(); + UploadTask uploadTask = filePath.putBytes(data); + + uploadTask.addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + finish(); + return; + } + }); + uploadTask.addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + Task downloadUrl = taskSnapshot.getMetadata().getReference().getDownloadUrl(); + Map newImage = new HashMap(); + newImage.put("profileImageUrl", downloadUrl.toString()); + mCustomerDatabase.updateChildren(newImage); + + finish(); + return; + } + }); + }else{ + finish(); + } + } + +} \ No newline at end of file diff --git a/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverLoginActivity.java b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverLoginActivity.java new file mode 100644 index 0000000..bab16ab --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverLoginActivity.java @@ -0,0 +1,93 @@ +package com.example.ubersachin; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; + +public class DriverLoginActivity extends AppCompatActivity { + private EditText mEmail, mPassword; + private Button mLogin, mRegistration; + + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener firebaseAuthListener; + public void register(View v) { + final String email = mEmail.getText().toString(); + final String password = mPassword.getText().toString(); + mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if(!task.isSuccessful()){ + Toast.makeText(DriverLoginActivity.this, "sign up error", Toast.LENGTH_SHORT).show(); + }else{ + String user_id = mAuth.getCurrentUser().getUid(); + DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(user_id); + current_user_db.setValue(true); + } + } + }); + } + public void lin(View v) { + final String email = mEmail.getText().toString(); + final String password = mPassword.getText().toString(); + mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if(!task.isSuccessful()){ + Toast.makeText(DriverLoginActivity.this, "sign in error", Toast.LENGTH_SHORT).show(); + } + } + }); + + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_driver_login); + mAuth = FirebaseAuth.getInstance(); + + firebaseAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); + if(user!=null){ + Intent intent = new Intent(DriverLoginActivity.this, DriverMapActivity.class); + startActivity(intent); + finish(); + } + } + }; + mEmail = findViewById(R.id.email); + mPassword = findViewById(R.id.password); + + mLogin = (Button) findViewById(R.id.login); + mRegistration = (Button) findViewById(R.id.registration); + } + + + @Override + protected void onStart() { + super.onStart(); + mAuth.addAuthStateListener(firebaseAuthListener); + } + @Override + protected void onStop() { + super.onStop(); + mAuth.removeAuthStateListener(firebaseAuthListener); + } +} diff --git a/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverMapActivity.java b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverMapActivity.java new file mode 100644 index 0000000..1e87ac0 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/java/com/example/ubersachin/DriverMapActivity.java @@ -0,0 +1,411 @@ +package com.example.ubersachin; + +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentActivity; + +import android.Manifest; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Build; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.directions.route.AbstractRouting; +import com.directions.route.Route; +import com.directions.route.RouteException; +import com.directions.route.Routing; +import com.directions.route.RoutingListener; +import com.firebase.geofire.GeoFire; +import com.firebase.geofire.GeoLocation; +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.BitmapDescriptorFactory; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.Marker; +import com.google.android.gms.maps.model.MarkerOptions; +import com.google.android.gms.maps.model.Polyline; +import com.google.android.gms.maps.model.PolylineOptions; +import com.google.firebase.auth.FirebaseAuth; +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; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class DriverMapActivity extends FragmentActivity implements OnMapReadyCallback, RoutingListener { + + + private GoogleMap mMap; + private Boolean isloggingout = false;Location lastKnownLocation; + LocationManager locationManager; + android.location.LocationListener locationListener; + private List polylines; + private static final int[] COLORS = new int[]{R.color.primary_dark_material_light}; + + private SupportMapFragment mapFragment; + + private LinearLayout mCustomerInfo; + + private ImageView mCustomerProfileImage; + + private TextView mCustomerName, mCustomerPhone; + + + public void logout(View view) { + isloggingout = true; + dr(); + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(DriverMapActivity.this, MainActivity.class); + startActivity(intent); + finish(); + + + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + + if (requestCode == 1) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); + } + } + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_driver_map); + // 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); + mCustomerInfo = (LinearLayout) findViewById(R.id.customerInfo); + polylines = new ArrayList<>(); + mCustomerProfileImage = (ImageView) findViewById(R.id.customerProfileImage); + + mCustomerName = (TextView) findViewById(R.id.customerName); + mCustomerPhone = (TextView) findViewById(R.id.customerPhone); + getAssignedCustomer(); + } + + private String customerId = ""; + private void getAssignedCustomerInfo(){ + mCustomerInfo.setVisibility(View.VISIBLE); + DatabaseReference mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Customers").child(customerId); + mCustomerDatabase.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if(dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){ + Map map = (Map) dataSnapshot.getValue(); + if(map.get("name")!=null){ + mCustomerName.setText(map.get("name").toString()); + } + if(map.get("phone")!=null){ + mCustomerPhone.setText(map.get("phone").toString()); + } + if(map.get("profileImageUrl")!=null){ + Glide.with(getApplication()).load(map.get("profileImageUrl").toString()).into(mCustomerProfileImage); + } + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + } + + private void getAssignedCustomer() { + String driverId = FirebaseAuth.getInstance().getCurrentUser().getUid(); + DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverId).child("customerRideId"); + assignedCustomerRef.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (dataSnapshot.exists()) { + customerId = dataSnapshot.getValue().toString(); + getAssignedCustomerPickupLocation(); + getAssignedCustomerInfo(); + } else { + erasePolylines(); + mCustomerInfo.setVisibility(View.INVISIBLE); + customerId = ""; + if (pickupMarker != null) { + pickupMarker.remove(); + } + if (assignedCustomerPickupLocationRefListener != null) { + assignedCustomerPickupLocationRef.removeEventListener(assignedCustomerPickupLocationRefListener); + } + } + } + + + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + } + + private void erasePolylines() { + for(Polyline line: polylines){ + line.remove(); + } + polylines.clear(); + } + + Marker pickupMarker; + private DatabaseReference assignedCustomerPickupLocationRef; + private ValueEventListener assignedCustomerPickupLocationRefListener; + + private void getAssignedCustomerPickupLocation() { + assignedCustomerPickupLocationRef = FirebaseDatabase.getInstance().getReference().child("customerRequest").child(customerId).child("l"); + assignedCustomerPickupLocationRefListener = assignedCustomerPickupLocationRef.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (dataSnapshot.exists()) { + List map = (List) dataSnapshot.getValue(); + double locationLat = 0; + double locationLng = 0; + if (map.get(0) != null) { + locationLat = Double.parseDouble(map.get(0).toString()); + } + if (map.get(1) != null) { + locationLng = Double.parseDouble(map.get(1).toString()); + } + LatLng pickupLatLng = new LatLng(locationLat, locationLng); + pickupMarker = mMap.addMarker(new MarkerOptions().position(pickupLatLng).title("pickup location")); + getRouteToMarker(pickupLatLng); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + } + + private void getRouteToMarker(LatLng pickupLatLng) { + Routing routing = new Routing.Builder() + .travelMode(AbstractRouting.TravelMode.DRIVING) + .withListener(this) + .alternativeRoutes(true) + .waypoints(new LatLng(lastKnownLocation.getLatitude(),lastKnownLocation.getLongitude() ),pickupLatLng) + .build(); + routing.execute(); + } + + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + + + locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + locationListener = new LocationListener() { + @Override + public void onLocationChanged(Location location) { + if (getApplicationContext() != null) { + mMap.clear(); + LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude()); + mMap.addMarker(new MarkerOptions().position(userLocation).title("Your Location")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); + + String userId = Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid(); + DatabaseReference refAvailable = FirebaseDatabase.getInstance().getReference("driversAvailable"); + + DatabaseReference refWorking = FirebaseDatabase.getInstance().getReference("driversWorking"); + GeoFire geoFireAvailable = new GeoFire(refAvailable); + GeoFire geoFireWorking = new GeoFire(refWorking); + + + switch (customerId) { + + case "": + geoFireWorking.removeLocation(userId, new GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + if (error != null) { + System.err.println("There was an error removing the location from GeoFire: " + error); + + } else { + System.out.println("Location removed on server successfully!"); + + } + } + }); + geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new + GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + //Do some stuff if you want to + if (error != null) { + System.err.println("There was an error saving the location to GeoFire: " + error); + } else { + System.out.println("Location saved on server successfully!"); + } + } + }); + break; + default: + geoFireAvailable.removeLocation(userId, new GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + if (error != null) { + System.err.println("There was an error removing the location from GeoFire: " + error); + + } else { + System.out.println("Location removed on server successfully!"); + + } + } + }); + geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new + GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + //Do some stuff if you want to + if (error != null) { + System.err.println("There was an error saving the location to GeoFire: " + error); + } else { + System.out.println("Location saved on server successfully!"); + } + } + }); + break; + } + } + } + + @Override + public void onStatusChanged(String s, int i, Bundle bundle) { + + } + + @Override + public void onProviderEnabled(String s) { + + } + + @Override + public void onProviderDisabled(String s) { + + } + + }; + + + if (Build.VERSION.SDK_INT < 23) { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); + } else { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1); + } else { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); + lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + + mMap.clear(); + LatLng userLocation = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()); + Log.i("location", userLocation.toString()); + mMap.addMarker(new MarkerOptions().position(userLocation).title("Your Location")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); + } + } + } + + private void dr() { + String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); + DatabaseReference ref = FirebaseDatabase.getInstance().getReference("driversAvailable"); + + GeoFire geoFire = new GeoFire(ref); + geoFire.removeLocation(userId, new GeoFire.CompletionListener() { + @Override + public void onComplete(String key, DatabaseError error) { + if (error != null) { + System.err.println("There was an error removing the location from GeoFire: " + error); + + } else { + System.out.println("Location removed on server successfully!"); + + } + } + }); + } + + + + + @Override + protected void onStop() { + super.onStop(); + if (!isloggingout) { +dr(); + } + } + + @Override + public void onRoutingFailure(RouteException e) { + + if(e != null) { + Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); + }else { + Toast.makeText(this, "Something went wrong, Try again", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onRoutingStart() { + + } + + @Override + public void onRoutingSuccess(ArrayList route, int shortestRouteIndex) { + if(polylines.size()>0) { + for (Polyline poly : polylines) { + poly.remove(); + } + } + + polylines = new ArrayList<>(); + //add route(s) to the map. + for (int i = 0; i + + + + + + + + + + \ No newline at end of file diff --git a/Taxi app clone/ubersachin/app/src/main/res/drawable/ic_launcher_background.xml b/Taxi app clone/ubersachin/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Taxi app clone/ubersachin/app/src/main/res/layout/activity_customer_login.xml b/Taxi app clone/ubersachin/app/src/main/res/layout/activity_customer_login.xml new file mode 100644 index 0000000..3a0410b --- /dev/null +++ b/Taxi app clone/ubersachin/app/src/main/res/layout/activity_customer_login.xml @@ -0,0 +1,71 @@ + + + EditText + + + +