use of org.telegram.ui.Components.CodepointsLengthInputFilter in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChangeBioActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("UserBio", R.string.UserBio));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
saveName();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setContentDescription(LocaleController.getString("Done", R.string.Done));
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener((v, event) -> true);
FrameLayout fieldContainer = new FrameLayout(context);
linearLayout.addView(fieldContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 24, 20, 0));
firstNameField = new EditTextBoldCursor(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
firstNameField.setMaxLines(4);
firstNameField.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 24 : 0), 0, AndroidUtilities.dp(LocaleController.isRTL ? 0 : 24), AndroidUtilities.dp(6));
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
firstNameField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new CodepointsLengthInputFilter(70) {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (source != null && source.length() > 0 && TextUtils.indexOf(source, '\n') == source.length() - 1) {
doneButton.performClick();
return "";
}
CharSequence result = super.filter(source, start, end, dest, dstart, dend);
if (result != null && source != null && result.length() != source.length()) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(checkTextView, 2, 0);
}
return result;
}
};
firstNameField.setFilters(inputFilters);
firstNameField.setMinHeight(AndroidUtilities.dp(36));
firstNameField.setHint(LocaleController.getString("UserBio", R.string.UserBio));
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setCursorSize(AndroidUtilities.dp(20));
firstNameField.setCursorWidth(1.5f);
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
});
firstNameField.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) {
}
@Override
public void afterTextChanged(Editable s) {
checkTextView.setNumber(70 - Character.codePointCount(s, 0, s.length()), true);
}
});
fieldContainer.addView(firstNameField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 0, 4, 0));
checkTextView = new NumberTextView(context);
checkTextView.setCenterAlign(true);
checkTextView.setTextSize(15);
checkTextView.setNumber(70, false);
checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
checkTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
fieldContainer.addView(checkTextView, LayoutHelper.createFrame(20, 20, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT, 0, 4, 4, 0));
helpTextView = new TextView(context);
helpTextView.setFocusable(true);
helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
helpTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8));
helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
helpTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("UserBioInfo", R.string.UserBioInfo)));
linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 0));
TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(UserConfig.getInstance(currentAccount).getClientUserId());
if (userFull != null && userFull.about != null) {
firstNameField.setText(userFull.about);
firstNameField.setSelection(firstNameField.length());
}
return fragmentView;
}
Aggregations