FreeRDP
Loading...
Searching...
No Matches
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 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 58 of file ScrollView2D.java.

Constructor & Destructor Documentation

◆ ScrollView2D() [1/3]

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

Definition at line 106 of file ScrollView2D.java.

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

◆ ScrollView2D() [2/3]

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

Definition at line 112 of file ScrollView2D.java.

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

◆ ScrollView2D() [3/3]

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

Definition at line 118 of file ScrollView2D.java.

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

Member Function Documentation

◆ addView() [1/4]

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

Definition at line 218 of file ScrollView2D.java.

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

◆ addView() [2/4]

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

Definition at line 227 of file ScrollView2D.java.

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

◆ addView() [3/4]

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

Definition at line 245 of file ScrollView2D.java.

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

◆ addView() [4/4]

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

Definition at line 236 of file ScrollView2D.java.

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

◆ 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 707 of file ScrollView2D.java.

708 {
709 View currentFocused = findFocus();
710 if (currentFocused == this)
711 currentFocused = null;
712 View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
713 final int maxJump =
714 horizontal ? getMaxScrollAmountHorizontal() : getMaxScrollAmountVertical();
715
716 if (!horizontal)
717 {
718 if (nextFocused != null)
719 {
720 nextFocused.getDrawingRect(mTempRect);
721 offsetDescendantRectToMyCoords(nextFocused, mTempRect);
722 int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
723 doScroll(0, scrollDelta);
724 nextFocused.requestFocus(direction);
725 }
726 else
727 {
728 // no new focus
729 int scrollDelta = maxJump;
730 if (direction == View.FOCUS_UP && getScrollY() < scrollDelta)
731 {
732 scrollDelta = getScrollY();
733 }
734 else if (direction == View.FOCUS_DOWN)
735 {
736 if (getChildCount() > 0)
737 {
738 int daBottom = getChildAt(0).getBottom();
739 int screenBottom = getScrollY() + getHeight();
740 if (daBottom - screenBottom < maxJump)
741 {
742 scrollDelta = daBottom - screenBottom;
743 }
744 }
745 }
746 if (scrollDelta == 0)
747 {
748 return false;
749 }
750 doScroll(0, direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
751 }
752 }
753 else
754 {
755 if (nextFocused != null)
756 {
757 nextFocused.getDrawingRect(mTempRect);
758 offsetDescendantRectToMyCoords(nextFocused, mTempRect);
759 int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
760 doScroll(scrollDelta, 0);
761 nextFocused.requestFocus(direction);
762 }
763 else
764 {
765 // no new focus
766 int scrollDelta = maxJump;
767 if (direction == View.FOCUS_UP && getScrollY() < scrollDelta)
768 {
769 scrollDelta = getScrollY();
770 }
771 else if (direction == View.FOCUS_DOWN)
772 {
773 if (getChildCount() > 0)
774 {
775 int daBottom = getChildAt(0).getBottom();
776 int screenBottom = getScrollY() + getHeight();
777 if (daBottom - screenBottom < maxJump)
778 {
779 scrollDelta = daBottom - screenBottom;
780 }
781 }
782 }
783 if (scrollDelta == 0)
784 {
785 return false;
786 }
787 doScroll(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta, 0);
788 }
789 }
790 return true;
791 }

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

Here is the call graph for this function:

◆ computeHorizontalScrollRange()

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

Definition at line 853 of file ScrollView2D.java.

854 {
855 int count = getChildCount();
856 return count == 0 ? getWidth() : (getChildAt(0)).getRight();
857 }

◆ computeScroll()

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

Definition at line 886 of file ScrollView2D.java.

887 {
888 if (mScroller.computeScrollOffset())
889 {
890 // This is called at drawing time by ViewGroup. We don't want to
891 // re-show the scrollbars at this point, which scrollTo will do,
892 // so we replicate most of scrollTo here.
893 //
894 // It's a little odd to call onScrollChanged from inside the drawing.
895 //
896 // It is, except when you remember that computeScroll() is used to
897 // animate scrolling. So unless we want to defer the onScrollChanged()
898 // until the end of the animated scrolling, we don't really have a
899 // choice here.
900 //
901 // I agree. The alternative, which I think would be worse, is to post
902 // something and tell the subclasses later. This is bad because there
903 // will be a window where mScrollX/Y is different from what the app
904 // thinks it is.
905 //
906 int oldX = getScrollX();
907 int oldY = getScrollY();
908 int x = mScroller.getCurrX();
909 int y = mScroller.getCurrY();
910 if (getChildCount() > 0)
911 {
912 View child = getChildAt(0);
913 scrollTo(
914 clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth()),
915 clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(),
916 child.getHeight()));
917 }
918 else
919 {
920 scrollTo(x, y);
921 }
922 if (oldX != getScrollX() || oldY != getScrollY())
923 {
924 onScrollChanged(getScrollX(), getScrollY(), oldX, oldY);
925 }
926
927 // Keep on drawing until the animation has finished.
928 postInvalidate();
929 }
930 }

◆ 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 983 of file ScrollView2D.java.

984 {
985 if (getChildCount() == 0)
986 return 0;
987 int height = getHeight();
988 int screenTop = getScrollY();
989 int screenBottom = screenTop + height;
990 int fadingEdge = getVerticalFadingEdgeLength();
991 // leave room for top fading edge as long as rect isn't at very top
992 if (rect.top > 0)
993 {
994 screenTop += fadingEdge;
995 }
996
997 // leave room for bottom fading edge as long as rect isn't at very bottom
998 if (rect.bottom < getChildAt(0).getHeight())
999 {
1000 screenBottom -= fadingEdge;
1001 }
1002 int scrollYDelta = 0;
1003 if (rect.bottom > screenBottom && rect.top > screenTop)
1004 {
1005 // need to move down to get it in view: move down just enough so
1006 // that the entire rectangle is in view (or at least the first
1007 // screen size chunk).
1008 if (rect.height() > height)
1009 {
1010 // just enough to get screen size chunk on
1011 scrollYDelta += (rect.top - screenTop);
1012 }
1013 else
1014 {
1015 // get entire rect at bottom of screen
1016 scrollYDelta += (rect.bottom - screenBottom);
1017 }
1018
1019 // make sure we aren't scrolling beyond the end of our content
1020 int bottom = getChildAt(0).getBottom();
1021 int distanceToBottom = bottom - screenBottom;
1022 scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
1023 }
1024 else if (rect.top < screenTop && rect.bottom < screenBottom)
1025 {
1026 // need to move up to get it in view: move up just enough so that
1027 // entire rectangle is in view (or at least the first screen
1028 // size chunk of it).
1029
1030 if (rect.height() > height)
1031 {
1032 // screen size chunk
1033 scrollYDelta -= (screenBottom - rect.bottom);
1034 }
1035 else
1036 {
1037 // entire rect at top
1038 scrollYDelta -= (screenTop - rect.top);
1039 }
1040
1041 // make sure we aren't scrolling any further than the top our content
1042 scrollYDelta = Math.max(scrollYDelta, -getScrollY());
1043 }
1044 return scrollYDelta;
1045 }

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 847 of file ScrollView2D.java.

848 {
849 int count = getChildCount();
850 return count == 0 ? getHeight() : (getChildAt(0)).getBottom();
851 }

◆ 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 1198 of file ScrollView2D.java.

1199 {
1200 if (getChildCount() > 0)
1201 {
1202 int height = getHeight() - getPaddingBottom() - getPaddingTop();
1203 int bottom = getChildAt(0).getHeight();
1204 int width = getWidth() - getPaddingRight() - getPaddingLeft();
1205 int right = getChildAt(0).getWidth();
1206
1207 mScroller.fling(getScrollX(), getScrollY(), velocityX, velocityY, 0, right - width, 0,
1208 bottom - height);
1209
1210 final boolean movingDown = velocityY > 0;
1211 final boolean movingRight = velocityX > 0;
1212
1213 View newFocused = findFocusableViewInMyBounds(
1214 movingRight, mScroller.getFinalX(), movingDown, mScroller.getFinalY(), findFocus());
1215 if (newFocused == null)
1216 {
1217 newFocused = this;
1218 }
1219
1220 if (newFocused != findFocus() &&
1221 newFocused.requestFocus(movingDown ? View.FOCUS_DOWN : View.FOCUS_UP))
1222 {
1223 mTwoDScrollViewMovedFocus = true;
1224 mTwoDScrollViewMovedFocus = false;
1225 }
1226
1227 awakenScrollBars(mScroller.getDuration());
1228 invalidate();
1229 }
1230 }

◆ 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 611 of file ScrollView2D.java.

612 {
613 if (!horizontal)
614 {
615 boolean down = direction == View.FOCUS_DOWN;
616 int height = getHeight();
617 mTempRect.top = 0;
618 mTempRect.bottom = height;
619 if (down)
620 {
621 int count = getChildCount();
622 if (count > 0)
623 {
624 View view = getChildAt(count - 1);
625 mTempRect.bottom = view.getBottom();
626 mTempRect.top = mTempRect.bottom - height;
627 }
628 }
629 return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom, 0, 0, 0);
630 }
631 else
632 {
633 boolean right = direction == View.FOCUS_DOWN;
634 int width = getWidth();
635 mTempRect.left = 0;
636 mTempRect.right = width;
637 if (right)
638 {
639 int count = getChildCount();
640 if (count > 0)
641 {
642 View view = getChildAt(count - 1);
643 mTempRect.right = view.getBottom();
644 mTempRect.left = mTempRect.right - width;
645 }
646 }
647 return scrollAndFocus(0, 0, 0, direction, mTempRect.top, mTempRect.bottom);
648 }
649 }

◆ getBottomFadingEdgeStrength()

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

Definition at line 138 of file ScrollView2D.java.

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

◆ getLeftFadingEdgeStrength()

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

Definition at line 154 of file ScrollView2D.java.

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

◆ getMaxScrollAmountHorizontal()

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

Definition at line 201 of file ScrollView2D.java.

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

◆ 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 196 of file ScrollView2D.java.

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

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 168 of file ScrollView2D.java.

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

◆ getTopFadingEdgeStrength()

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

Definition at line 124 of file ScrollView2D.java.

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

◆ measureChild()

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

Definition at line 860 of file ScrollView2D.java.

861 {
862 ViewGroup.LayoutParams lp = child.getLayoutParams();
863 int childWidthMeasureSpec;
864 int childHeightMeasureSpec;
865
866 childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
867 getPaddingLeft() + getPaddingRight(), lp.width);
868 childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
869
870 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
871 }

◆ measureChildWithMargins()

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

Definition at line 874 of file ScrollView2D.java.

876 {
877 final MarginLayoutParams lp = (MarginLayoutParams)child.getLayoutParams();
878 final int childWidthMeasureSpec =
879 MeasureSpec.makeMeasureSpec(lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED);
880 final int childHeightMeasureSpec =
881 MeasureSpec.makeMeasureSpec(lp.topMargin + lp.bottomMargin, MeasureSpec.UNSPECIFIED);
882
883 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
884 }

◆ onInterceptTouchEvent()

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

Definition at line 272 of file ScrollView2D.java.

273 {
274 /*
275 * This method JUST determines whether we want to intercept the motion.
276 * If we return true, onMotionEvent will be called and we do the actual
277 * scrolling there.
278 *
279 * Shortcut the most recurring case: the user is in the dragging
280 * state and he is moving his finger. We want to intercept this
281 * motion.
282 */
283 // Let child handle touchpad scroll gestures.
284 if (ev.getClassification() == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE)
285 {
286 mIsBeingDragged = false;
287 return false;
288 }
289
290 final int action = ev.getAction();
291 if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged))
292 {
293 return true;
294 }
295 if (!canScroll())
296 {
297 mIsBeingDragged = false;
298 return false;
299 }
300 final float y = ev.getY();
301 final float x = ev.getX();
302 switch (action)
303 {
304 case MotionEvent.ACTION_MOVE:
305 /*
306 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
307 * whether the user has moved far enough from his original down touch.
308 */
309 /*
310 * Locally do absolute value. mLastMotionY is set to the y value
311 * of the down event.
312 */
313 final int yDiff = (int)Math.abs(y - mLastMotionY);
314 final int xDiff = (int)Math.abs(x - mLastMotionX);
315 if (yDiff > mTouchSlop || xDiff > mTouchSlop)
316 {
317 mIsBeingDragged = true;
318 }
319 break;
320
321 case MotionEvent.ACTION_DOWN:
322 /* Remember location of down touch */
323 mLastMotionY = y;
324 mLastMotionX = x;
325
326 /*
327 * If being flinged and user touches the screen, initiate drag;
328 * otherwise don't. mScroller.isFinished should be false when
329 * being flinged.
330 */
331 mIsBeingDragged = !mScroller.isFinished();
332 break;
333
334 case MotionEvent.ACTION_CANCEL:
335 case MotionEvent.ACTION_UP:
336 /* Release the drag */
337 mIsBeingDragged = false;
338 break;
339 }
340
341 /*
342 * The only time we want to intercept motion events is if we are in the
343 * drag mode.
344 */
345 return mIsBeingDragged;
346 }

◆ onLayout()

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

Definition at line 1115 of file ScrollView2D.java.

1116 {
1117 super.onLayout(changed, l, t, r, b);
1118 mIsLayoutDirty = false;
1119 // Give a child focus if it needs it
1120 if (mChildToScrollTo != null && isViewDescendantOf(mChildToScrollTo, this))
1121 {
1122 scrollToChild(mChildToScrollTo);
1123 }
1124 mChildToScrollTo = null;
1125
1126 // Center the content area (excluding touch-pointer padding) within the viewport.
1127 // This keeps the RDP surface visually centered regardless of pointer padding changes.
1128 if (getChildCount() > 0)
1129 {
1130 View child = getChildAt(0);
1131 SessionView sv = findViewById(R.id.sessionView);
1132 int ptw = sv != null ? sv.getTouchPointerPaddingWidth() : 0;
1133 int pth = sv != null ? sv.getTouchPointerPaddingHeight() : 0;
1134 int contentW = child.getMeasuredWidth() - ptw;
1135 int contentH = child.getMeasuredHeight() - pth;
1136 int usableW = getWidth() - getPaddingLeft() - getPaddingRight();
1137 int usableH = getHeight() - getPaddingTop() - getPaddingBottom();
1138 int left = getPaddingLeft() + Math.max(0, (usableW - contentW) / 2);
1139 int top;
1140 if (contentH == lastCenterContentH)
1141 {
1142 // viewport-only change (e.g. keyboard): keep position, don't re-center
1143 top = lastCenterTop;
1144 }
1145 else
1146 {
1147 top = getPaddingTop() + Math.max(0, (usableH - contentH) / 2);
1148 lastCenterContentH = contentH;
1149 lastCenterTop = top;
1150 }
1151 child.layout(left, top, left + child.getMeasuredWidth(),
1152 top + child.getMeasuredHeight());
1153 }
1154
1155 // Calling this with the present values causes it to re-clamp them
1156 scrollTo(getScrollX(), getScrollY());
1157 }

◆ 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 1072 of file ScrollView2D.java.

1073 {
1074 // convert from forward / backward notation to up / down / left / right
1075 // (ugh).
1076 if (direction == View.FOCUS_FORWARD)
1077 {
1078 direction = View.FOCUS_DOWN;
1079 }
1080 else if (direction == View.FOCUS_BACKWARD)
1081 {
1082 direction = View.FOCUS_UP;
1083 }
1084
1085 final View nextFocus = previouslyFocusedRect == null
1086 ? FocusFinder.getInstance().findNextFocus(this, null, direction)
1087 : FocusFinder.getInstance().findNextFocusFromRect(
1088 this, previouslyFocusedRect, direction);
1089
1090 if (nextFocus == null)
1091 {
1092 return false;
1093 }
1094
1095 return nextFocus.requestFocus(direction, previouslyFocusedRect);
1096 }

◆ onScrollChanged()

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

Definition at line 1290 of file ScrollView2D.java.

1291 {
1292 super.onScrollChanged(x, y, oldx, oldy);
1293 if (scrollView2DListener != null)
1294 {
1295 scrollView2DListener.onScrollChanged(this, x, y, oldx, oldy);
1296 }
1297 }

◆ onSizeChanged()

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

Definition at line 1159 of file ScrollView2D.java.

1160 {
1161 super.onSizeChanged(w, h, oldw, oldh);
1162
1163 View currentFocused = findFocus();
1164 if (null == currentFocused || this == currentFocused)
1165 return;
1166
1167 // If the currently-focused view was visible on the screen when the
1168 // screen was at the old height, then scroll the screen to make that
1169 // view visible with the new screen height.
1170 currentFocused.getDrawingRect(mTempRect);
1171 offsetDescendantRectToMyCoords(currentFocused, mTempRect);
1172 int scrollDeltaX = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
1173 int scrollDeltaY = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
1174 doScroll(scrollDeltaX, scrollDeltaY);
1175 }

◆ onTouchEvent()

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

Definition at line 348 of file ScrollView2D.java.

349 {
350
351 if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0)
352 {
353 // Don't handle edge touches immediately -- they may actually belong to one of our
354 // descendants.
355 return false;
356 }
357
358 if (!canScroll())
359 {
360 return false;
361 }
362
363 if (mVelocityTracker == null)
364 {
365 mVelocityTracker = VelocityTracker.obtain();
366 }
367 mVelocityTracker.addMovement(ev);
368
369 final int action = ev.getAction();
370 final float y = ev.getY();
371 final float x = ev.getX();
372
373 switch (action)
374 {
375 case MotionEvent.ACTION_DOWN:
376 /*
377 * If being flinged and user touches, stop the fling. isFinished
378 * will be false if being flinged.
379 */
380 if (!mScroller.isFinished())
381 {
382 mScroller.abortAnimation();
383 }
384
385 // Remember where the motion event started
386 mLastMotionY = y;
387 mLastMotionX = x;
388 break;
389 case MotionEvent.ACTION_MOVE:
390 // Scroll to follow the motion event
391 int deltaX = (int)(mLastMotionX - x);
392 int deltaY = (int)(mLastMotionY - y);
393 mLastMotionX = x;
394 mLastMotionY = y;
395
396 if (deltaX < 0)
397 {
398 if (getScrollX() < 0)
399 {
400 deltaX = 0;
401 }
402 }
403 else if (deltaX > 0)
404 {
405 final int rightEdge = getWidth() - getPaddingRight();
406 final int availableToScroll =
407 getChildAt(0).getRight() - getScrollX() - rightEdge;
408 if (availableToScroll > 0)
409 {
410 deltaX = Math.min(availableToScroll, deltaX);
411 }
412 else
413 {
414 deltaX = 0;
415 }
416 }
417 if (deltaY < 0)
418 {
419 if (getScrollY() < 0)
420 {
421 deltaY = 0;
422 }
423 }
424 else if (deltaY > 0)
425 {
426 final int bottomEdge = getHeight() - getPaddingBottom();
427 final int availableToScroll =
428 getChildAt(0).getBottom() - getScrollY() - bottomEdge;
429 if (availableToScroll > 0)
430 {
431 deltaY = Math.min(availableToScroll, deltaY);
432 }
433 else
434 {
435 deltaY = 0;
436 }
437 }
438 if (deltaY != 0 || deltaX != 0)
439 scrollBy(deltaX, deltaY);
440 break;
441 case MotionEvent.ACTION_UP:
442 final VelocityTracker velocityTracker = mVelocityTracker;
443 velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
444 int initialXVelocity = (int)velocityTracker.getXVelocity();
445 int initialYVelocity = (int)velocityTracker.getYVelocity();
446 if ((Math.abs(initialXVelocity) + Math.abs(initialYVelocity) > mMinimumVelocity) &&
447 getChildCount() > 0)
448 {
449 fling(-initialXVelocity, -initialYVelocity);
450 }
451 if (mVelocityTracker != null)
452 {
453 mVelocityTracker.recycle();
454 mVelocityTracker = null;
455 }
456 }
457 return true;
458 }

◆ requestChildFocus()

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

Definition at line 1047 of file ScrollView2D.java.

1048 {
1049 if (!mTwoDScrollViewMovedFocus)
1050 {
1051 if (!mIsLayoutDirty)
1052 {
1053 scrollToChild(focused);
1054 }
1055 else
1056 {
1057 // The child may not be laid out yet, we can't compute the scroll yet
1058 mChildToScrollTo = focused;
1059 }
1060 }
1061 super.requestChildFocus(child, focused);
1062 }

◆ requestChildRectangleOnScreen()

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

Definition at line 1099 of file ScrollView2D.java.

1100 {
1101 // offset into coordinate space of this scroll view
1102 rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
1103 return scrollToChildRect(rectangle, immediate);
1104 }

◆ requestLayout()

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

Definition at line 1106 of file ScrollView2D.java.

1107 {
1108 mIsLayoutDirty = true;
1109 super.requestLayout();
1110 }

◆ 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 1237 of file ScrollView2D.java.

1238 {
1239 // we rely on the fact the View.scrollBy calls scrollTo.
1240 if (getChildCount() > 0)
1241 {
1242 View child = getChildAt(0);
1243 x = clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth());
1244 y = clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(), child.getHeight());
1245 if (x != getScrollX() || y != getScrollY())
1246 {
1247 super.scrollTo(x, y);
1248 }
1249 }
1250 }

◆ setScrollEnabled()

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

Disable/Enable scrolling

Definition at line 187 of file ScrollView2D.java.

188 {
189 scrollEnabled = enable;
190 }

◆ setScrollViewListener()

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

Definition at line 1285 of file ScrollView2D.java.

1286 {
1287 this.scrollView2DListener = scrollViewListener;
1288 }

◆ 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 812 of file ScrollView2D.java.

813 {
814 long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll;
815 if (duration > ANIMATED_SCROLL_GAP)
816 {
817 mScroller.startScroll(getScrollX(), getScrollY(), dx, dy);
818 awakenScrollBars(mScroller.getDuration());
819 invalidate();
820 }
821 else
822 {
823 if (!mScroller.isFinished())
824 {
825 mScroller.abortAnimation();
826 }
827 scrollBy(dx, dy);
828 }
829 mLastScroll = AnimationUtils.currentAnimationTimeMillis();
830 }

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 838 of file ScrollView2D.java.

839 {
840 smoothScrollBy(x - getScrollX(), y - getScrollY());
841 }

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: