Java Code Examples for android.widget.HorizontalScrollView#getScrollX()

The following examples show how to use android.widget.HorizontalScrollView#getScrollX() . 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: ReactHorizontalScrollContainerView.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  if (mLayoutDirection == LAYOUT_DIRECTION_RTL) {
    // When the layout direction is RTL, we expect Yoga to give us a layout
    // that extends off the screen to the left so we re-center it with left=0
    int newLeft = 0;
    int width = right - left;
    int newRight = newLeft + width;
    setLeft(newLeft);
    setRight(newRight);

    // Call with the present values in order to re-layout if necessary
    HorizontalScrollView parent = (HorizontalScrollView) getParent();
    // Fix the ScrollX position when using RTL language
    int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth;
    parent.scrollTo(offsetX, parent.getScrollY());
  }
  mCurrentWidth = getWidth();
}
 
Example 2
Source File: ReactHorizontalScrollViewTestCase.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 {
  HorizontalScrollView scrollView = getViewAtPath(0);
  ScrollViewTestModule jsModule =
      getReactContext().getCatalystInstance().getJSModule(ScrollViewTestModule.class);

  assertEquals(0, scrollView.getScrollX());

  jsModule.scrollTo(300, 0);
  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.getScrollX() > 0) {
      break;
    }
    Thread.sleep(interval);
  }
  assertNotSame(0, scrollView.getScrollX());
}
 
Example 3
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void hscrollOnDrag(View view, DragEvent event, HorizontalScrollView scrollView) {
    float tx = view.getLeft() + event.getX();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getWidth() / 6;

        if (tx < scrollView.getScrollX() + thresh) {
            scrollView.smoothScrollBy(-10, 0);
        } else if (tx > scrollView.getScrollX() + scrollView.getWidth() - thresh) {
            scrollView.smoothScrollBy(10,0);
        }
    }
}
 
Example 4
Source File: AppBarHorizontalScrollingTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testScrollAndClick() throws Throwable {
  final Activity activity = activityTestRule.getActivity();
  final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

  final Button button = activity.findViewById(R.id.button);
  final View.OnClickListener mockClickListener = mock(View.OnClickListener.class);
  button.setOnClickListener(mockClickListener);

  // Emulate a click on the button to verify that the registered listener is invoked
  // prior to performing a horizontal swipe across the app ba

  final int[] buttonXY = new int[2];
  button.getLocationOnScreen(buttonXY);
  final int buttonWidth = button.getWidth();
  final int buttonHeight = button.getHeight();
  final float emulatedTapX = buttonXY[0] + buttonWidth / 2.0f;
  final float emulatedTapY = buttonXY[1] + buttonHeight / 2.0f;

  emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY);
  verify(mockClickListener).onClick(button);
  reset(mockClickListener);

  final HorizontalScrollView hsv = activity.findViewById(R.id.hsv);
  final int scrollXBefore = hsv.getScrollX();
  // Now scroll / swipe horizontally across our scrollable content in the app bar
  onView(withId(R.id.app_bar)).perform(swipeLeft());
  assertTrue("Horizontal scroll performed", hsv.getScrollX() > scrollXBefore);

  // And emulate another click on the button to verify that the registered listener is still
  // invoked immediately after performing the horizontal swipe across the app bar
  emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY);
  verify(mockClickListener).onClick(button);
}
 
Example 5
Source File: x.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public boolean canScrollHorizontal(View view, int i)
{
    HorizontalScrollView horizontalscrollview = (HorizontalScrollView)view;
    for (int j = horizontalscrollview.getScrollX(); horizontalscrollview.getChildCount() == 0 || (i >= 0 || j >= horizontalscrollview.getChildAt(0).getWidth() - horizontalscrollview.getWidth()) && (i <= 0 || j <= 0);)
    {
        return false;
    }

    return true;
}
 
Example 6
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;
}