FreeRDP
com.freerdp.freerdpcore.presentation.ScrollView2D Class Reference
Inheritance diagram for com.freerdp.freerdpcore.presentation.ScrollView2D:
Collaboration diagram for com.freerdp.freerdpcore.presentation.ScrollView2D:

Data Structures

interface  ScrollView2DListener
 

Public Member Functions

 ScrollView2D (Context context)
 
 ScrollView2D (Context context, AttributeSet attrs)
 
 ScrollView2D (Context context, AttributeSet attrs, int defStyle)
 
void setScrollEnabled (boolean enable)
 
int getMaxScrollAmountVertical ()
 
int getMaxScrollAmountHorizontal ()
 
void addView (View child)
 
void addView (View child, int index)
 
void addView (View child, ViewGroup.LayoutParams params)
 
void addView (View child, int index, ViewGroup.LayoutParams params)
 
boolean dispatchKeyEvent (KeyEvent event)
 
boolean executeKeyEvent (KeyEvent event)
 
boolean onInterceptTouchEvent (MotionEvent ev)
 
boolean onTouchEvent (MotionEvent ev)
 
boolean fullScroll (int direction, boolean horizontal)
 
boolean arrowScroll (int direction, boolean horizontal)
 
final void smoothScrollBy (int dx, int dy)
 
final void smoothScrollTo (int x, int y)
 
void computeScroll ()
 
void requestChildFocus (View child, View focused)
 
boolean requestChildRectangleOnScreen (View child, Rect rectangle, boolean immediate)
 
void requestLayout ()
 
void fling (int velocityX, int velocityY)
 
void scrollTo (int x, int y)
 
void setScrollViewListener (ScrollView2DListener scrollViewListener)
 

Protected Member Functions

float getTopFadingEdgeStrength ()
 
float getBottomFadingEdgeStrength ()
 
float getLeftFadingEdgeStrength ()
 
float getRightFadingEdgeStrength ()
 
int computeVerticalScrollRange ()
 
int computeHorizontalScrollRange ()
 
void measureChild (View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec)
 
void measureChildWithMargins (View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
 
int computeScrollDeltaToGetChildRectOnScreen (Rect rect)
 
boolean onRequestFocusInDescendants (int direction, Rect previouslyFocusedRect)
 
void onLayout (boolean changed, int l, int t, int r, int b)
 
void onSizeChanged (int w, int h, int oldw, int oldh)
 
void onScrollChanged (int x, int y, int oldx, int oldy)
 

Detailed Description

Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A TwoDScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

The TextView class also takes care of its own scrolling, so does not require a TwoDScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.

Definition at line 57 of file ScrollView2D.java.

Member Function Documentation

◆ arrowScroll()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.arrowScroll ( int  direction,
boolean  horizontal 
)
inline

Handle scrolling in response to an up or down arrow click.

Parameters
directionThe direction corresponding to the arrow key that was pressed
Returns
True if we consumed the event, false otherwise

Definition at line 785 of file ScrollView2D.java.

786  {
787  View currentFocused = findFocus();
788  if (currentFocused == this)
789  currentFocused = null;
790  View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
791  final int maxJump =
792  horizontal ? getMaxScrollAmountHorizontal() : getMaxScrollAmountVertical();
793 
794  if (!horizontal)
795  {
796  if (nextFocused != null)
797  {
798  nextFocused.getDrawingRect(mTempRect);
799  offsetDescendantRectToMyCoords(nextFocused, mTempRect);
800  int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
801  doScroll(0, scrollDelta);
802  nextFocused.requestFocus(direction);
803  }
804  else
805  {
806  // no new focus
807  int scrollDelta = maxJump;
808  if (direction == View.FOCUS_UP && getScrollY() < scrollDelta)
809  {
810  scrollDelta = getScrollY();
811  }
812  else if (direction == View.FOCUS_DOWN)
813  {
814  if (getChildCount() > 0)
815  {
816  int daBottom = getChildAt(0).getBottom();
817  int screenBottom = getScrollY() + getHeight();
818  if (daBottom - screenBottom < maxJump)
819  {
820  scrollDelta = daBottom - screenBottom;
821  }
822  }
823  }
824  if (scrollDelta == 0)
825  {
826  return false;
827  }
828  doScroll(0, direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
829  }
830  }
831  else
832  {
833  if (nextFocused != null)
834  {
835  nextFocused.getDrawingRect(mTempRect);
836  offsetDescendantRectToMyCoords(nextFocused, mTempRect);
837  int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
838  doScroll(scrollDelta, 0);
839  nextFocused.requestFocus(direction);
840  }
841  else
842  {
843  // no new focus
844  int scrollDelta = maxJump;
845  if (direction == View.FOCUS_UP && getScrollY() < scrollDelta)
846  {
847  scrollDelta = getScrollY();
848  }
849  else if (direction == View.FOCUS_DOWN)
850  {
851  if (getChildCount() > 0)
852  {
853  int daBottom = getChildAt(0).getBottom();
854  int screenBottom = getScrollY() + getHeight();
855  if (daBottom - screenBottom < maxJump)
856  {
857  scrollDelta = daBottom - screenBottom;
858  }
859  }
860  }
861  if (scrollDelta == 0)
862  {
863  return false;
864  }
865  doScroll(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta, 0);
866  }
867  }
868  return true;
869  }

References com.freerdp.freerdpcore.presentation.ScrollView2D.computeScrollDeltaToGetChildRectOnScreen(), and com.freerdp.freerdpcore.presentation.ScrollView2D.getMaxScrollAmountVertical().

Referenced by com.freerdp.freerdpcore.presentation.ScrollView2D.executeKeyEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ computeScrollDeltaToGetChildRectOnScreen()

int com.freerdp.freerdpcore.presentation.ScrollView2D.computeScrollDeltaToGetChildRectOnScreen ( Rect  rect)
inlineprotected

Compute the amount to scroll in the Y direction in order to get a rectangle completely on the screen (or, if taller than the screen, at least the first screen size chunk of it).

Parameters
rectThe rect.
Returns
The scroll delta.

Definition at line 1061 of file ScrollView2D.java.

1062  {
1063  if (getChildCount() == 0)
1064  return 0;
1065  int height = getHeight();
1066  int screenTop = getScrollY();
1067  int screenBottom = screenTop + height;
1068  int fadingEdge = getVerticalFadingEdgeLength();
1069  // leave room for top fading edge as long as rect isn't at very top
1070  if (rect.top > 0)
1071  {
1072  screenTop += fadingEdge;
1073  }
1074 
1075  // leave room for bottom fading edge as long as rect isn't at very bottom
1076  if (rect.bottom < getChildAt(0).getHeight())
1077  {
1078  screenBottom -= fadingEdge;
1079  }
1080  int scrollYDelta = 0;
1081  if (rect.bottom > screenBottom && rect.top > screenTop)
1082  {
1083  // need to move down to get it in view: move down just enough so
1084  // that the entire rectangle is in view (or at least the first
1085  // screen size chunk).
1086  if (rect.height() > height)
1087  {
1088  // just enough to get screen size chunk on
1089  scrollYDelta += (rect.top - screenTop);
1090  }
1091  else
1092  {
1093  // get entire rect at bottom of screen
1094  scrollYDelta += (rect.bottom - screenBottom);
1095  }
1096 
1097  // make sure we aren't scrolling beyond the end of our content
1098  int bottom = getChildAt(0).getBottom();
1099  int distanceToBottom = bottom - screenBottom;
1100  scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
1101  }
1102  else if (rect.top < screenTop && rect.bottom < screenBottom)
1103  {
1104  // need to move up to get it in view: move up just enough so that
1105  // entire rectangle is in view (or at least the first screen
1106  // size chunk of it).
1107 
1108  if (rect.height() > height)
1109  {
1110  // screen size chunk
1111  scrollYDelta -= (screenBottom - rect.bottom);
1112  }
1113  else
1114  {
1115  // entire rect at top
1116  scrollYDelta -= (screenTop - rect.top);
1117  }
1118 
1119  // make sure we aren't scrolling any further than the top our content
1120  scrollYDelta = Math.max(scrollYDelta, -getScrollY());
1121  }
1122  return scrollYDelta;
1123  }

Referenced by com.freerdp.freerdpcore.presentation.ScrollView2D.arrowScroll().

Here is the caller graph for this function:

◆ computeVerticalScrollRange()

int com.freerdp.freerdpcore.presentation.ScrollView2D.computeVerticalScrollRange ( )
inlineprotected

The scroll range of a scroll view is the overall height of all of its children.

Definition at line 925 of file ScrollView2D.java.

926  {
927  int count = getChildCount();
928  return count == 0 ? getHeight() : (getChildAt(0)).getBottom();
929  }

◆ executeKeyEvent()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.executeKeyEvent ( KeyEvent  event)
inline

You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy.

Parameters
eventThe key event to execute.
Returns
Return true if the event was handled, else false.

Definition at line 290 of file ScrollView2D.java.

291  {
292  mTempRect.setEmpty();
293  if (!canScroll())
294  {
295  if (isFocused())
296  {
297  View currentFocused = findFocus();
298  if (currentFocused == this)
299  currentFocused = null;
300  View nextFocused =
301  FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
302  return nextFocused != null && nextFocused != this &&
303  nextFocused.requestFocus(View.FOCUS_DOWN);
304  }
305  return false;
306  }
307  boolean handled = false;
308  if (event.getAction() == KeyEvent.ACTION_DOWN)
309  {
310  switch (event.getKeyCode())
311  {
312  case KeyEvent.KEYCODE_DPAD_UP:
313  if (!event.isAltPressed())
314  {
315  handled = arrowScroll(View.FOCUS_UP, false);
316  }
317  else
318  {
319  handled = fullScroll(View.FOCUS_UP, false);
320  }
321  break;
322  case KeyEvent.KEYCODE_DPAD_DOWN:
323  if (!event.isAltPressed())
324  {
325  handled = arrowScroll(View.FOCUS_DOWN, false);
326  }
327  else
328  {
329  handled = fullScroll(View.FOCUS_DOWN, false);
330  }
331  break;
332  case KeyEvent.KEYCODE_DPAD_LEFT:
333  if (!event.isAltPressed())
334  {
335  handled = arrowScroll(View.FOCUS_LEFT, true);
336  }
337  else
338  {
339  handled = fullScroll(View.FOCUS_LEFT, true);
340  }
341  break;
342  case KeyEvent.KEYCODE_DPAD_RIGHT:
343  if (!event.isAltPressed())
344  {
345  handled = arrowScroll(View.FOCUS_RIGHT, true);
346  }
347  else
348  {
349  handled = fullScroll(View.FOCUS_RIGHT, true);
350  }
351  break;
352  }
353  }
354  return handled;
355  }
boolean arrowScroll(int direction, boolean horizontal)
boolean fullScroll(int direction, boolean horizontal)

References com.freerdp.freerdpcore.presentation.ScrollView2D.arrowScroll(), and com.freerdp.freerdpcore.presentation.ScrollView2D.fullScroll().

Here is the call graph for this function:

◆ fling()

void com.freerdp.freerdpcore.presentation.ScrollView2D.fling ( int  velocityX,
int  velocityY 
)
inline

Fling the scroll view

Parameters
velocityYThe initial velocity in the Y direction. Positive numbers mean that the finger/curor is moving down the screen, which means we want to scroll towards the top.

Definition at line 1244 of file ScrollView2D.java.

1245  {
1246  if (getChildCount() > 0)
1247  {
1248  int height = getHeight() - getPaddingBottom() - getPaddingTop();
1249  int bottom = getChildAt(0).getHeight();
1250  int width = getWidth() - getPaddingRight() - getPaddingLeft();
1251  int right = getChildAt(0).getWidth();
1252 
1253  mScroller.fling(getScrollX(), getScrollY(), velocityX, velocityY, 0, right - width, 0,
1254  bottom - height);
1255 
1256  final boolean movingDown = velocityY > 0;
1257  final boolean movingRight = velocityX > 0;
1258 
1259  View newFocused = findFocusableViewInMyBounds(
1260  movingRight, mScroller.getFinalX(), movingDown, mScroller.getFinalY(), findFocus());
1261  if (newFocused == null)
1262  {
1263  newFocused = this;
1264  }
1265 
1266  if (newFocused != findFocus() &&
1267  newFocused.requestFocus(movingDown ? View.FOCUS_DOWN : View.FOCUS_UP))
1268  {
1269  mTwoDScrollViewMovedFocus = true;
1270  mTwoDScrollViewMovedFocus = false;
1271  }
1272 
1273  awakenScrollBars(mScroller.getDuration());
1274  invalidate();
1275  }
1276  }

◆ fullScroll()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.fullScroll ( int  direction,
boolean  horizontal 
)
inline

Handles scrolling in response to a "home/end" shortcut press. This method will scroll the view to the top or bottom and give the focus to the topmost/bottommost component in the new visible area. If no component is a good candidate for focus, this scrollview reclaims the focus.

Parameters
directionthe scroll direction: android.view.View#FOCUS_UP to go the top of the view or android.view.View#FOCUS_DOWN to go the bottom
Returns
true if the key event is consumed by this method, false otherwise

Definition at line 689 of file ScrollView2D.java.

690  {
691  if (!horizontal)
692  {
693  boolean down = direction == View.FOCUS_DOWN;
694  int height = getHeight();
695  mTempRect.top = 0;
696  mTempRect.bottom = height;
697  if (down)
698  {
699  int count = getChildCount();
700  if (count > 0)
701  {
702  View view = getChildAt(count - 1);
703  mTempRect.bottom = view.getBottom();
704  mTempRect.top = mTempRect.bottom - height;
705  }
706  }
707  return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom, 0, 0, 0);
708  }
709  else
710  {
711  boolean right = direction == View.FOCUS_DOWN;
712  int width = getWidth();
713  mTempRect.left = 0;
714  mTempRect.right = width;
715  if (right)
716  {
717  int count = getChildCount();
718  if (count > 0)
719  {
720  View view = getChildAt(count - 1);
721  mTempRect.right = view.getBottom();
722  mTempRect.left = mTempRect.right - width;
723  }
724  }
725  return scrollAndFocus(0, 0, 0, direction, mTempRect.top, mTempRect.bottom);
726  }
727  }

Referenced by com.freerdp.freerdpcore.presentation.ScrollView2D.executeKeyEvent().

Here is the caller graph for this function:

◆ getMaxScrollAmountVertical()

int com.freerdp.freerdpcore.presentation.ScrollView2D.getMaxScrollAmountVertical ( )
inline
Returns
The maximum amount this scroll view will scroll in response to an arrow event.

Definition at line 195 of file ScrollView2D.java.

196  {
197  return (int)(MAX_SCROLL_FACTOR * getHeight());
198  }

Referenced by com.freerdp.freerdpcore.presentation.ScrollView2D.arrowScroll().

Here is the caller graph for this function:

◆ onRequestFocusInDescendants()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.onRequestFocusInDescendants ( int  direction,
Rect  previouslyFocusedRect 
)
inlineprotected

When looking for focus in children of a scroll view, need to be a little more careful not to give focus to something that is scrolled off screen.

This is more expensive than the default android.view.ViewGroup implementation, otherwise this behavior might have been made the default.

Definition at line 1150 of file ScrollView2D.java.

1151  {
1152  // convert from forward / backward notation to up / down / left / right
1153  // (ugh).
1154  if (direction == View.FOCUS_FORWARD)
1155  {
1156  direction = View.FOCUS_DOWN;
1157  }
1158  else if (direction == View.FOCUS_BACKWARD)
1159  {
1160  direction = View.FOCUS_UP;
1161  }
1162 
1163  final View nextFocus = previouslyFocusedRect == null
1164  ? FocusFinder.getInstance().findNextFocus(this, null, direction)
1165  : FocusFinder.getInstance().findNextFocusFromRect(
1166  this, previouslyFocusedRect, direction);
1167 
1168  if (nextFocus == null)
1169  {
1170  return false;
1171  }
1172 
1173  return nextFocus.requestFocus(direction, previouslyFocusedRect);
1174  }

◆ scrollTo()

void com.freerdp.freerdpcore.presentation.ScrollView2D.scrollTo ( int  x,
int  y 
)
inline

This version also clamps the scrolling to the bounds of our child.

Definition at line 1283 of file ScrollView2D.java.

1284  {
1285  // we rely on the fact the View.scrollBy calls scrollTo.
1286  if (getChildCount() > 0)
1287  {
1288  View child = getChildAt(0);
1289  x = clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth());
1290  y = clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(), child.getHeight());
1291  if (x != getScrollX() || y != getScrollY())
1292  {
1293  super.scrollTo(x, y);
1294  }
1295  }
1296  }

◆ setScrollEnabled()

void com.freerdp.freerdpcore.presentation.ScrollView2D.setScrollEnabled ( boolean  enable)
inline

Disable/Enable scrolling

Definition at line 186 of file ScrollView2D.java.

187  {
188  scrollEnabled = enable;
189  }

◆ smoothScrollBy()

final void com.freerdp.freerdpcore.presentation.ScrollView2D.smoothScrollBy ( int  dx,
int  dy 
)
inline

Like View#scrollBy, but scroll smoothly instead of immediately.

Parameters
dxthe number of pixels to scroll by on the X axis
dythe number of pixels to scroll by on the Y axis

Definition at line 890 of file ScrollView2D.java.

891  {
892  long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll;
893  if (duration > ANIMATED_SCROLL_GAP)
894  {
895  mScroller.startScroll(getScrollX(), getScrollY(), dx, dy);
896  awakenScrollBars(mScroller.getDuration());
897  invalidate();
898  }
899  else
900  {
901  if (!mScroller.isFinished())
902  {
903  mScroller.abortAnimation();
904  }
905  scrollBy(dx, dy);
906  }
907  mLastScroll = AnimationUtils.currentAnimationTimeMillis();
908  }

Referenced by com.freerdp.freerdpcore.presentation.ScrollView2D.smoothScrollTo().

Here is the caller graph for this function:

◆ smoothScrollTo()

final void com.freerdp.freerdpcore.presentation.ScrollView2D.smoothScrollTo ( int  x,
int  y 
)
inline

Like scrollTo, but scroll smoothly instead of immediately.

Parameters
xthe position where to scroll on the X axis
ythe position where to scroll on the Y axis

Definition at line 916 of file ScrollView2D.java.

917  {
918  smoothScrollBy(x - getScrollX(), y - getScrollY());
919  }

References com.freerdp.freerdpcore.presentation.ScrollView2D.smoothScrollBy().

Here is the call graph for this function:

The documentation for this class was generated from the following file: