Java Code Examples for android.widget.ScrollView#getScrollY()

The following examples show how to use android.widget.ScrollView#getScrollY() . 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: PtrDefaultHandler2.java    From android-Ultra-Pull-To-Refresh-With-Load-More-master with MIT License 6 votes vote down vote up
public static boolean canChildScrollDown(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else if (view instanceof ScrollView) {
            ScrollView scrollView = (ScrollView) view;
            if (scrollView.getChildCount() == 0) {
                return false;
            } else {
                return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight();
            }
        } else {
            return false;
        }
    } else {
        return view.canScrollVertically(1);
    }
}
 
Example 2
Source File: ReactScrollViewTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Verify that 'scrollTo' command makes ScrollView start scrolling
 */
public void testScrollToCommand() throws Exception {
  ScrollView scrollView = getViewAtPath(0);
  ScrollViewTestModule jsModule =
      getReactContext().getCatalystInstance().getJSModule(ScrollViewTestModule.class);

  assertEquals(0, scrollView.getScrollY());

  jsModule.scrollTo(0, 300);
  waitForBridgeAndUIIdle();
  getInstrumentation().waitForIdleSync();

  // Unfortunately we need to use timeouts here in order to wait for scroll animation to happen
  // there is no better way (yet) for waiting for scroll animation to finish
  long timeout = 10000;
  long interval = 50;
  long start = System.currentTimeMillis();
  while (System.currentTimeMillis() - start < timeout) {
    if (scrollView.getScrollY() > 0) {
      break;
    }
    Thread.sleep(interval);
  }
  assertNotSame(0, scrollView.getScrollY());
  assertFalse("Drag should not be called with scrollTo", mScrollListenerModule.dragEventsMatch());
}
 
Example 3
Source File: SlideBottomPanel.java    From pius1 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Copy From ScrollView (API Level >= 14)
 * <p>The scroll range of a scroll view is the overall height of all of its
 * children.</p>
 */
private int computeVerticalScrollRange(ScrollView scrollView) {
    final int count = scrollView.getChildCount();
    final int contentHeight = scrollView.getHeight() - scrollView.getPaddingBottom() - scrollView.getPaddingTop();
    if (count == 0) {
        return contentHeight;
    }

    int scrollRange = scrollView.getChildAt(0).getBottom();
    final int scrollY = scrollView.getScrollY();
    final int overScrollBottom = Math.max(0, scrollRange - contentHeight);
    if (scrollY < 0) {
        scrollRange -= scrollY;
    } else if (scrollY > overScrollBottom) {
        scrollRange += scrollY - overScrollBottom;
    }

    return scrollRange;
}
 
Example 4
Source File: ScrollingUtil.java    From AgentWebX5 with Apache License 2.0 5 votes vote down vote up
public static boolean isScrollViewToBottom(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollContentHeight = scrollView.getScrollY() + scrollView.getMeasuredHeight() - scrollView.getPaddingTop() - scrollView.getPaddingBottom();
        int realContentHeight = scrollView.getChildAt(0).getMeasuredHeight();
        if (scrollContentHeight == realContentHeight) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: ScrollingUtil.java    From Pas with Apache License 2.0 5 votes vote down vote up
public static boolean isScrollViewToBottom(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollContentHeight = scrollView.getScrollY() + scrollView.getMeasuredHeight() - scrollView.getPaddingTop() - scrollView.getPaddingBottom();
        int realContentHeight = scrollView.getChildAt(0).getMeasuredHeight();
        if (scrollContentHeight == realContentHeight) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: FixedSubmitBarLayout.java    From ResearchStack with Apache License 2.0 5 votes vote down vote up
private void onScrollChanged(ScrollView scrollView, View submitBarGuide, View submitBar) {
    int scrollY = scrollView.getScrollY();
    int guidePosition = submitBarGuide.getTop() - scrollY;
    int guideHeight = submitBarGuide.getHeight();
    int yLimit = scrollView.getHeight() - guideHeight;

    if (guidePosition <= yLimit) {
        ViewCompat.setTranslationY(submitBar, 0);
    } else {
        int translationY = guidePosition - yLimit;
        ViewCompat.setTranslationY(submitBar, translationY);
    }

}
 
Example 7
Source File: ScrollableHelper.java    From ScrollableLayout with MIT License 5 votes vote down vote up
private static boolean isScrollViewTop(ScrollView scrollView){
    if(scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 8
Source File: ScrollableHelper.java    From ScrollableLayout with Apache License 2.0 5 votes vote down vote up
private static boolean isScrollViewTop(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 9
Source File: DrMIPSActivity.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the state of the simulation controls and the values displayed.
 * Updates the enabled/disabled states of the simulation controls.
 * It also refreshes the values displayed in the tables and the datapath,
 * and scrolls the assembled code table to make the current instruction visible.
 */
private void refreshValues() {
	updateStepBackEnabled();
	updateStepEnabled();

	refreshRegistersTableValues();
	refreshDataMemoryTableValues();
	refreshAssembledCodeTableValues();
	refreshExecTableValues();
	if(datapath != null) datapath.refresh();

	// Scroll the assembled code table to the current instruction
	int index = getCPU().getPC().getCurrentInstructionIndex();
	if(index >= 0) {
		final ScrollView scroll = (ScrollView)findViewById(R.id.tblAssembledCodeScroll);
		final View row = tblAssembledCode.getChildAt(index + 1);

		// Scroll only if the row is out of view
		if(row != null && (row.getTop() < scroll.getScrollY() ||
		                   row.getBottom() > (scroll.getScrollY() + scroll.getHeight()))) {
			scroll.post(new Runnable() {
				@Override
				public void run() {
					if(row.getTop() < scroll.getScrollY()) {
						// Row is above the visible area
						// > scroll up until the row is visible at the top of the ScrollView
						scroll.smoothScrollTo(0, row.getTop());
					}
					else {
						// Row is below the visible area
						// > scroll down until the row is visible at the bottom of the ScrollView
						scroll.smoothScrollTo(0, row.getBottom() - scroll.getHeight());
					}
				}
			});
		}
	}
}
 
Example 10
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void scrollOnDrag(View view, DragEvent event, ScrollView scrollView) {
    float ty = view.getTop() + event.getY();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getHeight() / 6;

        if (ty < scrollView.getScrollY() + thresh) {
            scrollView.smoothScrollBy(0, -10);
        } else if (ty > scrollView.getScrollY() + scrollView.getHeight() - thresh) {
            scrollView.smoothScrollBy(0, 10);
        }
    }
}
 
Example 11
Source File: LineUtils.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static int getLastVisibleLine(@NonNull ScrollView scrollView,
                                     int childHeight, int lineCount) {
    if (childHeight == 0) return 0;
    int line = (scrollView.getScrollY() * lineCount) / childHeight;
    if (line > lineCount) line = lineCount;
    return line;
}
 
Example 12
Source File: LineUtils.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static int getFirstVisibleLine(@NonNull ScrollView scrollView, int childHeight,
                                      int lineCount) throws ArithmeticException {
    if (childHeight == 0) return 0;
    int line = (scrollView.getScrollY() * lineCount) / childHeight;
    if (line < 0) line = 0;
    return line;
}
 
Example 13
Source File: JSResponderTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void testResponderLocksScrollView() {
  ScrollView scrollView = getViewByTestId("scroll_view");
  assertNotNull(scrollView);
  assertEquals(0, scrollView.getScrollY());

  float inpx40dp = PixelUtil.toPixelFromDIP(40f);
  float inpx100dp = PixelUtil.toPixelFromDIP(100f);

  SingleTouchGestureGenerator gestureGenerator = createGestureGenerator();

  gestureGenerator
      .startGesture(30, 30 + inpx100dp)
      .dragTo(30 + inpx40dp, 30, 10, 1200)
      .endGesture(180, 100);

  waitForBridgeAndUIIdle();

  assertTrue("Expected to scroll by at least 80 dp", scrollView.getScrollY() >= inpx100dp * .8f);

  int previousScroll = scrollView.getScrollY();

  gestureGenerator
      .startGesture(30, 30 + inpx100dp)
      .dragTo(30 + inpx40dp, 30 + inpx100dp, 10, 1200);

  waitForBridgeAndUIIdle();

  gestureGenerator
      .dragTo(30 + inpx40dp, 30, 10, 1200)
      .endGesture();

  waitForBridgeAndUIIdle();
  assertEquals("Expected not to scroll", scrollView.getScrollY(), previousScroll);

}
 
Example 14
Source File: ScrollableHelper.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private static boolean isScrollViewTop(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 15
Source File: HeaderScrollHelper.java    From RichWebList with Apache License 2.0 5 votes vote down vote up
private boolean isScrollViewTop(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 16
Source File: LineUtils.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static int getLastVisibleLine(@NonNull ScrollView scrollView,
                                     int childHeight, int lineCount) {
    if (childHeight == 0) return 0;
    int line = (scrollView.getScrollY() * lineCount) / childHeight;
    if (line > lineCount) line = lineCount;
    return line;
}
 
Example 17
Source File: LineUtils.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static int getLastVisibleLine(@NonNull ScrollView scrollView,
                                     int childHeight, int lineCount) {
    if (childHeight == 0) return 0;
    int line = (scrollView.getScrollY() * lineCount) / childHeight;
    if (line > lineCount) line = lineCount;
    return line;
}
 
Example 18
Source File: DrawerView.java    From material-drawer with MIT License 4 votes vote down vote up
@Override
public Integer get(ScrollView object) {
    return object.getScrollY();
}
 
Example 19
Source File: SketchFile.java    From APDE with GNU General Public License v2.0 3 votes vote down vote up
public FileChange getFileChange() {
	EditText code = fragment.getCodeEditText();
	
	if (code == null) {
		return null;
	}
	
	String codeText = code.getText().toString();
	
	if (!text.equals(codeText)) {
		HorizontalScrollView scrollerX = fragment.getCodeScrollerX();
		ScrollView scrollerY = fragment.getCodeScroller();
		
		FileChange change = new FileChange();
		
		getTextChange(change, text, codeText);
		
		change.beforeSelectionStart = selectionStart;
		change.beforeSelectionEnd = selectionEnd;
		
		change.afterSelectionStart = code.getSelectionStart();
		change.afterSelectionEnd = code.getSelectionEnd();
		
		change.beforeScrollX = scrollX;
		change.beforeScrollY = scrollY;
		
		change.afterScrollX = scrollerX.getScrollX();
		change.afterScrollY = scrollerY.getScrollY();
		
		return change;
	}
	
	return null;
}
 
Example 20
Source File: ScrollStateUtil.java    From SimpleProject with MIT License 2 votes vote down vote up
/**
 * ScrollView是否已滑动到顶部
 * @param scrollView
 * @return
 */
public static boolean scrollViewReachTop(ScrollView scrollView) {
	return scrollView.getScrollY() == 0;
}