Search in sources :

Example 6 with TypefaceSpan

use of org.telegram.ui.Components.TypefaceSpan 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)

Example 7 with TypefaceSpan

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

the class AndroidUtilities method replaceTags.

public static SpannableStringBuilder replaceTags(String str, int flag, Object... args) {
    try {
        int start;
        int end;
        StringBuilder stringBuilder = new StringBuilder(str);
        if ((flag & FLAG_TAG_BR) != 0) {
            while ((start = stringBuilder.indexOf("<br>")) != -1) {
                stringBuilder.replace(start, start + 4, "\n");
            }
            while ((start = stringBuilder.indexOf("<br/>")) != -1) {
                stringBuilder.replace(start, start + 5, "\n");
            }
        }
        ArrayList<Integer> bolds = new ArrayList<>();
        if ((flag & FLAG_TAG_BOLD) != 0) {
            while ((start = stringBuilder.indexOf("<b>")) != -1) {
                stringBuilder.replace(start, start + 3, "");
                end = stringBuilder.indexOf("</b>");
                if (end == -1) {
                    end = stringBuilder.indexOf("<b>");
                }
                stringBuilder.replace(end, end + 4, "");
                bolds.add(start);
                bolds.add(end);
            }
            while ((start = stringBuilder.indexOf("**")) != -1) {
                stringBuilder.replace(start, start + 2, "");
                end = stringBuilder.indexOf("**");
                if (end >= 0) {
                    stringBuilder.replace(end, end + 2, "");
                    bolds.add(start);
                    bolds.add(end);
                }
            }
        }
        if ((flag & FLAG_TAG_URL) != 0) {
            while ((start = stringBuilder.indexOf("**")) != -1) {
                stringBuilder.replace(start, start + 2, "");
                end = stringBuilder.indexOf("**");
                if (end >= 0) {
                    stringBuilder.replace(end, end + 2, "");
                    bolds.add(start);
                    bolds.add(end);
                }
            }
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
        for (int a = 0; a < bolds.size() / 2; a++) {
            spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableStringBuilder;
    } catch (Exception e) {
        FileLog.e(e);
    }
    return new SpannableStringBuilder(str);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) SpannableStringBuilder(android.text.SpannableStringBuilder) IOException(java.io.IOException) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan)

Example 8 with TypefaceSpan

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

the class CameraScanActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setItemsColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarWhiteSelector), false);
    actionBar.setCastShadows(false);
    if (!AndroidUtilities.isTablet() && !isQr()) {
        actionBar.showActionModeTop();
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    paint.setColor(0x7f000000);
    cornerPaint.setColor(0xffffffff);
    cornerPaint.setStyle(Paint.Style.STROKE);
    cornerPaint.setStrokeWidth(AndroidUtilities.dp(4));
    cornerPaint.setStrokeJoin(Paint.Join.ROUND);
    ViewGroup viewGroup = new ViewGroup(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);
            actionBar.measure(widthMeasureSpec, heightMeasureSpec);
            if (currentType == TYPE_MRZ) {
                cameraView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (width * 0.704f), MeasureSpec.EXACTLY));
            } else {
                cameraView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                recognizedMrzView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                if (galleryButton != null) {
                    galleryButton.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
                }
                flashButton.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
            }
            titleTextView.measure(MeasureSpec.makeMeasureSpec(width - AndroidUtilities.dp(72), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
            descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.9f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
            setMeasuredDimension(width, height);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            int width = r - l;
            int height = b - t;
            int y = 0;
            if (currentType == TYPE_MRZ) {
                cameraView.layout(0, y, cameraView.getMeasuredWidth(), y + cameraView.getMeasuredHeight());
                y = (int) (height * 0.65f);
                titleTextView.layout(AndroidUtilities.dp(36), y, AndroidUtilities.dp(36) + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
                recognizedMrzView.setTextSize(TypedValue.COMPLEX_UNIT_PX, cameraView.getMeasuredHeight() / 22);
                recognizedMrzView.setPadding(0, 0, 0, cameraView.getMeasuredHeight() / 15);
            } else {
                actionBar.layout(0, 0, actionBar.getMeasuredWidth(), actionBar.getMeasuredHeight());
                cameraView.layout(0, 0, cameraView.getMeasuredWidth(), cameraView.getMeasuredHeight());
                int size = (int) (Math.min(cameraView.getWidth(), cameraView.getHeight()) / 1.5f);
                if (currentType == TYPE_QR) {
                    y = (cameraView.getMeasuredHeight() - size) / 2 - titleTextView.getMeasuredHeight() - AndroidUtilities.dp(30);
                } else {
                    y = (cameraView.getMeasuredHeight() - size) / 2 - titleTextView.getMeasuredHeight() - AndroidUtilities.dp(64);
                }
                titleTextView.layout(AndroidUtilities.dp(36), y, AndroidUtilities.dp(36) + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
                recognizedMrzView.layout(0, getMeasuredHeight() - recognizedMrzView.getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight());
                int x;
                if (needGalleryButton) {
                    x = cameraView.getMeasuredWidth() / 2 + AndroidUtilities.dp(35);
                } else {
                    x = cameraView.getMeasuredWidth() / 2 - flashButton.getMeasuredWidth() / 2;
                }
                y = (cameraView.getMeasuredHeight() - size) / 2 + size + AndroidUtilities.dp(30);
                flashButton.layout(x, y, x + flashButton.getMeasuredWidth(), y + flashButton.getMeasuredHeight());
                if (galleryButton != null) {
                    x = cameraView.getMeasuredWidth() / 2 - AndroidUtilities.dp(35) - galleryButton.getMeasuredWidth();
                    galleryButton.layout(x, y, x + galleryButton.getMeasuredWidth(), y + galleryButton.getMeasuredHeight());
                }
            }
            y = (int) (height * 0.74f);
            int x = (int) (width * 0.05f);
            descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (isQr() && child == cameraView) {
                int size = (int) (Math.min(child.getWidth(), child.getHeight()) / 1.5f);
                int x = (child.getWidth() - size) / 2;
                int y = (child.getHeight() - size) / 2;
                canvas.drawRect(0, 0, child.getMeasuredWidth(), y, paint);
                canvas.drawRect(0, y + size, child.getMeasuredWidth(), child.getMeasuredHeight(), paint);
                canvas.drawRect(0, y, x, y + size, paint);
                canvas.drawRect(x + size, y, child.getMeasuredWidth(), y + size, paint);
                path.reset();
                path.moveTo(x, y + AndroidUtilities.dp(20));
                path.lineTo(x, y);
                path.lineTo(x + AndroidUtilities.dp(20), y);
                canvas.drawPath(path, cornerPaint);
                path.reset();
                path.moveTo(x + size, y + AndroidUtilities.dp(20));
                path.lineTo(x + size, y);
                path.lineTo(x + size - AndroidUtilities.dp(20), y);
                canvas.drawPath(path, cornerPaint);
                path.reset();
                path.moveTo(x, y + size - AndroidUtilities.dp(20));
                path.lineTo(x, y + size);
                path.lineTo(x + AndroidUtilities.dp(20), y + size);
                canvas.drawPath(path, cornerPaint);
                path.reset();
                path.moveTo(x + size, y + size - AndroidUtilities.dp(20));
                path.lineTo(x + size, y + size);
                path.lineTo(x + size - AndroidUtilities.dp(20), y + size);
                canvas.drawPath(path, cornerPaint);
            }
            return result;
        }
    };
    viewGroup.setOnTouchListener((v, event) -> true);
    fragmentView = viewGroup;
    cameraView = new CameraView(context, false);
    cameraView.setUseMaxPreview(true);
    cameraView.setOptimizeForBarcode(true);
    cameraView.setDelegate(new CameraView.CameraViewDelegate() {

        @Override
        public void onCameraCreated(Camera camera) {
        }

        @Override
        public void onCameraInit() {
            startRecognizing();
        }
    });
    viewGroup.addView(cameraView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    if (currentType == TYPE_MRZ) {
        actionBar.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    } else {
        actionBar.setBackgroundDrawable(null);
        actionBar.setAddToContainer(false);
        actionBar.setItemsColor(0xffffffff, false);
        actionBar.setItemsBackgroundColor(0x22ffffff, false);
        viewGroup.setBackgroundColor(Theme.getColor(Theme.key_wallet_blackBackground));
        viewGroup.addView(actionBar);
    }
    if (currentType == TYPE_QR_LOGIN) {
        actionBar.setTitle(LocaleController.getString("AuthAnotherClientScan", R.string.AuthAnotherClientScan));
    }
    Paint selectionPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    selectionPaint.setColor(ColorUtils.setAlphaComponent(Color.WHITE, 100));
    titleTextView = new TextView(context) {

        LinkPath textPath;

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            if (getText() instanceof Spanned) {
                Spanned spanned = (Spanned) getText();
                URLSpanNoUnderline[] innerSpans = spanned.getSpans(0, spanned.length(), URLSpanNoUnderline.class);
                if (innerSpans != null && innerSpans.length > 0) {
                    textPath = new LinkPath(true);
                    textPath.setAllowReset(false);
                    for (int a = 0; a < innerSpans.length; a++) {
                        int start = spanned.getSpanStart(innerSpans[a]);
                        int end = spanned.getSpanEnd(innerSpans[a]);
                        textPath.setCurrentLayout(getLayout(), start, 0);
                        int shift = getText() != null ? getPaint().baselineShift : 0;
                        textPath.setBaselineShift(shift != 0 ? shift + AndroidUtilities.dp(shift > 0 ? 5 : -2) : 0);
                        getLayout().getSelectionPath(start, end, textPath);
                    }
                    textPath.setAllowReset(true);
                }
            }
        }

        @Override
        protected void onDraw(Canvas canvas) {
            if (textPath != null) {
                canvas.drawPath(textPath, selectionPaint);
            }
            super.onDraw(canvas);
        }
    };
    titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
    viewGroup.addView(titleTextView);
    descriptionText = new TextView(context);
    descriptionText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
    descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
    descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    viewGroup.addView(descriptionText);
    recognizedMrzView = new TextView(context);
    recognizedMrzView.setTextColor(0xffffffff);
    recognizedMrzView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    recognizedMrzView.setAlpha(0);
    if (currentType == TYPE_MRZ) {
        titleTextView.setText(LocaleController.getString("PassportScanPassport", R.string.PassportScanPassport));
        descriptionText.setText(LocaleController.getString("PassportScanPassportInfo", R.string.PassportScanPassportInfo));
        titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        recognizedMrzView.setTypeface(Typeface.MONOSPACE);
        cameraView.addView(recognizedMrzView);
    } else {
        if (needGalleryButton) {
        // titleTextView.setText(LocaleController.getString("WalletScanCode", R.string.WalletScanCode));
        } else {
            if (currentType == TYPE_QR) {
                titleTextView.setText(LocaleController.getString("AuthAnotherClientScan", R.string.AuthAnotherClientScan));
            } else {
                String text = LocaleController.getString("AuthAnotherClientInfo5", R.string.AuthAnotherClientInfo5);
                SpannableStringBuilder spanned = new SpannableStringBuilder(text);
                int index1 = text.indexOf('*');
                int index2 = text.indexOf('*', index1 + 1);
                if (index1 != -1 && index2 != -1 && index1 != index2) {
                    titleTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
                    spanned.replace(index2, index2 + 1, " ");
                    spanned.replace(index1, index1 + 1, " ");
                    index1 += 1;
                    index2 += 1;
                    spanned.setSpan(new URLSpanNoUnderline(LocaleController.getString("AuthAnotherClientDownloadClientUrl", R.string.AuthAnotherClientDownloadClientUrl)), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    spanned.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                text = spanned.toString();
                index1 = text.indexOf('*');
                index2 = text.indexOf('*', index1 + 1);
                if (index1 != -1 && index2 != -1 && index1 != index2) {
                    spanned.replace(index2, index2 + 1, " ");
                    spanned.replace(index1, index1 + 1, " ");
                    index1 += 1;
                    index2 += 1;
                    spanned.setSpan(new URLSpanNoUnderline(LocaleController.getString("AuthAnotherWebClientUrl", R.string.AuthAnotherWebClientUrl)), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    spanned.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                titleTextView.setLinkTextColor(Color.WHITE);
                titleTextView.setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkSelection));
                titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                titleTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
                titleTextView.setPadding(0, 0, 0, 0);
                titleTextView.setText(spanned);
            }
        }
        titleTextView.setTextColor(0xffffffff);
        recognizedMrzView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        recognizedMrzView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10));
        if (needGalleryButton) {
        // recognizedMrzView.setText(LocaleController.getString("WalletScanCodeNotFound", R.string.WalletScanCodeNotFound));
        } else {
            recognizedMrzView.setText(LocaleController.getString("AuthAnotherClientNotFound", R.string.AuthAnotherClientNotFound));
        }
        viewGroup.addView(recognizedMrzView);
        if (needGalleryButton) {
            galleryButton = new ImageView(context);
            galleryButton.setScaleType(ImageView.ScaleType.CENTER);
            galleryButton.setImageResource(R.drawable.qr_gallery);
            galleryButton.setBackgroundDrawable(Theme.createSelectorDrawableFromDrawables(Theme.createCircleDrawable(AndroidUtilities.dp(60), 0x22ffffff), Theme.createCircleDrawable(AndroidUtilities.dp(60), 0x44ffffff)));
            viewGroup.addView(galleryButton);
            galleryButton.setOnClickListener(currentImage -> {
                if (getParentActivity() == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 23) {
                    if (getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4);
                        return;
                    }
                }
                PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(PhotoAlbumPickerActivity.SELECT_TYPE_QR, false, false, null);
                fragment.setMaxSelectedPhotos(1, false);
                fragment.setAllowSearchImages(false);
                fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {

                    @Override
                    public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate) {
                        try {
                            if (!photos.isEmpty()) {
                                SendMessagesHelper.SendingMediaInfo info = photos.get(0);
                                if (info.path != null) {
                                    Point screenSize = AndroidUtilities.getRealScreenSize();
                                    Bitmap bitmap = ImageLoader.loadBitmap(info.path, null, screenSize.x, screenSize.y, true);
                                    String text = tryReadQr(null, null, 0, 0, 0, bitmap);
                                    if (text != null) {
                                        if (delegate != null) {
                                            delegate.didFindQr(text);
                                        }
                                        removeSelfFromStack();
                                    }
                                }
                            }
                        } catch (Throwable e) {
                            FileLog.e(e);
                        }
                    }

                    @Override
                    public void startPhotoSelectActivity() {
                        try {
                            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                            photoPickerIntent.setType("image/*");
                            getParentActivity().startActivityForResult(photoPickerIntent, 11);
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    }
                });
                presentFragment(fragment);
            });
        }
        flashButton = new ImageView(context);
        flashButton.setScaleType(ImageView.ScaleType.CENTER);
        flashButton.setImageResource(R.drawable.qr_flashlight);
        flashButton.setBackgroundDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(60), 0x22ffffff));
        viewGroup.addView(flashButton);
        flashButton.setOnClickListener(currentImage -> {
            CameraSession session = cameraView.getCameraSession();
            if (session != null) {
                ShapeDrawable shapeDrawable = (ShapeDrawable) flashButton.getBackground();
                if (flashAnimator != null) {
                    flashAnimator.cancel();
                    flashAnimator = null;
                }
                flashAnimator = new AnimatorSet();
                ObjectAnimator animator = ObjectAnimator.ofInt(shapeDrawable, AnimationProperties.SHAPE_DRAWABLE_ALPHA, flashButton.getTag() == null ? 0x44 : 0x22);
                animator.addUpdateListener(animation -> flashButton.invalidate());
                flashAnimator.playTogether(animator);
                flashAnimator.setDuration(200);
                flashAnimator.setInterpolator(CubicBezierInterpolator.DEFAULT);
                flashAnimator.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        flashAnimator = null;
                    }
                });
                flashAnimator.start();
                if (flashButton.getTag() == null) {
                    flashButton.setTag(1);
                    session.setTorchEnabled(true);
                } else {
                    flashButton.setTag(null);
                    session.setTorchEnabled(false);
                }
            }
        });
    }
    if (getParentActivity() != null) {
        getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    fragmentView.setKeepScreenOn(true);
    return fragmentView;
}
Also used : AnimatorSet(android.animation.AnimatorSet) Bitmap(android.graphics.Bitmap) BinaryBitmap(com.google.zxing.BinaryBitmap) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) LinkPath(org.telegram.ui.Components.LinkPath) CameraSession(org.telegram.messenger.camera.CameraSession) TextView(android.widget.TextView) Camera(android.hardware.Camera) ImageView(android.widget.ImageView) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) ActionBar(org.telegram.ui.ActionBar.ActionBar) ViewGroup(android.view.ViewGroup) ObjectAnimator(android.animation.ObjectAnimator) Canvas(android.graphics.Canvas) Intent(android.content.Intent) Paint(android.graphics.Paint) Point(android.graphics.Point) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CameraView(org.telegram.messenger.camera.CameraView) Spanned(android.text.Spanned) Paint(android.graphics.Paint) Point(android.graphics.Point) CameraView(org.telegram.messenger.camera.CameraView) NotFoundException(com.google.zxing.NotFoundException) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ShapeDrawable(android.graphics.drawable.ShapeDrawable) SpannableStringBuilder(android.text.SpannableStringBuilder) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan)

Example 9 with TypefaceSpan

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

the class GroupCreateActivity method onDonePressed.

private boolean onDonePressed(boolean alert) {
    if (selectedContacts.size() == 0 && chatType != ChatObject.CHAT_TYPE_CHANNEL) {
        return false;
    }
    if (alert && addToGroup) {
        if (getParentActivity() == null) {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        if (selectedContacts.size() == 1) {
            builder.setTitle(LocaleController.getString("AddOneMemberAlertTitle", R.string.AddOneMemberAlertTitle));
        } else {
            builder.setTitle(LocaleController.formatString("AddMembersAlertTitle", R.string.AddMembersAlertTitle, LocaleController.formatPluralString("Members", selectedContacts.size())));
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int a = 0; a < selectedContacts.size(); a++) {
            long uid = selectedContacts.keyAt(a);
            TLRPC.User user = getMessagesController().getUser(uid);
            if (user == null) {
                continue;
            }
            if (stringBuilder.length() > 0) {
                stringBuilder.append(", ");
            }
            stringBuilder.append("**").append(ContactsController.formatName(user.first_name, user.last_name)).append("**");
        }
        TLRPC.Chat chat = getMessagesController().getChat(chatId != 0 ? chatId : channelId);
        if (selectedContacts.size() > 5) {
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(AndroidUtilities.replaceTags(LocaleController.formatString("AddMembersAlertNamesText", R.string.AddMembersAlertNamesText, LocaleController.formatPluralString("Members", selectedContacts.size()), chat == null ? "" : chat.title)));
            String countString = String.format("%d", selectedContacts.size());
            int index = TextUtils.indexOf(spannableStringBuilder, countString);
            if (index >= 0) {
                spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), index, index + countString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            builder.setMessage(spannableStringBuilder);
        } else {
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AddMembersAlertNamesText", R.string.AddMembersAlertNamesText, stringBuilder, chat == null ? "" : chat.title)));
        }
        CheckBoxCell[] cells = new CheckBoxCell[1];
        if (!ChatObject.isChannel(chat)) {
            LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            cells[0] = new CheckBoxCell(getParentActivity(), 1);
            cells[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
            cells[0].setMultiline(true);
            if (selectedContacts.size() == 1) {
                TLRPC.User user = getMessagesController().getUser(selectedContacts.keyAt(0));
                cells[0].setText(AndroidUtilities.replaceTags(LocaleController.formatString("AddOneMemberForwardMessages", R.string.AddOneMemberForwardMessages, UserObject.getFirstName(user))), "", true, false);
            } else {
                cells[0].setText(LocaleController.getString("AddMembersForwardMessages", R.string.AddMembersForwardMessages), "", true, false);
            }
            cells[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
            linearLayout.addView(cells[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            cells[0].setOnClickListener(v -> cells[0].setChecked(!cells[0].isChecked(), true));
            builder.setCustomViewOffset(12);
            builder.setView(linearLayout);
        }
        builder.setPositiveButton(LocaleController.getString("Add", R.string.Add), (dialogInterface, i) -> onAddToGroupDone(cells[0] != null && cells[0].isChecked() ? 100 : 0));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        showDialog(builder.create());
    } else {
        if (chatType == ChatObject.CHAT_TYPE_CHANNEL) {
            ArrayList<TLRPC.InputUser> result = new ArrayList<>();
            for (int a = 0; a < selectedContacts.size(); a++) {
                TLRPC.InputUser user = getMessagesController().getInputUser(getMessagesController().getUser(selectedContacts.keyAt(a)));
                if (user != null) {
                    result.add(user);
                }
            }
            getMessagesController().addUsersToChannel(chatId, result, null);
            getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
            Bundle args2 = new Bundle();
            args2.putLong("chat_id", chatId);
            presentFragment(new ChatActivity(args2), true);
        } else {
            if (!doneButtonVisible || selectedContacts.size() == 0) {
                return false;
            }
            if (addToGroup) {
                onAddToGroupDone(0);
            } else {
                ArrayList<Long> result = new ArrayList<>();
                for (int a = 0; a < selectedContacts.size(); a++) {
                    result.add(selectedContacts.keyAt(a));
                }
                if (isAlwaysShare || isNeverShare) {
                    if (delegate != null) {
                        delegate.didSelectUsers(result);
                    }
                    finishFragment();
                } else {
                    Bundle args = new Bundle();
                    long[] array = new long[result.size()];
                    for (int a = 0; a < array.length; a++) {
                        array[a] = result.get(a);
                    }
                    args.putLongArray("result", array);
                    args.putInt("chatType", chatType);
                    args.putBoolean("forImport", forImport);
                    presentFragment(new GroupCreateFinalActivity(args));
                }
            }
        }
    }
    return true;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) Bundle(android.os.Bundle) SuppressLint(android.annotation.SuppressLint) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan)

Example 10 with TypefaceSpan

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

the class GroupCallActivity method updateSubtitle.

private void updateSubtitle() {
    if (actionBar == null || call == null) {
        return;
    }
    SpannableStringBuilder spannableStringBuilder = null;
    int speakingIndex = 0;
    for (int i = 0; i < call.currentSpeakingPeers.size(); i++) {
        long key = call.currentSpeakingPeers.keyAt(i);
        TLRPC.TL_groupCallParticipant participant = call.currentSpeakingPeers.get(key);
        if (participant.self || renderersContainer.isVisible(participant) || visiblePeerIds.get(key, 0) == 1) {
            continue;
        }
        long peerId = MessageObject.getPeerId(participant.peer);
        if (spannableStringBuilder == null) {
            spannableStringBuilder = new SpannableStringBuilder();
        }
        if (speakingIndex < 2) {
            TLRPC.User user = peerId > 0 ? MessagesController.getInstance(currentAccount).getUser(peerId) : null;
            TLRPC.Chat chat = peerId <= 0 ? MessagesController.getInstance(currentAccount).getChat(peerId) : null;
            if (user == null && chat == null) {
                continue;
            }
            if (speakingIndex != 0) {
                spannableStringBuilder.append(", ");
            }
            if (user != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    spannableStringBuilder.append(UserObject.getFirstName(user), new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0);
                } else {
                    spannableStringBuilder.append(UserObject.getFirstName(user));
                }
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    spannableStringBuilder.append(chat.title, new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0);
                } else {
                    spannableStringBuilder.append(chat.title);
                }
            }
        }
        speakingIndex++;
        if (speakingIndex == 2) {
            break;
        }
    }
    boolean drawStatus;
    if (speakingIndex > 0) {
        String s = LocaleController.getPluralString("MembersAreSpeakingToast", speakingIndex);
        int replaceIndex = s.indexOf("un1");
        SpannableStringBuilder spannableStringBuilder1 = new SpannableStringBuilder(s);
        spannableStringBuilder1.replace(replaceIndex, replaceIndex + 3, spannableStringBuilder);
        actionBar.getAdditionalSubtitleTextView().setText(spannableStringBuilder1);
        drawStatus = true;
    } else {
        drawStatus = false;
    }
    actionBar.getSubtitleTextView().setText(LocaleController.formatPluralString("Participants", call.call.participants_count + (listAdapter.addSelfToCounter() ? 1 : 0)));
    if (drawStatus != drawSpeakingSubtitle) {
        drawSpeakingSubtitle = drawStatus;
        actionBar.invalidate();
        actionBar.getSubtitleTextView().setPivotX(0);
        actionBar.getSubtitleTextView().setPivotY(actionBar.getMeasuredHeight() >> 1);
        actionBar.getSubtitleTextView().animate().scaleX(drawSpeakingSubtitle ? 0.98f : 1f).scaleY(drawSpeakingSubtitle ? 0.9f : 1f).alpha(drawSpeakingSubtitle ? 0f : 1f).setDuration(150);
        AndroidUtilities.updateViewVisibilityAnimated(actionBar.getAdditionalSubtitleTextView(), drawSpeakingSubtitle);
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan)

Aggregations

TypefaceSpan (org.telegram.ui.Components.TypefaceSpan)14 SpannableStringBuilder (android.text.SpannableStringBuilder)13 SuppressLint (android.annotation.SuppressLint)10 Paint (android.graphics.Paint)9 TLRPC (org.telegram.tgnet.TLRPC)9 TextPaint (android.text.TextPaint)8 StaticLayout (android.text.StaticLayout)4 TLObject (org.telegram.tgnet.TLObject)4 TextStyleSpan (org.telegram.ui.Components.TextStyleSpan)4 Animator (android.animation.Animator)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 AnimatorSet (android.animation.AnimatorSet)3 ObjectAnimator (android.animation.ObjectAnimator)3 Bitmap (android.graphics.Bitmap)3 Canvas (android.graphics.Canvas)3 View (android.view.View)3 ArrayList (java.util.ArrayList)3 ValueAnimator (android.animation.ValueAnimator)2 Activity (android.app.Activity)2 Context (android.content.Context)2