FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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.

Constructor & Destructor Documentation

◆ ScrollView2D() [1/3]

com.freerdp.freerdpcore.presentation.ScrollView2D.ScrollView2D ( Context  context)
inline

Definition at line 105 of file ScrollView2D.java.

106 {
107 super(context);
108 initTwoDScrollView();
109 }

◆ ScrollView2D() [2/3]

com.freerdp.freerdpcore.presentation.ScrollView2D.ScrollView2D ( Context  context,
AttributeSet  attrs 
)
inline

Definition at line 111 of file ScrollView2D.java.

112 {
113 super(context, attrs);
114 initTwoDScrollView();
115 }

◆ ScrollView2D() [3/3]

com.freerdp.freerdpcore.presentation.ScrollView2D.ScrollView2D ( Context  context,
AttributeSet  attrs,
int  defStyle 
)
inline

Definition at line 117 of file ScrollView2D.java.

118 {
119 super(context, attrs, defStyle);
120 initTwoDScrollView();
121 }

Member Function Documentation

◆ addView() [1/4]

void com.freerdp.freerdpcore.presentation.ScrollView2D.addView ( View  child)
inline

Definition at line 217 of file ScrollView2D.java.

218 {
219 if (getChildCount() > 0)
220 {
221 throw new IllegalStateException("TwoDScrollView can host only one direct child");
222 }
223 super.addView(child);
224 }

◆ addView() [2/4]

void com.freerdp.freerdpcore.presentation.ScrollView2D.addView ( View  child,
int  index 
)
inline

Definition at line 226 of file ScrollView2D.java.

227 {
228 if (getChildCount() > 0)
229 {
230 throw new IllegalStateException("TwoDScrollView can host only one direct child");
231 }
232 super.addView(child, index);
233 }

◆ addView() [3/4]

void com.freerdp.freerdpcore.presentation.ScrollView2D.addView ( View  child,
int  index,
ViewGroup.LayoutParams  params 
)
inline

Definition at line 244 of file ScrollView2D.java.

245 {
246 if (getChildCount() > 0)
247 {
248 throw new IllegalStateException("TwoDScrollView can host only one direct child");
249 }
250 super.addView(child, index, params);
251 }

◆ addView() [4/4]

void com.freerdp.freerdpcore.presentation.ScrollView2D.addView ( View  child,
ViewGroup.LayoutParams  params 
)
inline

Definition at line 235 of file ScrollView2D.java.

236 {
237 if (getChildCount() > 0)
238 {
239 throw new IllegalStateException("TwoDScrollView can host only one direct child");
240 }
241 super.addView(child, params);
242 }

◆ 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:

◆ computeHorizontalScrollRange()

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

Definition at line 931 of file ScrollView2D.java.

932 {
933 int count = getChildCount();
934 return count == 0 ? getWidth() : (getChildAt(0)).getRight();
935 }

◆ computeScroll()

void com.freerdp.freerdpcore.presentation.ScrollView2D.computeScroll ( )
inline

Definition at line 964 of file ScrollView2D.java.

965 {
966 if (mScroller.computeScrollOffset())
967 {
968 // This is called at drawing time by ViewGroup. We don't want to
969 // re-show the scrollbars at this point, which scrollTo will do,
970 // so we replicate most of scrollTo here.
971 //
972 // It's a little odd to call onScrollChanged from inside the drawing.
973 //
974 // It is, except when you remember that computeScroll() is used to
975 // animate scrolling. So unless we want to defer the onScrollChanged()
976 // until the end of the animated scrolling, we don't really have a
977 // choice here.
978 //
979 // I agree. The alternative, which I think would be worse, is to post
980 // something and tell the subclasses later. This is bad because there
981 // will be a window where mScrollX/Y is different from what the app
982 // thinks it is.
983 //
984 int oldX = getScrollX();
985 int oldY = getScrollY();
986 int x = mScroller.getCurrX();
987 int y = mScroller.getCurrY();
988 if (getChildCount() > 0)
989 {
990 View child = getChildAt(0);
991 scrollTo(
992 clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth()),
993 clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(),
994 child.getHeight()));
995 }
996 else
997 {
998 scrollTo(x, y);
999 }
1000 if (oldX != getScrollX() || oldY != getScrollY())
1001 {
1002 onScrollChanged(getScrollX(), getScrollY(), oldX, oldY);
1003 }
1004
1005 // Keep on drawing until the animation has finished.
1006 postInvalidate();
1007 }
1008 }

◆ 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 }

◆ dispatchKeyEvent()

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

Definition at line 271 of file ScrollView2D.java.

272 {
273 // Let the focused view and/or our descendants get the key first
274 boolean handled = super.dispatchKeyEvent(event);
275 if (handled)
276 {
277 return true;
278 }
279 return executeKeyEvent(event);
280 }

◆ 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:

◆ getBottomFadingEdgeStrength()

float com.freerdp.freerdpcore.presentation.ScrollView2D.getBottomFadingEdgeStrength ( )
inlineprotected

Definition at line 137 of file ScrollView2D.java.

138 {
139 if (getChildCount() == 0)
140 {
141 return 0.0f;
142 }
143 final int length = getVerticalFadingEdgeLength();
144 final int bottomEdge = getHeight() - getPaddingBottom();
145 final int span = getChildAt(0).getBottom() - getScrollY() - bottomEdge;
146 if (span < length)
147 {
148 return span / (float)length;
149 }
150 return 1.0f;
151 }

◆ getLeftFadingEdgeStrength()

float com.freerdp.freerdpcore.presentation.ScrollView2D.getLeftFadingEdgeStrength ( )
inlineprotected

Definition at line 153 of file ScrollView2D.java.

154 {
155 if (getChildCount() == 0)
156 {
157 return 0.0f;
158 }
159 final int length = getHorizontalFadingEdgeLength();
160 if (getScrollX() < length)
161 {
162 return getScrollX() / (float)length;
163 }
164 return 1.0f;
165 }

◆ getMaxScrollAmountHorizontal()

int com.freerdp.freerdpcore.presentation.ScrollView2D.getMaxScrollAmountHorizontal ( )
inline

Definition at line 200 of file ScrollView2D.java.

201 {
202 return (int)(MAX_SCROLL_FACTOR * getWidth());
203 }

◆ 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:

◆ getRightFadingEdgeStrength()

float com.freerdp.freerdpcore.presentation.ScrollView2D.getRightFadingEdgeStrength ( )
inlineprotected

Definition at line 167 of file ScrollView2D.java.

168 {
169 if (getChildCount() == 0)
170 {
171 return 0.0f;
172 }
173 final int length = getHorizontalFadingEdgeLength();
174 final int rightEdge = getWidth() - getPaddingRight();
175 final int span = getChildAt(0).getRight() - getScrollX() - rightEdge;
176 if (span < length)
177 {
178 return span / (float)length;
179 }
180 return 1.0f;
181 }

◆ getTopFadingEdgeStrength()

float com.freerdp.freerdpcore.presentation.ScrollView2D.getTopFadingEdgeStrength ( )
inlineprotected

Definition at line 123 of file ScrollView2D.java.

124 {
125 if (getChildCount() == 0)
126 {
127 return 0.0f;
128 }
129 final int length = getVerticalFadingEdgeLength();
130 if (getScrollY() < length)
131 {
132 return getScrollY() / (float)length;
133 }
134 return 1.0f;
135 }

◆ measureChild()

void com.freerdp.freerdpcore.presentation.ScrollView2D.measureChild ( View  child,
int  parentWidthMeasureSpec,
int  parentHeightMeasureSpec 
)
inlineprotected

Definition at line 938 of file ScrollView2D.java.

939 {
940 ViewGroup.LayoutParams lp = child.getLayoutParams();
941 int childWidthMeasureSpec;
942 int childHeightMeasureSpec;
943
944 childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
945 getPaddingLeft() + getPaddingRight(), lp.width);
946 childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
947
948 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
949 }

◆ measureChildWithMargins()

void com.freerdp.freerdpcore.presentation.ScrollView2D.measureChildWithMargins ( View  child,
int  parentWidthMeasureSpec,
int  widthUsed,
int  parentHeightMeasureSpec,
int  heightUsed 
)
inlineprotected

Definition at line 952 of file ScrollView2D.java.

954 {
955 final MarginLayoutParams lp = (MarginLayoutParams)child.getLayoutParams();
956 final int childWidthMeasureSpec =
957 MeasureSpec.makeMeasureSpec(lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED);
958 final int childHeightMeasureSpec =
959 MeasureSpec.makeMeasureSpec(lp.topMargin + lp.bottomMargin, MeasureSpec.UNSPECIFIED);
960
961 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
962 }

◆ onInterceptTouchEvent()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.onInterceptTouchEvent ( MotionEvent  ev)
inline

Definition at line 357 of file ScrollView2D.java.

358 {
359 /*
360 * This method JUST determines whether we want to intercept the motion.
361 * If we return true, onMotionEvent will be called and we do the actual
362 * scrolling there.
363 *
364 * Shortcut the most recurring case: the user is in the dragging
365 * state and he is moving his finger. We want to intercept this
366 * motion.
367 */
368 final int action = ev.getAction();
369 if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged))
370 {
371 return true;
372 }
373 if (!canScroll())
374 {
375 mIsBeingDragged = false;
376 return false;
377 }
378 final float y = ev.getY();
379 final float x = ev.getX();
380 switch (action)
381 {
382 case MotionEvent.ACTION_MOVE:
383 /*
384 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
385 * whether the user has moved far enough from his original down touch.
386 */
387 /*
388 * Locally do absolute value. mLastMotionY is set to the y value
389 * of the down event.
390 */
391 final int yDiff = (int)Math.abs(y - mLastMotionY);
392 final int xDiff = (int)Math.abs(x - mLastMotionX);
393 if (yDiff > mTouchSlop || xDiff > mTouchSlop)
394 {
395 mIsBeingDragged = true;
396 }
397 break;
398
399 case MotionEvent.ACTION_DOWN:
400 /* Remember location of down touch */
401 mLastMotionY = y;
402 mLastMotionX = x;
403
404 /*
405 * If being flinged and user touches the screen, initiate drag;
406 * otherwise don't. mScroller.isFinished should be false when
407 * being flinged.
408 */
409 mIsBeingDragged = !mScroller.isFinished();
410 break;
411
412 case MotionEvent.ACTION_CANCEL:
413 case MotionEvent.ACTION_UP:
414 /* Release the drag */
415 mIsBeingDragged = false;
416 break;
417 }
418
419 /*
420 * The only time we want to intercept motion events is if we are in the
421 * drag mode.
422 */
423 return mIsBeingDragged;
424 }

◆ onLayout()

void com.freerdp.freerdpcore.presentation.ScrollView2D.onLayout ( boolean  changed,
int  l,
int  t,
int  r,
int  b 
)
inlineprotected

Definition at line 1190 of file ScrollView2D.java.

1191 {
1192 super.onLayout(changed, l, t, r, b);
1193 mIsLayoutDirty = false;
1194 // Give a child focus if it needs it
1195 if (mChildToScrollTo != null && isViewDescendantOf(mChildToScrollTo, this))
1196 {
1197 scrollToChild(mChildToScrollTo);
1198 }
1199 mChildToScrollTo = null;
1200
1201 // Calling this with the present values causes it to re-clam them
1202 scrollTo(getScrollX(), getScrollY());
1203 }

◆ 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 }

◆ onScrollChanged()

void com.freerdp.freerdpcore.presentation.ScrollView2D.onScrollChanged ( int  x,
int  y,
int  oldx,
int  oldy 
)
inlineprotected

Definition at line 1336 of file ScrollView2D.java.

1337 {
1338 super.onScrollChanged(x, y, oldx, oldy);
1339 if (scrollView2DListener != null)
1340 {
1341 scrollView2DListener.onScrollChanged(this, x, y, oldx, oldy);
1342 }
1343 }

◆ onSizeChanged()

void com.freerdp.freerdpcore.presentation.ScrollView2D.onSizeChanged ( int  w,
int  h,
int  oldw,
int  oldh 
)
inlineprotected

Definition at line 1205 of file ScrollView2D.java.

1206 {
1207 super.onSizeChanged(w, h, oldw, oldh);
1208
1209 View currentFocused = findFocus();
1210 if (null == currentFocused || this == currentFocused)
1211 return;
1212
1213 // If the currently-focused view was visible on the screen when the
1214 // screen was at the old height, then scroll the screen to make that
1215 // view visible with the new screen height.
1216 currentFocused.getDrawingRect(mTempRect);
1217 offsetDescendantRectToMyCoords(currentFocused, mTempRect);
1218 int scrollDeltaX = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
1219 int scrollDeltaY = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
1220 doScroll(scrollDeltaX, scrollDeltaY);
1221 }

◆ onTouchEvent()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.onTouchEvent ( MotionEvent  ev)
inline

Definition at line 426 of file ScrollView2D.java.

427 {
428
429 if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0)
430 {
431 // Don't handle edge touches immediately -- they may actually belong to one of our
432 // descendants.
433 return false;
434 }
435
436 if (!canScroll())
437 {
438 return false;
439 }
440
441 if (mVelocityTracker == null)
442 {
443 mVelocityTracker = VelocityTracker.obtain();
444 }
445 mVelocityTracker.addMovement(ev);
446
447 final int action = ev.getAction();
448 final float y = ev.getY();
449 final float x = ev.getX();
450
451 switch (action)
452 {
453 case MotionEvent.ACTION_DOWN:
454 /*
455 * If being flinged and user touches, stop the fling. isFinished
456 * will be false if being flinged.
457 */
458 if (!mScroller.isFinished())
459 {
460 mScroller.abortAnimation();
461 }
462
463 // Remember where the motion event started
464 mLastMotionY = y;
465 mLastMotionX = x;
466 break;
467 case MotionEvent.ACTION_MOVE:
468 // Scroll to follow the motion event
469 int deltaX = (int)(mLastMotionX - x);
470 int deltaY = (int)(mLastMotionY - y);
471 mLastMotionX = x;
472 mLastMotionY = y;
473
474 if (deltaX < 0)
475 {
476 if (getScrollX() < 0)
477 {
478 deltaX = 0;
479 }
480 }
481 else if (deltaX > 0)
482 {
483 final int rightEdge = getWidth() - getPaddingRight();
484 final int availableToScroll =
485 getChildAt(0).getRight() - getScrollX() - rightEdge;
486 if (availableToScroll > 0)
487 {
488 deltaX = Math.min(availableToScroll, deltaX);
489 }
490 else
491 {
492 deltaX = 0;
493 }
494 }
495 if (deltaY < 0)
496 {
497 if (getScrollY() < 0)
498 {
499 deltaY = 0;
500 }
501 }
502 else if (deltaY > 0)
503 {
504 final int bottomEdge = getHeight() - getPaddingBottom();
505 final int availableToScroll =
506 getChildAt(0).getBottom() - getScrollY() - bottomEdge;
507 if (availableToScroll > 0)
508 {
509 deltaY = Math.min(availableToScroll, deltaY);
510 }
511 else
512 {
513 deltaY = 0;
514 }
515 }
516 if (deltaY != 0 || deltaX != 0)
517 scrollBy(deltaX, deltaY);
518 break;
519 case MotionEvent.ACTION_UP:
520 final VelocityTracker velocityTracker = mVelocityTracker;
521 velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
522 int initialXVelocity = (int)velocityTracker.getXVelocity();
523 int initialYVelocity = (int)velocityTracker.getYVelocity();
524 if ((Math.abs(initialXVelocity) + Math.abs(initialYVelocity) > mMinimumVelocity) &&
525 getChildCount() > 0)
526 {
527 fling(-initialXVelocity, -initialYVelocity);
528 }
529 if (mVelocityTracker != null)
530 {
531 mVelocityTracker.recycle();
532 mVelocityTracker = null;
533 }
534 }
535 return true;
536 }

◆ requestChildFocus()

void com.freerdp.freerdpcore.presentation.ScrollView2D.requestChildFocus ( View  child,
View  focused 
)
inline

Definition at line 1125 of file ScrollView2D.java.

1126 {
1127 if (!mTwoDScrollViewMovedFocus)
1128 {
1129 if (!mIsLayoutDirty)
1130 {
1131 scrollToChild(focused);
1132 }
1133 else
1134 {
1135 // The child may not be laid out yet, we can't compute the scroll yet
1136 mChildToScrollTo = focused;
1137 }
1138 }
1139 super.requestChildFocus(child, focused);
1140 }

◆ requestChildRectangleOnScreen()

boolean com.freerdp.freerdpcore.presentation.ScrollView2D.requestChildRectangleOnScreen ( View  child,
Rect  rectangle,
boolean  immediate 
)
inline

Definition at line 1177 of file ScrollView2D.java.

1178 {
1179 // offset into coordinate space of this scroll view
1180 rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
1181 return scrollToChildRect(rectangle, immediate);
1182 }

◆ requestLayout()

void com.freerdp.freerdpcore.presentation.ScrollView2D.requestLayout ( )
inline

Definition at line 1184 of file ScrollView2D.java.

1185 {
1186 mIsLayoutDirty = true;
1187 super.requestLayout();
1188 }

◆ 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 }

◆ setScrollViewListener()

void com.freerdp.freerdpcore.presentation.ScrollView2D.setScrollViewListener ( ScrollView2DListener  scrollViewListener)
inline

Definition at line 1331 of file ScrollView2D.java.

1332 {
1333 this.scrollView2DListener = scrollViewListener;
1334 }

◆ 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: