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 17 package com.android.launcher2; 18 19 import android.app.Application; 20 import android.content.ContentResolver; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.IntentFilter; 24 import android.database.ContentObserver; 25 import android.os.Handler; 26 import dalvik.system.VMRuntime; 27 28 public class LauncherApplication extends Application { 29 public final LauncherModel mModel; 30 LauncherApplication()31 public LauncherApplication() { 32 mModel = new LauncherModel(this); 33 } 34 35 @Override onCreate()36 public void onCreate() { 37 VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024); 38 39 super.onCreate(); 40 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"); 46 registerReceiver(mModel, filter); 47 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 onTerminate()58 public void onTerminate() { 59 super.onTerminate(); 60 61 unregisterReceiver(mModel); 62 63 ContentResolver resolver = getContentResolver(); 64 resolver.unregisterContentObserver(mFavoritesObserver); 65 } 66 67 /** 68 * 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(); 74 mModel.setWorkspaceDirty(); 75 mModel.startLoader(LauncherApplication.this, false); 76 } 77 }; 78 setLauncher(Launcher launcher)79 LauncherModel setLauncher(Launcher launcher) { 80 mModel.initialize(launcher); 81 return mModel; 82 } 83 } 84