Search in sources :

Example 1 with Incident

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) {
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) AppDatabase(com.sleepycookie.stillstanding.data.AppDatabase) AdapterView(android.widget.AdapterView) Incident(com.sleepycookie.stillstanding.data.Incident) ActionBar(android.support.v7.app.ActionBar)

Example 2 with Incident

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);
                }
            });
        }
    }
}
Also used : ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) Intent(android.content.Intent) Incident(com.sleepycookie.stillstanding.data.Incident) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 3 with Incident

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;
}
Also used : ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) Incident(com.sleepycookie.stillstanding.data.Incident) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) NonNull(android.support.annotation.NonNull)

Example 4 with Incident

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();
    }
}
Also used : Intent(android.content.Intent) Incident(com.sleepycookie.stillstanding.data.Incident) Date(java.util.Date) SmsManager(android.telephony.SmsManager)

Aggregations

Incident (com.sleepycookie.stillstanding.data.Incident)4 Intent (android.content.Intent)3 View (android.view.View)3 ImageButton (android.widget.ImageButton)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 NonNull (android.support.annotation.NonNull)1 ActionBar (android.support.v7.app.ActionBar)1 SmsManager (android.telephony.SmsManager)1 AdapterView (android.widget.AdapterView)1 AppDatabase (com.sleepycookie.stillstanding.data.AppDatabase)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1