Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76616b13 authored by Conley Owens's avatar Conley Owens Committed by Android Code Review
Browse files

Merge "Scolling using arrow keys with padding"

parents 425db473 5435a060
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -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;
                    }
+7 −0
Original line number Diff line number Diff line
@@ -417,6 +417,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" />
+17 −2
Original line number Diff line number Diff line
@@ -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));
+38 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+68 −0
Original line number Diff line number Diff line
/*
 * 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());
    }
}