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
17package android.widget.focus;
18
19import android.test.SingleLaunchActivityTestCase;
20import android.test.suitebuilder.annotation.MediumTest;
21import android.view.FocusFinder;
22import android.view.View;
23import android.view.ViewGroup;
24import android.widget.focus.LinearLayoutGrid;
25
26/**
27 * Tests focus searching between buttons within a grid that are touching, for example,
28 * two buttons next two each other would have the left button's right equal to the
29 * right button's left.  Same goes for top and bottom edges.
30 *
31 * This exercises some edge cases of {@link android.view.FocusFinder}.
32 */
33public class LinearLayoutGridTest extends SingleLaunchActivityTestCase<LinearLayoutGrid> {
34    private ViewGroup mRootView;
35
36    public LinearLayoutGridTest() {
37        super("com.android.frameworks.coretests", LinearLayoutGrid.class);
38    }
39
40    protected void setUp() throws Exception {
41        super.setUp();
42        mRootView = getActivity().getRootView();
43    }
44
45    @MediumTest
46    public void testGoDownFromMiddle() {
47        assertEquals(getActivity().getButtonAt(2, 1),
48                FocusFinder.getInstance().findNextFocus(
49                        mRootView,
50                        getActivity().getButtonAt(1, 1),
51                        View.FOCUS_DOWN));
52    }
53
54    @MediumTest
55    public void testGoUpFromMiddle() {
56        assertEquals(getActivity().getButtonAt(0, 1),
57                FocusFinder.getInstance().findNextFocus(
58                        mRootView,
59                        getActivity().getButtonAt(1, 1),
60                        View.FOCUS_UP));
61    }
62
63    @MediumTest
64    public void testGoRightFromMiddle() {
65        assertEquals(getActivity().getButtonAt(1, 2),
66                FocusFinder.getInstance().findNextFocus(
67                        mRootView,
68                        getActivity().getButtonAt(1, 1),
69                        View.FOCUS_RIGHT));
70    }
71
72    @MediumTest
73    public void testGoLeftFromMiddle() {
74        assertEquals(getActivity().getButtonAt(1, 0),
75                FocusFinder.getInstance().findNextFocus(
76                        mRootView,
77                        getActivity().getButtonAt(1, 1),
78                        View.FOCUS_LEFT));
79    }
80
81}
82