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.car.settings.suggestions; 18 19 import android.content.Context; 20 import android.service.settings.suggestions.Suggestion; 21 22 import androidx.loader.content.AsyncTaskLoader; 23 24 import com.android.car.settings.common.AsyncLoader; 25 import com.android.car.settings.common.Logger; 26 import com.android.settingslib.suggestions.SuggestionController; 27 28 import java.util.List; 29 30 /** 31 * Loads suggestions for car settings. Taken from 32 * {@link com.android.settingslib.suggestions.SuggestionLoader}, only change is to extend from car 33 * settings {@link AsyncLoader} which extends from support library {@link AsyncTaskLoader}. 34 */ 35 public class SettingsSuggestionsLoader extends AsyncLoader<List<Suggestion>> { 36 private static final Logger LOG = new Logger(SettingsSuggestionsLoader.class); 37 38 /** 39 * ID used for loader that loads the settings suggestions. ID value is an arbitrary value. 40 */ 41 public static final int LOADER_ID_SUGGESTIONS = 42; 42 43 private final SuggestionController mSuggestionController; 44 SettingsSuggestionsLoader(Context context, SuggestionController controller)45 public SettingsSuggestionsLoader(Context context, SuggestionController controller) { 46 super(context); 47 mSuggestionController = controller; 48 } 49 50 @Override loadInBackground()51 public List<Suggestion> loadInBackground() { 52 final List<Suggestion> data = mSuggestionController.getSuggestions(); 53 if (data == null) { 54 LOG.d("data is null"); 55 } else { 56 LOG.d("data size " + data.size()); 57 } 58 return data; 59 } 60 }