private String checkRight() {
   if (this.count == 0) {
     Toast.makeText(this, "您还没有选择张数", 0).show();
     return "您还没有选择张数";
   }
   TextView localTextView = (TextView) this.bNameItem.findViewById(R.id.itemInput);
   this.bName = localTextView.getText().toString().trim();
   if (TextUtils.isEmpty(this.bName)) {
     localTextView.setError(Html.fromHtml("<font color=#ff0000>取票人不能为空</font>"));
     localTextView.requestFocus();
     return "取票人不能为空";
   }
   localTextView = (TextView) this.bPhoneNoItem.findViewById(R.id.itemInput);
   this.bPhoneNo = localTextView.getText().toString().trim();
   if (TextUtils.isEmpty(this.bPhoneNo)) {
     localTextView.setError(Html.fromHtml("<font color=#ff0000>手机号不能为空</font>"));
     localTextView.requestFocus();
     return "手机号不能为空";
   }
   if ((this.bPhoneNo != null) && (this.bPhoneNo.length() < 11)) {
     localTextView.setError(Html.fromHtml("<font color=#ff0000>手机号错误</font>"));
     localTextView.requestFocus();
     return "手机号错误";
   }
   return null;
 }
  public boolean TextViewChecks() {

    Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(tbPass.getText());
    int count = 0;

    // Add Check for username with DB
    if (tbUser.length() < 6 | tbUser.length() > 12) {
      tbUser.setError("Enter a username between 6-12 Characters");
    } else {
      count++;
    }

    if (tbPass.length() < 6 | tbPass.length() > 12) {
      tbPass.setError("Enter a password between 6-12 Characters");
    } else {
      count++;
    }

    if (!m.find()) {
      count++;
      tbPass.setError("Enter a special character");
    } else {
      count++;
    }

    if (count == 3) return true;

    return false;
  }
Beispiel #3
0
  @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_save) {

      if (title.getText().toString().isEmpty()) title.setError("This field can't be empty.");
      else if (!price.getText().toString().matches("^\\d+$"))
        price.setError("It must be an integer.");
      else {
        currentBook.setTitle(title.getText().toString());
        currentBook.setAuthor(author.getText().toString());
        currentBook.setCourse(course.getText().toString());
        currentBook.setPrice(Integer.valueOf(price.getText().toString()));
        currentBook.setIsbn(isbn.getText().toString());
        SimpleBookManager.getInstance().saveChanges(this);
        setResult(RESULT_OK);
        finish();
        return true;
      }
    } else if (id == android.R.id.home) {
      onBackPressed();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
  private boolean SalvarConfig() {

    boolean erro = false;

    ParametroDTO parametro = null;

    txtImei = (TextView) findViewById(R.id.config_txt_Imei);
    txtVendedor = (TextView) findViewById(R.id.config_txt_Vendedor);
    txtConta = (TextView) findViewById(R.id.config_txt_Conta);

    String str = txtImei.getText().toString();
    if (str.equalsIgnoreCase("")) {
      txtImei.setHint(getResources().getString(R.string.config_lbl_dispositivo_hint));
      txtImei.setError(getResources().getString(R.string.config_lbl_dispositivo_hint));
      erro = true;
    }

    str = txtVendedor.getText().toString();
    if (str.equalsIgnoreCase("")) {
      txtVendedor.setHint(getResources().getString(R.string.config_lbl_vendedor_hint));
      txtVendedor.setError(getResources().getString(R.string.config_lbl_vendedor_hint));
      erro = true;
    }

    str = txtConta.getText().toString();
    if (str.equalsIgnoreCase("")) {
      txtConta.setHint(getResources().getString(R.string.config_lbl_conta_hint));
      txtConta.setError(getResources().getString(R.string.config_lbl_conta_hint));
      erro = true;
    }

    if (erro) return false;

    if (txtImei.getText().length() > 0) {
      parametro = new ParametroDTO();
      parametro.setid_empresa(0);
      parametro.setds_chave("IMEI");
      parametro.setds_valor(txtImei.getText().toString());
      ParametroDAO.insertorupdate(parametro);
    }

    if (txtVendedor.getText().length() > 0) {
      parametro = new ParametroDTO();
      parametro.setid_empresa(0);
      parametro.setds_chave("VENDEDOR");
      parametro.setds_valor(txtVendedor.getText().toString());
      ParametroDAO.insertorupdate(parametro);
    }

    if (txtConta.getText().length() > 0) {
      parametro = new ParametroDTO();
      parametro.setid_empresa(0);
      parametro.setds_chave("CONTA");
      parametro.setds_valor(txtConta.getText().toString());
      ParametroDAO.insertorupdate(parametro);
    }

    return true;
  }
  public boolean validateGrade(float grade, TextView editText) {
    if (grade < 1.0 || grade > 10.0) {
      editText.setError("Cijfer moet tussen 1.0 en 10.0 zijn");
      return false;
    }

    if (grade == 10.0 || ((grade + "").length() == 3 && (grade + "").charAt(1) == '.')) {
      return true;
    } else {
      editText.setError("Cijfer moet '1.0' formaat hebben");
      return false;
    }
  }
  /**
   * Kiểu tra Regex, tự set lỗi
   *
   * @param textView
   * @param regex
   * @param errorMessage
   * @return true: trùng regex
   */
  public static boolean isRegexValid(TextView textView, String regex, String errorMessage) {
    textView.setError(null); // clear error

    String text = textView.getText().toString().trim();

    // pattern doesn't match so returning false
    if (!Pattern.matches(regex, text)) {
      textView.setError(errorMessage);
      return false;
    }

    return true;
  }
 public void checkStopTimeInputAfterChange() {
   long newTime = 0;
   try {
     newTime = Long.parseLong(dayCycleStopTimeText.getText().toString());
     dayCycleStopTimeText.setError(null);
     if (newTime != EditorActivity.level.getDayCycleStopTime()) {
       EditorActivity.level.setDayCycleStopTime(newTime);
       EditorActivity.save(this);
     }
   } catch (NumberFormatException e) {
     dayCycleStopTimeText.setError(this.getResources().getText(R.string.invalid_number));
   }
 }
  /** kiểm tra có Text, tự set lỗi True: nếu có Text */
  public static boolean hasText(TextView textView, String errorMessage) {
    textView.setError(null); // clear error

    String text = textView.getText().toString().trim();

    if (TextUtils.isEmpty(text)) {
      // Không có text
      textView.setError(errorMessage);
      return false;
    }

    return true;
  }
Beispiel #9
0
 /**
  * Called to validate our form. If an error is found, it will be displayed in the corresponding
  * field.
  *
  * @return boolean : true if the form is valid false if the form is invalid
  */
 public boolean validate() {
   boolean result = true;
   Iterator<ValidateField> it = this.mValidates.iterator();
   while (it.hasNext()) {
     ValidateField validator = it.next();
     TextView field = validator.getSource();
     field.setError(null);
     if (!validator.isValid(field.getText())) {
       result = false;
       field.setError(validator.getMessages());
     }
   }
   return result;
 }
Beispiel #10
0
  private boolean isValid() {
    String old_password = input_old_password.getText().toString();
    String new_password = input_new_password.getText().toString();
    String confirm_password = input_confirm_password.getText().toString();

    if (old_password.isEmpty() || old_password.length() < 4 || old_password.length() > 32) {
      input_old_password.setError(getString(R.string.between_4_32));
      return false;
    } else {
      input_old_password.setError(null);
    }

    if (new_password.isEmpty() || new_password.length() < 4 || new_password.length() > 32) {
      input_new_password.setError(getString(R.string.between_4_32));
      return false;
    } else {
      input_new_password.setError(null);
    }

    if (old_password.equals(new_password)) {
      input_new_password.setError(getString(R.string.new_password_same));
      return false;
    } else {
      input_new_password.setError(null);
    }

    if (!confirm_password.equals(new_password)) {
      input_confirm_password.setError(getString(R.string.password_not_match));
      return false;
    } else {
      input_confirm_password.setError(null);
    }

    return true;
  }
 private boolean isValidField() {
   if (StringUtils.isNullOrEmpty(email)) {
     emailTextview.setError(getString(R.string.field_required));
     emailTextview.setFocusable(true);
     emailTextview.requestFocus();
     return false;
   }
   if (!StringUtils.isValidEmail(emailTextview.getText().toString(), false)) {
     emailTextview.setError(getString(R.string.field_validEmail));
     emailTextview.setFocusable(true);
     emailTextview.requestFocus();
     return false;
   }
   return true;
 }
Beispiel #12
0
  /**
   * @param text
   * @return
   */
  private boolean startConsoleActivity() {
    Uri uri =
        TransportFactory.getUri(
            (String) transportSpinner.getSelectedItem(), quickconnect.getText().toString());

    if (uri == null) {
      quickconnect.setError(
          getString(
              R.string.list_format_error,
              TransportFactory.getFormatHint(
                  (String) transportSpinner.getSelectedItem(), HostListActivity.this)));
      return false;
    }

    HostBean host = TransportFactory.findHost(hostdb, uri);
    if (host == null) {
      host = TransportFactory.getTransport(uri.getScheme()).createHost(uri);
      host.setColor(HostDatabase.COLOR_GRAY);
      host.setPubkeyId(HostDatabase.PUBKEYID_ANY);
      hostdb.saveHost(host);
    }

    Intent intent = new Intent(HostListActivity.this, ConsoleActivity.class);
    intent.setData(uri);
    startActivity(intent);

    return true;
  }
 @OnClick(R.id.btn_next)
 public void onNextEvent() {
   String phone = mPhoneView.getText().toString();
   if (StringUtils.isBlank(phone)) {
     mPhoneView.setError(getString(R.string.reqd_login_info));
     return;
   }
   Object countrySelection = mCountryListView.getSelectedItem();
   CountryVO selectedCountryVO = mCountriesView2VOMap.get(countrySelection.toString());
   PhonePINVerifyFragment next =
       PhonePINVerifyFragment.newInstance(
           phone, selectedCountryVO == null ? "" : selectedCountryVO.getCode());
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     Transition exit =
         TransitionInflater.from(getContext()).inflateTransition(R.transition.slide_right);
     Transition enter =
         TransitionInflater.from(getContext()).inflateTransition(R.transition.slide_left);
     next.setSharedElementEnterTransition(enter);
     next.setEnterTransition(enter);
     setExitTransition(exit);
     next.setSharedElementReturnTransition(exit);
   }
   getActivity()
       .getSupportFragmentManager()
       .beginTransaction()
       .addSharedElement(mBtnNextView, "btn_next")
       .replace(R.id.container, next)
       .addToBackStack(null)
       .commit();
 }
Beispiel #14
0
 /** 银行帐号为16-21位的数字 */
 public static boolean isAccountNumber(TextView w) {
   if (!RegexUtil.isAccountNumber(w.getText().toString().trim())) {
     w.setError("银行帐号必须为16-21位的数字!");
     w.setFocusable(true);
     return false;
   }
   return true;
 }
Beispiel #15
0
 public static boolean isMobileNumber(TextView w) {
   if (!RegexUtil.isMobileNumber(w.getText().toString().trim())) {
     w.setError("手机号码为11位数字!");
     w.setFocusable(true);
     return false;
   }
   return true;
 }
Beispiel #16
0
 public static boolean isArea(TextView w) {
   if (!RegexUtil.isArea(w.getText().toString().trim())) {
     w.setError("面积有非法字符!");
     w.setFocusable(true);
     return false;
   }
   return true;
 }
Beispiel #17
0
 public static boolean isDouble(TextView w, String displayStr) {
   if (!StringUtil.decimal(w.getText().toString().trim())) {
     w.setError(displayStr + "必须为数字且大于0!");
     w.setFocusable(true);
     w.requestFocus();
     return true;
   }
   return false;
 }
Beispiel #18
0
 public static boolean isEmpty(TextView w, String displayStr) {
   if (StringUtil.empty(w.getText().toString().trim())) {
     w.setError(displayStr + "不能为空!");
     w.setFocusable(true);
     w.requestFocus();
     return true;
   }
   return false;
 }
Beispiel #19
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handles item selection in action bar
    if (item.getItemId() == R.id.action_save_profile) {
      /*
          Performs validation of input data
      */
      boolean isError = false;

      if (name.getText().length() == 0) {
        isError = true;
        name.setError("Name is required");
      }

      if (name.getText().toString().trim().length() > 50) {
        isError = true;
        name.setError("Name can't be longer than 50 characters");
      }

      if (textTimeMinutes.getText().equals("00") && textTimeSeconds.getText().equals("00")) {
        isError = true;
        timeError.setError("Time is required");
      }

      if (repeat.isChecked() && repeatNumber.getText().length() == 0) {
        isError = true;
        repeatNumber.setError("Number of laps is required");
      }

      /*
          Produces an error if:
          - name of profile is taken and adding a new profile
          - changed profile name is taken
      */
      if (dbHandler.profileExists(name.getText().toString().trim())) {
        if (!isEditingProfile || !name.getText().toString().trim().equals(profile.getName())) {
          isError = true;
          name.setError("Name already exists");
        }
      }

      if (!isError) {
        // Either adds or edits the profile depending on what's needed
        if (isEditingProfile) {
          setResult(PROFILE_EDITED);
          updateProfile();
        } else {
          setResult(PROFILE_ADDED);
          addProfile();
        }

        finish();
      }
    }

    return super.onOptionsItemSelected(item);
  }
 protected void checkWorldFolderNameAfterChange() {
   String newText = worldFolderNameText.getText().toString();
   if (!newText.equals(EditorActivity.worldFolder.getName())) {
     File newLoc = new File(EditorActivity.worldFolder.getParentFile(), newText);
     if (newLoc.exists()) {
       worldFolderNameText.setError(this.getResources().getText(R.string.folder_exists));
       return;
     }
     worldFolderNameText.setError(null);
     boolean success = EditorActivity.worldFolder.renameTo(newLoc);
     if (!success) {
       worldFolderNameText.setError(this.getResources().getText(R.string.folder_rename_failed));
     } else {
       Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();
       EditorActivity.worldFolder = newLoc;
     }
   }
 }
  /**
   * Kiểm tra trùng
   *
   * @param textView
   * @param editText2
   * @param errorMessage
   * @return true: nếu trùng
   */
  public static boolean isTextEquals(TextView textView, EditText editText2, String errorMessage) {
    // clear error
    textView.setError(null);
    editText2.setError(null);

    String text1 = textView.getText().toString().trim();
    String text2 = editText2.getText().toString().trim();

    if (!text1.equals(text2)) {
      // Không có text
      textView.setError(errorMessage);
      editText2.setError(errorMessage);

      return false;
    }

    return true;
  }
  private boolean validInput() {

    model.shopDetails = edtShopDetails.getText().toString().trim();
    model.locationDetails = edtLocationDetails.getText().toString().trim();
    model.items = edtItems.getText().toString().trim();
    model.cost = edtCost.getText().toString().trim();
    if (model.driverToken == null || model.driverToken.isEmpty()) {
      model.driverToken = "";
    }

    if (model.latFrom == 0 || model.lngFrom == 0) {

      Snackbar.make(
              findViewById(R.id.tab_container),
              getString(R.string.snackbar_picklocationfrom),
              Snackbar.LENGTH_SHORT)
          .show();
      tvAddressFrom.setError("");
      return false;
    }
    if (model.latTo == 0 || model.lngTo == 0) {

      Snackbar.make(
              findViewById(R.id.tab_container),
              getString(R.string.snackbar_picklocationto),
              Snackbar.LENGTH_SHORT)
          .show();
      tvAddressTo.setError("");
      return false;
    }
    if (model.items.isEmpty()) {
      edtItems.setError(getText(R.string.error_itemsempty));
      return false;
    }
    if (model.cost.isEmpty()) {
      edtCost.setError(getText(R.string.error_costempty));
      return false;
    }

    return true;
  }
  public void clear(View v) {
    eID.setText("");
    eName.setText("");
    eEmail.setText("");
    eAccess.setText("");
    eAccessconfirm.setText("");
    female.setChecked(false);
    male.setChecked(false);
    affirm.setChecked(false);

    AccessText.setError("", null);
    AccessText.setTextColor(Color.BLACK);

    AccessConfirmText.setError("", null);
    AccessConfirmText.setTextColor(Color.BLACK);

    GenderText.setError("", null);
    GenderText.setTextColor(Color.BLACK);

    EmailText.setError("", null);
    EmailText.setTextColor(Color.BLACK);

    IDtext.setError("", null);
    IDtext.setTextColor(Color.BLACK);

    NameText.setError("", null);
    NameText.setTextColor(Color.BLACK);

    departmentSpinner.setSelection(0);
  }
Beispiel #24
0
  @Override
  public void onFinishTimeSelectFragment(boolean isMinutes, int timeChosen) {
    // Removes time error if user has selected a non-zero value
    if (timeChosen != 0) {
      timeError.setError(null);
    }

    // Determines whether minutes or seconds should be updated
    if (isMinutes) {
      setTextTime(textTimeMinutes, timeChosen);
    } else {
      setTextTime(textTimeSeconds, timeChosen);
    }
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
      LatLng receivedLatLng;
      switch (requestCode) {
        case RequestCodes.PICK_DRIVER:
          model.driverName = data.getStringExtra(Extras.PICKED_DRIVER_NAME);
          model.driverToken = data.getStringExtra(Extras.PICKED_DRIVER_TOKEN);

          tvDriverName.setText(model.driverName);
          tvDriverName.setError(null);

          break;
        case RequestCodes.PICK_LOCATION_FROM:
          receivedLatLng = data.getParcelableExtra(Extras.PICKED_LATLNG);
          model.latFrom = receivedLatLng.latitude;
          model.lngFrom = receivedLatLng.longitude;
          model.addressFrom = data.getStringExtra(Extras.PICKED_ADDRESS);

          tvAddressFrom.setText(model.addressFrom);
          tvAddressFrom.setError(null);

          break;
        case RequestCodes.PICK_LOCATION_TO:
          receivedLatLng = data.getParcelableExtra(Extras.PICKED_LATLNG);
          model.latTo = receivedLatLng.latitude;
          model.lngTo = receivedLatLng.longitude;
          model.addressTo = data.getStringExtra(Extras.PICKED_ADDRESS);

          tvAddressTo.setText(model.addressTo);
          tvAddressTo.setError(null);

          break;
      }
    }
  }
Beispiel #26
0
  /**
   * Checks if all inputs are filled and shows error if not.
   *
   * @return if all inputs are filled
   */
  private boolean validateInputs() {
    homeValueInput.setError(null);
    downPaymentInput.setError(null);
    interestRateInput.setError(null);
    propertyTaxRateInput.setError(null);

    boolean error = false;
    View focusView = null;

    if (isEmpty(homeValueInput)) {
      homeValueInput.setError(getString(R.string.error_field_required));
      focusView = homeValueInput;
      error = true;
    } else if (isEmpty(downPaymentInput)) {
      downPaymentInput.setError(getString(R.string.error_field_required));
      focusView = downPaymentInput;
      error = true;
    } else if (isEmpty(interestRateInput)) {
      interestRateInput.setError(getString(R.string.error_field_required));
      focusView = interestRateInput;
      error = true;
    } else if (termsSpinner.getSelectedItemPosition() == 0) {
      TextView errorText = (TextView) termsSpinner.getSelectedView();
      errorText.setError("");
      errorText.setTextColor(Color.RED);
      errorText.setText(R.string.error_field_required);
      focusView = termsSpinner;
      error = true;
    } else if (isEmpty(propertyTaxRateInput)) {
      propertyTaxRateInput.setError(getString(R.string.error_field_required));
      focusView = propertyTaxRateInput;
      error = true;
    }

    if (error) {
      focusView.requestFocus();
    }

    return !error;
  }
  @Override
  protected boolean executeAsyncPre() {
    // TODO Auto-generated method stub
    boolean isCodigo = txtCodigo.getText().toString().trim().equalsIgnoreCase("");
    boolean isRuc = txtRuc.getText().toString().trim().equalsIgnoreCase("");
    boolean isDni = txtDni.getText().toString().trim().equalsIgnoreCase("");

    if (isCodigo && isRuc && isDni) {
      txtCodigo.setError(parametros_empty);
      txtRuc.setError(parametros_empty);
      txtDni.setError(parametros_empty);
      return false;
    } else {
      txtCodigo.setError(null);
      txtRuc.setError(null);
      txtDni.setError(null);
    }

    return true;
  }
  /** Tries to register by checking username, email, and password and whether user exists. */
  private void attemptRegister() {
    // Reset errors.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    View focusView;

    // Store values at the time of the login attempt.
    String username = mUsernameView.getText().toString();
    String email = mEmailView.getText().toString();
    String password = mPasswordView.getText().toString();

    User currentUser = new User(username, email, password);

    boolean cancel = false;
    focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
      mPasswordView.setError(getString(R.string.error_invalid_password));
      focusView = mPasswordView;
      cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
      mEmailView.setError(getString(R.string.error_field_required));
      focusView = mEmailView;
      cancel = true;
    } else if (!isEmailValid(email)) {
      mEmailView.setError(getString(R.string.error_invalid_email));
      focusView = mEmailView;
      cancel = true;
    }

    // Check for a valid username.
    if (TextUtils.isEmpty(username)) {
      mUsernameView.setError(getString(R.string.error_field_required));
      focusView = mUsernameView;
      cancel = true;
    } else if (!isUsernameValid(username)) {
      mUsernameView.setError("This username is invalid.");
      focusView = mUsernameView;
      cancel = true;
    }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a Toast to alert user that a new user profile was created (or not).
      if (isEmailValid(email) && isPasswordValid(password) && isUsernameValid(username)) {
        if (UserList.getInstance().getUsers() == null
            || !UserList.getInstance().getUsers().contains(currentUser)) {
          UserList.getInstance().addUser(currentUser);
          Context context = getApplicationContext();
          CharSequence text = "New user created.";
          int duration = Toast.LENGTH_SHORT;
          Toast toast = Toast.makeText(context, text, duration);
          toast.show();
          // wait a few seconds for the user to comprehend message
          Thread wait =
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        Thread.sleep(3000);
                      } catch (Exception e) {
                        e.getLocalizedMessage();
                      }
                    }
                  });

          // save and go back to login screen
          UserList.getInstance()
              .saveUsers(new File(RegisterActivity.this.getFilesDir(), UserList.USERS));
          Intent loginIntent = new Intent(RegisterActivity.this, LoginActivity.class);
          startActivity(loginIntent);
          finish();

        } else {
          focusView = mEmailView;
          mEmailView.setError("User already exists.");
          focusView.requestFocus();
        }

      } else {
        if (!isEmailValid(email)) {
          mEmailView.setError(getString(R.string.error_invalid_email));
          focusView = mEmailView;
        }
        if (!isPasswordValid(password)) {
          mPasswordView.setError(getString(R.string.error_invalid_password));
          focusView = mPasswordView;
        }
        if (!isUsernameValid(username)) {
          mUsernameView.setError("This username is invalid.");
          focusView = mUsernameView;
        }
        //noinspection ConstantConditions
        focusView.requestFocus();
      }
    }
  }
  // register view validate
  public void validateRegisterInfo() {

    firstNameEditView.setError(null);
    lastNameEditView.setError(null);
    emailIdEditView.setError(null);
    cityEditView.setError(null);
    zipEditView.setError(null);

    firstName = firstNameEditView.getText().toString();
    lastName = lastNameEditView.getText().toString();
    emilId = emailIdEditView.getText().toString();
    city = cityEditView.getText().toString();
    zip = zipEditView.getText().toString();
    state = stateSpinner.getSelectedItem().toString();
    try {
      specialty = specialtySpinner.getSelectedItem().toString();
    } catch (Exception e) {
      e.printStackTrace();
    }

    boolean cancel = false;
    View focusView = null;

    try {
      if (specialty.equals("Specialty")) {
        TextView specialtyTextView = (TextView) specialtySpinner.getSelectedView();
        focusView = specialtyTextView;
        specialtyTextView.setError("");
        //            specialtyTextView.setTextColor(Color.RED);
        specialtyTextView.setText("Specialty");
        cancel = true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (TextUtils.isEmpty(zip)) {
      zipEditView.setError(getString(R.string.error_field_required));
      focusView = zipEditView;
      cancel = true;
    }
    if (state.equals("State")) {
      TextView stateTextView = (TextView) stateSpinner.getSelectedView();
      focusView = stateTextView;
      stateTextView.setError("");
      //            stateTextView.setTextColor(Color.RED);
      stateTextView.setText("State");
      cancel = true;
    }
    if (TextUtils.isEmpty(city)) {
      cityEditView.setError(getString(R.string.error_field_required));
      focusView = cityEditView;
      cancel = true;
    }
    if (TextUtils.isEmpty(emilId)) {
      emailIdEditView.setError(getString(R.string.error_field_required));
      focusView = emailIdEditView;
      cancel = true;
    } else if (!isEmailValid(emilId)) {
      emailIdEditView.setError("This email address is invalid");
      focusView = emailIdEditView;
      cancel = true;
    }
    if (TextUtils.isEmpty(lastName)) {
      lastNameEditView.setError(getString(R.string.error_field_required));
      focusView = lastNameEditView;
      cancel = true;
    }
    if (TextUtils.isEmpty(firstName)) {
      firstNameEditView.setError(getString(R.string.error_field_required));
      focusView = firstNameEditView;
      cancel = true;
    }

    // cancel = false;

    if (cancel) {
      focusView.requestFocus();
    } else {
      Intent intent = new Intent(MainActivity.this, TrialActivity.class);
      finish();
      startActivity(intent);
    }
  }
  /**
   * Validates all the configuration fields. Returns false if an error is encountered and true
   * otherwise
   */
  private boolean validateFields() {
    boolean validated = true;

    // VALIDATE NAME FIELD ALREADY EXISTS
    for (DeviceConfiguration c : configurations) {
      if (c.getName().compareTo(configurationName.getText().toString()) == 0) {
        configurationName.setError(getString(R.string.nc_error_message_name_duplicate));
        configurationName.requestFocus();
        validated = false;
      }
    }

    // VALIDATE NAME FIELD IS NOT NULL
    if (configurationName.getText().toString() == null
        || configurationName.getText().toString().compareTo("") == 0) {
      configurationName.setError(getString(R.string.nc_error_message_name_null));
      configurationName.requestFocus();
      validated = false;
    }

    // VALIDATE MAC FIELD
    String macSyntax = "^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$";
    if (macAddress.getText().toString() == null
        || macAddress.getText().toString().compareTo("") == 0
        || !macAddress.getText().toString().matches(macSyntax)
            && macAddress.getText().toString().compareTo("test") != 0) {
      macAddress.setError(getString(R.string.nc_error_message_mac));
      if (validated) {
        macAddress.requestFocus();
      }
      validated = false;
    }

    // VALIDATE RECEPTION FREQUENCY
    if (receptionFreqEditor.getText().toString() == null
        || receptionFreqEditor.getText().toString().compareTo("") == 0
        || Integer.parseInt(receptionFreqEditor.getText().toString()) < RECEPTION_FREQ_MIN
        || Integer.parseInt(receptionFreqEditor.getText().toString()) > RECEPTION_FREQ_MAX) {
      receptionFreqEditor.setError("invalid frequency");
      if (validated) {
        receptionFreqEditor.requestFocus();
      }
      validated = false;
    }

    // VALIDATE SAMPLING FREQUENCY
    if (samplingFreqEditor.getText().toString() == null
        || receptionFreqEditor.getText().toString().compareTo("") == 0
        || Integer.parseInt(samplingFreqEditor.getText().toString()) < SAMPLING_FREQ_MIN
        || Integer.parseInt(samplingFreqEditor.getText().toString()) > SAMPLING_FREQ_MAX) {
      samplingFreqEditor.setError("invalid frequency");
      if (validated) {
        samplingFreqEditor.requestFocus();
      }
      validated = false;
    }

    // VALIDATE ACTIVE CHANNELS
    if (activeChannels == null || noChannelsActivated(activeChannels)) {
      activeChannelsTV.setError("");
      activeChannelsTV.setTextColor(Color.RED);
      activeChannelsTV.setVisibility(View.VISIBLE);
      activeChannelsTV.setText(getString(R.string.nc_error_message_active_channels) + "  ");
      validated = false;
    }

    // VALIDATE CHANNELS TO DISPLAY
    if (channelsSelected == null || numberOfChannelsSelected(channelsSelected) == 0) {
      displayChannelsTV.setError("");
      displayChannelsTV.setTextColor(Color.RED);
      displayChannelsTV.setVisibility(View.VISIBLE);
      displayChannelsTV.setText(getString(R.string.nc_error_message_channels_to_display) + "  ");
      validated = false;
    }
    return validated;
  }