Search in sources :

Example 1 with GroupCreateCheckBox

use of org.telegram.ui.Components.GroupCreateCheckBox in project Telegram-FOSS by Telegram-FOSS-Team.

the class ThemeDescription method processViewColor.

private void processViewColor(View child, int color) {
    for (int b = 0; b < listClasses.length; b++) {
        if (listClasses[b].isInstance(child)) {
            child.invalidate();
            boolean passedCheck;
            if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, child)) {
                passedCheck = true;
                child.invalidate();
                if (listClassesFieldName == null && (changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                    Drawable drawable = child.getBackground();
                    if (drawable != null) {
                        if ((changeFlags & FLAG_CELLBACKGROUNDCOLOR) != 0) {
                            if (drawable instanceof CombinedDrawable) {
                                Drawable back = ((CombinedDrawable) drawable).getBackground();
                                if (back instanceof ColorDrawable) {
                                    ((ColorDrawable) back).setColor(color);
                                }
                            }
                        } else {
                            if (drawable instanceof CombinedDrawable) {
                                drawable = ((CombinedDrawable) drawable).getIcon();
                            } else if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                                Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                            }
                            drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                } else if ((changeFlags & FLAG_CELLBACKGROUNDCOLOR) != 0) {
                    child.setBackgroundColor(color);
                } else if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
                    if (child instanceof TextView) {
                        ((TextView) child).setTextColor(color);
                    } else if (child instanceof AudioPlayerAlert.ClippingTextViewSwitcher) {
                        for (int i = 0; i < 2; i++) {
                            TextView textView = i == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) child).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) child).getNextTextView();
                            if (textView != null) {
                                textView.setTextColor(color);
                            }
                        }
                    }
                } else if ((changeFlags & FLAG_SERVICEBACKGROUND) != 0) {
                } else if ((changeFlags & FLAG_SELECTOR) != 0) {
                    child.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                } else if ((changeFlags & FLAG_SELECTORWHITE) != 0) {
                    child.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                }
            } else {
                passedCheck = false;
            }
            if (listClassesFieldName != null) {
                String key = listClasses[b] + "_" + listClassesFieldName[b];
                if (notFoundCachedFields != null && notFoundCachedFields.containsKey(key)) {
                    continue;
                }
                try {
                    Field field = cachedFields.get(key);
                    if (field == null) {
                        field = listClasses[b].getDeclaredField(listClassesFieldName[b]);
                        if (field != null) {
                            field.setAccessible(true);
                            cachedFields.put(key, field);
                        }
                    }
                    if (field != null) {
                        Object object = field.get(child);
                        if (object != null) {
                            if (!passedCheck && object instanceof View && !checkTag(currentKey, (View) object)) {
                                continue;
                            }
                            if (object instanceof View) {
                                ((View) object).invalidate();
                            }
                            if (lottieLayerName != null && object instanceof RLottieImageView) {
                                ((RLottieImageView) object).setLayerColor(lottieLayerName + ".**", color);
                            }
                            if ((changeFlags & FLAG_USEBACKGROUNDDRAWABLE) != 0 && object instanceof View) {
                                object = ((View) object).getBackground();
                            }
                            if ((changeFlags & FLAG_BACKGROUND) != 0 && object instanceof View) {
                                View view = (View) object;
                                Drawable background = view.getBackground();
                                if (background instanceof MessageBackgroundDrawable) {
                                    ((MessageBackgroundDrawable) background).setColor(color);
                                    ((MessageBackgroundDrawable) background).setCustomPaint(null);
                                } else {
                                    view.setBackgroundColor(color);
                                }
                            } else if (object instanceof EditTextCaption) {
                                if ((changeFlags & FLAG_HINTTEXTCOLOR) != 0) {
                                    ((EditTextCaption) object).setHintColor(color);
                                    ((EditTextCaption) object).setHintTextColor(color);
                                } else if ((changeFlags & FLAG_CURSORCOLOR) != 0) {
                                    ((EditTextCaption) object).setCursorColor(color);
                                } else {
                                    ((EditTextCaption) object).setTextColor(color);
                                }
                            } else if (object instanceof SimpleTextView) {
                                if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    ((SimpleTextView) object).setLinkTextColor(color);
                                } else {
                                    ((SimpleTextView) object).setTextColor(color);
                                }
                            } else if (object instanceof TextView) {
                                TextView textView = (TextView) object;
                                if ((changeFlags & FLAG_IMAGECOLOR) != 0) {
                                    Drawable[] drawables = textView.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));
                                            }
                                        }
                                    }
                                } else if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    textView.getPaint().linkColor = color;
                                    textView.invalidate();
                                } else if ((changeFlags & FLAG_FASTSCROLL) != 0) {
                                    CharSequence text = textView.getText();
                                    if (text instanceof SpannedString) {
                                        TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                        if (spans != null && spans.length > 0) {
                                            for (int i = 0; i < spans.length; i++) {
                                                spans[i].setColor(color);
                                            }
                                        }
                                    }
                                } else {
                                    textView.setTextColor(color);
                                }
                            } else if (object instanceof ImageView) {
                                ImageView imageView = (ImageView) object;
                                Drawable drawable = imageView.getDrawable();
                                if (drawable instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) drawable).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) drawable).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else {
                                    imageView.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof BackupImageView) {
                                Drawable drawable = ((BackupImageView) object).getImageReceiver().getStaticThumb();
                                if (drawable instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) drawable).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) drawable).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else if (drawable != null) {
                                    drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof Drawable) {
                                if (object instanceof LetterDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((LetterDrawable) object).setBackgroundColor(color);
                                    } else {
                                        ((LetterDrawable) object).setColor(color);
                                    }
                                } else if (object instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) object).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) object).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else if (object instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && object instanceof RippleDrawable) {
                                    Theme.setSelectorDrawableColor((Drawable) object, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                                } else if (object instanceof GradientDrawable) {
                                    ((GradientDrawable) object).setColor(color);
                                } else {
                                    ((Drawable) object).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof CheckBox) {
                                if ((changeFlags & FLAG_CHECKBOX) != 0) {
                                    ((CheckBox) object).setBackgroundColor(color);
                                } else if ((changeFlags & FLAG_CHECKBOXCHECK) != 0) {
                                    ((CheckBox) object).setCheckColor(color);
                                }
                            } else if (object instanceof GroupCreateCheckBox) {
                                ((GroupCreateCheckBox) object).updateColors();
                            } else if (object instanceof Integer) {
                                field.set(child, color);
                            } else if (object instanceof RadioButton) {
                                if ((changeFlags & FLAG_CHECKBOX) != 0) {
                                    ((RadioButton) object).setBackgroundColor(color);
                                    ((RadioButton) object).invalidate();
                                } else if ((changeFlags & FLAG_CHECKBOXCHECK) != 0) {
                                    ((RadioButton) object).setCheckedColor(color);
                                    ((RadioButton) object).invalidate();
                                }
                            } else if (object instanceof TextPaint) {
                                if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    ((TextPaint) object).linkColor = color;
                                } else {
                                    ((TextPaint) object).setColor(color);
                                }
                            } else if (object instanceof LineProgressView) {
                                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                                    ((LineProgressView) object).setProgressColor(color);
                                } else {
                                    ((LineProgressView) object).setBackColor(color);
                                }
                            } else if (object instanceof RadialProgressView) {
                                ((RadialProgressView) object).setProgressColor(color);
                            } else if (object instanceof Paint) {
                                ((Paint) object).setColor(color);
                                child.invalidate();
                            } else if (object instanceof SeekBarView) {
                                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                                    ((SeekBarView) object).setOuterColor(color);
                                } else {
                                    ((SeekBarView) object).setInnerColor(color);
                                }
                            } else if (object instanceof AudioPlayerAlert.ClippingTextViewSwitcher) {
                                if ((changeFlags & FLAG_FASTSCROLL) != 0) {
                                    for (int k = 0; k < 2; k++) {
                                        TextView textView = k == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getNextTextView();
                                        if (textView != null) {
                                            CharSequence text = textView.getText();
                                            if (text instanceof SpannedString) {
                                                TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                                if (spans != null && spans.length > 0) {
                                                    for (int i = 0; i < spans.length; i++) {
                                                        spans[i].setColor(color);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
                                    if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, (View) object)) {
                                        for (int i = 0; i < 2; i++) {
                                            TextView textView = i == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getNextTextView();
                                            if (textView != null) {
                                                textView.setTextColor(color);
                                                CharSequence text = textView.getText();
                                                if (text instanceof SpannedString) {
                                                    TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                                    if (spans != null && spans.length > 0) {
                                                        for (int spanIdx = 0; spanIdx < spans.length; spanIdx++) {
                                                            spans[spanIdx].setColor(color);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Throwable e) {
                    FileLog.e(e);
                    notFoundCachedFields.put(key, true);
                }
            } else if (child instanceof GroupCreateSpan) {
                ((GroupCreateSpan) child).updateColors();
            }
        }
    }
}
Also used : SpannedString(android.text.SpannedString) RLottieImageView(org.telegram.ui.Components.RLottieImageView) AudioPlayerAlert(org.telegram.ui.Components.AudioPlayerAlert) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) SpannedString(android.text.SpannedString) StateListDrawable(android.graphics.drawable.StateListDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) Field(java.lang.reflect.Field) BackupImageView(org.telegram.ui.Components.BackupImageView) GroupCreateCheckBox(org.telegram.ui.Components.GroupCreateCheckBox) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) EditTextCaption(org.telegram.ui.Components.EditTextCaption) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) ScamDrawable(org.telegram.ui.Components.ScamDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) RadioButton(org.telegram.ui.Components.RadioButton) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) ContextProgressView(org.telegram.ui.Components.ContextProgressView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) VideoTimelineView(org.telegram.ui.Components.VideoTimelineView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) SeekBarView(org.telegram.ui.Components.SeekBarView) BackupImageView(org.telegram.ui.Components.BackupImageView) LineProgressView(org.telegram.ui.Components.LineProgressView) NumberTextView(org.telegram.ui.Components.NumberTextView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SeekBarView(org.telegram.ui.Components.SeekBarView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TextPaint(android.text.TextPaint) ColorDrawable(android.graphics.drawable.ColorDrawable) CheckBox(org.telegram.ui.Components.CheckBox) GroupCreateCheckBox(org.telegram.ui.Components.GroupCreateCheckBox) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) LineProgressView(org.telegram.ui.Components.LineProgressView) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan)

Aggregations

Paint (android.graphics.Paint)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 RippleDrawable (android.graphics.drawable.RippleDrawable)1 ShapeDrawable (android.graphics.drawable.ShapeDrawable)1 StateListDrawable (android.graphics.drawable.StateListDrawable)1 SpannedString (android.text.SpannedString)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 Field (java.lang.reflect.Field)1 AnimatedArrowDrawable (org.telegram.ui.Components.AnimatedArrowDrawable)1 AudioPlayerAlert (org.telegram.ui.Components.AudioPlayerAlert)1 AvatarDrawable (org.telegram.ui.Components.AvatarDrawable)1 BackupImageView (org.telegram.ui.Components.BackupImageView)1 ChatBigEmptyView (org.telegram.ui.Components.ChatBigEmptyView)1