Merge "Scolling using arrow keys with padding"
This commit is contained in:
@@ -832,7 +832,7 @@ public class ScrollView extends FrameLayout {
|
|||||||
int count = getChildCount();
|
int count = getChildCount();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
View view = getChildAt(count - 1);
|
View view = getChildAt(count - 1);
|
||||||
mTempRect.bottom = view.getBottom();
|
mTempRect.bottom = view.getBottom() + mPaddingBottom;
|
||||||
mTempRect.top = mTempRect.bottom - height;
|
mTempRect.top = mTempRect.bottom - height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -912,9 +912,7 @@ public class ScrollView extends FrameLayout {
|
|||||||
} else if (direction == View.FOCUS_DOWN) {
|
} else if (direction == View.FOCUS_DOWN) {
|
||||||
if (getChildCount() > 0) {
|
if (getChildCount() > 0) {
|
||||||
int daBottom = getChildAt(0).getBottom();
|
int daBottom = getChildAt(0).getBottom();
|
||||||
|
int screenBottom = getScrollY() + getHeight() - mPaddingBottom;
|
||||||
int screenBottom = getScrollY() + getHeight();
|
|
||||||
|
|
||||||
if (daBottom - screenBottom < maxJump) {
|
if (daBottom - screenBottom < maxJump) {
|
||||||
scrollDelta = daBottom - screenBottom;
|
scrollDelta = daBottom - screenBottom;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -417,6 +417,13 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</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">
|
<activity android:name="android.view.Include" android:label="IncludeTag">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public abstract class ScrollViewScenario extends Activity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Partially implement ViewFactory given a height ratio.
|
* 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 {
|
private static abstract class ViewFactoryBase implements ViewFactory {
|
||||||
|
|
||||||
@@ -87,6 +88,9 @@ public abstract class ScrollViewScenario extends Activity {
|
|||||||
|
|
||||||
List<ViewFactory> mViewFactories = Lists.newArrayList();
|
List<ViewFactory> mViewFactories = Lists.newArrayList();
|
||||||
|
|
||||||
|
int mTopPadding = 0;
|
||||||
|
int mBottomPadding = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a text view.
|
* Add a text view.
|
||||||
* @param text The text of the text view.
|
* @param text The text of the text view.
|
||||||
@@ -186,6 +190,13 @@ public abstract class ScrollViewScenario extends Activity {
|
|||||||
});
|
});
|
||||||
return this;
|
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
|
// create views specified by params
|
||||||
for (ViewFactory viewFactory : params.mViewFactories) {
|
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(
|
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT, height);
|
||||||
(int) (viewFactory.getHeightRatio() * screenHeight));
|
|
||||||
mLinearLayout.addView(viewFactory.create(this), lp);
|
mLinearLayout.addView(viewFactory.create(this), lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
mScrollView = createScrollView();
|
mScrollView = createScrollView();
|
||||||
|
mScrollView.setPadding(0, params.mTopPadding, 0, params.mBottomPadding);
|
||||||
mScrollView.addView(mLinearLayout, new ViewGroup.LayoutParams(
|
mScrollView.addView(mLinearLayout, new ViewGroup.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user