blob: be448a8910049469554ee046b6683d3f42a8b1a1 [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 Onorato64e6be72010-03-05 15:05:52 -050046 filter = new IntentFilter();
47 filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
48 filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
49 registerReceiver(mModel, filter);
Joe Onorato9c1289c2009-08-17 11:03:03 -040050
51 // Register for changes to the favorites
52 ContentResolver resolver = getContentResolver();
53 resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
54 mFavoritesObserver);
55 }
56
57 /**
58 * There's no guarantee that this function is ever called.
59 */
60 @Override
61 public void onTerminate() {
62 super.onTerminate();
63
Joe Onoratof99f8c12009-10-31 17:27:36 -040064 unregisterReceiver(mModel);
Joe Onorato9c1289c2009-08-17 11:03:03 -040065
66 ContentResolver resolver = getContentResolver();
67 resolver.unregisterContentObserver(mFavoritesObserver);
68 }
69
70 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040071 * Receives notifications whenever the user favorites have changed.
72 */
73 private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
74 @Override
75 public void onChange(boolean selfChange) {
76 // TODO: lockAllApps();
Joe Onoratof99f8c12009-10-31 17:27:36 -040077 mModel.setWorkspaceDirty();
78 mModel.startLoader(LauncherApplication.this, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -040079 }
80 };
81
82 LauncherModel setLauncher(Launcher launcher) {
Joe Onoratof99f8c12009-10-31 17:27:36 -040083 mModel.initialize(launcher);
84 return mModel;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080085 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080086
87 IconCache getIconCache() {
88 return mIconCache;
89 }
90
91 LauncherModel getModel() {
92 return mModel;
93 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094}