14572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood/* 24572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * Copyright (C) 2010 The Android Open Source Project 34572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * 44572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * Licensed under the Apache License, Version 2.0 (the "License"); 54572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * you may not use this file except in compliance with the License. 64572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * You may obtain a copy of the License at 74572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * 84572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * http://www.apache.org/licenses/LICENSE-2.0 94572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * 104572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * Unless required by applicable law or agreed to in writing, software 114572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * distributed under the License is distributed on an "AS IS" BASIS, 124572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * See the License for the specific language governing permissions and 144572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood * limitations under the License. 154572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood */ 164572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwoodpackage com.android.quicksearchbox; 174572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood 18b83882b9efa37ec0f20a0f1c85cf5ccc93194aeeBjorn Bringert/** 19af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood * Abstract {@link Promoter} that uses a {@link SuggestionFilter} to choose shortcuts. 20b83882b9efa37ec0f20a0f1c85cf5ccc93194aeeBjorn Bringert */ 21af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwoodpublic abstract class AbstractPromoter implements Promoter { 22af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood 23af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood private final SuggestionFilter mFilter; 2427691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood private final Promoter mNext; 25af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood private final Config mConfig; 264572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood 2727691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood protected AbstractPromoter(SuggestionFilter filter, Promoter next, Config config) { 28af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood mFilter = filter; 2927691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood mNext = next; 30af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood mConfig = config; 314572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood } 324572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood 3327691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood public void pickPromoted( 3427691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood Suggestions suggestions, int maxPromoted, ListSuggestionCursor promoted) { 3527691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood doPickPromoted(suggestions, maxPromoted, promoted); 3627691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood if (mNext != null) { 3727691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood mNext.pickPromoted(suggestions, maxPromoted, promoted); 3827691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood } 3927691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood } 4027691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood 4127691bfcdcf3d2918b45bfadd57b08547c317ce5Mathew Inwood protected abstract void doPickPromoted( 42af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood Suggestions suggestions, int maxPromoted, ListSuggestionCursor promoted); 43af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood 44af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood protected Config getConfig() { 45af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood return mConfig; 46af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood } 47af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood 484572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood protected boolean accept(Suggestion s) { 49af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood if (mFilter != null) { 50af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood return mFilter.accept(s); 51af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood } else { 52af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood return true; 53af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood } 544572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood } 554572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood 564572856ac85bb53ea06e65d00beebdf336af9b27Mathew Inwood} 57