Merge commit 'b737647d' (Scrolling using arrow keys with padding) into m

Conflicts:
	core/java/android/widget/ScrollView.java

Change-Id: I1cfd3f7091e92793ce9fa048a09ae08a04c10c80
This commit is contained in:
Conley Owens
2011-04-29 17:35:29 -07:00
5 changed files with 132 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -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" />

View File

@@ -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));

View File

@@ -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);
}
}

View File

@@ -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());
}
}