public class PhoneTabSwitcherLayout extends AbstractTabSwitcherLayout implements PhoneDragTabsEventHandler.Callback
TabSwitcher
on smartphones.AbstractTabSwitcherLayout.AnimationListenerWrapper, AbstractTabSwitcherLayout.Callback, AbstractTabSwitcherLayout.InitialItemIterator, AbstractTabSwitcherLayout.InitialItemIteratorBuilder, AbstractTabSwitcherLayout.LayoutListenerWrapper
Constructor and Description |
---|
PhoneTabSwitcherLayout(TabSwitcher tabSwitcher,
TabSwitcherModel model,
PhoneArithmetics arithmetics,
TabSwitcherStyle style,
TouchEventDispatcher touchEventDispatcher)
Creates a new layout, which implements the functionality of a
TabSwitcher on
smartphones. |
Modifier and Type | Method and Description |
---|---|
protected float |
calculateAttachedPosition(int count)
Calculates and returns the position on the dragging axis, where the distance between an item
and its predecessor should have reached the maximum.
|
protected float |
calculateMaxEndPosition(int index)
The method, which is invoked on implementing subclasses in order to retrieve the maximum
position of a specific item, when dragging towards the end.
|
protected android.support.v4.util.Pair<java.lang.Float,State> |
calculatePositionAndStateWhenStackedAtEnd(int index)
The method, which is invoked on implementing subclasses in order to retrieve the position and
state of a specific item, when stacked at the end.
|
protected android.support.v4.util.Pair<java.lang.Float,State> |
calculatePositionAndStateWhenStackedAtStart(int count,
int index,
State predecessorState)
The method, which is invoked on implementing subclasses in order to retrieve the position and
state of a specific item, when stacked at the start.
|
protected float |
calculatePredecessorPosition(AbstractItem item,
AbstractItem successor)
Calculates the position of an item in relation to the position of its successor.
|
protected float |
calculateSuccessorPosition(AbstractItem item,
AbstractItem predecessor)
Calculates the position of an item in relation to the position of its predecessor.
|
protected de.mrapp.android.util.view.AbstractViewRecycler<Tab,java.lang.Void> |
getContentViewRecycler()
The method, which is invoked on implementing subclasses in order to retrieve the view
recycler, which allows to recycle the views, which are associated with tabs.
|
AbstractDragTabsEventHandler<?> |
getDragHandler()
The method, which is invoked on implementing subclasses in order to retrieve the drag
handler, which is used by the layout.
|
protected int |
getStackedTabCount()
The method, which is invoked on implementing subclasses in order to retrieve the number of
tabs, which are contained by a stack.
|
android.view.ViewGroup |
getTabContainer()
Returns the view group, which contains the tab switcher's tabs.
|
protected AbstractTabRecyclerAdapter |
getTabRecyclerAdapter()
The method, which is invoked on implementing subclasses in order to retrieve the adapter of
the view recycler, which allows to inflate the views, which are used to visualize the tabs.
|
protected de.mrapp.android.util.view.AttachedViewRecycler<AbstractItem,java.lang.Integer> |
getTabViewRecycler()
The method, which is invoked on implementing subclasses in order to retrieve the view
recycler, which allows to inflate the views, which are used to visualize the tabs.
|
android.support.v7.widget.Toolbar[] |
getToolbars()
Returns the toolbars, which are shown, when the tab switcher is shown.
|
protected void |
inflateAndUpdateView(AbstractItem item,
boolean dragging,
android.view.ViewTreeObserver.OnGlobalLayoutListener listener)
The method, which is invoked on implementing subclasses in order to inflate and update the
view, which is used to visualize a specific item.
|
protected boolean |
isOvershootingAtEnd(AbstractDragTabsEventHandler.DragState dragState,
AbstractItemIterator iterator)
The method, which is invoked on implementing subclasses in order to retrieve, whether the
items are overshooting at the end.
|
protected boolean |
isOvershootingAtStart()
The method, which is invoked on implementing subclasses in order to retrieve, whether the
items are overshooting at the start.
|
void |
onAllTabsAdded(int index,
Tab[] tabs,
int previousSelectedTabIndex,
int selectedTabIndex,
boolean selectionChanged,
Animation animation)
The method, which is invoked, when multiple tabs have been added to the model.
|
void |
onAllTabsRemoved(Tab[] tabs,
Animation animation)
The method, which is invoked, when all tabs have been removed from the tab switcher.
|
void |
onApplyPaddingToTabsChanged(boolean applyPaddingToTabs)
The method, which is invoked, when it has been changed, whether the padding of the tab
switcher is applied to the content of its tabs, or not.
|
void |
onDecoratorChanged(TabSwitcherDecorator decorator)
The method, which is invoked, when the decorator has been changed.
|
protected android.support.v4.util.Pair<java.lang.Integer,java.lang.Float> |
onDetachLayout(boolean tabsOnly)
The method, which is invoked on implementing subclasses in order to detach the layout.
|
void |
onEmptyViewChanged(android.view.View view,
long animationDuration)
The method, which is invoked, when the view, which is shown, when the tab switcher is
empty, has been changed.
|
void |
onGlobalLayout() |
protected void |
onInflateLayout(android.view.LayoutInflater inflater,
boolean tabsOnly)
The method, which is invoked on implementing subclasses in order to inflate the layout.
|
void |
onPaddingChanged(int left,
int top,
int right,
int bottom)
The method, which is invoked, when the padding has been changed.
|
void |
onPulledDown()
The method, which is notified, when the currently selected tab has been pulled down.
|
void |
onRevertEndOvershoot()
The method, which is invoked, when an overshoot at the end should be reverted.
|
void |
onRevertStartOvershoot()
The method, which is invoked, when an overshoot at the start should be reverted.
|
void |
onSelectionChanged(int previousIndex,
int index,
Tab selectedTab,
boolean switcherHidden)
The method, which is invoked, when the currently selected tab has been changed.
|
void |
onStartOvershoot(float position)
The method, which is invoked, when tabs are overshooting at the start.
|
void |
onSwipe(TabItem tabItem,
float distance)
The method, which is invoked, when a tab is swiped.
|
void |
onSwipeEnded(TabItem tabItem,
boolean remove,
float velocity)
The method, which is invoked, when swiping a tab ended.
|
void |
onSwitcherHidden()
The method, which is invoked, when the tab switcher has been hidden.
|
void |
onSwitcherShown()
The method, which is invoked, when the tab switcher has been shown.
|
void |
onSwitchingBetweenTabs(int selectedTabIndex,
float distance)
The method, which is invoked, when switching between neighboring tabs.
|
void |
onSwitchingBetweenTabsEnded(int selectedTabIndex,
int previousSelectedTabIndex,
boolean selectionChanged,
float velocity,
long animationDuration)
The method, which is invoked, when switching between neighboring tabs ended.
|
void |
onTabAdded(int index,
Tab tab,
int previousSelectedTabIndex,
int selectedTabIndex,
boolean selectionChanged,
boolean switcherVisibilityChanged,
Animation animation)
The method, which is invoked, when a tab has been added to the model.
|
void |
onTabRemoved(int index,
Tab tab,
int previousSelectedTabIndex,
int selectedTabIndex,
boolean selectionChanged,
Animation animation)
The method, which is invoked, when a tab has been removed from the model.
|
void |
onTiltOnEndOvershoot(float angle)
The method, which is invoked, when the tabs should be tilted when overshooting at the
end.
|
void |
onTiltOnStartOvershoot(float angle)
The method, which is invoked, when the tabs should be tilted when overshooting at the
start.
|
protected void |
updateView(AbstractItem item,
boolean dragging)
Updates the view, which is used to visualize a specific item.
|
calculateMinStartPosition, calculatePositionAndStateWhenStackedAtStart, clipPosition, clipPosition, detachLayout, getArithmetics, getContext, getFirstVisibleIndex, getItemCount, getLogger, getModel, getStackedTabSpacing, getStyle, getTabSwitcher, getToolbarMenu, inflateLayout, inflateOrRemoveView, inflateView, isAnimationRunning, isStackedAtStart, onAddedEventHandler, onAddTabButtonColorChanged, onAddTabButtonVisibilityChanged, onCancelFling, onClick, onCreateContentRecyclerAdapter, onDrag, onFling, onLogLevelChanged, onPressEnded, onPressStarted, onRemovedEventHandler, onTabBackgroundColorChanged, onTabCloseButtonIconChanged, onTabContentBackgroundColorChanged, onTabIconChanged, onTabProgressBarColorChanged, onTabTitleColorChanged, onToolbarMenuInflated, onToolbarNavigationIconChanged, onToolbarTitleChanged, onToolbarVisibilityChanged, secondLayoutPass, setCallback, setFirstVisibleIndex
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onCancelFling, onClick, onDrag, onFling, onPressEnded, onPressStarted
public PhoneTabSwitcherLayout(@NonNull TabSwitcher tabSwitcher, @NonNull TabSwitcherModel model, @NonNull PhoneArithmetics arithmetics, @NonNull TabSwitcherStyle style, @NonNull TouchEventDispatcher touchEventDispatcher)
TabSwitcher
on
smartphones.tabSwitcher
- The tab switcher, the layout belongs to, as an instance of the class TabSwitcher
. The tab switcher may not be nullmodel
- The model of the tab switcher, the layout belongs to, as an instance of the class
TabSwitcherModel
. The model may not be nullarithmetics
- The arithmetics, which should be used by the layout, as an instance of the class
PhoneArithmetics
. The arithmetics may not be nullstyle
- The style, which allows to retrieve style attributes of the tab switcher, as an
instance of the class TabSwitcherStyle
. The style may not be nulltouchEventDispatcher
- The dispatcher, which is used to dispatch touch events to event handlers, as an
instance of the class TouchEventDispatcher
. The dispatcher may not be nullpublic final AbstractDragTabsEventHandler<?> getDragHandler()
AbstractTabSwitcherLayout
getDragHandler
in class AbstractTabSwitcherLayout
AbstractDragTabsEventHandler
or null, if the drag handler has not been initialized yetprotected final void onInflateLayout(@NonNull android.view.LayoutInflater inflater, boolean tabsOnly)
AbstractTabSwitcherLayout
onInflateLayout
in class AbstractTabSwitcherLayout
inflater
- The layout inflater, which should be used, as an instance of the class LayoutInflater
. The layout inflater may not be nulltabsOnly
- True, if only the tabs should be inflated, false otherwise@Nullable protected final android.support.v4.util.Pair<java.lang.Integer,java.lang.Float> onDetachLayout(boolean tabsOnly)
AbstractTabSwitcherLayout
onDetachLayout
in class AbstractTabSwitcherLayout
tabsOnly
- True, if only the tabs should be detached, false otherwiseprotected final de.mrapp.android.util.view.AbstractViewRecycler<Tab,java.lang.Void> getContentViewRecycler()
AbstractTabSwitcherLayout
getContentViewRecycler
in class AbstractTabSwitcherLayout
protected final de.mrapp.android.util.view.AttachedViewRecycler<AbstractItem,java.lang.Integer> getTabViewRecycler()
AbstractTabSwitcherLayout
getTabViewRecycler
in class AbstractTabSwitcherLayout
protected final AbstractTabRecyclerAdapter getTabRecyclerAdapter()
AbstractTabSwitcherLayout
getTabRecyclerAdapter
in class AbstractTabSwitcherLayout
AbstractTabRecyclerAdapter
or
null, if the view recycler has not been initialized yetprotected final void updateView(@NonNull AbstractItem item, boolean dragging)
AbstractTabSwitcherLayout
updateView
in class AbstractTabSwitcherLayout
item
- The item, whose view should be updated, as an instance of the class AbstractItem
. The item may not be nulldragging
- True, if the item is currently being dragged, false otherwiseprotected final float calculateAttachedPosition(int count)
AbstractTabSwitcherLayout
calculateAttachedPosition
in class AbstractTabSwitcherLayout
count
- The total number of items, which are contained by the tab switcher, as an Integer
valueFloat
value or -1,
if no attached position is usedprotected final void inflateAndUpdateView(@NonNull AbstractItem item, boolean dragging, @Nullable android.view.ViewTreeObserver.OnGlobalLayoutListener listener)
AbstractTabSwitcherLayout
inflateAndUpdateView
in class AbstractTabSwitcherLayout
item
- The item, whose view should be inflated, as an instance of the class AbstractItem
. The item may not be nulldragging
- True, if the view is currently being dragged, false otherwiselistener
- The layout listener, which should be notified, when the view has been inflated, as an
instance of the type ViewTreeObserver.OnGlobalLayoutListener
or null, if no listener should be
notifiedprotected final int getStackedTabCount()
AbstractTabSwitcherLayout
getStackedTabCount
in class AbstractTabSwitcherLayout
Integer
value@NonNull protected final android.support.v4.util.Pair<java.lang.Float,State> calculatePositionAndStateWhenStackedAtStart(int count, int index, @Nullable State predecessorState)
AbstractTabSwitcherLayout
calculatePositionAndStateWhenStackedAtStart
in class AbstractTabSwitcherLayout
count
- The total number of items, which are currently contained by the tab switcher, as an
Integer
valueindex
- The index of the item, whose position and state should be returned, as an Integer
valuepredecessorState
- The state of the predecessor of the given item as a value of the enum State
or null, if the item does not have a predecessor@NonNull protected final android.support.v4.util.Pair<java.lang.Float,State> calculatePositionAndStateWhenStackedAtEnd(int index)
AbstractTabSwitcherLayout
calculatePositionAndStateWhenStackedAtEnd
in class AbstractTabSwitcherLayout
index
- The index of the item, whose position and state should be returned, as an Integer
valueprotected final boolean isOvershootingAtStart()
AbstractTabSwitcherLayout
isOvershootingAtStart
in class AbstractTabSwitcherLayout
protected final boolean isOvershootingAtEnd(@NonNull AbstractDragTabsEventHandler.DragState dragState, @NonNull AbstractItemIterator iterator)
AbstractTabSwitcherLayout
isOvershootingAtEnd
in class AbstractTabSwitcherLayout
dragState
- The current drag state as an instance of the enum AbstractDragTabsEventHandler.DragState
. The drag state
may not be nulliterator
- An iterator, which allows to iterate the items, which are contained by the tab
switcher, as an instance of the class AbstractItemIterator
. The iterator may
not be nullprotected final float calculateMaxEndPosition(int index)
AbstractTabSwitcherLayout
calculateMaxEndPosition
in class AbstractTabSwitcherLayout
index
- The index of the item, whose position should be calculated, as an Integer
valueFloat
value or -1, if no
maximum position is availableprotected final float calculateSuccessorPosition(@NonNull AbstractItem item, @NonNull AbstractItem predecessor)
AbstractTabSwitcherLayout
calculateSuccessorPosition
in class AbstractTabSwitcherLayout
item
- The item, whose position should be calculated, as an instance of the class AbstractItem
. The item may not be nullpredecessor
- The predecessor as an instance of the class AbstractItem
. The predecessor may
not be nullFloat
valueprotected final float calculatePredecessorPosition(@NonNull AbstractItem item, @NonNull AbstractItem successor)
AbstractTabSwitcherLayout
calculatePredecessorPosition
in class AbstractTabSwitcherLayout
item
- The item, whose position should be calculated, as an instance of the class AbstractItem
. The item may not be nullsuccessor
- The successor as an instance of the class AbstractItem
. The successor may not
be nullFloat
value@Nullable public final android.view.ViewGroup getTabContainer()
TabSwitcherLayout
getTabContainer
in interface TabSwitcherLayout
ViewGroup
or null, if the view has not been laid out yet@NonNull public final android.support.v7.widget.Toolbar[] getToolbars()
TabSwitcherLayout
TabSwitcher.PRIMARY_TOOLBAR_INDEX
of the returned array corresponds to the primary toolbar and the index TabSwitcher.SECONDARY_TOOLBAR_INDEX
corresponds to the secondary toolbar.getToolbars
in interface TabSwitcherLayout
public final void onDecoratorChanged(@NonNull TabSwitcherDecorator decorator)
Model.Listener
onDecoratorChanged
in interface Model.Listener
onDecoratorChanged
in class AbstractTabSwitcherLayout
decorator
- The decorator, which has been set, as an instance of the class TabSwitcherDecorator
. The decorator may not be nullpublic final void onSwitcherShown()
Model.Listener
onSwitcherShown
in interface Model.Listener
onSwitcherShown
in class AbstractTabSwitcherLayout
public final void onSwitcherHidden()
Model.Listener
onSwitcherHidden
in interface Model.Listener
onSwitcherHidden
in class AbstractTabSwitcherLayout
public final void onSelectionChanged(int previousIndex, int index, @Nullable Tab selectedTab, boolean switcherHidden)
Model.Listener
onSelectionChanged
in interface Model.Listener
previousIndex
- The index of the previously selected tab as an Integer
value or -1, if no
tab was previously selectedindex
- The index of the currently selected tab as an Integer
value or -1, if the
tab switcher does not contain any tabsselectedTab
- The currently selected tab as an instance of the class Tab
or null, if
the tab switcher does not contain any tabsswitcherHidden
- True, if selecting the tab caused the tab switcher to be hidden, false otherwisepublic final void onTabAdded(int index, @NonNull Tab tab, int previousSelectedTabIndex, int selectedTabIndex, boolean selectionChanged, boolean switcherVisibilityChanged, @NonNull Animation animation)
Model.Listener
onTabAdded
in interface Model.Listener
index
- The index of the tab, which has been added, as an Integer
valuetab
- The tab, which has been added, as an instance of the class Tab
. The tab
may not be nullpreviousSelectedTabIndex
- The index of the previously selected tab as an Integer
value or -1, if no
tab was selectedselectedTabIndex
- The index of the currently selected tab as an Integer
value or -1, if the
tab switcher does not contain any tabsselectionChanged
- True, if the selection has changed, false otherwiseswitcherVisibilityChanged
- True, if adding the tab caused the visibility of the tab switcher to be changed,
false otherwiseanimation
- The animation, which has been used to add the tab, as an instance of the class
Animation
. The animation may not be nullpublic final void onAllTabsAdded(int index, @NonNull Tab[] tabs, int previousSelectedTabIndex, int selectedTabIndex, boolean selectionChanged, @NonNull Animation animation)
Model.Listener
onAllTabsAdded
in interface Model.Listener
index
- The index of the first tab, which has been added, as an Integer
valuetabs
- An array, which contains the tabs, which have been added, as an array of the type
Tab
or an empty array, if no tabs have been addedpreviousSelectedTabIndex
- The index of the previously selected tab as an Integer
value or -1, if no
tab was selectedselectedTabIndex
- The index of the currently selected tab as an Integer
value or -1, if the
tab switcher does not contain any tabsselectionChanged
- True, if the selection has changed, false otherwiseanimation
- The animation, which has been used to add the tabs, as an instance of the class
Animation
. The animation may not be nullpublic final void onTabRemoved(int index, @NonNull Tab tab, int previousSelectedTabIndex, int selectedTabIndex, boolean selectionChanged, @NonNull Animation animation)
Model.Listener
onTabRemoved
in interface Model.Listener
index
- The index of the tab, which has been removed, as an Integer
valuetab
- The tab, which has been removed, as an instance of the class Tab
. The tab
may not be nullpreviousSelectedTabIndex
- The index of the previously selected tab as an Integer
value or -1, if no
tab was selectedselectedTabIndex
- The index of the currently selected tab as an Integer
value or -1, if the
tab switcher does not contain any tabsselectionChanged
- True, if the selection changed, false otherwiseanimation
- The animation, which has been used to remove the tab, as an instance of the class
Animation
. The animation may not be nullpublic final void onAllTabsRemoved(@NonNull Tab[] tabs, @NonNull Animation animation)
Model.Listener
onAllTabsRemoved
in interface Model.Listener
tabs
- An array, which contains the tabs, which have been removed, as an array of the
type Tab
or an empty array, if no tabs have been removedanimation
- The animation, which has been used to remove the tabs, as an instance of the
class Animation
. The animation may not be nullpublic final void onPaddingChanged(int left, int top, int right, int bottom)
Model.Listener
onPaddingChanged
in interface Model.Listener
left
- The left padding, which has been set, in pixels as an Integer
valuetop
- The top padding, which has been set, in pixels as an Integer
valueright
- The right padding, which has been set, in pixels as an Integer
valuebottom
- The bottom padding, which has been set, in pixels as an Integer
valuepublic final void onApplyPaddingToTabsChanged(boolean applyPaddingToTabs)
Model.Listener
onApplyPaddingToTabsChanged
in interface Model.Listener
applyPaddingToTabs
- True, if the padding of the tab switcher is applied to the content of its tabs,
false otherwisepublic final void onEmptyViewChanged(@Nullable android.view.View view, long animationDuration)
Model.Listener
onEmptyViewChanged
in interface Model.Listener
view
- The view, which has been set, as an instance of the class View
or null,
if no view should be shown, when the tab switcher is emptyanimationDuration
- The duration of the fade animation, which is used to show or hide the view, in
milliseconds as a Long
value. The duration must be at least 0 or -1, if
the default duration should be usedpublic final void onGlobalLayout()
onGlobalLayout
in interface android.view.ViewTreeObserver.OnGlobalLayoutListener
public final void onRevertStartOvershoot()
AbstractDragTabsEventHandler.Callback
onRevertStartOvershoot
in interface AbstractDragTabsEventHandler.Callback
onRevertStartOvershoot
in class AbstractTabSwitcherLayout
public final void onRevertEndOvershoot()
AbstractDragTabsEventHandler.Callback
onRevertEndOvershoot
in interface AbstractDragTabsEventHandler.Callback
onRevertEndOvershoot
in class AbstractTabSwitcherLayout
public final void onStartOvershoot(float position)
PhoneDragTabsEventHandler.Callback
onStartOvershoot
in interface PhoneDragTabsEventHandler.Callback
position
- The position of the first tab in pixels as a Float
valuepublic final void onTiltOnStartOvershoot(float angle)
PhoneDragTabsEventHandler.Callback
onTiltOnStartOvershoot
in interface PhoneDragTabsEventHandler.Callback
angle
- The angle, the tabs should be tilted by, in degrees as a Float
valuepublic final void onTiltOnEndOvershoot(float angle)
PhoneDragTabsEventHandler.Callback
onTiltOnEndOvershoot
in interface PhoneDragTabsEventHandler.Callback
angle
- The angle, the tabs should be tilted by, in degrees as a Float
valuepublic final void onSwipe(@NonNull TabItem tabItem, float distance)
AbstractDragTabsEventHandler.Callback
onSwipe
in interface AbstractDragTabsEventHandler.Callback
onSwipe
in class AbstractTabSwitcherLayout
tabItem
- The tab item, which corresponds to the swiped tab, as an instance of the class
TabItem
. The tab item may not be nulldistance
- The distance, the tab is swiped by, in pixels as a Float
valuepublic final void onSwipeEnded(@NonNull TabItem tabItem, boolean remove, float velocity)
AbstractDragTabsEventHandler.Callback
onSwipeEnded
in interface AbstractDragTabsEventHandler.Callback
onSwipeEnded
in class AbstractTabSwitcherLayout
tabItem
- The tab item, which corresponds to the swiped tab, as an instance of the class
TabItem
. The tab item may not be nullremove
- True, if the tab should be removed, false otherwisevelocity
- The velocity of the swipe gesture in pixels per second as a Float
valuepublic final void onSwitchingBetweenTabs(int selectedTabIndex, float distance)
SwipeGestureEventHandler.Callback
onSwitchingBetweenTabs
in interface SwipeGestureEventHandler.Callback
selectedTabIndex
- The index of the currently selected tab as an Integer
valuedistance
- The distance, the currently selected tab is swiped by, in pixels as a Float
valuepublic final void onSwitchingBetweenTabsEnded(int selectedTabIndex, int previousSelectedTabIndex, boolean selectionChanged, float velocity, long animationDuration)
SwipeGestureEventHandler.Callback
onSwitchingBetweenTabsEnded
in interface SwipeGestureEventHandler.Callback
selectedTabIndex
- The index of the tab, which should become selected, as an Integer
valuepreviousSelectedTabIndex
- The index of the previously selected tab as an Integer
valueselectionChanged
- True, if the selection has changed, false otherwisevelocity
- The velocity of the swipe gesture in pixels per second as a Float
valueanimationDuration
- The duration of the swipe animation in milliseconds as a Long
valuepublic final void onPulledDown()
PullDownGestureEventHandler.Callback
onPulledDown
in interface PullDownGestureEventHandler.Callback
onPulledDown
in class AbstractTabSwitcherLayout