diff --git a/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java b/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java index 3f842e36d7f3a4fb3f03406701979f54bb985c1f..fb638ac1eb4bea7c0e5854667827015e6f13edb5 100644 --- a/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java +++ b/app/src/main/java/com/speedyapps/keepyousafe/MainActivity.java @@ -1,9 +1,11 @@ package com.speedyapps.keepyousafe; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.support.annotation.MainThread; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.telephony.SmsManager; @@ -14,12 +16,29 @@ import android.widget.ImageButton; public class MainActivity extends AppCompatActivity { Intent intent; int choice; - + SharedPreferences firsttime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + firsttime = this.getSharedPreferences("firsttimecheck",MODE_PRIVATE); + SharedPreferences.Editor editor = firsttime.edit(); + String checkString = firsttime.getString("status","false"); + if(!checkString.equals("true")){ + editor.putString("status","true"); + editor.apply(); + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.alert_dark_frame) + .setTitle("Instructions!") + .setMessage("How To Use : - \nStep 1 : - Add Trusted Contacts from your Existing Android Contacts to whom Distress Messages are to be Sent! \nStep 2 : - In Case of an Emergency, Open The App and Long Press The HELP Button! \nPlease Also Do the Following to Ensure Proper Functioning of the Application! \n1)If you have a Dual SIM phonw, Please set any one of them as default for sending SMS from settings > SIM cards! \n2) Add this app as an exception in any Task Killer apps if you are using any! \n3) Setup a PIN Code in the Next Screen for Security ! ") + .setPositiveButton("Ok", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Log.i("zz","OK"); + } + }).show(); + } intent = new Intent(MainActivity.this,confirmationScreen.class); choice=0; Intent serviceIntent = new Intent(MainActivity.this,SMSReader.class); diff --git a/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java b/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java index 11a77e29420b9b5dee80133b8a9fd8a63ebd3617..bf52d332783c1c883ef8ecb4c2cecc350a068ff5 100644 --- a/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java +++ b/app/src/main/java/com/speedyapps/keepyousafe/confirmationScreen.java @@ -49,44 +49,36 @@ public class confirmationScreen extends AppCompatActivity { handler.removeCallbacks(this); } else - handler.postDelayed(this,1000); + handler.postDelayed(this,1000); } }; + run2=new Runnable() { @Override public void run() { - if((!editText.getText().toString().equals("2020"))&&textView.getText().toString().equals("0")) { - distressCall(); - } - else if(editText.getText().toString().equals("2020")){ + if(editText.getText().toString().equals("2020")){ + stopService(alarmIntent); handler.removeCallbacks(run); handler2.removeCallbacks(this); Toast.makeText(confirmationScreen.this, "Distress Calls Cancelled!", Toast.LENGTH_SHORT).show(); Intent main = new Intent(confirmationScreen.this,MainActivity.class); - stopService(alarmIntent); startActivity(main); } - else if ((!editText.getText().toString().equals("2020"))) - handler2.post(this); + else if(textView.getText().toString().equals("0")) { + distressCall(); + handler2.postDelayed(this,100); + } + else + handler2.postDelayed(this,100); + + } }; - handler2.post(run2); handler.post(run); + handler2.post(run2); } - public void onCancel(View view){ - if((!editText.getText().toString().equals("2020"))&&textView.getText().toString().equals("0")) - distressCall(); - else if(editText.getText().toString().equals("2020")){ - handler.removeCallbacks(run); - Toast.makeText(this, "Cancelled Distress Signals!", Toast.LENGTH_SHORT).show(); - Intent main = new Intent(confirmationScreen.this,MainActivity.class); - stopService(alarmIntent); - startActivity(main); - } - - } public void distressCall(){ startService(alarmIntent); count = shared.getInt("count", 0);