use of org.telegram.ui.Components.NumberTextView in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemeDescription method setColor.
public void setColor(int color, boolean useDefault, boolean save) {
if (save) {
Theme.setColor(currentKey, color, useDefault);
}
currentColor = color;
if (alphaOverride > 0) {
color = Color.argb(alphaOverride, Color.red(color), Color.green(color), Color.blue(color));
}
if (paintToUpdate != null) {
for (int a = 0; a < paintToUpdate.length; a++) {
if ((changeFlags & FLAG_LINKCOLOR) != 0 && paintToUpdate[a] instanceof TextPaint) {
((TextPaint) paintToUpdate[a]).linkColor = color;
} else {
paintToUpdate[a].setColor(color);
}
}
}
if (drawablesToUpdate != null) {
for (int a = 0; a < drawablesToUpdate.length; a++) {
if (drawablesToUpdate[a] == null) {
continue;
}
if (drawablesToUpdate[a] instanceof BackDrawable) {
((BackDrawable) drawablesToUpdate[a]).setColor(color);
} else if (drawablesToUpdate[a] instanceof ScamDrawable) {
((ScamDrawable) drawablesToUpdate[a]).setColor(color);
} else if (drawablesToUpdate[a] instanceof RLottieDrawable) {
if (lottieLayerName != null) {
((RLottieDrawable) drawablesToUpdate[a]).setLayerColor(lottieLayerName + ".**", color);
}
} else if (drawablesToUpdate[a] instanceof CombinedDrawable) {
if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
((CombinedDrawable) drawablesToUpdate[a]).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
} else {
((CombinedDrawable) drawablesToUpdate[a]).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
} else if (drawablesToUpdate[a] instanceof AvatarDrawable) {
((AvatarDrawable) drawablesToUpdate[a]).setColor(color);
} else if (drawablesToUpdate[a] instanceof AnimatedArrowDrawable) {
((AnimatedArrowDrawable) drawablesToUpdate[a]).setColor(color);
} else {
drawablesToUpdate[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
}
}
if (viewToInvalidate != null && listClasses == null && listClassesFieldName == null) {
if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
if ((changeFlags & FLAG_BACKGROUND) != 0) {
Drawable background = viewToInvalidate.getBackground();
if (background instanceof MessageBackgroundDrawable) {
((MessageBackgroundDrawable) background).setColor(color);
((MessageBackgroundDrawable) background).setCustomPaint(null);
} else {
viewToInvalidate.setBackgroundColor(color);
}
}
if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
if (viewToInvalidate instanceof EditTextBoldCursor) {
((EditTextBoldCursor) viewToInvalidate).setErrorLineColor(color);
}
} else {
Drawable drawable = viewToInvalidate.getBackground();
if (drawable instanceof CombinedDrawable) {
if ((changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0) {
drawable = ((CombinedDrawable) drawable).getBackground();
} else {
drawable = ((CombinedDrawable) drawable).getIcon();
}
}
if (drawable != null) {
if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
} else if (drawable instanceof ShapeDrawable) {
((ShapeDrawable) drawable).getPaint().setColor(color);
} else {
drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
}
}
}
}
}
if (viewToInvalidate instanceof ActionBar) {
if ((changeFlags & FLAG_AB_ITEMSCOLOR) != 0) {
((ActionBar) viewToInvalidate).setItemsColor(color, false);
}
if ((changeFlags & FLAG_AB_TITLECOLOR) != 0) {
((ActionBar) viewToInvalidate).setTitleColor(color);
}
if ((changeFlags & FLAG_AB_SELECTORCOLOR) != 0) {
((ActionBar) viewToInvalidate).setItemsBackgroundColor(color, false);
}
if ((changeFlags & FLAG_AB_AM_SELECTORCOLOR) != 0) {
((ActionBar) viewToInvalidate).setItemsBackgroundColor(color, true);
}
if ((changeFlags & FLAG_AB_AM_ITEMSCOLOR) != 0) {
((ActionBar) viewToInvalidate).setItemsColor(color, true);
}
if ((changeFlags & FLAG_AB_SUBTITLECOLOR) != 0) {
((ActionBar) viewToInvalidate).setSubtitleColor(color);
}
if ((changeFlags & FLAG_AB_AM_BACKGROUND) != 0) {
((ActionBar) viewToInvalidate).setActionModeColor(color);
}
if ((changeFlags & FLAG_AB_AM_TOPBACKGROUND) != 0) {
((ActionBar) viewToInvalidate).setActionModeTopColor(color);
}
if ((changeFlags & FLAG_AB_SEARCHPLACEHOLDER) != 0) {
((ActionBar) viewToInvalidate).setSearchTextColor(color, true);
}
if ((changeFlags & FLAG_AB_SEARCH) != 0) {
((ActionBar) viewToInvalidate).setSearchTextColor(color, false);
}
if ((changeFlags & FLAG_AB_SUBMENUITEM) != 0) {
((ActionBar) viewToInvalidate).setPopupItemsColor(color, (changeFlags & FLAG_IMAGECOLOR) != 0, false);
}
if ((changeFlags & FLAG_AB_SUBMENUBACKGROUND) != 0) {
((ActionBar) viewToInvalidate).setPopupBackgroundColor(color, false);
}
}
if (viewToInvalidate instanceof VideoTimelineView) {
((VideoTimelineView) viewToInvalidate).setColor(color);
}
if (viewToInvalidate instanceof EmptyTextProgressView) {
if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
((EmptyTextProgressView) viewToInvalidate).setTextColor(color);
} else if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
((EmptyTextProgressView) viewToInvalidate).setProgressBarColor(color);
}
}
if (viewToInvalidate instanceof RadialProgressView) {
((RadialProgressView) viewToInvalidate).setProgressColor(color);
} else if (viewToInvalidate instanceof LineProgressView) {
if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
((LineProgressView) viewToInvalidate).setProgressColor(color);
} else {
((LineProgressView) viewToInvalidate).setBackColor(color);
}
} else if (viewToInvalidate instanceof ContextProgressView) {
((ContextProgressView) viewToInvalidate).updateColors();
} else if (viewToInvalidate instanceof SeekBarView) {
if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
((SeekBarView) viewToInvalidate).setOuterColor(color);
}
}
if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
if (viewToInvalidate instanceof TextView) {
((TextView) viewToInvalidate).setTextColor(color);
} else if (viewToInvalidate instanceof NumberTextView) {
((NumberTextView) viewToInvalidate).setTextColor(color);
} else if (viewToInvalidate instanceof SimpleTextView) {
((SimpleTextView) viewToInvalidate).setTextColor(color);
} else if (viewToInvalidate instanceof ChatBigEmptyView) {
((ChatBigEmptyView) viewToInvalidate).setTextColor(color);
}
}
}
if ((changeFlags & FLAG_CURSORCOLOR) != 0) {
if (viewToInvalidate instanceof EditTextBoldCursor) {
((EditTextBoldCursor) viewToInvalidate).setCursorColor(color);
}
}
if ((changeFlags & FLAG_HINTTEXTCOLOR) != 0) {
if (viewToInvalidate instanceof EditTextBoldCursor) {
if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
((EditTextBoldCursor) viewToInvalidate).setHeaderHintColor(color);
} else {
((EditTextBoldCursor) viewToInvalidate).setHintColor(color);
}
} else if (viewToInvalidate instanceof EditText) {
((EditText) viewToInvalidate).setHintTextColor(color);
}
}
if (viewToInvalidate != null && (changeFlags & FLAG_SERVICEBACKGROUND) != 0) {
}
if ((changeFlags & FLAG_IMAGECOLOR) != 0) {
if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
if (viewToInvalidate instanceof ImageView) {
if ((changeFlags & FLAG_USEBACKGROUNDDRAWABLE) != 0) {
Drawable drawable = ((ImageView) viewToInvalidate).getDrawable();
if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
}
} else {
((ImageView) viewToInvalidate).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
} else if (viewToInvalidate instanceof BackupImageView) {
// ((BackupImageView) viewToInvalidate).setResourceImageColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
} else if (viewToInvalidate instanceof SimpleTextView) {
SimpleTextView textView = (SimpleTextView) viewToInvalidate;
textView.setSideDrawablesColor(color);
} else if (viewToInvalidate instanceof TextView) {
Drawable[] drawables = ((TextView) viewToInvalidate).getCompoundDrawables();
if (drawables != null) {
for (int a = 0; a < drawables.length; a++) {
if (drawables[a] != null) {
drawables[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
}
}
}
}
}
if (viewToInvalidate instanceof ScrollView) {
if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
AndroidUtilities.setScrollViewEdgeEffectColor((ScrollView) viewToInvalidate, color);
}
}
if (viewToInvalidate instanceof ViewPager) {
if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
AndroidUtilities.setViewPagerEdgeEffectColor((ViewPager) viewToInvalidate, color);
}
}
if (viewToInvalidate instanceof RecyclerListView) {
RecyclerListView recyclerListView = (RecyclerListView) viewToInvalidate;
if ((changeFlags & FLAG_SELECTOR) != 0) {
recyclerListView.setListSelectorColor(color);
}
if ((changeFlags & FLAG_FASTSCROLL) != 0) {
recyclerListView.updateFastScrollColors();
}
if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
recyclerListView.setGlowColor(color);
}
if ((changeFlags & FLAG_SECTIONS) != 0) {
ArrayList<View> headers = recyclerListView.getHeaders();
if (headers != null) {
for (int a = 0; a < headers.size(); a++) {
processViewColor(headers.get(a), color);
}
}
headers = recyclerListView.getHeadersCache();
if (headers != null) {
for (int a = 0; a < headers.size(); a++) {
processViewColor(headers.get(a), color);
}
}
View header = recyclerListView.getPinnedHeader();
if (header != null) {
processViewColor(header, color);
}
}
} else if (viewToInvalidate != null && (listClasses == null || listClasses.length == 0)) {
if ((changeFlags & FLAG_SELECTOR) != 0) {
viewToInvalidate.setBackgroundDrawable(Theme.getSelectorDrawable(false));
} else if ((changeFlags & FLAG_SELECTORWHITE) != 0) {
viewToInvalidate.setBackgroundDrawable(Theme.getSelectorDrawable(true));
}
}
if (listClasses != null) {
if (viewToInvalidate instanceof RecyclerListView) {
RecyclerListView recyclerListView = (RecyclerListView) viewToInvalidate;
recyclerListView.getRecycledViewPool().clear();
int count = recyclerListView.getHiddenChildCount();
for (int a = 0; a < count; a++) {
processViewColor(recyclerListView.getHiddenChildAt(a), color);
}
count = recyclerListView.getCachedChildCount();
for (int a = 0; a < count; a++) {
processViewColor(recyclerListView.getCachedChildAt(a), color);
}
count = recyclerListView.getAttachedScrapChildCount();
for (int a = 0; a < count; a++) {
processViewColor(recyclerListView.getAttachedScrapChildAt(a), color);
}
}
if (viewToInvalidate instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) viewToInvalidate;
int count = viewGroup.getChildCount();
for (int a = 0; a < count; a++) {
processViewColor(viewGroup.getChildAt(a), color);
}
}
processViewColor(viewToInvalidate, color);
}
if (delegate != null) {
delegate.didSetColor();
}
if (viewToInvalidate != null) {
viewToInvalidate.invalidate();
}
}
use of org.telegram.ui.Components.NumberTextView 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