mirror of https://github.com/NekoX-Dev/NekoX.git
124 lines
4.8 KiB
Java
124 lines
4.8 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.content.Context;
|
|
import android.graphics.Canvas;
|
|
import android.util.TypedValue;
|
|
import android.view.Gravity;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import android.widget.LinearLayout;
|
|
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;
|
|
|
|
public class RadioButtonCell extends LinearLayout {
|
|
|
|
private LinearLayout textLayout;
|
|
private TextView textView;
|
|
private TextView valueTextView;
|
|
private RadioButton radioButton;
|
|
private boolean needDivider;
|
|
|
|
public RadioButtonCell(Context context) {
|
|
this(context, false);
|
|
}
|
|
|
|
public RadioButtonCell(Context context, boolean dialog) {
|
|
super(context);
|
|
|
|
setOrientation(LinearLayout.HORIZONTAL);
|
|
setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
textLayout = new LinearLayout(context);
|
|
textLayout.setOrientation(LinearLayout.VERTICAL);
|
|
textLayout.setGravity(Gravity.CENTER);
|
|
int padding = AndroidUtilities.dp(10);
|
|
textLayout.setPadding(AndroidUtilities.dp(24),padding,padding,padding);
|
|
addView(textLayout, new LinearLayout.LayoutParams(-1, -2) {{
|
|
weight = 1;
|
|
}});
|
|
|
|
textView = new TextView(context);
|
|
if (dialog) {
|
|
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
} else {
|
|
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
}
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
|
textLayout.addView(textView, LayoutHelper.createLinear(-2, -2, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 0, 0, 0, 5));
|
|
|
|
valueTextView = new TextView(context);
|
|
if (dialog) {
|
|
valueTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
|
|
} else {
|
|
valueTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
|
|
}
|
|
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
|
valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
|
|
valueTextView.setLines(0);
|
|
valueTextView.setMaxLines(0);
|
|
valueTextView.setSingleLine(false);
|
|
textLayout.addView(valueTextView, LayoutHelper.createLinear(-2, -2, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP));
|
|
|
|
radioButton = new RadioButton(context);
|
|
radioButton.setSize(AndroidUtilities.dp(20));
|
|
if (dialog) {
|
|
radioButton.setColor(Theme.getColor(Theme.key_dialogRadioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
} else {
|
|
radioButton.setColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_radioBackgroundChecked));
|
|
}
|
|
addView(radioButton, LayoutHelper.createLinear(22, 22, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL,0,0,21,0));
|
|
|
|
}
|
|
|
|
public void setTextAndValue(String text, boolean divider, boolean checked) {
|
|
textView.setText(text);
|
|
valueTextView.setVisibility(GONE);
|
|
radioButton.setChecked(checked, false);
|
|
needDivider = divider;
|
|
}
|
|
|
|
public void setTextAndValueAndCheck(String text, String value, boolean divider, boolean checked) {
|
|
textView.setText(text);
|
|
valueTextView.setText(value);
|
|
valueTextView.setVisibility(VISIBLE);
|
|
radioButton.setChecked(checked, false);
|
|
needDivider = divider;
|
|
}
|
|
|
|
public void setChecked(boolean checked, boolean animated) {
|
|
radioButton.setChecked(checked, animated);
|
|
}
|
|
|
|
public boolean isChecked() {
|
|
return radioButton.isChecked();
|
|
}
|
|
|
|
@Override
|
|
protected void onDraw(Canvas canvas) {
|
|
if (needDivider) {
|
|
canvas.drawLine(AndroidUtilities.dp(LocaleController.isRTL ? 0 : 60), getHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(LocaleController.isRTL ? 60 : 0), getHeight() - 1, Theme.dividerPaint);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
|
|
super.onInitializeAccessibilityNodeInfo(info);
|
|
info.setClassName("android.widget.RadioButton");
|
|
info.setCheckable(true);
|
|
info.setChecked(radioButton.isChecked());
|
|
}
|
|
}
|