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; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 24 | import android.database.ContentObserver; |
| 25 | import android.os.Handler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 26 | import dalvik.system.VMRuntime; |
| 27 | |
| 28 | public class LauncherApplication extends Application { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 29 | public LauncherModel mModel; |
| 30 | public IconCache mIconCache; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 31 | private static boolean sIsScreenXLarge; |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 32 | private static float sScreenDensity; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 33 | private static final boolean ENABLE_ROTATION = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 34 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | @Override |
| 36 | public void onCreate() { |
| 37 | VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024); |
| 38 | |
| 39 | super.onCreate(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 40 | |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame^] | 41 | // set sIsScreenXLarge and sScreenDensity *before* creating icon cache |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 42 | sIsScreenXLarge = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 43 | sScreenDensity = getResources().getDisplayMetrics().density; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 44 | |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame^] | 45 | mIconCache = new IconCache(this); |
| 46 | mModel = new LauncherModel(this, mIconCache); |
| 47 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 48 | // Register intent receivers |
| 49 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 50 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 51 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| 52 | filter.addDataScheme("package"); |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 53 | registerReceiver(mModel, filter); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 54 | filter = new IntentFilter(); |
| 55 | filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); |
| 56 | filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
Joe Onorato | e9ad59e | 2010-10-29 17:35:36 -0700 | [diff] [blame] | 57 | filter.addAction(Intent.ACTION_LOCALE_CHANGED); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 58 | registerReceiver(mModel, filter); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 59 | |
| 60 | // Register for changes to the favorites |
| 61 | ContentResolver resolver = getContentResolver(); |
| 62 | resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true, |
| 63 | mFavoritesObserver); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * There's no guarantee that this function is ever called. |
| 68 | */ |
| 69 | @Override |
| 70 | public void onTerminate() { |
| 71 | super.onTerminate(); |
| 72 | |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 73 | unregisterReceiver(mModel); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 74 | |
| 75 | ContentResolver resolver = getContentResolver(); |
| 76 | resolver.unregisterContentObserver(mFavoritesObserver); |
| 77 | } |
| 78 | |
| 79 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 80 | * Receives notifications whenever the user favorites have changed. |
| 81 | */ |
| 82 | private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) { |
| 83 | @Override |
| 84 | public void onChange(boolean selfChange) { |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 85 | mModel.startLoader(LauncherApplication.this, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 86 | } |
| 87 | }; |
| 88 | |
| 89 | LauncherModel setLauncher(Launcher launcher) { |
Joe Onorato | f99f8c1 | 2009-10-31 17:27:36 -0400 | [diff] [blame] | 90 | mModel.initialize(launcher); |
| 91 | return mModel; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 92 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 93 | |
| 94 | IconCache getIconCache() { |
| 95 | return mIconCache; |
| 96 | } |
| 97 | |
| 98 | LauncherModel getModel() { |
| 99 | return mModel; |
| 100 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 101 | |
| 102 | public static boolean isInPlaceRotationEnabled() { |
| 103 | return sIsScreenXLarge && ENABLE_ROTATION; |
| 104 | } |
| 105 | |
| 106 | public static boolean isScreenXLarge() { |
| 107 | return sIsScreenXLarge; |
| 108 | } |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 109 | |
| 110 | public static float getScreenDensity() { |
| 111 | return sScreenDensity; |
| 112 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 113 | } |