mirror of https://github.com/NekoX-Dev/NekoX.git
132 lines
5.4 KiB
Java
132 lines
5.4 KiB
Java
/*
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
*
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
|
*/
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
import android.animation.Animator;
|
|
import android.animation.ObjectAnimator;
|
|
import android.content.Context;
|
|
import android.graphics.Canvas;
|
|
import android.text.TextUtils;
|
|
import android.util.TypedValue;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.TextView;
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
import org.telegram.messenger.LocaleController;
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
import org.telegram.ui.Components.RadioButton;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class RadioCell extends FrameLayout {
|
|
|
|
private Theme.ResourcesProvider resourcesProvider;
|
|
private TextView textView;
|
|
private RadioButton radioButton;
|
|
private boolean needDivider;
|
|
|
|
public RadioCell(Context context) {
|
|
this(context, false, 21);
|
|
}
|
|
|
|
public RadioCell(Context context, Theme.ResourcesProvider resourcesProvider) {
|
|
this(context, false, 21, resourcesProvider);
|
|
}
|
|
|
|
public RadioCell(Context context, boolean dialog, int padding) {
|
|
this(context, dialog, padding, null);
|
|
}
|
|
|
|
public RadioCell(Context context, boolean dialog, int padding, Theme.ResourcesProvider resourcesProvider) {
|
|
super(context);
|
|
this.resourcesProvider = resourcesProvider;
|
|
|
|
textView = new TextView(context);
|
|
if (dialog) {
|
|
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack, resourcesProvider));
|
|
} else {
|
|
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText, resourcesProvider));
|
|
}
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
textView.setLines(1);
|
|
textView.setMaxLines(1);
|
|
textView.setSingleLine(true);
|
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
|
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
|
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, padding, 0, padding, 0));
|
|
|
|
radioButton = new RadioButton(context);
|
|
radioButton.setSize(AndroidUtilities.dp(20));
|
|
if (dialog) {
|
|
radioButton.setColor(Theme.getColor(Theme.key_dialogRadioBackground, resourcesProvider), Theme.getColor(Theme.key_dialogRadioBackgroundChecked, resourcesProvider));
|
|
} else {
|
|
radioButton.setColor(Theme.getColor(Theme.key_radioBackground, resourcesProvider), Theme.getColor(Theme.key_radioBackgroundChecked, resourcesProvider));
|
|
}
|
|
addView(radioButton, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, (LocaleController.isRTL ? padding + 1 : 0), 14, (LocaleController.isRTL ? 0 : padding + 1), 0));
|
|
}
|
|
|
|
@Override
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(50) + (needDivider ? 1 : 0));
|
|
|
|
int availableWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - AndroidUtilities.dp(34);
|
|
radioButton.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(22), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(22), MeasureSpec.EXACTLY));
|
|
textView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
|
|
}
|
|
|
|
public void setTextColor(int color) {
|
|
textView.setTextColor(color);
|
|
}
|
|
|
|
public void setText(String text, boolean checked, boolean divider) {
|
|
textView.setText(text);
|
|
radioButton.setChecked(checked, false);
|
|
needDivider = divider;
|
|
setWillNotDraw(!divider);
|
|
}
|
|
|
|
public boolean isChecked() {
|
|
return radioButton.isChecked();
|
|
}
|
|
|
|
public void setChecked(boolean checked, boolean animated) {
|
|
radioButton.setChecked(checked, animated);
|
|
}
|
|
|
|
public void setEnabled(boolean value, ArrayList<Animator> animators) {
|
|
super.setEnabled(value);
|
|
if (animators != null) {
|
|
animators.add(ObjectAnimator.ofFloat(textView, View.ALPHA, value ? 1.0f : 0.5f));
|
|
animators.add(ObjectAnimator.ofFloat(radioButton, View.ALPHA, value ? 1.0f : 0.5f));
|
|
} else {
|
|
textView.setAlpha(value ? 1.0f : 0.5f);
|
|
radioButton.setAlpha(value ? 1.0f : 0.5f);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDraw(Canvas canvas) {
|
|
if (needDivider) {
|
|
canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(20), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
|
|
super.onInitializeAccessibilityNodeInfo(info);
|
|
info.setClassName("android.widget.RadioButton");
|
|
info.setCheckable(true);
|
|
info.setChecked(isChecked());
|
|
}
|
|
}
|