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

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

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

847 {
848 int count = getChildCount();
849 return count == 0 ? getWidth() : (getChildAt(0)).getRight();
850 }

◆ computeScroll()

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

Definition at line 879 of file ScrollView2D.java.

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

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

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

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

841 {
842 int count = getChildCount();
843 return count == 0 ? getHeight() : (getChildAt(0)).getBottom();
844 }

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

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

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

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

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

854 {
855 ViewGroup.LayoutParams lp = child.getLayoutParams();
856 int childWidthMeasureSpec;
857 int childHeightMeasureSpec;
858
859 childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
860 getPaddingLeft() + getPaddingRight(), lp.width);
861 childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
862
863 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
864 }

◆ measureChildWithMargins()

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

Definition at line 867 of file ScrollView2D.java.

869 {
870 final MarginLayoutParams lp = (MarginLayoutParams)child.getLayoutParams();
871 final int childWidthMeasureSpec =
872 MeasureSpec.makeMeasureSpec(lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED);
873 final int childHeightMeasureSpec =
874 MeasureSpec.makeMeasureSpec(lp.topMargin + lp.bottomMargin, MeasureSpec.UNSPECIFIED);
875
876 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
877 }

◆ 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 final int action = ev.getAction();
284 if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged))
285 {
286 return true;
287 }
288 if (!canScroll())
289 {
290 mIsBeingDragged = false;
291 return false;
292 }
293 final float y = ev.getY();
294 final float x = ev.getX();
295 switch (action)
296 {
297 case MotionEvent.ACTION_MOVE:
298 /*
299 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
300 * whether the user has moved far enough from his original down touch.
301 */
302 /*
303 * Locally do absolute value. mLastMotionY is set to the y value
304 * of the down event.
305 */
306 final int yDiff = (int)Math.abs(y - mLastMotionY);
307 final int xDiff = (int)Math.abs(x - mLastMotionX);
308 if (yDiff > mTouchSlop || xDiff > mTouchSlop)
309 {
310 mIsBeingDragged = true;
311 }
312 break;
313
314 case MotionEvent.ACTION_DOWN:
315 /* Remember location of down touch */
316 mLastMotionY = y;
317 mLastMotionX = x;
318
319 /*
320 * If being flinged and user touches the screen, initiate drag;
321 * otherwise don't. mScroller.isFinished should be false when
322 * being flinged.
323 */
324 mIsBeingDragged = !mScroller.isFinished();
325 break;
326
327 case MotionEvent.ACTION_CANCEL:
328 case MotionEvent.ACTION_UP:
329 /* Release the drag */
330 mIsBeingDragged = false;
331 break;
332 }
333
334 /*
335 * The only time we want to intercept motion events is if we are in the
336 * drag mode.
337 */
338 return mIsBeingDragged;
339 }

◆ onLayout()

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

Definition at line 1108 of file ScrollView2D.java.

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

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

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

◆ onScrollChanged()

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

Definition at line 1283 of file ScrollView2D.java.

1284 {
1285 super.onScrollChanged(x, y, oldx, oldy);
1286 if (scrollView2DListener != null)
1287 {
1288 scrollView2DListener.onScrollChanged(this, x, y, oldx, oldy);
1289 }
1290 }

◆ onSizeChanged()

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

Definition at line 1152 of file ScrollView2D.java.

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

◆ onTouchEvent()

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

Definition at line 341 of file ScrollView2D.java.

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

◆ requestChildFocus()

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

Definition at line 1040 of file ScrollView2D.java.

1041 {
1042 if (!mTwoDScrollViewMovedFocus)
1043 {
1044 if (!mIsLayoutDirty)
1045 {
1046 scrollToChild(focused);
1047 }
1048 else
1049 {
1050 // The child may not be laid out yet, we can't compute the scroll yet
1051 mChildToScrollTo = focused;
1052 }
1053 }
1054 super.requestChildFocus(child, focused);
1055 }

◆ requestChildRectangleOnScreen()

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

Definition at line 1092 of file ScrollView2D.java.

1093 {
1094 // offset into coordinate space of this scroll view
1095 rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
1096 return scrollToChildRect(rectangle, immediate);
1097 }

◆ requestLayout()

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

Definition at line 1099 of file ScrollView2D.java.

1100 {
1101 mIsLayoutDirty = true;
1102 super.requestLayout();
1103 }

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

1231 {
1232 // we rely on the fact the View.scrollBy calls scrollTo.
1233 if (getChildCount() > 0)
1234 {
1235 View child = getChildAt(0);
1236 x = clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth());
1237 y = clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(), child.getHeight());
1238 if (x != getScrollX() || y != getScrollY())
1239 {
1240 super.scrollTo(x, y);
1241 }
1242 }
1243 }

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

1279 {
1280 this.scrollView2DListener = scrollViewListener;
1281 }

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

806 {
807 long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll;
808 if (duration > ANIMATED_SCROLL_GAP)
809 {
810 mScroller.startScroll(getScrollX(), getScrollY(), dx, dy);
811 awakenScrollBars(mScroller.getDuration());
812 invalidate();
813 }
814 else
815 {
816 if (!mScroller.isFinished())
817 {
818 mScroller.abortAnimation();
819 }
820 scrollBy(dx, dy);
821 }
822 mLastScroll = AnimationUtils.currentAnimationTimeMillis();
823 }

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

832 {
833 smoothScrollBy(x - getScrollX(), y - getScrollY());
834 }

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: