Class UnitSelectionEditText
-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback
,android.view.KeyEvent.Callback
,android.view.ViewTreeObserver.OnPreDrawListener
,android.view.accessibility.AccessibilityEventSource
,androidx.appcompat.widget.EmojiCompatConfigurationView
,androidx.core.view.OnReceiveContentViewBehavior
,androidx.core.view.TintableBackgroundView
,androidx.core.widget.TintableCompoundDrawablesView
public class UnitSelectionEditText extends ScreenAdjustingEditText
Edit text with blocked selection to prevent user interacting with a unit label.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
UnitSelectionEditText.UnitSelectionListener
Listener for unit values selection.
-
Field Summary
Fields Modifier and Type Field Description public String
unitLabel
public int
unitLengthNotSelectable
public int
defaultValue
public int
minimumValue
public int
maximumValue
-
Constructor Summary
Constructors Constructor Description UnitSelectionEditText(Context context)
UnitSelectionEditText(Context context, AttributeSet attrs)
UnitSelectionEditText(Context context, AttributeSet attrs, int defStyle)
-
Method Summary
Modifier and Type Method Description String
getUnitLabel()
Returns current unit label. int
getUnitLengthNotSelectable()
Gets length of the unit. int
getDefaultValue()
Returns default value. void
setDefaultValue(int defaultValue)
Sets default value of the unit. int
getMinimumValue()
Returns minimum value of the unit. void
setMinimumValue(int minimumValue)
Sets minimum value of the unit. int
getMaximumValue()
Returns maximum value of the unit. void
setMaximumValue(int maximumValue)
Sets maximum value of the unit. void
setUnitLabel(@NonNull() String unitLabel, @IntRange(from = 1) int defaultValue, @IntRange(from = 1) int minimumValue, @IntRange(from = 1) int maximumValue, @Nullable() UnitSelectionEditText.UnitSelectionListener listener)
Sets unit label. int
parseValue(@NonNull() String s)
Returns the parsed value of the unit. void
setTextToDefault()
Sets text to default value and notifies the listener if not null. void
setTextToFormat(int value)
Sets text properly formatted according to unitLabel. int
getValue()
Gets current value. void
focusCheck()
Checks if the view has the focus and select the editable value. -
-
Constructor Detail
-
UnitSelectionEditText
UnitSelectionEditText(Context context)
-
UnitSelectionEditText
UnitSelectionEditText(Context context, AttributeSet attrs)
-
UnitSelectionEditText
UnitSelectionEditText(Context context, AttributeSet attrs, int defStyle)
-
-
Method Detail
-
getUnitLabel
@NonNull() String getUnitLabel()
Returns current unit label.
- Returns:
current unit label.
-
getUnitLengthNotSelectable
int getUnitLengthNotSelectable()
Gets length of the unit.
- Returns:
length of the unit.
-
getDefaultValue
int getDefaultValue()
Returns default value.
- Returns:
default value.
-
setDefaultValue
void setDefaultValue(int defaultValue)
Sets default value of the unit.
- Parameters:
defaultValue
- default value of the unit.
-
getMinimumValue
int getMinimumValue()
Returns minimum value of the unit.
- Returns:
minimum value.
-
setMinimumValue
void setMinimumValue(int minimumValue)
Sets minimum value of the unit.
- Parameters:
minimumValue
- minimum value of the unit.
-
getMaximumValue
int getMaximumValue()
Returns maximum value of the unit.
- Returns:
maximum value.
-
setMaximumValue
void setMaximumValue(int maximumValue)
Sets maximum value of the unit.
- Parameters:
maximumValue
- maximum value.
-
setUnitLabel
void setUnitLabel(@NonNull() String unitLabel, @IntRange(from = 1) int defaultValue, @IntRange(from = 1) int minimumValue, @IntRange(from = 1) int maximumValue, @Nullable() UnitSelectionEditText.UnitSelectionListener listener)
Sets unit label.
- Parameters:
unitLabel
- Unit label format.defaultValue
- Default value of the unit label.minimumValue
- Maximum value allowed.maximumValue
- Minimum value allowed.listener
- Listener for text changes.
-
parseValue
int parseValue(@NonNull() String s)
Returns the parsed value of the unit. Returns default value if the input is malformed. Returns maximum value if the input value is over the maximum value. Returns minimum value if the input value is under the minimum value.
- Parameters:
s
- Input value to parse.- Returns:
parsed value of the unit.
-
setTextToDefault
void setTextToDefault()
Sets text to default value and notifies the listener if not null.
-
setTextToFormat
void setTextToFormat(int value)
Sets text properly formatted according to unitLabel.
- Parameters:
value
- to format with unitLabel.
-
getValue
int getValue()
Gets current value.
-
focusCheck
void focusCheck()
Checks if the view has the focus and select the editable value.
-
-
-
-