That fuck shit the fascists are using
1package org.tm.archive.components;
2
3import android.content.Context;
4import android.content.res.TypedArray;
5import android.graphics.Color;
6import android.text.Editable;
7import android.text.TextUtils;
8import android.util.AttributeSet;
9import android.view.View;
10import android.view.ViewGroup;
11import android.widget.EditText;
12import android.widget.FrameLayout;
13import android.widget.TextView;
14
15import androidx.annotation.NonNull;
16import androidx.annotation.Nullable;
17
18import org.tm.archive.R;
19import org.tm.archive.util.ViewUtil;
20
21public class LabeledEditText extends FrameLayout implements View.OnFocusChangeListener {
22
23 private TextView label;
24 private EditText input;
25 private View border;
26 private ViewGroup textContainer;
27
28 public LabeledEditText(@NonNull Context context) {
29 super(context);
30 init(null);
31 }
32
33 public LabeledEditText(@NonNull Context context, @Nullable AttributeSet attrs) {
34 super(context, attrs);
35 init(attrs);
36 }
37
38 private void init(@Nullable AttributeSet attrs) {
39 inflate(getContext(), R.layout.labeled_edit_text, this);
40
41 String labelText = "";
42 int backgroundColor = Color.BLACK;
43 int textLayout = R.layout.labeled_edit_text_default;
44
45 if (attrs != null) {
46 TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.LabeledEditText, 0, 0);
47
48 labelText = typedArray.getString(R.styleable.LabeledEditText_labeledEditText_label);
49 backgroundColor = typedArray.getColor(R.styleable.LabeledEditText_labeledEditText_background, Color.BLACK);
50 textLayout = typedArray.getResourceId(R.styleable.LabeledEditText_labeledEditText_textLayout, R.layout.labeled_edit_text_default);
51
52 typedArray.recycle();
53 }
54
55 label = findViewById(R.id.label);
56 border = findViewById(R.id.border);
57 textContainer = findViewById(R.id.text_container);
58
59 inflate(getContext(), textLayout, textContainer);
60 input = findViewById(R.id.input);
61
62 label.setText(labelText);
63 label.setBackgroundColor(backgroundColor);
64
65 if (TextUtils.isEmpty(labelText)) {
66 label.setVisibility(INVISIBLE);
67 }
68
69 input.setOnFocusChangeListener(this);
70 }
71
72 public EditText getInput() {
73 return input;
74 }
75
76 public void setText(String text) {
77 input.setText(text);
78 }
79
80 public Editable getText() {
81 return input.getText();
82 }
83
84 @Override
85 public void onFocusChange(View v, boolean hasFocus) {
86 border.setBackgroundResource(hasFocus ? R.drawable.labeled_edit_text_background_active
87 : R.drawable.labeled_edit_text_background_inactive);
88 }
89
90 @Override
91 public void setEnabled(boolean enabled) {
92 super.setEnabled(enabled);
93 input.setEnabled(enabled);
94 }
95
96 public void focusAndMoveCursorToEndAndOpenKeyboard() {
97 ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(input);
98 }
99}