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 17 package android.support.v4.widget; 18 19 import android.app.SearchManager; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.view.View; 23 import android.widget.SearchView; 24 import android.widget.SearchView.OnCloseListener; 25 import android.widget.SearchView.OnQueryTextListener; 26 27 /** 28 * Implementation of SearchView compatibility that can call Honeycomb APIs. 29 */ 30 class SearchViewCompatHoneycomb { 31 32 interface OnQueryTextListenerCompatBridge { onQueryTextSubmit(String query)33 public boolean onQueryTextSubmit(String query); onQueryTextChange(String newText)34 public boolean onQueryTextChange(String newText); 35 } 36 37 interface OnCloseListenerCompatBridge { onClose()38 public boolean onClose(); 39 } 40 newSearchView(Context context)41 public static View newSearchView(Context context) { 42 return new SearchView(context); 43 } 44 setSearchableInfo(View searchView, ComponentName searchableComponent)45 public static void setSearchableInfo(View searchView, ComponentName searchableComponent) { 46 SearchView sv = ((SearchView) searchView); 47 SearchManager searchManager = (SearchManager) 48 sv.getContext().getSystemService(Context.SEARCH_SERVICE); 49 sv.setSearchableInfo(searchManager.getSearchableInfo(searchableComponent)); 50 } 51 newOnQueryTextListener(final OnQueryTextListenerCompatBridge listener)52 public static Object newOnQueryTextListener(final OnQueryTextListenerCompatBridge listener) { 53 return new OnQueryTextListener() { 54 @Override 55 public boolean onQueryTextSubmit(String query) { 56 return listener.onQueryTextSubmit(query); 57 } 58 59 @Override 60 public boolean onQueryTextChange(String newText) { 61 return listener.onQueryTextChange(newText); 62 } 63 }; 64 } 65 66 public static void setOnQueryTextListener(Object searchView, Object listener) { 67 ((SearchView) searchView).setOnQueryTextListener((OnQueryTextListener) listener); 68 } 69 70 public static Object newOnCloseListener(final OnCloseListenerCompatBridge listener) { 71 return new OnCloseListener() { 72 @Override 73 public boolean onClose() { 74 return listener.onClose(); 75 } 76 }; 77 } 78 79 public static void setOnCloseListener(Object searchView, Object listener) { 80 ((SearchView) searchView).setOnCloseListener((OnCloseListener) listener); 81 } 82 83 public static CharSequence getQuery(View searchView) { 84 return ((SearchView) searchView).getQuery(); 85 } 86 87 public static void setQuery(View searchView, CharSequence query, boolean submit) { 88 ((SearchView) searchView).setQuery(query, submit); 89 } 90 91 public static void setQueryHint(View searchView, CharSequence hint) { 92 ((SearchView) searchView).setQueryHint(hint); 93 } 94 95 public static void setIconified(View searchView, boolean iconify) { 96 ((SearchView) searchView).setIconified(iconify); 97 } 98 99 public static boolean isIconified(View searchView) { 100 return ((SearchView) searchView).isIconified(); 101 } 102 103 public static void setSubmitButtonEnabled(View searchView, boolean enabled) { 104 ((SearchView) searchView).setSubmitButtonEnabled(enabled); 105 } 106 107 public static boolean isSubmitButtonEnabled(View searchView) { 108 return ((SearchView) searchView).isSubmitButtonEnabled(); 109 } 110 111 public static void setQueryRefinementEnabled(View searchView, boolean enable) { 112 ((SearchView) searchView).setQueryRefinementEnabled(enable); 113 } 114 115 public static boolean isQueryRefinementEnabled(View searchView) { 116 return ((SearchView) searchView).isQueryRefinementEnabled(); 117 } 118 119 public static void setMaxWidth(View searchView, int maxpixels) { 120 ((SearchView) searchView).setMaxWidth(maxpixels); 121 } 122 } 123