Skip to content

Commit

Permalink
auto import from //branches/cupcake/...@137197
Browse files Browse the repository at this point in the history
  • Loading branch information
The Android Open Source Project committed Mar 9, 2009
1 parent 1ff70f7 commit bc219c3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := user eng development
LOCAL_MODULE_TAGS := user

LOCAL_SRC_FILES := $(call all-subdir-java-files)

Expand Down
1 change: 0 additions & 1 deletion src/com/android/launcher/CellLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, RectF
*
* @param width Width in pixels
* @param height Height in pixels
* @param Horizontal and vertical spans required
*/
public int[] rectToCell(int width, int height) {
// Always assume we're working with the smallest span to make sure we
Expand Down
7 changes: 2 additions & 5 deletions src/com/android/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
// Type: long
private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";

private static LauncherModel sModel;
private static final LauncherModel sModel = new LauncherModel();

private static Bitmap sWallpaper;

Expand Down Expand Up @@ -212,10 +212,6 @@ protected void onCreate(Bundle savedInstanceState) {
checkForLocaleChange();
setWallpaperDimension();

if (sModel == null) {
sModel = new LauncherModel();
}

setContentView(R.layout.launcher);
setupViews();

Expand Down Expand Up @@ -1742,6 +1738,7 @@ public void onReceive(Context context, Intent intent) {
}
}
removeDialog(DIALOG_CREATE_SHORTCUT);
sModel.dropApplicationCache();
if (!reloadWorkspace) {
sModel.loadApplications(false, Launcher.this, false);
} else {
Expand Down
88 changes: 63 additions & 25 deletions src/com/android/launcher/LauncherModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;
import android.os.Process;
Expand All @@ -44,14 +45,17 @@
/**
* Maintains in-memory state of the Launcher. It is expected that there should be only one
* LauncherModel object held in a static. Also provide APIs for updating the database state
* for the Launcher
* for the Launcher.
*/
public class LauncherModel {
private static final int UI_NOTIFICATION_RATE = 4;
private static final int DEFAULT_APPLICATIONS_NUMBER = 42;
private static final long APPLICATION_NOT_RESPONDING_TIMEOUT = 5000;
private static final int INITIAL_ICON_CACHE_CAPACITY = 50;

private final Collator sCollator = Collator.getInstance();
private static final boolean DEBUG = false;

private final Collator sCollator = Collator.getInstance();

private boolean mApplicationsLoaded;
private boolean mDesktopItemsLoaded;
Expand All @@ -67,6 +71,9 @@ public class LauncherModel {
private Thread mLoader;
private Thread mDesktopLoader;

private final HashMap<ComponentName, ApplicationInfo> mAppInfoCache =
new HashMap<ComponentName, ApplicationInfo>(INITIAL_ICON_CACHE_CAPACITY);

void abortLoaders() {
if (mApplicationsLoader != null && mApplicationsLoader.isRunning()) {
mApplicationsLoader.stop();
Expand All @@ -78,18 +85,31 @@ void abortLoaders() {
}
}

/**
* Drop our cache of components to their lables & icons. We do
* this from Launcher when applications are added/removed. It's a
* bit overkill, but it's a rare operation anyway.
*/
synchronized void dropApplicationCache() {
mAppInfoCache.clear();
}

/**
* Loads the list of installed applications in mApplications.
*/
void loadApplications(boolean isLaunching, Launcher launcher, boolean localeChanged) {
synchronized void loadApplications(boolean isLaunching, Launcher launcher,
boolean localeChanged) {
if (localeChanged) {
dropApplicationCache();
}
if (isLaunching && mApplicationsLoaded && !localeChanged) {
mApplicationsAdapter = new ApplicationsAdapter(launcher, mApplications);
return;
}

if (mApplicationsAdapter == null || isLaunching || localeChanged) {
mApplicationsAdapter = new ApplicationsAdapter(launcher,
mApplications = new ArrayList<ApplicationInfo>(DEFAULT_APPLICATIONS_NUMBER));
mApplications = new ArrayList<ApplicationInfo>(DEFAULT_APPLICATIONS_NUMBER);
mApplicationsAdapter = new ApplicationsAdapter(launcher, mApplications);
}

if (mApplicationsLoader != null && mApplicationsLoader.isRunning()) {
Expand Down Expand Up @@ -153,20 +173,27 @@ public void run() {
ChangeNotifier action = new ChangeNotifier(applicationList);

for (int i = 0; i < count && !mStopped; i++) {
ApplicationInfo application = new ApplicationInfo();
ResolveInfo info = apps.get(i);

application.title = info.loadLabel(manager);
if (application.title == null) {
application.title = info.activityInfo.name;
}
application.setActivity(new ComponentName(
ComponentName componentName = new ComponentName(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name),
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
application.icon = info.activityInfo.loadIcon(manager);
application.container = ItemInfo.NO_ID;
info.activityInfo.name);
ApplicationInfo application = mAppInfoCache.get(componentName);
if (application == null) {
application = new ApplicationInfo();
application.title = info.loadLabel(manager);
if (application.title == null) {
application.title = info.activityInfo.name;
}
application.setActivity(componentName,
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
application.container = ItemInfo.NO_ID;
application.icon = info.activityInfo.loadIcon(manager);
if (DEBUG) {
Log.d(Launcher.LOG_TAG, "Loaded ApplicationInfo for " + componentName);
}
mAppInfoCache.put(componentName, application);
}

action.add(application);
}
Expand All @@ -191,7 +218,7 @@ public final int compare(ApplicationInfo a, ApplicationInfo b) {

private static class ChangeNotifier implements Runnable {
private final ApplicationsAdapter mApplicationList;
private ArrayList<ApplicationInfo> mBuffer;
private final ArrayList<ApplicationInfo> mBuffer;

ChangeNotifier(ApplicationsAdapter applicationList) {
mApplicationList = applicationList;
Expand Down Expand Up @@ -226,7 +253,7 @@ void sort(Comparator<ApplicationInfo> comparator) {
boolean isDesktopLoaded() {
return mDesktopItems != null && mDesktopGadgets != null && mDesktopItemsLoaded;
}

/**
* Loads all of the items on the desktop, in folders, or in the dock.
* These can be apps, shortcuts or widgets
Expand Down Expand Up @@ -512,7 +539,7 @@ public void run() {
+ "!= CONTAINER_DESKTOP ignoring!");
continue;
}

widgetInfo.id = c.getLong(idIndex);
widgetInfo.screen = c.getInt(screenIndex);
widgetInfo.container = container;
Expand All @@ -539,7 +566,7 @@ public void run() {
continue;
}
gadgetInfo.container = c.getInt(containerIndex);

desktopGadgets.add(gadgetInfo);
break;
}
Expand Down Expand Up @@ -590,15 +617,15 @@ private static void loadLiveFolderIcon(Launcher launcher, Cursor c, int iconType
break;
default:
liveFolderInfo.icon =
launcher.getResources().getDrawable(R.drawable.ic_launcher_folder);
launcher.getResources().getDrawable(R.drawable.ic_launcher_folder);
}
}

/**
* Finds the user folder defined by the specified id.
*
* @param id The id of the folder to look for.
*
*
* @return A UserFolderInfo if the folder exists or null otherwise.
*/
FolderInfo findFolderById(long id) {
Expand Down Expand Up @@ -648,8 +675,9 @@ void unbind() {
unbindAppDrawables(mApplications);
unbindDrawables(mDesktopItems);
unbindGadgetHostViews(mDesktopGadgets);
unbindCachedIconDrawables();
}

/**
* Remove the callback for the cached drawables or we leak the previous
* Home screen on orientation change.
Expand All @@ -668,7 +696,7 @@ private void unbindDrawables(ArrayList<ItemInfo> desktopItems) {
}
}
}

/**
* Remove the callback for the cached drawables or we leak the previous
* Home screen on orientation change.
Expand All @@ -695,6 +723,16 @@ private void unbindGadgetHostViews(ArrayList<LauncherGadgetInfo> gadgets) {
}
}

/**
* Remove the callback for the cached drawables or we leak the previous
* Home screen on orientation change.
*/
private void unbindCachedIconDrawables() {
for (ApplicationInfo appInfo : mAppInfoCache.values()) {
appInfo.icon.setCallback(null);
}
}

/**
* @return The current list of applications
*/
Expand Down

0 comments on commit bc219c3

Please sign in to comment.