Replace edit text with text view

This commit is contained in:
PavelRatushny 2017-10-31 15:36:54 +02:00
parent ab6c6f0765
commit 704ab9d457
10 changed files with 935 additions and 158 deletions

View file

@ -43,7 +43,7 @@
android:focusable="true"
android:focusableInTouchMode="true"/>
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
android:id="@+id/latitude_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -52,16 +52,16 @@
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
<net.osmand.plus.widgets.CursorTextView
android:imeOptions="actionNext"
android:id="@+id/latitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
android:id="@+id/longitude_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -70,16 +70,16 @@
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
<net.osmand.plus.widgets.CursorTextView
android:imeOptions="actionNext"
android:id="@+id/longitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
android:id="@+id/name_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -88,7 +88,7 @@
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
<net.osmand.plus.widgets.CursorTextView
android:imeOptions="actionDone"
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
@ -96,7 +96,7 @@
android:hint="@string/access_hint_enter_name"
android:inputType="text"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
<ImageButton
android:id="@+id/options_button"

View file

@ -85,7 +85,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
android:id="@+id/latitude_box"
android:layout_width="0dp"
android:layout_weight="1"
@ -94,30 +94,30 @@
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
<net.osmand.plus.widgets.CursorTextView
android:imeOptions="actionNext"
android:inputType="number"
android:id="@+id/latitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
android:id="@+id/longitude_box"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
osmand:labelText="@string/navigate_point_longitude">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
<net.osmand.plus.widgets.CursorTextView
android:imeOptions="actionNext"
android:inputType="number"
android:id="@+id/longitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
</LinearLayout>
@ -127,7 +127,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
android:id="@+id/name_box"
android:layout_width="0dp"
android:layout_weight="1"
@ -136,7 +136,7 @@
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
<net.osmand.plus.widgets.CursorTextView
android:imeOptions="actionDone"
android:inputType="text"
android:hint="@string/access_hint_enter_name"
@ -144,7 +144,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
<View
android:layout_width="0dp"

View file

@ -11,7 +11,7 @@
android:focusable="true"
android:focusableInTouchMode="true"/>
<net.osmand.plus.OsmandTextFieldBoxes
<net.osmand.plus.widgets.OsmandEditTextFieldBoxes
android:id="@+id/name_text_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -26,6 +26,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.OsmandTextFieldBoxes>
</net.osmand.plus.widgets.OsmandEditTextFieldBoxes>
</LinearLayout>

View file

@ -1,81 +0,0 @@
package net.osmand.plus;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import studio.carbonylgroup.textfieldboxes.TextFieldBoxes;
public class OsmandTextFieldBoxes extends TextFieldBoxes {
private boolean useOsmandKeyboard;
public void setUseOsmandKeyboard(boolean useOsmandKeyboard) {
this.useOsmandKeyboard = useOsmandKeyboard;
}
public OsmandTextFieldBoxes(Context context) {
super(context);
}
public OsmandTextFieldBoxes(Context context, AttributeSet attrs) {
super(context, attrs);
}
public OsmandTextFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (editText != null) {
this.panel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
select();
}
});
this.iconImageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
select();
}
});
}
}
public void select() {
if(!OsmandTextFieldBoxes.this.isActivated()) {
OsmandTextFieldBoxes.this.activate(true);
}
OsmandTextFieldBoxes.this.setHasFocus(true);
if (!useOsmandKeyboard) {
OsmandTextFieldBoxes.this.inputMethodManager.showSoftInput(OsmandTextFieldBoxes.this.editText, InputMethodManager.SHOW_IMPLICIT);
}
}
@Override
public void activate(boolean animated) {
super.activate(animated);
}
@Override
public void deactivate() {
if(this.editText.getText().toString().isEmpty()) {
ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION);
this.editTextLayout.setVisibility(View.INVISIBLE);
if(this.editText.hasFocus()) {
if (!useOsmandKeyboard) {
this.inputMethodManager.hideSoftInputFromWindow(this.editText.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
this.editText.clearFocus();
}
}
this.activated = false;
}
}

View file

@ -49,7 +49,7 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandTextFieldBoxes;
import net.osmand.plus.widgets.OsmandTextViewFieldBoxes;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities;
@ -61,8 +61,6 @@ import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.List;
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
import static android.content.Context.CLIPBOARD_SERVICE;
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
@ -92,8 +90,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private boolean lightTheme;
private boolean useOsmandKeyboard = true;
private int coordinateFormat = -1;
private List<OsmandTextFieldBoxes> textFieldBoxes;
private List<ExtendedEditText> extendedEditTexts;
private List<OsmandTextViewFieldBoxes> textFieldBoxes;
private List<TextView> inputTextViews;
private View mainView;
private IconsCache iconsCache;
private Location location;
@ -168,7 +166,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
@Override
public void onClick(View view) {
View focusedView = getDialog().getCurrentFocus();
if (focusedView != null && focusedView instanceof ExtendedEditText) {
if (focusedView != null && focusedView instanceof TextView) {
focusedView.clearFocus();
AndroidUtils.hideSoftKeyboard(getMapActivity(), focusedView);
}
@ -183,11 +181,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
});
textFieldBoxes = new ArrayList<>();
final OsmandTextFieldBoxes latitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box);
final OsmandTextViewFieldBoxes latitudeBox = (OsmandTextViewFieldBoxes) mainView.findViewById(R.id.latitude_box);
textFieldBoxes.add(latitudeBox);
final OsmandTextFieldBoxes longitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box);
final OsmandTextViewFieldBoxes longitudeBox = (OsmandTextViewFieldBoxes) mainView.findViewById(R.id.longitude_box);
textFieldBoxes.add(longitudeBox);
final OsmandTextFieldBoxes nameBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box);
final OsmandTextViewFieldBoxes nameBox = (OsmandTextViewFieldBoxes) mainView.findViewById(R.id.name_box);
nameBox.setEndIcon(iconsCache.getThemedIcon(R.drawable.ic_action_keyboard));
nameBox.getEndIconImageButton().setOnClickListener(new View.OnClickListener() {
@Override
@ -205,13 +203,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
registerTextFieldBoxes();
extendedEditTexts = new ArrayList<>();
final ExtendedEditText latitudeEditText = (ExtendedEditText) mainView.findViewById(R.id.latitude_edit_text);
extendedEditTexts.add(latitudeEditText);
final ExtendedEditText longitudeEditText = (ExtendedEditText) mainView.findViewById(R.id.longitude_edit_text);
extendedEditTexts.add(longitudeEditText);
final ExtendedEditText nameEditText = (ExtendedEditText) mainView.findViewById(R.id.name_edit_text);
extendedEditTexts.add(nameEditText);
inputTextViews = new ArrayList<>();
final TextView latitudeEditText = (TextView) mainView.findViewById(R.id.latitude_edit_text);
inputTextViews.add(latitudeEditText);
final TextView longitudeEditText = (TextView) mainView.findViewById(R.id.longitude_edit_text);
inputTextViews.add(longitudeEditText);
final TextView nameEditText = (TextView) mainView.findViewById(R.id.name_edit_text);
inputTextViews.add(nameEditText);
registerEditTexts();
@ -267,21 +265,21 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
View focusedView = getDialog().getCurrentFocus();
if (focusedView != null && focusedView instanceof ExtendedEditText) {
ExtendedEditText extendedEditText = (ExtendedEditText) focusedView;
if (focusedView != null && focusedView instanceof TextView) {
TextView focusedTextView = (TextView) focusedView;
switch (i) {
case CLEAR_BUTTON_POSITION:
extendedEditText.setText("");
focusedTextView.setText("");
break;
case DELETE_BUTTON_POSITION:
String str = extendedEditText.getText().toString();
String str = focusedTextView.getText().toString();
if (str.length() > 0) {
str = str.substring(0, str.length() - 1);
extendedEditText.setText(str);
focusedTextView.setText(str);
}
break;
default:
extendedEditText.append(keyboardAdapter.getItem(i));
focusedTextView.append(keyboardAdapter.getItem(i));
}
}
}
@ -352,7 +350,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
};
for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) {
for (OsmandTextViewFieldBoxes textFieldBox : textFieldBoxes) {
textFieldBox.getPanel().setOnTouchListener(textFieldBoxOnTouchListener);
}
changeKeyboardInBoxes();
@ -378,8 +376,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
public void afterTextChanged(Editable editable) {
View focusedView = getDialog().getCurrentFocus();
if (focusedView != null && focusedView instanceof EditText) {
ExtendedEditText focusedEditText = (ExtendedEditText) focusedView;
String str = focusedEditText.getText().toString();
TextView focusedTextView = (TextView) focusedView;
String str = focusedTextView.getText().toString();
int strLength = str.length();
if (len < strLength) {
String strAfterChanging = str.substring(len);
@ -401,20 +399,18 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
if (strDivider != null) {
String textToSet = strBeforeChanging + strDivider + strAfterChanging;
focusedEditText.setText(textToSet);
focusedEditText.setSelection(textToSet.length());
focusedTextView.setText(textToSet);
}
} else if (len > strLength) {
if (strLength > 0 && (".:").contains(str.substring(strLength - 1))) {
focusedEditText.setText(str.substring(0, str.length() - 1));
focusedTextView.setText(str.substring(0, str.length() - 1));
}
focusedEditText.setSelection(focusedEditText.getText().length());
}
if ((strLength == DEGREES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_DEGREES)
|| (strLength == MINUTES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_MINUTES)
|| (strLength == SECONDS_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_SECONDS)) {
switchToNextInput(focusedEditText.getId());
switchToNextInput(focusedTextView.getId());
}
}
}
@ -522,7 +518,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
resId = 0;
}
if (resId != 0) {
OsmandTextFieldBoxes textFieldBox = mainView.findViewById(resId);
OsmandTextViewFieldBoxes textFieldBox = mainView.findViewById(resId);
if (b) {
textFieldBox.setHasFocus(true);
} else {
@ -549,14 +545,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
};
for (ExtendedEditText editText : extendedEditTexts) {
if (editText.getId() != R.id.name_edit_text) {
editText.addTextChangedListener(textWatcher);
for (TextView textView : inputTextViews) {
if (textView.getId() != R.id.name_edit_text) {
textView.addTextChangedListener(textWatcher);
}
editText.setOnTouchListener(editTextOnTouchListener);
editText.setOnLongClickListener(editTextOnLongClickListener);
editText.setOnFocusChangeListener(focusChangeListener);
editText.setOnEditorActionListener(editTextOnEditorActionListener);
textView.setOnTouchListener(editTextOnTouchListener);
textView.setOnLongClickListener(editTextOnLongClickListener);
textView.setOnFocusChangeListener(focusChangeListener);
textView.setOnEditorActionListener(editTextOnEditorActionListener);
}
}
@ -598,7 +594,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
public void changeKeyboardInBoxes() {
for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) {
for (OsmandTextViewFieldBoxes textFieldBox : textFieldBoxes) {
textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard);
}
}
@ -613,9 +609,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
maxLength = SECONDS_MAX_LENGTH;
}
InputFilter[] filtersArray = new InputFilter[] {new InputFilter.LengthFilter(maxLength)};
for (ExtendedEditText extendedEditText : extendedEditTexts) {
if (extendedEditText.getId() != R.id.name_edit_text) {
extendedEditText.setFilters(filtersArray);
for (TextView textView : inputTextViews) {
if (textView.getId() != R.id.name_edit_text) {
textView.setFilters(filtersArray);
}
}
}
@ -629,18 +625,18 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} else {
hint = SECONDS_HINT;
}
for (ExtendedEditText editText : extendedEditTexts) {
if (editText.getId() != R.id.name_edit_text) {
editText.setHint(hint);
for (TextView textView : inputTextViews) {
if (textView.getId() != R.id.name_edit_text) {
textView.setHint(hint);
}
}
}
private void switchToNextInput(int id) {
if (id == R.id.latitude_edit_text) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
((OsmandTextViewFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
} else {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box)).select();
((OsmandTextViewFieldBoxes) mainView.findViewById(R.id.name_box)).select();
}
}
@ -671,14 +667,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
mapMarkers.add(mapMarker);
adapter.notifyDataSetChanged();
clearInputs();
((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).select();
((OsmandTextViewFieldBoxes) mainView.findViewById(R.id.latitude_box)).select();
}
private void clearInputs() {
for (ExtendedEditText editText : extendedEditTexts) {
editText.setText("");
for (TextView inputTextView : inputTextViews) {
inputTextView.setText("");
}
for (OsmandTextFieldBoxes osmandTextFieldBox : textFieldBoxes) {
for (OsmandTextViewFieldBoxes osmandTextFieldBox : textFieldBoxes) {
osmandTextFieldBox.deactivate();
}
}

View file

@ -21,7 +21,7 @@ import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandTextFieldBoxes;
import net.osmand.plus.widgets.OsmandEditTextFieldBoxes;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetDialogFragment;
@ -63,8 +63,8 @@ public class RenameMarkerBottomSheetDialogFragment extends BottomSheetDialogFrag
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
View textBox = mainView.findViewById(R.id.name_text_box);
if (textBox instanceof OsmandTextFieldBoxes) {
((OsmandTextFieldBoxes) textBox).activate(true);
if (textBox instanceof OsmandEditTextFieldBoxes) {
((OsmandEditTextFieldBoxes) textBox).activate(true);
}
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {

View file

@ -17,7 +17,7 @@ import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandTextFieldBoxes;
import net.osmand.plus.widgets.OsmandEditTextFieldBoxes;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetDialogFragment;
@ -76,8 +76,8 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
nameEditText.setText(displayedName);
View textBox = mainView.findViewById(R.id.name_text_box);
if (textBox instanceof OsmandTextFieldBoxes) {
((OsmandTextFieldBoxes) textBox).activate(true);
if (textBox instanceof OsmandEditTextFieldBoxes) {
((OsmandEditTextFieldBoxes) textBox).activate(true);
}
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {

View file

@ -0,0 +1,50 @@
package net.osmand.plus.widgets;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
public class CursorTextView extends AppCompatTextView {
private Paint linePaint;
private Rect bounds;
public CursorTextView(Context context) {
super(context);
init();
}
public CursorTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CursorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
linePaint = new Paint();
linePaint.setAntiAlias(true);
linePaint.setFilterBitmap(true);
linePaint.setColor(Color.RED);
bounds = new Rect();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
float height = fontMetrics.bottom - fontMetrics.top + fontMetrics.leading;
Paint paint = getPaint();
String text = getText().toString();
paint.getTextBounds(text, 0, text.length(), bounds);
int width = bounds.width();
canvas.drawLine(width, 0, width, height, linePaint);
}
}

View file

@ -0,0 +1,29 @@
package net.osmand.plus.widgets;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import studio.carbonylgroup.textfieldboxes.TextFieldBoxes;
public class OsmandEditTextFieldBoxes extends TextFieldBoxes {
public OsmandEditTextFieldBoxes(Context context) {
super(context);
}
public OsmandEditTextFieldBoxes(Context context, AttributeSet attrs) {
super(context, attrs);
}
public OsmandEditTextFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void activate(boolean animated) {
super.activate(animated);
}
}

View file

@ -0,0 +1,783 @@
package net.osmand.plus.widgets;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.AppCompatTextView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.lang.reflect.Field;
public class OsmandTextViewFieldBoxes extends FrameLayout {
public int DEFAULT_ERROR_COLOR;
public int DEFAULT_PRIMARY_COLOR;
public int DEFAULT_TEXT_COLOR;
public int DEFAULT_DISABLED_TEXT_COLOR;
public int DEFAULT_BG_COLOR;
protected boolean enabled;
protected String labelText;
protected String helperText;
protected int maxCharacters;
protected int minCharacters;
protected int helperTextColor;
protected int errorColor;
protected int primaryColor;
protected int panelBackgroundColor;
protected int iconSignifierResourceId;
protected int endIconResourceId;
protected boolean isResponsiveIconColor;
protected boolean hasClearButton;
protected boolean hasFocus;
protected View panel;
protected View bottomLine;
protected ViewGroup editTextLayout;
protected AppCompatTextView inputText;
protected AppCompatTextView helperLabel;
protected AppCompatTextView counterLabel;
protected AppCompatTextView floatingLabel;
protected AppCompatImageButton clearButton;
protected AppCompatImageButton iconImageButton;
protected AppCompatImageButton endIconImageButton;
protected InputMethodManager inputMethodManager;
protected RelativeLayout rightShell;
protected RelativeLayout upperPanel;
protected RelativeLayout bottomPart;
protected RelativeLayout inputLayout;
protected int labelColor = -1;
protected int labelTopMargin = -1;
protected int ANIMATION_DURATION = 100;
protected boolean onError = false;
protected boolean activated = false;
protected boolean doNotRemoveError = false;
private boolean useOsmandKeyboard;
public OsmandTextViewFieldBoxes(Context context) {
super(context);
this.init();
}
public OsmandTextViewFieldBoxes(Context context, AttributeSet attrs) {
super(context, attrs);
this.init();
this.handleAttributes(context, attrs);
}
public OsmandTextViewFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.init();
this.handleAttributes(context, attrs);
}
public void setUseOsmandKeyboard(boolean useOsmandKeyboard) {
this.useOsmandKeyboard = useOsmandKeyboard;
}
protected void init() {
this.initDefaultColor();
this.inputMethodManager = (InputMethodManager)this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
}
protected void initDefaultColor() {
Resources.Theme theme = this.getContext().getTheme();
this.DEFAULT_ERROR_COLOR = ContextCompat.getColor(this.getContext(), studio.carbonylgroup.textfieldboxes.R.color.A400red);
TypedArray themeArray = theme.obtainStyledAttributes(new int[]{16842800});
this.DEFAULT_BG_COLOR = adjustAlpha(themeArray.getColor(0, 0), 0.06F);
themeArray = theme.obtainStyledAttributes(new int[]{studio.carbonylgroup.textfieldboxes.R.attr.colorPrimary});
if(isLight(this.DEFAULT_BG_COLOR)) {
this.DEFAULT_PRIMARY_COLOR = lighter(themeArray.getColor(0, 0), 0.2F);
} else {
this.DEFAULT_PRIMARY_COLOR = themeArray.getColor(0, 0);
}
themeArray = theme.obtainStyledAttributes(new int[]{16843282});
this.DEFAULT_TEXT_COLOR = themeArray.getColor(0, 0);
themeArray = theme.obtainStyledAttributes(new int[]{16842803});
float disabledAlpha = themeArray.getFloat(0, 0.0F);
themeArray = theme.obtainStyledAttributes(new int[]{16843282});
this.DEFAULT_DISABLED_TEXT_COLOR = adjustAlpha(themeArray.getColor(0, 0), disabledAlpha);
themeArray.recycle();
}
protected AppCompatTextView findEditTextChild() {
return this.getChildCount() > 0 && this.getChildAt(0) instanceof AppCompatTextView?(AppCompatTextView) this.getChildAt(0):null;
}
protected void onFinishInflate() {
super.onFinishInflate();
this.inputText = this.findEditTextChild();
if(this.inputText != null) {
this.addView(LayoutInflater.from(this.getContext()).inflate(studio.carbonylgroup.textfieldboxes.R.layout.text_field_boxes_layout, this, false));
this.removeView(this.inputText);
this.inputText.setBackgroundColor(0);
this.inputLayout = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_input_layout);
this.inputLayout.addView(this.inputText);
this.inputLayout.setAlpha(0.0F);
this.panel = this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_panel);
this.floatingLabel = (AppCompatTextView)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_label);
this.floatingLabel.setPivotX(0.0F);
this.floatingLabel.setPivotY(0.0F);
this.bottomLine = this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.bg_bottom_line);
this.rightShell = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_right_shell);
this.upperPanel = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_upper_panel);
this.bottomPart = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_bottom);
this.labelColor = this.floatingLabel.getCurrentTextColor();
this.clearButton = (AppCompatImageButton)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_clear_button);
this.clearButton.setColorFilter(this.DEFAULT_TEXT_COLOR);
this.clearButton.setAlpha(0.35F);
this.endIconImageButton = (AppCompatImageButton)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
this.endIconImageButton.setColorFilter(this.DEFAULT_TEXT_COLOR);
this.endIconImageButton.setAlpha(0.54F);
this.helperLabel = (AppCompatTextView)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_helper);
this.counterLabel = (AppCompatTextView)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_counter);
this.iconImageButton = (AppCompatImageButton)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_imageView);
this.editTextLayout = (ViewGroup)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_editTextLayout);
this.labelTopMargin = ((RelativeLayout.LayoutParams)RelativeLayout.LayoutParams.class.cast(this.floatingLabel.getLayoutParams())).topMargin;
this.panel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
select();
}
});
this.iconImageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
select();
}
});
this.inputText.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean b) {
if(b) {
setHasFocus(true);
} else {
setHasFocus(false);
}
}
});
this.inputText.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable editable) {
if(!doNotRemoveError) {
removeError();
updateCounterText();
}
}
});
this.clearButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
inputText.setText("");
}
});
if(!this.inputText.getText().toString().isEmpty() || this.hasFocus) {
this.activate(false);
}
this.setLabelText(this.labelText);
this.setHelperText(this.helperText);
this.setHelperTextColor(this.helperTextColor);
this.setErrorColor(this.errorColor);
this.setPrimaryColor(this.primaryColor);
this.setPanelBackgroundColor(this.panelBackgroundColor);
this.setMaxCharacters(this.maxCharacters);
this.setMinCharacters(this.minCharacters);
this.setEnabled(this.enabled);
this.setIconSignifier(this.iconSignifierResourceId);
this.setEndIcon(this.endIconResourceId);
this.setIsResponsiveIconColor(this.isResponsiveIconColor);
this.setHasClearButton(this.hasClearButton);
this.setHasFocus(this.hasFocus);
this.updateCounterText();
this.updateBottomViewVisibility();
}
}
public void select() {
if(!isActivated()) {
activate(true);
}
setHasFocus(true);
if (!useOsmandKeyboard) {
inputMethodManager.showSoftInput(inputText, 1);
}
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if(widthMode == 1073741824) {
this.inputLayout.getLayoutParams().width = -1;
this.upperPanel.getLayoutParams().width = -1;
this.editTextLayout.getLayoutParams().width = -1;
if(this.endIconImageButton.getVisibility() == VISIBLE) {
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(1, 0);
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
if(Build.VERSION.SDK_INT >= 17) {
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(17, 0);
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(16, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
}
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(1, 0);
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(11);
if(Build.VERSION.SDK_INT >= 17) {
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(17, 0);
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(21);
}
if(this.hasClearButton) {
((RelativeLayout.LayoutParams)this.inputLayout.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_clear_button);
} else {
((RelativeLayout.LayoutParams)this.inputLayout.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
}
} else {
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(1, 0);
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(11);
if(Build.VERSION.SDK_INT >= 17) {
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(17, 0);
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(21);
}
((RelativeLayout.LayoutParams)this.inputLayout.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_clear_button);
}
} else if(widthMode == -2147483648) {
this.inputLayout.getLayoutParams().width = -2;
this.upperPanel.getLayoutParams().width = -2;
this.editTextLayout.getLayoutParams().width = -2;
}
if(heightMode == 1073741824) {
this.panel.getLayoutParams().height = -1;
this.rightShell.getLayoutParams().height = -1;
this.upperPanel.getLayoutParams().height = -1;
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(3, 0);
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(3, 0);
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(12);
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(12);
((RelativeLayout.LayoutParams)this.panel.getLayoutParams()).addRule(2, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_bottom);
} else if(heightMode == -2147483648) {
this.panel.getLayoutParams().height = -2;
this.rightShell.getLayoutParams().height = -2;
this.upperPanel.getLayoutParams().height = -2;
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(3, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_panel);
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(3, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_upper_panel);
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(12, 0);
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(12, 0);
((RelativeLayout.LayoutParams)this.panel.getLayoutParams()).addRule(2, 0);
}
}
protected void handleAttributes(Context context, AttributeSet attrs) {
try {
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes);
this.labelText = styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_labelText) == null?"":styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_labelText);
this.helperText = styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_helperText) == null?"":styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_helperText);
this.helperTextColor = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_helperTextColor, this.DEFAULT_TEXT_COLOR);
this.errorColor = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_errorColor, this.DEFAULT_ERROR_COLOR);
this.primaryColor = styledAttrs.getColor(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_primaryColor, this.DEFAULT_PRIMARY_COLOR);
this.panelBackgroundColor = styledAttrs.getColor(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_panelBackgroundColor, this.DEFAULT_BG_COLOR);
this.maxCharacters = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_maxCharacters, 0);
this.minCharacters = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_minCharacters, 0);
this.enabled = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_enabled, true);
this.iconSignifierResourceId = styledAttrs.getResourceId(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_iconSignifier, 0);
this.endIconResourceId = styledAttrs.getResourceId(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_endIcon, 0);
this.isResponsiveIconColor = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_isResponsiveIconColor, true);
this.hasClearButton = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_hasClearButton, false);
this.hasFocus = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_hasFocus, false);
styledAttrs.recycle();
} catch (Exception var4) {
var4.printStackTrace();
}
}
public void deactivate() {
if(this.inputText.getText().toString().isEmpty()) {
ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION);
this.editTextLayout.setVisibility(INVISIBLE);
if(this.inputText.hasFocus()) {
if (!useOsmandKeyboard) {
this.inputMethodManager.hideSoftInputFromWindow(this.inputText.getWindowToken(), 0);
}
this.inputText.clearFocus();
}
}
this.activated = false;
}
protected void activate(boolean animated) {
this.editTextLayout.setVisibility(VISIBLE);
if(this.inputText.getText().toString().isEmpty() && !this.isActivated()) {
this.inputLayout.setAlpha(0.0F);
this.floatingLabel.setScaleX(1.0F);
this.floatingLabel.setScaleY(1.0F);
this.floatingLabel.setTranslationY(0.0F);
}
if(animated) {
ViewCompat.animate(this.inputLayout).alpha(1.0F).setDuration((long)this.ANIMATION_DURATION);
ViewCompat.animate(this.floatingLabel).scaleX(0.75F).scaleY(0.75F).translationY((float)(-this.labelTopMargin + this.getContext().getResources().getDimensionPixelOffset(studio.carbonylgroup.textfieldboxes.R.dimen.text_field_boxes_margin_top))).setDuration((long)this.ANIMATION_DURATION);
} else {
this.inputLayout.setAlpha(1.0F);
this.floatingLabel.setScaleX(0.75F);
this.floatingLabel.setScaleY(0.75F);
this.floatingLabel.setTranslationY((float)(-this.labelTopMargin + this.getContext().getResources().getDimensionPixelOffset(studio.carbonylgroup.textfieldboxes.R.dimen.text_field_boxes_margin_top)));
}
this.activated = true;
}
protected void makeCursorBlink() {
int cursorPos = this.inputText.getSelectionStart();
if(cursorPos == 0) {
if(this.inputText.getText().toString().isEmpty()) {
if(this.onError) {
this.doNotRemoveError = true;
this.inputText.setText(" ");
this.inputText.setText("");
this.doNotRemoveError = false;
}
}
}
}
protected void setHighlightColor(int colorRes) {
this.floatingLabel.setTextColor(colorRes);
setCursorDrawableColor(this.inputText, colorRes);
if(this.getIsResponsiveIconColor()) {
this.iconImageButton.setColorFilter(colorRes);
if(colorRes == this.DEFAULT_TEXT_COLOR) {
this.iconImageButton.setAlpha(0.54F);
} else {
this.iconImageButton.setAlpha(1.0F);
}
}
if(colorRes == this.DEFAULT_DISABLED_TEXT_COLOR) {
this.iconImageButton.setAlpha(0.35F);
}
this.bottomLine.setBackgroundColor(colorRes);
}
protected void updateCounterText() {
if(this.hasClearButton) {
if(this.inputText.getText().toString().length() == 0) {
this.showClearButton(false);
} else {
this.showClearButton(true);
}
}
int length = this.inputText.getText().toString().replaceAll(" ", "").replaceAll("\n", "").length();
String lengthStr = Integer.toString(length) + " / ";
if(this.maxCharacters > 0) {
if(this.minCharacters > 0) {
this.counterLabel.setText(lengthStr + Integer.toString(this.minCharacters) + "-" + Integer.toString(this.maxCharacters));
if(length >= this.minCharacters && length <= this.maxCharacters) {
this.removeCounterError();
} else {
this.setCounterError();
}
} else {
this.counterLabel.setText(lengthStr + Integer.toString(this.maxCharacters) + "");
if(length > this.maxCharacters) {
this.setCounterError();
} else {
this.removeCounterError();
}
}
} else if(this.minCharacters > 0) {
this.counterLabel.setText(lengthStr + Integer.toString(this.minCharacters) + "+");
if(length < this.minCharacters) {
this.setCounterError();
} else {
this.removeCounterError();
}
} else {
this.counterLabel.setText("");
}
}
protected void updateBottomViewVisibility() {
if(this.helperLabel.getText().toString().isEmpty() && this.counterLabel.getText().toString().isEmpty()) {
this.bottomPart.setVisibility(GONE);
} else {
this.bottomPart.setVisibility(GONE);
}
}
protected void setCounterError() {
this.onError = true;
this.setHighlightColor(this.errorColor);
this.counterLabel.setTextColor(this.errorColor);
}
protected void removeCounterError() {
this.onError = false;
if(this.hasFocus) {
this.setHighlightColor(this.primaryColor);
} else {
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
}
this.counterLabel.setTextColor(this.DEFAULT_TEXT_COLOR);
}
public void setError(String errorText, boolean giveFocus) {
if(this.enabled) {
this.onError = true;
this.activate(true);
this.setHighlightColor(this.errorColor);
this.helperLabel.setTextColor(this.errorColor);
this.helperLabel.setText(errorText);
if(giveFocus) {
this.setHasFocus(true);
}
this.makeCursorBlink();
}
}
public void removeError() {
this.onError = false;
if(this.hasFocus) {
this.setHighlightColor(this.primaryColor);
} else {
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
}
this.helperLabel.setTextColor(this.helperTextColor);
this.helperLabel.setText(this.helperText);
}
protected void showClearButton(boolean show) {
if(show) {
this.clearButton.setVisibility(VISIBLE);
} else {
this.clearButton.setVisibility(GONE);
}
}
public void setLabelText(String labelText) {
this.labelText = labelText;
this.floatingLabel.setText(this.labelText);
}
public void setHelperText(String helperText) {
this.helperText = helperText;
this.helperLabel.setText(this.helperText);
}
public void setHelperTextColor(int colorRes) {
this.helperTextColor = colorRes;
this.helperLabel.setTextColor(this.helperTextColor);
}
public void setErrorColor(int colorRes) {
this.errorColor = colorRes;
}
public void setPrimaryColor(int colorRes) {
this.primaryColor = colorRes;
if(this.hasFocus) {
this.setHighlightColor(this.primaryColor);
}
}
public void setPanelBackgroundColor(int colorRes) {
this.panelBackgroundColor = colorRes;
this.panel.getBackground().setColorFilter(new PorterDuffColorFilter(colorRes, PorterDuff.Mode.SRC_IN));
}
public void setMaxCharacters(int maxCharacters) {
this.maxCharacters = maxCharacters;
}
public void removeMaxCharacters() {
this.maxCharacters = 0;
}
public void setMinCharacters(int minCharacters) {
this.minCharacters = minCharacters;
}
public void removeMinCharacters() {
this.minCharacters = 0;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
if(this.enabled) {
this.inputText.setEnabled(true);
this.inputText.setFocusableInTouchMode(true);
this.inputText.setFocusable(true);
this.helperLabel.setVisibility(VISIBLE);
this.counterLabel.setVisibility(VISIBLE);
this.bottomLine.setVisibility(VISIBLE);
this.panel.setEnabled(true);
this.iconImageButton.setEnabled(true);
this.iconImageButton.setClickable(true);
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
this.updateCounterText();
} else {
this.removeError();
this.setHasFocus(false);
this.inputText.setEnabled(false);
this.inputText.setFocusableInTouchMode(false);
this.inputText.setFocusable(false);
this.iconImageButton.setClickable(false);
this.iconImageButton.setEnabled(false);
this.helperLabel.setVisibility(INVISIBLE);
this.counterLabel.setVisibility(INVISIBLE);
this.bottomLine.setVisibility(INVISIBLE);
this.panel.setEnabled(false);
this.setHighlightColor(this.DEFAULT_DISABLED_TEXT_COLOR);
}
}
public void setIconSignifier(int resourceID) {
this.iconSignifierResourceId = resourceID;
if(this.iconSignifierResourceId != 0) {
this.iconImageButton.setImageResource(this.iconSignifierResourceId);
this.iconImageButton.setVisibility(VISIBLE);
} else {
this.removeIconSignifier();
}
}
public void setIconSignifier(Drawable drawable) {
this.removeIconSignifier();
this.iconImageButton.setImageDrawable(drawable);
this.iconImageButton.setVisibility(VISIBLE);
}
public void removeIconSignifier() {
this.iconSignifierResourceId = 0;
this.iconImageButton.setVisibility(GONE);
}
public void setEndIcon(int resourceID) {
this.endIconResourceId = resourceID;
if(this.endIconResourceId != 0) {
this.endIconImageButton.setImageResource(this.endIconResourceId);
this.endIconImageButton.setVisibility(VISIBLE);
} else {
this.removeEndIcon();
}
}
public void setEndIcon(Drawable drawable) {
this.removeEndIcon();
this.endIconImageButton.setImageDrawable(drawable);
this.endIconImageButton.setVisibility(VISIBLE);
}
public void removeEndIcon() {
this.endIconResourceId = 0;
this.endIconImageButton.setVisibility(GONE);
}
public void setHasFocus(boolean hasFocus) {
this.hasFocus = hasFocus;
if(this.hasFocus) {
this.activate(true);
this.inputText.requestFocus();
this.makeCursorBlink();
if(!this.onError && this.enabled) {
this.setHighlightColor(this.primaryColor);
}
} else {
this.deactivate();
if(!this.onError && this.enabled) {
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
}
}
}
public void setIsResponsiveIconColor(boolean isResponsiveIconColor) {
this.isResponsiveIconColor = isResponsiveIconColor;
if(this.isResponsiveIconColor) {
if(this.hasFocus) {
this.iconImageButton.setColorFilter(this.primaryColor);
this.iconImageButton.setAlpha(1.0F);
} else {
this.iconImageButton.setColorFilter(this.DEFAULT_TEXT_COLOR);
this.iconImageButton.setAlpha(0.54F);
}
} else {
this.iconImageButton.setColorFilter(this.primaryColor);
this.iconImageButton.setAlpha(1.0F);
}
}
public void setHasClearButton(boolean hasClearButton) {
this.hasClearButton = hasClearButton;
}
public String getLabelText() {
return this.labelText;
}
public String getHelperText() {
return this.helperText;
}
public String getCounterText() {
return this.counterLabel.getText().toString();
}
public int getHelperTextColor() {
return this.helperTextColor;
}
public int getErrorColor() {
return this.errorColor;
}
public int getPrimaryColor() {
return this.primaryColor;
}
public int getPanelBackgroundColor() {
return this.panelBackgroundColor;
}
public int getMaxCharacters() {
return this.maxCharacters;
}
public int getMinCharacters() {
return this.minCharacters;
}
public View getPanel() {
return this.panel;
}
public View getBottomLine() {
return this.bottomLine;
}
public AppCompatTextView getHelperLabel() {
return this.helperLabel;
}
public AppCompatTextView getCounterLabel() {
return this.counterLabel;
}
public AppCompatTextView getFloatingLabel() {
return this.floatingLabel;
}
public AppCompatImageButton getIconImageButton() {
return this.iconImageButton;
}
public AppCompatImageButton getEndIconImageButton() {
return this.endIconImageButton;
}
public boolean isActivated() {
return this.activated;
}
public boolean isEnabled() {
return this.enabled;
}
public int getIconSignifierResourceId() {
return this.iconSignifierResourceId;
}
public int getEndIconResourceId() {
return this.endIconResourceId;
}
public boolean getIsResponsiveIconColor() {
return this.isResponsiveIconColor;
}
public boolean getHasClearButton() {
return this.hasClearButton;
}
public boolean getHasFocus() {
return this.hasFocus;
}
protected static void setCursorDrawableColor(AppCompatTextView _inputText, int _colorRes) {
try {
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
fCursorDrawableRes.setAccessible(true);
int mCursorDrawableRes = fCursorDrawableRes.getInt(_inputText);
Field fEditor = TextView.class.getDeclaredField("mEditor");
fEditor.setAccessible(true);
Object editor = fEditor.get(_inputText);
Class<?> clazz = editor.getClass();
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
fCursorDrawable.setAccessible(true);
Drawable[] drawables = new Drawable[]{ContextCompat.getDrawable(_inputText.getContext(), mCursorDrawableRes), ContextCompat.getDrawable(_inputText.getContext(), mCursorDrawableRes)};
drawables[0].setColorFilter(_colorRes, PorterDuff.Mode.SRC_IN);
drawables[1].setColorFilter(_colorRes, PorterDuff.Mode.SRC_IN);
fCursorDrawable.set(editor, drawables);
} catch (Throwable var9) {
;
}
}
protected static int lighter(int color, float _factor) {
int red = (int)(((float) Color.red(color) * (1.0F - _factor) / 255.0F + _factor) * 255.0F);
int green = (int)(((float)Color.green(color) * (1.0F - _factor) / 255.0F + _factor) * 255.0F);
int blue = (int)(((float)Color.blue(color) * (1.0F - _factor) / 255.0F + _factor) * 255.0F);
return Color.argb(Color.alpha(color), red, green, blue);
}
protected static boolean isLight(int color) {
return Math.sqrt((double)(Color.red(color) * Color.red(color)) * 0.241D + (double)(Color.green(color) * Color.green(color)) * 0.691D + (double)(Color.blue(color) * Color.blue(color)) * 0.068D) > 130.0D;
}
protected static int adjustAlpha(int color, float _toAlpha) {
int alpha = Math.round(255.0F * _toAlpha);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha, red, green, blue);
}
}