This repository has been archived by the owner on Nov 18, 2020. It is now read-only.
forked from geocam/geocamMemoAndroid
/
GeoCamMemoCreateActivity.java
99 lines (82 loc) · 2.72 KB
/
GeoCamMemoCreateActivity.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
// __BEGIN_LICENSE__
// Copyright (C) 2008-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__
package gov.nasa.arc.geocam.memo.activity;
import gov.nasa.arc.geocam.memo.GeoCamMemoRoboApplication;
import gov.nasa.arc.geocam.memo.R;
import gov.nasa.arc.geocam.memo.UIUtils;
import gov.nasa.arc.geocam.memo.bean.GeoCamMemoMessage;
import gov.nasa.arc.geocam.memo.exception.AuthenticationFailedException;
import gov.nasa.arc.geocam.memo.service.DjangoMemoInterface;
import java.util.Date;
import roboguice.activity.RoboActivity;
import roboguice.inject.InjectView;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.google.inject.Inject;
/**
* The Class GeoCamMemoCreateActivity. This activity gives the
* user the opportunity to add a new memo
*/
public class GeoCamMemoCreateActivity extends RoboActivity {
/** The new memo input. */
@InjectView(R.id.newMemoInput)
EditText newMemoInput;
/** The app state. */
@Inject
GeoCamMemoRoboApplication appState;
/** The django memo interface. */
@Inject
DjangoMemoInterface djangoMemoInterface;
/**
* Called when the activity is first created.
*
* @param savedInstanceState the saved instance state
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_memo);
}
/**
* On home click, restart the {@link GeoCamMemoHomeActivity}.
*
* @param v the view
*/
public void onHomeClick(View v) {
UIUtils.goHome(this);
}
/**
* On send click, create a new {@link GeoCamMemoMessage} using the
* text and time stamp from the {@link GeoCamMemoCreateActivity}. Populate
* the location if available.
*
* @param v the view
*/
public void onSendClick(View v) {
CharSequence text = newMemoInput.getText();
Location location = appState.getLocation();
GeoCamMemoMessage message = new GeoCamMemoMessage();
message.setContent(text.toString());
message.setContentTimestamp(new Date());
if (location != null) {
message.setLatitude(location.getLatitude());
message.setLongitude(location.getLongitude());
if (location.hasAccuracy()) {
message.setAccuracy((int) location.getAccuracy());
}
}
try {
djangoMemoInterface.createMemo(message);
UIUtils.goHome(this);
} catch (AuthenticationFailedException e) {
UIUtils.displayException(this, e, "Could not authenticate with the server");
} catch (Exception e) {
UIUtils.displayException(this, e, "Communication with the server failed");
}
}
}