Exemplo n.º 1
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btnSigup:
        if (InternetUtils.getInstance().isConnectingToInternet(this)) {
          Boolean flagEmail = false;
          Boolean flagFirstName = false;
          Boolean flagLastName = false;
          Boolean flagmobile = false;
          Boolean flagPassword = false;
          Boolean flagConfirmPassword = false;

          String strEmail = edEmail.getText().toString();
          String strFirstName = edFirstName.getText().toString();
          String strLastName = edLastName.getText().toString();
          String strMobile = edMobile.getText().toString();
          String strPassword = edPassword.getText().toString();
          String strConfirmPassword = edConfirmPassword.getText().toString();

          if (strEmail.equalsIgnoreCase("") || !isValidInput(strEmail)) {
            btnCheckEmail.setVisibility(View.VISIBLE);
            btnCheckEmail.setBackgroundResource(R.drawable.check_false);
            flagEmail = false;
          } else {
            btnCheckEmail.setVisibility(View.VISIBLE);
            btnCheckEmail.setBackgroundResource(R.drawable.check_true);
            flagEmail = true;
          }
          if (strFirstName.equalsIgnoreCase("")) {

            btnCheckFirstName.setVisibility(View.VISIBLE);
            btnCheckFirstName.setBackgroundResource(R.drawable.check_false);
            flagFirstName = false;
          } else {
            if (strFirstName.length() < 2) {
              btnCheckFirstName.setVisibility(View.VISIBLE);
              btnCheckFirstName.setBackgroundResource(R.drawable.check_false);
              txtCheckFirstName.setVisibility(View.VISIBLE);
              txtCheckFirstName.setText("First Name is required");
              flagFirstName = false;
            } else {
              txtCheckFirstName.setVisibility(View.GONE);
              btnCheckFirstName.setVisibility(View.VISIBLE);
              btnCheckFirstName.setBackgroundResource(R.drawable.check_true);
              flagFirstName = true;
            }
          }
          if (strLastName.equalsIgnoreCase("")) {
            btnCheckLastName.setVisibility(View.VISIBLE);
            btnCheckLastName.setBackgroundResource(R.drawable.check_false);
            flagLastName = false;
          } else {
            if (strLastName.length() < 2) {
              btnCheckLastName.setVisibility(View.VISIBLE);
              btnCheckLastName.setBackgroundResource(R.drawable.check_false);
              txtCheckLastName.setVisibility(View.VISIBLE);
              txtCheckLastName.setText("Last Name is required");
              flagLastName = false;
            } else {
              txtCheckLastName.setVisibility(View.GONE);
              btnCheckLastName.setVisibility(View.VISIBLE);
              btnCheckLastName.setBackgroundResource(R.drawable.check_true);
              flagLastName = true;
            }
          }
          if (strMobile.equalsIgnoreCase("")) {
            btnCheckMobile.setVisibility(View.VISIBLE);
            btnCheckMobile.setBackgroundResource(R.drawable.check_false);
            flagmobile = false;
          } else {
            if (strMobile.length() < 10) {
              btnCheckMobile.setVisibility(View.VISIBLE);
              btnCheckMobile.setBackgroundResource(R.drawable.check_false);
              txtCheckMobile.setVisibility(View.VISIBLE);
              txtCheckMobile.setText("Mobile number is required");
              flagmobile = false;
            } else {
              txtCheckMobile.setVisibility(View.GONE);
              btnCheckMobile.setVisibility(View.VISIBLE);
              btnCheckMobile.setBackgroundResource(R.drawable.check_true);
              flagmobile = true;
            }
          }
          if (strPassword.equalsIgnoreCase("")) {
            btnCheckPassword.setVisibility(View.VISIBLE);
            btnCheckPassword.setBackgroundResource(R.drawable.check_false);
            flagPassword = false;
          } else {
            if (strPassword.length() < 6) {
              btnCheckPassword.setVisibility(View.VISIBLE);
              btnCheckPassword.setBackgroundResource(R.drawable.check_false);
              txtCheckPassword.setVisibility(View.VISIBLE);
              txtCheckPassword.setText("The Password must be at least 6 characters long");
              flagPassword = false;
            } else {
              txtCheckPassword.setVisibility(View.GONE);
              PasswordValidator checkpass = new PasswordValidator(MainActivity.this);
              if (checkpass.validate(strPassword) == false) {
                final Dialog dialogerr =
                    new Dialog(MainActivity.this, android.R.style.Theme_Translucent);
                dialogerr.requestWindowFeature(Window.FEATURE_NO_TITLE);

                dialogerr.setCancelable(true);
                dialogerr.setContentView(R.layout.dialog_err);
                TextView txtContent = (TextView) dialogerr.findViewById(R.id.txtContent);
                txtContent.setText(
                    "Passwords must have at least one non letter or digit character. Passwords must have at least one lowercase ('a'-'z'). Passwords must have at least one uppercase ('A'-'Z').");
                Button btnOke = (Button) dialogerr.findViewById(R.id.bntOk);

                btnOke.setOnClickListener(
                    new OnClickListener() {

                      @Override
                      public void onClick(View v) {

                        dialogerr.dismiss();
                      }
                    });

                dialogerr.show();
                flagPassword = false;
              } else {
                btnCheckPassword.setVisibility(View.VISIBLE);
                btnCheckPassword.setBackgroundResource(R.drawable.check_true);
                flagPassword = true;
              }
            }
          }
          if (strConfirmPassword.equalsIgnoreCase("")
              || !strConfirmPassword.equalsIgnoreCase(strPassword)) {
            btnCheckConfirmPassword.setVisibility(View.VISIBLE);
            btnCheckConfirmPassword.setBackgroundResource(R.drawable.check_false);
            flagConfirmPassword = false;
          } else {
            if (!flagPassword) {
              btnCheckConfirmPassword.setVisibility(View.VISIBLE);
              btnCheckConfirmPassword.setBackgroundResource(R.drawable.check_false);
              flagConfirmPassword = false;
            } else {
              btnCheckConfirmPassword.setVisibility(View.VISIBLE);
              btnCheckConfirmPassword.setBackgroundResource(R.drawable.check_true);
              flagConfirmPassword = true;
            }
          }
          AccountDTO dto = new AccountDTO();
          dto.setEmail(strEmail);
          dto.setFirstName(strFirstName);
          dto.setLastName(strLastName);
          dto.setMobileNo(strMobile);
          dto.setPassword(strPassword);
          dto.setConfirmPassword(strConfirmPassword);

          if (flagEmail
              && flagFirstName
              && flagLastName
              && flagmobile
              && flagPassword
              && flagConfirmPassword) {
            if (InternetUtils.getInstance().isConnectingToInternet(this)) {
              new VerySlowTaskRegister(dto).execute();
            }
          }
        } else {
          Toast.makeText(MainActivity.this, "no network", Toast.LENGTH_LONG).show();
        }

        break;

      default:
        break;
    }
  }
Exemplo n.º 2
0
  @SuppressLint("SimpleDateFormat")
  @Override
  public void onClick(View v) {
    Intent intent;
    switch (v.getId()) {
      case R.id.img_view_push_messages:
        if (InternetUtils.getInstance().isConnectingToInternet(HomeActivity.this)) {
          intent = new Intent(HomeActivity.this, ViewMessageActivity.class);

          startActivity(intent);
        } else {
          Toast.makeText(HomeActivity.this, "no net work", Toast.LENGTH_LONG).show();
        }

        break;

      case R.id.img_new_push_message:
        intent = new Intent(HomeActivity.this, UpdateAnimalActivity.class);

        startActivity(intent);
        break;
      case R.id.contact_us:
        intent = new Intent(HomeActivity.this, ContactUsActivity.class);
        startActivity(intent);
        break;
      case R.id.update:
        TokenModel tokenModel = TokenModel.getInstance();
        TokenDTO tokenDTO = tokenModel.getToken(HomeActivity.this);
        String dateExpires = tokenDTO.getExpires();
        Date date2 = null;
        Date date1 = null;
        String pattern = "EEE, dd MMM yyyy HH:mm:ss Z";
        SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.ENGLISH);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String currentDay = sdf.format(new Date());
        String currentDayExpires = format.format(new Date());
        try {
          date1 = format.parse(currentDayExpires);
          date2 = format.parse(dateExpires);
          if (date1.compareTo(date2) < 0) {
            if (InternetUtils.getInstance().isConnectingToInternet(this)) {
              this.runOnUiThread(
                  new Runnable() {

                    @Override
                    public void run() {
                      String path = Constants.URL_CATEGORY;
                      String[] strs = path.split("/");
                      File file =
                          new File(
                              Environment.getExternalStorageDirectory()
                                  + "/"
                                  + Constants.APP_NAME
                                  + "/"
                                  + strs[4]
                                  + "/");
                      // deleteDirectory(file);
                      DeleteRecursive(file);
                      adapter.notifyDataSetChanged();
                      grid.invalidateViews();
                    }
                  });
              new AsystaskUpdateAnimal(currentDay, tokenDTO, HomeActivity.this).execute();
              flag = true;
              // arrData = new ArrayList<Object>();
              // InitData();
              // adapter = new AnimalCategoryMasterAdapter(this,
              // R.layout.grid_row,
              // arrData);
              adapter.notifyDataSetChanged();
            } else {
              Toast.makeText(HomeActivity.this, "no network", Toast.LENGTH_LONG).show();
            }
          }
        } catch (Exception e) {
          // TODO: handle exception
        }

        break;
      default:
        break;
    }
  }