public class

SwitchFormCell

extends LinearLayout
implements FormCell<T> InlineValidation SupportsHelperText SupportsKey
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.LinearLayout
         ↳ com.sap.cloud.mobile.fiori.formcell.SwitchFormCell

Class Overview

A customised Switch control which contains a TextView and a Switch allowing the user to select between two options

Structure of the control is:

  • TextView :showing the text to be displayed for label of the control See also: setKey(CharSequence)
  • Switch: showing if the property is checked or not See also:setValue(Boolean)
  • Summary

    XML Attributes
    Attribute Name Related Method Description
    FormCellMetadataLayout_android_clickable setClickable(boolean)  
    FormCellMetadataLayout_android_enabled setEnabled(boolean)  
    FormCellMetadataLayout_android_focusable setFocusable(boolean)  
    FormCellMetadataLayout_errorEnabled isErrorEnabled()  
    FormCellMetadataLayout_helperEnabled isHelperEnabled()  
    FormCellMetadataLayout_label setLabel(CharSequence)  
    FormCellMetadataLayout_labelEnabled isLabelEnabled()  
    FormCellMetadataLayout_labelTextAppearance setLabelTextAppearanceFocused(int)  
    FormCellMetadataLayout_labelTextAppearanceFocused setLabelTextAppearanceFocused(int)  
    FormCellMetadataLayout_labelTextAppearanceUnFocused setLabelTextAppearanceFocused(int)  
    SwitchFormCell_displayValueTextAppearance setValueTextAppearance(int)  
    SwitchFormCell_key  
    SwitchFormCell_keyTextAppearance setKeyTextAppearance(int)  
    SwitchFormCell_value  
    [Expand]
    Inherited Constants
    From class android.widget.LinearLayout
    From class android.view.ViewGroup
    From class android.view.View
    Fields
    protected CharSequence mErrorMessage
    protected int mErrorTextAppearance
    protected CharSequence mHelperText
    protected int mHelperTextAppearance
    protected int mHorizontalMargin
    protected boolean mIsInError
    protected boolean mIsTablet
    protected int mLabelTextAppearance
    protected int mLabelTextAppearanceUnFocused
    protected TextView mLabelTextView
    protected boolean mShouldAttachOrientationListener
    protected TextView mStatusView
    [Expand]
    Inherited Fields
    From class android.view.View
    Public Constructors
    SwitchFormCell(Context context)
    Construct a new SwitchFormCell with default styling, sets the CellType to WidgetType.SWITCH
    SwitchFormCell(Context context, AttributeSet attrs)
    Construct a new SwitchFormCell with default styling, overriding the attributes for the control as requested, sets the CellType to WidgetType.SWITCH
    Public Methods
    void addView(View child, int index, ViewGroup.LayoutParams params)
    Add given view in the view
    int getCellType()
    Return the enum value corresponding to SwitchFormCell
    CellValueChangeListener<Boolean> getCellValueChangeListener()
    Return the value change handler of the control
    CharSequence getError()
    Get the error
    TextView getErrorView()
    CharSequence getHelperText()
    Get the helper text from the view
    CharSequence getKey()
    Get the key of the Switch FormCell
    Boolean getValue()
    Return the state of the Switch(True/False)
    boolean isEditable()
    Get if the Switch FormCell is enabled
    boolean isErrorEnabled()
    Is error enabled on the view
    boolean isHelperEnabled()
    Set if the helper field is enabled on the view
    boolean isLabelEnabled()
    Is the label field on the view is enabled
    boolean onInterceptTouchEvent(MotionEvent ev)
    boolean performClick()
    void setCellValueChangeListener(CellValueChangeListener<Boolean> listener)
    void setClickable(boolean clickable)
    Enable or disable clickable property on the view and all its children
    void setEditable(boolean isEditable)
    Set if the Switch FormCell editable
    void setEnabled(boolean enabled)
    Enable or disable the view
    void setError(CharSequence error)
    Set the error on the view.
    void setErrorEnabled(boolean errorEnabled)
    Enable or disable the error field on the view
    void setErrorTextAppearance(int resId)
    Set the text appearance on the error
    void setFocusable(boolean focusable)
    Enable or disable focusable property on the view and all its children
    void setHelperEnabled(boolean enabled)
    Enable or disable the helper field on the view
    void setHelperText(CharSequence helperText)
    Set the helper text on the view
    void setHelperTextAppearance(int textAppearance)
    Set the helper text appearance
    void setKey(CharSequence keyName)
    Set the key of the switch FormCell
    void setKeyTextAppearance(int resId)
    Sets the text color, size, style, hint color, and highlight color for key from the specified TextAppearance resource.
    void setLabelTextAppearanceUnFocused(int labelTextAppearanceUnFocused)
    Set the label text appearance when the view is not focused
    void setOverrideKeyStyle(boolean overrideKeyStyle)
    Override the Key styling manually.
    void setOverrideStatusStyle(boolean overrideStatusStyle)
    Override the status i.e.
    void setShouldAttachOrientationListener(boolean shouldAttach)
    Determines if an OrientationEventListener should be attached.
    void setValue(Boolean value)
    Set the state of the switch whether is True or False
    void setValueTextAppearance(int resId)
    Sets the text color, size, style, hint color, and highlight color for value from the specified TextAppearance resource.
    Protected Methods
    void adjustMargins()
    Calculate and set the margins for the cell's elements.
    static boolean arrayContains(int[] array, int value)
    Check if the array contains the given property
    void drawableStateChanged()
    Drawable state changed
    TextView generateTextView()
    Generate the text view
    ViewGroup.LayoutParams getDefaultLayoutParams()
    CharSequence getLabel()
    Get the label on the view
    void onRestoreInstanceState(Parcelable state)
    Parcelable onSaveInstanceState()
    void replaceStatusView()
    Each time you add a new view, error/helper view has to be adjusted to be the last view in the layout
    void setLabel(CharSequence key)
    Set the label on the view
    void setLabelEnabled(boolean labelEnabled)
    Enable or disable the label field on the view
    void setLabelTextAppearance(int textAppearance)
    Set the text appearance on the label.
    void setLabelTextAppearanceFocused(int textAppearance)
    Set the text appearance on the label when the view is not focused
    void setLabelTextColorError(ColorStateList color)
    Set the text color of the label for error mode
    void setLabelTextColorFocused(ColorStateList color)
    Set the color of label when the view is focused
    void setLabelTextColorUnFocused(ColorStateList color)
    Set the color of label when the view is not focused
    boolean setupErrorHelperView()
    Setup the error/helper field on the view
    boolean setupLabelView()
    Setup the label view on the view
    boolean shouldLayout(View v)
    Should layout the given view
    [Expand]
    Inherited Methods
    From class android.widget.LinearLayout
    From class android.view.ViewGroup
    From class android.view.View
    From class java.lang.Object
    From interface android.graphics.drawable.Drawable.Callback
    From interface android.view.KeyEvent.Callback
    From interface android.view.ViewManager
    From interface android.view.ViewParent
    From interface android.view.accessibility.AccessibilityEventSource
    From interface com.sap.cloud.mobile.fiori.formcell.FormCell
    From interface com.sap.cloud.mobile.fiori.formcell.InlineValidation
    From interface com.sap.cloud.mobile.fiori.formcell.SupportsHelperText
    From interface com.sap.cloud.mobile.fiori.formcell.SupportsKey

    XML Attributes

    FormCellMetadataLayout_android_clickable

    Related Methods

    FormCellMetadataLayout_android_enabled

    Related Methods

    FormCellMetadataLayout_android_focusable

    Related Methods

    FormCellMetadataLayout_errorEnabled

    Related Methods

    FormCellMetadataLayout_helperEnabled

    Related Methods

    FormCellMetadataLayout_label

    Related Methods

    FormCellMetadataLayout_labelEnabled

    Related Methods

    FormCellMetadataLayout_labelTextAppearance

    FormCellMetadataLayout_labelTextAppearanceFocused

    FormCellMetadataLayout_labelTextAppearanceUnFocused

    SwitchFormCell_displayValueTextAppearance

    Related Methods

    SwitchFormCell_key

    Related Methods

    SwitchFormCell_keyTextAppearance

    Related Methods

    SwitchFormCell_value

    Related Methods

    Fields

    protected CharSequence mErrorMessage

    protected int mErrorTextAppearance

    protected CharSequence mHelperText

    protected int mHelperTextAppearance

    protected int mHorizontalMargin

    protected boolean mIsInError

    protected boolean mIsTablet

    protected int mLabelTextAppearance

    protected int mLabelTextAppearanceUnFocused

    protected TextView mLabelTextView

    protected boolean mShouldAttachOrientationListener

    protected TextView mStatusView

    Public Constructors

    public SwitchFormCell (Context context)

    Construct a new SwitchFormCell with default styling, sets the CellType to WidgetType.SWITCH

    Parameters
    context context

    public SwitchFormCell (Context context, AttributeSet attrs)

    Construct a new SwitchFormCell with default styling, overriding the attributes for the control as requested, sets the CellType to WidgetType.SWITCH

    Parameters
    context context
    attrs attribute set

    Public Methods

    public void addView (View child, int index, ViewGroup.LayoutParams params)

    Add given view in the view

    Parameters
    child View
    index position at which the view has to be added
    params ViewGroup.LayoutParams

    public int getCellType ()

    Return the enum value corresponding to SwitchFormCell

    Returns
    • WidgetType type of the control which has implemented FormCell

    public CellValueChangeListener<Boolean> getCellValueChangeListener ()

    Return the value change handler of the control

    Returns
    • OnCellChangeListener - value change listener of the control

    public CharSequence getError ()

    Get the error

    Returns
    • CharSequence

    public TextView getErrorView ()

    public CharSequence getHelperText ()

    Get the helper text from the view

    Returns
    • CharSequence

    public CharSequence getKey ()

    Get the key of the Switch FormCell

    Returns
    • CharSequence

    public Boolean getValue ()

    Return the state of the Switch(True/False)

    Returns
    • Boolean value

    public boolean isEditable ()

    Get if the Switch FormCell is enabled

    Returns
    • boolean

    public boolean isErrorEnabled ()

    Is error enabled on the view

    Related XML Attributes
    Returns
    • boolean

    public boolean isHelperEnabled ()

    Set if the helper field is enabled on the view

    Related XML Attributes
    Returns
    • boolean

    public boolean isLabelEnabled ()

    Is the label field on the view is enabled

    Related XML Attributes
    Returns
    • boolean

    public boolean onInterceptTouchEvent (MotionEvent ev)

    public boolean performClick ()

    public void setCellValueChangeListener (CellValueChangeListener<Boolean> listener)

    public void setClickable (boolean clickable)

    Enable or disable clickable property on the view and all its children

    Parameters
    clickable boolean

    public void setEditable (boolean isEditable)

    Set if the Switch FormCell editable

    Parameters
    isEditable boolean

    public void setEnabled (boolean enabled)

    Enable or disable the view

    Parameters
    enabled boolean

    public void setError (CharSequence error)

    Set the error on the view. If the view is not error enabled then this API does not take any effect.

    Parameters
    error CharSequence

    public void setErrorEnabled (boolean errorEnabled)

    Enable or disable the error field on the view

    Parameters
    errorEnabled boolean

    public void setErrorTextAppearance (int resId)

    Set the text appearance on the error

    Parameters
    resId style resource

    public void setFocusable (boolean focusable)

    Enable or disable focusable property on the view and all its children

    Parameters
    focusable boolean

    public void setHelperEnabled (boolean enabled)

    Enable or disable the helper field on the view

    Parameters
    enabled boolean

    public void setHelperText (CharSequence helperText)

    Set the helper text on the view

    Parameters
    helperText CharSequence

    public void setHelperTextAppearance (int textAppearance)

    Set the helper text appearance

    Parameters
    textAppearance style resource

    public void setKey (CharSequence keyName)

    Set the key of the switch FormCell

    Parameters
    keyName key of the property

    public void setKeyTextAppearance (int resId)

    Sets the text color, size, style, hint color, and highlight color for key from the specified TextAppearance resource.

    Related XML Attributes

    public void setLabelTextAppearanceUnFocused (int labelTextAppearanceUnFocused)

    Set the label text appearance when the view is not focused

    Parameters
    labelTextAppearanceUnFocused Style resource

    public void setOverrideKeyStyle (boolean overrideKeyStyle)

    Override the Key styling manually.

    Parameters
    overrideKeyStyle boolean

    public void setOverrideStatusStyle (boolean overrideStatusStyle)

    Override the status i.e. error and helper styling manually

    Parameters
    overrideStatusStyle boolean

    public void setShouldAttachOrientationListener (boolean shouldAttach)

    Determines if an OrientationEventListener should be attached.

    Parameters
    shouldAttach Whether the FormCell should consider attaching an OrientationEventListener or not

    public void setValue (Boolean value)

    Set the state of the switch whether is True or False

    Parameters
    value value of the property

    public void setValueTextAppearance (int resId)

    Sets the text color, size, style, hint color, and highlight color for value from the specified TextAppearance resource.

    Protected Methods

    protected void adjustMargins ()

    Calculate and set the margins for the cell's elements. Subclasses should override this method to suit their own needs.

    protected static boolean arrayContains (int[] array, int value)

    Check if the array contains the given property

    Parameters
    array array of integer
    value int
    Returns
    • boolean

    protected void drawableStateChanged ()

    Drawable state changed

    protected TextView generateTextView ()

    Generate the text view

    Returns
    • TextView

    protected ViewGroup.LayoutParams getDefaultLayoutParams ()

    protected CharSequence getLabel ()

    Get the label on the view

    Related XML Attributes
    Returns
    • CharSequence

    protected void onRestoreInstanceState (Parcelable state)

    protected Parcelable onSaveInstanceState ()

    protected void replaceStatusView ()

    Each time you add a new view, error/helper view has to be adjusted to be the last view in the layout

    protected void setLabel (CharSequence key)

    Set the label on the view

    Related XML Attributes
    Parameters
    key CharSequence
    See Also

    protected void setLabelEnabled (boolean labelEnabled)

    Enable or disable the label field on the view

    Parameters
    labelEnabled boolean

    protected void setLabelTextAppearance (int textAppearance)

    Set the text appearance on the label. This changes the appearance when the view is focused and unfocused

    Parameters
    textAppearance style resource

    protected void setLabelTextAppearanceFocused (int textAppearance)

    Set the text appearance on the label when the view is not focused

    Parameters
    textAppearance Style resource

    protected void setLabelTextColorError (ColorStateList color)

    Set the text color of the label for error mode

    Parameters
    color ColorStateList

    protected void setLabelTextColorFocused (ColorStateList color)

    Set the color of label when the view is focused

    Parameters
    color ColorStateList

    protected void setLabelTextColorUnFocused (ColorStateList color)

    Set the color of label when the view is not focused

    Parameters
    color ColorStateList

    protected boolean setupErrorHelperView ()

    Setup the error/helper field on the view

    Returns
    • boolean true: new view is created false:existing view is used

    protected boolean setupLabelView ()

    Setup the label view on the view

    Returns
    • boolean true: new view is created false:existing view is used

    protected boolean shouldLayout (View v)

    Should layout the given view

    Parameters
    v View
    Returns
    • boolean