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;
|
2011-06-28 13:46:59 +01:00
|
|
|
import android.app.SearchManager;
|
2009-08-17 11:03:03 -04:00
|
|
|
import android.content.ContentResolver;
|
2011-07-27 17:46:20 -07:00
|
|
|
import android.content.Context;
|
2009-08-17 11:03:03 -04:00
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.IntentFilter;
|
2010-06-11 17:34:16 -07:00
|
|
|
import android.content.res.Configuration;
|
2009-08-17 11:03:03 -04:00
|
|
|
import android.database.ContentObserver;
|
|
|
|
|
import android.os.Handler;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2011-04-28 14:59:33 -07:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
public class LauncherApplication extends Application {
|
2010-02-08 13:44:00 -08:00
|
|
|
public LauncherModel mModel;
|
|
|
|
|
public IconCache mIconCache;
|
2011-05-12 14:57:05 -07:00
|
|
|
private static boolean sIsScreenLarge;
|
2010-10-14 13:21:48 -07:00
|
|
|
private static float sScreenDensity;
|
2011-04-28 14:59:33 -07:00
|
|
|
WeakReference<LauncherProvider> mLauncherProvider;
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
super.onCreate();
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2010-11-01 11:52:08 -07:00
|
|
|
// set sIsScreenXLarge and sScreenDensity *before* creating icon cache
|
2011-10-25 21:38:29 -07:00
|
|
|
final int screenSize = getResources().getConfiguration().screenLayout &
|
|
|
|
|
Configuration.SCREENLAYOUT_SIZE_MASK;
|
2011-05-12 14:57:05 -07:00
|
|
|
sIsScreenLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE ||
|
|
|
|
|
screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
2010-10-14 13:21:48 -07:00
|
|
|
sScreenDensity = getResources().getDisplayMetrics().density;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2010-11-01 11:52:08 -07: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);
|
2010-10-29 17:35:36 -07:00
|
|
|
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
|
2011-09-23 17:20:28 -07:00
|
|
|
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
2010-03-05 15:05:52 -05:00
|
|
|
registerReceiver(mModel, filter);
|
2011-06-28 13:46:59 +01:00
|
|
|
filter = new IntentFilter();
|
|
|
|
|
filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
|
|
|
|
|
registerReceiver(mModel, filter);
|
2011-08-23 11:58:54 -07:00
|
|
|
filter = new IntentFilter();
|
|
|
|
|
filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
|
|
|
|
|
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;
|
|
|
|
|
}
|
2010-06-11 17:34:16 -07:00
|
|
|
|
2011-04-28 14:59:33 -07:00
|
|
|
void setLauncherProvider(LauncherProvider provider) {
|
|
|
|
|
mLauncherProvider = new WeakReference<LauncherProvider>(provider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LauncherProvider getLauncherProvider() {
|
|
|
|
|
return mLauncherProvider.get();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-12 14:57:05 -07:00
|
|
|
public static boolean isScreenLarge() {
|
|
|
|
|
return sIsScreenLarge;
|
2010-06-11 17:34:16 -07:00
|
|
|
}
|
2010-10-14 13:21:48 -07:00
|
|
|
|
2011-07-27 17:46:20 -07:00
|
|
|
public static boolean isScreenLandscape(Context context) {
|
|
|
|
|
return context.getResources().getConfiguration().orientation ==
|
|
|
|
|
Configuration.ORIENTATION_LANDSCAPE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-14 13:21:48 -07:00
|
|
|
public static float getScreenDensity() {
|
|
|
|
|
return sScreenDensity;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|