blob: 183dbf5719f65b894cdda8ecfcc615c916b0d646 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
19import android.app.Application;
Joe Onorato9c1289c2009-08-17 11:03:03 -040020import android.content.ContentResolver;
Joe Onorato9c1289c2009-08-17 11:03:03 -040021import android.content.Intent;
22import android.content.IntentFilter;
23import android.database.ContentObserver;
24import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import dalvik.system.VMRuntime;
26
27public class LauncherApplication extends Application {
Joe Onorato0589f0f2010-02-08 13:44:00 -080028 public LauncherModel mModel;
29 public IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -040030
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031 @Override
32 public void onCreate() {
33 VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
34
35 super.onCreate();
Joe Onorato9c1289c2009-08-17 11:03:03 -040036
Joe Onorato0589f0f2010-02-08 13:44:00 -080037 mIconCache = new IconCache(this);
38 mModel = new LauncherModel(this, mIconCache);
39
Joe Onorato9c1289c2009-08-17 11:03:03 -040040 // Register intent receivers
41 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
42 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
43 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
44 filter.addDataScheme("package");
Joe Onoratof99f8c12009-10-31 17:27:36 -040045 registerReceiver(mModel, filter);
Joe Onorato9c1289c2009-08-17 11:03:03 -040046
47 // Register for changes to the favorites
48 ContentResolver resolver = getContentResolver();
49 resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
50 mFavoritesObserver);
51 }
52
53 /**
54 * There's no guarantee that this function is ever called.
55 */
56 @Override
57 public void onTerminate() {
58 super.onTerminate();
59
Joe Onoratof99f8c12009-10-31 17:27:36 -040060 unregisterReceiver(mModel);
Joe Onorato9c1289c2009-08-17 11:03:03 -040061
62 ContentResolver resolver = getContentResolver();
63 resolver.unregisterContentObserver(mFavoritesObserver);
64 }
65
66 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040067 * Receives notifications whenever the user favorites have changed.
68 */
69 private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
70 @Override
71 public void onChange(boolean selfChange) {
72 // TODO: lockAllApps();
Joe Onoratof99f8c12009-10-31 17:27:36 -040073 mModel.setWorkspaceDirty();
74 mModel.startLoader(LauncherApplication.this, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -040075 }
76 };
77
78 LauncherModel setLauncher(Launcher launcher) {
Joe Onoratof99f8c12009-10-31 17:27:36 -040079 mModel.initialize(launcher);
80 return mModel;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080082
83 IconCache getIconCache() {
84 return mIconCache;
85 }
86
87 LauncherModel getModel() {
88 return mModel;
89 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090}