Home | History | Annotate | Download | only in quicksearchbox
      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 
     17 package com.android.quicksearchbox;
     18 
     19 import android.util.Log;
     20 
     21 import java.util.ArrayList;
     22 
     23 /**
     24  * A promoter that first promotes any shortcuts, and then delegates to another
     25  * promoter.
     26  */
     27 public class ShortcutPromoter extends PromoterWrapper {
     28 
     29     private static final String TAG = "QSB.ShortcutPromoter";
     30     private static final boolean DBG = false;
     31 
     32     /**
     33      * Creates a new ShortcutPromoter.
     34      *
     35      * @param nextPromoter The promoter to use when there are no more shortcuts.
     36      *        May be {@code null}.
     37      */
     38     public ShortcutPromoter(Promoter nextPromoter) {
     39         super(nextPromoter);
     40     }
     41 
     42     @Override
     43     public void pickPromoted(SuggestionCursor shortcuts,
     44             ArrayList<CorpusResult> suggestions, int maxPromoted,
     45             ListSuggestionCursor promoted) {
     46         int shortcutCount = shortcuts == null ? 0 : shortcuts.getCount();
     47         int promotedShortcutCount = Math.min(shortcutCount, maxPromoted);
     48         if (DBG) {
     49             Log.d(TAG, "pickPromoted(shortcutCount = " + shortcutCount +
     50                     ", maxPromoted = " + maxPromoted + ")");
     51         }
     52 
     53         for (int i = 0; i < promotedShortcutCount; i++) {
     54             promoted.add(new SuggestionPosition(shortcuts, i));
     55         }
     56 
     57         super.pickPromoted(null, suggestions, maxPromoted, promoted);
     58     }
     59 
     60 }
     61