List of usage examples for android.text Editable length
int length();
From source file:com.learnit.LearnIt.activities.EditWord.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); removeActionBarLabelIfNeeded();/*www .ja va 2 s. c om*/ dbHelper = FactoryDbHelper.createDbHelper(this, DBHelper.DB_WORDS); utils = new Utils(); oldWord = getIntent().getStringExtra(WORD_TAG); String translation = dbHelper.getTranslation(oldWord); Log.d(LOG_TAG, "got word to edit = " + oldWord + ", trans = " + translation); setContentView(R.layout.edit_word); edtWord = (EditText) findViewById(R.id.edtWord); edtTrans = (EditText) findViewById(R.id.edtTrans); edtWord.setText(oldWord); edtTrans.setText(translation); btnClearWord = (ImageButton) findViewById(R.id.btn_add_word_clear); btnClearTrans = (ImageButton) findViewById(R.id.btn_add_trans_clear); MyBtnTouchListener myBtnTouchListener = new MyBtnTouchListener(); btnClearTrans.setOnClickListener(myBtnTouchListener); btnClearWord.setOnClickListener(myBtnTouchListener); edtWord.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { if (editable.toString() != null && !editable.toString().equals("")) { btnClearWord.setVisibility(View.VISIBLE); } if (editable.length() == 0) { btnClearWord.setVisibility(View.INVISIBLE); } } }); edtTrans.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { if (editable.toString() != null && !editable.toString().equals("")) { btnClearTrans.setVisibility(View.VISIBLE); } if (editable.length() == 0) { btnClearTrans.setVisibility(View.INVISIBLE); } } }); }
From source file:com.newtifry.android.SourceList.java
/** * Helper function to show a dialog to ask for a source name. *//*from w w w. ja va2s . c om*/ private void askForSourceName() { final EditText input = new EditText(this); new AlertDialog.Builder(this).setTitle(getString(R.string.create_source)) .setMessage(getString(R.string.create_source_message)).setView(input) .setPositiveButton(getString(R.string.create), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); if (value.length() > 0) { // Fire it off to the create source function. createSource(value.toString()); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // No need to take any action. } }).show(); }
From source file:org.miaowo.miaowo.util.Html.java
private static void startFont(Editable text, Attributes attributes) { String color = attributes.getValue("", "color"); String face = attributes.getValue("", "face"); int len = text.length(); text.setSpan(new Font(color, face), len, len, Spannable.SPAN_MARK_MARK); }
From source file:com.notifry.android.SourceList.java
/** * Helper function to show a dialog to ask for a source name. *//*from w w w. j ava 2 s . c om*/ private void askForSourceName() { final EditText input = new EditText(this); new AlertDialog.Builder(this).setTitle(getString(R.string.create_source)) .setMessage(getString(R.string.create_source_message)).setView(input) .setPositiveButton(getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); if (value.length() > 0) { // Fire it off to the create source // function. createSource(value.toString()); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { // No need to take any action. } }).show(); }
From source file:org.miaowo.miaowo.util.Html.java
private static void startCssStyle(Editable text, Attributes attributes) { String style = attributes.getValue("", "style"); if (style != null) { final int len = text.length(); Matcher m = getForegroundColorPattern().matcher(style); if (m.find()) { int c = Color.parseColor(m.group(1)); if (c != -1) { text.setSpan(new Foreground(c | 0xFF000000), len, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }//from w w w . ja v a2 s . co m } m = getBackgroundColorPattern().matcher(style); if (m.find()) { int c = Color.parseColor(m.group(1)); if (c != -1) { text.setSpan(new Background(c | 0xFF000000), len, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } } m = getTextDecorationPattern().matcher(style); if (m.find()) { String textDecoration = m.group(1); if (textDecoration.equalsIgnoreCase("line-through")) { text.setSpan(new Strikethrough(), len, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } } } }
From source file:org.adaway.ui.HostsSourcesFragment.java
/** * Add Entry Menu Action//from w w w. ja v a2s . co m */ 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_url_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url); // set EditText inputEditText.setText(getString(R.string.hosts_add_dialog_input)); inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.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 input = inputEditText.getText().toString(); addEntry(input); } }); 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:sssemil.com.hostsaway.ui.BlacklistFragment.java
/** * Edit entry based on selection in context menu * * @param info/*from w w w. jav a 2 s . c o m*/ */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidHostname(input)) { ProviderHelper.updateBlacklistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); 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:sssemil.com.hostsaway.ui.WhitelistFragment.java
/** * Edit entry based on selection in context menu * * @param info//from w ww. ja v a 2s . co m */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidWhitelistHostname(input)) { ProviderHelper.updateWhitelistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); 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:de.stadtrallye.rallyesoft.fragments.ChatroomFragment.java
@Override public void onClick(View v) { Editable msg = text.getText(); IPictureManager.IPicture pic = pictureHandler.getPicture(); if (pic != null || msg.length() > 0) { chatroom.postChat(msg.toString(), pic); pictureHandler.discardPicture();//TODO wait for postState result... }// w w w .j a v a 2s . c o m }
From source file:org.adaway.ui.BlacklistFragment.java
/** * Edit entry based on selection in context menu * /*from w w w .ja va 2 s . co m*/ * @param info */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidHostname(input)) { ProviderHelper.updateBlacklistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(org.adaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); 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(); }