Guest User

Untitled

a guest
Feb 17th, 2018
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.constraint.ConstraintLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7.  
  8. <EditText
  9. android:id="@+id/editText_username"
  10. android:layout_width="0dp"
  11. android:layout_height="wrap_content"
  12. android:layout_marginEnd="32dp"
  13. android:layout_marginStart="32dp"
  14. android:layout_marginTop="128dp"
  15. android:ems="10"
  16. android:inputType="textPersonName"
  17. android:text=""
  18. app:layout_constraintEnd_toEndOf="parent"
  19. app:layout_constraintStart_toStartOf="parent"
  20. app:layout_constraintTop_toTopOf="parent" />
  21.  
  22.  
  23. <TextView
  24. android:id="@+id/textView_username"
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:layout_marginBottom="8dp"
  28. android:layout_marginLeft="32dp"
  29. android:layout_marginStart="32dp"
  30. android:text="Фамилия имя: "
  31. app:layout_constraintBottom_toTopOf="@+id/editText_username"
  32. app:layout_constraintStart_toStartOf="parent" />
  33.  
  34. <EditText
  35. android:id="@+id/editText_email"
  36. android:layout_width="0dp"
  37. android:layout_height="wrap_content"
  38. android:layout_marginEnd="32dp"
  39. android:layout_marginStart="32dp"
  40. android:layout_marginTop="32dp"
  41. android:ems="10"
  42. android:inputType="textEmailAddress"
  43. app:layout_constraintEnd_toEndOf="parent"
  44. app:layout_constraintStart_toStartOf="parent"
  45. app:layout_constraintTop_toBottomOf="@+id/editText_username" />
  46.  
  47. <TextView
  48. android:id="@+id/textView_email"
  49. android:layout_width="wrap_content"
  50. android:layout_height="wrap_content"
  51. android:layout_marginBottom="8dp"
  52. android:layout_marginLeft="32dp"
  53. android:layout_marginStart="32dp"
  54. android:text="E-Mail:"
  55. app:layout_constraintBottom_toTopOf="@+id/editText_email"
  56. app:layout_constraintStart_toStartOf="parent" />
  57.  
  58. <EditText
  59. android:id="@+id/editText_password"
  60. android:layout_width="0dp"
  61. android:layout_height="wrap_content"
  62. android:layout_marginEnd="32dp"
  63. android:layout_marginStart="32dp"
  64. android:layout_marginTop="32dp"
  65. android:ems="10"
  66. android:inputType="textPassword"
  67. app:layout_constraintEnd_toEndOf="parent"
  68. app:layout_constraintHorizontal_bias="0.0"
  69. app:layout_constraintStart_toStartOf="parent"
  70. app:layout_constraintTop_toBottomOf="@+id/editText_email" />
  71.  
  72.  
  73. <TextView
  74. android:id="@+id/textView_password"
  75. android:layout_width="wrap_content"
  76. android:layout_height="wrap_content"
  77. android:layout_marginBottom="8dp"
  78. android:layout_marginLeft="32dp"
  79. android:layout_marginStart="32dp"
  80. android:text="Пароль:"
  81. app:layout_constraintBottom_toTopOf="@+id/editText_password"
  82. app:layout_constraintStart_toStartOf="parent" />
  83.  
  84. <Button
  85. android:id="@+id/button"
  86. android:layout_width="0dp"
  87. android:layout_height="wrap_content"
  88. android:layout_marginBottom="32dp"
  89. android:layout_marginEnd="32dp"
  90. android:layout_marginStart="32dp"
  91. android:text="Зарегестрироваться"
  92. app:layout_constraintBottom_toBottomOf="parent"
  93. app:layout_constraintEnd_toEndOf="parent"
  94. app:layout_constraintStart_toStartOf="parent" />
  95.  
  96.  
  97. </android.support.constraint.ConstraintLayout>
  98.  
  99. public class RegistrationActivity extends AppCompatActivity{
  100.  
  101. private UserRegistrationTask userRegistrationTask;
  102.  
  103.  
  104. @Override
  105. protected void onCreate(@Nullable Bundle savedInstanceState) {
  106. super.onCreate(savedInstanceState);
  107. setContentView(R.layout.activity_registration);
  108. final EditText editTextUsername = findViewById(R.id.editText_username);
  109. final EditText editTextEmail = findViewById(R.id.editText_email);
  110. final EditText editTextPassword = findViewById(R.id.editText_password);
  111. Button registration = findViewById(R.id.button_registration);
  112.  
  113. registration.setOnClickListener(new View.OnClickListener() {
  114. @Override
  115. public void onClick(View v) {
  116. String username = String.valueOf(editTextUsername.getText());
  117. String email = String.valueOf(editTextEmail.getText());
  118. String password = String.valueOf(editTextPassword.getText());
  119.  
  120. userRegistrationTask = new UserRegistrationTask(username, email, password);
  121. userRegistrationTask.execute((Void) null);
  122.  
  123. }
  124. });
  125. }
  126.  
  127.  
  128. public class UserRegistrationTask extends AsyncTask<Void, Void, Boolean> {
  129.  
  130. private final String mUsername;
  131. private final String mEmail;
  132. private final String mPassword;
  133.  
  134. UserRegistrationTask(String username, String email, String password) {
  135. mUsername = username;
  136. mEmail = email;
  137. mPassword = password;
  138. }
  139.  
  140. @Override
  141. protected Boolean doInBackground(Void... params) {
  142. // TODO: attempt authentication against a network service.
  143.  
  144. try {
  145. URL url = new URL("http://dancecrm.ru/templates/register.php");
  146. Map<String,Object> requestParams = new LinkedHashMap<>();
  147. requestParams.put("name", mUsername);
  148. requestParams.put("email", mEmail);
  149. requestParams.put("password", mPassword);
  150.  
  151. StringBuilder postData = new StringBuilder();
  152. for (Map.Entry<String,Object> param : requestParams.entrySet()) {
  153. if (postData.length() != 0) postData.append('&');
  154. postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
  155. postData.append('=');
  156. postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
  157. }
  158. byte[] postDataBytes = postData.toString().getBytes("UTF-8");
  159.  
  160. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
  161. conn.setRequestMethod("POST");
  162. conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  163. conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
  164. conn.setDoOutput(true);
  165. conn.getOutputStream().write(postDataBytes);
  166. conn.getResponseCode();
  167. } catch (Exception e) {
  168. e.printStackTrace();
  169. }
  170.  
  171.  
  172. // TODO: register the new account here.
  173. return true;
  174. }
  175.  
  176. }
  177. }
  178.  
  179. <?xml version="1.0" encoding="utf-8"?>
  180. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  181. package="devs.mulham.raee.sample">
  182.  
  183. <uses-permission android:name="android.permission.INTERNET" />
  184.  
  185. <application
  186. android:allowBackup="true"
  187. android:icon="@mipmap/ic_launcher"
  188. android:theme="@style/AppTheme">
  189. <activity
  190. android:name=".RegistrationActivity"
  191. android:theme="@style/AppTheme.NoActionBar">
  192. <intent-filter>
  193. <action android:name="android.intent.action.MAIN" />
  194.  
  195. <category android:name="android.intent.category.LAUNCHER" />
  196. </intent-filter>
  197. </activity>
  198. <activity android:name=".MainActivity"/>
  199. </application>
  200.  
  201. </manifest>
Add Comment
Please, Sign In to add comment