-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistration.java
361 lines (295 loc) · 12.7 KB
/
Registration.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package com.example.tlee1.petmanager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Registration extends AppCompatActivity {
DatabaseHelper myDb;
EditText nm, em, un, p1, p2;
Button btnsign;
private EditText petname;
TextView txtResult;
private String name, email, userName, pass1, pass2, text;
private long session;
private Long when;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
myDb = new DatabaseHelper(this);
nm = (EditText) findViewById(R.id.editTextName);
name = nm.getText().toString();
em = (EditText) findViewById(R.id.editTextEmail);
email = em.getText().toString();
un = (EditText) findViewById(R.id.editTextUserName);
userName = un.getText().toString();
p1 = (EditText) findViewById(R.id.editTextPass1);
pass1 = p1.getText().toString();
p2 = (EditText) findViewById(R.id.editTextPass2);
pass2 = p2.getText().toString();
btnsign = (Button) findViewById(R.id.buttonSignUp);
onSignUpClick();
}
public void onSignUpClick() {
btnsign.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
/*boolean isInserted =*/
//myDb.insertData(name.getText().toString(),
// email.getText().toString(),
// userName.getText().toString(),
// pass1.getText().toString());
/* if(isInserted =true)*/
myDb.insertData(name, email, userName, pass1);
Intent intent = new Intent(Registration.this, MainActivity.class);
startActivity(intent);
//send();
/* if (pass1 == pass2) {
Toast.makeText(Registration.this, "Information Saved", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(Registration.this, "Information not Saved", Toast.LENGTH_LONG).show();
*//*Intent intent = new Intent(Registration.this, MainActivity.class);
startActivity(intent);*//*
}*/
}
}
);
}
/* public void send() {
Registration entry = new Registration();
entry.setWhen(getWhen());
//entry.setTitle(getTitle());
entry.setUserName(UiUtil.readText(this, R.id.editTextUserName));
entry.setEmail(UiUtil.readText(this, R.id.editTextEmail));
entry.setName(UiUtil.readText(this, R.id.editTextName));
entry.setPass1(UiUtil.readText(this, R.id.editTextPass1));
Server serv = new Server(this, userName, pass1);
try {
serv.send(entry);
Toast.makeText(Registration.this, "done", Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(Registration.this, "fail", Toast.LENGTH_LONG).show();
// sendStatusMessage(ex.getMessage());
}
}
// private String name, email, userName, pass1, pass2;
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public String getUsername() {
// userName = UiUtil.readText(this, R.id.editTextUserName);
return userName;
}
public String getPass1() {
return pass1;
}
public long getWhen() {
return when != null ? when.longValue() : 0L;
}
public void setWhen(long when) {
this.when = when;
}
public void setUserName(String userName) {
// userName = UiUtil.readText(this, R.id.editTextUserName);
this.userName = userName;
}
public void setEmail(String email) {
this.email = email;
}
public void setName(String name) {
this.name = name;
}
public void setPass1(String pass1) {
this.pass1 = pass1;
}
*//*public void setText(String text) {
this.text = text;
}*//*
public static String toJson(Registration reg) {
// new Gson().toJson(user) would include the hashpassword,
// which we don't want; so we'd either have to customize
// the JSON-generation using filters or metadata, or
// (much simpler) just grab the fields we actually want to send
HashMap<String, Object> obj = new HashMap<>();
obj.put("userName", reg.getUsername());
obj.put("email", reg.getEmail());
obj.put("name", reg.getName());
obj.put("pass1", reg.getPass1());
return new Gson().toJson(obj);
}
public static Registration fromJson(String json) throws JSONException {
JSONObject tmp = new JSONObject(json);
Registration entry = new Registration();
entry.setWhen(tmp.getLong("when"));
entry.setTitle(tmp.getString("title"));
entry.setUserName(tmp.getString("userName"));
entry.setEmail(tmp.getString("email"));
entry.setName(tmp.getString("name"));
entry.setPass1(tmp.getString("pass1"));
return entry;
}
public void doGet(View v) {
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
TextView userName = (TextView) findViewById(R.id.editTextUserName);
userName.setText("Please wait...");
}
protected String doInBackground(Void... params) {
HttpGet http = new HttpGet("http://httpbin.org/get");
http.addFormField("userName", "user");
http.addFormField("password", "pass");
try {
return http.finish();
} catch (Exception e) {
return formatError(e);
}
}
protected void onPostExecute(String txt) {
setText(txt);
}
}.execute();
}
public void doPost(View v) {
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
TextView userName = (TextView) findViewById(R.id.editTextUserName);
userName.setText("Please wait...");
}
protected String doInBackground(Void... params) {
HttpPost http = new HttpPost("http://httpbin.org/post", "");
http.addFormField("userName", "user");
http.addFormField("password", "pass");
try {
return http.finish();
} catch (Exception e) {
return formatError(e);
}
}
protected void onPostExecute(String txt) {
setText(txt);
}
}.execute();
}
public void doGetJson(View v) {
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
TextView userName = (TextView) findViewById(R.id.editTextUserName);
userName.setText("Please wait...");
}
protected String doInBackground(Void... params) {
HttpGet http = new HttpGet("http://httpbin.org/get");
http.addFormField("userName", "user");
http.addFormField("password", "pass");
try {
String txt = http.finish();
JSONObject json = new JSONObject(txt);
StringBuffer rv = new StringBuffer();
Iterator<String> it = json.keys();
while (it.hasNext()) {
String nm = it.next();
rv.append(nm + "=" + json.get(nm) + "\n\n");
}
return rv.toString();
} catch (Exception e) {
return formatError(e);
}
}
protected void onPostExecute(String txt) {
setText(txt);
}
}.execute();
}
public void doPutJson(View v) {
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
TextView userName = (TextView) findViewById(R.id.editTextUserName);
userName.setText("Please wait...");
}
protected String doInBackground(Void... params) {
HttpPut http = new HttpPut("https://pets-1332.appspot.com/?op=create");
try {
JSONObject json = new JSONObject();
json.put("userName", "user");
json.put("password", "pass");
return http.finish(json.toString());
} catch (Exception e) {
return formatError(e);
}
}
protected void onPostExecute(String txt) {
setText(txt);
}
}.execute();
}
public void doFileUpload(View v) {
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
TextView userName = (TextView) findViewById(R.id.editTextUserName);
userName.setText("Please wait...");
}
protected String doInBackground(Void... params) {
try {
HttpUpload http = new HttpUpload("https://pets-1332.appspot.com/?op=create", "UTF-8");
http.addFormField("userName", "user");
http.addFormField("password", "pass");
http.addFilePart("file", "my junky file.txt", "these can be any bytes, even an image, or whatever".getBytes("UTF-8"));
String txt = http.finish();
// let's see if the service sends back a URL we can follow for more information
int httpLoc = txt.indexOf("http://");
int crlfLoc = txt.indexOf("\n", httpLoc + 1);
if (httpLoc != -1 && crlfLoc != -1) {
String feedbackUrl = txt.substring(httpLoc, crlfLoc).trim();
String feedbackInfo = new HttpGet(feedbackUrl).finish();
// let's see if the "more information" includes the URL where I can check my upload
int finalHttpLoc = feedbackInfo.lastIndexOf("http://");
if (finalHttpLoc != -1) {
String urlOfMyUpload = feedbackInfo.substring(finalHttpLoc).trim();
String myUpload = new HttpGet(urlOfMyUpload).finish();
return feedbackInfo + "\n\n------------------\n\n" + myUpload;
}
return feedbackInfo + "\n\n\n(No further information about file upload)";
} else {
return txt + "\n\n\n(Cannot parse result to get further details)";
}
} catch (Exception e) {
return formatError(e);
}
}
protected void onPostExecute(String txt) {
setText(txt);
}
}.execute();
}
private void setText(final String str) {
if (Looper.getMainLooper() == Looper.myLooper()) {
txtResult = (TextView) (findViewById(R.id.editTextName));
if (txtResult != null) {
txtResult.setText(str);
txtResult.setMovementMethod(new ScrollingMovementMethod());
txtResult.scrollTo(0, 0);
}
} else {
runOnUiThread(
new Runnable() {
@Override
public void run() {
setText(str);
}
}
);
}
}
private String formatError(Exception ex) {
StringWriter tmp = new StringWriter();
tmp.append("An exception has occurred...\n");
ex.printStackTrace(new PrintWriter(tmp));
return tmp.toString();
}*/
}