List of usage examples for android.text Editable length
int length();
From source file:com.dirkgassen.wator.ui.fragment.NewWorld.java
/** * Validate the "initial fish count" {@link EditText}. The text is already provided as a parameter. * * If the text is valid the "initial shark count" {@link EditText} is validated as well to eventually remove an * error that previously existed (e.g., number of initial fish was reduced so that the number of shark are now valid). * * Note that the "initial shark count" {@link EditText} is not validated if the text is invalid to not add * an error message to the "initial shark count" {@link EditText} if this text value is invalid. * * @param s text of the "initial fish count" {@link EditText} * @param worldSize size of the world//from w w w.j a v a 2 s . co m */ private void validateInitialSharkCount(Editable s, int worldSize) { if (s.length() == 0) { inputs[INITIAL_SHARK_COUNT_INPUT].setError(getString(R.string.initial_shark_count_empty_error)); } else { Editable fishCountEditable = inputs[INITIAL_FISH_COUNT_INPUT].getText(); int initialSharkValue = Integer.valueOf(s.toString()); int initialFishValue = fishCountEditable.length() == 0 ? 0 : Integer.valueOf(fishCountEditable.toString()); int max = worldSize - initialFishValue; if (max < 0) { max = 0; } if (initialSharkValue > max) { inputs[INITIAL_SHARK_COUNT_INPUT].setError(getString(R.string.too_many_shark_error, max)); } else { inputs[INITIAL_SHARK_COUNT_INPUT].setError(null); if (fishCountEditable.length() > 0 && initialFishValue < worldSize - initialSharkValue) { inputs[INITIAL_FISH_COUNT_INPUT].setError(null); } } } }
From source file:com.todoroo.astrid.actfm.TagUpdatesFragment.java
protected void setUpUpdateList() { if (getActivity() instanceof TagUpdatesActivity) { ActionBar ab = ((AstridActivity) getActivity()).getSupportActionBar(); String title = (tagData == null) ? getString(R.string.TLA_all_activity) : getString(R.string.tag_updates_title, tagData.getValue(TagData.NAME)); ((TextView) ab.getCustomView().findViewById(R.id.title)).setText(title); }// w ww .ja v a 2 s .c om final ImageButton commentButton = (ImageButton) getView().findViewById(R.id.commentButton); addCommentField = (EditText) getView().findViewById(R.id.commentField); addCommentField.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && addCommentField.getText().length() > 0) { addComment(); return true; } return false; } }); addCommentField.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { commentButton.setVisibility((s.length() > 0) ? View.VISIBLE : View.GONE); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // } }); commentButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addComment(); } }); final ClearImageCallback clearImage = new ClearImageCallback() { @Override public void clearImage() { picture = null; resetPictureButton(); } }; pictureButton = (ImageButton) getView().findViewById(R.id.picture); pictureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (picture != null) ActFmCameraModule.showPictureLauncher(TagUpdatesFragment.this, clearImage); else ActFmCameraModule.showPictureLauncher(TagUpdatesFragment.this, null); } }); refreshUpdatesList(); refreshActivity(false); // start a pull in the background }
From source file:org.adaway.ui.RedirectionListFragment.java
/** * Add Entry Menu Action/* www . j av a 2s .c om*/ */ public void menuAddEntry() { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_add_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null); final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip); // move cursor to end of EditText Editable hostnameEditContent = hostnameEditText.getText(); hostnameEditText.setSelection(hostnameEditContent.length()); // move cursor to end of EditText Editable ipEditContent = ipEditText.getText(); ipEditText.setSelection(ipEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_add), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String hostname = hostnameEditText.getText().toString(); String ip = ipEditText.getText().toString(); addEntry(hostname, ip); } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.xperia64.timidityae.TrackFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { reset();//from w w w. j av a 2s .c om fileList = new ArrayAdapter<String>(getActivity(), R.layout.row); for (int i = 0; i < JNIHandler.MAX_CHANNELS; i++) { fileList.add(String.format(getActivity().getResources().getString(R.string.trk_form), (getActivity().getResources() .getString(JNIHandler.drums.get(i) ? R.string.trk_drum : R.string.trk_inst2)), (i + 1), JNIHandler.drums.get(i) ? 0 : localInst.get(i) + 1, localVol.get(i))); } channelList.setAdapter(fileList); channelList.setOnItemClickListener(new OnItemClickListener() { @SuppressLint("InflateParams") @Override public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); View v = getActivity().getLayoutInflater().inflate(R.layout.track_dialog, null); final Spinner instSpin = (Spinner) v.findViewById(R.id.instSpin); instSpin.setClickable(JNIHandler.custInst.get(arg2) && !JNIHandler.drums.get(arg2)); instSpin.setOnLongClickListener(null); instSpin.setEnabled(JNIHandler.custInst.get(arg2) && !JNIHandler.drums.get(arg2)); List<String> arrayAdapter = new ArrayList<String>(); final int offset = (!JNIHandler.drums.get(arg2)) ? 0 : 34; if (!JNIHandler.drums.get(arg2)) { for (String inst : getActivity().getResources().getStringArray(R.array.midi_instruments)) arrayAdapter.add(inst); } else { for (String inst : getActivity().getResources().getStringArray(R.array.midi_drums)) arrayAdapter.add(inst); } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arrayAdapter); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); } else { dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); } dataAdapter.setNotifyOnChange(false); if (!JNIHandler.drums.get(arg2)) { instSpin.setAdapter(dataAdapter); instSpin.setSelection(localInst.get(arg2) - offset); } final EditText txtVol = (EditText) v.findViewById(R.id.txtVol); txtVol.setText(Integer.toString(localVol.get(arg2))); txtVol.setClickable(JNIHandler.custVol.get(arg2)); txtVol.setEnabled(JNIHandler.custVol.get(arg2)); final SeekBar volSeek = (SeekBar) v.findViewById(R.id.volSeek); volSeek.setClickable(JNIHandler.custVol.get(arg2)); volSeek.setEnabled(JNIHandler.custVol.get(arg2)); volSeek.setMax(127); volSeek.setProgress(localVol.get(arg2)); volSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { if (arg2 && !fromUser) { fromUser = true; txtVol.setText(Integer.toString(arg0.getProgress())); } else { fromUser = false; } } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onStopTrackingTouch(SeekBar arg0) { } }); txtVol.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { if (!fromUser) { if (s.length() > 0) { int numm = Integer.parseInt(s.toString()); if (numm > 127) { fromUser = true; numm = 127; } if (numm < 0) { fromUser = true; numm = 0; } if (fromUser) { txtVol.setText(Integer.toString(numm)); } fromUser = true; volSeek.setProgress(numm); fromUser = false; } } else { fromUser = false; } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final CheckBox inst = (CheckBox) v.findViewById(R.id.defInstr); inst.setEnabled(!JNIHandler.drums.get(arg2)); inst.setChecked(!JNIHandler.custInst.get(arg2)); inst.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { instSpin.setClickable(!arg1); instSpin.setEnabled(!arg1); } }); final CheckBox vol = (CheckBox) v.findViewById(R.id.defVol); vol.setChecked(!JNIHandler.custVol.get(arg2)); //System.out.println("Def inst: "+(!JNIHandler.custInst.get(arg2)?"true":"false")+" def vol: "+(!JNIHandler.custVol.get(arg2)?"true":"false")); vol.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { volSeek.setClickable(!arg1); volSeek.setEnabled(!arg1); txtVol.setClickable(!arg1); txtVol.setEnabled(!arg1); } }); if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) v.setBackgroundColor(Globals.theme == 1 ? Color.WHITE : Color.BLACK); b.setView(v); b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JNIHandler.custInst.set(arg2, !inst.isChecked()); JNIHandler.custVol.set(arg2, !vol.isChecked()); JNIHandler.setChannelVolumeTimidity(arg2 | (JNIHandler.custVol.get(arg2) ? 0x800 : 0x8000), volSeek.getProgress()); JNIHandler.setChannelTimidity(arg2 | (JNIHandler.custInst.get(arg2) ? 0x800 : 0x8000), instSpin.getSelectedItemPosition()); if (!JNIHandler.paused && Globals.isPlaying == 0) JNIHandler.seekTo(JNIHandler.currTime); //bigCounter=12; updateList(); } }); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); b.setTitle(String.format((getActivity().getResources().getString(R.string.trk_form2)), (arg2 + 1))); ddd = b.create(); ddd.show(); } }); }
From source file:io.romain.passport.ui.AddCityActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_city); FabDialogMorphSetup.setupSharedElementTransitions(this, mRoot, getResources().getDimensionPixelSize(R.dimen.dialog_corners)); Dog.d("Main thread is : " + Looper.getMainLooper().getThread().getName()); final CitySearchAdapter adapter = new CitySearchAdapter(this); mEditText.setAdapter(adapter);/*from ww w .j a v a 2 s . c o m*/ mEditText.setOnItemClickListener((parent, view, position, id) -> { showLoadingSpinner(); CityAutocomplete autocomplete = (CityAutocomplete) mEditText.getAdapter().getItem(position); unsubscribe(); mEditText.setText(autocomplete.name()); mSubscription = mRetrofit.create(City.CityService.class).resolve(autocomplete.id()) .subscribeOn(Schedulers.io()).map(city -> CitySaverObservable.save(this, city)) .observeOn(AndroidSchedulers.mainThread()).subscribe(city -> { dismiss(Activity.RESULT_OK, city); }, throwable -> { Dog.e(throwable, "An error occurred :'("); hideLoadingSpinner(); }); }); mEditText.setDrawableListener((text, touched) -> { switch (touched) { case LocationAutocompleteTextView.DRAWABLE_RIGHT: getUserLocation(); return true; } return false; }); mEditText.setThreshold(2); mEditText.addTextChangedListener(new SimpleTextWatcher() { @Override public void afterTextChanged(Editable s) { mValidateButton.setEnabled(s.length() > 0); } }); String initial = getIntent().getStringExtra(EXTRA_INITIAL_TEXT); if (!TextUtils.isEmpty(initial)) { mEditText.setText(initial); } }
From source file:com.granita.tasks.QuickAddDialogFragment.java
@Override public void afterTextChanged(Editable s) { // disable buttons if there is no title boolean enabled = s == null || s.length() != 0; mSaveButton.setEnabled(enabled);/*from w w w.j a v a 2s .c o m*/ mSaveAndNextButton.setEnabled(enabled); }
From source file:de.dmxcontrol.fragment.PanelSelectorFragment.java
private void removeLastCharFromActive() { Editable et; if (mActiveInputType == ACTIVE_INPUT_TYPE_DEVICE) { et = mEditDevice.getEditableText(); } else {/*from www .j av a 2 s. co m*/ et = mEditGroup.getEditableText(); } if (et.length() > 0) { Log.d(TAG, "deleting from " + (et.length() - 1) + " - " + et.length()); et.delete(et.length() - 1, et.length()); } mIsEditing = true; updateEntitySelection(et); mIsEditing = false; }
From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.AppsViewFragment.java
@Override public void afterTextChanged(Editable s) { if (s.length() == 0) { mSendTextButton.setVisibility(View.GONE); mSendObjectButton.setVisibility(View.VISIBLE); } else {/* w w w . j a va 2 s. co m*/ mSendTextButton.setVisibility(View.VISIBLE); mSendObjectButton.setVisibility(View.GONE); } }
From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_driver_license); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); ProgDialog = new Prog_Dialog(this); setSupportActionBar(toolbar);// w w w . j a v a 2s . com getSupportActionBar().setDisplayHomeAsUpEnabled(true); preview = (ImageView) findViewById(R.id.imgLicence); Button b = (Button) findViewById(R.id.BtnDriverBrowse); staticSpinner = (Spinner) findViewById(R.id.txtLicenseIssue); txtLicenseNumber = (EditText) findViewById(R.id.txtLicenseNumber); txtLicenseExpire = (EditText) findViewById(R.id.txtLicenseExpire); userHierarchy = new ArrayList<>(); if (AppConstant.isNetworkAvailable(this)) { try { state_spiner(); } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else { AppConstant.showNetworkError(this); } staticSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { //CountryPosition = (userHierarchy.get(position).toString()); countryPosition = userHierarchy.get(position).getStateId(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); 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();*/ if (CheckValidation()) { LicenseIssuedStateId = countryPosition; LicenseNumber = txtLicenseNumber.getText().toString(); LicenseExpiryDate = txtLicenseExpire.getText().toString(); LicenseImageBase64String = imagedata; Intent intent = new Intent(getApplicationContext(), TruckActivity.class); startActivity(intent); } } }); txtLicenseExpire.addTextChangedListener(new TextWatcher() { int prevL = 0; @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { prevL = txtLicenseExpire.getText().toString().length(); } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { int length = editable.length(); if ((prevL < length) && (length == 2 || length == 5)) { editable.append("/"); } } }); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Image_Picker_Dialog(); } }); }
From source file:com.hamzahrmalik.calculator2.Calculator.java
private void onDelete() { // Delete works like backspace; remove the last character from the // expression. final Editable formulaText = mFormulaEditText.getEditableText(); final int formulaLength = formulaText.length(); if (formulaLength > 0) { formulaText.delete(formulaLength - 1, formulaLength); }/* w w w . j a v a 2 s.co m*/ }