-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TouchInterceptionFrameLayout's test.
- Loading branch information
Showing
16 changed files
with
852 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...github/ksoichiro/android/observablescrollview/test/TouchInterceptionGridViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.github.ksoichiro.android.observablescrollview.test; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.MotionEvent; | ||
import android.widget.FrameLayout; | ||
import android.widget.TextView; | ||
|
||
import com.github.ksoichiro.android.observablescrollview.ObservableGridView; | ||
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; | ||
import com.github.ksoichiro.android.observablescrollview.ScrollState; | ||
import com.github.ksoichiro.android.observablescrollview.Scrollable; | ||
import com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout; | ||
import com.nineoldandroids.view.ViewHelper; | ||
|
||
public class TouchInterceptionGridViewActivity extends Activity implements ObservableScrollViewCallbacks { | ||
|
||
private TouchInterceptionFrameLayout mInterceptionLayout; | ||
private Scrollable mScrollable; | ||
|
||
private int mIntersectionHeight; | ||
private int mHeaderBarHeight; | ||
|
||
private float mScrollYOnDownMotion; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_touchinterception_gridview); | ||
((TextView) findViewById(R.id.title)).setText(getClass().getSimpleName()); | ||
mScrollable = (Scrollable) findViewById(R.id.scrollable); | ||
mScrollable.setScrollViewCallbacks(this); | ||
UiTestUtils.setDummyData(this, (ObservableGridView) mScrollable); | ||
|
||
mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.intersection_height); | ||
mHeaderBarHeight = getResources().getDimensionPixelSize(R.dimen.header_bar_height); | ||
|
||
mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.scroll_wrapper); | ||
mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener); | ||
} | ||
|
||
@Override | ||
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { | ||
} | ||
|
||
@Override | ||
public void onDownMotionEvent() { | ||
} | ||
|
||
@Override | ||
public void onUpOrCancelMotionEvent(ScrollState scrollState) { | ||
} | ||
|
||
private TouchInterceptionFrameLayout.TouchInterceptionListener mInterceptionListener = new TouchInterceptionFrameLayout.TouchInterceptionListener() { | ||
@Override | ||
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) { | ||
final int minInterceptionLayoutY = -mIntersectionHeight; | ||
return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout) | ||
|| (moving && mScrollable.getCurrentScrollY() - diffY < 0); | ||
} | ||
|
||
@Override | ||
public void onDownMotionEvent(MotionEvent ev) { | ||
mScrollYOnDownMotion = mScrollable.getCurrentScrollY(); | ||
} | ||
|
||
@Override | ||
public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) { | ||
float translationY = ViewHelper.getTranslationY(mInterceptionLayout) - mScrollYOnDownMotion + diffY; | ||
if (translationY < -mIntersectionHeight) { | ||
translationY = -mIntersectionHeight; | ||
} else if (getScreenHeight() - mHeaderBarHeight < translationY) { | ||
translationY = getScreenHeight() - mHeaderBarHeight; | ||
} | ||
|
||
slideTo(translationY, true); | ||
} | ||
|
||
@Override | ||
public void onUpOrCancelMotionEvent(MotionEvent ev) { | ||
} | ||
}; | ||
|
||
private void slideTo(float translationY, final boolean animated) { | ||
ViewHelper.setTranslationY(mInterceptionLayout, translationY); | ||
|
||
if (translationY < 0) { | ||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); | ||
lp.height = (int) -translationY + getScreenHeight(); | ||
mInterceptionLayout.requestLayout(); | ||
} | ||
} | ||
|
||
private int getScreenHeight() { | ||
return findViewById(android.R.id.content).getHeight(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ub/ksoichiro/android/observablescrollview/test/TouchInterceptionGridViewActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.ksoichiro.android.observablescrollview.test; | ||
|
||
import android.app.Activity; | ||
import android.test.ActivityInstrumentationTestCase2; | ||
import android.test.TouchUtils; | ||
|
||
import com.github.ksoichiro.android.observablescrollview.ObservableGridView; | ||
|
||
public class TouchInterceptionGridViewActivityTest extends ActivityInstrumentationTestCase2<TouchInterceptionGridViewActivity> { | ||
|
||
private Activity activity; | ||
private ObservableGridView scrollable; | ||
|
||
public TouchInterceptionGridViewActivityTest() { | ||
super(TouchInterceptionGridViewActivity.class); | ||
} | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
setActivityInitialTouchMode(true); | ||
activity = getActivity(); | ||
scrollable = (ObservableGridView) activity.findViewById(R.id.scrollable); | ||
} | ||
|
||
public void testScroll() throws Throwable { | ||
TouchUtils.touchAndCancelView(this, scrollable); | ||
getInstrumentation().waitForIdleSync(); | ||
|
||
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.UP); | ||
getInstrumentation().waitForIdleSync(); | ||
|
||
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.DOWN); | ||
getInstrumentation().waitForIdleSync(); | ||
|
||
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.DOWN); | ||
getInstrumentation().waitForIdleSync(); | ||
} | ||
|
||
public void testSaveAndRestoreInstanceState() throws Throwable { | ||
UiTestUtils.saveAndRestoreInstanceState(this, activity); | ||
testScroll(); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...github/ksoichiro/android/observablescrollview/test/TouchInterceptionListViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.github.ksoichiro.android.observablescrollview.test; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.MotionEvent; | ||
import android.widget.FrameLayout; | ||
import android.widget.TextView; | ||
|
||
import com.github.ksoichiro.android.observablescrollview.ObservableListView; | ||
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; | ||
import com.github.ksoichiro.android.observablescrollview.ScrollState; | ||
import com.github.ksoichiro.android.observablescrollview.Scrollable; | ||
import com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout; | ||
import com.nineoldandroids.view.ViewHelper; | ||
|
||
public class TouchInterceptionListViewActivity extends Activity implements ObservableScrollViewCallbacks { | ||
|
||
private TouchInterceptionFrameLayout mInterceptionLayout; | ||
private Scrollable mScrollable; | ||
|
||
private int mIntersectionHeight; | ||
private int mHeaderBarHeight; | ||
|
||
private float mScrollYOnDownMotion; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_touchinterception_listview); | ||
((TextView) findViewById(R.id.title)).setText(getClass().getSimpleName()); | ||
mScrollable = (Scrollable) findViewById(R.id.scrollable); | ||
mScrollable.setScrollViewCallbacks(this); | ||
UiTestUtils.setDummyData(this, (ObservableListView) mScrollable); | ||
|
||
mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.intersection_height); | ||
mHeaderBarHeight = getResources().getDimensionPixelSize(R.dimen.header_bar_height); | ||
|
||
mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.scroll_wrapper); | ||
mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener); | ||
} | ||
|
||
@Override | ||
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { | ||
} | ||
|
||
@Override | ||
public void onDownMotionEvent() { | ||
} | ||
|
||
@Override | ||
public void onUpOrCancelMotionEvent(ScrollState scrollState) { | ||
} | ||
|
||
private TouchInterceptionFrameLayout.TouchInterceptionListener mInterceptionListener = new TouchInterceptionFrameLayout.TouchInterceptionListener() { | ||
@Override | ||
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) { | ||
final int minInterceptionLayoutY = -mIntersectionHeight; | ||
return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout) | ||
|| (moving && mScrollable.getCurrentScrollY() - diffY < 0); | ||
} | ||
|
||
@Override | ||
public void onDownMotionEvent(MotionEvent ev) { | ||
mScrollYOnDownMotion = mScrollable.getCurrentScrollY(); | ||
} | ||
|
||
@Override | ||
public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) { | ||
float translationY = ViewHelper.getTranslationY(mInterceptionLayout) - mScrollYOnDownMotion + diffY; | ||
if (translationY < -mIntersectionHeight) { | ||
translationY = -mIntersectionHeight; | ||
} else if (getScreenHeight() - mHeaderBarHeight < translationY) { | ||
translationY = getScreenHeight() - mHeaderBarHeight; | ||
} | ||
|
||
slideTo(translationY, true); | ||
} | ||
|
||
@Override | ||
public void onUpOrCancelMotionEvent(MotionEvent ev) { | ||
} | ||
}; | ||
|
||
private void slideTo(float translationY, final boolean animated) { | ||
ViewHelper.setTranslationY(mInterceptionLayout, translationY); | ||
|
||
if (translationY < 0) { | ||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); | ||
lp.height = (int) -translationY + getScreenHeight(); | ||
mInterceptionLayout.requestLayout(); | ||
} | ||
} | ||
|
||
private int getScreenHeight() { | ||
return findViewById(android.R.id.content).getHeight(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ub/ksoichiro/android/observablescrollview/test/TouchInterceptionListViewActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.ksoichiro.android.observablescrollview.test; | ||
|
||
import android.app.Activity; | ||
import android.test.ActivityInstrumentationTestCase2; | ||
import android.test.TouchUtils; | ||
|
||
import com.github.ksoichiro.android.observablescrollview.ObservableListView; | ||
|
||
public class TouchInterceptionListViewActivityTest extends ActivityInstrumentationTestCase2<TouchInterceptionListViewActivity> { | ||
|
||
private Activity activity; | ||
private ObservableListView scrollable; | ||
|
||
public TouchInterceptionListViewActivityTest() { | ||
super(TouchInterceptionListViewActivity.class); | ||
} | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
setActivityInitialTouchMode(true); | ||
activity = getActivity(); | ||
scrollable = (ObservableListView) activity.findViewById(R.id.scrollable); | ||
} | ||
|
||
public void testScroll() throws Throwable { | ||
TouchUtils.touchAndCancelView(this, scrollable); | ||
getInstrumentation().waitForIdleSync(); | ||
|
||
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.UP); | ||
getInstrumentation().waitForIdleSync(); | ||
|
||
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.DOWN); | ||
getInstrumentation().waitForIdleSync(); | ||
|
||
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.DOWN); | ||
getInstrumentation().waitForIdleSync(); | ||
} | ||
|
||
public void testSaveAndRestoreInstanceState() throws Throwable { | ||
UiTestUtils.saveAndRestoreInstanceState(this, activity); | ||
testScroll(); | ||
} | ||
} |
Oops, something went wrong.