Issue #2 points 1 and 3 resolved
This commit is contained in:
parent
884996ca71
commit
86cf54f00d
|
@ -0,0 +1,2 @@
|
|||
|
||||
androidkey.jks
|
|
@ -12,7 +12,6 @@
|
|||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application
|
||||
|
|
|
@ -18,7 +18,7 @@ import android.widget.Button;
|
|||
public class RingerActivity extends AppCompatActivity {
|
||||
|
||||
private Ringtone ringtoneManager;
|
||||
private Vibrator v;
|
||||
private Vibrator vibrator;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -60,7 +60,7 @@ public class RingerActivity extends AppCompatActivity {
|
|||
ringtoneManager.setVolume(1f);
|
||||
ringtoneManager.play();
|
||||
|
||||
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
// Start without a delay
|
||||
// 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)
|
||||
// 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) {
|
||||
v.vibrate(VibrationEffect.createWaveform(pattern, 0));
|
||||
vibrator.vibrate(VibrationEffect.createWaveform(pattern, 0));
|
||||
}
|
||||
else{
|
||||
v.vibrate(pattern,0);
|
||||
vibrator.vibrate(pattern,0);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopRinging(){
|
||||
ringtoneManager.stop();
|
||||
v.cancel();
|
||||
finishAffinity();
|
||||
vibrator.cancel();
|
||||
finishAndRemoveTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,4 +59,9 @@ public class Utils {
|
|||
return String.valueOf(numberProto.getCountryCode());
|
||||
}
|
||||
|
||||
// We'll remove parenthesis, dashes and whitespaces
|
||||
public static String normalizePhoneNumber(String phoneNo){
|
||||
return phoneNo.replaceAll("[-()\\s]", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.ArrayList;
|
|||
public class WhitelistContactsActivity extends AppCompatActivity {
|
||||
|
||||
private ListView contactsListView;
|
||||
private ArrayList<String> contacts;
|
||||
private ArrayList<String> contactsListView_datasource;
|
||||
private ArrayAdapter<String> listviewAdapter;
|
||||
private final WhitelistDbHandler whitelistDbHandler = new WhitelistDbHandler(this);
|
||||
|
||||
|
@ -35,10 +35,10 @@ public class WhitelistContactsActivity extends AppCompatActivity {
|
|||
setViews();
|
||||
setListeners();
|
||||
|
||||
contacts = whitelistDbHandler.getAllContacts();
|
||||
contactsListView_datasource = whitelistDbHandler.getAllContacts();
|
||||
listviewAdapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_1,
|
||||
contacts);
|
||||
contactsListView_datasource);
|
||||
contactsListView.setAdapter(listviewAdapter);
|
||||
}
|
||||
|
||||
|
@ -58,9 +58,7 @@ public class WhitelistContactsActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
String number = (String)adapterView.getItemAtPosition(i);
|
||||
contacts.remove(number);
|
||||
listviewAdapter.notifyDataSetChanged();
|
||||
whitelistDbHandler.deleteContact(number);
|
||||
removeNumberFromWhiteList(number);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -98,23 +96,27 @@ public class WhitelistContactsActivity extends AppCompatActivity {
|
|||
int phoneIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
||||
int contactNameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
|
||||
String number = c.getString(phoneIndex);
|
||||
String contactName = c.getString(contactNameIndex);
|
||||
contactSelected(number);
|
||||
String contactName = c.getString(contactNameIndex); // planned to show contact's name as well
|
||||
addNumberToWhiteList(number);
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void contactSelected(String phoneNo){
|
||||
// We'll replace parenthesis, dashes and whitespaces to obtain a valid phone number
|
||||
phoneNo = phoneNo.replaceAll("[-()\\s]", "");
|
||||
|
||||
if(contacts.contains(phoneNo)){
|
||||
private void addNumberToWhiteList(String phoneNo){
|
||||
phoneNo = Utils.normalizePhoneNumber(phoneNo);
|
||||
if(contactsListView_datasource.contains(phoneNo)){
|
||||
Toast.makeText(this, "Contact already in the list", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue