Package org.robolectric.shadows
Class ShadowView
- java.lang.Object
-
- org.robolectric.shadows.ShadowView
-
- Direct Known Subclasses:
ShadowProgressBar
,ShadowSurfaceView
,ShadowTextView
,ShadowViewGroup
@Implements(android.view.View.class) public class ShadowView extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowView.WindowIdHelper
-
Field Summary
Fields Modifier and Type Field Description protected AttributeSet
attributeSet
protected View
realView
Point
scrollToCoordinates
protected org.robolectric.shadows.ShadowView._View_
viewReflector
-
Constructor Summary
Constructors Constructor Description ShadowView()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
__constructor__(Context context, AttributeSet attributeSet, int defStyle)
protected void
__constructor__(Context context, AttributeSet attributeSet, int defStyleAttr, int defStyleRes)
static void
addGlobalPerformClickListener(View.OnClickListener listener)
Registers anView.OnClickListener
to theShadowView
.static void
addGlobalPerformLongClickListener(View.OnLongClickListener listener)
Registers anView.OnLongClickListener
to theShadowView
.protected void
addOnAttachStateChangeListener(View.OnAttachStateChangeListener onAttachStateChangeListener)
protected void
addOnLayoutChangeListener(View.OnLayoutChangeListener onLayoutChangeListener)
void
callOnAttachedToWindow()
void
callOnDetachedFromWindow()
boolean
checkedPerformClick()
Deprecated.- Please use Espresso for View interactions.protected void
clearAnimation()
void
clearWasInvalidated()
Clears the wasInvalidated flagstatic boolean
clickOn(View view)
Deprecated.Please use Espresso for view interactionsboolean
didRequestLayout()
protected void
draw(Canvas canvas)
void
dump()
Deprecated.- Please useandroidx.test.espresso.util.HumanReadables#describe(View)
static void
dump(View view)
Deprecated.- Please useandroidx.test.espresso.util.HumanReadables#describe(View)
void
dump(PrintStream out, int indent)
Deprecated.- Please useandroidx.test.espresso.util.HumanReadables#describe(View)
protected void
dumpAttribute(PrintStream out, String name, String value)
Deprecated.protected void
dumpAttributes(PrintStream out)
Deprecated.protected void
dumpFirstPart(PrintStream out, int indent)
Deprecated.protected void
dumpIndent(PrintStream out, int indent)
Deprecated.protected boolean
getGlobalVisibleRect(Rect rect, Point globalOffset)
MotionEvent
getLastTouchEvent()
protected int
getLayerType()
protected void
getLocationOnScreen(int[] outLocation)
Set<View.OnAttachStateChangeListener>
getOnAttachStateChangeListeners()
View.OnClickListener
getOnClickListener()
View.OnCreateContextMenuListener
getOnCreateContextMenuListener()
Set<View.OnLayoutChangeListener>
getOnLayoutChangeListeners()
View.OnLongClickListener
getOnLongClickListener()
View.OnSystemUiVisibilityChangeListener
getOnSystemUiVisibilityChangeListener()
View.OnTouchListener
getOnTouchListener()
protected int
getScrollX()
protected int
getScrollY()
int
getSourceLayoutResId()
Returns the layout resource id this view was inflated from.protected void
getWindowDisplayFrame(Rect outRect)
protected WindowId
getWindowId()
protected void
getWindowVisibleDisplayFrame(Rect outRect)
protected boolean
initialAwakenScrollBars()
String
innerText()
Returns a string representation of thisView
.static String
innerText(View view)
Returns the text contained within this view.protected void
invalidate()
protected boolean
isAttachedToWindow()
int
lastHapticFeedbackPerformed()
protected void
mapRectFromViewToScreenCoords(RectF rect, boolean clipToParent)
protected void
onLayout(boolean changed, int left, int top, int right, int bottom)
boolean
onLayoutWasCalled()
protected boolean
onTouchEvent(MotionEvent event)
protected boolean
performClick()
protected boolean
performHapticFeedback(int hapticFeedbackType)
protected boolean
performLongClick()
protected boolean
post(Runnable action)
protected boolean
postDelayed(Runnable action, long delayMills)
protected void
postInvalidateDelayed(long delayMilliseconds)
protected boolean
removeCallbacks(Runnable callback)
static void
removeGlobalPerformClickListener(View.OnClickListener listener)
Removes anView.OnClickListener
from theShadowView
.static void
removeGlobalPerformLongClickListener(View.OnLongClickListener listener)
Removes anView.OnLongClickListener
from theShadowView
.protected void
removeOnAttachStateChangeListener(View.OnAttachStateChangeListener onAttachStateChangeListener)
protected void
removeOnLayoutChangeListener(View.OnLayoutChangeListener onLayoutChangeListener)
protected void
requestLayout()
static void
reset()
protected void
scrollBy(int x, int y)
protected void
scrollTo(int x, int y)
protected void
setAnimation(Animation animation)
void
setDidRequestLayout(boolean didRequestLayout)
void
setGlobalVisibleRect(Rect rect)
protected void
setLayerType(int layerType, Paint paint)
void
setMyParent(ViewParent viewParent)
protected void
setOnClickListener(View.OnClickListener onClickListener)
protected void
setOnCreateContextMenuListener(View.OnCreateContextMenuListener onCreateContextMenuListener)
protected void
setOnFocusChangeListener(View.OnFocusChangeListener l)
protected void
setOnLongClickListener(View.OnLongClickListener onLongClickListener)
protected void
setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener onSystemUiVisibilityChangeListener)
protected void
setOnTouchListener(View.OnTouchListener onTouchListener)
protected void
setScrollX(int scrollX)
protected void
setScrollY(int scrollY)
void
setViewFocus(boolean hasFocus)
static String
visualize(View view)
Returns a textual representation of the appearance of the object.boolean
wasInvalidated()
-
-
-
Field Detail
-
realView
@RealObject protected View realView
-
viewReflector
@ReflectorObject protected org.robolectric.shadows.ShadowView._View_ viewReflector
-
attributeSet
protected AttributeSet attributeSet
-
scrollToCoordinates
public Point scrollToCoordinates
-
-
Method Detail
-
clickOn
@Deprecated public static boolean clickOn(View view)
Deprecated.Please use Espresso for view interactionsCallsperformClick()
on aView
after ensuring that it and its ancestors are visible and that it is enabled.- Parameters:
view
- the view to click on- Returns:
- true if
View.OnClickListener
s were found and fired, false otherwise. - Throws:
RuntimeException
- if the preconditions are not met.
-
visualize
public static String visualize(View view)
Returns a textual representation of the appearance of the object.- Parameters:
view
- the view to visualize- Returns:
- Textual representation of the appearance of the object.
-
dump
@Deprecated public static void dump(View view)
Deprecated.- Please useandroidx.test.espresso.util.HumanReadables#describe(View)
Emits an xml-like representation of the view to System.out.- Parameters:
view
- the view to dump.
-
innerText
public static String innerText(View view)
Returns the text contained within this view.- Parameters:
view
- the view to scan for text- Returns:
- Text contained within this view.
-
__constructor__
@Implementation(maxSdk=19) protected void __constructor__(Context context, AttributeSet attributeSet, int defStyle)
-
__constructor__
@Implementation(minSdk=20) protected void __constructor__(Context context, AttributeSet attributeSet, int defStyleAttr, int defStyleRes)
-
setLayerType
@Implementation protected void setLayerType(int layerType, Paint paint)
-
setOnFocusChangeListener
@Implementation protected void setOnFocusChangeListener(View.OnFocusChangeListener l)
-
setOnClickListener
@Implementation protected void setOnClickListener(View.OnClickListener onClickListener)
-
setOnLongClickListener
@Implementation protected void setOnLongClickListener(View.OnLongClickListener onLongClickListener)
-
setOnSystemUiVisibilityChangeListener
@Implementation protected void setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener onSystemUiVisibilityChangeListener)
-
setOnCreateContextMenuListener
@Implementation protected void setOnCreateContextMenuListener(View.OnCreateContextMenuListener onCreateContextMenuListener)
-
addOnAttachStateChangeListener
@Implementation protected void addOnAttachStateChangeListener(View.OnAttachStateChangeListener onAttachStateChangeListener)
-
removeOnAttachStateChangeListener
@Implementation protected void removeOnAttachStateChangeListener(View.OnAttachStateChangeListener onAttachStateChangeListener)
-
addOnLayoutChangeListener
@Implementation protected void addOnLayoutChangeListener(View.OnLayoutChangeListener onLayoutChangeListener)
-
removeOnLayoutChangeListener
@Implementation protected void removeOnLayoutChangeListener(View.OnLayoutChangeListener onLayoutChangeListener)
-
draw
@Implementation protected void draw(Canvas canvas)
-
onLayout
@Implementation protected void onLayout(boolean changed, int left, int top, int right, int bottom)
-
onLayoutWasCalled
public boolean onLayoutWasCalled()
-
requestLayout
@Implementation protected void requestLayout()
-
performClick
@Implementation protected boolean performClick()
-
addGlobalPerformClickListener
public static void addGlobalPerformClickListener(View.OnClickListener listener)
Registers anView.OnClickListener
to theShadowView
.- Parameters:
listener
- TheView.OnClickListener
to be registered.
-
removeGlobalPerformClickListener
public static void removeGlobalPerformClickListener(View.OnClickListener listener)
Removes anView.OnClickListener
from theShadowView
.- Parameters:
listener
- TheView.OnClickListener
to be removed.
-
performLongClick
@Implementation protected boolean performLongClick()
-
addGlobalPerformLongClickListener
public static void addGlobalPerformLongClickListener(View.OnLongClickListener listener)
Registers anView.OnLongClickListener
to theShadowView
.- Parameters:
listener
- TheView.OnLongClickListener
to be registered.
-
removeGlobalPerformLongClickListener
public static void removeGlobalPerformLongClickListener(View.OnLongClickListener listener)
Removes anView.OnLongClickListener
from theShadowView
.- Parameters:
listener
- TheView.OnLongClickListener
to be removed.
-
reset
@Resetter public static void reset()
-
didRequestLayout
public boolean didRequestLayout()
-
setDidRequestLayout
public void setDidRequestLayout(boolean didRequestLayout)
-
setViewFocus
public void setViewFocus(boolean hasFocus)
-
invalidate
@Implementation protected void invalidate()
-
onTouchEvent
@Implementation protected boolean onTouchEvent(MotionEvent event)
-
setOnTouchListener
@Implementation protected void setOnTouchListener(View.OnTouchListener onTouchListener)
-
getLastTouchEvent
public MotionEvent getLastTouchEvent()
-
innerText
public String innerText()
Returns a string representation of thisView
. Unless overridden, it will be an empty string.Robolectric extension.
- Returns:
- String representation of this view.
-
dump
@Deprecated public void dump()
Deprecated.- Please useandroidx.test.espresso.util.HumanReadables#describe(View)
Dumps the status of thisView
toSystem.out
-
dump
@Deprecated public void dump(PrintStream out, int indent)
Deprecated.- Please useandroidx.test.espresso.util.HumanReadables#describe(View)
Dumps the status of thisView
toSystem.out
at the given indentation level- Parameters:
out
- Output stream.indent
- Indentation level.
-
dumpFirstPart
@Deprecated protected void dumpFirstPart(PrintStream out, int indent)
Deprecated.
-
dumpAttributes
@Deprecated protected void dumpAttributes(PrintStream out)
Deprecated.
-
dumpAttribute
@Deprecated protected void dumpAttribute(PrintStream out, String name, String value)
Deprecated.
-
dumpIndent
@Deprecated protected void dumpIndent(PrintStream out, int indent)
Deprecated.
-
wasInvalidated
public boolean wasInvalidated()
- Returns:
- whether or not
invalidate()
has been called
-
clearWasInvalidated
public void clearWasInvalidated()
Clears the wasInvalidated flag
-
checkedPerformClick
@Deprecated public boolean checkedPerformClick()
Deprecated.- Please use Espresso for View interactions.Utility method for clicking on views exposing testing scenarios that are not possible when using the actual app.If running with LooperMode PAUSED will also idle the main Looper.
- Returns:
- Return value of the underlying click operation.
- Throws:
RuntimeException
- if the view is disabled or if the view or any of its parents are not visible.
-
getOnTouchListener
public View.OnTouchListener getOnTouchListener()
- Returns:
- Touch listener, if set.
-
getOnClickListener
public View.OnClickListener getOnClickListener()
- Returns:
- Returns click listener, if set.
-
getOnLongClickListener
@Implementation(minSdk=30) public View.OnLongClickListener getOnLongClickListener()
- Returns:
- Returns long click listener, if set.
-
getOnSystemUiVisibilityChangeListener
public View.OnSystemUiVisibilityChangeListener getOnSystemUiVisibilityChangeListener()
- Returns:
- Returns system ui visibility change listener.
-
getOnCreateContextMenuListener
public View.OnCreateContextMenuListener getOnCreateContextMenuListener()
- Returns:
- Returns create ContextMenu listener, if set.
-
getOnAttachStateChangeListeners
public Set<View.OnAttachStateChangeListener> getOnAttachStateChangeListeners()
- Returns:
- Returns the attached listeners, or the empty set if none are present.
-
getOnLayoutChangeListeners
public Set<View.OnLayoutChangeListener> getOnLayoutChangeListeners()
- Returns:
- Returns the layout change listeners, or the empty set if none are present.
-
post
@Implementation protected boolean post(Runnable action)
-
postDelayed
@Implementation protected boolean postDelayed(Runnable action, long delayMills)
-
postInvalidateDelayed
@Implementation protected void postInvalidateDelayed(long delayMilliseconds)
-
removeCallbacks
@Implementation protected boolean removeCallbacks(Runnable callback)
-
scrollTo
@Implementation protected void scrollTo(int x, int y)
-
scrollBy
@Implementation protected void scrollBy(int x, int y)
-
getScrollX
@Implementation protected int getScrollX()
-
getScrollY
@Implementation protected int getScrollY()
-
setScrollX
@Implementation protected void setScrollX(int scrollX)
-
setScrollY
@Implementation protected void setScrollY(int scrollY)
-
getLocationOnScreen
@Implementation protected void getLocationOnScreen(int[] outLocation)
-
mapRectFromViewToScreenCoords
@Implementation(minSdk=26) protected void mapRectFromViewToScreenCoords(RectF rect, boolean clipToParent)
-
getLayerType
@Implementation protected int getLayerType()
-
setAnimation
@Implementation protected void setAnimation(Animation animation)
-
clearAnimation
@Implementation protected void clearAnimation()
-
initialAwakenScrollBars
@Implementation protected boolean initialAwakenScrollBars()
-
isAttachedToWindow
@Implementation(minSdk=19) protected boolean isAttachedToWindow()
-
callOnAttachedToWindow
public void callOnAttachedToWindow()
-
callOnDetachedFromWindow
public void callOnDetachedFromWindow()
-
getWindowId
@Implementation(minSdk=18) protected WindowId getWindowId()
-
performHapticFeedback
@Implementation protected boolean performHapticFeedback(int hapticFeedbackType)
-
getGlobalVisibleRect
@Implementation protected boolean getGlobalVisibleRect(Rect rect, Point globalOffset)
-
setGlobalVisibleRect
public void setGlobalVisibleRect(Rect rect)
-
lastHapticFeedbackPerformed
public int lastHapticFeedbackPerformed()
-
setMyParent
public void setMyParent(ViewParent viewParent)
-
getWindowVisibleDisplayFrame
@Implementation protected void getWindowVisibleDisplayFrame(Rect outRect)
-
getWindowDisplayFrame
@Implementation(minSdk=24) protected void getWindowDisplayFrame(Rect outRect)
-
getSourceLayoutResId
@Implementation(minSdk=29) public int getSourceLayoutResId()
Returns the layout resource id this view was inflated from. Backwards compatible version ofView.getSourceLayoutResId()
, passes through to the underlying implementation on API levels where it is supported.
-
-