Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
080b998
confirmed that broadcast receiver works properly
May 2, 2018
e27e5e6
merged changes
May 2, 2018
cd0cd05
Created call class to handle parsing of calls from server
May 9, 2018
abcf92d
added new tester for calls
May 9, 2018
11a0ac1
updated fields in Call.java; started skeleton for accepting calls in …
May 9, 2018
779b9be
Merge branch 'devel-geofence' of https://github.com/EMSTrack/CleanApp…
May 9, 2018
50cb4f3
added call unit tester
May 9, 2018
664780d
finished step 2, minus prompting user for dialog
May 10, 2018
52a942f
completed steps 2 to 5 and set up skeleton for 6 to 10 for wesley; pr…
lwuleonwu May 14, 2018
ff5f8f6
Implemented function to create dialog box for accepting incoming calls
yblank1 May 16, 2018
be73f94
Implemented accepting calls step 7
May 17, 2018
144d438
steps 1 to 5 seem to work; moved step 5 into replyToAcceptCall()
lwuleonwu May 17, 2018
017ff5f
Merge branch 'devel-geofence' of https://github.com/EMSTrack/CleanApp…
May 23, 2018
bf4d5f9
implement server accept call step 6 and 8
May 23, 2018
e854996
Create geofence transition intents and replies
May 30, 2018
def0e25
call acceptance dialog sometimes shows up
lwuleonwu May 30, 2018
276861a
need to finish telling the difference between patient and hospital ge…
lwuleonwu May 30, 2018
6c92c33
new globals defined; logic needs to be implemented
May 31, 2018
ad5bb3a
moved publishing into one function
May 31, 2018
994e1bf
all 10 steps for accepting calls finished; testing still to be done
lwuleonwu Jun 3, 2018
d793970
clean up before merge
Jun 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions app/src/main/java/org/emstrack/ambulance/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class MainActivity extends AppCompatActivity {
private ImageView onlineIcon;
private ImageView trackingIcon;
private LocationChangeBroadcastReceiver receiver;
private CallPromptReceiver promptReceiver;
private int requestingToStreamLocation;

public class LocationChangeBroadcastReceiver extends BroadcastReceiver {
Expand Down Expand Up @@ -93,6 +94,29 @@ public void onReceive(Context context, Intent intent ) {
}
};

public class CallPromptReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "received broadcast for call prompt");
if (intent != null) {
final String action = intent.getAction();

if (action.equals(AmbulanceForegroundService.BroadcastActions.PROMPT_CALL_ACCEPT)) {
Log.i(TAG, "PROMPT_CALL_ACCEPT");

String callId = intent.getStringExtra("CALLID");
String callDetails = intent.getStringExtra("CALL_DETAILS");

createAcceptDialog(callId, callDetails);
} else if (action.equals(AmbulanceForegroundService.BroadcastActions.PROMPT_CALL_END)) {
Log.i(TAG, "PROMPT_CALL_END");

createEndDialog();
}
}
}
};

/**
* @param savedInstanceState
*/
Expand All @@ -102,6 +126,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



// Identifier text
headerText = (TextView) findViewById(R.id.headerText);

Expand Down Expand Up @@ -281,6 +307,8 @@ public void onReceive(Context context, Intent intent) {

}



}
}
});
Expand Down Expand Up @@ -333,6 +361,8 @@ public void onReceive(Context context, Intent intent) {
tabLayout.getTabAt(1).setIcon(R.drawable.ic_hospital);
tabLayout.getTabAt(2).setIcon(R.drawable.ic_globe);



}

public boolean canWrite() {
Expand Down Expand Up @@ -457,6 +487,13 @@ public void onResume() {
receiver = new LocationChangeBroadcastReceiver();
getLocalBroadcastManager().registerReceiver(receiver, filter);

Log.i(TAG, "Creating CallPromptReceiver");

IntentFilter promptFilter = new IntentFilter();
promptFilter.addAction(AmbulanceForegroundService.BroadcastActions.PROMPT_CALL_ACCEPT);
promptFilter.addAction(AmbulanceForegroundService.BroadcastActions.PROMPT_CALL_END);
promptReceiver = new CallPromptReceiver();
getLocalBroadcastManager().registerReceiver(promptReceiver, promptFilter);
}

@Override
Expand All @@ -468,6 +505,12 @@ public void onPause() {
getLocalBroadcastManager().unregisterReceiver(receiver);
receiver = null;
}

// Unregister prompt receiver
if (promptReceiver != null) {
getLocalBroadcastManager().unregisterReceiver(promptReceiver);
promptReceiver = null;
}
}

public void panicPopUp() {
Expand Down Expand Up @@ -501,4 +544,71 @@ private LocalBroadcastManager getLocalBroadcastManager() {
return LocalBroadcastManager.getInstance(this);
}

private void createAcceptDialog(final String callId, final String callDetails) {

Log.i(TAG, "Creating accept dialog");

// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(callDetails)
.setTitle("Accept Incoming Call?")
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(MainActivity.this, "Call accepted", Toast.LENGTH_SHORT).show();

Log.i(TAG, "Call accepted");

Intent serviceIntent = new Intent(MainActivity.this, AmbulanceForegroundService.class);
serviceIntent.setAction(AmbulanceForegroundService.Actions.CALL_ACCEPTED);
serviceIntent.putExtra("CALLID", callId);
startService(serviceIntent);

}
})
.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(MainActivity.this, "Call declined", Toast.LENGTH_SHORT).show();

Log.i(TAG, "Call declined");

Intent serviceIntent = new Intent(MainActivity.this, AmbulanceForegroundService.class);
serviceIntent.setAction(AmbulanceForegroundService.Actions.CALL_DECLINED);
startService(serviceIntent);
}
});
// Create the AlertDialog object and return it
builder.create().show();

}

private void createEndDialog() {

Log.i(TAG, "Creating end call dialog");

// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Finish Current Call?")
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(MainActivity.this, "Call ending", Toast.LENGTH_SHORT).show();

Log.i(TAG, "Call ending");

Intent serviceIntent = new Intent(MainActivity.this, AmbulanceForegroundService.class);
serviceIntent.setAction(AmbulanceForegroundService.Actions.CALL_FINISHED);
startService(serviceIntent);

}
})
.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(MainActivity.this, "Continuing call", Toast.LENGTH_SHORT).show();

Log.i(TAG, "Call not finished");
}
});
// Create the AlertDialog object and return it
builder.create().show();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

// TODO: REMOVE, JUST FOR TESTING
// Add geofence
Log.i(TAG, "Adding geofence");
Intent serviceIntent = new Intent(getActivity(),
AmbulanceForegroundService.class);
serviceIntent.setAction(AmbulanceForegroundService.Actions.GEOFENCE_START);
serviceIntent.putExtra("LATITUDE", (float) ambulance.getLocation().getLatitude());
serviceIntent.putExtra("LONGITUDE", (float) ambulance.getLocation().getLongitude());
serviceIntent.putExtra("RADIUS", 50.f);
getActivity().startService(serviceIntent);
// Log.i(TAG, "Adding geofence");
// Intent serviceIntent = new Intent(getActivity(),
// AmbulanceForegroundService.class);
// serviceIntent.setAction(AmbulanceForegroundService.Actions.GEOFENCE_START);
// serviceIntent.putExtra("LATITUDE", (float) 32.881150);
// serviceIntent.putExtra("LONGITUDE", (float) -117.238200);
// serviceIntent.putExtra("RADIUS", 50.f);
// getActivity().startService(serviceIntent);

}

Expand Down
Loading