-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateTaskActivity.java
136 lines (109 loc) · 4.78 KB
/
UpdateTaskActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.li.tritonia.wildlife;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class UpdateTaskActivity extends ActionBarActivity {
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
protected LocationManager locationManager;
protected Button retrieveLocationButton;
private TextView latText;
private TextView lonText;
private EditText tagName;
private EditText descriptionText;
private int taskIdVal, huntIdVal;
private String taskName, taskDesc;
private double gpsLat, gpsLon;
Intent intent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_task);
//Variable initialization
retrieveLocationButton = (Button) findViewById(R.id.readyButton);
latText = (TextView)findViewById(R.id.latitudeTextView);
lonText = (TextView)findViewById(R.id.longitudeTextView);
tagName = (EditText)findViewById(R.id.tagNameEditView);
descriptionText = (EditText)findViewById(R.id.descriptionEditView);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//GPS on
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
}
@Override
protected void onResume() {
super.onResume();
intent = getIntent();
// Data from existing task if user wants to edit
huntIdVal = intent.getIntExtra("huntIdValue", 99);
taskIdVal = intent.getIntExtra("taskIdValue", 0);
taskName = MainActivity.dataBase.getTaskName(taskIdVal, huntIdVal);
taskDesc = MainActivity.dataBase.getTaskDesc(taskIdVal, huntIdVal);
// Setting fields to existing data
tagName.setText(taskName);
descriptionText.setText(taskDesc);
// pass task data to NFC write activity
retrieveLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
final Intent changeActivityWriteNFC = new Intent(UpdateTaskActivity.this, UpdateNFCActivity.class);
if(location != null){
changeActivityWriteNFC.putExtra("taskIdValue", taskIdVal);
changeActivityWriteNFC.putExtra("huntIdValue", huntIdVal);
changeActivityWriteNFC.putExtra("passTaskName", tagName.getText().toString());
changeActivityWriteNFC.putExtra("passTaskDesc", descriptionText.getText().toString());
changeActivityWriteNFC.putExtra("passGPSLat", location.getLatitude());
changeActivityWriteNFC.putExtra("passGPSLon", location.getLongitude());
startActivity(changeActivityWriteNFC);
}
}
});
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
}
public void onStatusChanged(String s, int i, Bundle b) {
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_add_task, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}