private void initView() { type = (RadioGroup) findViewById(R.id.rg_questiontype); topic = (TextInputLayout) findViewById(R.id.questiontopic); option_a = (TextInputLayout) findViewById(R.id.option_a); option_b = (TextInputLayout) findViewById(R.id.option_b); option_c = (TextInputLayout) findViewById(R.id.option_c); option_d = (TextInputLayout) findViewById(R.id.option_d); submit = (AppCompatButton) findViewById(R.id.submit); // choice = (AppCompatRadioButton) findViewById(R.id.type_choice); // judge = (AppCompatRadioButton) findViewById(R.id.type_judgment); hint = (AppCompatTextView) findViewById(R.id.questionimage_hint); progressBar = (CircularProgressBar) findViewById(R.id.cpb); upload = (AppCompatTextView) findViewById(R.id.upload); image = (ImageButton) findViewById(R.id.questionimage); type.setOnCheckedChangeListener(this); image.setOnClickListener(this); image.setOnLongClickListener(this); submit.setOnClickListener(this); topic.getEditText().setOnFocusChangeListener(this); option_a.getEditText().setOnFocusChangeListener(this); option_b.getEditText().setOnFocusChangeListener(this); option_c.getEditText().setOnFocusChangeListener(this); option_d.getEditText().setOnFocusChangeListener(this); topic.setHint(getString(R.string.question_titlehint)); option_a.setHint(getString(R.string.result_right)); option_b.setHint(getString(R.string.result_false)); option_c.setHint(getString(R.string.result_false)); option_d.setHint(getString(R.string.result_false)); }
private long addProductShown() { // lấy giá trị Product product = (Product) mSpinner_Product.getSelectedItem(); long productId = product.get_id(); int number = Integer.valueOf(mInputLayout_Number.getEditText().getText() + ""); long retailPrice = Long.valueOf(mInputLayout_RetailPrice.getEditText().getText() + ""); // gán giá trị mProductShown = new ProductShown(); mProductShown.setAssignId(mAssignId); mProductShown.setProductId(productId); mProductShown.setNumber(number); mProductShown.setRetailPrice(retailPrice); mProductShown.setSessionCode(DatabaseUtil.getCodeGenerationByTime()); mProductShown.setCreateBy(UserPref.getUserPrefId(this)); mProductShown.setCreateAt(Calendar.getInstance()); mProductShown.setUploadStatus(UploadStatus.WAITING_UPLOAD); long id = ProductShownData.add(this, mProductShown); mProductShown.set_id(id); return id; }
private void initVars() { mDialog = new ProgressDialog(this); mProductAddNew = new Product() { { set_id(ProductAdapter.ACTION_ID_ADD); setName(getString(R.string.action_add_product)); } }; // --- Product --- spinner_Product_init(); // khởi tạo giá trị qua Intent mAssignId = getIntent().getLongExtra(EXTRA_ASSIGN_ID, -1); long mPSId = getIntent().getLongExtra(EXTRA_PRODUCT_SHOWN_ID, -1); if (mPSId == -1) { isAddNew = true; } else { // Hiển thị Cập nhật updateUIAddOrEdit(false); isAddNew = false; mProductShown = ProductShownData.getById(this, mPSId); spinner_Product_setSelection(mProductShown.getProductId()); mInputLayout_Number.getEditText().setText(mProductShown.getNumber() + ""); mInputLayout_RetailPrice.getEditText().setText(mProductShown.getRetailPrice() + ""); } }
@Override public RealmObject createDBObject() { return new Member( vorname.getEditText().getText().toString(), nachname.getEditText().getText().toString(), date.getEditText().getText().toString(), email.getEditText().getText().toString(), address.getEditText().getText().toString()); }
@Override public void setField(RealmObject object) { Member member = (Member) object; vorname.getEditText().setText(member.getFirstName()); nachname.getEditText().setText(member.getLastName()); email.getEditText().setText(member.getEmail()); address.getEditText().setText(member.getAddress()); date.getEditText().setText(member.getBirthday()); }
@Override public void onRefresh() { AnonymousAccess.setChecked(false); textInputLayoutpasswords.getEditText().setText(""); textInputLayoutusername.getEditText().setText(""); textInputLayoutport.getEditText().setText(""); textInputLayoutdir.getEditText().setText(""); clean.setRefreshing(false); }
private void getQuestion() { mQuestion.setTitle(topic.getEditText().getText().toString()); mQuestion.setAnswerOne(option_a.getEditText().getText().toString()); if (mQuestion.getQuestionType().equals("choice")) { mQuestion.setAnswerTwo(option_b.getEditText().getText().toString()); mQuestion.setAnswerThree(option_c.getEditText().getText().toString()); mQuestion.setAnswerFour(option_d.getEditText().getText().toString()); } else if (mQuestion.getAnswerOne().equals(getString(R.string.correct))) { mQuestion.setAnswerTwo(getString(R.string.wrong)); } else if (mQuestion.getAnswerOne().equals(getString(R.string.wrong))) { mQuestion.setAnswerTwo(getString(R.string.correct)); } }
private void login() { strUsername = username.getEditText().getText().toString(); strPassword = password.getEditText().getText().toString(); mProgressBar.setVisibility(View.VISIBLE); new Thread() { @Override public void run() { result = HttpUtil.sendPostRequest(URL, "username="******"&password=" + strPassword); // Log.i(TAG, result); handler.sendEmptyMessage(0x125); } }.start(); }
/** 配置TextInputLayout */ public static void configureTextInputLayout( final TextInputLayout textInputLayout, final int length, final Button button) { textInputLayout .getEditText() .addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() < length) { textInputLayout.setError("长度不能小于" + length + "个字符"); textInputLayout.setErrorEnabled(true); // 显示错误星系 button.setClickable(false); } else { textInputLayout.setErrorEnabled(false); button.setClickable(true); } } @Override public void afterTextChanged(Editable s) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text_input_layout); final TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.my_input_layout); EditText editText = textInputLayout.getEditText(); textInputLayout.setHint("Password"); editText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() > 4) { textInputLayout.setError("Password error"); textInputLayout.setErrorEnabled(true); } else { textInputLayout.setErrorEnabled(false); } } @Override public void afterTextChanged(Editable s) {} }); }
private void onSearchClicked() { String username = inputView.getEditText().getText().toString().trim(); userService .info(username) .compose(bindToLifecycle()) .lift(BusyDialogFragment.busyDialog(this)) .subscribe(this::onSearchSuccess, this::onSearchFailure); }
@Override public void onClick(View v) { mMobileNumber = mUserNameWrapper.getEditText().getText().toString(); mPassword = mPasswordWrapper.getEditText().getText().toString(); switch (v.getId()) { case R.id.sing_in: if (!validatePassword(mPassword)) { mPasswordWrapper.setError("Please Enter More than 5 char"); } else { mPasswordWrapper.setErrorEnabled(false); // Check with server for login details // if successfull save data into prefernces doLogin(); } // finish(); return; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { final Vehiculo vehiculo = (Vehiculo) getIntent().getExtras().getSerializable("vehiculo"); final String correo = (String) getIntent().getExtras().getString("email"); final User sesion = (User) getIntent().getExtras().getSerializable("sesion"); int id = item.getItemId(); if (id == R.id.I_Menu_Nuevo_Aceptar) { String nom = nombre.getEditText().getText().toString(); String ape = apellido.getEditText().getText().toString(); String ema = email.getEditText().getText().toString(); String con1 = contraseña1.getEditText().getText().toString(); String con2 = contraseña2.getEditText().getText().toString(); boolean due = dueño.isChecked(); if (nom.matches("")) { nom = nombre.getHint().toString(); } if (ema.matches("")) { ema = email.getHint().toString(); } if (ape.matches("")) { ape = apellido.getHint().toString(); } // validar los campos String errorEmail = validarEmail(ema); String errorNombre = validarNombre(nom); String errorApellido = validarApellido(ape); String errorContraseña2 = validarContraseña2(con1, con2); // mostrar errores email.setError(errorEmail); nombre.setError(errorNombre); apellido.setError(errorApellido); contraseña2.setError(errorContraseña2); // entrar si no hay errores if (errorEmail.matches("") && errorNombre.matches("") && errorApellido.matches("") && errorContraseña2.matches("")) { visibilityLoadOn(); registrar(sesion, vehiculo, ema, nom, ape, con1, due); } return true; } return super.onOptionsItemSelected(item); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (1 == requestCode) { Bundle bundle = null; if (data != null && (bundle = data.getExtras()) != null) { textInputLayoutdir.getEditText().setText(bundle.getString("file") + "/"); } } }
private void cargarAlumno() { tilFoto.getEditText().setText(alumno.getFoto()); tilCurso.getEditText().setText(alumno.getCurso()); tilRepetidor.getEditText().setText(String.valueOf(alumno.getRepetidor())); tilTelefono.getEditText().setText(alumno.getTelefono()); tilDireccion.getEditText().setText(alumno.getDireccion()); tilEdad.getEditText().setText(String.valueOf(alumno.getEdad())); tilNombre.getEditText().setText(alumno.getNombre()); }
private boolean validateEmail() { String EMAIL_PATTERN = "^[a-zA-Z0-9#_~!$&'()*+,;=:.\"(),:;<>@\\[\\]\\\\]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*$"; Pattern pattern = Pattern.compile(EMAIL_PATTERN); Matcher matcher = null; if (!validateEmailasd(pattern, matcher, email.getEditText().toString())) { email.setError("Not a valid email address!"); return true; } return true; }
/** * Kiểm tra trùng * * @param inputLayout1 * @param inputLayout2 * @param errorMessage * @return true: nếu trùng */ public static boolean isTextEquals( TextInputLayout inputLayout1, TextInputLayout inputLayout2, String errorMessage) { // clear error inputLayout1.setError(null); inputLayout2.setError(null); inputLayout1.setErrorEnabled(false); inputLayout2.setErrorEnabled(false); if (!isTextEquals(inputLayout1.getEditText(), inputLayout2.getEditText(), errorMessage)) { // Không có text inputLayout1.setErrorEnabled(true); inputLayout2.setErrorEnabled(true); inputLayout1.setError(errorMessage); inputLayout2.setError(errorMessage); return false; } return true; }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.type_choice: option_b.setVisibility(View.VISIBLE); option_c.setVisibility(View.VISIBLE); option_d.setVisibility(View.VISIBLE); mQuestion.setQuestionType("choice"); break; case R.id.type_judgment: option_b.setVisibility(View.GONE); option_c.setVisibility(View.GONE); option_d.setVisibility(View.GONE); option_b.getEditText().setText(""); option_c.getEditText().setText(""); option_d.getEditText().setText(""); mQuestion.setQuestionType("judge"); break; } topic.getEditText().requestFocus(); }
public void FbaWriteSharedPreferences() { SharedPreferencesUtils.putString( this, "username", textInputLayoutusername.getEditText().getText().toString()); SharedPreferencesUtils.putString( this, "password", textInputLayoutpasswords.getEditText().getText().toString()); SharedPreferencesUtils.putString( this, "portNum", textInputLayoutport.getEditText().getText().toString()); SharedPreferencesUtils.putString( this, "chrootDir", textInputLayoutdir.getEditText().getText().toString()); SharedPreferencesUtils.putBoolean(this, "allow_anonymous", AnonymousAccess.isChecked()); Snackbar.make(coordinatorLayout, "保存成功", Snackbar.LENGTH_LONG) .setAction( "关闭页面", new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }) .show(); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.reset: DialogUtils.showAlertTwo( this, "重置", getString(R.string.reset_tips), "确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (SharedPreferencesUtils.clear(Settings.this)) { AnonymousAccess.setChecked(false); Snackbar.make(coordinatorLayout, "重置成功", Snackbar.LENGTH_SHORT).show(); } } }, "取消", null); break; case R.id.fab: if ((textInputLayoutdir.getEditText().getText().length() != 0) && (textInputLayoutpasswords.getEditText().getText().length() != 0) && (textInputLayoutusername.getEditText().getText().length() != 0) && (textInputLayoutport.getEditText().getText().length() == 4)) { FbaWriteSharedPreferences(); } else { Snackbar.make(coordinatorLayout, "输入内容不合法!", Snackbar.LENGTH_SHORT).show(); } break; case R.id.readconfig: ReadSharedPreferences(); break; case R.id.selectdir: Intent intent = new Intent(Settings.this, FileDirectorySelected.class); startActivityForResult(intent, 1); break; } }
private boolean checkParams() { boolean result = false; if (null != mQuestion.getTitle() && TOPIC_LENGTH_MIN <= mQuestion.getTitle().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getTitle().trim().length()) { if (null != mQuestion.getAnswerOne() && OPTION_LENGTH_MIN <= mQuestion.getAnswerOne().trim().length() && OPTION_LENGTH_MAX >= mQuestion.getAnswerOne().trim().length()) { if (mQuestion.getQuestionType().equals("judge")) { if (mQuestion.getAnswerOne().equals(getString(R.string.wrong)) || mQuestion.getAnswerOne().equals(getString(R.string.correct))) { return true; } else { option_a.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_a); return false; } } else { if (null != mQuestion.getAnswerTwo() && OPTION_LENGTH_MIN <= mQuestion.getAnswerTwo().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getAnswerTwo().trim().length()) { if (null != mQuestion.getAnswerThree() && OPTION_LENGTH_MIN <= mQuestion.getAnswerThree().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getAnswerThree().trim().length()) { if (null != mQuestion.getAnswerFour() && OPTION_LENGTH_MIN <= mQuestion.getAnswerFour().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getAnswerFour().trim().length()) { result = true; } else { // D option_d.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_d); } } else { // C option_c.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_c); } } else { // B option_b.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_b); } } } else { // 答案A长度不正确 option_a.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_a); } } else { // 标题长度不正确 topic.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(topic); } return result; }
/** kiểm tra có Text, tự set lỗi True: nếu có Text */ public static boolean hasText(TextInputLayout inputLayout, String errorMessage) { // clear error inputLayout.setError(""); inputLayout.setErrorEnabled(false); if (!hasText(inputLayout.getEditText(), errorMessage)) { // Không có text => lỗi inputLayout.setErrorEnabled(true); inputLayout.setError(errorMessage); return false; } return true; }
/** * Kiểu tra Regex, tự set lỗi * * @param inputLayout * @param regex * @param errorMessage * @return true: trùng regex */ public static boolean isRegexValid( TextInputLayout inputLayout, String regex, String errorMessage) { // clear error inputLayout.setError(null); inputLayout.setErrorEnabled(false); if (!isRegexValid(inputLayout.getEditText(), regex, errorMessage)) { // KHông trùng Pattern => lỗi inputLayout.setErrorEnabled(true); inputLayout.setError(errorMessage); return false; } return true; }
private boolean validateInputs() { boolean isValidInput = false; String strLastName = mLayoutMessage.getEditText().getText().toString(); if (!TextUtils.isEmpty(strLastName)) { mLayoutMessage.setErrorEnabled(false); isValidInput = true; } else { mLayoutMessage.setError("Input required"); mLayoutMessage.setErrorEnabled(true); isValidInput = false; } return isValidInput; }
@Override public void onClick(View v) { boolean isCorrect = true; pedido = new Pedido(); tilDireccionP.setErrorEnabled(false); tilReferenciaP.setErrorEnabled(false); tilTelefonoP.setErrorEnabled(false); if (tilDireccionP.getEditText().getText().toString().trim().length() <= 0) { tilDireccionP.setError("Ingrese una dirección"); tilDireccionP.setErrorEnabled(true); isCorrect = false; } else pedido.setDireccion(tilDireccionP.getEditText().getText().toString().trim()); if (tilReferenciaP.getEditText().getText().toString().trim().length() <= 0) { tilReferenciaP.setError("Ingrese una referencia"); tilReferenciaP.setErrorEnabled(true); isCorrect = false; } else pedido.setReferencia(tilReferenciaP.getEditText().getText().toString().trim()); if (tilTelefonoP.getEditText().getText().toString().trim().length() <= 0) { tilTelefonoP.setError("Ingrese un teléfono"); tilTelefonoP.setErrorEnabled(true); isCorrect = false; } else pedido.setTelefono(tilTelefonoP.getEditText().getText().toString().trim()); if (isCorrect) { tilDireccionP.getEditText().setText(""); tilDireccionP.getEditText().setHint("Direccion"); tilReferenciaP.getEditText().setText(""); tilReferenciaP.getEditText().setHint("Referencia"); tilTelefonoP.getEditText().setText(""); tilTelefonoP.getEditText().setHint("Teléfono"); new ProgressAsyncTask().execute(); } }
private void updateErrorText() { mErrorText.clear(); mErrorText.clearSpans(); final int length = mTextInputLayout.getEditText().length(); if (length > 0) { mErrorText.append(String.valueOf(length)); mErrorText.append(" / "); mErrorText.append(String.valueOf(mMaxLen)); mErrorText.setSpan( mAlignmentSpan, 0, mErrorText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); if (hasValidLength()) { mErrorText.setSpan( mNormalTextAppearance, 0, mErrorText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } } mTextInputLayout.setError(mErrorText); }
@Override protected View onCreateDialogView() { View dialogLayout = View.inflate(mContext, R.layout.dialog_sql_pref, null); // анимация поворота стрелки final Animation rotationAnim = AnimationUtils.loadAnimation(mContext, R.anim.rotate); rotationAnim.setRepeatCount(Animation.INFINITE); mInputServerName = (TextInputLayout) dialogLayout.findViewById(R.id.preference_item_sql_input_server); mServerName = mInputServerName.getEditText(); mCheckServerConnect = (ImageView) dialogLayout.findViewById(R.id.preference_item_sql_check_connect); mServerStatus = (ImageView) dialogLayout.findViewById(R.id.preference_item_sql_status); mServerName.setText(SharedPrefs.getServerName()); mCheckServerConnect.startAnimation(rotationAnim); connect(mServerName.getText().toString(), mCallback); mCheckServerConnect.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mInputServerName.getEditText().getText().length() == 0) { mInputServerName.setErrorEnabled(true); mInputServerName.setError( App.getAppContext().getString(R.string.input_sql_server_name_error)); } else { mCheckServerConnect.startAnimation(rotationAnim); connect(mServerName.getText().toString(), mCallback); } } }); // если android по 4.4 включительно, то включаем программное ускорение // иначе анимация не работает if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { mCheckServerConnect.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } return dialogLayout; }
@Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.dialog_playlist, container); mListView = (ListView) view.findViewById(android.R.id.list); mSaveButton = (Button) view.findViewById(R.id.dialog_playlist_save); mEmptyView = (TextView) view.findViewById(android.R.id.empty); TextInputLayout mLayout = (TextInputLayout) view.findViewById(R.id.dialog_playlist_name); mLayout.setHint(getString(R.string.playlist_name_hint)); mEditText = mLayout.getEditText(); mListView.setOnItemClickListener(this); mSaveButton.setOnClickListener(this); mEditText.setOnEditorActionListener(this); mListView.setEmptyView(mEmptyView); mListView.setAdapter(mAdapter); return view; }
public void ReadSharedPreferences() { textInputLayoutpasswords .getEditText() .setText(SharedPreferencesUtils.getString(Settings.this, "password", "admin")); textInputLayoutusername .getEditText() .setText(SharedPreferencesUtils.getString(Settings.this, "username", "admin")); textInputLayoutport .getEditText() .setText(SharedPreferencesUtils.getString(Settings.this, "portNum", "2121")); textInputLayoutdir .getEditText() .setText(SharedPreferencesUtils.getString(Settings.this, "chrootDir", "/")); AnonymousAccess.setChecked( SharedPreferencesUtils.getBoolean(Settings.this, "allow_anonymous", false)); if (AnonymousAccess.isChecked()) { textInputLayoutpasswords.getEditText().setEnabled(false); textInputLayoutusername.getEditText().setEnabled(false); } else { textInputLayoutpasswords.getEditText().setEnabled(true); textInputLayoutusername.getEditText().setEnabled(true); } }
public void onEvent(DatePickerEvent event) { ((Member) getSelectedItem()).setBirthday(event.getDate()); date.getEditText().setText(event.getDate()); }