Java Code Examples for org.telegram.ui.ActionBar.Theme#getColor()

The following examples show how to use org.telegram.ui.ActionBar.Theme#getColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollSlidingTextTabStrip.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void setAnimationProgressInernal(TextView newTab, TextView prevTab, float value) {
    int newColor = Theme.getColor(Theme.key_actionBarDefaultTitle);
    int prevColor = Theme.getColor(Theme.key_actionBarDefaultSubtitle);

    int r1 = Color.red(newColor);
    int g1 = Color.green(newColor);
    int b1 = Color.blue(newColor);
    int a1 = Color.alpha(newColor);
    int r2 = Color.red(prevColor);
    int g2 = Color.green(prevColor);
    int b2 = Color.blue(prevColor);
    int a2 = Color.alpha(prevColor);

    prevTab.setTextColor(Color.argb((int) (a1 + (a2 - a1) * value), (int) (r1 + (r2 - r1) * value), (int) (g1 + (g2 - g1) * value), (int) (b1 + (b2 - b1) * value)));
    newTab.setTextColor(Color.argb((int) (a2 + (a1 - a2) * value), (int) (r2 + (r1 - r2) * value), (int) (g2 + (g1 - g2) * value), (int) (b2 + (b1 - b2) * value)));

    indicatorX = (int) (animateIndicatorStartX + (animateIndicatorToX - animateIndicatorStartX) * value);
    indicatorWidth = (int) (animateIndicatorStartWidth + (animateIndicatorToWidth - animateIndicatorStartWidth) * value);
    invalidate();
}
 
Example 2
Source File: ScrollSlidingTextTabStrip.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void setAnimationProgressInernal(TextView newTab, TextView prevTab, float value) {
    int newColor = Theme.getColor(Theme.key_actionBarDefaultTitle);
    int prevColor = Theme.getColor(Theme.key_actionBarDefaultSubtitle);

    int r1 = Color.red(newColor);
    int g1 = Color.green(newColor);
    int b1 = Color.blue(newColor);
    int a1 = Color.alpha(newColor);
    int r2 = Color.red(prevColor);
    int g2 = Color.green(prevColor);
    int b2 = Color.blue(prevColor);
    int a2 = Color.alpha(prevColor);

    prevTab.setTextColor(Color.argb((int) (a1 + (a2 - a1) * value), (int) (r1 + (r2 - r1) * value), (int) (g1 + (g2 - g1) * value), (int) (b1 + (b2 - b1) * value)));
    newTab.setTextColor(Color.argb((int) (a2 + (a1 - a2) * value), (int) (r2 + (r1 - r2) * value), (int) (g2 + (g1 - g2) * value), (int) (b2 + (b1 - b2) * value)));

    indicatorX = (int) (animateIndicatorStartX + (animateIndicatorToX - animateIndicatorStartX) * value);
    indicatorWidth = (int) (animateIndicatorStartWidth + (animateIndicatorToWidth - animateIndicatorStartWidth) * value);
    invalidate();
}
 
Example 3
Source File: FilterTabsView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setValue(FilterTabsView object, float value) {
    animationValue = value;

    int color1 = Theme.getColor(tabLineColorKey);
    int color2 = Theme.getColor(aTabLineColorKey);
    selectorDrawable.setColor(ColorUtils.blendARGB(color1, color2, value));

    if (aBackgroundColorKey != null) {
        color1 = Theme.getColor(backgroundColorKey);
        color2 = Theme.getColor(aBackgroundColorKey);
        object.setBackgroundColor(ColorUtils.blendARGB(color1, color2, value));
    }

    listView.invalidateViews();
    listView.invalidate();
    object.invalidate();
}
 
Example 4
Source File: StatisticActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void recolorRecyclerItem(View child) {
    if (child instanceof ChartCell) {
        ((ChartCell) child).recolor();
    }

    if (child instanceof ShadowSectionCell) {
        Drawable shadowDrawable = Theme.getThemedDrawable(ApplicationLoader.applicationContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
        Drawable background = new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray));
        CombinedDrawable combinedDrawable = new CombinedDrawable(background, shadowDrawable, 0, 0);
        combinedDrawable.setFullsize(true);
        child.setBackground(combinedDrawable);
    }

    if (child instanceof OverviewCell) {
        ((OverviewCell) child).updateColors();
    }
}
 
Example 5
Source File: StatisticActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void recolor() {
    chartView.updateColors();
    chartView.invalidate();

    zoomedChartView.updateColors();
    zoomedChartView.invalidate();

    chartHeaderView.recolor();
    chartHeaderView.invalidate();

    if (data != null && data.chartData != null && data.chartData.lines != null && data.chartData.lines.size() > 1) {
        for (int i = 0; i < data.chartData.lines.size(); i++) {
            int color;
            if (data.chartData.lines.get(i).colorKey != null && Theme.hasThemeKey(data.chartData.lines.get(i).colorKey)) {
                color = Theme.getColor(data.chartData.lines.get(i).colorKey);
            } else {
                boolean darkBackground = ColorUtils.calculateLuminance(Theme.getColor(Theme.key_windowBackgroundWhite)) < 0.5f;
                color = darkBackground ? data.chartData.lines.get(i).colorDark :
                        data.chartData.lines.get(i).color;
            }
            if (i < checkBoxes.size()) {
                checkBoxes.get(i).recolor(color);
            }
        }
    }
    progressView.setProgressColor(Theme.getColor(Theme.key_progressCircle));
    errorTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray4));
}
 
Example 6
Source File: BotHelpCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    int x = (getWidth() - width) / 2;
    int y = AndroidUtilities.dp(2);
    Drawable shadowDrawable = Theme.chat_msgInMediaDrawable.getShadowDrawable();
    if (shadowDrawable != null) {
        shadowDrawable.setBounds(x, y, width + x, height + y);
        shadowDrawable.draw(canvas);
    }
    int h = AndroidUtilities.displaySize.y;
    if (getParent() instanceof View) {
        View view = (View) getParent();
        h = view.getMeasuredHeight();
    }
    Theme.chat_msgInMediaDrawable.setTop((int) getY(), h, false, false);
    Theme.chat_msgInMediaDrawable.setBounds(x, y, width + x, height + y);
    Theme.chat_msgInMediaDrawable.draw(canvas);
    Theme.chat_msgTextPaint.setColor(Theme.getColor(Theme.key_chat_messageTextIn));
    Theme.chat_msgTextPaint.linkColor = Theme.getColor(Theme.key_chat_messageLinkIn);
    canvas.save();
    canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y);
    if (pressedLink != null) {
        canvas.drawPath(urlPath, Theme.chat_urlPaint);
    }
    if (textLayout != null) {
        textLayout.draw(canvas);
    }
    canvas.restore();
    wasDraw = true;
}
 
Example 7
Source File: SendLocationCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    LocationController.SharingLocationInfo currentInfo = LocationController.getInstance(currentAccount).getSharingLocationInfo(dialogId);
    if (currentInfo == null) {
        return;
    }
    int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    if (currentInfo.stopTime < currentTime) {
        return;
    }

    float progress = Math.abs(currentInfo.stopTime - currentTime) / (float) currentInfo.period;
    if (LocaleController.isRTL) {
        rect.set(AndroidUtilities.dp(13), AndroidUtilities.dp(18), AndroidUtilities.dp(43), AndroidUtilities.dp(48));
    } else {
        rect.set(getMeasuredWidth() - AndroidUtilities.dp(43), AndroidUtilities.dp(18), getMeasuredWidth() - AndroidUtilities.dp(13), AndroidUtilities.dp(48));
    }

    int color = Theme.getColor(Theme.key_location_liveLocationProgress);
    Theme.chat_radialProgress2Paint.setColor(color);
    Theme.chat_livePaint.setColor(color);

    canvas.drawArc(rect, -90, -360 * progress, false, Theme.chat_radialProgress2Paint);

    String text = LocaleController.formatLocationLeftTime(Math.abs(currentInfo.stopTime - currentTime));

    float size = Theme.chat_livePaint.measureText(text);

    canvas.drawText(text, rect.centerX() - size / 2, AndroidUtilities.dp(37), Theme.chat_livePaint);
}
 
Example 8
Source File: RadialProgressView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public RadialProgressView(Context context) {
    super(context);

    size = AndroidUtilities.dp(40);

    progressColor = Theme.getColor(Theme.key_progressCircle);
    decelerateInterpolator = new DecelerateInterpolator();
    accelerateInterpolator = new AccelerateInterpolator();
    progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    progressPaint.setStyle(Paint.Style.STROKE);
    progressPaint.setStrokeCap(Paint.Cap.ROUND);
    progressPaint.setStrokeWidth(AndroidUtilities.dp(3));
    progressPaint.setColor(progressColor);
}
 
Example 9
Source File: RadialProgressView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public RadialProgressView(Context context) {
    super(context);

    size = AndroidUtilities.dp(40);

    progressColor = Theme.getColor(Theme.key_progressCircle);
    decelerateInterpolator = new DecelerateInterpolator();
    accelerateInterpolator = new AccelerateInterpolator();
    progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    progressPaint.setStyle(Paint.Style.STROKE);
    progressPaint.setStrokeCap(Paint.Cap.ROUND);
    progressPaint.setStrokeWidth(AndroidUtilities.dp(3));
    progressPaint.setColor(progressColor);
}
 
Example 10
Source File: TextSelectionHint.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public TextSelectionHint(Context context) {
    super(context);
    int textColor = Theme.getColor(Theme.key_undo_infoColor);
    int alpha = Color.alpha(textColor);
    textPaint.setTextSize(AndroidUtilities.dp(15));
    textPaint.setColor(textColor);
    selectionPaint.setColor(textColor);
    selectionPaint.setAlpha((int) (alpha * 0.14));
    setBackground(Theme.createRoundRectDrawable(AndroidUtilities.dp(6), Theme.getColor(Theme.key_undo_background)));
}
 
Example 11
Source File: ChatListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    int color = Theme.getColor(Theme.key_switchTrack);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    button.setColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_radioBackgroundChecked));

    rect.set(AndroidUtilities.dp(1), AndroidUtilities.dp(1), getMeasuredWidth() - AndroidUtilities.dp(1), AndroidUtilities.dp(73));
    Theme.chat_instantViewRectPaint.setColor(Color.argb((int) (43 * button.getProgress()), r, g, b));
    canvas.drawRoundRect(rect, AndroidUtilities.dp(6), AndroidUtilities.dp(6), Theme.chat_instantViewRectPaint);

    rect.set(0, 0, getMeasuredWidth(), AndroidUtilities.dp(74));
    Theme.dialogs_onlineCirclePaint.setColor(Color.argb((int) (31 * (1.0f - button.getProgress())), r, g, b));
    canvas.drawRoundRect(rect, AndroidUtilities.dp(6), AndroidUtilities.dp(6), Theme.dialogs_onlineCirclePaint);

    String text = isThreeLines ? LocaleController.getString("ChatListExpanded", R.string.ChatListExpanded) : LocaleController.getString("ChatListDefault", R.string.ChatListDefault);
    int width = (int) Math.ceil(textPaint.measureText(text));

    textPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    canvas.drawText(text, (getMeasuredWidth() - width) / 2, AndroidUtilities.dp(96), textPaint);

    for (int a = 0; a < 2; a++) {
        int cy = AndroidUtilities.dp(a == 0 ? 21 : 53);
        Theme.dialogs_onlineCirclePaint.setColor(Color.argb(a == 0 ? 204 : 90, r, g, b));
        canvas.drawCircle(AndroidUtilities.dp(22), cy, AndroidUtilities.dp(11), Theme.dialogs_onlineCirclePaint);

        for (int i = 0; i < (isThreeLines ? 3 : 2); i++) {
            Theme.dialogs_onlineCirclePaint.setColor(Color.argb(i == 0 ? 204 : 90, r, g, b));
            if (isThreeLines) {
                rect.set(AndroidUtilities.dp(41), cy - AndroidUtilities.dp(8.3f - i * 7), getMeasuredWidth() - AndroidUtilities.dp(i == 0 ? 72 : 48), cy - AndroidUtilities.dp(8.3f - 3 - i * 7));
                canvas.drawRoundRect(rect, AndroidUtilities.dpf2(1.5f), AndroidUtilities.dpf2(1.5f), Theme.dialogs_onlineCirclePaint);
            } else {
                rect.set(AndroidUtilities.dp(41), cy - AndroidUtilities.dp(7 - i * 10), getMeasuredWidth() - AndroidUtilities.dp(i == 0 ? 72 : 48), cy - AndroidUtilities.dp(7 - 4 - i * 10));
                canvas.drawRoundRect(rect, AndroidUtilities.dp(2), AndroidUtilities.dp(2), Theme.dialogs_onlineCirclePaint);
            }
        }
    }
}
 
Example 12
Source File: Bulletin.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public UndoButton(@NonNull Context context) {
    super(context);

    final int undoCancelColor = Theme.getColor(Theme.key_undo_cancelColor);

    final ImageView undoImageView = new ImageView(getContext());
    undoImageView.setOnClickListener(v -> undo());
    undoImageView.setImageResource(R.drawable.chats_undo);
    undoImageView.setColorFilter(new PorterDuffColorFilter(undoCancelColor, PorterDuff.Mode.MULTIPLY));
    undoImageView.setBackground(Theme.createSelectorDrawable((undoCancelColor & 0x00ffffff) | 0x19000000));
    ViewHelper.setPaddingRelative(undoImageView, 0, 12, 0, 12);
    addView(undoImageView, LayoutHelper.createFrameRelatively(56, 48, Gravity.CENTER_VERTICAL));
}
 
Example 13
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Keep
public void setAnimationProgress(float progress)
{
    animationProgress = progress;
    listView.setAlpha(progress);

    listView.setTranslationX(AndroidUtilities.dp(48) - AndroidUtilities.dp(48) * progress);
    int color = AvatarDrawable.getProfileBackColorForId(user_id != 0 || ChatObject.isChannel(chat_id, currentAccount) && !currentChat.megagroup ? 5 : chat_id);

    int actionBarColor = Theme.getColor(Theme.key_actionBarDefault);
    int r = Color.red(actionBarColor);
    int g = Color.green(actionBarColor);
    int b = Color.blue(actionBarColor);
    int a;

    int rD = (int) ((Color.red(color) - r) * progress);
    int gD = (int) ((Color.green(color) - g) * progress);
    int bD = (int) ((Color.blue(color) - b) * progress);
    int aD;
    topView.setBackgroundColor(Color.rgb(r + rD, g + gD, b + bD));

    color = AvatarDrawable.getIconColorForId(user_id != 0 || ChatObject.isChannel(chat_id, currentAccount) && !currentChat.megagroup ? 5 : chat_id);
    int iconColor = Theme.getColor(Theme.key_actionBarDefaultIcon);
    r = Color.red(iconColor);
    g = Color.green(iconColor);
    b = Color.blue(iconColor);

    rD = (int) ((Color.red(color) - r) * progress);
    gD = (int) ((Color.green(color) - g) * progress);
    bD = (int) ((Color.blue(color) - b) * progress);
    actionBar.setItemsColor(Color.rgb(r + rD, g + gD, b + bD), false);

    color = Theme.getColor(Theme.key_profile_title);
    int titleColor = Theme.getColor(Theme.key_actionBarDefaultTitle);
    r = Color.red(titleColor);
    g = Color.green(titleColor);
    b = Color.blue(titleColor);
    a = Color.alpha(titleColor);

    rD = (int) ((Color.red(color) - r) * progress);
    gD = (int) ((Color.green(color) - g) * progress);
    bD = (int) ((Color.blue(color) - b) * progress);
    aD = (int) ((Color.alpha(color) - a) * progress);
    for (int i = 0; i < 2; i++)
    {
        if (nameTextView[i] == null)
        {
            continue;
        }
        nameTextView[i].setTextColor(Color.argb(a + aD, r + rD, g + gD, b + bD));
    }

    color = AvatarDrawable.getProfileTextColorForId(user_id != 0 || ChatObject.isChannel(chat_id, currentAccount) && !currentChat.megagroup ? 5 : chat_id);
    int subtitleColor = Theme.getColor(Theme.key_actionBarDefaultSubtitle);
    r = Color.red(subtitleColor);
    g = Color.green(subtitleColor);
    b = Color.blue(subtitleColor);
    a = Color.alpha(subtitleColor);

    rD = (int) ((Color.red(color) - r) * progress);
    gD = (int) ((Color.green(color) - g) * progress);
    bD = (int) ((Color.blue(color) - b) * progress);
    aD = (int) ((Color.alpha(color) - a) * progress);
    for (int i = 0; i < 2; i++)
    {
        if (onlineTextView[i] == null)
        {
            continue;
        }
        onlineTextView[i].setTextColor(Color.argb(a + aD, r + rD, g + gD, b + bD));
    }
    extraHeight = (int) (initialAnimationExtraHeight * progress);
    color = AvatarDrawable.getProfileColorForId(user_id != 0 ? user_id : chat_id);
    int color2 = AvatarDrawable.getColorForId(user_id != 0 ? user_id : chat_id);
    if (color != color2)
    {
        rD = (int) ((Color.red(color) - Color.red(color2)) * progress);
        gD = (int) ((Color.green(color) - Color.green(color2)) * progress);
        bD = (int) ((Color.blue(color) - Color.blue(color2)) * progress);
        avatarDrawable.setColor(Color.rgb(Color.red(color2) + rD, Color.green(color2) + gD, Color.blue(color2) + bD));
        avatarImage.invalidate();
    }

    needLayout();
}
 
Example 14
Source File: FragmentContextView.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void checkLocationString() {
    if (!(fragment instanceof ChatActivity) || titleTextView == null) {
        return;
    }
    ChatActivity chatActivity = (ChatActivity) fragment;
    long dialogId = chatActivity.getDialogId();
    int currentAccount = chatActivity.getCurrentAccount();
    ArrayList<TLRPC.Message> messages = LocationController.getInstance(currentAccount).locationsCache.get(dialogId);
    if (!firstLocationsLoaded) {
        LocationController.getInstance(currentAccount).loadLiveLocations(dialogId);
        firstLocationsLoaded = true;
    }

    int locationSharingCount = 0;
    TLRPC.User notYouUser = null;
    if (messages != null) {
        int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
        int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (int a = 0; a < messages.size(); a++) {
            TLRPC.Message message = messages.get(a);
            if (message.media == null) {
                continue;
            }
            if (message.date + message.media.period > date) {
                if (notYouUser == null && message.from_id != currentUserId) {
                    notYouUser = MessagesController.getInstance(currentAccount).getUser(message.from_id);
                }
                locationSharingCount++;
            }
        }
    }
    if (lastLocationSharingCount == locationSharingCount) {
        return;
    }
    lastLocationSharingCount = locationSharingCount;

    String liveLocation = LocaleController.getString("LiveLocationContext", R.string.LiveLocationContext);
    String fullString;
    if (locationSharingCount == 0) {
        fullString = liveLocation;
    } else {
        int otherSharingCount = locationSharingCount - 1;
        if (LocationController.getInstance(currentAccount).isSharingLocation(dialogId)) {
            if (otherSharingCount != 0) {
                if (otherSharingCount == 1 && notYouUser != null) {
                    fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.formatString("SharingYouAndOtherName", R.string.SharingYouAndOtherName, UserObject.getFirstName(notYouUser)));
                } else {
                    fullString = String.format("%1$s - %2$s %3$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName), LocaleController.formatPluralString("AndOther", otherSharingCount));
                }
            } else {
                fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName));
            }
        } else {
            if (otherSharingCount != 0) {
                fullString = String.format("%1$s - %2$s %3$s", liveLocation, UserObject.getFirstName(notYouUser), LocaleController.formatPluralString("AndOther", otherSharingCount));
            } else {
                fullString = String.format("%1$s - %2$s", liveLocation, UserObject.getFirstName(notYouUser));
            }
        }
    }
    if (fullString.equals(lastString)) {
        return;
    }
    lastString = fullString;
    int start = fullString.indexOf(liveLocation);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
    titleTextView.setEllipsize(TextUtils.TruncateAt.END);
    if (start >= 0) {
        TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, Theme.getColor(Theme.key_inappPlayerPerformer));
        stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    }
    titleTextView.setText(stringBuilder);
}
 
Example 15
Source File: AvatarDrawable.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static int getProfileBackColorForId(int id) {
    return Theme.getColor(Theme.keys_avatar_backgroundActionBar[getColorIndex(id)]);
}
 
Example 16
Source File: AvatarDrawable.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static int getProfileColorForId(int id) {
    return Theme.getColor(Theme.keys_avatar_backgroundInProfile[getColorIndex(id)]);
}
 
Example 17
Source File: SharingLiveLocationCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (currentInfo == null && liveLocation == null) {
        return;
    }
    int stopTime;
    int period;
    if (currentInfo != null) {
        stopTime = currentInfo.stopTime;
        period = currentInfo.period;
    } else {
        stopTime = liveLocation.object.date + liveLocation.object.media.period;
        period = liveLocation.object.media.period;
    }
    int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    if (stopTime < currentTime) {
        return;
    }
    float progress = Math.abs(stopTime - currentTime) / (float) period;
    if (LocaleController.isRTL) {
        rect.set(AndroidUtilities.dp(13), AndroidUtilities.dp(distanceTextView != null ? 18 : 12), AndroidUtilities.dp(43), AndroidUtilities.dp(distanceTextView != null ? 48 : 42));
    } else {
        rect.set(getMeasuredWidth() - AndroidUtilities.dp(43), AndroidUtilities.dp(distanceTextView != null ? 18 : 12), getMeasuredWidth() - AndroidUtilities.dp(13), AndroidUtilities.dp(distanceTextView != null ? 48 : 42));
    }

    int color;
    if (distanceTextView == null) {
        color = Theme.getColor(Theme.key_dialog_liveLocationProgress);
    } else {
        color = Theme.getColor(Theme.key_location_liveLocationProgress);
    }
    Theme.chat_radialProgress2Paint.setColor(color);
    Theme.chat_livePaint.setColor(color);

    canvas.drawArc(rect, -90, -360 * progress, false, Theme.chat_radialProgress2Paint);

    String text = LocaleController.formatLocationLeftTime(stopTime - currentTime);

    float size = Theme.chat_livePaint.measureText(text);

    canvas.drawText(text, rect.centerX() - size / 2, AndroidUtilities.dp(distanceTextView != null ? 37 : 31), Theme.chat_livePaint);
}
 
Example 18
Source File: FragmentContextView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void checkLocationString()
{
    if (!(fragment instanceof ChatActivity) || titleTextView == null)
    {
        return;
    }
    ChatActivity chatActivity = (ChatActivity) fragment;
    long dialogId = chatActivity.getDialogId();
    int currentAccount = chatActivity.getCurrentAccount();
    ArrayList<TLRPC.Message> messages = LocationController.getInstance(currentAccount).locationsCache.get(dialogId);
    if (!firstLocationsLoaded)
    {
        LocationController.getInstance(currentAccount).loadLiveLocations(dialogId);
        firstLocationsLoaded = true;
    }

    int locationSharingCount = 0;
    TLRPC.User notYouUser = null;
    if (messages != null)
    {
        int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
        int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (int a = 0; a < messages.size(); a++)
        {
            TLRPC.Message message = messages.get(a);
            if (message.media == null)
            {
                continue;
            }
            if (message.date + message.media.period > date)
            {
                if (notYouUser == null && message.from_id != currentUserId)
                {
                    notYouUser = MessagesController.getInstance(currentAccount).getUser(message.from_id);
                }
                locationSharingCount++;
            }
        }
    }
    if (lastLocationSharingCount == locationSharingCount)
    {
        return;
    }
    lastLocationSharingCount = locationSharingCount;

    String liveLocation = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation);
    String fullString;
    if (locationSharingCount == 0)
    {
        fullString = liveLocation;
    }
    else
    {
        int otherSharingCount = locationSharingCount - 1;
        if (LocationController.getInstance(currentAccount).isSharingLocation(dialogId))
        {
            if (otherSharingCount != 0)
            {
                if (otherSharingCount == 1 && notYouUser != null)
                {
                    fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.formatString("SharingYouAndOtherName", R.string.SharingYouAndOtherName, UserObject.getFirstName(notYouUser)));
                }
                else
                {
                    fullString = String.format("%1$s - %2$s %3$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName), LocaleController.formatPluralString("AndOther", otherSharingCount));
                }
            }
            else
            {
                fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName));
            }
        }
        else
        {
            if (otherSharingCount != 0)
            {
                fullString = String.format("%1$s - %2$s %3$s", liveLocation, UserObject.getFirstName(notYouUser), LocaleController.formatPluralString("AndOther", otherSharingCount));
            }
            else
            {
                fullString = String.format("%1$s - %2$s", liveLocation, UserObject.getFirstName(notYouUser));
            }
        }
    }
    if (lastString != null && fullString.equals(lastString))
    {
        return;
    }
    lastString = fullString;
    int start = fullString.indexOf(liveLocation);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
    titleTextView.setEllipsize(TextUtils.TruncateAt.END);
    if (start >= 0)
    {
        TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, Theme.getColor(Theme.key_inappPlayerPerformer));
        stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    }
    titleTextView.setText(stringBuilder);
}
 
Example 19
Source File: UserCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public UserCell(Context context, int padding, int checkbox, boolean admin)
{
    super(context);

    statusColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText);
    statusOnlineColor = Theme.getColor(Theme.key_windowBackgroundWhiteBlueText);

    avatarDrawable = new AvatarDrawable();

    avatarImageView = new BackupImageView(context);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(24));
    addView(avatarImageView, LayoutHelper.createFrame(48, 48, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 7 + padding, 8, LocaleController.isRTL ? 7 + padding : 0, 0));

    nameTextView = new SimpleTextView(context);
    nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameTextView.setTextSize(17);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 + (checkbox == 2 ? 18 : 0) : (68 + padding), 11.5f, LocaleController.isRTL ? (68 + padding) : 28 + (checkbox == 2 ? 18 : 0), 0));

    statusTextView = new SimpleTextView(context);
    statusTextView.setTextSize(14);
    statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(statusTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 : (68 + padding), 34.5f, LocaleController.isRTL ? (68 + padding) : 28, 0));

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteGrayIcon), PorterDuff.Mode.MULTIPLY));
    imageView.setVisibility(GONE);
    addView(imageView, LayoutHelper.createFrame(LayoutParams.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL,
            LocaleController.isRTL ? 0 : 16, 0, LocaleController.isRTL ? 16 : 0, 0));

    if (checkbox == 2)
    {
        checkBoxBig = new CheckBoxSquare(context, false);
        addView(checkBoxBig, LayoutHelper.createFrame(18, 18, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 19 : 0, 0, LocaleController.isRTL ? 0 : 19, 0));
    }
    else if (checkbox == 1)
    {
        checkBox = new CheckBox(context, R.drawable.round_check2);
        checkBox.setVisibility(INVISIBLE);
        checkBox.setColor(Theme.getColor(Theme.key_checkbox), Theme.getColor(Theme.key_checkboxCheck));
        addView(checkBox, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 37 + padding, 38, LocaleController.isRTL ? 37 + padding : 0, 0));
    }

    if (admin)
    {
        adminImage = new ImageView(context);
        adminImage.setImageResource(R.drawable.admin_star);
        addView(adminImage, LayoutHelper.createFrame(16, 16,
                (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP,
                LocaleController.isRTL ? 24 : 0, 13.5f,
                LocaleController.isRTL ? 0 : 24, 0));

        adminText = new TextView(context);
        adminText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        adminText.setTextSize(12);
        adminText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
        addView(adminText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 20,
                (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP,
                LocaleController.isRTL ? 24 : 0, 34.5f,
                LocaleController.isRTL ? 0 : 24, 0));
    }
}
 
Example 20
Source File: UserCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public UserCell(Context context, int padding, int checkbox, boolean admin, boolean needAddButton) {
    super(context);

    int additionalPadding;
    if (needAddButton) {
        addButton = new TextView(context);
        addButton.setGravity(Gravity.CENTER);
        addButton.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
        addButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        addButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        addButton.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
        addButton.setText(LocaleController.getString("Add", R.string.Add));
        addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0);
        addView(addButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 28, Gravity.TOP | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT), LocaleController.isRTL ? 14 : 0, 15, LocaleController.isRTL ? 0 : 14, 0));
        additionalPadding = (int) Math.ceil((addButton.getPaint().measureText(addButton.getText().toString()) + AndroidUtilities.dp(34 + 14)) / AndroidUtilities.density);
    } else {
        additionalPadding = 0;
    }

    statusColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText);
    statusOnlineColor = Theme.getColor(Theme.key_windowBackgroundWhiteBlueText);

    avatarDrawable = new AvatarDrawable();

    avatarImageView = new BackupImageView(context);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(24));
    addView(avatarImageView, LayoutHelper.createFrame(46, 46, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 7 + padding, 6, LocaleController.isRTL ? 7 + padding : 0, 0));

    nameTextView = new SimpleTextView(context);
    nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    nameTextView.setTextSize(16);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 + (checkbox == 2 ? 18 : 0) + additionalPadding : (64 + padding), 10, LocaleController.isRTL ? (64 + padding) : 28 + (checkbox == 2 ? 18 : 0) + additionalPadding, 0));

    statusTextView = new SimpleTextView(context);
    statusTextView.setTextSize(15);
    statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(statusTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 + additionalPadding : (64 + padding), 32, LocaleController.isRTL ? (64 + padding) : 28 + additionalPadding, 0));

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteGrayIcon), PorterDuff.Mode.MULTIPLY));
    imageView.setVisibility(GONE);
    addView(imageView, LayoutHelper.createFrame(LayoutParams.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 0 : 16, 0, LocaleController.isRTL ? 16 : 0, 0));

    if (checkbox == 2) {
        checkBoxBig = new CheckBoxSquare(context, false);
        addView(checkBoxBig, LayoutHelper.createFrame(18, 18, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 19 : 0, 0, LocaleController.isRTL ? 0 : 19, 0));
    } else if (checkbox == 1) {
        checkBox = new CheckBox(context, R.drawable.round_check2);
        checkBox.setVisibility(INVISIBLE);
        checkBox.setColor(Theme.getColor(Theme.key_checkbox), Theme.getColor(Theme.key_checkboxCheck));
        addView(checkBox, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 37 + padding, 40, LocaleController.isRTL ? 37 + padding : 0, 0));
    }

    if (admin) {
        adminTextView = new TextView(context);
        adminTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        adminTextView.setTextColor(Theme.getColor(Theme.key_profile_creatorIcon));
        addView(adminTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, LocaleController.isRTL ? 23 : 0, 10, LocaleController.isRTL ? 0 : 23, 0));
    }

    setFocusable(true);
}