use of android.text.Editable in project Carbon by ZieIony.
the class AutoCompleteEditText method autoComplete.
private void autoComplete() {
if (dataProvider == null) {
return;
}
Editable text = getText();
if (autoCompleting) {
return;
}
HintSpan[] spans = text.getSpans(0, length(), HintSpan.class);
if (spans.length > 1) {
throw new IllegalStateException("more than one HintSpan");
}
int selStart = getSelectionStart();
if (selStart != getSelectionEnd()) {
return;
}
for (HintSpan span : spans) {
text.delete(text.getSpanStart(span), text.getSpanEnd(span));
}
Word currentWord = getCurrentWord();
if (currentWord == null || currentWord.length() == 0) {
fireOnFilterEvent(null);
return;
}
autoCompleting = true;
filter(currentWord);
fireOnFilterEvent(filteredItems);
if (filteredItems.size() != 0 && filteredItems.get(0).type == FILTERING_START) {
String word = filteredItems.get(0).text.toString();
String remainingPart = word.substring(currentWord.preCursor.length());
text.insert(selStart, remainingPart);
HintSpan span = new HintSpan(getCurrentHintTextColor());
setSelection(selStart);
text.setSpan(span, selStart, selStart + remainingPart.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
AutoCompleteEditText.super.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
autoCompleting = false;
}
use of android.text.Editable in project actor-platform by actorapp.
the class InputBarFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View res = inflater.inflate(R.layout.fragment_inputbar, container, false);
res.setBackgroundColor(style.getMainBackgroundColor());
//
// Message Body
//
messageEditText = (BarEditText) res.findViewById(R.id.et_message);
messageEditText.setTextColor(style.getTextPrimaryColor());
messageEditText.setHintTextColor(style.getTextHintColor());
// Hardware keyboard events
messageEditText.setOnKeyListener((view, keycode, keyEvent) -> {
if (messenger().isSendByEnterEnabled()) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keycode == KeyEvent.KEYCODE_ENTER) {
onSendButtonPressed();
return true;
}
}
return false;
});
// Software keyboard events
messageEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_SEND) {
onSendButtonPressed();
return true;
}
if (i == EditorInfo.IME_ACTION_DONE) {
onSendButtonPressed();
return true;
}
if (messenger().isSendByEnterEnabled()) {
if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
onSendButtonPressed();
return true;
}
}
return false;
});
messageEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
onBeforeTextChanged(charSequence, i, i1, i2);
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
InputBarFragment.this.onTextChanged(charSequence, i, i1, i2);
}
@Override
public void afterTextChanged(Editable editable) {
onAfterTextChanged(editable);
}
});
messageEditText.addSelectionListener((start, length) -> {
InputBarFragment.this.onSelectionChanged(start, length);
});
messageEditText.setOnFocusChangeListener((v, hasFocus) -> {
Fragment parent = getParentFragment();
if (parent instanceof InputBarCallback) {
((InputBarCallback) parent).onTextFocusChanged(hasFocus);
}
});
//
// Send Button
//
sendButton = (TintImageView) res.findViewById(R.id.ib_send);
sendButton.setResource(R.drawable.conv_send);
sendButton.setOnClickListener(v -> {
onSendButtonPressed();
});
//
// Attach Button
//
attachButton = (ImageButton) res.findViewById(R.id.ib_attach);
attachButton.setOnClickListener(v -> {
onAttachButtonClicked();
});
//
// Emoji keyboard
//
emojiButton = (ImageView) res.findViewById(R.id.ib_emoji);
emojiButton.setOnClickListener(v -> emojiKeyboard.toggle());
emojiKeyboard = getEmojiKeyboard();
emojiKeyboard.setOnStickerClickListener(sticker -> {
Fragment parent = getParentFragment();
if (parent instanceof InputBarCallback) {
((InputBarCallback) parent).onStickerSent(sticker);
}
});
emojiKeyboard.setKeyboardStatusListener(new KeyboardStatusListener() {
@Override
public void onDismiss() {
emojiButton.setImageResource(R.drawable.ic_emoji);
}
@Override
public void onShow() {
emojiButton.setImageResource(R.drawable.ic_keyboard);
}
});
//
// Audio
//
audioContainer = res.findViewById(R.id.audioContainer);
audioTimer = (TextView) res.findViewById(R.id.audioTimer);
audioSlide = res.findViewById(R.id.audioSlide);
recordPoint = res.findViewById(R.id.record_point);
audioButton = (ImageView) res.findViewById(R.id.record_btn);
audioButton.setVisibility(View.VISIBLE);
audioButton.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (!isAudioVisible) {
showAudio();
slideStart = (int) event.getX();
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (isAudioVisible) {
hideAudio(false);
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (isAudioVisible) {
int slide = slideStart - (int) event.getX();
if (slide < 0) {
slide = 0;
}
if (slide > SLIDE_LIMIT) {
hideAudio(true);
} else {
slideAudio(slide);
}
}
}
return true;
});
return res;
}
use of android.text.Editable in project GT by Tencent.
the class GTInputParamSetActivity method initAutoCompleteTV.
private void initAutoCompleteTV(ArrayList<String> vals, final AutoCompleteTextView auto) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.gt_drop_default_listitem, vals);
auto.setDropDownBackgroundResource(R.drawable.btn_gray);
auto.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
auto.showDropDown();
}
});
auto.setText(vals.get(0));
auto.setSelection(vals.get(0).length());
auto.setAdapter(adapter);
auto.setThreshold(1);
auto.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (auto.getText().toString().equals("")) {
btn_c.setVisibility(View.GONE);
} else {
btn_c.setVisibility(View.VISIBLE);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
auto.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
auto.showDropDown();
}
});
}
use of android.text.Editable in project CoCoin by Nightonke.
the class AccountBookSettingActivity method userRegister.
private void userRegister() {
registerDialog = new MaterialDialog.Builder(this).title(R.string.go_register).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.dialog_user_register, true).build();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
registerDialogView = registerDialog.getCustomView();
registerDialogButton = (CircularProgressButton) registerDialogView.findViewById(R.id.button);
registerDialogButton.setTypeface(CoCoinUtil.GetTypeface());
registerDialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerDialogButton.setProgress(1);
registerDialog.setCancelable(false);
// User register, a new user////////////////////////////////////////////////////////////////////////
final User user = new User();
// basic info
user.setUsername(registerUserName.getText().toString());
user.setPassword(registerPassword.getText().toString());
user.setEmail(registerUserEmail.getText().toString());
user.setAndroidId(CoCoinApplication.getAndroidId());
if (BuildConfig.DEBUG)
Log.d("CoCoin", "Android Id: " + user.getAndroidId());
// settings info
// user.setLogo();
user.setIsMonthLimit(SettingManager.getInstance().getIsMonthLimit());
user.setMonthLimit(SettingManager.getInstance().getMonthLimit());
user.setIsColorRemind(SettingManager.getInstance().getIsColorRemind());
user.setMonthWarning(SettingManager.getInstance().getMonthWarning());
user.setRemindColor(SettingManager.getInstance().getRemindColor());
user.setIsForbidden(SettingManager.getInstance().getIsForbidden());
user.setAccountBookName(SettingManager.getInstance().getAccountBookName());
user.setAccountBookPassword(SettingManager.getInstance().getPassword());
// Todo store tag order
user.setShowPicture(SettingManager.getInstance().getShowPicture());
user.setIsHollow(SettingManager.getInstance().getIsHollow());
user.setLogoObjectId("");
user.signUp(CoCoinApplication.getAppContext(), new SaveListener() {
@Override
public void onSuccess() {
registerDialogButton.setProgress(0);
registerDialog.setCancelable(true);
registerDialogButton.setIdleText(getResourceString(R.string.register_complete));
// if register successfully/////////////////////////////////////////////////////////////////////////
SettingManager.getInstance().setLoggenOn(true);
SettingManager.getInstance().setUserName(registerUserName.getText().toString());
SettingManager.getInstance().setUserEmail(registerUserEmail.getText().toString());
SettingManager.getInstance().setUserPassword(registerPassword.getText().toString());
showToast(4, registerUserName.getText().toString());
// if login successfully////////////////////////////////////////////////////////////////////////////
user.login(CoCoinApplication.getAppContext(), new SaveListener() {
@Override
public void onSuccess() {
SettingManager.getInstance().setTodayViewInfoShouldChange(true);
updateViews();
// use a new method
// RecordManager.updateOldRecordsToServer();
}
@Override
public void onFailure(int code, String msg) {
// if login failed//////////////////////////////////////////////////////////////////////////////////
}
});
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (registerDialog != null)
registerDialog.dismiss();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
}
}, 500);
}
// if register failed///////////////////////////////////////////////////////////////////////////////
@Override
public void onFailure(int code, String msg) {
if (BuildConfig.DEBUG)
Log.d("CoCoin", "Register failed: " + msg);
String tip = getResourceString(R.string.network_disconnection);
if (msg.charAt(1) == 's')
tip = getResourceString(R.string.user_name_exist);
if (msg.charAt(0) == 'e')
tip = getResourceString(R.string.user_email_exist);
if (msg.charAt(1) == 'n')
tip = getResourceString(R.string.user_mobile_exist);
registerDialogButton.setIdleText(tip);
registerDialogButton.setProgress(0);
registerDialog.setCancelable(true);
}
});
}
});
final MDButton positiveAction = registerDialog.getActionButton(DialogAction.POSITIVE);
positiveAction.setEnabled(false);
final EmailValidator emailValidator = new EmailValidator();
TextView userNameTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_user_name_text);
TextView userEmailTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_user_email_text);
TextView userPasswordTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_password_text);
userNameTV.setTypeface(CoCoinUtil.GetTypeface());
userEmailTV.setTypeface(CoCoinUtil.GetTypeface());
userPasswordTV.setTypeface(CoCoinUtil.GetTypeface());
registerUserName = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_user_name);
registerUserEmail = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_user_email);
registerPassword = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_password);
registerUserName.setTypeface(CoCoinUtil.GetTypeface());
registerUserName.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) {
boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
if (emailValidator.validate(registerUserEmail.getText().toString())) {
registerUserEmail.validate();
} else {
registerUserEmail.invalidate();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
registerUserEmail.setTypeface(CoCoinUtil.GetTypeface());
registerUserEmail.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) {
boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
if (emailValidator.validate(registerUserEmail.getText().toString())) {
registerUserEmail.validate();
} else {
registerUserEmail.invalidate();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
registerPassword.setTypeface(CoCoinUtil.GetTypeface());
registerPassword.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) {
boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
if (emailValidator.validate(registerUserEmail.getText().toString())) {
registerUserEmail.validate();
} else {
registerUserEmail.invalidate();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
registerDialog.show();
}
use of android.text.Editable in project CoCoin by Nightonke.
the class AccountBookSettingActivity method userLogin.
private void userLogin() {
loginDialog = new MaterialDialog.Builder(this).title(R.string.go_login).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.dialog_user_login, true).build();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
loginDialogView = loginDialog.getCustomView();
loginDialogButton = (CircularProgressButton) loginDialogView.findViewById(R.id.button);
loginDialogButton.isIndeterminateProgressMode();
loginDialogButton.setProgress(0);
loginDialogButton.setTypeface(CoCoinUtil.GetTypeface());
loginDialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginDialog.setCancelable(false);
loginDialogButton.setProgress(1);
// the user ask to login////////////////////////////////////////////////////////////////////////////
final User user = new User();
user.setUsername(loginUserName.getText().toString());
user.setPassword(loginPassword.getText().toString());
user.login(CoCoinApplication.getAppContext(), new SaveListener() {
// try with user name///////////////////////////////////////////////////////////////////////////////
@Override
public void onSuccess() {
loginDialog.setCancelable(true);
loginDialogButton.setProgress(0);
loginDialogButton.setIdleText(getResourceString(R.string.login_complete));
// login successfully through user name/////////////////////////////////////////////////////////////
SettingManager.getInstance().setTodayViewInfoShouldChange(true);
User loginUser = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
if (!CoCoinApplication.getAndroidId().equals(loginUser.getAndroidId())) {
// 2 users on one mobile////////////////////////////////////////////////////////////////////////////
showToast(7, "unique...");
return;
}
SettingManager.getInstance().setLoggenOn(true);
SettingManager.getInstance().setUserName(loginUserName.getText().toString());
SettingManager.getInstance().setUserEmail(loginUser.getEmail());
updateViews();
// use a new method
// RecordManager.updateOldRecordsToServer();
whetherSyncSettingsFromServer();
showToast(6, loginUserName.getText().toString());
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (loginDialog != null)
loginDialog.dismiss();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
}
}, 500);
}
// login fail through user name/////////////////////////////////////////////////////////////////////
@Override
public void onFailure(int code, String msg) {
// try with user email//////////////////////////////////////////////////////////////////////////////
user.setEmail(loginUserName.getText().toString());
user.login(CoCoinApplication.getAppContext(), new SaveListener() {
@Override
public void onSuccess() {
loginDialog.setCancelable(true);
loginDialogButton.setProgress(0);
loginDialogButton.setIdleText(getResourceString(R.string.login_complete));
// login successfully through user email////////////////////////////////////////////////////////////
SettingManager.getInstance().setTodayViewInfoShouldChange(true);
User loginUser = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
if (!CoCoinApplication.getAndroidId().equals(loginUser.getAndroidId())) {
// 2 users on one mobile////////////////////////////////////////////////////////////////////////////
showToast(7, "unique...");
return;
}
String userName = loginUser.getUsername();
SettingManager.getInstance().setLoggenOn(true);
SettingManager.getInstance().setUserName(userName);
SettingManager.getInstance().setUserEmail(loginUserName.getText().toString());
SettingManager.getInstance().setUserPassword(loginPassword.getText().toString());
updateViews();
// use a new method
// RecordManager.updateOldRecordsToServer();
whetherSyncSettingsFromServer();
showToast(6, userName);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (loginDialog != null)
loginDialog.dismiss();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
}
}, 500);
}
// login fail through user name and email///////////////////////////////////////////////////////////
@Override
public void onFailure(int code, String msg) {
loginDialog.setCancelable(true);
loginDialogButton.setProgress(0);
String tip = getResourceString(R.string.network_disconnection);
if (msg.charAt(0) == 'u')
tip = getResourceString(R.string.user_name_or_password_incorrect);
if (msg.charAt(1) == 'n')
tip = getResourceString(R.string.user_mobile_exist);
loginDialogButton.setIdleText(tip);
}
});
}
});
}
});
final MDButton positiveAction = loginDialog.getActionButton(DialogAction.POSITIVE);
positiveAction.setEnabled(false);
TextView userNameTV = (TextView) loginDialog.getCustomView().findViewById(R.id.login_user_name_text);
TextView userPasswordTV = (TextView) loginDialog.getCustomView().findViewById(R.id.login_password_text);
userNameTV.setTypeface(CoCoinUtil.GetTypeface());
userPasswordTV.setTypeface(CoCoinUtil.GetTypeface());
loginUserName = (MaterialEditText) loginDialog.getCustomView().findViewById(R.id.login_user_name);
loginPassword = (MaterialEditText) loginDialog.getCustomView().findViewById(R.id.login_password);
loginUserName.setTypeface(CoCoinUtil.GetTypeface());
loginUserName.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) {
loginDialogButton.setEnabled(0 < loginUserName.getText().toString().length() && 0 < loginPassword.getText().toString().length());
}
@Override
public void afterTextChanged(Editable s) {
}
});
loginPassword.setTypeface(CoCoinUtil.GetTypeface());
loginPassword.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) {
loginDialogButton.setEnabled(0 < loginUserName.getText().toString().length() && 0 < loginPassword.getText().toString().length());
}
@Override
public void afterTextChanged(Editable s) {
}
});
loginDialog.show();
}
Aggregations