• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.intentresolver.icons;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.os.AsyncTask;
22 
23 import com.android.intentresolver.R;
24 import com.android.intentresolver.TargetPresentationGetter;
25 
26 import java.util.function.Consumer;
27 
28 abstract class BaseLoadIconTask extends AsyncTask<Void, Void, Drawable> {
29     protected final Context mContext;
30     protected final TargetPresentationGetter.Factory mPresentationFactory;
31     private final Consumer<Drawable> mCallback;
32 
BaseLoadIconTask( Context context, TargetPresentationGetter.Factory presentationFactory, Consumer<Drawable> callback)33     BaseLoadIconTask(
34             Context context,
35             TargetPresentationGetter.Factory presentationFactory,
36             Consumer<Drawable> callback) {
37         mContext = context;
38         mPresentationFactory = presentationFactory;
39         mCallback = callback;
40     }
41 
loadIconPlaceholder()42     protected final Drawable loadIconPlaceholder() {
43         return mContext.getDrawable(R.drawable.resolver_icon_placeholder);
44     }
45 
46     @Override
onPostExecute(Drawable d)47     protected final void onPostExecute(Drawable d) {
48         mCallback.accept(d);
49     }
50 }
51