Home | History | Annotate | Download | only in modifiers
      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.holo.cts.modifiers;
     18 
     19 import com.android.cts.holo.R;
     20 
     21 import android.content.Context;
     22 import android.view.View;
     23 import android.widget.SearchView;
     24 
     25 public class SearchViewModifier extends AbstractLayoutModifier {
     26 
     27     public static final int QUERY_HINT = 0;
     28     public static final int QUERY = 1;
     29 
     30     private int mSearchViewType;
     31 
     32     public SearchViewModifier(int searchViewType) {
     33         mSearchViewType = searchViewType;
     34     }
     35 
     36     @Override
     37     public View modifyView(View view) {
     38         SearchView searchView = (SearchView) view;
     39         Context context = view.getContext();
     40 
     41         switch (mSearchViewType) {
     42             case QUERY_HINT:
     43                 searchView.setQueryHint(context.getString(R.string.searchview_query_hint));
     44                 break;
     45 
     46             case QUERY:
     47                 searchView.setQuery(context.getString(R.string.searchview_query), false);
     48                 break;
     49 
     50             default:
     51                 throw new IllegalArgumentException("Bad search view type: " + mSearchViewType);
     52         }
     53 
     54         searchView.setIconifiedByDefault(false);
     55         return searchView;
     56     }
     57 }
     58