Skip to content

Commit 1b0f93b

Browse files
committed
Uber Clone App
Uses Google Maps API to display Maps and RiderActivity ensures to display The Location to user who needs ride... I attempted to Build UberClone of my Own...
1 parent 2fb6333 commit 1b0f93b

5 files changed

+1001
-0
lines changed

uber/DriverLocationActivity.java

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package com.lenovo.uber;
2+
3+
4+
import android.content.Intent;
5+
import android.net.Uri;
6+
import android.support.v4.app.FragmentActivity;
7+
import android.os.Bundle;
8+
import android.view.View;
9+
import android.view.ViewTreeObserver;
10+
import android.widget.RelativeLayout;
11+
12+
import com.google.android.gms.maps.CameraUpdate;
13+
import com.google.android.gms.maps.CameraUpdateFactory;
14+
import com.google.android.gms.maps.GoogleMap;
15+
import com.google.android.gms.maps.OnMapReadyCallback;
16+
import com.google.android.gms.maps.SupportMapFragment;
17+
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
18+
import com.google.android.gms.maps.model.LatLng;
19+
import com.google.android.gms.maps.model.LatLngBounds;
20+
import com.google.android.gms.maps.model.Marker;
21+
import com.google.android.gms.maps.model.MarkerOptions;
22+
import com.parse.FindCallback;
23+
import com.parse.ParseException;
24+
import com.parse.ParseObject;
25+
import com.parse.ParseQuery;
26+
import com.parse.ParseUser;
27+
import com.parse.SaveCallback;
28+
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
public class DriverLocationActivity extends FragmentActivity implements OnMapReadyCallback {
33+
34+
private GoogleMap mMap;
35+
Intent intent;
36+
37+
public void acceptRequest(View view) {
38+
39+
ParseQuery<ParseObject> query = ParseQuery.getQuery("Request");
40+
41+
query.whereEqualTo("username", intent.getStringExtra("username"));
42+
43+
query.findInBackground(new FindCallback<ParseObject>() {
44+
@Override
45+
public void done(List<ParseObject> objects, ParseException e) {
46+
47+
if (e == null) {
48+
49+
if (objects.size() > 0) {
50+
51+
for (ParseObject object : objects) {
52+
53+
object.put("driverUsername", ParseUser.getCurrentUser().getUsername());
54+
55+
object.saveInBackground(new SaveCallback() {
56+
@Override
57+
public void done(ParseException e) {
58+
59+
if (e == null) {
60+
61+
Intent directionsIntent = new Intent(android.content.Intent.ACTION_VIEW,
62+
Uri.parse("http://maps.google.com/maps?saddr=" + intent.getDoubleExtra("driverLatitude", 0) + "," + intent.getDoubleExtra("driverLongitude", 0) + "&daddr=" + intent.getDoubleExtra("requestLatitude", 0) + "," + intent.getDoubleExtra("requestLongitude", 0)));
63+
startActivity(directionsIntent);
64+
65+
}
66+
67+
}
68+
});
69+
70+
}
71+
72+
}
73+
74+
}
75+
76+
}
77+
});
78+
79+
}
80+
81+
@Override
82+
protected void onCreate(Bundle savedInstanceState) {
83+
super.onCreate(savedInstanceState);
84+
setContentView(R.layout.activity_driver_location);
85+
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
86+
87+
intent = getIntent();
88+
89+
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
90+
.findFragmentById(R.id.map);
91+
mapFragment.getMapAsync(this);
92+
93+
RelativeLayout mapLayout = (RelativeLayout)findViewById(R.id.mapRelativeLayout);
94+
mapLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
95+
@Override
96+
public void onGlobalLayout() {
97+
98+
LatLng driverLocation = new LatLng(intent.getDoubleExtra("driverLatitude", 0), intent.getDoubleExtra("driverLongitude", 0));
99+
100+
LatLng requestLocation = new LatLng(intent.getDoubleExtra("requestLatitude", 0), intent.getDoubleExtra("requestLongitude", 0));
101+
102+
ArrayList<Marker> markers = new ArrayList<>();
103+
104+
markers.add(mMap.addMarker(new MarkerOptions().position(driverLocation).title("Your Location")));
105+
markers.add(mMap.addMarker(new MarkerOptions().position(requestLocation).title("Request Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))));
106+
107+
LatLngBounds.Builder builder = new LatLngBounds.Builder();
108+
for (Marker marker : markers) {
109+
builder.include(marker.getPosition());
110+
}
111+
LatLngBounds bounds = builder.build();
112+
113+
114+
int padding = 60; // offset from edges of the map in pixels
115+
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
116+
117+
mMap.animateCamera(cu);
118+
119+
}
120+
});
121+
}
122+
123+
124+
/**
125+
* Manipulates the map once available.
126+
* This callback is triggered when the map is ready to be used.
127+
* This is where we can add markers or lines, add listeners or move the camera. In this case,
128+
* we just add a marker near Sydney, Australia.
129+
* If Google Play services is not installed on the device, the user will be prompted to install
130+
* it inside the SupportMapFragment. This method will only be triggered once the user has
131+
* installed Google Play services and returned to the app.
132+
*/
133+
@Override
134+
public void onMapReady(GoogleMap googleMap) {
135+
mMap = googleMap;
136+
137+
}
138+
}

uber/MainActivity.java

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.lenovo.uber;
2+
3+
import android.content.Intent;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
import android.view.View;
8+
import android.widget.Switch;
9+
10+
import com.parse.LogInCallback;
11+
import com.parse.Parse;
12+
import com.parse.ParseACL;
13+
import com.parse.ParseAnalytics;
14+
import com.parse.ParseAnonymousUtils;
15+
import com.parse.ParseException;
16+
import com.parse.ParseObject;
17+
import com.parse.ParseUser;
18+
import com.parse.SaveCallback;
19+
20+
public class MainActivity extends AppCompatActivity {
21+
/* appId: "4dedb0f3872a4543e16f8624cf8ac5fb4789f925",
22+
masterKey: "948bbcfceec6438c259633bfdba7411d0746f3ef",*/
23+
24+
public void redirectActivity() {
25+
26+
if (ParseUser.getCurrentUser().getString("riderOrDriver").equals("rider")) {
27+
28+
Intent intent = new Intent(getApplicationContext(), RiderActivity.class);
29+
startActivity(intent);
30+
31+
} else {
32+
33+
Intent intent = new Intent(getApplicationContext(), ViewRequestActivity.class);
34+
startActivity(intent);
35+
36+
37+
}
38+
}
39+
public void getStarted(View view) {
40+
41+
Switch userTypeSwitch = (Switch) findViewById(R.id.userTypeSwitch);
42+
43+
Log.i("Switch value", String.valueOf(userTypeSwitch.isChecked()));
44+
45+
String userType = "rider";
46+
47+
if (userTypeSwitch.isChecked()) {
48+
49+
userType = "driver";
50+
51+
}
52+
53+
ParseUser.getCurrentUser().put("riderOrDriver", userType);
54+
Log.i("INFO","REdirecting as "+userType);
55+
ParseUser.getCurrentUser().saveInBackground(new SaveCallback() {
56+
@Override
57+
public void done(ParseException e) {
58+
59+
redirectActivity();
60+
61+
}
62+
});
63+
64+
65+
66+
67+
}
68+
69+
70+
@Override
71+
protected void onCreate(Bundle savedInstanceState) {
72+
super.onCreate(savedInstanceState);
73+
setContentView(R.layout.activity_main);
74+
getSupportActionBar().hide();
75+
// Parse.enableLocalDatastore(this);
76+
77+
// Add your initialization code here
78+
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
79+
.applicationId("4dedb0f3872a4543e16f8624cf8ac5fb4789f925")
80+
.clientKey("948bbcfceec6438c259633bfdba7411d0746f3ef")
81+
.server("http://52.14.175.235:80/parse/")
82+
.build()
83+
);
84+
85+
if (ParseUser.getCurrentUser() == null) {
86+
87+
ParseAnonymousUtils.logIn(new LogInCallback() {
88+
@Override
89+
public void done(ParseUser user, ParseException e) {
90+
91+
if (e == null) {
92+
93+
Log.i("Info", "Anonymous login successful");
94+
95+
} else {
96+
97+
Log.i("Info", "Anonymous login failed");
98+
99+
}
100+
101+
102+
}
103+
});
104+
105+
} else {
106+
107+
if (ParseUser.getCurrentUser().get("riderOrDriver") != null) {
108+
109+
Log.i("Info", "Redirecting as " + ParseUser.getCurrentUser().get("riderOrDriver"));
110+
111+
redirectActivity();
112+
113+
}
114+
115+
116+
}
117+
ParseAnalytics.trackAppOpenedInBackground(getIntent());
118+
119+
}
120+
}

0 commit comments

Comments
 (0)