auto import from //branches/cupcake_rel/...@138607
This commit is contained in:
parent
7376faefbb
commit
ca9475f040
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,15 +95,23 @@ 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) {
|
||||
|
@ -110,28 +119,38 @@ public class LauncherModel {
|
|||
mApplicationsAdapter = new ApplicationsAdapter(launcher, mApplications);
|
||||
}
|
||||
|
||||
if (mApplicationsLoader != null && mApplicationsLoader.isRunning()) {
|
||||
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);
|
||||
} catch (InterruptedException e) {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
mApplicationsLoaderThread.join(APPLICATION_NOT_RESPONDING_TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
// EMpty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,10 +213,15 @@ 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) {
|
||||
mApplicationsLoaded = true;
|
||||
}
|
||||
|
@ -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,7 +250,6 @@ public class LauncherModel {
|
|||
mFirst = false;
|
||||
}
|
||||
|
||||
synchronized (mLock) {
|
||||
final ArrayList<ApplicationInfo> buffer = mBuffer;
|
||||
final int count = buffer.size();
|
||||
|
||||
|
@ -238,20 +259,15 @@ public class LauncherModel {
|
|||
}
|
||||
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
applicationList.sort(this);
|
||||
applicationList.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
synchronized void add(ApplicationInfo application) {
|
||||
synchronized (mLock) {
|
||||
boolean add(ApplicationInfo application) {
|
||||
final ArrayList<ApplicationInfo> buffer = mBuffer;
|
||||
buffer.add(application);
|
||||
if (buffer.size() >= UI_NOTIFICATION_RATE) {
|
||||
mLauncher.runOnUiThread(this);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1196,6 +1196,14 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
|
|||
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>();
|
||||
final LauncherModel model = Launcher.getModel();
|
||||
|
|
Loading…
Reference in New Issue