Advertisement
Guest User

Untitled

a guest
Nov 11th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.06 KB | None | 0 0
  1. package com.foi.air1603.sport_manager;
  2.  
  3. import android.content.Context;
  4. import android.os.Bundle;
  5. import android.support.design.widget.FloatingActionButton;
  6. import android.support.design.widget.Snackbar;
  7. import android.text.TextUtils;
  8. import android.view.View;
  9. import android.support.design.widget.NavigationView;
  10. import android.support.v4.view.GravityCompat;
  11. import android.support.v4.widget.DrawerLayout;
  12. import android.support.v7.app.ActionBarDrawerToggle;
  13. import android.support.v7.app.AppCompatActivity;
  14. import android.support.v7.widget.Toolbar;
  15. import android.view.Menu;
  16. import android.view.MenuItem;
  17. import android.view.inputmethod.InputMethodManager;
  18. import android.widget.Button;
  19. import android.widget.EditText;
  20. import android.widget.TextView;
  21. import com.example.webservice.DataLoadedListener;
  22.  
  23. import com.example.webservice.DataLoader;
  24. import com.example.webservice.User;
  25. import com.example.webservice.WsDataLoader;
  26.  
  27. public class RegisterActivity extends AppCompatActivity
  28. implements NavigationView.OnNavigationItemSelectedListener, DataLoadedListener {
  29.  
  30. @Override
  31. protected void onCreate(Bundle savedInstanceState) {
  32. super.onCreate(savedInstanceState);
  33. setContentView(R.layout.activity_register);
  34. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  35. setSupportActionBar(toolbar);
  36.  
  37. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  38. fab.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View view) {
  41. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  42. .setAction("Action", null).show();
  43. }
  44. });
  45.  
  46. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  47. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  48. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  49. drawer.setDrawerListener(toggle);
  50. toggle.syncState();
  51.  
  52. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  53. navigationView.setNavigationItemSelectedListener(this);
  54.  
  55. final EditText etUsernameR = (EditText) findViewById(R.id.etUsernameR); //et is short for EditText
  56. final EditText etPasswordR1 = (EditText) findViewById(R.id.etPasswordR1);
  57. final EditText etPasswordR2 = (EditText) findViewById(R.id.etPasswordR2);
  58. final EditText etName = (EditText) findViewById(R.id.etName);
  59. final EditText etLastName = (EditText) findViewById(R.id.etLastName);
  60. final EditText etAddress = (EditText) findViewById(R.id.etAddress);
  61. final EditText etPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
  62. final Button bRegistracija = (Button) findViewById(R.id.bRegistracija); //b is short for Button
  63.  
  64.  
  65. bRegistracija.setOnClickListener(new View.OnClickListener() {
  66. @Override
  67. public void onClick(View v) {
  68.  
  69.  
  70. EditText etMail = (EditText) findViewById(R.id.etMail);
  71. String strMail = etMail.getText().toString();
  72. EditText etUsernameR = (EditText) findViewById(R.id.etUsernameR);
  73. String strUsernameR = etUsernameR.getText().toString();
  74. EditText etPasswordR1 = (EditText) findViewById(R.id.etPasswordR1);
  75. String strPasswordR1 = etPasswordR1.getText().toString();
  76. EditText etPasswordR2 = (EditText) findViewById(R.id.etPasswordR2);
  77. String strPasswordR2 = etPasswordR2.getText().toString();
  78. EditText etName = (EditText) findViewById(R.id.etName);
  79. String strName = etName.getText().toString();
  80. EditText etLastName = (EditText) findViewById(R.id.etLastName);
  81. String strLastName = etLastName.getText().toString();
  82. EditText etAddress = (EditText) findViewById(R.id.etAddress);
  83. String strAddress = etAddress.getText().toString();
  84. EditText etPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
  85. String strPhoneNumber = etPhoneNumber.getText().toString();
  86. boolean pass = false;
  87. boolean email = false;
  88.  
  89.  
  90.  
  91. if(TextUtils.isEmpty(strMail)) {
  92. etMail.setError("Polje je obavezno");
  93. } else {
  94. boolean valid = isValidEmailAddress(strMail);
  95. if(valid){
  96. email = true;
  97. } else {
  98. etMail.setError("Email nije validan");
  99. }
  100. }
  101. if(TextUtils.isEmpty(strUsernameR)) {
  102. etUsernameR.setError("Polje je obavezno");
  103. }
  104. if(TextUtils.isEmpty(strPasswordR1)) {
  105. etPasswordR1.setError("Polje je obavezno");
  106. }
  107. if(TextUtils.isEmpty(strPasswordR2)) {
  108. etPasswordR2.setError("Polje je obavezno");
  109. } else {
  110. if(etPasswordR2 == etPasswordR1) {
  111. pass = true;
  112. } else {
  113. pass = true;
  114. etPasswordR2.setError("Lozinke se moraju podudarati!");
  115. }
  116.  
  117.  
  118. }
  119. if(TextUtils.isEmpty(strName)) {
  120. etName.setError("Polje je obavezno");
  121. }
  122. if(TextUtils.isEmpty(strLastName)) {
  123. etLastName.setError("Polje je obavezno");
  124. }
  125. if(TextUtils.isEmpty(strAddress)) {
  126. etAddress.setError("Polje je obavezno");
  127. }
  128. if(TextUtils.isEmpty(strPhoneNumber)) {
  129. etPhoneNumber.setError("Polje je obavezno");
  130. }
  131.  
  132. InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  133. imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
  134.  
  135. if(!TextUtils.isEmpty(strPhoneNumber) && !TextUtils.isEmpty(strAddress) && !TextUtils.isEmpty(strLastName) && !TextUtils.isEmpty(strName) && pass && !TextUtils.isEmpty(strPasswordR1) && !TextUtils.isEmpty(strUsernameR) && email) {
  136. DataLoader dataLoader;
  137. dataLoader = new WsDataLoader();
  138. //dataLoader.loadData(dataLoader. , "getUserById", "1", User.class);
  139. System.out.println("eto me nazad u viewueeeeee");
  140.  
  141. }
  142.  
  143. }
  144. });
  145. }
  146.  
  147. public boolean isValidEmailAddress(String email) {
  148. String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
  149. java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
  150. java.util.regex.Matcher m = p.matcher(email);
  151. return m.matches();
  152. }
  153.  
  154. @Override
  155. public void onBackPressed() {
  156. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  157. if (drawer.isDrawerOpen(GravityCompat.START)) {
  158. drawer.closeDrawer(GravityCompat.START);
  159. } else {
  160. super.onBackPressed();
  161. }
  162. }
  163.  
  164. @Override
  165. public boolean onCreateOptionsMenu(Menu menu) {
  166. // Inflate the menu; this adds items to the action bar if it is present.
  167. getMenuInflater().inflate(R.menu.register, menu);
  168. return true;
  169. }
  170.  
  171. @Override
  172. public boolean onOptionsItemSelected(MenuItem item) {
  173. // Handle action bar item clicks here. The action bar will
  174. // automatically handle clicks on the Home/Up button, so long
  175. // as you specify a parent activity in AndroidManifest.xml.
  176. int id = item.getItemId();
  177.  
  178. //noinspection SimplifiableIfStatement
  179. if (id == R.id.action_settings) {
  180. return true;
  181. }
  182.  
  183. return super.onOptionsItemSelected(item);
  184. }
  185.  
  186. @SuppressWarnings("StatementWithEmptyBody")
  187. @Override
  188. public boolean onNavigationItemSelected(MenuItem item) {
  189. // Handle navigation view item clicks here.
  190. int id = item.getItemId();
  191.  
  192. if (id == R.id.nav_camera) {
  193. // Handle the camera action
  194. } else if (id == R.id.nav_gallery) {
  195.  
  196. } else if (id == R.id.nav_slideshow) {
  197.  
  198. } else if (id == R.id.nav_manage) {
  199.  
  200. } else if (id == R.id.nav_share) {
  201.  
  202. } else if (id == R.id.nav_send) {
  203.  
  204. }
  205.  
  206. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  207. drawer.closeDrawer(GravityCompat.START);
  208. return true;
  209. }
  210.  
  211. @Override
  212. public void onDataLoaded(Object result) {
  213. System.out.println("eto me nazad u viewueeeeee");
  214.  
  215. if (result instanceof User) {
  216. User user = (User) result;
  217. System.out.println("Moje ime je: " + user.firstName + " " + user.lastName);
  218. }
  219.  
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement