NekoX/TMessagesProj/src/main/java/org/telegram/ui/Cells/HeaderCell.java

169 lines
6.4 KiB
Java
Raw Normal View History

2014-11-11 23:16:17 +01:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2014-11-11 23:16:17 +01:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2014-11-11 23:16:17 +01:00
*/
package org.telegram.ui.Cells;
2019-01-23 18:03:33 +01:00
import android.animation.Animator;
import android.animation.ObjectAnimator;
2014-11-11 23:16:17 +01:00
import android.content.Context;
2019-05-14 14:08:05 +02:00
import android.os.Build;
2019-01-23 18:03:33 +01:00
import android.text.TextUtils;
2014-11-11 23:16:17 +01:00
import android.util.TypedValue;
import android.view.Gravity;
2020-06-25 17:28:24 +02:00
import android.view.View;
import android.view.ViewGroup;
2022-06-30 13:16:32 +02:00
import android.view.View;
2019-05-14 14:08:05 +02:00
import android.view.accessibility.AccessibilityNodeInfo;
2020-06-25 17:28:24 +02:00
import android.widget.LinearLayout;
2014-11-11 23:16:17 +01:00
import android.widget.TextView;
2020-07-26 10:03:38 +02:00
import androidx.core.view.ViewCompat;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
2022-07-06 14:07:52 +02:00
import org.telegram.ui.ActionBar.SimpleTextView;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.LayoutHelper;
2014-11-11 23:16:17 +01:00
2019-01-23 18:03:33 +01:00
import java.util.ArrayList;
2020-06-25 17:28:24 +02:00
public class HeaderCell extends LinearLayout {
2014-11-11 23:16:17 +01:00
private TextView textView;
2020-06-25 17:28:24 +02:00
private TextView textView2;
2019-01-23 18:03:33 +01:00
private int height = 40;
2021-09-20 00:10:42 +02:00
private final Theme.ResourcesProvider resourcesProvider;
2014-11-11 23:16:17 +01:00
2015-05-21 23:27:27 +02:00
public HeaderCell(Context context) {
2022-07-06 14:07:52 +02:00
this(context, Theme.key_windowBackgroundWhiteBlueHeader, 21, 15, false, null);
2021-09-20 00:10:42 +02:00
}
public HeaderCell(Context context, Theme.ResourcesProvider resourcesProvider) {
2022-07-06 14:07:52 +02:00
this(context, Theme.key_windowBackgroundWhiteBlueHeader, 21, 15, false, resourcesProvider);
2019-01-23 18:03:33 +01:00
}
public HeaderCell(Context context, int padding) {
2022-07-06 14:07:52 +02:00
this(context, Theme.key_windowBackgroundWhiteBlueHeader, padding, 15, false, null);
2019-01-23 18:03:33 +01:00
}
2022-06-21 04:51:00 +02:00
public HeaderCell(Context context, int padding, Theme.ResourcesProvider resourcesProvider) {
this(context, Theme.key_windowBackgroundWhiteBlueHeader, padding, 15, false, resourcesProvider);
}
2020-03-30 14:00:09 +02:00
public HeaderCell(Context context, String textColorKey, int padding, int topMargin, boolean text2) {
2022-07-06 14:07:52 +02:00
this(context, textColorKey, padding, topMargin, text2, null);
2020-06-25 17:28:24 +02:00
}
2022-07-06 14:07:52 +02:00
public HeaderCell(Context context, String textColorKey, int padding, int topMargin, boolean text2, Theme.ResourcesProvider resourcesProvider) {
2022-06-21 04:51:00 +02:00
this(context, textColorKey, padding, topMargin, 0, text2, resourcesProvider);
}
public HeaderCell(Context context, String textColorKey, int padding, int topMargin, int bottomMargin, boolean text2, Theme.ResourcesProvider resourcesProvider) {
2015-05-21 23:27:27 +02:00
super(context);
2021-09-20 00:10:42 +02:00
this.resourcesProvider = resourcesProvider;
2015-05-21 23:27:27 +02:00
2014-11-11 23:16:17 +01:00
textView = new TextView(getContext());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
2022-07-06 14:07:52 +02:00
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2019-01-23 18:03:33 +01:00
textView.setEllipsize(TextUtils.TruncateAt.END);
2014-11-11 23:16:17 +01:00
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
2021-09-20 00:10:42 +02:00
textView.setTextColor(getThemedColor(textColorKey));
2020-03-30 14:00:09 +02:00
textView.setTag(textColorKey);
2022-06-21 04:51:00 +02:00
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, padding, topMargin, padding, text2 ? 0 : bottomMargin));
2019-01-23 18:03:33 +01:00
2020-06-25 17:28:24 +02:00
textView2 = new TextView(getContext());
textView2.setTextSize(13);
textView2.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
textView2.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
2022-06-30 13:16:32 +02:00
addView(textView2, LayoutHelper.createLinear(-2, -2, 0, 4, 0, bottomMargin));
2020-06-25 17:28:24 +02:00
if (!text2) textView2.setVisibility(View.GONE);
2020-07-26 10:03:38 +02:00
ViewCompat.setAccessibilityHeading(this, true);
2020-06-25 17:28:24 +02:00
}
2022-07-06 14:07:52 +02:00
// NekoX: BottomSheet BigTitle, move big title from constructor to here
public HeaderCell setBigTitle(boolean enabled) {
if (enabled) {
textView.setTypeface(AndroidUtilities.getTypeface("fonts/mw_bold.ttf"));
} else {
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
return this;
}
2020-06-25 17:28:24 +02:00
@Override
public void setLayoutParams(ViewGroup.LayoutParams params) {
params.width = -1;
super.setLayoutParams(params);
2014-11-11 23:16:17 +01:00
}
2019-01-23 18:03:33 +01:00
public void setHeight(int value) {
2022-07-06 14:33:37 +02:00
textView.setMinHeight(AndroidUtilities.dp(height = value) - ((LayoutParams) textView.getLayoutParams()).topMargin);
2019-01-23 18:03:33 +01:00
}
public void setEnabled(boolean value, ArrayList<Animator> animators) {
if (animators != null) {
2022-06-21 04:51:00 +02:00
animators.add(ObjectAnimator.ofFloat(textView, View.ALPHA, value ? 1.0f : 0.5f));
2019-01-23 18:03:33 +01:00
} else {
textView.setAlpha(value ? 1.0f : 0.5f);
}
2017-03-31 01:58:05 +02:00
}
2014-11-11 23:16:17 +01:00
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2019-05-14 14:08:05 +02:00
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
2014-11-11 23:16:17 +01:00
}
2022-04-16 16:43:17 +02:00
public void setTextSize(float dip) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, dip);
}
public void setTextColor(int color) {
textView.setTextColor(color);
}
2020-04-24 11:21:58 +02:00
public void setText(CharSequence text) {
2014-11-11 23:16:17 +01:00
textView.setText(text);
}
2019-01-23 18:03:33 +01:00
2020-04-24 11:21:58 +02:00
public void setText2(CharSequence text) {
2020-06-25 17:28:24 +02:00
if (textView2.getVisibility() != View.VISIBLE) {
textView2.setVisibility(View.VISIBLE);
2019-01-23 18:03:33 +01:00
}
textView2.setText(text);
}
2020-04-24 11:21:58 +02:00
public TextView getTextView() {
return textView;
}
2020-06-25 17:28:24 +02:00
public TextView getTextView2() {
2019-01-23 18:03:33 +01:00
return textView2;
}
2019-05-14 14:08:05 +02:00
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
2022-06-21 04:51:00 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
info.setHeading(true);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
2019-05-14 14:08:05 +02:00
AccessibilityNodeInfo.CollectionItemInfo collection = info.getCollectionItemInfo();
if (collection != null) {
info.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain(collection.getRowIndex(), collection.getRowSpan(), collection.getColumnIndex(), collection.getColumnSpan(), true));
}
}
2022-06-21 04:51:00 +02:00
info.setEnabled(true);
2019-05-14 14:08:05 +02:00
}
2021-09-20 00:10:42 +02:00
private int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key);
}
2014-11-11 23:16:17 +01:00
}