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 4145f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood public SuggestionsAdapter<ExpandableListAdapter> getSuggestionsAdapter() { 4245f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood return mSuggestionsAdapter; 4345f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood } 4445f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood 45fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public void setLimitSuggestionsToViewHeight(boolean limit) { 46fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // not supported 47fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 48fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 497a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood @Override 507a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public void onFinishInflate() { 517a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood super.onFinishInflate(); 5245f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood setItemsCanFocus(false); 537a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood setOnGroupClickListener(new OnGroupClickListener(){ 547a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public boolean onGroupClick( 557a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood ExpandableListView parent, View v, int groupPosition, long id) { 567a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // disable collapsing / expanding 577a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood return true; 587a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood }}); 597a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 607a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 617a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public void expandAll() { 62bb57ae79a795983f048d1f43aa6dfc538906bc6aMathew Inwood if (mSuggestionsAdapter != null) { 63bb57ae79a795983f048d1f43aa6dfc538906bc6aMathew Inwood ExpandableListAdapter adapter = mSuggestionsAdapter.getListAdapter(); 64bb57ae79a795983f048d1f43aa6dfc538906bc6aMathew Inwood for (int i = 0; i < adapter.getGroupCount(); ++i) { 65bb57ae79a795983f048d1f43aa6dfc538906bc6aMathew Inwood expandGroup(i); 66bb57ae79a795983f048d1f43aa6dfc538906bc6aMathew Inwood } 677a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 687a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 697a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 70fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood} 71