09 ResolutionPreference - michael-rapp/AndroidMaterialPreferences GitHub Wiki
The purpose of the preference ResolutionPreference
is to enter two-dimensional image or video resolutions. It contains two EditText
widgets, which allow to enter the width and height of the resolution. Both widgets are already validated by default in order to ensure, that they contain numbers, which are greater than 0. The resolution of a ResolutionPreference is stored as a textual representation using the syntax <width>x<height>
. Such a textual representation can be easily created by using the static method formatResolution(Context,int,int):String
. When retrieving the stored resolution from the shared preferences, the width and height of the resolution can be retrieved by using the static method parseResolution(Context,String):Pair
. This method returns an instance of the class Pair
, which contains two integer values. The first one represents the resolution's width, the second one represents the height.
The getter and setter methods shown below can be used to change the properties of a ResolutionPreference
.
Getter and setter methods | Description | Default value | Restrictions |
---|---|---|---|
getWidth():int setWidth(int):void
|
Returns or sets the width of the preference's resolution. If a width is set, it is instantly persisted. | 0 |
The width must be at least 1. |
getHeight():int setHeight(int):void
|
Returns or sets the height of the preference's resolution. If a height is set, it is instantly persisted. | 0 |
The height must be at least 1. |
getUnit():CharSequence setUnit(CharSequence):void setUnit(int):void
|
Returns or sets the unit, which is shown in the preference's dialog. | R.string.resolution_preference_unit |
If the unit is specified as a resource ID, the ID must correspond to a valid string resource. |
getWidthHint():CharSequence setWidthHint(CharSequence):void setWidthHint(int):void
|
Returns or sets the hint of the EditText widget, which allows to enter the width of the resolution. |
R.string.resolution_preference_width_hint |
If the hint is specified as a resource ID, the ID must correspond to a valid string resource. |
getHeightHint():CharSequence setHeightHint(CharSequence):void setHeightHint(int):void
|
Returns or sets the hint of the EditText widget, which allows to enter the height of the resolution. |
R.string.resolution_preference_height_hint |
If the hint is specified as a resource ID, the ID must correspond to a valid string resource. |
Instead of the setter methods shown above, the following XML attributes can be used in order to set the properties of a ResolutionPreference
.
XML attribute | Description | Format |
---|---|---|
android:defaultValue |
The default resolution of the preference. | string |
custom:unit |
The unit, which is shown in the preference's dialog. | string |
custom:widthHint |
The hint of the EditText widget, which allows to enter the width of the resolution. | string |
custom:heightHint |
The hint of the EditText widget, which allows to enter the height of the resolution. | string |