2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.widget.scroll;
19 import com.android.frameworks.coretests.R;
21 import android.app.Activity;
22 import android.os.Bundle;
23 import android.graphics.Rect;
24 import android.view.View;
25 import android.widget.ScrollView;
26 import android.widget.TextView;
29 * A screen with some scenarios that exercise {@link ScrollView}'s implementation
30 * of {@link android.view.ViewGroup#requestChildRectangleOnScreen}:
31 * <li>Scrolling to something off screen (from top and from bottom)
32 * <li>Scrolling to bring something that is larger than the screen on screen
33 * (from top and from bottom).
35 public class RequestRectangleVisible extends Activity {
38 protected void onCreate(Bundle icicle) {
39 super.onCreate(icicle);
41 setContentView(R.layout.scroll_to_rectangle);
43 final Rect rect = new Rect();
44 final View childToMakeVisible = findViewById(R.id.childToMakeVisible);
46 final TextView topBlob = (TextView) findViewById(R.id.topBlob);
47 final TextView bottomBlob = (TextView) findViewById(R.id.bottomBlob);
49 // estimate to get blobs larger than screen
50 int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
51 int numLinesForScreen = screenHeight / 18;
53 for (int i = 0; i < numLinesForScreen; i++) {
54 topBlob.append(i + " another line in the blob\n");
55 bottomBlob.append(i + " another line in the blob\n");
58 findViewById(R.id.scrollToRectFromTop).setOnClickListener(new View.OnClickListener() {
60 public void onClick(View v) {
61 rect.set(0, 0, childToMakeVisible.getLeft(), childToMakeVisible.getHeight());
62 childToMakeVisible.requestRectangleOnScreen(rect, true);
66 findViewById(R.id.scrollToRectFromTop2).setOnClickListener(new View.OnClickListener() {
68 public void onClick(View v) {
69 rect.set(0, 0, topBlob.getWidth(), topBlob.getHeight());
70 topBlob.requestRectangleOnScreen(rect, true);
74 findViewById(R.id.scrollToRectFromBottom).setOnClickListener(new View.OnClickListener() {
76 public void onClick(View v) {
77 rect.set(0, 0, childToMakeVisible.getLeft(), childToMakeVisible.getHeight());
78 childToMakeVisible.requestRectangleOnScreen(rect, true);
82 findViewById(R.id.scrollToRectFromBottom2).setOnClickListener(new View.OnClickListener() {
84 public void onClick(View v) {
85 rect.set(0, 0, bottomBlob.getWidth(), bottomBlob.getHeight());
86 bottomBlob.requestRectangleOnScreen(rect, true);