Skip to content
Snippets Groups Projects
Commit 35bf03d8 authored by chan24's avatar chan24
Browse files

profile saved to database

parent d6a1fc2a
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chan24.smartplanner">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
......
......@@ -16,6 +16,7 @@ import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
......@@ -28,7 +29,6 @@ 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.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
......@@ -49,7 +49,8 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
String dining;
String supermarket;
int distance;
String type;
double latitude;
double longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -77,34 +78,55 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
supermarket=i.getStringExtra("supermarket");
distance= Integer.parseInt(i.getStringExtra("distance"));
StringBuilder typeBuilder=new StringBuilder();
Button sh=(Button)findViewById(R.id.shopping);
if (shopping.contentEquals("yes")){
typeBuilder.append("shopping_mall");
if (dining.contentEquals("yes")){
typeBuilder.append("_or_restaurant");
sh.setEnabled(true);
}
else{
sh.setEnabled(false);
}
Button s=(Button)findViewById(R.id.supermarket);
if (supermarket.contentEquals("yes")){
typeBuilder.append("_or_department_store");
s.setEnabled(true);
}
else {
s.setEnabled(false);
}
else{
Button d=(Button)findViewById(R.id.dining);
if (dining.contentEquals("yes")){
typeBuilder.append("restaurant");
if (supermarket.contentEquals("yes")){
typeBuilder.append("_or_department_store");
}
d.setEnabled(true);
}
else {
if (supermarket.contentEquals("yes")){
typeBuilder.append("department_store");
d.setEnabled(false);
}
sh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadNearByPlaces(latitude,longitude,"shopping_mall");
}
});
s.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadNearByPlaces(latitude,longitude,"department_store");
}
});
d.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadNearByPlaces(latitude,longitude,"restaurant");
}
type=typeBuilder.toString();
//Toast.makeText(getApplicationContext(),type,Toast.LENGTH_LONG).show();
});
}
private void showLocationSettings() {
......@@ -178,16 +200,14 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
latitude = location.getLatitude();
longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(latLng).title("My Location"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
loadNearByPlaces(latitude, longitude);
}
@Override
......@@ -205,7 +225,7 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
}
private void loadNearByPlaces(double latitude, double longitude) {
private void loadNearByPlaces(double latitude, double longitude, String type) {
StringBuilder googlePlacesUrl =
new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
......@@ -266,7 +286,6 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
icon = place.getString(ICON);
String t=place.getString("types");
//Toast.makeText(getApplicationContext(),t,Toast.LENGTH_SHORT).show();
MarkerOptions markerOptions = new MarkerOptions();
LatLng latLng = new LatLng(latitude, longitude);
......@@ -292,16 +311,12 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
mMap.addMarker(markerOptions);
}
/*markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
markerOptions.icon((BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
mMap.addMarker(markerOptions);*/
}
Toast.makeText(getBaseContext(), jsonArray.length() + " Supermarkets found!",Toast.LENGTH_LONG).show();
Toast.makeText(getBaseContext(), jsonArray.length() + " places found!",Toast.LENGTH_LONG).show();
} else if (result.getString(STATUS).equalsIgnoreCase(ZERO_RESULTS)) {
Toast.makeText(getBaseContext(), "No Supermarket found in 5KM radius!!!",
Toast.makeText(getBaseContext(), "No places found in "+distance+"m radius!!!",
Toast.LENGTH_LONG).show();
}
......
package com.example.chan24.smartplanner;
import android.content.Intent;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
......@@ -8,11 +9,15 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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 ProfileActivity extends AppCompatActivity {
......@@ -33,11 +38,82 @@ public class ProfileActivity extends AppCompatActivity {
startActivity(i);
}
});
firebaseAuth=FirebaseAuth.getInstance();
user=firebaseAuth.getCurrentUser();
databaseReference=FirebaseDatabase.getInstance().getReference().child("Profile").child(user.getUid()).child("Username");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String s=dataSnapshot.getValue().toString();
TextView u=(TextView)findViewById(R.id.userName);
u.setText(s);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}});
databaseReference=FirebaseDatabase.getInstance().getReference().child("Profile").child(user.getUid()).child("Age");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String s= dataSnapshot.getValue().toString();
TextView a=(TextView)findViewById(R.id.age);
a.setText(s);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}});
databaseReference=FirebaseDatabase.getInstance().getReference().child("Profile").child(user.getUid()).child("Gender");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String s= dataSnapshot.getValue().toString();
RadioButton rb =(RadioButton)findViewById(R.id.female);
RadioButton rb1 =(RadioButton)findViewById(R.id.male);
if (rb.getText().toString().contentEquals(s) ){
rb.setChecked(true);
}
else if (rb1.getText().toString().contentEquals(s)){
rb1.setChecked(true);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
databaseReference=FirebaseDatabase.getInstance().getReference().child("Profile").child(user.getUid()).child("Phone");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String s=dataSnapshot.getValue().toString();
TextView p=(TextView)findViewById(R.id.phone);
p.setText(s);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}});
}
public void save(View view)
{
/*EditText age = (EditText)findViewById(R.id.age);
EditText age = (EditText)findViewById(R.id.age);
RadioGroup gender =(RadioGroup)findViewById(R.id.gender);
EditText phone = (EditText)findViewById(R.id.phone);
RadioButton selectedRadioButton;
......@@ -56,6 +132,8 @@ public class ProfileActivity extends AppCompatActivity {
DatabaseReference databaseReference2=FirebaseDatabase.getInstance().getReference().child("Profile").child(user.getUid()).child("Gender");
databaseReference2.setValue(g);
DatabaseReference databaseReference3=FirebaseDatabase.getInstance().getReference().child("Profile").child(user.getUid()).child("Phone");
databaseReference3.setValue(p);*/
databaseReference3.setValue(p);
startActivity(new Intent(getApplicationContext(),UserArea.class));
}
}
......@@ -61,7 +61,6 @@ public class UserArea extends AppCompatActivity {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
s=dataSnapshot.getValue().toString();
//Toast.makeText(getApplicationContext(),s,Toast.LENGTH_SHORT).show();
TextView t=(TextView)findViewById(R.id.textView2);
t.setText("Welcome "+s);
}
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="500dp"
android:fitsSystemWindows="true"
tools:context=".MapsActivity">
......@@ -13,8 +15,53 @@
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="500dp"
tools:context="com.example.chan24.smartplanner.MapsActivity" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/mainCoordinatorLayout">
<Button
android:id="@+id/shopping"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shopping"
android:layout_alignParentBottom="true"
android:layout_alignEnd="@+id/supermarket"
/>
<Button
android:id="@+id/dining"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dining"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@+id/shopping"
android:layout_marginStart="46dp"
/>
<Button
android:id="@+id/supermarket"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Supermarket"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
/>
</LinearLayout>
</RelativeLayout>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment