ListSuggestionCursor.java revision 782dd228e78e9294692d639597f96c26283968bb
1/* 2 * Copyright (C) 2009 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; 18 19import android.content.ComponentName; 20import android.content.Context; 21import android.content.Intent; 22import android.graphics.Rect; 23import android.graphics.drawable.Drawable; 24import android.net.Uri; 25import android.os.Bundle; 26 27import java.util.ArrayList; 28 29/** 30 * A SuggestionCursor that is backed by a list of SuggestionPosition objects. 31 * This cursor does not own the SuggestionCursors that the SuggestionPosition 32 * objects refer to. 33 * 34 */ 35public class ListSuggestionCursor extends AbstractSuggestionCursor { 36 37 private final ArrayList<SuggestionPosition> mSuggestions; 38 39 private int mPos; 40 41 public ListSuggestionCursor(String userQuery) { 42 super(userQuery); 43 mSuggestions = new ArrayList<SuggestionPosition>(); 44 mPos = 0; 45 } 46 47 /** 48 * Adds a suggestion from another suggestion cursor. 49 * 50 * @param suggestionPos 51 * @return {@code true} if the suggestion was added. 52 */ 53 public boolean add(SuggestionPosition suggestionPos) { 54 mSuggestions.add(suggestionPos); 55 return true; 56 } 57 58 public void close() { 59 mSuggestions.clear(); 60 } 61 62 public boolean isFailed() { 63 return false; 64 } 65 66 public int getPosition() { 67 return mPos; 68 } 69 70 public void moveTo(int pos) { 71 mPos = pos; 72 } 73 74 public int getCount() { 75 return mSuggestions.size(); 76 } 77 78 private SuggestionCursor current() { 79 return mSuggestions.get(mPos).getSuggestion(); 80 } 81 82 public Drawable getIcon(String iconId) { 83 return current().getIcon(iconId); 84 } 85 86 public Uri getIconUri(String iconId) { 87 return current().getIconUri(iconId); 88 } 89 90 public Intent getSecondarySuggestionIntent(Context context, Bundle appSearchData, Rect target) { 91 return current().getSecondarySuggestionIntent(context, appSearchData, target); 92 } 93 94 public String getShortcutId() { 95 return current().getShortcutId(); 96 } 97 98 public ComponentName getSourceComponentName() { 99 return current().getSourceComponentName(); 100 } 101 102 public Drawable getSourceIcon() { 103 return current().getSourceIcon(); 104 } 105 106 public Uri getSourceIconUri() { 107 return current().getSourceIconUri(); 108 } 109 110 public CharSequence getSourceLabel() { 111 return current().getSourceLabel(); 112 } 113 114 public String getSuggestionDisplayQuery() { 115 return current().getSuggestionDisplayQuery(); 116 } 117 118 public String getSuggestionFormat() { 119 return current().getSuggestionFormat(); 120 } 121 122 public String getSuggestionIcon1() { 123 return current().getSuggestionIcon1(); 124 } 125 126 public String getSuggestionIcon2() { 127 return current().getSuggestionIcon2(); 128 } 129 130 public Intent getSuggestionIntent(Context context, Bundle appSearchData, int actionKey, 131 String actionMsg) { 132 return current().getSuggestionIntent(context, appSearchData, actionKey, actionMsg); 133 } 134 135 public String getSuggestionText1() { 136 return current().getSuggestionText1(); 137 } 138 139 public String getSuggestionText2() { 140 return current().getSuggestionText2(); 141 } 142 143 public boolean hasSecondaryIntent() { 144 return current().hasSecondaryIntent(); 145 } 146 147 public String getSuggestionKey() { 148 return current().getSuggestionKey(); 149 } 150 151 public String getActionKeyMsg(int keyCode) { 152 return current().getActionKeyMsg(keyCode); 153 } 154 155} 156