1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package android.widget.scroll; 18 19 import com.android.frameworks.coretests.R; 20 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; 27 28 /** 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). 34 */ 35 public class RequestRectangleVisible extends Activity { 36 37 @Override onCreate(Bundle icicle)38 protected void onCreate(Bundle icicle) { 39 super.onCreate(icicle); 40 41 setContentView(R.layout.scroll_to_rectangle); 42 43 final Rect rect = new Rect(); 44 final View childToMakeVisible = findViewById(R.id.childToMakeVisible); 45 46 final TextView topBlob = findViewById(R.id.topBlob); 47 final TextView bottomBlob = findViewById(R.id.bottomBlob); 48 49 // estimate to get blobs larger than screen 50 int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); 51 int numLinesForScreen = screenHeight / 18; 52 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"); 56 } 57 58 findViewById(R.id.scrollToRectFromTop).setOnClickListener(new View.OnClickListener() { 59 60 public void onClick(View v) { 61 rect.set(0, 0, childToMakeVisible.getLeft(), childToMakeVisible.getHeight()); 62 childToMakeVisible.requestRectangleOnScreen(rect, true); 63 } 64 }); 65 66 findViewById(R.id.scrollToRectFromTop2).setOnClickListener(new View.OnClickListener() { 67 68 public void onClick(View v) { 69 rect.set(0, 0, topBlob.getWidth(), topBlob.getHeight()); 70 topBlob.requestRectangleOnScreen(rect, true); 71 } 72 }); 73 74 findViewById(R.id.scrollToRectFromBottom).setOnClickListener(new View.OnClickListener() { 75 76 public void onClick(View v) { 77 rect.set(0, 0, childToMakeVisible.getLeft(), childToMakeVisible.getHeight()); 78 childToMakeVisible.requestRectangleOnScreen(rect, true); 79 } 80 }); 81 82 findViewById(R.id.scrollToRectFromBottom2).setOnClickListener(new View.OnClickListener() { 83 84 public void onClick(View v) { 85 rect.set(0, 0, bottomBlob.getWidth(), bottomBlob.getHeight()); 86 bottomBlob.requestRectangleOnScreen(rect, true); 87 } 88 }); 89 90 } 91 92 93 94 } 95