use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.
the class UserAutoCompleteHelper method on.
private void on(final EditText textView) {
userAutoComplete.setAnchorView(textView);
textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String tvText = textView.getText().toString();
try {
int position = textView.getSelectionStart() - 1;
if (tvText.charAt(position) == '@') {
userAutoComplete.show();
} else if (!tvText.contains("@")) {
userAutoComplete.dismiss();
} else if (userAutoComplete.isShowing()) {
String searchText = "";
do {
searchText = tvText.charAt(position--) + searchText;
} while (tvText.charAt(position) != '@');
searchText = searchText.replace("@", "");
search(searchText);
}
} catch (Exception e) {
e.printStackTrace();
userAutoComplete.dismiss();
}
}
});
userAutoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
userAutoComplete.dismiss();
autoCompleter.completeTweet(textView, users.get(i).getScreenName(), '@');
if (callback != null) {
callback.onUserSelected(users.get(i));
}
}
});
}
use of android.text.TextWatcher in project KJFrameForAndroid by kymjs.
the class TweetRecordFragment method initWidget.
@Override
protected void initWidget(View view) {
super.initWidget(view);
RelativeLayout.LayoutParams params = (LayoutParams) mBtnRecort.getLayoutParams();
params.width = DensityUtils.getScreenW(getActivity());
params.height = (int) (DensityUtils.getScreenH(getActivity()) * 0.4);
mBtnRecort.setLayoutParams(params);
mBtnRecort.setOnFinishedRecordListener(new OnFinishedRecordListener() {
@Override
public void onFinishedRecord(String audioPath, int recordTime) {
mLayout.setVisibility(View.VISIBLE);
if (recordTime < 10) {
mTvTime.setText("0" + recordTime + "\"");
} else {
mTvTime.setText(recordTime + "\"");
}
mImgAdd.setVisibility(View.GONE);
filePath = null;
}
@Override
public void onCancleRecord() {
mLayout.setVisibility(View.GONE);
}
});
drawable = (AnimationDrawable) mImgVolume.getBackground();
mBtnRecort.getAudioUtil().setOnPlayListener(new OnPlayListener() {
@Override
public void stopPlay() {
drawable.stop();
mImgVolume.setBackgroundDrawable(drawable.getFrame(0));
}
@Override
public void starPlay() {
mImgVolume.setBackgroundDrawable(drawable);
drawable.start();
}
});
mEtSpeech.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > MAX_LEN) {
mTvInputLen.setText("已达到最大长度");
} else {
mTvInputLen.setText("你还可以输入" + (MAX_LEN - s.length()) + "个字");
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() > MAX_LEN) {
mEtSpeech.setText(s.subSequence(0, MAX_LEN));
CharSequence text = mEtSpeech.getText();
if (text instanceof Spannable) {
Selection.setSelection((Spannable) text, MAX_LEN);
}
}
}
});
}
use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.
the class NewScheduledTweet method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = AppSettings.getInstance(this);
Utils.setUpTheme(this, settings);
countHandler = new Handler();
setContentView(R.layout.scheduled_new_tweet_activity);
Intent intent = getIntent();
sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
context = this;
mEditText = (EditText) findViewById(R.id.tweet_content);
counter = (HoloTextView) findViewById(R.id.char_remaining);
emojiButton = (ImageButton) findViewById(R.id.emojiButton);
emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
// if they are coming from the compose window with text, then display it
if (getIntent().getBooleanExtra("has_text", false)) {
mEditText.setText(getIntent().getStringExtra("text"));
mEditText.setSelection(mEditText.getText().length());
}
final ListPopupWindow autocomplete = new ListPopupWindow(context);
autocomplete.setAnchorView(mEditText);
autocomplete.setHeight(Utils.toDP(100, context));
autocomplete.setWidth(Utils.toDP(275, context));
try {
autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, mEditText.getText().toString()), mEditText));
} catch (Exception e) {
// not really sure why
}
autocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
autocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
autocomplete.dismiss();
}
});
mEditText.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 = mEditText.getText().toString();
try {
if (searchText.substring(searchText.length() - 1, searchText.length()).equals("@")) {
autocomplete.show();
} else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
autocomplete.dismiss();
} else if (autocomplete.isShowing()) {
String[] split = mEditText.getText().toString().split(" ");
String adapterText;
if (split.length > 1) {
adapterText = split[split.length - 1];
} else {
adapterText = split[0];
}
adapterText = adapterText.replace("@", "");
autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, adapterText), mEditText));
}
} catch (Exception e) {
// there is no text
try {
autocomplete.dismiss();
} catch (Exception x) {
// something went really wrong i guess haha
}
}
countHandler.removeCallbacks(getCount);
countHandler.postDelayed(getCount, 300);
}
});
if (!sharedPrefs.getBoolean("keyboard_type", true)) {
mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
mEditText.setImeOptions(EditorInfo.IME_ACTION_NONE);
}
startDate = intent.getStringExtra(ViewScheduledTweets.EXTRA_TIME);
startMessage = intent.getStringExtra(ViewScheduledTweets.EXTRA_TEXT);
if (TextUtils.isEmpty(startDate)) {
startDate = "";
}
if (TextUtils.isEmpty(startMessage)) {
startMessage = "";
}
final Calendar c = Calendar.getInstance();
currentYear = c.get(Calendar.YEAR);
currentMonth = c.get(Calendar.MONTH);
currentDay = c.get(Calendar.DAY_OF_MONTH);
currentHour = c.get(Calendar.HOUR_OF_DAY);
currentMinute = c.get(Calendar.MINUTE);
currentDate = new Date(currentYear, currentMonth, currentDay, currentHour, currentMinute);
timeDisplay = (TextView) findViewById(R.id.currentTime);
dateDisplay = (TextView) findViewById(R.id.currentDate);
btDate = (Button) findViewById(R.id.setDate);
btTime = (Button) findViewById(R.id.setTime);
if (!startDate.equals("") && !startDate.equals("null")) {
setDate = new Date(Long.parseLong(startDate));
timeDone = true;
btTime.setEnabled(true);
} else {
btTime.setEnabled(false);
}
if (mEditText.getText().toString().isEmpty()) {
mEditText.setText(startMessage);
}
if (!startDate.equals("")) {
Date startDateObj = new Date(Long.parseLong(startDate));
if (sharedPrefs.getBoolean("hour_format", false)) {
timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(startDateObj));
} else {
timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(startDateObj));
}
if (sharedPrefs.getBoolean("hour_format", false)) {
dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
} else {
dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
}
}
if (!settings.useEmoji) {
emojiButton.setVisibility(View.GONE);
} else {
emojiKeyboard.setAttached((HoloEditText) mEditText);
mEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (emojiKeyboard.isShowing()) {
emojiKeyboard.setVisibility(false);
}
}
});
emojiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
emojiKeyboard.toggleVisibility();
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) emojiKeyboard.getLayoutParams();
params.topMargin = mEditText.getHeight();
emojiKeyboard.setLayoutParams(params);
}
});
}
// sets the date button listener to call the dialog
btDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
com.android.datetimepicker.date.DatePickerDialog.newInstance(reservationDate, currentYear, currentMonth, currentDay, settings.theme != AppSettings.THEME_LIGHT).show(getFragmentManager(), "date_picker");
btTime.setEnabled(true);
}
});
// sets the time button listener to call the dialog
btTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
com.android.datetimepicker.time.TimePickerDialog dialog = com.android.datetimepicker.time.TimePickerDialog.newInstance(timeDate, currentHour, currentMinute, settings.militaryTime);
if (settings.theme != AppSettings.THEME_LIGHT) {
dialog.setThemeDark(true);
}
dialog.show(getFragmentManager(), "time_picker");
}
});
// Inflate a "Done/Discard" custom action bar view.
LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(R.layout.actionbar_done_discard, null);
FrameLayout done = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_done);
((TextView) done.findViewById(R.id.done)).setText(R.string.done_label);
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
doneClick();
}
});
FrameLayout discard = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_discard);
if (!TextUtils.isEmpty(getIntent().getStringExtra(ViewScheduledTweets.EXTRA_TIME))) {
((TextView) discard.findViewById(R.id.discard)).setText(R.string.delete);
}
discard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
discardClick();
}
});
// Show the custom action bar view and hide the normal Home icon and title.
final ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
use of android.text.TextWatcher in project k-9 by k9mail.
the class AccountSetupNames method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_names);
mDescription = (EditText) findViewById(R.id.account_description);
mName = (EditText) findViewById(R.id.account_name);
mDoneButton = (Button) findViewById(R.id.done);
mDoneButton.setOnClickListener(this);
TextWatcher validationTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
validateFields();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
};
mName.addTextChangedListener(validationTextWatcher);
mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS));
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
// mDescription.setText(mAccount.getDescription());
if (mAccount.getName() != null) {
mName.setText(mAccount.getName());
}
if (!Utility.requiredFieldValid(mName)) {
mDoneButton.setEnabled(false);
}
}
use of android.text.TextWatcher in project mobile-android by photo.
the class TwitterFragment method init.
void init(View view, Bundle savedInstanceState) {
try {
new ShowCurrentlyLoggedInUserTask(view).execute();
messageEt = (EditText) view.findViewById(R.id.message);
if (savedInstanceState != null) {
messageEt.setText(savedInstanceState.getString(TWEET));
textModified = savedInstanceState.getBoolean(TEXT_MODIFIED);
photo = savedInstanceState.getParcelable(PHOTO);
} else {
String message = getDefaultTweetMessage(photo);
messageEt.setText(message);
}
messageEt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
textModified = true;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
Button logOutButton = (Button) view.findViewById(R.id.logoutBtn);
logOutButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("logoutBtn", TwitterFragment.this);
performTwitterLogout();
}
});
sendButton = (Button) view.findViewById(R.id.sendBtn);
sendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("sendBtn", TwitterFragment.this);
if (GuiUtils.checkLoggedInAndOnline()) {
postTweet();
}
}
});
if (!textModified) {
sendButton.setEnabled(false);
PhotoUtils.validateShareTokenExistsAsyncAndRunAsync(photo, new RunnableWithParameter<Photo>() {
@Override
public void run(Photo parameter) {
sendButton.setEnabled(true);
String message = getDefaultTweetMessage(photo, true);
messageEt.setText(message);
}
}, new Runnable() {
@Override
public void run() {
sendButton.setEnabled(false);
}
}, new TweetLoadingControl(view));
}
} catch (Exception ex) {
GuiUtils.error(TAG, R.string.errorCouldNotInitTwitterFragment, ex, getActivity());
dismissAllowingStateLoss();
}
}
Aggregations