Home | History | Annotate | Download | only in quicksearchbox
      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 package com.android.quicksearchbox;
     17 
     18 import com.android.quicksearchbox.util.NamedTaskExecutor;
     19 
     20 import android.content.Context;
     21 import android.graphics.drawable.Drawable;
     22 import android.net.Uri;
     23 import android.os.Handler;
     24 
     25 /**
     26  * Abstract implementation of a source that is not backed by a searchable activity.
     27  */
     28 public abstract class AbstractInternalSource extends AbstractSource {
     29 
     30     public AbstractInternalSource(Context context, Handler uiThread, NamedTaskExecutor iconLoader) {
     31         super(context, uiThread, iconLoader);
     32     }
     33 
     34     public String getSuggestUri() {
     35         return null;
     36     }
     37 
     38     public boolean canRead() {
     39         return true;
     40     }
     41 
     42     public String getDefaultIntentData() {
     43         return null;
     44     }
     45 
     46     @Override
     47     protected String getIconPackage() {
     48         return getContext().getPackageName();
     49     }
     50 
     51     public int getQueryThreshold() {
     52         return 0;
     53     }
     54 
     55     public Drawable getSourceIcon() {
     56         return getContext().getResources().getDrawable(getSourceIconResource());
     57     }
     58 
     59     public Uri getSourceIconUri() {
     60         return Uri.parse("android.resource://" + getContext().getPackageName()
     61                 + "/" +  getSourceIconResource());
     62     }
     63 
     64     protected abstract int getSourceIconResource();
     65 
     66     public int getVersionCode() {
     67         return QsbApplication.get(getContext()).getVersionCode();
     68     }
     69 
     70     /**
     71      * Shortcuts from previous version are compatible with shortcuts from this version, so we just
     72      * return true. If shortcuts become incompatible during an upgrade, some examination of the
     73      * version code should be added here.
     74      */
     75     @Override
     76     public boolean isVersionCodeCompatible(int version) {
     77         return true;
     78     }
     79 
     80     public boolean queryAfterZeroResults() {
     81         return true;
     82     }
     83 
     84 }
     85