Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class efetuarcadastro extends android.support.v4.app.Fragment {
- View myView;
- String url = "";
- String parametros = "";
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- myView = inflater.inflate( R.layout.efetuarcadastro, container,false);
- final EditText nome = myView.findViewById( R.id.nome );
- final EditText login = myView.findViewById( R.id.login );
- final EditText email = myView.findViewById( R.id.cadmail );
- final EditText senha = myView.findViewById( R.id.Asenha );
- final EditText confSenha = myView.findViewById( R.id.confSenha );
- myView.findViewById( R.id.cad ).setOnClickListener( new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ConnectivityManager connMgr = (ConnectivityManager)
- getActivity().getSystemService( Context.CONNECTIVITY_SERVICE );
- NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
- if (networkInfo != null && networkInfo.isConnected()){
- String name = nome.getText().toString();
- String user = login.getText().toString();
- String emails = email.getText().toString();
- String password = senha.getText().toString();
- String confpass = confSenha.getText().toString();
- if (name.isEmpty() ||
- user.isEmpty() ||
- login.getText().toString().length() < 5 ||
- emails.isEmpty() ||
- !emailValidar( emails ) ||
- password.isEmpty() ||
- senha.getText().toString().length() < 8 ||
- confpass.isEmpty() ||
- !confpass.equals(password))
- {
- validaCampos();
- } else
- {
- url = "http://192.168.25.230:8888/app/cadastro.php";
- parametros = "nome=" + name + "&login=" + user + "&email=" + emails + "&senha=" + password;
- new SolicitaDados().execute(url);
- }
- } else {
- Toast.makeText( getActivity().getApplicationContext(), "Nehuma Conexão foi Identificada", Toast.LENGTH_LONG).show();
- }
- }
- private void validaCampos() {
- boolean res = false;
- boolean sen = false;
- boolean qtdlogin = false;
- boolean qtdsenha = false;
- String name = nome.getText().toString();
- String user = login.getText().toString();
- String emails = email.getText().toString();
- String password = senha.getText().toString();
- String confpass = confSenha.getText().toString();
- if (res = verificaCampovazio( name )) {
- nome.requestFocus();
- } else if (res = verificaCampovazio( user )) {
- login.requestFocus();
- } else if (qtdlogin = login.getText().toString().length() < 5) {
- login.getText().clear();
- login.requestFocus();
- } else if (res = !emailValidar( emails )) {
- email.requestFocus();
- } else if (res = verificaCampovazio( password )) {
- senha.requestFocus();
- } else if (qtdsenha = senha.getText().toString().length() < 8) {
- senha.getText().clear();
- confSenha.getText().clear();
- senha.requestFocus();
- } else if (res = verificaCampovazio( confpass )) {
- confSenha.requestFocus();
- } else if (sen = !password.equals( confpass )) {
- senha.getText().clear();
- confSenha.getText().clear();
- senha.requestFocus();
- }
- if (res) {
- AlertDialog.Builder Mcampovazio = new AlertDialog.Builder( efetuarcadastro.this.getActivity() );
- Mcampovazio.setTitle( "Aviso: " );
- Mcampovazio.setMessage( "Há campos inválidos ou sem preenchimento" );
- Mcampovazio.setNeutralButton( "OK", null );
- Mcampovazio.show();
- }
- if (sen) {
- AlertDialog.Builder Mcampovazio = new AlertDialog.Builder( efetuarcadastro.this.getActivity() );
- Mcampovazio.setTitle( "Aviso: " );
- Mcampovazio.setMessage( "Senhas estão diferentes" );
- Mcampovazio.setNeutralButton( "OK", null );
- Mcampovazio.show();
- }
- if (qtdlogin) {
- AlertDialog.Builder Mcampovazio = new AlertDialog.Builder( efetuarcadastro.this.getActivity() );
- Mcampovazio.setTitle( "Aviso: " );
- Mcampovazio.setMessage( "O login não pode conter menos que 5 caracteres" );
- Mcampovazio.setNeutralButton( "OK", null );
- Mcampovazio.show();
- }
- if (qtdsenha) {
- AlertDialog.Builder Mcampovazio = new AlertDialog.Builder( efetuarcadastro.this.getActivity() );
- Mcampovazio.setTitle( "Aviso: " );
- Mcampovazio.setMessage( "A senha não pode conter menos que 8 caracteres" );
- Mcampovazio.setNeutralButton( "OK", null );
- Mcampovazio.show();
- }
- }
- private boolean verificaCampovazio(String valor) {
- Boolean resultado = (TextUtils.isEmpty( valor ) || valor.trim().isEmpty());
- return resultado;
- }
- private boolean emailValidar(String email) {
- Boolean resultado = (!verificaCampovazio( email ) && Patterns.EMAIL_ADDRESS.matcher( email ).matches());
- return resultado;
- }
- private String getMACAddress(String interfaceName) {
- try {
- List<NetworkInterface> interfaces = Collections.list( NetworkInterface.getNetworkInterfaces() );
- for (NetworkInterface intf : interfaces) {
- if (interfaceName != null) {
- if (!intf.getName().equalsIgnoreCase( interfaceName )) continue;
- }
- byte[] mac = intf.getHardwareAddress();
- if (mac == null) return "";
- StringBuilder buf = new StringBuilder();
- for (byte aMac : mac) buf.append( String.format( "%02X:", aMac ) );
- if (buf.length() > 0) buf.deleteCharAt( buf.length() - 1 );
- return buf.toString();
- }
- } catch (Exception ignored) {
- }
- return "";
- }
- class SolicitaDados extends AsyncTask<String,Void, String>{
- @Override
- protected String doInBackground (String... urls){
- return conexao.postdados (urls[0],parametros);
- }
- @Override
- protected void onPostExecute (String resultado){
- if (resultado.contains("email_erro")){
- AlertDialog.Builder Mcampovazio = new AlertDialog.Builder( efetuarcadastro.this.getActivity() );
- Mcampovazio.setTitle( "Aviso: " );
- Mcampovazio.setMessage( "Endereço MAC já cadastrado" );
- Mcampovazio.setNeutralButton( "OK", null );
- Mcampovazio.show();
- }
- else if (resultado.contains("login_erro")){
- AlertDialog.Builder Mcampovazio = new AlertDialog.Builder( efetuarcadastro.this.getActivity() );
- Mcampovazio.setTitle( "Aviso: " );
- Mcampovazio.setMessage( "Login já cadastrado" );
- Mcampovazio.setNeutralButton( "OK", null );
- Mcampovazio.show();
- }
- else if (resultado.contains("login_ok")) {
- FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
- ft.replace( R.id.frame_layout, new Tela_Principal() );
- ft.commit();
- Toast.makeText( getActivity().getApplicationContext(), "Cadastro Realizado com Sucesso", Toast.LENGTH_LONG ).show();
- }
- else
- {
- Toast.makeText( getActivity().getApplicationContext(), "Erro ao realizar cadastro", Toast.LENGTH_LONG ).show();
- }
- }
- }
- } );
- return myView;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement