Java Code Examples for android.view.View#requestRectangleOnScreen()
The following examples show how to use
android.view.View#requestRectangleOnScreen() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NestedScrollTo.java From Kore with Apache License 2.0 | 6 votes |
@Override public void perform(UiController uiController, View view) { if (isDisplayingAtLeast(90).matches(view)) { LogUtils.LOGI(TAG, "View is already displayed. Returning."); return; } Rect rect = new Rect(); view.getDrawingRect(rect); if (!view.requestRectangleOnScreen(rect, true /* immediate */)) { LogUtils.LOGW(TAG, "Scrolling to view was requested, but none of the parents scrolled."); } uiController.loopMainThreadUntilIdle(); if (!isDisplayingAtLeast(90).matches(view)) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(new RuntimeException( "Scrolling to view was attempted, but the view is not displayed")) .build(); } }
Example 2
Source File: ScrollToAction.java From android-test with Apache License 2.0 | 6 votes |
@Override public void perform(UiController uiController, View view) { if (isDisplayingAtLeast(90).matches(view)) { Log.i(TAG, "View is already displayed. Returning."); return; } Rect rect = new Rect(); view.getDrawingRect(rect); if (!view.requestRectangleOnScreen(rect, true /* immediate */)) { Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled."); } uiController.loopMainThreadUntilIdle(); if (!isDisplayingAtLeast(90).matches(view)) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause( new RuntimeException( "Scrolling to view was attempted, but the view is not displayed")) .build(); } }
Example 3
Source File: QuestionWidget.java From commcare-android with Apache License 2.0 | 4 votes |
/** * Use to signal that there's a portion of this view that wants to be * visible to the user on the screen. This method will place the sub * view on the screen, and will also place as much of this view as possible * on the screen. If this view is smaller than the viewable area available, it * will be fully visible in addition to the subview. */ private void requestChildViewOnScreen(View child) { //Take focus so the user can be prepared to interact with this question, since //they will need to be fixing the input acceptFocus(); //Get the rectangle that wants to put itself on the screen Rect vitalPortion = new Rect(); child.getDrawingRect(vitalPortion); //Save a reference to it in case we have to manipulate it later. Rect vitalPortionSaved = new Rect(); child.getDrawingRect(vitalPortionSaved); //Then get the bounding rectangle for this whole view. Rect wholeView = new Rect(); this.getDrawingRect(wholeView); //If we don't know enough about the screen, just default to asking to see the //subview that was requested. if (mFrameHeight == -1) { child.requestRectangleOnScreen(vitalPortion); return; } //If the whole view fits, just request that we display the whole thing. if (wholeView.height() < mFrameHeight) { this.requestRectangleOnScreen(wholeView); return; } //The whole view will not fit, we need to scale down our requested focus. //Trying to construct the "ideal" rectangle here is actually pretty hard //but the base case is just to see if we can get the view onto the screen from //the bottom or the top int topY = wholeView.top; int bottomY = wholeView.bottom; //shrink the view to contain only the current frame size. wholeView.inset(0, (wholeView.height() - mFrameHeight) / 2); wholeView.offsetTo(wholeView.left, topY); //The view is now the size of the frame and anchored back at the top. //Now let's contextualize where the child view actually is in this frame. this.offsetDescendantRectToMyCoords(child, vitalPortion); //If the newly transformed view now contains the child portion, we're good if (wholeView.contains(vitalPortion)) { this.requestRectangleOnScreen(wholeView); return; } //otherwise, move to the requested frame to be at the bottom of this view wholeView.offsetTo(wholeView.left, bottomY - wholeView.height()); //now see if the transformed view contains the vital portion if (wholeView.contains(vitalPortion)) { this.requestRectangleOnScreen(wholeView); return; } //Otherwise the child is hidden in the frame, so it won't matter which //we choose. child.requestRectangleOnScreen(vitalPortionSaved); }