1/* 2 * Copyright (C) 2011 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.support.v4.widget; 18 19import android.content.Context; 20import android.view.View; 21import android.widget.SearchView; 22import android.widget.SearchView.OnQueryTextListener; 23 24/** 25 * Implementation of SearchView compatibility that can call Honeycomb APIs. 26 */ 27class SearchViewCompatHoneycomb { 28 29 interface OnQueryTextListenerCompatBridge { 30 public boolean onQueryTextSubmit(String query); 31 public boolean onQueryTextChange(String newText); 32 } 33 34 public static View newSearchView(Context context) { 35 return new SearchView(context); 36 } 37 38 public static Object newOnQueryTextListener(final OnQueryTextListenerCompatBridge listener) { 39 return new OnQueryTextListener() { 40 @Override 41 public boolean onQueryTextSubmit(String query) { 42 return listener.onQueryTextSubmit(query); 43 } 44 45 @Override 46 public boolean onQueryTextChange(String newText) { 47 return listener.onQueryTextChange(newText); 48 } 49 }; 50 } 51 52 public static void setOnQueryTextListener(Object searchView, Object listener) { 53 ((SearchView) searchView).setOnQueryTextListener((OnQueryTextListener) listener); 54 } 55} 56