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("");
}
}
}
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;
}
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);
}
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;
}
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);
}
Aggregations