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

Constructor & Destructor Documentation

◆ ScrollView2D() [1/3]

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

Definition at line 107 of file ScrollView2D.java.

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

◆ ScrollView2D() [2/3]

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

Definition at line 113 of file ScrollView2D.java.

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

◆ ScrollView2D() [3/3]

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

Definition at line 119 of file ScrollView2D.java.

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

Member Function Documentation

◆ addView() [1/4]

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

Definition at line 219 of file ScrollView2D.java.

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

◆ addView() [2/4]

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

Definition at line 228 of file ScrollView2D.java.

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

◆ addView() [3/4]

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

Definition at line 246 of file ScrollView2D.java.

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

◆ addView() [4/4]

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

Definition at line 237 of file ScrollView2D.java.

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

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

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

References computeScrollDeltaToGetChildRectOnScreen(), and getMaxScrollAmountVertical().

Here is the call graph for this function:

◆ computeHorizontalScrollRange()

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

Definition at line 855 of file ScrollView2D.java.

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

◆ computeScroll()

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

Definition at line 888 of file ScrollView2D.java.

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

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

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

Referenced by 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 849 of file ScrollView2D.java.

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

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

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

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

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

◆ getBottomFadingEdgeStrength()

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

Definition at line 139 of file ScrollView2D.java.

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

◆ getLeftFadingEdgeStrength()

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

Definition at line 155 of file ScrollView2D.java.

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

◆ getMaxScrollAmountHorizontal()

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

Definition at line 202 of file ScrollView2D.java.

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

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

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

Referenced by arrowScroll().

Here is the caller graph for this function:

◆ getRightFadingEdgeStrength()

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

Definition at line 169 of file ScrollView2D.java.

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

◆ getTopFadingEdgeStrength()

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

Definition at line 125 of file ScrollView2D.java.

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

◆ measureChild()

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

Definition at line 862 of file ScrollView2D.java.

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

◆ measureChildWithMargins()

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

Definition at line 876 of file ScrollView2D.java.

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

◆ onInterceptTouchEvent()

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

Definition at line 273 of file ScrollView2D.java.

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

◆ onLayout()

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

Definition at line 1117 of file ScrollView2D.java.

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

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

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

◆ onScrollChanged()

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

Definition at line 1292 of file ScrollView2D.java.

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

◆ onSizeChanged()

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

Definition at line 1161 of file ScrollView2D.java.

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

◆ onTouchEvent()

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

Definition at line 350 of file ScrollView2D.java.

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

◆ requestChildFocus()

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

Definition at line 1049 of file ScrollView2D.java.

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

◆ requestChildRectangleOnScreen()

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

Definition at line 1101 of file ScrollView2D.java.

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

◆ requestLayout()

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

Definition at line 1108 of file ScrollView2D.java.

1109 {
1110 mIsLayoutDirty = true;
1111 super.requestLayout();
1112 }

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

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

◆ setScrollEnabled()

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

Disable/Enable scrolling

Definition at line 188 of file ScrollView2D.java.

189 {
190 scrollEnabled = enable;
191 }

◆ setScrollViewListener()

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

Definition at line 1287 of file ScrollView2D.java.

1288 {
1289 this.scrollView2DListener = scrollViewListener;
1290 }

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

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

Referenced by 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 840 of file ScrollView2D.java.

841 {
842 smoothScrollBy(x - getScrollX(), y - getScrollY());
843 }

References smoothScrollBy().

Here is the call graph for this function:

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