public class

TextColumnSpec

extends Object
implements ColumnSpec OnStyleChangedListener
java.lang.Object
   ↳ com.shinobicontrols.grids.supplement.TextColumnSpec

Class Overview

A convenience ColumnSpec that deals with textual data and places it in android.widget.TextViews. A PropertyBinder, parametrized by CharSequence, is required in order to provide the text for the TextViews.

By default it creates several styles and sets itself as a listener for changes to those styles, refreshing the grid each time a change is made. New style objects can be set on the grid and will cause an immediate redraw but this TextColumnSpec must be set as the styles' OnStyleChangedListener for any further changes to have any effect.

Summary

Fields
protected Column.Callback callback

The Callback providing controlled access to the Column this ColumnSpec describes.

Public Constructors
TextColumnSpec(PropertyBinder<CharSequence> propertyBinder)

Creates a new TextColumnSpec with the given PropertyBinder, which provides the text for the onBindViewHolder(RecyclerView.ViewHolder, int) method to place into the TextViews.

TextColumnSpec(CharSequence columnTitle, PropertyBinder<CharSequence> propertyBinder)

Creates a new TextColumnSpec with the given title and PropertyBinder, which provides the text for the onBindViewHolder(RecyclerView.ViewHolder, int) method to place into the TextViews.

Public Methods
Parcelable createParcelable()
Creates a Parcelable which may be used to save the state of this Column.
TextColumnStyle getAlternateStyle()

Returns the TextColumnStyle that is used to style the TextViews of the alternate rows within the Column this ColumnSpec relates to.

CharSequence getColumnTitle()

Returns the title given to this ColumnSpec.

TextColumnStyle getDefaultStyle()

Returns the TextColumnStyle that is used to style the TextViews within the Column this ColumnSpec relates to.

int getHeaderItemViewType()

Returns the itemViewType for the header of this TextColumnSpec - this is sg_header_text_view.

TextColumnStyle getHeaderStyle()

Returns the TextColumnStyle that is used to style the TextViews of the header within the Column this ColumnSpec relates to.

int getItemViewType(int rowIndex)

Returns the itemViewType for this TextColumnSpec - this is sg_text_view and is applicable for every row in the column.

PropertyBinder<CharSequence> getPropertyBinder()

Returns the PropertyBinder for this TextColumnSpec.

TextColumnStyle getSelectedStyle()

Returns the TextColumnStyle that is used to style the TextViews of the selected items within the Column this ColumnSpec relates to.

Integer getWidth()
Gets the width, in pixels which the Column which this ColumnSpec defines should adopt, the next time it is laid out.
boolean hasHeader()

Returns true if this ColumnSpec was given a non-null columnTitle when instantiated, false otherwise.

void initialize(Column.Callback callback)

Called when the Column is created, this method gives this ColumnSpec an opportunity to hold a reference to a callback object that provides controlled access to the Column via a number of useful methods.

void onBindHeaderViewHolder(RecyclerView.ViewHolder holder)

Binds the columnTitle for this TextColumnSpec to the TextView inside a HeaderTextViewHolder.

void onBindViewHolder(RecyclerView.ViewHolder holder, int rowIndex)

Binds the CharSequence returned from this TextColumnSpec's PropertyBinder to the TextView inside a TextViewHolder.

void onColumnAdded(Context context)

Notifies this ColumnSpec that the Column it belongs to has been added to a ShinobiGridView.

void onStyleChanged()

Called when the style has changed.

void restoreState(Parcelable state)
Called by the ShinobiGridView during the recreation of this Column to restore its state to what it was, prior to its destruction.
void saveState(Parcelable state)
Called by the ShinobiGridView to retrieve instance state of this Column before it is destroyed, so that it can be restored at some time in the future.
void setAlternateStyle(TextColumnStyle alternateStyle)

Sets the style for each item on the alternate rows within this ColumnSpec.

void setDefaultStyle(TextColumnStyle defaultStyle)

Sets the style for each item on the even rows within this ColumnSpec.

void setHeaderStyle(TextColumnStyle headerStyle)

Sets the style for the item on the header row within this ColumnSpec.

void setSelectedStyle(TextColumnStyle selectedStyle)

Sets the style for each selected item within this ColumnSpec.

void setWidth(Integer width)
Sets the width, in pixels which the Column which this TextColumnSpec defines should adopt, the next time it is laid out.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.shinobicontrols.grids.core.ColumnSpec
From interface com.shinobicontrols.grids.supplement.OnStyleChangedListener

Fields

protected Column.Callback callback

The Callback providing controlled access to the Column this ColumnSpec describes. It has a number of useful methods including the notifyDataSetChanged() method which can be used to notify the ShinobiGridView that the visual appearance of the items in the Column this ColumnSpec describes has changed.

This reference is set in the initialize(Column.Callback) method and so when subclassing this TextColumnSpec, if you do not call the super implementation of the initialize() method this will be null.

Public Constructors

public TextColumnSpec (PropertyBinder<CharSequence> propertyBinder)

Creates a new TextColumnSpec with the given PropertyBinder, which provides the text for the onBindViewHolder(RecyclerView.ViewHolder, int) method to place into the TextViews.

Parameters
propertyBinder the PropertyBinder that provides the text to be bound to the TextViews given to the Column

public TextColumnSpec (CharSequence columnTitle, PropertyBinder<CharSequence> propertyBinder)

Creates a new TextColumnSpec with the given title and PropertyBinder, which provides the text for the onBindViewHolder(RecyclerView.ViewHolder, int) method to place into the TextViews.

Parameters
columnTitle the title for this Column
propertyBinder the PropertyBinder that provides the text to be bound to the TextViews given to the Column

Public Methods

public Parcelable createParcelable ()

Creates a Parcelable which may be used to save the state of this Column. This method is typically used by the ShinobiGridView prior to the destruction of this Column.

Returns
  • the Parcelable which may be used to save the state of this Column

public TextColumnStyle getAlternateStyle ()

Returns the TextColumnStyle that is used to style the TextViews of the alternate rows within the Column this ColumnSpec relates to.

Returns
  • the TextColumnStyle that is used to style the TextViews of the alternate rows

public CharSequence getColumnTitle ()

Returns the title given to this ColumnSpec. May be null.

Returns
  • the title for this ColumnSpec, may be null

public TextColumnStyle getDefaultStyle ()

Returns the TextColumnStyle that is used to style the TextViews within the Column this ColumnSpec relates to.

Returns

public int getHeaderItemViewType ()

Returns the itemViewType for the header of this TextColumnSpec - this is sg_header_text_view.

Returns
  • the itemViewType for the header of this TextColumnSpec

public TextColumnStyle getHeaderStyle ()

Returns the TextColumnStyle that is used to style the TextViews of the header within the Column this ColumnSpec relates to.

Returns

public int getItemViewType (int rowIndex)

Returns the itemViewType for this TextColumnSpec - this is sg_text_view and is applicable for every row in the column.

Parameters
rowIndex the zero-based index of the row in the grid that the item being bound to the given holder is on, as the same itemViewType is returned for every row in this TextColumnSpec the rowIndex is not used
Returns
  • the itemViewType for this TextColumnSpec

public PropertyBinder<CharSequence> getPropertyBinder ()

Returns the PropertyBinder for this TextColumnSpec. This provides the text for the onBindViewHolder(RecyclerView.ViewHolder, int) method to place into the TextViews.

Returns
  • the PropertyBinder for this TextColumnSpec

public TextColumnStyle getSelectedStyle ()

Returns the TextColumnStyle that is used to style the TextViews of the selected items within the Column this ColumnSpec relates to.

Returns
  • the TextColumnStyle that is used to style the TextViews of the selected items

public Integer getWidth ()

Gets the width, in pixels which the Column which this ColumnSpec defines should adopt, the next time it is laid out.

Note: by returning a value other than null any default or minimum column width values set on the ShinobiGridView, for the Column which this ColumnSpec defines are overridden. Conversely, returning a null value will result in the width of the Column which this ColumnSpec defines, being set to the defaultColumnWidth, or minimumColumnWidth, if set. If neither are set, then a column width which allows the ShinobiGridView to use all available space will be used.

Returns
  • the width, in pixels which the Column which this ColumnSpec defines should adopt, the next time it is laid out

public boolean hasHeader ()

Returns true if this ColumnSpec was given a non-null columnTitle when instantiated, false otherwise.

Returns
  • true if this ColumnSpec was given a non-null columnTitle when instantiated, false otherwise

public void initialize (Column.Callback callback)

Called when the Column is created, this method gives this ColumnSpec an opportunity to hold a reference to a callback object that provides controlled access to the Column via a number of useful methods.

Parameters
callback the Callback into the Column which contains a number of useful methods

public void onBindHeaderViewHolder (RecyclerView.ViewHolder holder)

Binds the columnTitle for this TextColumnSpec to the TextView inside a HeaderTextViewHolder.

Parameters
holder the ViewHolder containing the item view for the Column's header

public void onBindViewHolder (RecyclerView.ViewHolder holder, int rowIndex)

Binds the CharSequence returned from this TextColumnSpec's PropertyBinder to the TextView inside a TextViewHolder.

Parameters
holder the ViewHolder containing an item view that is suitable for the given rowIndex - this can be safely cast to a TextViewHolder
rowIndex the zero-based index of the row in the grid that the item being bound to the given holder is on

public void onColumnAdded (Context context)

Notifies this ColumnSpec that the Column it belongs to has been added to a ShinobiGridView. The current Context is passed in allowing the retrieval of attributes in the theme that has been applied to the grid.

Parameters
context the current context of the grid the Column has been added to providing access to attributes in the current theme

public void onStyleChanged ()

Called when the style has changed.

public void restoreState (Parcelable state)

Called by the ShinobiGridView during the recreation of this Column to restore its state to what it was, prior to its destruction.

This method provides a convenient place restore custom state, such as width.

Parameters
state the Parcelable containing the state of this Column

public void saveState (Parcelable state)

Called by the ShinobiGridView to retrieve instance state of this Column before it is destroyed, so that it can be restored at some time in the future.

This method provides a convenient place save custom state, such as width.

Parameters
state the Parcelable containing the state of this Column

public void setAlternateStyle (TextColumnStyle alternateStyle)

Sets the style for each item on the alternate rows within this ColumnSpec. If the Column this ColumnSpec defines is added to the grid then this setting the style will cause an automatic redraw. For subsequent changes to the style to cause the grid to redraw then this ColumnSpec needs to be added as a listener to the style using the setOnStyleChangedListener(OnStyleChangedListener) method.

It is not possible to set a null TextColumnStyle on this TextColumnSpec; attempting to do so will result in an IllegalArgumentException being thrown.

Parameters
alternateStyle the style for each item on the alternate rows within this ColumnSpec

public void setDefaultStyle (TextColumnStyle defaultStyle)

Sets the style for each item on the even rows within this ColumnSpec. If the Column this ColumnSpec defines is added to the grid then this setting the style will cause an automatic redraw. For subsequent changes to the style to cause the grid to redraw then this ColumnSpec needs to be added as a listener to the style using the setOnStyleChangedListener(OnStyleChangedListener) method.

It is not possible to set a null TextColumnStyle on this TextColumnSpec; attempting to do so will result in an IllegalArgumentException being thrown.

Parameters
defaultStyle the style for each item on the even rows within this ColumnSpec

public void setHeaderStyle (TextColumnStyle headerStyle)

Sets the style for the item on the header row within this ColumnSpec. If the Column this ColumnSpec defines is added to the grid then this setting the style will cause an automatic redraw. For subsequent changes to the style to cause the grid to redraw then this ColumnSpec needs to be added as a listener to the style using the setOnStyleChangedListener(OnStyleChangedListener) method.

It is not possible to set a null TextColumnStyle on this TextColumnSpec; attempting to do so will result in an IllegalArgumentException being thrown.

Parameters
headerStyle the style for the item on the header row within this ColumnSpec
See Also

public void setSelectedStyle (TextColumnStyle selectedStyle)

Sets the style for each selected item within this ColumnSpec. If the Column this ColumnSpec defines is added to the grid then setting the style will cause an automatic redraw. For subsequent changes to the style to cause the grid to redraw then this ColumnSpec needs to be added as a listener to the style using the setOnStyleChangedListener(OnStyleChangedListener) method.

It is not possible to set a null TextColumnStyle on this TextColumnSpec; attempting to do so will result in an IllegalArgumentException being thrown.

Parameters
selectedStyle the style for each selected item within this ColumnSpec

public void setWidth (Integer width)

Sets the width, in pixels which the Column which this TextColumnSpec defines should adopt, the next time it is laid out. If the Column this ColumnSpec defines is added to the grid then setting the width will cause an automatic redraw.

Note: by setting a value other than null any default or minimum column width values set on the ShinobiGridView, for the Column which this TextColumnSpec defines are overridden. Conversely, setting a null value will result in the width of the Column which this TextColumnSpec defines, being set to the defaultColumnWidth, or minimumColumnWidth, if set. If neither are set, then a column width which allows the ShinobiGridView to use all available space will be used.

Parameters
width the width, in pixels which the Column which this TextColumnSpec defines should adopt, the next time it is laid out. Can be null or a positive integer. If a negative value is given, an IllegalArgumentException will be thrown