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 com.android.quicksearchbox.util.Now;
20import com.android.quicksearchbox.util.NowOrLater;
21
22import android.content.ContentResolver;
23import android.content.Context;
24import android.graphics.drawable.Drawable;
25import android.net.Uri;
26import android.text.TextUtils;
27
28/**
29 * Mock implementation of {@link IconLoader}.
30 *
31 */
32public class MockIconLoader implements IconLoader {
33
34    private final Context mContext;
35
36    public MockIconLoader(Context context) {
37        mContext = context;
38    }
39
40    public NowOrLater<Drawable> getIcon(String drawableId) {
41        if (TextUtils.isEmpty(drawableId) || "0".equals(drawableId)) {
42            return new Now<Drawable>(null);
43        } else {
44            return new Now<Drawable>(
45                    mContext.getResources().getDrawable(android.R.drawable.star_on));
46        }
47    }
48
49    public Uri getIconUri(String drawableId) {
50        if (TextUtils.isEmpty(drawableId) || "0".equals(drawableId)) {
51            return null;
52        }
53        return new Uri.Builder()
54                .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
55                .authority(mContext.getPackageName())
56                .appendEncodedPath(String.valueOf(android.R.drawable.star_on))
57                .build();
58    }
59
60}