• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.settings.print;
18 
19 import android.annotation.NonNull;
20 import android.content.Context;
21 import android.print.PrintManager;
22 import android.print.PrintServicesLoader;
23 import android.printservice.PrintServiceInfo;
24 
25 import androidx.loader.content.Loader;
26 
27 import com.android.internal.util.Preconditions;
28 
29 import java.util.List;
30 
31 /**
32  * Loader for the list of print services. Can be parametrized to select a subset.
33  */
34 public class SettingsPrintServicesLoader extends Loader<List<PrintServiceInfo>> {
35 
36     private PrintServicesLoader mLoader;
37 
SettingsPrintServicesLoader(@onNull PrintManager printManager, @NonNull Context context, int selectionFlags)38     public SettingsPrintServicesLoader(@NonNull PrintManager printManager, @NonNull Context context,
39             int selectionFlags) {
40         super(Preconditions.checkNotNull(context));
41 
42         mLoader = new PrintServicesLoader(printManager, context, selectionFlags) {
43             @Override
44             public void deliverResult(List<PrintServiceInfo> data) {
45                 super.deliverResult(data);
46 
47                 // deliver the result to outer Loader class
48                 SettingsPrintServicesLoader.this.deliverResult(data);
49             }
50         };
51     }
52 
53     @Override
onForceLoad()54     protected void onForceLoad() {
55         mLoader.forceLoad();
56     }
57 
58     @Override
onStartLoading()59     protected void onStartLoading() {
60         mLoader.startLoading();
61     }
62 
63     @Override
onStopLoading()64     protected void onStopLoading() {
65         mLoader.stopLoading();
66     }
67 
68     @Override
onCancelLoad()69     protected boolean onCancelLoad() {
70         return mLoader.cancelLoad();
71     }
72 
73     @Override
onAbandon()74     protected void onAbandon() {
75         mLoader.abandon();
76     }
77 
78     @Override
onReset()79     protected void onReset() {
80         mLoader.reset();
81     }
82 }
83