ClusteredSuggestionsView.java revision 7a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24
1fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/* 2fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Copyright (C) 2010 The Android Open Source Project 3fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 4fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Licensed under the Apache License, Version 2.0 (the "License"); 5fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * you may not use this file except in compliance with the License. 6fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * You may obtain a copy of the License at 7fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 8fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * http://www.apache.org/licenses/LICENSE-2.0 9fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 10fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Unless required by applicable law or agreed to in writing, software 11fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * distributed under the License is distributed on an "AS IS" BASIS, 12fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * See the License for the specific language governing permissions and 14fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * limitations under the License. 15fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood */ 16fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodpackage com.android.quicksearchbox.ui; 17fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 18fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.content.Context; 19fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.util.AttributeSet; 207a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodimport android.view.View; 21fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.widget.ExpandableListAdapter; 22fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.widget.ExpandableListView; 23fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 24fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/** 25fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Suggestions view that displays suggestions clustered by corpus type. 26fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood */ 27fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodpublic class ClusteredSuggestionsView extends ExpandableListView 28fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood implements SuggestionsListView<ExpandableListAdapter> { 29fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 307a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood SuggestionsAdapter<ExpandableListAdapter> mSuggestionsAdapter; 317a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 32fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public ClusteredSuggestionsView(Context context, AttributeSet attrs) { 33fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood super(context, attrs); 34fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 35fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 36fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public void setSuggestionsAdapter(SuggestionsAdapter<ExpandableListAdapter> adapter) { 377a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood mSuggestionsAdapter = adapter; 387a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood super.setAdapter(adapter == null ? null : adapter.getListAdapter()); 39fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 40fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 41fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public void setLimitSuggestionsToViewHeight(boolean limit) { 42fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // not supported 43fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 44fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 457a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood @Override 467a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public void onFinishInflate() { 477a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood super.onFinishInflate(); 487a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood setItemsCanFocus(true); 497a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood setOnGroupClickListener(new OnGroupClickListener(){ 507a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public boolean onGroupClick( 517a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood ExpandableListView parent, View v, int groupPosition, long id) { 527a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // disable collapsing / expanding 537a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood return true; 547a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood }}); 557a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 567a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 577a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public void expandAll() { 587a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood ExpandableListAdapter adapter = mSuggestionsAdapter.getListAdapter(); 597a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood for (int i = 0; i < adapter.getGroupCount(); ++i) { 607a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood expandGroup(i); 617a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 627a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 637a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 64fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood} 65