Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.foi.air1603.sport_manager;
- import android.content.Context;
- import android.os.Bundle;
- import android.support.design.widget.FloatingActionButton;
- import android.support.design.widget.Snackbar;
- import android.text.TextUtils;
- import android.view.View;
- import android.support.design.widget.NavigationView;
- import android.support.v4.view.GravityCompat;
- import android.support.v4.widget.DrawerLayout;
- import android.support.v7.app.ActionBarDrawerToggle;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import com.example.webservice.DataLoadedListener;
- import com.example.webservice.DataLoader;
- import com.example.webservice.User;
- import com.example.webservice.WsDataLoader;
- public class RegisterActivity extends AppCompatActivity
- implements NavigationView.OnNavigationItemSelectedListener, DataLoadedListener {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
- }
- });
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
- drawer.setDrawerListener(toggle);
- toggle.syncState();
- NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
- navigationView.setNavigationItemSelectedListener(this);
- final EditText etUsernameR = (EditText) findViewById(R.id.etUsernameR); //et is short for EditText
- final EditText etPasswordR1 = (EditText) findViewById(R.id.etPasswordR1);
- final EditText etPasswordR2 = (EditText) findViewById(R.id.etPasswordR2);
- final EditText etName = (EditText) findViewById(R.id.etName);
- final EditText etLastName = (EditText) findViewById(R.id.etLastName);
- final EditText etAddress = (EditText) findViewById(R.id.etAddress);
- final EditText etPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
- final Button bRegistracija = (Button) findViewById(R.id.bRegistracija); //b is short for Button
- bRegistracija.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- EditText etMail = (EditText) findViewById(R.id.etMail);
- String strMail = etMail.getText().toString();
- EditText etUsernameR = (EditText) findViewById(R.id.etUsernameR);
- String strUsernameR = etUsernameR.getText().toString();
- EditText etPasswordR1 = (EditText) findViewById(R.id.etPasswordR1);
- String strPasswordR1 = etPasswordR1.getText().toString();
- EditText etPasswordR2 = (EditText) findViewById(R.id.etPasswordR2);
- String strPasswordR2 = etPasswordR2.getText().toString();
- EditText etName = (EditText) findViewById(R.id.etName);
- String strName = etName.getText().toString();
- EditText etLastName = (EditText) findViewById(R.id.etLastName);
- String strLastName = etLastName.getText().toString();
- EditText etAddress = (EditText) findViewById(R.id.etAddress);
- String strAddress = etAddress.getText().toString();
- EditText etPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
- String strPhoneNumber = etPhoneNumber.getText().toString();
- boolean pass = false;
- boolean email = false;
- if(TextUtils.isEmpty(strMail)) {
- etMail.setError("Polje je obavezno");
- } else {
- boolean valid = isValidEmailAddress(strMail);
- if(valid){
- email = true;
- } else {
- etMail.setError("Email nije validan");
- }
- }
- if(TextUtils.isEmpty(strUsernameR)) {
- etUsernameR.setError("Polje je obavezno");
- }
- if(TextUtils.isEmpty(strPasswordR1)) {
- etPasswordR1.setError("Polje je obavezno");
- }
- if(TextUtils.isEmpty(strPasswordR2)) {
- etPasswordR2.setError("Polje je obavezno");
- } else {
- if(etPasswordR2 == etPasswordR1) {
- pass = true;
- } else {
- pass = true;
- etPasswordR2.setError("Lozinke se moraju podudarati!");
- }
- }
- if(TextUtils.isEmpty(strName)) {
- etName.setError("Polje je obavezno");
- }
- if(TextUtils.isEmpty(strLastName)) {
- etLastName.setError("Polje je obavezno");
- }
- if(TextUtils.isEmpty(strAddress)) {
- etAddress.setError("Polje je obavezno");
- }
- if(TextUtils.isEmpty(strPhoneNumber)) {
- etPhoneNumber.setError("Polje je obavezno");
- }
- InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
- if(!TextUtils.isEmpty(strPhoneNumber) && !TextUtils.isEmpty(strAddress) && !TextUtils.isEmpty(strLastName) && !TextUtils.isEmpty(strName) && pass && !TextUtils.isEmpty(strPasswordR1) && !TextUtils.isEmpty(strUsernameR) && email) {
- DataLoader dataLoader;
- dataLoader = new WsDataLoader();
- //dataLoader.loadData(dataLoader. , "getUserById", "1", User.class);
- System.out.println("eto me nazad u viewueeeeee");
- }
- }
- });
- }
- public boolean isValidEmailAddress(String email) {
- 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,}))$";
- java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
- java.util.regex.Matcher m = p.matcher(email);
- return m.matches();
- }
- @Override
- public void onBackPressed() {
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- if (drawer.isDrawerOpen(GravityCompat.START)) {
- drawer.closeDrawer(GravityCompat.START);
- } else {
- super.onBackPressed();
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.register, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @SuppressWarnings("StatementWithEmptyBody")
- @Override
- public boolean onNavigationItemSelected(MenuItem item) {
- // Handle navigation view item clicks here.
- int id = item.getItemId();
- if (id == R.id.nav_camera) {
- // Handle the camera action
- } else if (id == R.id.nav_gallery) {
- } else if (id == R.id.nav_slideshow) {
- } else if (id == R.id.nav_manage) {
- } else if (id == R.id.nav_share) {
- } else if (id == R.id.nav_send) {
- }
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- drawer.closeDrawer(GravityCompat.START);
- return true;
- }
- @Override
- public void onDataLoaded(Object result) {
- System.out.println("eto me nazad u viewueeeeee");
- if (result instanceof User) {
- User user = (User) result;
- System.out.println("Moje ime je: " + user.firstName + " " + user.lastName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement