diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000000000000000000000000000000000..28d5863a9a331f42e1b6c059d4f7f3d385f6978a --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ +<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + <inspection_tool class="AndroidLintLongLogTag" enabled="false" level="ERROR" enabled_by_default="false" /> + <inspection_tool class="ResourceType" enabled="false" level="ERROR" enabled_by_default="false" /> + </profile> +</component> \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..3b312839bf2e939fea3ebdef15630a4b33e57caf --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ +<component name="InspectionProjectProfileManager"> + <settings> + <option name="PROJECT_PROFILE" value="Project Default" /> + <option name="USE_PROJECT_PROFILE" value="true" /> + <version value="1.0" /> + </settings> +</component> \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 08aae018d44cb79246c0c40c4e5f1c2d36881734..c81f84863abca60300a4c4f24dfb178829fc5b35 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,5 +25,6 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.1' + compile 'com.google.android.gms:play-services-maps:10.2.1' testCompile 'junit:junit:4.12' } diff --git a/app/src/debug/res/values/google_maps_api.xml b/app/src/debug/res/values/google_maps_api.xml new file mode 100644 index 0000000000000000000000000000000000000000..d1c04c36b87d4f0deb0f82335d39755d10c1b3cd --- /dev/null +++ b/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,26 @@ +<resources> + <!-- + TODO: Before you run your application, you need a Google Maps API key. + + To get one, follow this link, follow the directions and press "Create" at the end: + + https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=7C:8A:3C:0D:F3:30:A2:61:C6:0E:E4:DC:2D:4E:09:A2:47:20:32:20%3Bcom.speedyapps.keepyousafe + + You can also add your credentials to an existing key, using these values: + + Package name: + 7C:8A:3C:0D:F3:30:A2:61:C6:0E:E4:DC:2D:4E:09:A2:47:20:32:20 + + SHA-1 certificate fingerprint: + 7C:8A:3C:0D:F3:30:A2:61:C6:0E:E4:DC:2D:4E:09:A2:47:20:32:20 + + Alternatively, follow the directions here: + https://developers.google.com/maps/documentation/android/start#get-key + + Once you have your key (it starts with "AIza"), replace the "google_maps_key" + string in this file. + --> + <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> + AIzaSyB3bf-8bbz85sz0ZejHkGN4GXigr-oUSxk + </string> +</resources> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9a5929360422a46853c2aefa256c2b62c41903a9..55459180993e5fc65613e3f84058b45f50f3cb16 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,19 +6,21 @@ <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> - <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> + <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> - <application android:allowBackup="true" android:icon="@mipmap/kms" android:label="@string/app_name" android:supportsRtl="true" + android:theme="@style/MyTheme"> - <activity android:name=".MainActivity"> + <activity android:name=".MainActivity" + android:screenOrientation="portrait"> + <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -26,24 +28,36 @@ </intent-filter> </activity> - <service - android:name=".alarmService" - android:enabled="true" - android:exported="true" /> - <receiver android:name=".SMSReader$readSMS"> - <intent-filter> + + <receiver android:name=".SMSManager" android:exported="true" > + <intent-filter android:priority="999" > <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> - <service - android:name=".SMSReader" - android:enabled="true" - android:exported="true" /> - <activity android:name=".ContactSelection" /> - <activity android:name=".confirmationScreen"></activity> + <activity android:name=".ContactSelection" + android:screenOrientation="portrait"/> + <activity android:name=".confirmationScreen" + android:screenOrientation="portrait"/> + <!-- + The API key for Google Maps-based APIs is defined as a string resource. + (See the file "res/values/google_maps_api.xml"). + Note that the API key is linked to the encryption key used to sign the APK. + You need a different API key for each encryption key, including the release key that is used to + sign the APK for publishing. + You can define the keys for the debug and release targets in src/debug/ and src/release/. + --> + <meta-data + android:name="com.google.android.geo.API_KEY" + android:value="@string/google_maps_key" /> + + <activity + android:name=".MapsActivity" + android:label="@string/title_activity_maps" /> + + </application> </manifest> \ No newline at end of file diff --git a/app/src/main/java/com/speedyapps/keepyousafe/GpsTool.java b/app/src/main/java/com/speedyapps/keepyousafe/GpsTool.java deleted file mode 100644 index c92f97271e8b8e8a21f850b2cbd62cdda627cc14..0000000000000000000000000000000000000000 --- a/app/src/main/java/com/speedyapps/keepyousafe/GpsTool.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.speedyapps.keepyousafe; - -/** - * Created by SUBASH on 18-04-2017. - */ - -import android.content.Context; -import android.content.Intent; -import android.location.Location; -import android.location.LocationListener; -import android.location.LocationManager; -import android.os.Bundle; -import android.provider.Settings; - -/** - * Created by pethoalpar on 4/13/2016. - */ -public class GpsTool { - - String locationProvider = LocationManager.GPS_PROVIDER; - private LocationManager locationManager; - private LocationListener locationListener; - - public GpsTool(Context context){ - locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - this.turnOnGps(context); - locationListener = new LocationListener() { - @Override - public void onLocationChanged(Location location) { - onGpsLocationChanged(location); - location.reset(); - } - - @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - onGpsStatusChanged(provider, status, extras); - } - - @Override - public void onProviderEnabled(String provider) { - onGpsProviderEnabled(provider); - } - - @Override - public void onProviderDisabled(String provider) { - onGpsProviderDisabled(provider); - } - }; - startGpsUpdate(); - } - - public void onGpsLocationChanged(Location location) { - //Location change. - } - - public void onGpsStatusChanged(String provider, int status, Bundle extras) { - - } - - public void onGpsProviderEnabled(String provider) { - - } - - public void onGpsProviderDisabled(String provider) { - - } - - public Location getLocation(){ - return locationManager.getLastKnownLocation(locationProvider); - } - - public void startGpsUpdate(){ - locationManager.requestLocationUpdates(locationProvider, 1000, 0, locationListener); - } - - public void stopGpsUpdate(){ - locationManager.removeUpdates(locationListener); - } - - public void turnOnGps(Context context){ - boolean isEnabled = locationManager.isProviderEnabled(locationProvider); - if(!isEnabled){ - Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); - context.startActivity(intent); - } - } -} diff --git a/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java b/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java index a48e940f833185d5c082e229cd53a3ce47e7255e..024306ede0f969b6a44bfec2e8168234dc9c16cd 100644 --- a/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java +++ b/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java @@ -27,8 +27,7 @@ import java.util.List; public class MainActivity extends AppCompatActivity { Intent intent; int choice; - private TextView textView; - private GpsTool gpsTool; + MapsActivity maps ; SharedPreferences firsttime; private static final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 291; int backCount=0; @@ -38,6 +37,7 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); requestPermissionsApp(); + maps=new MapsActivity(); firsttime = this.getSharedPreferences("firsttimecheck",MODE_PRIVATE); SharedPreferences.Editor editor = firsttime.edit(); String checkString = firsttime.getString("status","false"); @@ -57,8 +57,8 @@ public class MainActivity extends AppCompatActivity { } intent = new Intent(MainActivity.this,confirmationScreen.class); choice=0; - Intent serviceIntent = new Intent(MainActivity.this,SMSReader.class); - startService(serviceIntent); + //Intent serviceIntent = new Intent(MainActivity.this,SMSReader.class); + //startService(serviceIntent); ImageButton help = (ImageButton)findViewById(R.id.helpButton); help.setOnLongClickListener(new View.OnLongClickListener(){ public boolean onLongClick(View v){ @@ -69,23 +69,7 @@ public class MainActivity extends AppCompatActivity { } }); - - textView = (TextView) this.findViewById(R.id.loc); - if (gpsTool == null) { - gpsTool = new GpsTool(this) { - @Override - public void onGpsLocationChanged(Location location) { - super.onGpsLocationChanged(location); - refreshLocation(location); - } - }; - } - - } - - - - + } public void contact(View v) { backCount=0; @@ -161,18 +145,18 @@ public class MainActivity extends AppCompatActivity { sb.append("Longitude:").append(longitude).append("\n"); sb.append("Latitude:").append(latitude).append("\n"); sb.append("Altitude:").append(altitude); - textView.setText(sb.toString()); + Intent intent = new Intent(MainActivity.this,MapsActivity.class); + startActivity(intent); + } @Override protected void onPause() { super.onPause(); - gpsTool.stopGpsUpdate(); } @Override protected void onResume() { super.onResume(); - gpsTool.startGpsUpdate(); } } diff --git a/app/src/main/java/com/speedyapps/keepyousafe/MapsActivity.java b/app/src/main/java/com/speedyapps/keepyousafe/MapsActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..3e64233c0c98b5c158fbf1ecffa3e83ec458b831 --- /dev/null +++ b/app/src/main/java/com/speedyapps/keepyousafe/MapsActivity.java @@ -0,0 +1,83 @@ +package com.speedyapps.keepyousafe; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Handler; +import android.support.v4.app.FragmentActivity; +import android.os.Bundle; +import android.widget.Toast; + +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.CircleOptions; +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; + SharedPreferences sp; + Double latitude,longitude; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_maps); + sp=getSharedPreferences("locationinfo",MODE_PRIVATE); + // 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); + final Handler handler = new Handler(); + + Runnable run = new Runnable() { + @Override + public void run() { + if(Double.parseDouble(sp.getString("latitude","0.0"))!=latitude&&!(sp.getString("latitude","null").equals("null"))) { + Toast.makeText(MapsActivity.this, "Calling updateMap", Toast.LENGTH_SHORT).show(); + updateLocation(); + handler.postDelayed(this, 1000); + } + } + }; + handler.post(run); + } + + @Override + protected void onStart() { + super.onStart(); + sp.edit().putString("status","running").commit(); + } + + @Override + protected void onStop() { + super.onStop(); + sp.edit().putString("status","stopped").commit(); + } + + @Override + protected void onPause() { + super.onPause(); + sp.edit().putString("status","paused").commit(); + } + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + updateLocation(); + } + + public void updateLocation(){ + latitude=Double.parseDouble(sp.getString("latitude","0.00")); + longitude=Double.parseDouble(sp.getString("longitude","0.00")); + Toast.makeText(this, ""+latitude+longitude, Toast.LENGTH_SHORT).show(); + if(latitude!=0.00) { + LatLng currentLocation = new LatLng(latitude,longitude); + mMap.addMarker(new MarkerOptions().position(currentLocation).title("Last known Location !")); + mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),18)); + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),18)); + } + } +} diff --git a/app/src/main/java/com/speedyapps/keepyousafe/SMSManager.java b/app/src/main/java/com/speedyapps/keepyousafe/SMSManager.java new file mode 100644 index 0000000000000000000000000000000000000000..20bff8952fe46246c8b28cee507af671b721e0ee --- /dev/null +++ b/app/src/main/java/com/speedyapps/keepyousafe/SMSManager.java @@ -0,0 +1,68 @@ +package com.speedyapps.keepyousafe; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.Handler; +import android.telephony.SmsMessage; +import android.util.Log; +import android.widget.Toast; + +public class SMSManager extends BroadcastReceiver { + private String TAG = SMSManager.class.getSimpleName(); + String latitudepart=null,longitudepart=null; + Double latitude,longitude; + SharedPreferences sp; + public SMSManager() { + } + @Override + public void onReceive(Context context, Intent intent) { + // Get the data (SMS data) bound to intent + Bundle bundle = intent.getExtras(); + SmsMessage[] msgs = null; + Toast.makeText(context, "OK", Toast.LENGTH_SHORT).show(); + sp=context.getSharedPreferences("locationinfo",Context.MODE_PRIVATE); + sp.edit().putString("status","stoped").commit(); + String str = "",sender=""; + + if (bundle != null) { + // Retrieve the SMS Messages received + Object[] pdus = (Object[]) bundle.get("pdus"); + msgs = new SmsMessage[pdus.length]; + + // For every SMS message received + for (int i=0; i < msgs.length; i++) { + // Convert Object array + msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); + // Sender's phone number + sender += msgs[i].getOriginatingAddress(); + // Fetch the text message + str += msgs[i].getMessageBody().toString(); + // Newline <img draggable="false" class="emoji" alt="🙂" src="https://s.w.org/images/core/emoji/72x72/1f642.png"> + str += "\n"; + } + Toast.makeText(context, "`Sender : "+sender+" Message : "+str, Toast.LENGTH_SHORT).show(); + } + + if(str.contains("Help Me!!!!")){ + //myContext.startService(alarm); + String[] coordinates = str.split(">"); + latitudepart=coordinates[1].split(",")[0]; + longitudepart=coordinates[1].split(",")[1]; + sp.edit().putString("latitude",latitudepart).putString("longitude",longitudepart).commit(); + Log.i("lat","lat"+latitudepart); + Intent mapsIntent = new Intent(context, MapsActivity.class); + //mapsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mapsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); +// if(!sp.getString("status","null").equals("running")) { + context.startActivity(mapsIntent); +// } +// if(sp.getString("status","null").equals("paused")){ +// context.stopService(mapsIntent); + context.startActivity(mapsIntent); + } + } + } + diff --git a/app/src/main/java/com/speedyapps/keepyousafe/SMSReader.java b/app/src/main/java/com/speedyapps/keepyousafe/SMSReader.java index 89afd79a5215be47fde52a2dc0da8c1d5fcbfe67..84102b67269cff2c32093575dd02cf253ac51e04 100644 --- a/app/src/main/java/com/speedyapps/keepyousafe/SMSReader.java +++ b/app/src/main/java/com/speedyapps/keepyousafe/SMSReader.java @@ -28,52 +28,50 @@ public class SMSReader extends Service { // TODO: Return the communication channel to the service. throw new UnsupportedOperationException("Not yet implemented"); } - public static class readSMS extends BroadcastReceiver{ + public class readSMS extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { - final SmsManager sms = SmsManager.getDefault(); final Intent alarm = new Intent(myContext,alarmService.class); // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); - - try { - + Toast.makeText(context, "Received Message", Toast.LENGTH_SHORT).show(); if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); - for (int i = 0; i < pdusObj.length; i++) { - SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); - String phoneNumber = currentMessage.getDisplayOriginatingAddress(); - - String senderNum = phoneNumber; - String message = currentMessage.getDisplayMessageBody(); - - Log.d("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message); + SmsMessage rcvdmsg =null; + String message = null; + for(int p=0;p<pdusObj.length;p++){ + rcvdmsg=SmsMessage.createFromPdu((byte[])pdusObj[p]); + } + byte[] data=null; + data=rcvdmsg.getUserData(); + if(data!=null){ + for(int index=0;index<data.length;index++){ + message+=Character.toString((char)data[index]); + } + } int count=0; Handler handler = new Handler(); - if(message.equals("Help Me!!!!")){ - myContext.startService(alarm); - handler.postDelayed(new Runnable() { - public void run() { - myContext.stopService(alarm); - - } - },5000); + if(message.contains("Help Me!!!!")){ + //myContext.startService(alarm); + String[] coordinates = message.split(">"); + String latitudepart=coordinates[1].split(",")[0]; + String longitudepart=coordinates[1].split(",")[1]; + Log.i("lat","lat"+latitudepart); + Intent mapsIntent = new Intent(myContext,MapsActivity.class); + mapsIntent.putExtra("latitude",Double.parseDouble(latitudepart)); + mapsIntent.putExtra("longitude",Double.parseDouble(longitudepart)); + startActivity(mapsIntent); } // Show alert int duration = Toast.LENGTH_LONG; } // end for loop } // bundle is null - - } catch (Exception e) { - Log.e("SmsReceiver", "Exception smsReceiver" +e); - } } } -} diff --git a/app/src/main/java/com/speedyapps/keepyousafe/alarmService.java b/app/src/main/java/com/speedyapps/keepyousafe/alarmService.java index e523c97036ff5f2d057f51af61c79bc9789c85b1..1df06dd243336baa2b97e56520c7772f3c8e007d 100644 --- a/app/src/main/java/com/speedyapps/keepyousafe/alarmService.java +++ b/app/src/main/java/com/speedyapps/keepyousafe/alarmService.java @@ -39,7 +39,6 @@ public class alarmService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { mediaPlayer.start(); - forceFullVolume(); return super.onStartCommand(intent, flags, startId); } diff --git a/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java b/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java index f6e56e10c8d6874b525703a6cb67cbe0e353f491..358ef5e48a65031e4e0e62a8ef9d69c02520095d 100644 --- a/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java +++ b/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java @@ -1,9 +1,24 @@ package com.speedyapps.keepyousafe; +import android.Manifest; +import android.app.Activity; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.location.Criteria; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.location.LocationProvider; import android.os.Handler; +import android.provider.Settings; +import android.support.v4.app.ActivityCompat; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.telephony.SmsManager; @@ -15,94 +30,265 @@ import android.widget.Toast; import org.w3c.dom.Text; -public class confirmationScreen extends AppCompatActivity { - TextView textView ; - EditText editText ; - SharedPreferences sharedpreferences,sp,shared; - String n,n1; - int count,i; +import java.util.List; + +public class confirmationScreen extends AppCompatActivity implements LocationListener { + + public static int SMS_SEND_INTERVAL=2000; + LocationManager locationManager; + TextView textView; + EditText editText; + Double latitude = null, longitude = null,newlat=null,newlong=null; + Handler timehandler; + SharedPreferences sharedpreferences, sp, shared; + String n; + String n1; + LocationProvider provider; + int count, i; public static String file1 = "MyPREFERENCES"; public static String file2 = "PREFERENCES"; public static String file3 = "COUNT"; - Handler handler,handler2; - Intent alarmIntent ; - Runnable run,run2; + Handler handler, handler2; + Runnable run, run2,run3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_confirmation_screen); - handler=new Handler(); + locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + provider = locationManager.getProvider(LocationManager.GPS_PROVIDER); + Toast.makeText(this, "Provider"+provider, Toast.LENGTH_SHORT).show(); + handler = new Handler(); handler2 = new Handler(); - alarmIntent = new Intent(confirmationScreen.this,alarmService.class); - textView= (TextView)findViewById(R.id.countDown); - editText=(EditText)findViewById(R.id.editTextPIN); + timehandler = new Handler(); + //alarmIntent = new Intent(confirmationScreen.this, alarmService.class); + textView = (TextView) findViewById(R.id.countDown); + editText = (EditText) findViewById(R.id.editTextPIN); sharedpreferences = getSharedPreferences(file1, Context.MODE_PRIVATE); sp = getSharedPreferences(file2, Context.MODE_PRIVATE); shared = getSharedPreferences(file3, Context.MODE_PRIVATE); - i=10; + i = 10; run = new Runnable() { @Override public void run() { - textView.setText(""+i); - if((i--)<=0){ + textView.setText("" + i); + if ((i) == 0) { + Toast.makeText(confirmationScreen.this, "distress called", Toast.LENGTH_SHORT).show(); distressCall(); handler.removeCallbacks(this); + } else{ + i--; + if(i<=0) + i=0; + handler.postDelayed(this, 100); } - else - handler.postDelayed(this,1000); } }; - - run2=new Runnable() { + handler.post(run); + run2 = new Runnable() { @Override public void run() { - if(editText.getText().toString().equals("2020")){ - stopService(alarmIntent); + if (editText.getText().toString().equals("2020")) { + //stopService(alarmIntent); handler.removeCallbacks(run); handler2.removeCallbacks(this); + timehandler.removeCallbacks(run3); Toast.makeText(confirmationScreen.this, "Distress Calls Cancelled!", Toast.LENGTH_SHORT).show(); - Intent main = new Intent(confirmationScreen.this,MainActivity.class); + Intent main = new Intent(confirmationScreen.this, MainActivity.class); startActivity(main); finish(); - } - else - handler2.postDelayed(this,100); + } else + handler2.postDelayed(this, 100); } }; - handler.post(run); handler2.post(run2); - } - public void distressCall(){ - startService(alarmIntent); + public void distressCall() { + // startService(alarmIntent); + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } + Location location = getLastKnownLocation(); + Toast.makeText(this, "Initial Location var : "+location.getLatitude()+location.getLongitude(), Toast.LENGTH_SHORT).show(); + if(location!=null){ + latitude=location.getLatitude(); + longitude=location.getLongitude(); count = shared.getInt("count", 0); Log.d("COUNT", String.valueOf(count)); - for (int i = 1; i <= count; i++) - { + for (int i = 1; i <= count; i++) { n1 = sp.getString("value" + i, ""); n = sharedpreferences.getString(n1, ""); - Log.d("sub",n); - try - { - if(!(n.isEmpty())) - { - sendSMS(n, "Help Me!!!!"); + Log.d("sub", n); + try { + if (!(n.isEmpty())) { + sendSMS(n, "Help Me!!!!>" + latitude + "," + longitude); } + } catch (Exception e) { } - catch (Exception e){} } + } + + run3 = new Runnable() { + @Override + public void run() { + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(confirmationScreen.this, "Old longitude :"+longitude+" New Longitude : "+newlong, Toast.LENGTH_SHORT).show(); + } + }); + if (longitude != newlong && newlong != null) { + count = shared.getInt("count", 0); + Log.d("COUNT", String.valueOf(count)); + for (int i = 1; i <= count; i++) { + n1 = sp.getString("value" + i, ""); + n = sharedpreferences.getString(n1, ""); + Log.d("sub", n); + try { + if (!(n.isEmpty())) { + sendSMS(n, "Help Me!!!!>" + newlat + "," + newlong); + } + } catch (Exception e) { + } + } + latitude=newlat; + longitude=newlong; + } + timehandler.postDelayed(this, SMS_SEND_INTERVAL); + } + }; + timehandler.postDelayed(run3,SMS_SEND_INTERVAL); + } + public void sendSMS(String phoneNumber, String message) { - SmsManager sms = SmsManager.getDefault(); - sms.sendTextMessage(phoneNumber, null, message, null, null); + + String SMS_SENT = "SMS_SENT"; + String SMS_DELIVERED = "SMS_DELIVERED"; + + PendingIntent sentPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMS_SENT), 0); + PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMS_DELIVERED), 0); + +// For when the SMS has been sent + registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + switch (getResultCode()) { + case Activity.RESULT_OK: + Toast.makeText(context, "SMS sent successfully", Toast.LENGTH_SHORT).show(); + break; + case SmsManager.RESULT_ERROR_GENERIC_FAILURE: + Toast.makeText(context, "Generic failure cause", Toast.LENGTH_SHORT).show(); + break; + case SmsManager.RESULT_ERROR_NO_SERVICE: + Toast.makeText(context, "Service is currently unavailable", Toast.LENGTH_SHORT).show(); + break; + case SmsManager.RESULT_ERROR_NULL_PDU: + Toast.makeText(context, "No pdu provided", Toast.LENGTH_SHORT).show(); + break; + case SmsManager.RESULT_ERROR_RADIO_OFF: + Toast.makeText(context, "Radio was explicitly turned off", Toast.LENGTH_SHORT).show(); + break; + } + } + }, new IntentFilter(SMS_SENT)); + +// For when the SMS has been delivered + registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + switch (getResultCode()) { + case Activity.RESULT_OK: + Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show(); + break; + case Activity.RESULT_CANCELED: + Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show(); + break; + } + } + }, new IntentFilter(SMS_DELIVERED)); + +// Get the default instance of SmsManager + SmsManager smsManager = SmsManager.getDefault(); +// Send a text based SMS + smsManager.sendTextMessage(phoneNumber, null, message, sentPendingIntent, deliveredPendingIntent); + } @Override public void onBackPressed() { Toast.makeText(this, "Please Enter the PIN CODE in order to Go Back!!!", Toast.LENGTH_SHORT).show(); } + + @Override + public void onLocationChanged(Location location) { + Toast.makeText(this, "new Location : "+latitude+","+longitude, Toast.LENGTH_SHORT).show(); + newlat=location.getLatitude(); + newlong=location.getLongitude(); + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + + } + + @Override + public void onProviderEnabled(String provider) { + Toast.makeText(this, "Enabled Provider", Toast.LENGTH_SHORT).show(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + handler.removeCallbacks(run); + handler2.removeCallbacks(run2); + timehandler.removeCallbacks(run3); + } + + @Override + public void onProviderDisabled(String provider) { + final AlertDialog.Builder builder = new AlertDialog.Builder(this); + final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS; + final String message = "Please Enable GPS to continue !"; + + builder.setMessage(message) + .setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface d, int id) { + startActivity(new Intent(action)); + d.dismiss(); + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface d, int id) { + d.cancel(); + } + }); + builder.create().show(); + } + private Location getLastKnownLocation() { + List<String> providers = locationManager.getProviders(true); + Location bestLocation = null; + for (String provider : providers) { + Location l = locationManager.getLastKnownLocation(provider); + Log.d("last known location, provider: %s, location: %s", provider+l); + + if (l == null) { + continue; + } + if (bestLocation == null + || l.getAccuracy() < bestLocation.getAccuracy()) { + Log.d("found best last known location: %s", ""+l); + bestLocation = l; + } + } + if (bestLocation == null) { + return null; + } + return bestLocation; + } } diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml new file mode 100644 index 0000000000000000000000000000000000000000..638e8591b41e057d8ab91d7293a48bb24e58c8e6 --- /dev/null +++ b/app/src/main/res/layout/activity_maps.xml @@ -0,0 +1,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="com.speedyapps.keepyousafe.MapsActivity" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2965a0d463b24cbadbb4566fbb7d6dc12174df3..0b1b093893575d411f50c5ca772ebed87339d7fc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ <resources> <string name="app_name">KeepMeSafe</string> + <string name="title_activity_maps">Map</string> </resources> diff --git a/app/src/release/res/values/google_maps_api.xml b/app/src/release/res/values/google_maps_api.xml new file mode 100644 index 0000000000000000000000000000000000000000..fa88c612644439299cf42e81f9ea12e0f6e09598 --- /dev/null +++ b/app/src/release/res/values/google_maps_api.xml @@ -0,0 +1,22 @@ +<resources> + <!-- + TODO: Before you release your application, you need a Google Maps API key. + + To do this, you can either add your release key credentials to your existing + key, or create a new key. + + Note that this file specifies the API key for the release build target. + If you have previously set up a key for the debug target with the debug signing certificate, + you will also need to set up a key for your release certificate. + + Follow the directions here: + + https://developers.google.com/maps/documentation/android/signup + + Once you have your key (it starts with "AIza"), replace the "google_maps_key" + string in this file. + --> + <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> + YOUR_KEY_HERE + </string> +</resources> diff --git a/build.gradle b/build.gradle index 74b2ab0dd88f66079893ee7c77a46dbace4f0fde..1ea4bd05500327c0032ade1bb0cb00e0fa032c22 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:2.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f34080d98841a9fac832466aec720aecec..f9f055493ced214e893c0d3d89396cb325feab03 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Fri Apr 21 13:28:53 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip