summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-13 13:04:24 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-13 13:04:24 -0700
commitca9475f0403d9c0e843d5c189575068a386b2eb6 (patch)
tree1e11e1499277de5da9a1166fbd826e50d0b6f12f /src/com/android
parent7376faefbbcbe30cc4e3f706ab95c254a4707d98 (diff)
downloadandroid_packages_apps_Trebuchet-ca9475f0403d9c0e843d5c189575068a386b2eb6.tar.gz
android_packages_apps_Trebuchet-ca9475f0403d9c0e843d5c189575068a386b2eb6.tar.bz2
android_packages_apps_Trebuchet-ca9475f0403d9c0e843d5c189575068a386b2eb6.zip
auto import from //branches/cupcake_rel/...@138607
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/launcher/Launcher.java41
-rw-r--r--src/com/android/launcher/LauncherModel.java130
-rw-r--r--src/com/android/launcher/LauncherProvider.java14
-rw-r--r--src/com/android/launcher/LauncherSettings.java2
-rw-r--r--src/com/android/launcher/Workspace.java8
5 files changed, 108 insertions, 87 deletions
diff --git a/src/com/android/launcher/Launcher.java b/src/com/android/launcher/Launcher.java
index 99182f1dc..17f16a7a3 100644
--- a/src/com/android/launcher/Launcher.java
+++ b/src/com/android/launcher/Launcher.java
@@ -273,8 +273,9 @@ public final class Launcher extends Activity implements View.OnClickListener, On
}
private void startLoaders() {
- sModel.loadApplications(true, this, mLocaleChanged);
- sModel.loadUserItems(!mLocaleChanged, this, mLocaleChanged, true);
+ boolean loadApplications = sModel.loadApplications(true, this, mLocaleChanged);
+ sModel.loadUserItems(!mLocaleChanged, this, mLocaleChanged, loadApplications);
+
mRestoring = false;
}
@@ -352,16 +353,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
closeDrawer(false);
}
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event) {
- boolean handled = super.onKeyUp(keyCode, event);
- if (keyCode == KeyEvent.KEYCODE_SEARCH) {
- handled = mWorkspace.snapToSearch();
- if (handled) closeDrawer(true);
- }
- return handled;
- }
-
private boolean acceptFilter() {
final InputMethodManager inputManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -882,11 +873,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
startWallpaper();
return true;
case MENU_SEARCH:
- if (mWorkspace.snapToSearch()) {
- closeDrawer(true); // search widget: get drawer out of the way
- } else {
- onSearchRequested(); // no search widget: use system search UI
- }
+ onSearchRequested();
return true;
case MENU_NOTIFICATIONS:
showNotifications();
@@ -896,6 +883,16 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return super.onOptionsItemSelected(item);
}
+ @Override
+ public boolean onSearchRequested() {
+ if (mWorkspace.snapToSearch()) {
+ closeDrawer(true); // search widget: get drawer out of the way
+ return true;
+ } else {
+ return super.onSearchRequested(); // no search widget: use system search UI
+ }
+ }
+
private void addItems() {
showAddDialog(mMenuAddInfo);
}
@@ -1166,8 +1163,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On
void onDesktopItemsLoaded() {
if (mDestroyed) return;
-
- mAllAppsGrid.setAdapter(Launcher.getModel().getApplicationsAdapter());
+android.util.Log.d("Home", "setting grid adapter");
+ mAllAppsGrid.setAdapter(sModel.getApplicationsAdapter());
bindDesktopItems();
}
@@ -1467,6 +1464,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
if (cellInfo.cell == null) {
if (cellInfo.valid) {
// User long pressed on empty space
+ mWorkspace.setAllowLongPress(false);
showAddDialog(cellInfo);
}
} else {
@@ -1745,6 +1743,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On
@Override
public void onReceive(Context context, Intent intent) {
boolean reloadWorkspace = false;
+android.util.Log.d("Home", "application intent received: " + intent.getAction());
+android.util.Log.d("Home", " --> " + intent.getData());
if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
removeShortcutsForPackage(intent.getData().getSchemeSpecificPart());
@@ -1753,10 +1753,11 @@ public final class Launcher extends Activity implements View.OnClickListener, On
}
}
removeDialog(DIALOG_CREATE_SHORTCUT);
- sModel.dropApplicationCache();
if (!reloadWorkspace) {
+android.util.Log.d("Home", " --> loading apps");
sModel.loadApplications(false, Launcher.this, false);
} else {
+android.util.Log.d("Home", " --> loading workspace");
sModel.loadUserItems(false, Launcher.this, false, true);
}
}
diff --git a/src/com/android/launcher/LauncherModel.java b/src/com/android/launcher/LauncherModel.java
index 5266bdd62..70b4c10f4 100644
--- a/src/com/android/launcher/LauncherModel.java
+++ b/src/com/android/launcher/LauncherModel.java
@@ -66,17 +66,18 @@ public class LauncherModel {
private ApplicationsAdapter mApplicationsAdapter;
private ApplicationsLoader mApplicationsLoader;
private DesktopItemsLoader mDesktopItemsLoader;
- private Thread mLoader;
- private Thread mDesktopLoader;
+ private Thread mApplicationsLoaderThread;
+ private Thread mDesktopLoaderThread;
private final HashMap<ComponentName, ApplicationInfo> mAppInfoCache =
new HashMap<ComponentName, ApplicationInfo>(INITIAL_ICON_CACHE_CAPACITY);
- void abortLoaders() {
+ synchronized void abortLoaders() {
if (mApplicationsLoader != null && mApplicationsLoader.isRunning()) {
mApplicationsLoader.stop();
mApplicationsLoaded = false;
}
+
if (mDesktopItemsLoader != null && mDesktopItemsLoader.isRunning()) {
mDesktopItemsLoader.stop();
mDesktopItemsLoaded = false;
@@ -94,44 +95,62 @@ public class LauncherModel {
/**
* Loads the list of installed applications in mApplications.
+ *
+ * @return true if the applications loader must be started
+ * (see startApplicationsLoader()), false otherwise.
*/
- synchronized void loadApplications(boolean isLaunching, Launcher launcher,
+ synchronized boolean loadApplications(boolean isLaunching, Launcher launcher,
boolean localeChanged) {
- if (localeChanged) {
- dropApplicationCache();
- }
+android.util.Log.d("Home", "load applications");
if (isLaunching && mApplicationsLoaded && !localeChanged) {
mApplicationsAdapter = new ApplicationsAdapter(launcher, mApplications);
- return;
+android.util.Log.d("Home", " --> applications loaded, return");
+ return false;
}
+ waitForApplicationsLoader();
+
+ if (localeChanged) {
+ dropApplicationCache();
+ }
+
if (mApplicationsAdapter == null || isLaunching || localeChanged) {
mApplications = new ArrayList<ApplicationInfo>(DEFAULT_APPLICATIONS_NUMBER);
mApplicationsAdapter = new ApplicationsAdapter(launcher, mApplications);
}
+ mApplicationsLoaded = false;
+
+ if (!isLaunching) {
+ startApplicationsLoader(launcher);
+ return false;
+ }
+
+ return true;
+ }
+
+ private synchronized void waitForApplicationsLoader() {
if (mApplicationsLoader != null && mApplicationsLoader.isRunning()) {
+ android.util.Log.d("Home", " --> wait for applications loader");
+
mApplicationsLoader.stop();
// Wait for the currently running thread to finish, this can take a little
// time but it should be well below the timeout limit
try {
- mLoader.join(APPLICATION_NOT_RESPONDING_TIMEOUT);
+ mApplicationsLoaderThread.join(APPLICATION_NOT_RESPONDING_TIMEOUT);
} catch (InterruptedException e) {
- // Empty
+ // EMpty
}
}
-
- mApplicationsLoaded = false;
-
- if (!isLaunching) {
- startApplicationsLoader(launcher);
- }
}
- private void startApplicationsLoader(Launcher launcher) {
+ private synchronized void startApplicationsLoader(Launcher launcher) {
+android.util.Log.d("Home", " --> starting applications loader");
+ waitForApplicationsLoader();
+
mApplicationsLoader = new ApplicationsLoader(launcher);
- mLoader = new Thread(mApplicationsLoader, "Applications Loader");
- mLoader.start();
+ mApplicationsLoaderThread = new Thread(mApplicationsLoader, "Applications Loader");
+ mApplicationsLoaderThread.start();
}
private class ApplicationsLoader implements Runnable {
@@ -168,7 +187,7 @@ public class LauncherModel {
final int count = apps.size();
final ApplicationsAdapter applicationList = mApplicationsAdapter;
- final ChangeNotifier action = new ChangeNotifier(applicationList, launcher);
+ ChangeNotifier action = new ChangeNotifier(applicationList, true);
final HashMap<ComponentName, ApplicationInfo> appInfoCache = mAppInfoCache;
for (int i = 0; i < count && !mStopped; i++) {
@@ -194,8 +213,13 @@ public class LauncherModel {
appInfoCache.put(componentName, application);
}
- action.add(application);
+ if (action.add(application)) {
+ launcher.runOnUiThread(action);
+ action = new ChangeNotifier(applicationList, false);
+ }
}
+
+ launcher.runOnUiThread(action);
}
if (!mStopped) {
@@ -207,15 +231,13 @@ public class LauncherModel {
private static class ChangeNotifier implements Runnable, Comparator<ApplicationInfo> {
private final ApplicationsAdapter mApplicationList;
- private final Launcher mLauncher;
private final ArrayList<ApplicationInfo> mBuffer;
- private final Object mLock = new Object();
private boolean mFirst = true;
- ChangeNotifier(ApplicationsAdapter applicationList, Launcher launcher) {
+ ChangeNotifier(ApplicationsAdapter applicationList, boolean first) {
mApplicationList = applicationList;
- mLauncher = launcher;
+ mFirst = first;
mBuffer = new ArrayList<ApplicationInfo>(UI_NOTIFICATION_RATE);
}
@@ -228,30 +250,24 @@ public class LauncherModel {
mFirst = false;
}
- synchronized (mLock) {
- final ArrayList<ApplicationInfo> buffer = mBuffer;
- final int count = buffer.size();
-
- for (int i = 0; i < count; i++) {
- applicationList.setNotifyOnChange(false);
- applicationList.add(buffer.get(i));
- }
+ final ArrayList<ApplicationInfo> buffer = mBuffer;
+ final int count = buffer.size();
- buffer.clear();
+ for (int i = 0; i < count; i++) {
+ applicationList.setNotifyOnChange(false);
+ applicationList.add(buffer.get(i));
}
+ buffer.clear();
+
applicationList.sort(this);
applicationList.notifyDataSetChanged();
}
- synchronized void add(ApplicationInfo application) {
- synchronized (mLock) {
- final ArrayList<ApplicationInfo> buffer = mBuffer;
- buffer.add(application);
- if (buffer.size() >= UI_NOTIFICATION_RATE) {
- mLauncher.runOnUiThread(this);
- }
- }
+ boolean add(ApplicationInfo application) {
+ final ArrayList<ApplicationInfo> buffer = mBuffer;
+ buffer.add(application);
+ return buffer.size() >= UI_NOTIFICATION_RATE;
}
public final int compare(ApplicationInfo a, ApplicationInfo b) {
@@ -269,8 +285,10 @@ public class LauncherModel {
*/
void loadUserItems(boolean isLaunching, Launcher launcher, boolean localeChanged,
boolean loadApplications) {
+android.util.Log.d("Home", "loading user items");
if (isLaunching && isDesktopLoaded()) {
+android.util.Log.d("Home", " --> items loaded, return");
if (loadApplications) startApplicationsLoader(launcher);
// We have already loaded our data from the DB
launcher.onDesktopItemsLoaded();
@@ -282,16 +300,17 @@ public class LauncherModel {
// Wait for the currently running thread to finish, this can take a little
// time but it should be well below the timeout limit
try {
- mDesktopLoader.join(APPLICATION_NOT_RESPONDING_TIMEOUT);
+ mDesktopLoaderThread.join(APPLICATION_NOT_RESPONDING_TIMEOUT);
} catch (InterruptedException e) {
// Empty
}
}
+android.util.Log.d("Home", " --> starting workspace loader");
mDesktopItemsLoaded = false;
mDesktopItemsLoader = new DesktopItemsLoader(launcher, localeChanged, loadApplications);
- mDesktopLoader = new Thread(mDesktopItemsLoader, "Desktop Items Loader");
- mDesktopLoader.start();
+ mDesktopLoaderThread = new Thread(mDesktopItemsLoader, "Desktop Items Loader");
+ mDesktopLoaderThread.start();
}
private static void updateShortcutLabels(ContentResolver resolver, PackageManager manager) {
@@ -745,28 +764,21 @@ public class LauncherModel {
/**
* @return The current list of applications
*/
- public ArrayList<ApplicationInfo> getApplications() {
- return mApplications;
- }
-
- /**
- * @return The current list of applications
- */
- public ApplicationsAdapter getApplicationsAdapter() {
+ ApplicationsAdapter getApplicationsAdapter() {
return mApplicationsAdapter;
}
/**
* @return The current list of desktop items
*/
- public ArrayList<ItemInfo> getDesktopItems() {
+ ArrayList<ItemInfo> getDesktopItems() {
return mDesktopItems;
}
/**
* @return The current list of desktop items
*/
- public ArrayList<LauncherAppWidgetInfo> getDesktopAppWidgets() {
+ ArrayList<LauncherAppWidgetInfo> getDesktopAppWidgets() {
return mDesktopAppWidgets;
}
@@ -774,7 +786,7 @@ public class LauncherModel {
* Add an item to the desktop
* @param info
*/
- public void addDesktopItem(ItemInfo info) {
+ void addDesktopItem(ItemInfo info) {
// TODO: write to DB; also check that folder has been added to folders list
mDesktopItems.add(info);
}
@@ -783,7 +795,7 @@ public class LauncherModel {
* Remove an item from the desktop
* @param info
*/
- public void removeDesktopItem(ItemInfo info) {
+ void removeDesktopItem(ItemInfo info) {
// TODO: write to DB; figure out if we should remove folder from folders list
mDesktopItems.remove(info);
}
@@ -791,14 +803,14 @@ public class LauncherModel {
/**
* Add a widget to the desktop
*/
- public void addDesktopAppWidget(LauncherAppWidgetInfo info) {
+ void addDesktopAppWidget(LauncherAppWidgetInfo info) {
mDesktopAppWidgets.add(info);
}
/**
* Remove a widget from the desktop
*/
- public void removeDesktopAppWidget(LauncherAppWidgetInfo info) {
+ void removeDesktopAppWidget(LauncherAppWidgetInfo info) {
mDesktopAppWidgets.remove(info);
}
diff --git a/src/com/android/launcher/LauncherProvider.java b/src/com/android/launcher/LauncherProvider.java
index 83f185ea4..5cd7a0ff9 100644
--- a/src/com/android/launcher/LauncherProvider.java
+++ b/src/com/android/launcher/LauncherProvider.java
@@ -55,7 +55,7 @@ public class LauncherProvider extends ContentProvider {
private static final String DATABASE_NAME = "launcher.db";
- private static final int DATABASE_VERSION = 2;
+ private static final int DATABASE_VERSION = 3;
static final String AUTHORITY = "com.android.launcher.settings";
@@ -200,7 +200,7 @@ public class LauncherProvider extends ContentProvider {
"spanX INTEGER," +
"spanY INTEGER," +
"itemType INTEGER," +
- "gadgetId INTEGER NOT NULL DEFAULT -1," +
+ "appWidgetId INTEGER NOT NULL DEFAULT -1," +
"isShortcut INTEGER," +
"iconType INTEGER," +
"iconPackage TEXT," +
@@ -320,15 +320,15 @@ public class LauncherProvider extends ContentProvider {
if (LOGD) Log.d(LOG_TAG, "onUpgrade triggered");
int version = oldVersion;
- if (version == 1) {
- // upgrade 1 -> 2 added appWidgetId column
+ if (version < 3) {
+ // upgrade 1,2 -> 3 added appWidgetId column
db.beginTransaction();
try {
// Insert new column for holding appWidgetIds
db.execSQL("ALTER TABLE favorites " +
- "ADD COLUMN gadgetId INTEGER NOT NULL DEFAULT -1;");
+ "ADD COLUMN appWidgetId INTEGER NOT NULL DEFAULT -1;");
db.setTransactionSuccessful();
- version = 2;
+ version = 3;
} catch (SQLException ex) {
// Old version remains, which means we wipe old data
Log.e(LOG_TAG, ex.getMessage(), ex);
@@ -337,7 +337,7 @@ public class LauncherProvider extends ContentProvider {
}
// Convert existing widgets only if table upgrade was successful
- if (version == 2) {
+ if (version == 3) {
convertWidgets(db);
}
}
diff --git a/src/com/android/launcher/LauncherSettings.java b/src/com/android/launcher/LauncherSettings.java
index ed35635e8..60ea0df6a 100644
--- a/src/com/android/launcher/LauncherSettings.java
+++ b/src/com/android/launcher/LauncherSettings.java
@@ -172,7 +172,7 @@ class LauncherSettings {
*
* <P>Type: INTEGER</P>
*/
- static final String APPWIDGET_ID = "gadgetId";
+ static final String APPWIDGET_ID = "appWidgetId";
/**
* Indicates whether this favorite is an application-created shortcut or not.
diff --git a/src/com/android/launcher/Workspace.java b/src/com/android/launcher/Workspace.java
index 8a7baf546..bc5347e7a 100644
--- a/src/com/android/launcher/Workspace.java
+++ b/src/com/android/launcher/Workspace.java
@@ -1195,6 +1195,14 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
public boolean allowLongPress() {
return mAllowLongPress;
}
+
+ /**
+ * Set true to allow long-press events to be triggered, usually checked by
+ * {@link Launcher} to accept or block dpad-initiated long-presses.
+ */
+ public void setAllowLongPress(boolean allowLongPress) {
+ mAllowLongPress = allowLongPress;
+ }
void removeShortcutsForPackage(String packageName) {
final ArrayList<View> childrenToRemove = new ArrayList<View>();