Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ObservableNestedScrollView #257

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ subprojects {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Tue Jul 19 18:40:39 KST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

buildTypes {
debug {
testCoverageEnabled = true
testCoverageEnabled = false
}
}

Expand Down
1 change: 1 addition & 0 deletions library/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<activity android:name=".RecyclerViewActivity" />
<activity android:name=".RecyclerViewScrollFromBottomActivity" />
<activity android:name=".ScrollViewActivity" />
<activity android:name=".NestedScrollViewActivity" />
<activity android:name=".TouchInterceptionGridViewActivity" android:theme="@style/AppTheme.Toolbar" />
<activity android:name=".TouchInterceptionListViewActivity" android:theme="@style/AppTheme.Toolbar" />
<activity android:name=".TouchInterceptionRecyclerViewActivity" android:theme="@style/AppTheme.Toolbar" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.ksoichiro.android.observablescrollview.test;

import android.app.Activity;
import android.os.Bundle;

import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import com.github.ksoichiro.android.observablescrollview.Scrollable;

public class NestedScrollViewActivity extends Activity implements ObservableScrollViewCallbacks {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nestedscrollview);
((Scrollable) findViewById(R.id.scrollable)).setScrollViewCallbacks(this);
}

@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
}

@Override
public void onDownMotionEvent() {
}

@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.github.ksoichiro.android.observablescrollview.test;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;

import com.github.ksoichiro.android.observablescrollview.ObservableNestedScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;

public class NestedScrollViewActivityTest extends ActivityInstrumentationTestCase2<NestedScrollViewActivity> {

private Activity activity;
private ObservableNestedScrollView scrollable;
private int[] callbackCounter;

public NestedScrollViewActivityTest() {
super(NestedScrollViewActivity.class);
}

@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(true);
activity = getActivity();
scrollable = (ObservableNestedScrollView) activity.findViewById(R.id.scrollable);
callbackCounter = new int[2];
}

public void testInitialize() throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
new ObservableNestedScrollView(activity);
new ObservableNestedScrollView(activity, null, 0);
}
});
}

public void testScroll() throws Throwable {
UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.UP);
getInstrumentation().waitForIdleSync();

UiTestUtils.swipeVertically(this, scrollable, UiTestUtils.Direction.DOWN);
getInstrumentation().waitForIdleSync();
}

public void testSaveAndRestoreInstanceState() throws Throwable {
UiTestUtils.saveAndRestoreInstanceState(this, activity);
testScroll();
}

public void testNoCallbacks() throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
scrollable = (ObservableNestedScrollView) activity.findViewById(R.id.scrollable);
scrollable.setScrollViewCallbacks(null);
}
});
testScroll();
}

public void testCallbacks() throws Throwable {
final ObservableScrollViewCallbacks[] callbacks = new ObservableScrollViewCallbacks[2];
callbackCounter[0] = 0;
callbackCounter[1] = 0;
runTestOnUiThread(new Runnable() {
@Override
public void run() {
scrollable = (ObservableNestedScrollView) activity.findViewById(R.id.scrollable);
callbacks[0] = new ObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
callbackCounter[0]++;
}

@Override
public void onDownMotionEvent() {
}

@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
};
scrollable.addScrollViewCallbacks(callbacks[0]);
callbacks[1] = new ObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
callbackCounter[1]++;
}

@Override
public void onDownMotionEvent() {
}

@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
};
scrollable.addScrollViewCallbacks(callbacks[1]);
}
});
testScroll();
// Assert that all the callbacks are enabled and get called.
assertTrue(0 < callbackCounter[0]);
assertTrue(0 < callbackCounter[1]);

// Remove one of the callbacks and scroll again to assert it's really removed.
runTestOnUiThread(new Runnable() {
@Override
public void run() {
scrollable.removeScrollViewCallbacks(callbacks[0]);
}
});
callbackCounter[0] = 0;
callbackCounter[1] = 0;
testScroll();
assertTrue(0 == callbackCounter[0]);
assertTrue(0 < callbackCounter[1]);

// Clear all callbacks and assert they're really removed.
runTestOnUiThread(new Runnable() {
@Override
public void run() {
scrollable.clearScrollViewCallbacks();
}
});
callbackCounter[0] = 0;
callbackCounter[1] = 0;
testScroll();
assertTrue(0 == callbackCounter[0]);
assertTrue(0 == callbackCounter[1]);
}
}
28 changes: 28 additions & 0 deletions library/src/androidTest/res/layout/activity_nestedscrollview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Copyright 2014 Soichiro Kashima

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<com.github.ksoichiro.android.observablescrollview.ObservableNestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lipsum" />

</com.github.ksoichiro.android.observablescrollview.ObservableNestedScrollView>
Loading