blob: ca25746eb54862910b31e65ee6749f0386ec104c [file] [log] [blame]
Brian Muramatsub6a4d982012-04-24 17:16:04 -07001/*
2 * Copyright (C) 2012 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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Brian Muramatsub6a4d982012-04-24 17:16:04 -070018
19import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.Intent;
Michael Jurka43467462013-11-14 12:03:58 +010022import android.os.AsyncTask;
Brian Muramatsu5524b492012-10-02 16:55:54 -070023import android.text.TextUtils;
24import android.util.Log;
Brian Muramatsub6a4d982012-04-24 17:16:04 -070025
26public class PreloadReceiver extends BroadcastReceiver {
Brian Muramatsu5524b492012-10-02 16:55:54 -070027 private static final String TAG = "Launcher.PreloadReceiver";
28 private static final boolean LOGD = false;
29
30 public static final String EXTRA_WORKSPACE_NAME =
Daniel Sandler325dc232013-06-05 22:57:57 -040031 "com.android.launcher3.action.EXTRA_WORKSPACE_NAME";
Brian Muramatsu5524b492012-10-02 16:55:54 -070032
Brian Muramatsub6a4d982012-04-24 17:16:04 -070033 @Override
34 public void onReceive(Context context, Intent intent) {
Michael Jurka104c4562013-07-08 18:03:46 -070035 final LauncherProvider provider = LauncherAppState.getLauncherProvider();
Brian Muramatsub6a4d982012-04-24 17:16:04 -070036 if (provider != null) {
Brian Muramatsu5524b492012-10-02 16:55:54 -070037 String name = intent.getStringExtra(EXTRA_WORKSPACE_NAME);
38 final int workspaceResId = !TextUtils.isEmpty(name)
Daniel Sandler325dc232013-06-05 22:57:57 -040039 ? context.getResources().getIdentifier(name, "xml", "com.android.launcher3") : 0;
Brian Muramatsu5524b492012-10-02 16:55:54 -070040 if (LOGD) {
41 Log.d(TAG, "workspace name: " + name + " id: " + workspaceResId);
42 }
Michael Jurka43467462013-11-14 12:03:58 +010043 new AsyncTask<Void, Void, Void>() {
44 public Void doInBackground(Void ... args) {
Brian Muramatsu5524b492012-10-02 16:55:54 -070045 provider.loadDefaultFavoritesIfNecessary(workspaceResId);
Michael Jurka43467462013-11-14 12:03:58 +010046 return null;
Brian Muramatsub6a4d982012-04-24 17:16:04 -070047 }
Michael Jurka43467462013-11-14 12:03:58 +010048 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Brian Muramatsub6a4d982012-04-24 17:16:04 -070049 }
50 }
51}