The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.app.Application; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 20 | import android.content.ContentResolver; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
| 23 | import android.database.ContentObserver; |
| 24 | import android.os.Handler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import dalvik.system.VMRuntime; |
| 26 | |
| 27 | public class LauncherApplication extends Application { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 28 | public LauncherModel mModel; |
| 29 | public IconCache mIconCache; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 30 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | @Override |
| 32 | public void onCreate() { |
| 33 | VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024); |
| 34 | |
| 35 | super.onCreate(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 36 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 37 | mIconCache = new IconCache(this); |
| 38 | mModel = new LauncherModel(this, mIconCache); |
| 39 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 40 | // 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 Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 45 | registerReceiver(mModel, filter); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 46 | |
| 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 Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 60 | unregisterReceiver(mModel); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 61 | |
| 62 | ContentResolver resolver = getContentResolver(); |
| 63 | resolver.unregisterContentObserver(mFavoritesObserver); |
| 64 | } |
| 65 | |
| 66 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 67 | * 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 Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 73 | mModel.setWorkspaceDirty(); |
| 74 | mModel.startLoader(LauncherApplication.this, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 75 | } |
| 76 | }; |
| 77 | |
| 78 | LauncherModel setLauncher(Launcher launcher) { |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 79 | mModel.initialize(launcher); |
| 80 | return mModel; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 81 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 82 | |
| 83 | IconCache getIconCache() { |
| 84 | return mIconCache; |
| 85 | } |
| 86 | |
| 87 | LauncherModel getModel() { |
| 88 | return mModel; |
| 89 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | } |