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 package com.android.launcher3.model; 17 18 import android.content.Context; 19 import android.util.Log; 20 21 import androidx.annotation.WorkerThread; 22 23 import com.android.launcher3.LauncherAppState; 24 import com.android.launcher3.LauncherModel; 25 import com.android.launcher3.LauncherModel.ModelUpdateTask; 26 import com.android.launcher3.model.BgDataModel.Callbacks; 27 28 import java.util.concurrent.Executor; 29 30 /** 31 * Utility class to preload LauncherModel 32 */ 33 public class ModelPreload implements ModelUpdateTask { 34 35 private static final String TAG = "ModelPreload"; 36 37 private LauncherAppState mApp; 38 private LauncherModel mModel; 39 private BgDataModel mBgDataModel; 40 private AllAppsList mAllAppsList; 41 42 @Override init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, AllAppsList allAppsList, Executor uiExecutor)43 public final void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, 44 AllAppsList allAppsList, Executor uiExecutor) { 45 mApp = app; 46 mModel = model; 47 mBgDataModel = dataModel; 48 mAllAppsList = allAppsList; 49 } 50 51 @Override run()52 public final void run() { 53 mModel.startLoaderForResultsIfNotLoaded( 54 new LoaderResults(mApp, mBgDataModel, mAllAppsList, new Callbacks[0])); 55 Log.d(TAG, "Preload completed : " + mModel.isModelLoaded()); 56 onComplete(mModel.isModelLoaded()); 57 } 58 59 /** 60 * Called when the task is complete 61 */ 62 @WorkerThread onComplete(boolean isSuccess)63 public void onComplete(boolean isSuccess) { } 64 start(Context context)65 public void start(Context context) { 66 LauncherAppState.getInstance(context).getModel().enqueueModelUpdateTask(this); 67 } 68 }