Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #26 from tacticalDevC/future
Browse files Browse the repository at this point in the history
Merging ready future branch in master. v0.6 release
  • Loading branch information
tacticalDevC authored Jun 13, 2019
2 parents 487af75 + e326209 commit a727ef5
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 111 deletions.
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE"/>

<!--<uses-permission android:name="android.permission.READ_CONTACTS"/>-->
<application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
Expand Down Expand Up @@ -64,36 +68,57 @@ public void onClick(View view) {
final View content = getLayoutInflater().inflate(R.layout.content_dialog_contact_entry, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ContactPickerActivity.this);

builder.setView(content);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
final ArrayAdapter<String> ad = new ArrayAdapter<>(ContactPickerActivity.this, R.layout.support_simple_spinner_dropdown_item);
ad.addAll(((ContactAdapter)rv.getAdapter()).getGroups().toArray(new String[]{}));
((Spinner)content.findViewById(R.id.group_select)).setAdapter(ad);

AlertDialog alert = builder.setView(content)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Contact c = new Contact(((TextView)content.findViewById(R.id.contact_name)).getText().toString(),
((TextView)content.findViewById(R.id.contact_number)).getText().toString(),
((String)((Spinner)content.findViewById(R.id.group_select)).getSelectedItem()));
list.add(c);
rv.getAdapter().notifyItemInserted(list.indexOf(c));
}
})
.setNegativeButton("Cancel", null)
.setNeutralButton("New group", null)
.create();
alert.show();
alert.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Contact c = new Contact(((TextView)content.findViewById(R.id.contact_name)).getText().toString(), ((TextView)content.findViewById(R.id.contact_number)).getText().toString());
list.add(c);
rv.getAdapter().notifyItemInserted(list.indexOf(c));
public void onClick(View v) {
final EditText et = new EditText(ContactPickerActivity.this);
new AlertDialog.Builder(ContactPickerActivity.this)
.setTitle("Enter new group name")
.setView(et)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ad.add(et.getText().toString());
}
})
.show();
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
}
});

//Import data from shared prefs
for(String contactString : prefs.getStringSet(mode, new HashSet<String>()))
{
String[] parts = contactString.split(";");
if(parts.length == 2)
{
Contact c = new Contact(parts[1], parts[0]);
list.add(c);
rv.getAdapter().notifyItemInserted(list.indexOf(c));
}
else
{
Contact c = new Contact("", parts[0]);
list.add(c);
rv.getAdapter().notifyItemInserted(list.indexOf(c));
}

Contact c = new Contact(
(parts.length >= 2 ? parts[1] : ""),
parts[0],
(parts.length >= 3 ? parts[2] : "General")
);

list.add(c);
rv.getAdapter().notifyItemInserted(list.indexOf(c));
}
}

Expand All @@ -109,7 +134,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
for(int i = 0; i < rv.getAdapter().getItemCount(); i++)
{
Contact c = list.get(i);
newValues.add(c.number + ";" + c.name);
newValues.add(c.number + ";" + c.name + ";" + c.groupID);
}
prefs.edit().putStringSet(getString(R.string.var_numbers_trigger), newValues).putStringSet(getString(R.string.var_numbers_notify), newValues).apply();
return true;
Expand All @@ -123,7 +148,7 @@ protected void onDestroy() {
for(int i = 0; i < rv.getAdapter().getItemCount(); i++)
{
Contact c = list.get(i);
newValues.add(c.number + ";" + c.name);
newValues.add(c.number + ";" + c.name + ";" + c.groupID);
}
prefs.edit().putStringSet(mode, newValues).apply();
}
Expand Down
95 changes: 52 additions & 43 deletions app/src/main/java/at/tacticaldevc/panictrigger/TriggerActivity.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
package at.tacticaldevc.panictrigger;

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.HashSet;
import java.util.Set;

import at.tacticaldevc.panictrigger.contactList.Contact;
import at.tacticaldevc.panictrigger.utils.Utils;

public class TriggerActivity extends AppCompatActivity implements View.OnClickListener, LocationListener
{
private Vibrator v;
private Contact[] notifyContacts;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trigger);

if(checkSelfPermission(Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.CALL_PRIVILEGED) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
{
requestPermissions(new String[]{
Manifest.permission.RECEIVE_SMS,
Manifest.permission.SEND_SMS,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.CALL_PHONE,
Manifest.permission.READ_CONTACTS,
Manifest.permission.CALL_PRIVILEGED,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
}, 1);
}
v = (Vibrator) getSystemService(VIBRATOR_SERVICE);

String[] perms;
if((perms = Utils.checkPermissions(this)).length > 0)
requestPermissions(perms, 255);

if(!getSharedPreferences("conf", MODE_PRIVATE).getBoolean("firstStartDone", false))
{
Expand Down Expand Up @@ -92,11 +80,7 @@ public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(TriggerActivity.this, SettingsActivity.class));
}
})
.setNegativeButton("Yes.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Yes.", null)
.show();
}
})
Expand Down Expand Up @@ -130,7 +114,28 @@ public void onClick(View v) {
switch (v.getId())
{
case R.id.triggerButton:
getCurrentLocationAndPanic();
if(callEmergServices())
{
Intent emergService = new Intent(Intent.ACTION_CALL, Uri.parse("tel:112"));
startActivity(emergService);
return;
}

this.v.vibrate(1000);
final View content = getLayoutInflater().inflate(R.layout.content_dialog_trigger_group_select, null);
final ArrayAdapter<String> ad = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item, Utils.getContactGroups(this));
((Spinner)content.findViewById(R.id.emergency_group)).setAdapter(ad);

new AlertDialog.Builder(this)
.setView(content)
.setPositiveButton("Trigger", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notifyContacts = Utils.getContactsByGroup(((Spinner)content.findViewById(R.id.emergency_group)).getSelectedItem().toString(), TriggerActivity.this);
getCurrentLocationAndPanic();
}
})
.show();
break;
case R.id.configure:
Intent settings = new Intent(this, SettingsActivity.class);
Expand All @@ -141,28 +146,20 @@ public void onClick(View v) {

private void sendOutPanic(Location loc)
{
Set<String> contacts = getSharedPreferences("conf", MODE_PRIVATE).getStringSet(getString(R.string.var_numbers_notify), new HashSet<String>());
String keyword = getSharedPreferences("conf", MODE_PRIVATE).getString(getString(R.string.var_words_keyword), "Panic");
SmsManager manager = SmsManager.getDefault();
for (String number : contacts)
for (Contact c : notifyContacts)
{
StringBuilder sb = new StringBuilder(keyword);
if(loc != null)
sb.append("\n" + loc.getLatitude() + "\n" + loc.getLongitude());

manager.sendTextMessage(number.split(";")[0], null, sb.toString(), null, null);
manager.sendTextMessage(c.number, null, sb.toString(), null, null);
}
}

private void getCurrentLocationAndPanic()
{
if(callEmergServices())
{
Intent emergService = new Intent(Intent.ACTION_CALL, Uri.parse("tel:112"));
startActivity(emergService);
return;
}
Location currLoc;
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try
{
Expand All @@ -175,7 +172,7 @@ else if(locManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
}
catch (Exception e)
{
Toast.makeText(this, "GPS fix could be acquired. Please check your settings!", Toast.LENGTH_LONG).show();
Toast.makeText(this, "GPS fix could not be acquired. Please check your settings!", Toast.LENGTH_LONG).show();
sendOutPanic(null);
}
}
Expand Down Expand Up @@ -205,4 +202,16 @@ public void onProviderEnabled(String provider) {
public void onProviderDisabled(String provider) {

}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if(!Utils.onRequestPermissionsResult(requestCode, permissions, grantResults))
{
new AlertDialog.Builder(TriggerActivity.this)
.setTitle("Permissions")
.setMessage("It looks like not all permissions have been granted.\nPlease grant them or the app will not work!")
.show();
findViewById(R.id.triggerButton).setEnabled(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

public class Contact {

public String name, number;
public Contact(String name, String number)
public String name, number, groupID;
public Contact(String name, String number, String groupID)
{
this.name = name;
this.number = number;
this.groupID = groupID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.xml.datatype.Duration;

Expand All @@ -32,6 +34,7 @@ public void onBindViewHolder(ContactItem contactItem, int i) {
Contact ci = list.get(i);
contactItem.name.setText(ci.name);
contactItem.number.setText(ci.number);
contactItem.group.setText(ci.groupID);
contactItem.c = ci;
}

Expand All @@ -40,16 +43,31 @@ public int getItemCount() {
return list.size();
}

public Set<String> getGroups()
{
Set<String> groups = new HashSet<>();

groups.add("General");

for(Contact c : list)
{
groups.add(c.groupID);
}

return groups;
}

public class ContactItem extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener
{
public TextView name, number;
public TextView name, number, group;
public Contact c;
public View v;

public ContactItem(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.name);
number = itemView.findViewById(R.id.number);
group = itemView.findViewById(R.id.group);

itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
Expand Down
Loading

0 comments on commit a727ef5

Please sign in to comment.