diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher/HandleView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher/Launcher.java | 163 | ||||
-rw-r--r-- | src/com/android/launcher/LauncherModel.java | 26 |
3 files changed, 126 insertions, 65 deletions
diff --git a/src/com/android/launcher/HandleView.java b/src/com/android/launcher/HandleView.java index 437d559..9afe41c 100644 --- a/src/com/android/launcher/HandleView.java +++ b/src/com/android/launcher/HandleView.java @@ -49,7 +49,7 @@ public class HandleView extends ImageView { @Override public View focusSearch(int direction) { View newFocus = super.focusSearch(direction); - if (newFocus == null) { + if (newFocus == null && mLauncher.isDrawerDown()) { final Workspace workspace = mLauncher.getWorkspace(); workspace.dispatchUnhandledMove(null, direction); return (mOrientation == ORIENTATION_HORIZONTAL && direction == FOCUS_DOWN) ? diff --git a/src/com/android/launcher/Launcher.java b/src/com/android/launcher/Launcher.java index 928f4ca..01001c0 100644 --- a/src/com/android/launcher/Launcher.java +++ b/src/com/android/launcher/Launcher.java @@ -45,6 +45,7 @@ import android.os.IBinder; import android.os.Parcelable; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.Message; import android.provider.*; import android.telephony.PhoneNumberUtils; import android.text.Selection; @@ -260,7 +261,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On private void startLoaders() { sModel.loadApplications(true, this, mLocaleChanged); - sModel.loadUserItems(!mLocaleChanged, this, mLocaleChanged); + sModel.loadUserItems(!mLocaleChanged, this, mLocaleChanged, true); mRestoring = false; } @@ -812,13 +813,13 @@ public final class Launcher extends Activity implements View.OnClickListener, On .setIcon(android.R.drawable.ic_menu_add) .setAlphabeticShortcut('A'); menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) - .setIcon(R.drawable.ic_menu_gallery) + .setIcon(android.R.drawable.ic_menu_gallery) .setAlphabeticShortcut('W'); menu.add(0, MENU_SEARCH, 0, R.string.menu_search) .setIcon(android.R.drawable.ic_search_category_default) .setAlphabeticShortcut(SearchManager.MENU_KEY); menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) - .setIcon(R.drawable.ic_menu_notifications) + .setIcon(android.R.drawable.ic_menu_notifications) .setAlphabeticShortcut('N'); final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); @@ -826,7 +827,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) - .setIcon(R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') + .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') .setIntent(settings); return true; @@ -1111,7 +1112,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On private void onFavoritesChanged() { mDesktopLocked = true; mDrawer.lock(); - sModel.loadUserItems(false, this, false); + sModel.loadUserItems(false, this, false, false); } void onDesktopItemsLoaded() { @@ -1119,7 +1120,80 @@ public final class Launcher extends Activity implements View.OnClickListener, On bindDesktopItems(); mAllAppsGrid.setAdapter(Launcher.getModel().getApplicationsAdapter()); + } + + /** + * Refreshes the shortcuts shown on the workspace. + */ + private void bindDesktopItems() { + final ArrayList<ItemInfo> shortcuts = sModel.getDesktopItems(); + if (shortcuts == null) { + return; + } + + final Workspace workspace = mWorkspace; + int count = workspace.getChildCount(); + for (int i = 0; i < count; i++) { + ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); + } + + count = shortcuts.size(); + + final DesktopItemsBinder binder = new DesktopItemsBinder(this, shortcuts); + binder.obtainMessage(DesktopItemsBinder.MESSAGE_BIND_ITEMS, 0, count).sendToTarget(); + } + private void bindItems(Launcher.DesktopItemsBinder binder, + ArrayList<ItemInfo> shortcuts, int start, int count) { + + final Workspace workspace = mWorkspace; + final boolean desktopLocked = mDesktopLocked; + + final int end = Math.min(start + DesktopItemsBinder.ITEMS_COUNT, count); + int i = start; + + for ( ; i < end; i++) { + final ItemInfo item = shortcuts.get(i); + switch (item.itemType) { + case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: + case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + final View shortcut = createShortcut((ApplicationInfo) item); + workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, + !desktopLocked); + break; + case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: + final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, + (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), + (UserFolderInfo) item); + workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, + !desktopLocked); + break; + case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: + final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( + R.layout.live_folder_icon, this, + (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), + (LiveFolderInfo) item); + workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, + !desktopLocked); + break; + default: + final Widget widget = (Widget) item; + final View view = createWidget(mInflater, widget); + view.setTag(widget); + workspace.addWidget(view, widget, !desktopLocked); + } + } + + workspace.requestLayout(); + + if (end >= count) { + finishBindDesktopItems(); + } else { + binder.obtainMessage(DesktopItemsBinder.MESSAGE_BIND_ITEMS, i, count).sendToTarget(); + } + } + + private void finishBindDesktopItems() { if (mSavedState != null) { mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); @@ -1152,57 +1226,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On mDrawer.unlock(); } - /** - * Refreshes the shortcuts shown on the workspace. - */ - private void bindDesktopItems() { - final ArrayList<ItemInfo> shortcuts = sModel.getDesktopItems(); - if (shortcuts == null) { - return; - } - - final Workspace workspace = mWorkspace; - int count = workspace.getChildCount(); - for (int i = 0; i < count; i++) { - ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); - } - - count = shortcuts.size(); - for (int i = 0; i < count; i++) { - final ItemInfo item = shortcuts.get(i); - switch (item.itemType) { - case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: - case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: - final View shortcut = createShortcut((ApplicationInfo) item); - workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, - !mDesktopLocked); - break; - case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: - final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, - (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), - ((UserFolderInfo) item)); - workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, - !mDesktopLocked); - break; - case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: - final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( - R.layout.live_folder_icon, this, - (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), - ((LiveFolderInfo) item)); - workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, - !mDesktopLocked); - break; - default: - final Widget widget = (Widget)item; - final View view = createWidget(mInflater, widget); - view.setTag(widget); - workspace.addWidget(view, widget, !mDesktopLocked); - } - } - - workspace.requestLayout(); - } - private View createWidget(LayoutInflater inflater, Widget widget) { final Workspace workspace = mWorkspace; final int screen = workspace.getCurrentScreen(); @@ -1456,7 +1479,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On if (mDesktopLocked) { mDrawer.lock(); - sModel.loadUserItems(false, Launcher.this, false); + sModel.loadUserItems(false, Launcher.this, false, false); } else { final FolderIcon folderIcon = (FolderIcon) mWorkspace.getViewForTag(mFolderInfo); @@ -1466,7 +1489,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On } else { mDesktopLocked = true; mDrawer.lock(); - sModel.loadUserItems(false, Launcher.this, false); + sModel.loadUserItems(false, Launcher.this, false, false); } } } @@ -1635,4 +1658,28 @@ public final class Launcher extends Activity implements View.OnClickListener, On public void onScrollEnded() { } } + + private static class DesktopItemsBinder extends Handler { + static final int MESSAGE_BIND_ITEMS = 0x1; + // Number of items to bind in every pass + static final int ITEMS_COUNT = 6; + + private final ArrayList<ItemInfo> mShortcuts; + private final WeakReference<Launcher> mLauncher; + + DesktopItemsBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts) { + mLauncher = new WeakReference<Launcher>(launcher); + mShortcuts = shortcuts; + } + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MESSAGE_BIND_ITEMS: + Launcher launcher = mLauncher.get(); + if (launcher != null) launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2); + break; + } + } + } } diff --git a/src/com/android/launcher/LauncherModel.java b/src/com/android/launcher/LauncherModel.java index 0ef2a80..314a502 100644 --- a/src/com/android/launcher/LauncherModel.java +++ b/src/com/android/launcher/LauncherModel.java @@ -28,9 +28,9 @@ import android.content.res.Resources; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.util.Log; +import android.os.Process; import java.util.ArrayList; import java.util.Collections; @@ -45,7 +45,6 @@ import java.net.URISyntaxException; * 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 - * */ public class LauncherModel { private static final int UI_NOTIFICATION_RATE = 4; @@ -104,6 +103,13 @@ public class LauncherModel { } mApplicationsLoaded = false; + + if (!isLaunching) { + startApplicationsLoader(launcher); + } + } + + private void startApplicationsLoader(Launcher launcher) { mApplicationsLoader = new ApplicationsLoader(launcher); mLoader = new Thread(mApplicationsLoader, "Applications Loader"); mLoader.start(); @@ -130,6 +136,8 @@ public class LauncherModel { public void run() { mRunning = true; + android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); @@ -221,8 +229,11 @@ public class LauncherModel { * Loads all of the items on the desktop, in folders, or in the dock. * These can be apps, shortcuts or widgets */ - void loadUserItems(boolean isLaunching, Launcher launcher, boolean localeChanged) { + void loadUserItems(boolean isLaunching, Launcher launcher, boolean localeChanged, + boolean loadApplications) { + if (isLaunching && mDesktopItems != null && mDesktopItemsLoaded) { + if (loadApplications) startApplicationsLoader(launcher); // We have already loaded our data from the DB launcher.onDesktopItemsLoaded(); return; @@ -240,7 +251,7 @@ public class LauncherModel { } mDesktopItemsLoaded = false; - mDesktopItemsLoader = new DesktopItemsLoader(launcher, localeChanged); + mDesktopItemsLoader = new DesktopItemsLoader(launcher, localeChanged, loadApplications); mDesktopLoader = new Thread(mDesktopItemsLoader, "Desktop Items Loader"); mDesktopLoader.start(); } @@ -317,9 +328,11 @@ public class LauncherModel { private volatile boolean mRunning; private final WeakReference<Launcher> mLauncher; - private boolean mLocaleChanged; + private final boolean mLocaleChanged; + private final boolean mLoadApplications; - DesktopItemsLoader(Launcher launcher, boolean localeChanged) { + DesktopItemsLoader(Launcher launcher, boolean localeChanged, boolean loadApplications) { + mLoadApplications = loadApplications; mLauncher = new WeakReference<Launcher>(launcher); mLocaleChanged = localeChanged; } @@ -532,6 +545,7 @@ public class LauncherModel { launcher.onDesktopItemsLoaded(); } }); + if (mLoadApplications) startApplicationsLoader(launcher); } if (!mStopped) { |