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.BroadcastReceiver; |
| 21 | import android.content.ContentResolver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
| 25 | import android.database.ContentObserver; |
| 26 | import android.os.Handler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | import dalvik.system.VMRuntime; |
| 28 | |
| 29 | public class LauncherApplication extends Application { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame^] | 30 | public static final LauncherModel sModel = new LauncherModel(); |
| 31 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | @Override |
| 33 | public void onCreate() { |
| 34 | VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024); |
| 35 | |
| 36 | super.onCreate(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame^] | 37 | |
| 38 | // Register intent receivers |
| 39 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 40 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 41 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| 42 | filter.addDataScheme("package"); |
| 43 | registerReceiver(mApplicationsReceiver, filter); |
| 44 | |
| 45 | // Register for changes to the favorites |
| 46 | ContentResolver resolver = getContentResolver(); |
| 47 | resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true, |
| 48 | mFavoritesObserver); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * There's no guarantee that this function is ever called. |
| 53 | */ |
| 54 | @Override |
| 55 | public void onTerminate() { |
| 56 | super.onTerminate(); |
| 57 | |
| 58 | unregisterReceiver(mApplicationsReceiver); |
| 59 | |
| 60 | ContentResolver resolver = getContentResolver(); |
| 61 | resolver.unregisterContentObserver(mFavoritesObserver); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Receives notifications when applications are added/removed. |
| 66 | */ |
| 67 | private final BroadcastReceiver mApplicationsReceiver = new BroadcastReceiver() { |
| 68 | @Override |
| 69 | public void onReceive(Context context, Intent intent) { |
| 70 | sModel.onReceiveIntent(LauncherApplication.this, intent); |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * Receives notifications whenever the user favorites have changed. |
| 76 | */ |
| 77 | private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) { |
| 78 | @Override |
| 79 | public void onChange(boolean selfChange) { |
| 80 | // TODO: lockAllApps(); |
| 81 | sModel.setWorkspaceDirty(); |
| 82 | sModel.startLoader(LauncherApplication.this, false); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | LauncherModel setLauncher(Launcher launcher) { |
| 87 | sModel.initialize(launcher); |
| 88 | return sModel; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 89 | } |
| 90 | } |