Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. public class Home extends Activity {
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6.  
  7. requestWindowFeature(Window.FEATURE_NO_TITLE);
  8. setContentView(R.layout.activity_home);
  9.  
  10. }
  11.  
  12. public void userRegister(View view){
  13.  
  14. startActivity(new Intent(this,Register.class));
  15. }
  16.  
  17. public void userLogin(View view){
  18.  
  19.  
  20. }
  21.  
  22. public class FontTextView extends TextView {
  23.  
  24.  
  25. public FontTextView(Context context) {
  26. super(context);
  27. Typeface face=Typeface.createFromAsset(context.getAssets(), "Rockwell.ttf");
  28. this.setTypeface(face);
  29. }
  30.  
  31. public FontTextView(Context context, AttributeSet attrs) {
  32. super(context, attrs);
  33. Typeface face=Typeface.createFromAsset(context.getAssets(), "Rockwell.ttf");
  34. this.setTypeface(face);
  35. }
  36.  
  37. public FontTextView(Context context, AttributeSet attrs, int defStyle) {
  38. super(context, attrs, defStyle);
  39. Typeface face=Typeface.createFromAsset(context.getAssets(), "Rockwell.ttf");
  40. this.setTypeface(face);
  41. }
  42.  
  43. protected void onDraw (Canvas canvas) {
  44. super.onDraw(canvas);
  45.  
  46.  
  47. }
  48.  
  49. }
  50.  
  51. public class Register extends Activity {
  52.  
  53. private EditText etFirstname, etLastname, etNickname, etUsername, etPassword, etConfirmPassword, etPhone, etEmail;
  54.  
  55. @Override
  56. protected void onCreate(Bundle savedInstanceState) {
  57. // TODO Auto-generated method stub
  58. super.onCreate(savedInstanceState);
  59. setContentView(R.layout.activity_register);
  60.  
  61. etFirstname = (EditText) findViewById(R.id.etFirstname);
  62. etLastname = (EditText) findViewById(R.id.etLastname);
  63. etNickname = (EditText) findViewById(R.id.etNickname);
  64. etUsername = (EditText) findViewById(R.id.etUsername);
  65. etPassword = (EditText) findViewById(R.id.etPassword);
  66. etConfirmPassword = (EditText) findViewById(R.id.etConfirmPassword);
  67. etPhone = (EditText) findViewById(R.id.etPhone);
  68. etEmail = (EditText) findViewById(R.id.etEmail);
  69. }
  70.  
  71. public void bRegister(View v) {
  72. String firstname = etFirstname.getText().toString();
  73. String lastname = etLastname.getText().toString();
  74. String nickname = etNickname.getText().toString();
  75. String username = etUsername.getText().toString();
  76. String password = etPassword.getText().toString();
  77. String confirmpassword = etConfirmPassword.getText().toString();
  78. String phone = etPhone.getText().toString();
  79. String email = etEmail.getText().toString();
  80.  
  81. Toast.makeText(this, "Signing up...", Toast.LENGTH_SHORT).show();
  82. new RegisterActivity(this).execute(firstname, lastname, nickname, username, password, confirmpassword, phone, email);
  83.  
  84. private EditText etFirstname, etLastname, etNickname, etUsername, etPassword, etConfirmPassword, etPhone, etEmail;
  85.  
  86. @Override
  87. protected void onCreate(Bundle savedInstanceState) {
  88. // TODO Auto-generated method stub
  89. super.onCreate(savedInstanceState);
  90. setContentView(R.layout.activity_register);
  91.  
  92. etFirstname = (EditText) findViewById(R.id.etFirstname);
  93. etLastname = (EditText) findViewById(R.id.etLastname);
  94. etNickname = (EditText) findViewById(R.id.etNickname);
  95. etUsername = (EditText) findViewById(R.id.etUsername);
  96. etPassword = (EditText) findViewById(R.id.etPassword);
  97. etConfirmPassword = (EditText) findViewById(R.id.etConfirmPassword);
  98. etPhone = (EditText) findViewById(R.id.etPhone);
  99. etEmail = (EditText) findViewById(R.id.etEmail);
  100. }
  101.  
  102. public void bRegister(View v) {
  103. String firstname = etFirstname.getText().toString();
  104. String lastname = etLastname.getText().toString();
  105. String nickname = etNickname.getText().toString();
  106. String username = etUsername.getText().toString();
  107. String password = etPassword.getText().toString();
  108. String confirmpassword = etConfirmPassword.getText().toString();
  109. String phone = etPhone.getText().toString();
  110. String email = etEmail.getText().toString();
  111.  
  112. Toast.makeText(this, "Signing up...", Toast.LENGTH_SHORT).show();
  113. new RegisterActivity(this).execute(firstname, lastname, nickname, username, password, confirmpassword, phone, email);
  114. }
  115.  
  116. public class RegisterActivity extends AsyncTask<String, Void, String> {
  117.  
  118. private Context context;
  119.  
  120. public RegisterActivity(Context context) {
  121. this.context = context;
  122. }
  123.  
  124. protected void onPreExecute() {
  125.  
  126. }
  127.  
  128. @Override
  129. protected String doInBackground(String... arg0) {
  130. String firstname = arg0[0];
  131. String lastname = arg0[1];
  132. String nickname = arg0[2];
  133. String username = arg0[3];
  134. String password = arg0[4];
  135. String confirmpassword = arg0[5];
  136. String phone = arg0[6];
  137. String email = arg0[7];
  138.  
  139. String link;
  140. String data;
  141. BufferedReader bufferedReader;
  142. String result;
  143.  
  144. try {
  145. data = "&firstname=" + URLEncoder.encode(firstname, "UTF-8");
  146. data += "&lastname=" + URLEncoder.encode(lastname, "UTF-8");
  147. data += "&nickname=" + URLEncoder.encode(nickname, "UTF-8");
  148. data += "&username=" + URLEncoder.encode(username, "UTF-8");
  149. data += "&password=" + URLEncoder.encode(password, "UTF-8");
  150. data += "&confirmpassword=" + URLEncoder.encode(confirmpassword, "UTF-8");
  151. data += "&username=" + URLEncoder.encode(username, "UTF-8");
  152. data += "&phone=" + URLEncoder.encode(phone, "UTF-8");
  153. data += "&email=" + URLEncoder.encode(email, "UTF-8");
  154.  
  155. link = "https://49.151.4.22/RemindMePHP/Register.php" + data;
  156. URL url = new URL(link);
  157. HttpURLConnection con = (HttpURLConnection) url.openConnection();
  158.  
  159. bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
  160. result = bufferedReader.readLine();
  161. return result;
  162. } catch (Exception e) {
  163. return new String("Exception: " + e.getMessage());
  164. }
  165. }
  166.  
  167. @Override
  168. protected void onPostExecute(String result) {
  169. String jsonStr = result;
  170. if (jsonStr != null) {
  171. try {
  172. JSONObject jsonObj = new JSONObject(jsonStr);
  173. String query_result = jsonObj.getString("query_result");
  174. if (query_result.equals("SUCCESS")) {
  175. Toast.makeText(context, "Data inserted successfully. Signup successful.", Toast.LENGTH_SHORT).show();
  176. } else if (query_result.equals("FAILURE")) {
  177. Toast.makeText(context, "Data could not be inserted. Signup failed.", Toast.LENGTH_SHORT).show();
  178. } else {
  179. Toast.makeText(context, "Couldn't connect to remote database.", Toast.LENGTH_SHORT).show();
  180. }
  181. } catch (JSONException e) {
  182. e.printStackTrace();
  183. Toast.makeText(context, "Error parsing JSON data.", Toast.LENGTH_SHORT).show();
  184. }
  185. } else {
  186. Toast.makeText(context, "Couldn't get any JSON data.", Toast.LENGTH_SHORT).show();
  187. }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement