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.listview;
18
19import com.android.frameworks.coretests.R;
20
21import android.app.ListActivity;
22import android.content.Context;
23import android.os.Bundle;
24import android.view.View;
25import android.view.ViewGroup;
26import android.view.LayoutInflater;
27import android.widget.BaseAdapter;
28import android.widget.TextView;
29
30/**
31 * Exercises moving focus into the list from the side
32 */
33public class ListTakeFocusFromSide extends ListActivity {
34
35
36    private class ThrashListAdapter extends BaseAdapter {
37        private LayoutInflater mInflater;
38
39        private String[] mTitles = new String[100];
40
41        public ThrashListAdapter(Context context) {
42            mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
43            mTitles = new String[100];
44
45            int i;
46            for (i = 0; i < 100; i++) {
47                mTitles[i] = "[" + i + "]";
48            }
49        }
50
51        public int getCount() {
52            return mTitles.length;
53        }
54
55        public Object getItem(int position) {
56            return position;
57        }
58
59        public long getItemId(int position) {
60            return position;
61        }
62
63        public View getView(int position, View convertView, ViewGroup parent) {
64            TextView view;
65
66            if (convertView == null) {
67                view = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1, null);
68            } else {
69                view = (TextView) convertView;
70            }
71            view.setText(mTitles[position]);
72            return view;
73        }
74
75    }
76
77    @Override
78    public void onCreate(Bundle icicle) {
79        super.onCreate(icicle);
80
81        setContentView(R.layout.list_take_focus_from_side);
82        setListAdapter(new ThrashListAdapter(this));
83    }
84}
85