Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. package com.maps.deseuri.deseuri.JoiningScreen;
  2.  
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.support.v4.view.ViewPager;
  6. import android.support.v7.app.AlertDialog;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.ImageSwitcher;
  14.  
  15. import com.maps.deseuri.deseuri.CustomSwipe;
  16. import com.maps.deseuri.deseuri.MapsActivity;
  17. import com.maps.deseuri.deseuri.R;
  18. import com.maps.deseuri.deseuri.Singleton.Response;
  19.  
  20. public class RegisterActivity extends AppCompatActivity {
  21. MapsActivity mapsActivity;
  22.  
  23. ViewPager viewPager;
  24. CustomSwipe customSwipe;
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28.  
  29. //mapsActivity = new MapsActivity();
  30.  
  31. try {
  32. Log.e("AM INITIALIZAT","AM INITIALIZAT");
  33. mapsActivity = new MapsActivity();
  34. mapsActivity.initTcpFunc();
  35. } catch (Exception e) {
  36. Log.e("initTcpFunct", e.getMessage());
  37. }
  38.  
  39. setContentView(R.layout.activity_register);
  40.  
  41. //UI
  42. final EditText etName = (EditText)findViewById(R.id.etName);
  43. final EditText etUsername = (EditText)findViewById(R.id.etUsername);
  44. final EditText etPassword = (EditText)findViewById(R.id.etPassword);
  45. //final EditText etPhoneNumber = (EditText)findViewById(R.id.etPhoneNumber);
  46. final Button bRegister = (Button)findViewById(R.id.bRegister);
  47.  
  48. final Context asta = this;
  49. bRegister.setOnClickListener(new View.OnClickListener() {
  50. @Override
  51. public void onClick(View view) {
  52.  
  53. if(validateName(etName.getEditableText().toString())){
  54. //show alert
  55. }
  56. else if(validateUsername(etUsername.getEditableText().toString())){
  57.  
  58. }
  59. else if(validatePassword(etPassword.getEditableText().toString())){
  60.  
  61. }
  62. /*
  63. else if(validatePhoneNumber(){
  64.  
  65. }*/
  66. else
  67. {
  68. Log.e("am intrat2", "am intrat2");
  69. try {
  70. Log.e("am intrat", "am intrat");
  71. int response;
  72. String imgPoz = String.valueOf(Response.getInstance().getCurentImagePoz());
  73. mapsActivity.registerAccount(etName.getEditableText().toString(), etUsername.getEditableText().toString(), etPassword.getEditableText().toString(), imgPoz);
  74. while (Response.getInstance().getResponseCode() == -1) ;
  75. response = Response.getInstance().getResponseCode();
  76. Response.getInstance().setResponseCode(-1);
  77. Log.e("response", String.valueOf(response));
  78. if (response == 0)
  79. RegisterActivity.this.finish();//good
  80. else
  81. new AlertDialog.Builder(asta)
  82. .setTitle("ERROR")
  83. .setMessage("ERROR")
  84. .setCancelable(false)
  85. .setPositiveButton("ok", new DialogInterface.OnClickListener() {
  86. @Override
  87. public void onClick(DialogInterface dialog, int which) {
  88. // Whatever...
  89. }
  90. }).show();//bad
  91. } catch (Exception e) {
  92. e.getMessage();
  93. }
  94. }
  95.  
  96. }
  97. });
  98.  
  99. //before register check if everything is good
  100. //insert back button
  101. //if everything is good then go to the login screen
  102.  
  103. viewPager=(ViewPager)findViewById(R.id.viewPager);
  104. customSwipe = new CustomSwipe(this);
  105. viewPager.setAdapter(customSwipe);
  106. }
  107. private boolean validateName(String name){
  108. if(name.length()<=3){
  109. return true;
  110. }
  111. for(int poz=0; poz<name.length();poz++){
  112. if(!((name.charAt(poz)>='a' && name.charAt(poz)<='z') || (name.charAt(poz)>='A' && name.charAt(poz)<='Z') || name.charAt(poz)==' ')){
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. private boolean validateUsername(String username){
  119. if(username.length()<=3){
  120. return true;
  121. }
  122. for(int poz=0; poz<username.length();poz++){
  123. if(!((username.charAt(poz)>='a' && username.charAt(poz)<='z') || (username.charAt(poz)>='A' && username.charAt(poz)<='Z') || username.charAt(poz)=='.'|| username.charAt(poz)=='_'|| username.charAt(poz)=='-')){
  124. return true;
  125. }
  126. }
  127. return false;
  128. }
  129. private boolean validatePassword(String password){
  130. if(password.length()<=3){
  131. return true;
  132. }
  133. for(int poz=0; poz<password.length();poz++){
  134. if(!(password.charAt(poz)==' ')){
  135. return true;
  136. }
  137. }
  138. return false;
  139. }
  140. private boolean validatePhoneNumber(String phoneNumber){
  141. return false;
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement