use of android.text.TextWatcher in project Jota-Text-Editor-old by jiro-aqua.
the class TextView method sendAfterTextChanged.
/**
* Not private so it can be called from an inner class without going
* through a thunk.
*/
void sendAfterTextChanged(Editable text) {
if (mListeners != null) {
final ArrayList<TextWatcher> list = mListeners;
final int count = list.size();
for (int i = 0; i < count; i++) {
list.get(i).afterTextChanged(text);
}
}
}
use of android.text.TextWatcher in project ToolBarLib by jjhesk.
the class MaterialSearchView method initSearchView.
protected void initSearchView() {
mSearchSrcTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
onSubmitQuery();
return true;
}
});
mSearchSrcTextView.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) {
mUserQuery = s;
startFilter(s);
MaterialSearchView.this.onTextChanged(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
showKeyboard(mSearchSrcTextView);
showSuggestions();
}
}
});
}
use of android.text.TextWatcher in project Android-CollapsibleSearchMenu by johnkil.
the class CollapsibleMenuUtils method addSearchMenuItem.
/**
* Adding collapsible search menu item to the menu.
*
* @param menu
* @param isLightTheme - true if use light them for ActionBar, else false
* @return menu item
*/
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final OnQueryTextListener onQueryChangeListener) {
final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
final View searchView = menuItem.getActionView();
final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
final TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
onQueryChangeListener.onQueryTextChange(charSequence.toString());
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
}
};
final TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
onQueryChangeListener.onQueryTextSubmit(textView.getText().toString());
return true;
}
return false;
}
};
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
editText.addTextChangedListener(textWatcher);
editText.setOnEditorActionListener(onEditorActionListener);
editText.requestFocus();
showKeyboard(editText);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
editText.setText(null);
editText.removeTextChangedListener(textWatcher);
// editText.clearFocus();
hideKeyboard(editText);
return true;
}
});
final View searchPlate = searchView.findViewById(R.id.search_plate);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
searchView.post(new Runnable() {
public void run() {
searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
searchView.invalidate();
}
});
}
});
final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
closeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!TextUtils.isEmpty(editText.getText())) {
editText.setText(null);
} else {
menuItem.collapseActionView();
}
}
});
return menuItem;
}
use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.
the class Compose method setUpSimilar.
public void setUpSimilar() {
attachImage[0] = (ImageView) findViewById(R.id.picture1);
attachImage[1] = (ImageView) findViewById(R.id.picture2);
attachImage[2] = (ImageView) findViewById(R.id.picture3);
attachImage[3] = (ImageView) findViewById(R.id.picture4);
attachButton = (ImageButton) findViewById(R.id.attach);
gifButton = (ImageButton) findViewById(R.id.gif);
emojiButton = (ImageButton) findViewById(R.id.emoji);
emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
reply = (EditText) findViewById(R.id.tweet_content);
charRemaining = (TextView) findViewById(R.id.char_remaining);
findViewById(R.id.prompt_pos).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.v("talon_input", "clicked the view");
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(reply, InputMethodManager.SHOW_FORCED);
}
});
NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);
if (settings.roundContactImages) {
pic.loadImage(settings.myProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
} else {
pic.loadImage(settings.myProfilePicUrl, false, null);
}
currentName.setText("@" + settings.myScreenName);
//numberAttached.setText("0 " + getString(R.string.attached_images));
charRemaining.setText(140 - reply.getText().length() + "");
reply.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) {
countHandler.removeCallbacks(getCount);
countHandler.postDelayed(getCount, 300);
}
});
}
use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.
the class ComposeActivity method setUpLayout.
public void setUpLayout() {
setContentView(R.layout.compose_activity);
setUpSimilar();
// number of accounts logged in
int count = 0;
if (sharedPrefs.getBoolean("is_logged_in_1", false)) {
count++;
}
if (sharedPrefs.getBoolean("is_logged_in_2", false)) {
count++;
}
if (count == 2) {
findViewById(R.id.accounts).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] options = new String[3];
options[0] = "@" + settings.myScreenName;
options[1] = "@" + settings.secondScreenName;
options[2] = getString(R.string.both_accounts);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setItems(options, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int item) {
NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);
switch(item) {
case 0:
useAccOne = true;
useAccTwo = false;
if (settings.roundContactImages) {
pic.loadImage(settings.myProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
} else {
pic.loadImage(settings.myProfilePicUrl, false, null);
}
currentName.setText("@" + settings.myScreenName);
break;
case 1:
useAccOne = false;
useAccTwo = true;
if (settings.roundContactImages) {
pic.loadImage(settings.secondProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
} else {
pic.loadImage(settings.secondProfilePicUrl, false, null);
}
currentName.setText("@" + settings.secondScreenName);
break;
case 2:
useAccOne = true;
useAccTwo = true;
TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.favUser });
int resource = a.getResourceId(0, 0);
a.recycle();
pic.setImageResource(resource);
currentName.setText(getString(R.string.both_accounts));
break;
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
UserAutoCompleteHelper.applyTo(this, reply);
hashtagAutoComplete = new ListPopupWindow(context);
hashtagAutoComplete.setAnchorView(reply);
hashtagAutoComplete.setHeight(toDP(200));
hashtagAutoComplete.setWidth((int) (width * .75));
hashtagAutoComplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(reply.getText().toString()), reply));
hashtagAutoComplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
hashtagAutoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
hashtagAutoComplete.dismiss();
}
});
// watcher for the @
reply.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) {
String searchText = reply.getText().toString();
try {
int position = reply.getSelectionStart() - 1;
if (searchText.charAt(position) == '#') {
hashtagAutoComplete.show();
} else if (searchText.charAt(position) == ' ') {
hashtagAutoComplete.dismiss();
} else if (hashtagAutoComplete.isShowing()) {
String adapterText = "";
do {
adapterText = searchText.charAt(position--) + adapterText;
} while (searchText.charAt(position) != '#');
adapterText = adapterText.replace("#", "");
hashtagAutoComplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(adapterText), reply));
}
} catch (Exception e) {
// there is no text
try {
hashtagAutoComplete.dismiss();
} catch (Exception x) {
// something went really wrong I guess haha
}
}
}
});
overflow = (ImageButton) findViewById(R.id.overflow_button);
overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
attachButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
attachImage();
}
});
gifButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
findGif();
}
});
ImageButton at = (ImageButton) findViewById(R.id.at_button);
at.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int start = reply.getSelectionStart();
reply.getText().insert(start, "@");
reply.setSelection(start + 1);
}
});
ImageButton hashtag = (ImageButton) findViewById(R.id.hashtag_button);
hashtag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int start = reply.getSelectionStart();
reply.getText().insert(start, "#");
reply.setSelection(start + 1);
}
});
final int SAVE_DRAFT = 0;
final int VIEW_DRAFTS = 1;
final int VIEW_QUEUE = 2;
final int SCHEDULE = 3;
final ImageButton overflow = (ImageButton) findViewById(R.id.overflow_button);
overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(context, findViewById(R.id.discard_button));
menu.getMenu().add(Menu.NONE, SAVE_DRAFT, Menu.NONE, context.getString(R.string.menu_save_draft));
menu.getMenu().add(Menu.NONE, VIEW_DRAFTS, Menu.NONE, context.getString(R.string.menu_view_drafts));
menu.getMenu().add(Menu.NONE, VIEW_QUEUE, Menu.NONE, context.getString(R.string.menu_view_queued));
menu.getMenu().add(Menu.NONE, SCHEDULE, Menu.NONE, context.getString(R.string.menu_schedule_tweet));
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch(menuItem.getItemId()) {
case SAVE_DRAFT:
if (reply.getText().length() > 0) {
QueuedDataSource.getInstance(context).createDraft(reply.getText().toString(), currentAccount);
Toast.makeText(context, getResources().getString(R.string.saved_draft), Toast.LENGTH_SHORT).show();
reply.setText("");
finish();
} else {
Toast.makeText(context, getResources().getString(R.string.no_tweet), Toast.LENGTH_SHORT).show();
}
break;
case VIEW_DRAFTS:
final String[] drafts = QueuedDataSource.getInstance(context).getDrafts();
if (drafts.length > 0) {
final String[] draftsAndDelete = new String[drafts.length + 1];
draftsAndDelete[0] = getString(R.string.delete_all);
for (int i = 1; i < draftsAndDelete.length; i++) {
draftsAndDelete[i] = drafts[i - 1];
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setItems(draftsAndDelete, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int item) {
if (item == 0) {
// clicked the delete all item
new AlertDialog.Builder(context).setMessage(getString(R.string.delete_all) + "?").setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
QueuedDataSource.getInstance(context).deleteAllDrafts();
dialogInterface.dismiss();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).create().show();
dialog.dismiss();
} else {
new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.apply)).setMessage(draftsAndDelete[item]).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
reply.setText(draftsAndDelete[item]);
reply.setSelection(reply.getText().length());
QueuedDataSource.getInstance(context).deleteDraft(draftsAndDelete[item]);
dialogInterface.dismiss();
}
}).setNegativeButton(R.string.delete_draft, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
QueuedDataSource.getInstance(context).deleteDraft(draftsAndDelete[item]);
dialogInterface.dismiss();
}
}).create().show();
dialog.dismiss();
}
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
Toast.makeText(context, R.string.no_drafts, Toast.LENGTH_SHORT).show();
}
break;
case SCHEDULE:
Intent schedule = new Intent(context, ViewScheduledTweets.class);
if (!reply.getText().toString().isEmpty()) {
schedule.putExtra("has_text", true);
schedule.putExtra("text", reply.getText().toString());
}
startActivity(schedule);
finish();
break;
case VIEW_QUEUE:
final String[] queued = QueuedDataSource.getInstance(context).getQueuedTweets(currentAccount);
if (queued.length > 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setItems(queued, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int item) {
new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.keep_queued_tweet)).setMessage(queued[item]).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).setNegativeButton(R.string.delete_draft, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
QueuedDataSource.getInstance(context).deleteQueuedTweet(queued[item]);
dialogInterface.dismiss();
}
}).create().show();
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
Toast.makeText(context, R.string.no_queued, Toast.LENGTH_SHORT).show();
}
break;
}
return false;
}
});
menu.show();
}
});
final ImageButton location = (ImageButton) findViewById(R.id.location);
location.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!addLocation) {
sharedPrefs.edit().putBoolean("share_location", true).commit();
addLocation = true;
if (!settings.addonTheme) {
location.setColorFilter(context.getResources().getColor(R.color.app_color));
} else {
location.setColorFilter(settings.accentInt);
}
} else {
sharedPrefs.edit().putBoolean("share_location", false).commit();
addLocation = false;
location.clearColorFilter();
}
}
});
if (sharedPrefs.getBoolean("share_location", false)) {
location.performClick();
}
if (!settings.useEmoji) {
emojiButton.setVisibility(View.GONE);
} else {
emojiKeyboard.setAttached((HoloEditText) reply);
reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (emojiKeyboard.isShowing()) {
emojiKeyboard.setVisibility(false);
TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button_changing });
int resource = a.getResourceId(0, 0);
a.recycle();
emojiButton.setImageResource(resource);
}
}
});
emojiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (emojiKeyboard.isShowing()) {
emojiKeyboard.setVisibility(false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(reply, 0);
}
}, 250);
TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button_changing });
int resource = a.getResourceId(0, 0);
a.recycle();
emojiButton.setImageResource(resource);
} else {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(reply.getWindowToken(), 0);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
emojiKeyboard.setVisibility(true);
}
}, 250);
TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.keyboard_button_changing });
int resource = a.getResourceId(0, 0);
a.recycle();
emojiButton.setImageResource(resource);
}
}
});
}
}
Aggregations