summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/widget/ScrollView.java6
-rw-r--r--core/tests/coretests/AndroidManifest.xml7
-rw-r--r--core/tests/coretests/src/android/util/ScrollViewScenario.java19
-rw-r--r--core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java38
-rw-r--r--core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java68
5 files changed, 132 insertions, 6 deletions
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index de38d05..b1e1fbc 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -832,7 +832,7 @@ public class ScrollView extends FrameLayout {
int count = getChildCount();
if (count > 0) {
View view = getChildAt(count - 1);
- mTempRect.bottom = view.getBottom();
+ mTempRect.bottom = view.getBottom() + mPaddingBottom;
mTempRect.top = mTempRect.bottom - height;
}
}
@@ -912,9 +912,7 @@ public class ScrollView extends FrameLayout {
} else if (direction == View.FOCUS_DOWN) {
if (getChildCount() > 0) {
int daBottom = getChildAt(0).getBottom();
-
- int screenBottom = getScrollY() + getHeight();
-
+ int screenBottom = getScrollY() + getHeight() - mPaddingBottom;
if (daBottom - screenBottom < maxJump) {
scrollDelta = daBottom - screenBottom;
}
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index 487a00d..fc4ea73 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -411,6 +411,13 @@
</intent-filter>
</activity>
+ <activity android:name="android.widget.scroll.arrowscroll.MultiPageTextWithPadding" android:label="arrowscrollMultiPageTextWithPadding">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
+
<activity android:name="android.view.Include" android:label="IncludeTag">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/core/tests/coretests/src/android/util/ScrollViewScenario.java b/core/tests/coretests/src/android/util/ScrollViewScenario.java
index 83afe06..db3d9d0 100644
--- a/core/tests/coretests/src/android/util/ScrollViewScenario.java
+++ b/core/tests/coretests/src/android/util/ScrollViewScenario.java
@@ -61,6 +61,7 @@ public abstract class ScrollViewScenario extends Activity {
/**
* Partially implement ViewFactory given a height ratio.
+ * A negative height ratio means that WRAP_CONTENT will be used as height
*/
private static abstract class ViewFactoryBase implements ViewFactory {
@@ -87,6 +88,9 @@ public abstract class ScrollViewScenario extends Activity {
List<ViewFactory> mViewFactories = Lists.newArrayList();
+ int mTopPadding = 0;
+ int mBottomPadding = 0;
+
/**
* Add a text view.
* @param text The text of the text view.
@@ -186,6 +190,13 @@ public abstract class ScrollViewScenario extends Activity {
});
return this;
}
+
+ public Params addPaddingToScrollView(int topPadding, int bottomPadding) {
+ mTopPadding = topPadding;
+ mBottomPadding = bottomPadding;
+
+ return this;
+ }
}
/**
@@ -239,13 +250,17 @@ public abstract class ScrollViewScenario extends Activity {
// create views specified by params
for (ViewFactory viewFactory : params.mViewFactories) {
+ int height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ if (viewFactory.getHeightRatio() >= 0) {
+ height = (int) (viewFactory.getHeightRatio() * screenHeight);
+ }
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- (int) (viewFactory.getHeightRatio() * screenHeight));
+ ViewGroup.LayoutParams.MATCH_PARENT, height);
mLinearLayout.addView(viewFactory.create(this), lp);
}
mScrollView = createScrollView();
+ mScrollView.setPadding(0, params.mTopPadding, 0, params.mBottomPadding);
mScrollView.addView(mLinearLayout, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
diff --git a/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java
new file mode 100644
index 0000000..7d5a8d8
--- /dev/null
+++ b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package android.widget.scroll.arrowscroll;
+
+import android.util.ScrollViewScenario;
+
+/**
+ * One TextView with a text covering several pages. Padding is added
+ * above and below the ScrollView.
+ */
+public class MultiPageTextWithPadding extends ScrollViewScenario {
+
+ @Override
+ protected void init(Params params) {
+
+ String text = "This is a long text.";
+ String longText = "First text.";
+ for (int i = 0; i < 300; i++) {
+ longText = longText + " " + text;
+ }
+ longText = longText + " Last text.";
+ params.addTextView(longText, -1.0f).addPaddingToScrollView(50, 50);
+ }
+}
diff --git a/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java
new file mode 100644
index 0000000..ddde48f
--- /dev/null
+++ b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 Sony Ericsson Mobile Communications AB.
+ *
+ * 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.
+ */
+
+package android.widget.scroll.arrowscroll;
+
+import android.widget.scroll.arrowscroll.MultiPageTextWithPadding;
+import android.test.ActivityInstrumentationTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.view.KeyEvent;
+import android.widget.TextView;
+import android.widget.ScrollView;
+
+public class MultiPageTextWithPaddingTest extends
+ ActivityInstrumentationTestCase<MultiPageTextWithPadding> {
+
+ private ScrollView mScrollView;
+
+ private TextView mTextView;
+
+ public MultiPageTextWithPaddingTest() {
+ super("com.android.frameworks.coretests", MultiPageTextWithPadding.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mScrollView = getActivity().getScrollView();
+ mTextView = getActivity().getContentChildAt(0);
+ }
+
+ @MediumTest
+ public void testPreconditions() {
+ assertTrue("text should not fit on screen",
+ mTextView.getHeight() > mScrollView.getHeight());
+ }
+
+ @LargeTest
+ public void testScrollDownToBottom() throws Exception {
+ // Calculate the number of arrow scrolls needed to reach the bottom
+ int scrollsNeeded = (int)Math.ceil(Math.max(0.0f,
+ (mTextView.getHeight() - mScrollView.getHeight()))
+ / mScrollView.getMaxScrollAmount());
+ for (int i = 0; i < scrollsNeeded; i++) {
+ sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+ }
+
+ assertEquals(
+ "should be fully scrolled to bottom",
+ getActivity().getLinearLayout().getHeight()
+ - (mScrollView.getHeight() - mScrollView.getPaddingTop() - mScrollView
+ .getPaddingBottom()), mScrollView.getScrollY());
+ }
+}