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