blob: 9b63524332e360896d8e7e141f0b63da84197802 [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;
21import android.content.Context;
22import android.content.Intent;
23import android.content.IntentFilter;
24import android.database.ContentObserver;
25import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026import dalvik.system.VMRuntime;
27
28public class LauncherApplication extends Application {
Joe Onoratof99f8c12009-10-31 17:27:36 -040029 public final LauncherModel mModel;
30
31 public LauncherApplication() {
32 mModel = new LauncherModel(this);
33 }
Joe Onorato9c1289c2009-08-17 11:03:03 -040034
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035 @Override
36 public void onCreate() {
37 VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
38
39 super.onCreate();
Joe Onorato9c1289c2009-08-17 11:03:03 -040040
41 // Register intent receivers
42 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
43 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
44 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
45 filter.addDataScheme("package");
Joe Onoratof99f8c12009-10-31 17:27:36 -040046 registerReceiver(mModel, filter);
Joe Onorato9c1289c2009-08-17 11:03:03 -040047
48 // Register for changes to the favorites
49 ContentResolver resolver = getContentResolver();
50 resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
51 mFavoritesObserver);
52 }
53
54 /**
55 * There's no guarantee that this function is ever called.
56 */
57 @Override
58 public void onTerminate() {
59 super.onTerminate();
60
Joe Onoratof99f8c12009-10-31 17:27:36 -040061 unregisterReceiver(mModel);
Joe Onorato9c1289c2009-08-17 11:03:03 -040062
63 ContentResolver resolver = getContentResolver();
64 resolver.unregisterContentObserver(mFavoritesObserver);
65 }
66
67 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040068 * Receives notifications whenever the user favorites have changed.
69 */
70 private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
71 @Override
72 public void onChange(boolean selfChange) {
73 // TODO: lockAllApps();
Joe Onoratof99f8c12009-10-31 17:27:36 -040074 mModel.setWorkspaceDirty();
75 mModel.startLoader(LauncherApplication.this, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -040076 }
77 };
78
79 LauncherModel setLauncher(Launcher launcher) {
Joe Onoratof99f8c12009-10-31 17:27:36 -040080 mModel.initialize(launcher);
81 return mModel;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082 }
83}