Issue #2 points 1 and 3 resolved

This commit is contained in:
Alessandro Ferro 2022-10-27 14:58:18 +02:00
parent 884996ca71
commit 86cf54f00d
5 changed files with 29 additions and 21 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
androidkey.jks

View File

@ -12,7 +12,6 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<application <application

View File

@ -18,7 +18,7 @@ import android.widget.Button;
public class RingerActivity extends AppCompatActivity { public class RingerActivity extends AppCompatActivity {
private Ringtone ringtoneManager; private Ringtone ringtoneManager;
private Vibrator v; private Vibrator vibrator;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -60,7 +60,7 @@ public class RingerActivity extends AppCompatActivity {
ringtoneManager.setVolume(1f); ringtoneManager.setVolume(1f);
ringtoneManager.play(); ringtoneManager.play();
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Start without a delay // Start without a delay
// Vibrate for 500 milliseconds // Vibrate for 500 milliseconds
@ -70,17 +70,17 @@ public class RingerActivity extends AppCompatActivity {
// '0' is actually the index at which the pattern keeps repeating from (the start) // '0' is actually the index at which the pattern keeps repeating from (the start)
// To repeat the pattern from any other point, you could increase the index, e.g. '1' // To repeat the pattern from any other point, you could increase the index, e.g. '1'
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createWaveform(pattern, 0)); vibrator.vibrate(VibrationEffect.createWaveform(pattern, 0));
} }
else{ else{
v.vibrate(pattern,0); vibrator.vibrate(pattern,0);
} }
} }
private void stopRinging(){ private void stopRinging(){
ringtoneManager.stop(); ringtoneManager.stop();
v.cancel(); vibrator.cancel();
finishAffinity(); finishAndRemoveTask();
} }
@Override @Override

View File

@ -59,4 +59,9 @@ public class Utils {
return String.valueOf(numberProto.getCountryCode()); return String.valueOf(numberProto.getCountryCode());
} }
// We'll remove parenthesis, dashes and whitespaces
public static String normalizePhoneNumber(String phoneNo){
return phoneNo.replaceAll("[-()\\s]", "");
}
} }

View File

@ -21,7 +21,7 @@ import java.util.ArrayList;
public class WhitelistContactsActivity extends AppCompatActivity { public class WhitelistContactsActivity extends AppCompatActivity {
private ListView contactsListView; private ListView contactsListView;
private ArrayList<String> contacts; private ArrayList<String> contactsListView_datasource;
private ArrayAdapter<String> listviewAdapter; private ArrayAdapter<String> listviewAdapter;
private final WhitelistDbHandler whitelistDbHandler = new WhitelistDbHandler(this); private final WhitelistDbHandler whitelistDbHandler = new WhitelistDbHandler(this);
@ -35,10 +35,10 @@ public class WhitelistContactsActivity extends AppCompatActivity {
setViews(); setViews();
setListeners(); setListeners();
contacts = whitelistDbHandler.getAllContacts(); contactsListView_datasource = whitelistDbHandler.getAllContacts();
listviewAdapter = new ArrayAdapter<String>(this, listviewAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.layout.simple_list_item_1,
contacts); contactsListView_datasource);
contactsListView.setAdapter(listviewAdapter); contactsListView.setAdapter(listviewAdapter);
} }
@ -58,9 +58,7 @@ public class WhitelistContactsActivity extends AppCompatActivity {
@Override @Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
String number = (String)adapterView.getItemAtPosition(i); String number = (String)adapterView.getItemAtPosition(i);
contacts.remove(number); removeNumberFromWhiteList(number);
listviewAdapter.notifyDataSetChanged();
whitelistDbHandler.deleteContact(number);
return true; return true;
} }
}); });
@ -98,23 +96,27 @@ public class WhitelistContactsActivity extends AppCompatActivity {
int phoneIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); int phoneIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int contactNameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); int contactNameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
String number = c.getString(phoneIndex); String number = c.getString(phoneIndex);
String contactName = c.getString(contactNameIndex); String contactName = c.getString(contactNameIndex); // planned to show contact's name as well
contactSelected(number); addNumberToWhiteList(number);
} }
c.close(); c.close();
} }
} }
private void contactSelected(String phoneNo){ private void addNumberToWhiteList(String phoneNo){
// We'll replace parenthesis, dashes and whitespaces to obtain a valid phone number phoneNo = Utils.normalizePhoneNumber(phoneNo);
phoneNo = phoneNo.replaceAll("[-()\\s]", ""); if(contactsListView_datasource.contains(phoneNo)){
if(contacts.contains(phoneNo)){
Toast.makeText(this, "Contact already in the list", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Contact already in the list", Toast.LENGTH_SHORT).show();
return; return;
} }
whitelistDbHandler.addContact(phoneNo); whitelistDbHandler.addContact(phoneNo);
contacts.add(phoneNo); contactsListView_datasource.add(phoneNo);
listviewAdapter.notifyDataSetChanged();
}
private void removeNumberFromWhiteList(String phoneNo){
whitelistDbHandler.deleteContact(phoneNo);
contactsListView_datasource.remove(phoneNo);
listviewAdapter.notifyDataSetChanged(); listviewAdapter.notifyDataSetChanged();
} }
} }