blob: ca08378d8ce6a776bb5f5f4fcb3d3d35a3f4a055 [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;
Winson Chungaafa03c2010-06-11 17:34:16 -070023import android.content.res.Configuration;
Joe Onorato9c1289c2009-08-17 11:03:03 -040024import 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 Onorato0589f0f2010-02-08 13:44:00 -080029 public LauncherModel mModel;
30 public IconCache mIconCache;
Winson Chungaafa03c2010-06-11 17:34:16 -070031 private static boolean sIsScreenXLarge;
32 private static final boolean ENABLE_ROTATION = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -040033
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034 @Override
35 public void onCreate() {
36 VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
37
38 super.onCreate();
Joe Onorato9c1289c2009-08-17 11:03:03 -040039
Joe Onorato0589f0f2010-02-08 13:44:00 -080040 mIconCache = new IconCache(this);
41 mModel = new LauncherModel(this, mIconCache);
Winson Chungaafa03c2010-06-11 17:34:16 -070042 sIsScreenXLarge = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
Joe Onorato0589f0f2010-02-08 13:44:00 -080043
Joe Onorato9c1289c2009-08-17 11:03:03 -040044 // Register intent receivers
45 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
46 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
47 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
48 filter.addDataScheme("package");
Joe Onoratof99f8c12009-10-31 17:27:36 -040049 registerReceiver(mModel, filter);
Joe Onorato64e6be72010-03-05 15:05:52 -050050 filter = new IntentFilter();
51 filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
52 filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
53 registerReceiver(mModel, filter);
Joe Onorato9c1289c2009-08-17 11:03:03 -040054
55 // Register for changes to the favorites
56 ContentResolver resolver = getContentResolver();
57 resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
58 mFavoritesObserver);
59 }
60
61 /**
62 * There's no guarantee that this function is ever called.
63 */
64 @Override
65 public void onTerminate() {
66 super.onTerminate();
67
Joe Onoratof99f8c12009-10-31 17:27:36 -040068 unregisterReceiver(mModel);
Joe Onorato9c1289c2009-08-17 11:03:03 -040069
70 ContentResolver resolver = getContentResolver();
71 resolver.unregisterContentObserver(mFavoritesObserver);
72 }
73
74 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040075 * 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) {
Joe Onoratof99f8c12009-10-31 17:27:36 -040080 mModel.startLoader(LauncherApplication.this, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -040081 }
82 };
83
84 LauncherModel setLauncher(Launcher launcher) {
Joe Onoratof99f8c12009-10-31 17:27:36 -040085 mModel.initialize(launcher);
86 return mModel;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080088
89 IconCache getIconCache() {
90 return mIconCache;
91 }
92
93 LauncherModel getModel() {
94 return mModel;
95 }
Winson Chungaafa03c2010-06-11 17:34:16 -070096
97 public static boolean isInPlaceRotationEnabled() {
98 return sIsScreenXLarge && ENABLE_ROTATION;
99 }
100
101 public static boolean isScreenXLarge() {
102 return sIsScreenXLarge;
103 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800104}