Search in sources :

Example 1 with CombinedDrawable

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

the class SharingLiveLocationCell method setDialog.

public void setDialog(MessageObject messageObject, Location userLocation, boolean userLocationDenied) {
    long fromId = messageObject.getFromChatId();
    if (messageObject.isForwarded()) {
        fromId = MessageObject.getPeerId(messageObject.messageOwner.fwd_from.from_id);
    }
    currentAccount = messageObject.currentAccount;
    String address = null;
    String name;
    if (!TextUtils.isEmpty(messageObject.messageOwner.media.address)) {
        address = messageObject.messageOwner.media.address;
    }
    if (!TextUtils.isEmpty(messageObject.messageOwner.media.title)) {
        name = messageObject.messageOwner.media.title;
        Drawable drawable = getResources().getDrawable(R.drawable.pin);
        drawable.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_location_sendLocationIcon), PorterDuff.Mode.MULTIPLY));
        int color = getThemedColor(Theme.key_location_placeLocationBackground);
        Drawable circle = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(42), color, color);
        CombinedDrawable combinedDrawable = new CombinedDrawable(circle, drawable);
        combinedDrawable.setCustomSize(AndroidUtilities.dp(42), AndroidUtilities.dp(42));
        combinedDrawable.setIconSize(AndroidUtilities.dp(24), AndroidUtilities.dp(24));
        avatarImageView.setImageDrawable(combinedDrawable);
    } else {
        name = "";
        avatarDrawable = null;
        if (fromId > 0) {
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(fromId);
            if (user != null) {
                avatarDrawable = new AvatarDrawable(user);
                name = UserObject.getUserName(user);
                avatarImageView.setForUserOrChat(user, avatarDrawable);
            }
        } else {
            TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-fromId);
            if (chat != null) {
                avatarDrawable = new AvatarDrawable(chat);
                name = chat.title;
                avatarImageView.setForUserOrChat(chat, avatarDrawable);
            }
        }
    }
    nameTextView.setText(name);
    location.setLatitude(messageObject.messageOwner.media.geo.lat);
    location.setLongitude(messageObject.messageOwner.media.geo._long);
    if (userLocation != null) {
        float distance = location.distanceTo(userLocation);
        if (address != null) {
            distanceTextView.setText(String.format("%s - %s", address, LocaleController.formatDistance(distance, 0)));
        } else {
            distanceTextView.setText(LocaleController.formatDistance(distance, 0));
        }
    } else {
        if (address != null) {
            distanceTextView.setText(address);
        } else if (!userLocationDenied) {
            distanceTextView.setText(LocaleController.getString("Loading", R.string.Loading));
        } else {
            distanceTextView.setText("");
        }
    }
}
Also used : CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) GeoPoint(org.osmdroid.util.GeoPoint) TLRPC(org.telegram.tgnet.TLRPC)

Example 2 with CombinedDrawable

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

the class SessionCell method createDrawable.

public static Drawable createDrawable(TLRPC.TL_authorization session) {
    String platform = session.platform.toLowerCase();
    if (platform.isEmpty()) {
        platform = session.system_version.toLowerCase();
    }
    String deviceModel = session.device_model.toLowerCase();
    int iconId;
    String colorKey;
    if (deviceModel.contains("safari")) {
        iconId = R.drawable.device_web_safari;
        colorKey = Theme.key_avatar_backgroundPink;
    } else if (deviceModel.contains("edge")) {
        iconId = R.drawable.device_web_edge;
        colorKey = Theme.key_avatar_backgroundPink;
    } else if (deviceModel.contains("chrome")) {
        iconId = R.drawable.device_web_chrome;
        colorKey = Theme.key_avatar_backgroundPink;
    } else if (deviceModel.contains("opera")) {
        iconId = R.drawable.device_web_opera;
        colorKey = Theme.key_avatar_backgroundPink;
    } else if (deviceModel.contains("firefox")) {
        iconId = R.drawable.device_web_firefox;
        colorKey = Theme.key_avatar_backgroundPink;
    } else if (deviceModel.contains("vivaldi")) {
        iconId = R.drawable.device_web_other;
        colorKey = Theme.key_avatar_backgroundPink;
    } else if (platform.contains("ios")) {
        iconId = deviceModel.contains("ipad") ? R.drawable.device_tablet_ios : R.drawable.device_phone_ios;
        colorKey = Theme.key_avatar_backgroundBlue;
    } else if (platform.contains("windows")) {
        iconId = R.drawable.device_desktop_win;
        colorKey = Theme.key_avatar_backgroundCyan;
    } else if (platform.contains("macos")) {
        iconId = R.drawable.device_desktop_osx;
        colorKey = Theme.key_avatar_backgroundCyan;
    } else if (platform.contains("android")) {
        iconId = deviceModel.contains("tab") ? R.drawable.device_tablet_android : R.drawable.device_phone_android;
        colorKey = Theme.key_avatar_backgroundGreen;
    } else {
        if (session.app_name.toLowerCase().contains("desktop")) {
            iconId = R.drawable.device_desktop_other;
            colorKey = Theme.key_avatar_backgroundCyan;
        } else {
            iconId = R.drawable.device_web_other;
            colorKey = Theme.key_avatar_backgroundPink;
        }
    }
    Drawable iconDrawable = ContextCompat.getDrawable(ApplicationLoader.applicationContext, iconId).mutate();
    iconDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_avatar_text), PorterDuff.Mode.SRC_IN));
    CombinedDrawable combinedDrawable = new CombinedDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(42), Theme.getColor(colorKey)), iconDrawable);
    return combinedDrawable;
}
Also used : CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter)

Example 3 with CombinedDrawable

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

the class DialogsAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    View view;
    switch(viewType) {
        case 0:
            DialogCell dialogCell = new DialogCell(parentFragment, mContext, true, false, currentAccount, null);
            dialogCell.setArchivedPullAnimation(pullForegroundDrawable);
            dialogCell.setPreloader(preloader);
            view = dialogCell;
            break;
        case 1:
            FlickerLoadingView flickerLoadingView = new FlickerLoadingView(mContext);
            flickerLoadingView.setIsSingleCell(true);
            flickerLoadingView.setViewType(FlickerLoadingView.DIALOG_CELL_TYPE);
            view = flickerLoadingView;
            break;
        case 2:
            {
                HeaderCell headerCell = new HeaderCell(mContext);
                headerCell.setText(LocaleController.getString("RecentlyViewed", R.string.RecentlyViewed));
                TextView textView = new TextView(mContext);
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
                textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
                textView.setText(LocaleController.getString("RecentlyViewedHide", R.string.RecentlyViewedHide));
                textView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL);
                headerCell.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, 17, 15, 17, 0));
                textView.setOnClickListener(view1 -> {
                    MessagesController.getInstance(currentAccount).hintDialogs.clear();
                    SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                    preferences.edit().remove("installReferer").commit();
                    notifyDataSetChanged();
                });
                view = headerCell;
                break;
            }
        case 3:
            FrameLayout frameLayout = new FrameLayout(mContext) {

                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(12), MeasureSpec.EXACTLY));
                }
            };
            frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
            View v = new View(mContext);
            v.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            frameLayout.addView(v, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            view = frameLayout;
            break;
        case 4:
            view = new DialogMeUrlCell(mContext);
            break;
        case 5:
            view = new DialogsEmptyCell(mContext);
            break;
        case 6:
            view = new UserCell(mContext, 8, 0, false);
            break;
        case 7:
            view = new HeaderCell(mContext);
            break;
        case 8:
            {
                view = new ShadowSectionCell(mContext);
                Drawable drawable = Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
                CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
                combinedDrawable.setFullsize(true);
                view.setBackgroundDrawable(combinedDrawable);
                break;
            }
        case 9:
            archiveHintCell = new ArchiveHintCell(mContext);
            view = archiveHintCell;
            break;
        case 10:
            {
                view = new LastEmptyView(mContext);
                break;
            }
        case 11:
            {
                view = new TextInfoPrivacyCell(mContext) {

                    private int movement;

                    private float moveProgress;

                    private long lastUpdateTime;

                    private int originalX;

                    private int originalY;

                    @Override
                    protected void afterTextDraw() {
                        if (arrowDrawable != null) {
                            Rect bounds = arrowDrawable.getBounds();
                            arrowDrawable.setBounds(originalX, originalY, originalX + bounds.width(), originalY + bounds.height());
                        }
                    }

                    @Override
                    protected void onTextDraw() {
                        if (arrowDrawable != null) {
                            Rect bounds = arrowDrawable.getBounds();
                            int dx = (int) (moveProgress * AndroidUtilities.dp(3));
                            originalX = bounds.left;
                            originalY = bounds.top;
                            arrowDrawable.setBounds(originalX + dx, originalY + AndroidUtilities.dp(1), originalX + dx + bounds.width(), originalY + AndroidUtilities.dp(1) + bounds.height());
                            long newUpdateTime = SystemClock.elapsedRealtime();
                            long dt = newUpdateTime - lastUpdateTime;
                            if (dt > 17) {
                                dt = 17;
                            }
                            lastUpdateTime = newUpdateTime;
                            if (movement == 0) {
                                moveProgress += dt / 664.0f;
                                if (moveProgress >= 1.0f) {
                                    movement = 1;
                                    moveProgress = 1.0f;
                                }
                            } else {
                                moveProgress -= dt / 664.0f;
                                if (moveProgress <= 0.0f) {
                                    movement = 0;
                                    moveProgress = 0.0f;
                                }
                            }
                            getTextView().invalidate();
                        }
                    }
                };
                Drawable drawable = Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
                CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
                combinedDrawable.setFullsize(true);
                view.setBackgroundDrawable(combinedDrawable);
                break;
            }
        case 12:
        default:
            {
                view = new TextCell(mContext);
            }
    }
    view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, viewType == 5 ? RecyclerView.LayoutParams.MATCH_PARENT : RecyclerView.LayoutParams.WRAP_CONTENT));
    return new RecyclerListView.Holder(view);
}
Also used : ArchiveHintCell(org.telegram.ui.Cells.ArchiveHintCell) Rect(android.graphics.Rect) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) TextCell(org.telegram.ui.Cells.TextCell) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) DialogsActivity(org.telegram.ui.DialogsActivity) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) ViewPager(androidx.viewpager.widget.ViewPager) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) DialogMeUrlCell(org.telegram.ui.Cells.DialogMeUrlCell) TLObject(org.telegram.tgnet.TLObject) SharedConfig(org.telegram.messenger.SharedConfig) DialogsEmptyCell(org.telegram.ui.Cells.DialogsEmptyCell) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) DialogCell(org.telegram.ui.Cells.DialogCell) DialogObject(org.telegram.messenger.DialogObject) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) HeaderCell(org.telegram.ui.Cells.HeaderCell) TextCell(org.telegram.ui.Cells.TextCell) DialogCell(org.telegram.ui.Cells.DialogCell) DialogsEmptyCell(org.telegram.ui.Cells.DialogsEmptyCell) TextView(android.widget.TextView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) UserCell(org.telegram.ui.Cells.UserCell) Rect(android.graphics.Rect) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) SharedPreferences(android.content.SharedPreferences) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) DialogMeUrlCell(org.telegram.ui.Cells.DialogMeUrlCell) ColorDrawable(android.graphics.drawable.ColorDrawable) FrameLayout(android.widget.FrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ArchiveHintCell(org.telegram.ui.Cells.ArchiveHintCell) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 4 with CombinedDrawable

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

the class Theme method createCircleDrawableWithIcon.

public static CombinedDrawable createCircleDrawableWithIcon(int size, Drawable drawable, int stroke) {
    OvalShape ovalShape = new OvalShape();
    ovalShape.resize(size, size);
    ShapeDrawable defaultDrawable = new ShapeDrawable(ovalShape);
    Paint paint = defaultDrawable.getPaint();
    paint.setColor(0xffffffff);
    if (stroke == 1) {
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(AndroidUtilities.dp(2));
    } else if (stroke == 2) {
        paint.setAlpha(0);
    }
    CombinedDrawable combinedDrawable = new CombinedDrawable(defaultDrawable, drawable);
    combinedDrawable.setCustomSize(size, size);
    return combinedDrawable;
}
Also used : CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 5 with CombinedDrawable

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

the class ContactsAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view;
    switch(viewType) {
        case 0:
            view = new UserCell(mContext, 58, 1, false);
            break;
        case 1:
            view = new TextCell(mContext);
            break;
        case 2:
            view = new GraySectionCell(mContext);
            break;
        case 3:
            view = new DividerCell(mContext);
            view.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 28 : 72), AndroidUtilities.dp(8), AndroidUtilities.dp(LocaleController.isRTL ? 72 : 28), AndroidUtilities.dp(8));
            break;
        case 4:
            FrameLayout frameLayout = new FrameLayout(mContext) {

                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    int height;
                    height = MeasureSpec.getSize(heightMeasureSpec);
                    if (height == 0) {
                        height = parent.getMeasuredHeight();
                    }
                    if (height == 0) {
                        height = AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
                    }
                    int cellHeight = AndroidUtilities.dp(50);
                    int totalHeight = onlyUsers != 0 ? 0 : cellHeight + AndroidUtilities.dp(30);
                    if (hasGps) {
                        totalHeight += cellHeight;
                    }
                    if (!isAdmin && !needPhonebook) {
                        totalHeight += cellHeight;
                    }
                    if (totalHeight < height) {
                        height = height - totalHeight;
                    } else {
                        height = 0;
                    }
                    super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                }
            };
            ContactsEmptyView emptyView = new ContactsEmptyView(mContext);
            frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
            view = frameLayout;
            break;
        case 5:
        default:
            view = new ShadowSectionCell(mContext);
            Drawable drawable = Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
            CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
            combinedDrawable.setFullsize(true);
            view.setBackgroundDrawable(combinedDrawable);
            break;
    }
    return new RecyclerListView.Holder(view);
}
Also used : GraySectionCell(org.telegram.ui.Cells.GraySectionCell) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ContactsEmptyView(org.telegram.ui.Components.ContactsEmptyView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCell(org.telegram.ui.Cells.TextCell) DividerCell(org.telegram.ui.Cells.DividerCell) ColorDrawable(android.graphics.drawable.ColorDrawable) FrameLayout(android.widget.FrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) UserCell(org.telegram.ui.Cells.UserCell) ContactsEmptyView(org.telegram.ui.Components.ContactsEmptyView)

Aggregations

CombinedDrawable (org.telegram.ui.Components.CombinedDrawable)29 Drawable (android.graphics.drawable.Drawable)26 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)21 View (android.view.View)20 RecyclerListView (org.telegram.ui.Components.RecyclerListView)18 ImageView (android.widget.ImageView)16 RecyclerView (androidx.recyclerview.widget.RecyclerView)16 ActionBar (org.telegram.ui.ActionBar.ActionBar)16 ViewGroup (android.view.ViewGroup)15 FrameLayout (android.widget.FrameLayout)15 TLRPC (org.telegram.tgnet.TLRPC)15 Paint (android.graphics.Paint)14 TextView (android.widget.TextView)14 SuppressLint (android.annotation.SuppressLint)12 Context (android.content.Context)12 Outline (android.graphics.Outline)12 Build (android.os.Build)12 ViewOutlineProvider (android.view.ViewOutlineProvider)12 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)12 ArrayList (java.util.ArrayList)12