blob: 98fbed31eabf896205f0f8235b8838a4cc8eeb73 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Neal Nguyen1d3165f2010-01-12 13:26:10 -080017package android.widget.listview;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Neal Nguyen1d3165f2010-01-12 13:26:10 -080019import android.util.InternalSelectionView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020
21import android.app.Activity;
22import android.os.Bundle;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.BaseAdapter;
26import android.widget.LinearLayout;
27import android.widget.ListView;
28
29/**
30 * Most bodacious scenario yet!
31 */
32public class AdjacentListsWithAdjacentISVsInside extends Activity {
33
34 private ListView mLeftListView;
35 private ListView mRightListView;
36
37 public ListView getLeftListView() {
38 return mLeftListView;
39 }
40
41 public ListView getRightListView() {
42 return mRightListView;
43 }
44
45 public InternalSelectionView getLeftIsv() {
46 return (InternalSelectionView)
47 ((ViewGroup) mLeftListView.getChildAt(0)).getChildAt(0);
48 }
49
50 public InternalSelectionView getLeftMiddleIsv() {
51 return (InternalSelectionView)
52 ((ViewGroup) mLeftListView.getChildAt(0)).getChildAt(1);
53 }
54
55 public InternalSelectionView getRightMiddleIsv() {
56 return (InternalSelectionView)
57 ((ViewGroup) mRightListView.getChildAt(0)).getChildAt(0);
58 }
59
60 public InternalSelectionView getRightIsv() {
61 return (InternalSelectionView)
62 ((ViewGroup) mRightListView.getChildAt(0)).getChildAt(1);
63 }
64
65 @Override
66 protected void onCreate(Bundle savedInstanceState) {
67 super.onCreate(savedInstanceState);
68
69 final int desiredHeight = (int) (0.8 * getWindowManager().getDefaultDisplay().getHeight());
70
71 mLeftListView = new ListView(this);
72 mLeftListView.setAdapter(new AdjacentISVAdapter(desiredHeight));
73 mLeftListView.setItemsCanFocus(true);
74
75
76 mRightListView = new ListView(this);
77 mRightListView.setAdapter(new AdjacentISVAdapter(desiredHeight));
78 mRightListView.setItemsCanFocus(true);
79
80
81
82 setContentView(combineAdjacent(mLeftListView, mRightListView));
83 }
84
85 private static View combineAdjacent(View... views) {
86 if (views.length < 2) {
87 throw new IllegalArgumentException("you should pass at least 2 views in");
88 }
89
90 final LinearLayout ll = new LinearLayout(views[0].getContext());
91 ll.setOrientation(LinearLayout.HORIZONTAL);
92 final LinearLayout.LayoutParams lp =
93 new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
94
95 for (View view : views) {
96 ll.addView(view, lp);
97 }
98 return ll;
99 }
100
101 static class AdjacentISVAdapter extends BaseAdapter {
102
103 private final int mItemHeight;
104
105 AdjacentISVAdapter(int itemHeight) {
106 mItemHeight = itemHeight;
107 }
108
109 public int getCount() {
110 return 1;
111 }
112
113 public Object getItem(int position) {
114 return position;
115 }
116
117 public long getItemId(int position) {
118 return position;
119 }
120
121 public View getView(int position, View convertView, ViewGroup parent) {
122 final InternalSelectionView isvLeft = new InternalSelectionView(
123 parent.getContext(), 5, "isv left");
124 isvLeft.setDesiredHeight(mItemHeight);
125 final InternalSelectionView isvRight = new InternalSelectionView(
126 parent.getContext(), 5, "isv right");
127 isvRight.setDesiredHeight(mItemHeight);
128 return combineAdjacent(isvLeft, isvRight);
129 }
130 }
131}