From 9ae2d45f2d30939627eabded4ec0165ae6587739 Mon Sep 17 00:00:00 2001 From: mohnalkhateeb Date: Wed, 1 Dec 2021 23:14:18 +0200 Subject: [PATCH 1/2] addmap --- .idea/deploymentTargetDropDown.xml | 4 +- .idea/misc.xml | 1 + amplify/.config/project-config.json | 8 +- amplify/README.md | 8 - app/build.gradle | 7 + app/src/main/AndroidManifest.xml | 17 ++ .../java/com/example/thrifty/GPSTracker.java | 188 ++++++++++++++++++ .../com/example/thrifty/MainActivity.java | 7 + .../com/example/thrifty/MapsActivity.java | 62 ++++++ .../java/com/example/thrifty/Tracking.java | 68 +++++++ .../main/res/drawable-v24/userplaceholder.png | Bin 0 -> 2241 bytes app/src/main/res/layout/activity_main.xml | 10 + app/src/main/res/layout/activity_maps.xml | 7 + app/src/main/res/layout/activity_tracking.xml | 73 +++++++ build.gradle | 2 +- 15 files changed, 447 insertions(+), 15 deletions(-) delete mode 100644 amplify/README.md create mode 100644 app/src/main/java/com/example/thrifty/GPSTracker.java create mode 100644 app/src/main/java/com/example/thrifty/MapsActivity.java create mode 100644 app/src/main/java/com/example/thrifty/Tracking.java create mode 100644 app/src/main/res/drawable-v24/userplaceholder.png create mode 100644 app/src/main/res/layout/activity_maps.xml create mode 100644 app/src/main/res/layout/activity_tracking.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index b40952a..6922eb8 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -7,11 +7,11 @@ - + - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 28966ce..747dd37 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -26,6 +26,7 @@ + diff --git a/amplify/.config/project-config.json b/amplify/.config/project-config.json index 8119c68..a1ed03a 100644 --- a/amplify/.config/project-config.json +++ b/amplify/.config/project-config.json @@ -1,4 +1,7 @@ { + "providers": [ + "awscloudformation" + ], "projectName": "thrifty", "version": "3.1", "frontend": "android", @@ -6,8 +9,5 @@ "config": { "ResDir": "app/src/main/res" } - }, - "providers": [ - "awscloudformation" - ] + } } \ No newline at end of file diff --git a/amplify/README.md b/amplify/README.md deleted file mode 100644 index 7c0a9e2..0000000 --- a/amplify/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Getting Started with Amplify CLI -This directory was generated by [Amplify CLI](https://docs.amplify.aws/cli). - -Helpful resources: -- Amplify documentation: https://docs.amplify.aws -- Amplify CLI documentation: https://docs.amplify.aws/cli -- More details on this folder & generated files: https://docs.amplify.aws/cli/reference/files -- Join Amplify's community: https://amplify.aws/community/ diff --git a/app/build.gradle b/app/build.gradle index a5e0539..550a404 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -97,6 +97,13 @@ dependencies { // location implementation 'com.google.android.gms:play-services-location:18.0.0' implementation 'com.google.android.gms:play-services-maps:18.0.0' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support.constraint:constraint-layout:2.0.4' + implementation 'com.google.firebase:firebase-database:20.0.3' + implementation 'com.google.firebase:firebase-auth:21.0.1' + implementation 'com.google.android.gms:play-services-maps:18.0.0' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e829941..0188bef 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,14 @@ + + + + + + + + + + + diff --git a/app/src/main/java/com/example/thrifty/GPSTracker.java b/app/src/main/java/com/example/thrifty/GPSTracker.java new file mode 100644 index 0000000..b00cfdb --- /dev/null +++ b/app/src/main/java/com/example/thrifty/GPSTracker.java @@ -0,0 +1,188 @@ +package com.example.thrifty; + +import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.app.Service; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.os.IBinder; +import android.provider.Settings; + +/** + * Created by tulsi on 4/7/2018. + */ +public class GPSTracker extends Service implements LocationListener { + + private final Context mContext; + + // flag for GPS status + boolean isGPSEnabled = false; + // flag for GPS status + boolean canGetLocation = false; + Location location; // location + double latitude; // latitude + double longitude; // longitude + + // The minimum distance to change Updates in meters + private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters + + // The minimum time between updates in milliseconds + private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute + + // Declaring a Location Manager + protected LocationManager locationManager; + + public GPSTracker(Context context) { + this.mContext = context; + getLocation(); + } + + @SuppressLint("MissingPermission") + public Location getLocation() { + try { + locationManager = (LocationManager) mContext + .getSystemService(LOCATION_SERVICE); + // getting GPS status + isGPSEnabled = locationManager + .isProviderEnabled(LocationManager.GPS_PROVIDER); + + // if GPS Enabled get lat/long using GPS Services + if (isGPSEnabled) { + this.canGetLocation = true; + if (location == null) { + locationManager.requestLocationUpdates( + LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, + MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + if (locationManager != null) { + location = locationManager + .getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return location; + } + + /** + * Stop using GPS listener Calling this function will stop using GPS in your + * app + * */ + public void stopUsingGPS() { + if (locationManager != null) { + locationManager.removeUpdates(GPSTracker.this); + } + } + + /** + * Function to get latitude + * */ + public double getLatitude() { + if (location != null) { + latitude = location.getLatitude(); + } + + // return latitude + return latitude; + } + + /** + * Function to get longitude + * */ + public double getLongitude() { + if (location != null) { + longitude = location.getLongitude(); + } + + // return longitude + return longitude; + } + + /** + * Function to check GPS/wifi enabled + * + * @return boolean + * */ + public boolean canGetLocation() { + return this.canGetLocation; + } + + /** + * Function to show settings alert dialog On pressing Settings button will + * lauch Settings Options + * */ + public void showSettingsAlert() { + AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext); + + // Setting Dialog Title + alertDialog.setTitle("GPS is settings"); + + // Setting Dialog Message + alertDialog + .setMessage("GPS is not enabled. Do you want to go to settings menu?"); + + // On pressing Settings button + alertDialog.setPositiveButton("Settings", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent( + Settings.ACTION_LOCATION_SOURCE_SETTINGS); + mContext.startActivity(intent); + } + }); + + // on pressing cancel button + alertDialog.setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + + // Showing Alert Message + alertDialog.show(); + } + + @Override + public void onLocationChanged(Location arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onProviderDisabled(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onProviderEnabled(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onStatusChanged(String arg0, int arg1, Bundle arg2) { + // TODO Auto-generated method stub + + } + + @Override + public IBinder onBind(Intent arg0) { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/thrifty/MainActivity.java b/app/src/main/java/com/example/thrifty/MainActivity.java index 03cfcde..2b38ad8 100644 --- a/app/src/main/java/com/example/thrifty/MainActivity.java +++ b/app/src/main/java/com/example/thrifty/MainActivity.java @@ -93,6 +93,13 @@ public void onClick(View view) { startActivity(intent); } }); + findViewById(R.id.map).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(MainActivity.this, Tracking.class); + startActivity(intent); + } + }); } diff --git a/app/src/main/java/com/example/thrifty/MapsActivity.java b/app/src/main/java/com/example/thrifty/MapsActivity.java new file mode 100644 index 0000000..55ba192 --- /dev/null +++ b/app/src/main/java/com/example/thrifty/MapsActivity.java @@ -0,0 +1,62 @@ +package com.example.thrifty; + +import android.os.Bundle; + +import androidx.fragment.app.FragmentActivity; + +import com.google.android.gms.maps.CameraUpdate; +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.MarkerOptions; + +public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { + + private GoogleMap mMap; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_maps); + // 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; + + // Add a marker in Sydney and move the camera + LatLng sydney = new LatLng(37.391219,-121.930); + MarkerOptions marker = new MarkerOptions().position(sydney).title("Anuradha Rajashekar"); + marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.userplaceholder)); + mMap.addMarker(marker); + // mMap.addMarker(new MarkerOptions().position(sydney).title("Anuradha's location")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); + mMap.animateCamera(CameraUpdateFactory.zoomTo(17.0f)); + + /* LatLng location2 = new LatLng(37.402276,-121.942161); + mMap.addMarker(new MarkerOptions().position(location2).title("Anuradha's new location")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(location2));*/ + + //zoom into a particular position + CameraUpdate zoom = CameraUpdateFactory.zoomTo(12); + mMap.moveCamera(zoom); + mMap.animateCamera(zoom); + } +} diff --git a/app/src/main/java/com/example/thrifty/Tracking.java b/app/src/main/java/com/example/thrifty/Tracking.java new file mode 100644 index 0000000..ac5fea2 --- /dev/null +++ b/app/src/main/java/com/example/thrifty/Tracking.java @@ -0,0 +1,68 @@ +package com.example.thrifty; + +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; + +public class Tracking extends AppCompatActivity { + + private Button btnShowLocation,btnshowMap; + FirebaseDatabase database; + DatabaseReference myRef; + + private static final int REQUEST_CODE_PERMISSION =2; + String mPermission = android.Manifest.permission.ACCESS_FINE_LOCATION; + GPSTracker gps; + TextView location; + String value =null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_tracking); + + try{ + if (ActivityCompat.checkSelfPermission(this,mPermission)!= PackageManager.PERMISSION_GRANTED){ + ActivityCompat.requestPermissions(this,new String[]{mPermission},REQUEST_CODE_PERMISSION); + } + }catch (Exception e){ + e.printStackTrace(); + } + btnShowLocation=(Button)findViewById(R.id.button); + btnshowMap=(Button)findViewById(R.id.button2); + btnShowLocation.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + gps = new GPSTracker(Tracking.this); + location=(TextView)findViewById(R.id.Location); + if (gps.canGetLocation()){ + double latitude = gps.getLatitude(); + double longitude = gps.getLongitude(); + database = FirebaseDatabase.getInstance(); + location.setText(latitude+""+longitude); + myRef = database.getReference("Location"); + myRef.setValue(latitude+","+longitude); + }else{ + gps.showSettingsAlert(); + } + } + + }); + } + + public void Map(View view){ + + + Intent intent=new Intent(getApplicationContext(),MapsActivity.class); + startActivity(intent); + } +} diff --git a/app/src/main/res/drawable-v24/userplaceholder.png b/app/src/main/res/drawable-v24/userplaceholder.png new file mode 100644 index 0000000000000000000000000000000000000000..62ad490faaafc30e378b881881ffc0d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