diff options
author | Conley Owens <cco3@android.com> | 2011-04-29 17:35:29 -0700 |
---|---|---|
committer | Conley Owens <cco3@android.com> | 2011-04-29 17:35:29 -0700 |
commit | dddaa56f793ad9ecb4e20df746f562ac7f24d158 (patch) | |
tree | 9928f59f2979598ace84cf1b250b447d45c58c9d /core | |
parent | f395e3042accd7f3f5df466dbb532befcd1db5d4 (diff) | |
parent | b737647db80dad073408064710d61b28890c6e98 (diff) | |
download | frameworks_base-dddaa56f793ad9ecb4e20df746f562ac7f24d158.zip frameworks_base-dddaa56f793ad9ecb4e20df746f562ac7f24d158.tar.gz frameworks_base-dddaa56f793ad9ecb4e20df746f562ac7f24d158.tar.bz2 |
Merge commit 'b737647d' (Scrolling using arrow keys with padding) into m
Conflicts:
core/java/android/widget/ScrollView.java
Change-Id: I1cfd3f7091e92793ce9fa048a09ae08a04c10c80
Diffstat (limited to 'core')
5 files changed, 132 insertions, 6 deletions
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 4b4f5f2..ade3a0a 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -873,7 +873,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; } } @@ -949,9 +949,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 010e3c3..fadf1ec 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -421,6 +421,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()); + } +} |