SearchActivityViewTwoPane.java revision e833f84eee7ab575c8d53dec9b133fa5de9c7e6d
1/* 2 * Copyright (C) 2010 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 com.android.quicksearchbox.ui; 18 19import com.android.quicksearchbox.Corpus; 20import com.android.quicksearchbox.Promoter; 21import com.android.quicksearchbox.R; 22import com.android.quicksearchbox.Suggestions; 23 24import android.animation.ObjectAnimator; 25import android.animation.ValueAnimator; 26import android.animation.ValueAnimator.AnimatorUpdateListener; 27import android.content.Context; 28import android.graphics.drawable.Drawable; 29import android.util.AttributeSet; 30import android.view.View; 31import android.widget.ImageView; 32 33/** 34 * Two-pane variant for the search activity view. 35 */ 36public class SearchActivityViewTwoPane extends SearchActivityView { 37 38 private static final int TINT_ANIMATION_DURATION = 400; // in millis 39 40 private ImageView mSettingsButton; 41 42 // View that shows the results other than the query completions 43 private SuggestionsView mResultsView; 44 private SuggestionsAdapter mResultsAdapter; 45 46 public SearchActivityViewTwoPane(Context context) { 47 super(context); 48 } 49 50 public SearchActivityViewTwoPane(Context context, AttributeSet attrs) { 51 super(context, attrs); 52 } 53 54 public SearchActivityViewTwoPane(Context context, AttributeSet attrs, int defStyle) { 55 super(context, attrs, defStyle); 56 } 57 58 @Override 59 protected void onFinishInflate() { 60 super.onFinishInflate(); 61 62 mSettingsButton = (ImageView) findViewById(R.id.settings_icon); 63 64 mResultsView = (SuggestionsView) findViewById(R.id.shortcuts); 65 mResultsAdapter = createSuggestionsAdapter(); 66 mResultsAdapter.setSuggestionAdapterChangeListener(this); 67 mResultsView.setOnKeyListener(new SuggestionsViewKeyListener()); 68 } 69 70 @Override 71 public void onSuggestionAdapterChanged() { 72 mResultsView.setAdapter(mResultsAdapter); 73 super.onSuggestionAdapterChanged(); 74 } 75 76 @Override 77 public void onResume() { 78 setupWallpaperTint(); 79 } 80 81 private void setupWallpaperTint() { 82 // Alpha fade-in the background tint when the activity resumes. 83 final Drawable drawable = getBackground(); 84 ValueAnimator animator = ObjectAnimator.ofInt(drawable, "alpha", 0, 255); 85 // TODO: Remove this listener when the alpha animation update issue is fixed. 86 animator.addUpdateListener(new AnimatorUpdateListener() { 87 88 public void onAnimationUpdate(ValueAnimator animator) { 89 drawable.invalidateSelf(); 90 } 91 }); 92 animator.setDuration(TINT_ANIMATION_DURATION); 93 animator.start(); 94 } 95 96 @Override 97 public void onStop() { 98 } 99 100 @Override 101 public void start() { 102 super.start(); 103 mResultsView.setAdapter(mResultsAdapter); 104 } 105 106 @Override 107 public void destroy() { 108 mResultsView.setAdapter(null); 109 110 super.destroy(); 111 } 112 113 @Override 114 public void considerHidingInputMethod() { 115 // Don't hide keyboard when interacting with suggestions list 116 } 117 118 @Override 119 public void hideSuggestions() { 120 // Never hiding suggestions view in two-pane UI 121 } 122 123 @Override 124 public void showSuggestions() { 125 // Never hiding suggestions view in two-pane UI 126 } 127 128 @Override 129 public void showCorpusSelectionDialog() { 130 // not used 131 } 132 133 @Override 134 protected boolean shouldShowVoiceSearch(boolean queryEmpty) { 135 return true; 136 } 137 138 @Override 139 public void clearSuggestions() { 140 super.clearSuggestions(); 141 mResultsAdapter.setSuggestions(null); 142 } 143 144 @Override 145 public void setMaxPromotedResults(int maxPromoted) { 146 mResultsView.setLimitSuggestionsToViewHeight(false); 147 mResultsAdapter.setMaxPromoted(maxPromoted); 148 } 149 150 @Override 151 public void limitResultsToViewHeight() { 152 mResultsView.setLimitSuggestionsToViewHeight(true); 153 } 154 155 156 @Override 157 public void setSettingsButtonClickListener(OnClickListener listener) { 158 mSettingsButton.setOnClickListener(listener); 159 } 160 161 @Override 162 public void setSuggestionClickListener(SuggestionClickListener listener) { 163 super.setSuggestionClickListener(listener); 164 mResultsAdapter.setSuggestionClickListener(listener); 165 } 166 167 @Override 168 public void setEmptySpaceClickListener(final View.OnClickListener listener) { 169 findViewById(R.id.panes).setOnClickListener(listener); 170 } 171 172 @Override 173 public void setSuggestions(Suggestions suggestions) { 174 super.setSuggestions(suggestions); 175 suggestions.acquire(); 176 mResultsAdapter.setSuggestions(suggestions); 177 } 178 179 @Override 180 protected void setCorpus(Corpus corpus) { 181 super.setCorpus(corpus); 182 mResultsAdapter.setPromoter(createResultsPromoter()); 183 } 184 185 @Override 186 protected Promoter createSuggestionsPromoter() { 187 return getQsbApplication().createWebPromoter(); 188 } 189 190 protected Promoter createResultsPromoter() { 191 Corpus corpus = getCorpus(); 192 if (corpus == null) { 193 return getQsbApplication().createResultsPromoter(); 194 } else { 195 return getQsbApplication().createSingleCorpusResultsPromoter(corpus); 196 } 197 } 198 199 @Override 200 protected void onSuggestionsChanged() { 201 super.onSuggestionsChanged(); 202 } 203 204 @Override 205 public Corpus getSearchCorpus() { 206 return getWebCorpus(); 207 } 208 209} 210