2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-30 13:37:37 -07:00
|
|
|
package com.android.launcher2;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
import android.app.Application;
|
2009-08-17 11:03:03 -04:00
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
|
import android.database.ContentObserver;
|
|
|
|
|
import android.os.Handler;
|
2009-03-03 19:32:27 -08:00
|
|
|
import dalvik.system.VMRuntime;
|
|
|
|
|
|
|
|
|
|
public class LauncherApplication extends Application {
|
2010-02-08 13:44:00 -08:00
|
|
|
public LauncherModel mModel;
|
|
|
|
|
public IconCache mIconCache;
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
|
|
|
|
|
|
|
|
|
|
super.onCreate();
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
mIconCache = new IconCache(this);
|
|
|
|
|
mModel = new LauncherModel(this, mIconCache);
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
// Register intent receivers
|
|
|
|
|
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
|
|
|
|
|
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
|
|
|
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
|
|
|
|
filter.addDataScheme("package");
|
2009-10-31 17:27:36 -04:00
|
|
|
registerReceiver(mModel, filter);
|
2010-03-05 15:05:52 -05:00
|
|
|
filter = new IntentFilter();
|
|
|
|
|
filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
|
|
|
|
|
filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
|
|
|
|
|
registerReceiver(mModel, filter);
|
2009-08-17 11:03:03 -04:00
|
|
|
|
|
|
|
|
// Register for changes to the favorites
|
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
|
resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
|
|
|
|
|
mFavoritesObserver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* There's no guarantee that this function is ever called.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onTerminate() {
|
|
|
|
|
super.onTerminate();
|
|
|
|
|
|
2009-10-31 17:27:36 -04:00
|
|
|
unregisterReceiver(mModel);
|
2009-08-17 11:03:03 -04:00
|
|
|
|
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
|
resolver.unregisterContentObserver(mFavoritesObserver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Receives notifications whenever the user favorites have changed.
|
|
|
|
|
*/
|
|
|
|
|
private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onChange(boolean selfChange) {
|
2009-10-31 17:27:36 -04:00
|
|
|
mModel.startLoader(LauncherApplication.this, false);
|
2009-08-17 11:03:03 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LauncherModel setLauncher(Launcher launcher) {
|
2009-10-31 17:27:36 -04:00
|
|
|
mModel.initialize(launcher);
|
|
|
|
|
return mModel;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
|
|
|
|
|
IconCache getIconCache() {
|
|
|
|
|
return mIconCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LauncherModel getModel() {
|
|
|
|
|
return mModel;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|