~steve-evolvedlight/opensatnav/osm-droid-update

« back to all changes in this revision

Viewing changes to src/org/opensatnav/ContributeActivity.java

  • Committer: evolvedlight
  • Date: 2009-10-10 22:58:29 UTC
  • Revision ID: svn-v4:9bbf34d3-3897-488d-afc9-b14ce4e6a41e:trunk:65
Changeset for issue #30
This is the first commit of the Contribute to OSM functionality.

It's still a bit rough around the edges but it means other people can also contribute more easily.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.opensatnav;
 
2
 
 
3
import java.io.InputStream;
 
4
import java.io.OutputStream;
 
5
import java.io.StringWriter;
 
6
import java.io.UnsupportedEncodingException;
 
7
import java.net.HttpURLConnection;
 
8
import java.net.URL;
 
9
 
 
10
import org.anddev.openstreetmap.contributor.util.OSMUploader;
 
11
import org.xmlpull.v1.XmlSerializer;
 
12
 
 
13
import android.app.Activity;
 
14
import android.app.AlertDialog;
 
15
import android.content.Context;
 
16
import android.content.DialogInterface;
 
17
import android.content.Intent;
 
18
import android.content.SharedPreferences;
 
19
import android.content.res.Resources;
 
20
import android.os.Bundle;
 
21
import android.preference.PreferenceManager;
 
22
import android.text.TextWatcher;
 
23
import android.util.Xml;
 
24
import android.view.View;
 
25
import android.widget.Button;
 
26
import android.widget.EditText;
 
27
import android.widget.TextView;
 
28
import android.widget.Toast;
 
29
import android.widget.ToggleButton;
 
30
 
 
31
public class ContributeActivity extends Activity {
 
32
        Bundle gpsTracks = new Bundle();
 
33
        
 
34
        private static final int UPLOAD_NOW = 10;
 
35
        private static final int TRACE_TOGGLE = UPLOAD_NOW + 1;
 
36
        private static final int DELETE_TRACKS = TRACE_TOGGLE + 1;
 
37
        private static final int NEW_WAYPOINT = DELETE_TRACKS + 1;
 
38
        private static final int CLEAR_OLD_TRACES = NEW_WAYPOINT + 1;
 
39
        
 
40
        private String editName = "";
 
41
        private String editDescription = "";
 
42
        
 
43
        private Boolean inEditName = false;
 
44
        private Boolean inEditDescription = false;
 
45
        
 
46
        public void onCreate(Bundle onSavedInstance) {
 
47
                super.onCreate(onSavedInstance);
 
48
                setTitle(R.string.contribute_title);
 
49
                setContentView(R.layout.contribute);
 
50
 
 
51
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
 
52
 
 
53
                if (!(prefs.contains(String.valueOf(R.string.pref_username_key))) && prefs.contains(String.valueOf(R.string.pref_password_key))); 
 
54
                TextView textInfo = (TextView) findViewById(R.id.textInfo);
 
55
                textInfo.setText(getText(R.string.prefs_contribute_osm_username) + " : " + prefs.getString(getString(R.string.pref_username_key), getString(R.string.contribute_username_not_entered)));
 
56
                Boolean tracing = Boolean.valueOf(getIntent().getDataString());
 
57
                Button startButton = (Button) findViewById(R.id.startRecord);
 
58
                if (tracing == true) {
 
59
                        startButton.setText("Stop Recording");
 
60
                }
 
61
                Button deleteButton = (Button) findViewById(R.id.deleteTracks);
 
62
 
 
63
                Button deleteOldTracesButton = (Button) findViewById(R.id.clearOldTraces);
 
64
                Button addWayPointButton = (Button) findViewById(R.id.newWayPoint);
 
65
                if (tracing == false) {
 
66
                        addWayPointButton.setVisibility(Button.INVISIBLE);
 
67
                } else {
 
68
                        addWayPointButton.setVisibility(Button.VISIBLE);
 
69
                }
 
70
                
 
71
 
 
72
                startButton.setOnClickListener(new View.OnClickListener() {
 
73
 
 
74
                        @Override
 
75
                        public void onClick(View v) {
 
76
                                // TODO Auto-generated method stub
 
77
                                setResult(TRACE_TOGGLE);
 
78
                                finish();
 
79
                        }
 
80
                });
 
81
 
 
82
 
 
83
 
 
84
                deleteButton.setOnClickListener(new View.OnClickListener() {
 
85
 
 
86
                        @Override
 
87
                        public void onClick(View v) {
 
88
                                setResult(DELETE_TRACKS);
 
89
                                finish();
 
90
                        }
 
91
                });
 
92
                
 
93
                deleteOldTracesButton.setOnClickListener(new View.OnClickListener() {
 
94
                        
 
95
                        @Override
 
96
                        public void onClick(View v) {
 
97
                                setResult(CLEAR_OLD_TRACES);
 
98
                                finish();
 
99
                        }
 
100
                });
 
101
                
 
102
                addWayPointButton.setOnClickListener(new View.OnClickListener() {
 
103
                        
 
104
                        @Override
 
105
                        public void onClick(View v) {
 
106
                                inEditName = true;
 
107
                                getWayPointInfo();
 
108
                        }
 
109
                });
 
110
 
 
111
                Button uploadButton = (Button) findViewById(R.id.uploadButton);
 
112
                uploadButton.setOnClickListener(new View.OnClickListener() {
 
113
 
 
114
                        @Override
 
115
                        public void onClick(View v) {
 
116
                                
 
117
                                inEditDescription = true;
 
118
                                askForDescription();
 
119
 
 
120
                        }
 
121
                });
 
122
 
 
123
 
 
124
        }
 
125
        public void askForDescription() {
 
126
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
 
127
 
 
128
                alert.setTitle(getText(R.string.contribute_dialogue_trace_description));
 
129
                alert.setMessage(getText(R.string.contribute_dialogue_trace_message));
 
130
 
 
131
                // Set an EditText view to get user input 
 
132
                final EditText input = new EditText(this);
 
133
 
 
134
                alert.setView(input);
 
135
 
 
136
                alert.setPositiveButton(getText(R.string.contribute_dialogue_ok), new DialogInterface.OnClickListener() {
 
137
                        public void onClick(DialogInterface dialog, int whichButton) {
 
138
                                String description = input.getText().toString();
 
139
                                Intent data = getIntent();
 
140
                                data.putExtra("description", description);
 
141
                                setResult(UPLOAD_NOW, data);
 
142
                                finish();
 
143
                        }
 
144
                });
 
145
                
 
146
                
 
147
 
 
148
                alert.setNegativeButton(getText(R.string.contribute_dialogue_cancel), new DialogInterface.OnClickListener() {
 
149
                        public void onClick(DialogInterface dialog, int whichButton) {
 
150
                                // Canceled.
 
151
                        }
 
152
                });
 
153
 
 
154
                alert.show();
 
155
 
 
156
        }
 
157
        
 
158
        public void getWayPointInfo() {
 
159
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
 
160
                
 
161
                alert.setTitle(getText(R.string.contribute_dialogue_new_waypoint));
 
162
                alert.setMessage(getText(R.string.contribute_dialogue_new_waypoint_message));
 
163
 
 
164
                // Set an EditText view to get user input 
 
165
                final EditText wayPointName = new EditText(this);
 
166
                
 
167
                
 
168
                alert.setView(wayPointName);
 
169
 
 
170
                alert.setPositiveButton(getText(R.string.contribute_dialogue_ok), new DialogInterface.OnClickListener() {
 
171
                        public void onClick(DialogInterface dialog, int whichButton) {
 
172
                                String name = wayPointName.getText().toString();
 
173
                                
 
174
                                Intent data = getIntent();
 
175
                                data.putExtra("wayPointName", name);
 
176
                                setResult(NEW_WAYPOINT, data);
 
177
                                finish();
 
178
                        }
 
179
                });
 
180
 
 
181
                alert.setNegativeButton(getText(R.string.contribute_dialogue_cancel), new DialogInterface.OnClickListener() {
 
182
                        public void onClick(DialogInterface dialog, int whichButton) {
 
183
                                // Canceled.
 
184
                        }
 
185
                });
 
186
 
 
187
                alert.show();
 
188
        }
 
189
        
 
190
        protected void onSaveInstanceState(Bundle savedInstanceState) {
 
191
                savedInstanceState.putBoolean("inEditName", inEditName);
 
192
                savedInstanceState.putBoolean("inEditDescription", inEditDescription);
 
193
                super.onSaveInstanceState(savedInstanceState); // the UI component values are saved here.
 
194
        }
 
195
        
 
196
        @Override
 
197
        protected void onRestoreInstanceState(Bundle savedInstanceState) {
 
198
                super.onRestoreInstanceState(savedInstanceState);
 
199
                if (savedInstanceState.getBoolean("inEditName")) {
 
200
                        getWayPointInfo();
 
201
                }
 
202
                if (savedInstanceState.getBoolean("inEditDescription")) {
 
203
                        askForDescription();
 
204
                }
 
205
        }
 
206
}
 
 
b'\\ No newline at end of file'