use of com.sleepycookie.stillstanding.data.Incident in project stillStanding by katsik.
the class IncidentHistory method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
// Get a support ActionBar corresponding to this toolbar
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);
AppDatabase db = AppDatabase.getInstance(this);
final ArrayList<Incident> incidents = new ArrayList<Incident>();
Collections.addAll(incidents, db.incidentDao().loadAllIncidents());
IncidentAdapter adapter = new IncidentAdapter(this, incidents);
ListView listView = (ListView) findViewById(R.id.history);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
long viewId = view.getId();
if (viewId == R.id.incident_location) {
Incident tempIncident = incidents.get(position);
StringBuffer url = new StringBuffer();
url.append("http://maps.google.com?q=");
url.append(String.format("%.7f", tempIncident.getLatitude()));
url.append(",");
url.append(String.format("%.7f", tempIncident.getLongitude()));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url.toString()));
startActivity(i);
} else if (viewId == R.id.list_item) {
}
}
});
}
use of com.sleepycookie.stillstanding.data.Incident in project stillStanding by katsik.
the class MainActivity method setIncidentCard.
/**
*----------------------------------- UI setup ---------------------------------------------*
*/
/**
* This method is responsible for showing the last incident card in the UI. It puts the last fall's
* data every time this screen is brought back. It hides the card if the database is empty.
*/
public void setIncidentCard() {
final Incident lastIncident = db.incidentDao().loadLastIncident();
incidentCard = findViewById(R.id.incident_card);
if (lastIncident != null) {
incidentCard.setVisibility(View.VISIBLE);
TextView incidentDate = findViewById(R.id.incident_card_date);
incidentDate.setText(lastIncident.getDateText());
TextView incidentInfo = findViewById(R.id.incident_card_info);
incidentInfo.setText(lastIncident.getInfo());
ImageView incidentImage = findViewById(R.id.incident_image);
incidentImage.setImageResource(lastIncident.getIcon());
ImageButton incidentLocationButton = findViewById(R.id.incident_card_location);
if (lastIncident.hasLocation() == false) {
incidentLocationButton.setVisibility(View.GONE);
} else {
incidentLocationButton.setVisibility(View.VISIBLE);
incidentLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// The two lines below are needed to open location
StringBuffer url = new StringBuffer();
url.append("http://maps.google.com?q=");
url.append(String.format("%.7f", lastIncident.getLatitude()).replaceAll(",", "."));
url.append(",");
url.append(String.format("%.7f", lastIncident.getLongitude()).replaceAll(",", "."));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url.toString()));
startActivity(i);
}
});
}
}
}
use of com.sleepycookie.stillstanding.data.Incident in project stillStanding by katsik.
the class IncidentAdapter method getView.
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull final ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_incident, parent, false);
}
Incident currentIncident = getItem(position);
TextView idView = listItemView.findViewById(R.id.incident_id);
idView.setText("Incident " + currentIncident.getId());
TextView dateView = listItemView.findViewById(R.id.incident_date);
dateView.setText(currentIncident.getDateText());
TextView infoView = listItemView.findViewById(R.id.incident_info);
infoView.setText(currentIncident.getInfo());
ImageView imageView = listItemView.findViewById(R.id.incident_item_image);
imageView.setImageResource(currentIncident.getIcon());
ImageButton imageButton = listItemView.findViewById(R.id.incident_location);
if (currentIncident.hasLocation() == false) {
imageButton.setVisibility(View.GONE);
} else {
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Let the event be handled in onItemClick()
((ListView) parent).performItemClick(v, position, 0);
}
});
}
return listItemView;
}
use of com.sleepycookie.stillstanding.data.Incident in project stillStanding by katsik.
the class Emergency method triggerEmergency.
/**
* This method is used to trigger the actions needed to be done in case the user falls.
* Currently this method calls the saved phone number or sends an SMS (with or without location).
*/
// TODO Handle the case where the user has set no emergency contact. Maybe play an alarm.
public void triggerEmergency() {
showAToast(mR.getString(R.string.toast_fall_detected));
boolean smsPref = Preferences.getSmsPref(context);
String smsBody = Preferences.getSmsBody(context);
boolean locationPref = Preferences.getLocationPref(context);
String mNumber = Preferences.getNumber(context);
try {
if (!smsPref) {
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE);
if (permissionCheck == PERMISSION_GRANTED) {
ReadDataFromAccelerometer.setOnCall(true);
MainActivity.setOnCall(true);
Intent callingIntent = new Intent(Intent.ACTION_CALL);
callingIntent.setData(Uri.parse("tel:" + mNumber));
db.incidentDao().insertIncidents(new Incident(new Date(), "Call to " + mNumber, 1, 0, 0));
context.startActivity(callingIntent);
} else {
Log.d("Place emergency call", "User didn't give permission (phone)");
}
} else if (smsPref && !locationPref) {
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS);
if (permissionCheck == PERMISSION_GRANTED) {
StringBuffer smsBodyBuilder = new StringBuffer();
smsBodyBuilder.append(smsBody);
db.incidentDao().insertIncidents(new Incident(new Date(), "SMS to " + mNumber, 2, 0, 0));
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(mNumber, null, smsBodyBuilder.toString(), null, null);
Log.d("Trigger", smsBodyBuilder.toString());
showAToast(mR.getString(R.string.toast_sms_sent_to, mNumber));
} else {
Log.d("Place emergency call", "User didn't give permission (SMS)");
}
} else if (smsPref && locationPref) {
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS);
int permissionCheck2 = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION);
if (permissionCheck == PERMISSION_GRANTED && permissionCheck2 == PERMISSION_GRANTED) {
new Emergency.LocationRetrieving().execute(new String[] { mNumber, smsBody });
} else {
Log.d("Place emergency call", "User didn't give permission (SMS/Location)");
}
} else {
// TODO review if we want this
// play alarm
db.incidentDao().insertIncidents(new Incident(new Date(), "Alarm played", 3, 0, 0));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations