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

111 lines
4.2 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;
2019-05-14 14:08:05 +02:00
import android.view.accessibility.AccessibilityNodeInfo;
2014-11-11 23:16:17 +01:00
import android.widget.FrameLayout;
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
2019-01-23 18:03:33 +01: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;
2014-11-11 23:16:17 +01:00
public class HeaderCell extends FrameLayout {
private TextView textView;
2019-01-23 18:03:33 +01:00
private SimpleTextView textView2;
private int height = 40;
2014-11-11 23:16:17 +01:00
2015-05-21 23:27:27 +02:00
public HeaderCell(Context context) {
2019-01-23 18:03:33 +01:00
this(context, false, 21, 15, false);
}
public HeaderCell(Context context, int padding) {
this(context, false, padding, 15, false);
}
public HeaderCell(Context context, boolean dialog, int padding, int topMargin, boolean text2) {
2015-05-21 23:27:27 +02:00
super(context);
2014-11-11 23:16:17 +01:00
textView = new TextView(getContext());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
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);
2019-05-14 14:08:05 +02:00
textView.setMinHeight(AndroidUtilities.dp(height - topMargin));
2019-01-23 18:03:33 +01:00
if (dialog) {
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
} else {
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
}
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, padding, topMargin, padding, 0));
if (text2) {
textView2 = new SimpleTextView(getContext());
textView2.setTextSize(13);
textView2.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);
addView(textView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, padding, 21, padding, 0));
}
2014-11-11 23:16:17 +01:00
}
2019-01-23 18:03:33 +01:00
public void setHeight(int value) {
2019-09-10 12:56:11 +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) {
animators.add(ObjectAnimator.ofFloat(textView, "alpha", value ? 1.0f : 0.5f));
} 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
}
public void setText(String text) {
textView.setText(text);
}
2019-01-23 18:03:33 +01:00
public void setText2(String text) {
if (textView2 == null) {
return;
}
textView2.setText(text);
}
public SimpleTextView getTextView2() {
return textView2;
}
2019-05-14 14:08:05 +02:00
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AccessibilityNodeInfo.CollectionItemInfo collection = info.getCollectionItemInfo();
if (collection != null) {
info.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain(collection.getRowIndex(), collection.getRowSpan(), collection.getColumnIndex(), collection.getColumnSpan(), true));
}
}
}
2014-11-11 23:16:17 +01:00
}