Fix locked workspace in Home.

A dialog can be dismissed without being cancelled. This change simply
adds a dismiss listener to the Add dialog in Home to make sure the
workspace is properly unlocked when the dialog is dismissed.
This commit is contained in:
Romain Guy 2009-06-08 15:52:54 -07:00
parent c2e24c0a37
commit cbb89e4fc2
1 changed files with 102 additions and 97 deletions

View File

@ -118,10 +118,10 @@ public final class Launcher extends Activity implements View.OnClickListener, On
static final int SCREEN_COUNT = 3; static final int SCREEN_COUNT = 3;
static final int DEFAULT_SCREN = 1; static final int DEFAULT_SCREN = 1;
static final int NUMBER_CELLS_X = 4; static final int NUMBER_CELLS_X = 4;
static final int NUMBER_CELLS_Y = 4; static final int NUMBER_CELLS_Y = 4;
private static final int DIALOG_CREATE_SHORTCUT = 1; private static final int DIALOG_CREATE_SHORTCUT = 1;
static final int DIALOG_RENAME_FOLDER = 2; static final int DIALOG_RENAME_FOLDER = 2;
private static final String PREFERENCES = "launcher"; private static final String PREFERENCES = "launcher";
private static final String KEY_LOCALE = "locale"; private static final String KEY_LOCALE = "locale";
@ -171,12 +171,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private DragLayer mDragLayer; private DragLayer mDragLayer;
private Workspace mWorkspace; private Workspace mWorkspace;
private AppWidgetManager mAppWidgetManager; private AppWidgetManager mAppWidgetManager;
private LauncherAppWidgetHost mAppWidgetHost; private LauncherAppWidgetHost mAppWidgetHost;
static final int APPWIDGET_HOST_ID = 1024; static final int APPWIDGET_HOST_ID = 1024;
private CellLayout.CellInfo mAddItemCellInfo; private CellLayout.CellInfo mAddItemCellInfo;
private CellLayout.CellInfo mMenuAddInfo; private CellLayout.CellInfo mMenuAddInfo;
private final int[] mCellCoordinates = new int[2]; private final int[] mCellCoordinates = new int[2];
@ -201,17 +201,17 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private Bundle mSavedInstanceState; private Bundle mSavedInstanceState;
private DesktopBinder mBinder; private DesktopBinder mBinder;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mInflater = getLayoutInflater(); mInflater = getLayoutInflater();
mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetManager = AppWidgetManager.getInstance(this);
mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
mAppWidgetHost.startListening(); mAppWidgetHost.startListening();
if (PROFILE_STARTUP) { if (PROFILE_STARTUP) {
android.os.Debug.startMethodTracing("/sdcard/launcher"); android.os.Debug.startMethodTracing("/sdcard/launcher");
} }
@ -240,7 +240,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDefaultKeySsb = new SpannableStringBuilder(); mDefaultKeySsb = new SpannableStringBuilder();
Selection.setSelection(mDefaultKeySsb, 0); Selection.setSelection(mDefaultKeySsb, 0);
} }
private void checkForLocaleChange() { private void checkForLocaleChange() {
final SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE); final SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
final Configuration configuration = getResources().getConfiguration(); final Configuration configuration = getResources().getConfiguration();
@ -304,10 +304,10 @@ public final class Launcher extends Activity implements View.OnClickListener, On
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// The pattern used here is that a user PICKs a specific application, // The pattern used here is that a user PICKs a specific application,
// which, depending on the target, might need to CREATE the actual target. // which, depending on the target, might need to CREATE the actual target.
// For example, the user would PICK_SHORTCUT for "Music playlist", and we // For example, the user would PICK_SHORTCUT for "Music playlist", and we
// launch over to the Music app to actually CREATE_SHORTCUT. // launch over to the Music app to actually CREATE_SHORTCUT.
if (resultCode == RESULT_OK && mAddItemCellInfo != null) { if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
switch (requestCode) { switch (requestCode) {
case REQUEST_PICK_APPLICATION: case REQUEST_PICK_APPLICATION:
@ -358,16 +358,16 @@ public final class Launcher extends Activity implements View.OnClickListener, On
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
closeDrawer(false); closeDrawer(false);
} }
@Override @Override
public Object onRetainNonConfigurationInstance() { public Object onRetainNonConfigurationInstance() {
// Flag any binder to stop early before switching // Flag any binder to stop early before switching
if (mBinder != null) { if (mBinder != null) {
mBinder.mTerminate = true; mBinder.mTerminate = true;
} }
if (PROFILE_ROTATE) { if (PROFILE_ROTATE) {
android.os.Debug.startMethodTracing("/sdcard/launcher-rotate"); android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
} }
@ -388,7 +388,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
keyCode, event); keyCode, event);
if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
// something usable has been typed - start a search // something usable has been typed - start a search
// the typed text will be retrieved and cleared by // the typed text will be retrieved and cleared by
// showSearchDialog() // showSearchDialog()
// If there are multiple keystrokes before the search dialog takes focus, // If there are multiple keystrokes before the search dialog takes focus,
// onSearchRequested() will be called for every keystroke, // onSearchRequested() will be called for every keystroke,
@ -554,15 +554,15 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
Log.e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e); Log.e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e);
} }
if (activityInfo != null) { if (activityInfo != null) {
ApplicationInfo itemInfo = new ApplicationInfo(); ApplicationInfo itemInfo = new ApplicationInfo();
itemInfo.title = activityInfo.loadLabel(packageManager); itemInfo.title = activityInfo.loadLabel(packageManager);
if (itemInfo.title == null) { if (itemInfo.title == null) {
itemInfo.title = activityInfo.name; itemInfo.title = activityInfo.name;
} }
itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK | itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
itemInfo.icon = activityInfo.loadIcon(packageManager); itemInfo.icon = activityInfo.loadIcon(packageManager);
@ -571,7 +571,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mWorkspace.addApplicationShortcut(itemInfo, cellInfo, insertAtFirst); mWorkspace.addApplicationShortcut(itemInfo, cellInfo, insertAtFirst);
} }
} }
/** /**
* Add a shortcut to the workspace. * Add a shortcut to the workspace.
* *
@ -583,7 +583,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
boolean insertAtFirst) { boolean insertAtFirst) {
cellInfo.screen = mWorkspace.getCurrentScreen(); cellInfo.screen = mWorkspace.getCurrentScreen();
if (!findSingleSlot(cellInfo)) return; if (!findSingleSlot(cellInfo)) return;
final ApplicationInfo info = addShortcut(this, data, cellInfo, false); final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
if (!mRestoring) { if (!mRestoring) {
@ -596,7 +596,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} }
} }
/** /**
* Add a widget to the workspace. * Add a widget to the workspace.
* *
@ -608,15 +608,15 @@ public final class Launcher extends Activity implements View.OnClickListener, On
Bundle extras = data.getExtras(); Bundle extras = data.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
d(LOG_TAG, "dumping extras content="+extras.toString()); d(LOG_TAG, "dumping extras content="+extras.toString());
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
// Calculate the grid spans needed to fit this widget // Calculate the grid spans needed to fit this widget
CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight); int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
// Try finding open space on Launcher screen // Try finding open space on Launcher screen
final int[] xy = mCellCoordinates; final int[] xy = mCellCoordinates;
if (!findSlot(cellInfo, xy, spans[0], spans[1])) return; if (!findSlot(cellInfo, xy, spans[0], spans[1])) return;
@ -625,31 +625,31 @@ public final class Launcher extends Activity implements View.OnClickListener, On
LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
launcherInfo.spanX = spans[0]; launcherInfo.spanX = spans[0];
launcherInfo.spanY = spans[1]; launcherInfo.spanY = spans[1];
LauncherModel.addItemToDatabase(this, launcherInfo, LauncherModel.addItemToDatabase(this, launcherInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP, LauncherSettings.Favorites.CONTAINER_DESKTOP,
mWorkspace.getCurrentScreen(), xy[0], xy[1], false); mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
if (!mRestoring) { if (!mRestoring) {
sModel.addDesktopAppWidget(launcherInfo); sModel.addDesktopAppWidget(launcherInfo);
// Perform actual inflation because we're live // Perform actual inflation because we're live
launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
launcherInfo.hostView.setTag(launcherInfo); launcherInfo.hostView.setTag(launcherInfo);
mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1], mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
launcherInfo.spanX, launcherInfo.spanY, insertAtFirst); launcherInfo.spanX, launcherInfo.spanY, insertAtFirst);
} else if (sModel.isDesktopLoaded()) { } else if (sModel.isDesktopLoaded()) {
sModel.addDesktopAppWidget(launcherInfo); sModel.addDesktopAppWidget(launcherInfo);
} }
} }
public LauncherAppWidgetHost getAppWidgetHost() { public LauncherAppWidgetHost getAppWidgetHost() {
return mAppWidgetHost; return mAppWidgetHost;
} }
static ApplicationInfo addShortcut(Context context, Intent data, static ApplicationInfo addShortcut(Context context, Intent data,
CellLayout.CellInfo cellInfo, boolean notify) { CellLayout.CellInfo cellInfo, boolean notify) {
@ -798,7 +798,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDestroyed = true; mDestroyed = true;
super.onDestroy(); super.onDestroy();
try { try {
mAppWidgetHost.stopListening(); mAppWidgetHost.stopListening();
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
@ -823,11 +823,11 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} }
@Override @Override
public void startSearch(String initialQuery, boolean selectInitialQuery, public void startSearch(String initialQuery, boolean selectInitialQuery,
Bundle appSearchData, boolean globalSearch) { Bundle appSearchData, boolean globalSearch) {
closeDrawer(false); closeDrawer(false);
// Slide the search widget to the top, if it's on the current screen, // Slide the search widget to the top, if it's on the current screen,
// otherwise show the search dialog immediately. // otherwise show the search dialog immediately.
Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
@ -839,15 +839,15 @@ public final class Launcher extends Activity implements View.OnClickListener, On
searchWidget.setQuery(getTypedText()); searchWidget.setQuery(getTypedText());
} }
} }
/** /**
* Show the search dialog immediately, without changing the search widget. * Show the search dialog immediately, without changing the search widget.
* *
* @see Activity#startSearch(String, boolean, android.os.Bundle, boolean) * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
*/ */
void showSearchDialog(String initialQuery, boolean selectInitialQuery, void showSearchDialog(String initialQuery, boolean selectInitialQuery,
Bundle appSearchData, boolean globalSearch) { Bundle appSearchData, boolean globalSearch) {
if (initialQuery == null) { if (initialQuery == null) {
// Use any text typed in the launcher as the initial query // Use any text typed in the launcher as the initial query
initialQuery = getTypedText(); initialQuery = getTypedText();
@ -857,7 +857,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
appSearchData = new Bundle(); appSearchData = new Bundle();
appSearchData.putString(SearchManager.SOURCE, "launcher-search"); appSearchData.putString(SearchManager.SOURCE, "launcher-search");
} }
final SearchManager searchManager = final SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE); (SearchManager) getSystemService(Context.SEARCH_SERVICE);
@ -869,12 +869,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On
public void onCancel() { public void onCancel() {
searchManager.setOnCancelListener(null); searchManager.setOnCancelListener(null);
stopSearch(); stopSearch();
} }
}); });
} }
searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
appSearchData, globalSearch); appSearchData, globalSearch);
} }
/** /**
@ -892,7 +892,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
searchWidget.stopSearch(false); searchWidget.stopSearch(false);
} }
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
if (mDesktopLocked) return false; if (mDesktopLocked) return false;
@ -951,7 +951,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
/** /**
* Indicates that we want global search for this activity by setting the globalSearch * Indicates that we want global search for this activity by setting the globalSearch
* argument for {@link #startSearch} to true. * argument for {@link #startSearch} to true.
@ -959,7 +959,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
@Override @Override
public boolean onSearchRequested() { public boolean onSearchRequested() {
startSearch(null, false, null, true); startSearch(null, false, null, true);
return true; return true;
} }
@ -972,7 +972,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mWorkspace.removeShortcutsForPackage(packageName); mWorkspace.removeShortcutsForPackage(packageName);
} }
} }
private void updateShortcutsForPackage(String packageName) { private void updateShortcutsForPackage(String packageName) {
if (packageName != null && packageName.length() > 0) { if (packageName != null && packageName.length() > 0) {
mWorkspace.updateShortcutsForPackage(packageName); mWorkspace.updateShortcutsForPackage(packageName);
@ -1005,26 +1005,26 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} }
} }
} }
void addSearch() { void addSearch() {
final Widget info = Widget.makeSearch(); final Widget info = Widget.makeSearch();
final CellLayout.CellInfo cellInfo = mAddItemCellInfo; final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
final int[] xy = mCellCoordinates; final int[] xy = mCellCoordinates;
final int spanX = info.spanX; final int spanX = info.spanX;
final int spanY = info.spanY; final int spanY = info.spanY;
if (!findSlot(cellInfo, xy, spanX, spanY)) return; if (!findSlot(cellInfo, xy, spanX, spanY)) return;
sModel.addDesktopItem(info); sModel.addDesktopItem(info);
LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
mWorkspace.getCurrentScreen(), xy[0], xy[1], false); mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
final View view = mInflater.inflate(info.layoutResource, null); final View view = mInflater.inflate(info.layoutResource, null);
view.setTag(info); view.setTag(info);
Search search = (Search) view.findViewById(R.id.widget_search); Search search = (Search) view.findViewById(R.id.widget_search);
search.setLauncher(this); search.setLauncher(this);
mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY); mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
} }
@ -1032,11 +1032,11 @@ public final class Launcher extends Activity implements View.OnClickListener, On
// Handle case where user selected "Applications" // Handle case where user selected "Applications"
String applicationName = getResources().getString(R.string.group_applications); String applicationName = getResources().getString(R.string.group_applications);
String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
if (applicationName != null && applicationName.equals(shortcutName)) { if (applicationName != null && applicationName.equals(shortcutName)) {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION); startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION);
@ -1049,7 +1049,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
// Handle case where user selected "Folder" // Handle case where user selected "Folder"
String folderName = getResources().getString(R.string.group_folder); String folderName = getResources().getString(R.string.group_folder);
String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
if (folderName != null && folderName.equals(shortcutName)) { if (folderName != null && folderName.equals(shortcutName)) {
addFolder(!mDesktopLocked); addFolder(!mDesktopLocked);
} else { } else {
@ -1077,7 +1077,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mWorkspace.addInCurrentScreen(newFolder, mWorkspace.addInCurrentScreen(newFolder,
cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst); cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
} }
private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo, private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo,
boolean insertAtFirst) { boolean insertAtFirst) {
cellInfo.screen = mWorkspace.getCurrentScreen(); cellInfo.screen = mWorkspace.getCurrentScreen();
@ -1214,11 +1214,11 @@ public final class Launcher extends Activity implements View.OnClickListener, On
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) { switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_BACK:
mWorkspace.dispatchKeyEvent(event); mWorkspace.dispatchKeyEvent(event);
if (mDrawer.isOpened()) { if (mDrawer.isOpened()) {
closeDrawer(); closeDrawer();
} else { } else {
closeFolder(); closeFolder();
} }
return true; return true;
case KeyEvent.KEYCODE_HOME: case KeyEvent.KEYCODE_HOME:
@ -1276,7 +1276,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
if (mDestroyed) return; if (mDestroyed) return;
bindDesktopItems(); bindDesktopItems();
} }
/** /**
* Refreshes the shortcuts shown on the workspace. * Refreshes the shortcuts shown on the workspace.
*/ */
@ -1293,7 +1293,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
} }
if (DEBUG_USER_INTERFACE) { if (DEBUG_USER_INTERFACE) {
android.widget.Button finishButton = new android.widget.Button(this); android.widget.Button finishButton = new android.widget.Button(this);
finishButton.setText("Finish"); finishButton.setText("Finish");
@ -1305,12 +1305,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} }
}); });
} }
// Flag any old binder to terminate early // Flag any old binder to terminate early
if (mBinder != null) { if (mBinder != null) {
mBinder.mTerminate = true; mBinder.mTerminate = true;
} }
mBinder = new DesktopBinder(this, shortcuts, appWidgets, drawerAdapter); mBinder = new DesktopBinder(this, shortcuts, appWidgets, drawerAdapter);
mBinder.startBindingItems(); mBinder.startBindingItems();
} }
@ -1352,13 +1352,13 @@ public final class Launcher extends Activity implements View.OnClickListener, On
final int screen = workspace.getCurrentScreen(); final int screen = workspace.getCurrentScreen();
final View view = mInflater.inflate(R.layout.widget_search, final View view = mInflater.inflate(R.layout.widget_search,
(ViewGroup) workspace.getChildAt(screen), false); (ViewGroup) workspace.getChildAt(screen), false);
Search search = (Search) view.findViewById(R.id.widget_search); Search search = (Search) view.findViewById(R.id.widget_search);
search.setLauncher(this); search.setLauncher(this);
final Widget widget = (Widget) item; final Widget widget = (Widget) item;
view.setTag(widget); view.setTag(widget);
workspace.addWidget(view, widget, !desktopLocked); workspace.addWidget(view, widget, !desktopLocked);
break; break;
} }
@ -1414,34 +1414,34 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDesktopLocked = false; mDesktopLocked = false;
mDrawer.unlock(); mDrawer.unlock();
} }
private void bindDrawer(Launcher.DesktopBinder binder, private void bindDrawer(Launcher.DesktopBinder binder,
ApplicationsAdapter drawerAdapter) { ApplicationsAdapter drawerAdapter) {
mAllAppsGrid.setAdapter(drawerAdapter); mAllAppsGrid.setAdapter(drawerAdapter);
binder.startBindingAppWidgetsWhenIdle(); binder.startBindingAppWidgetsWhenIdle();
} }
private void bindAppWidgets(Launcher.DesktopBinder binder, private void bindAppWidgets(Launcher.DesktopBinder binder,
LinkedList<LauncherAppWidgetInfo> appWidgets) { LinkedList<LauncherAppWidgetInfo> appWidgets) {
final Workspace workspace = mWorkspace; final Workspace workspace = mWorkspace;
final boolean desktopLocked = mDesktopLocked; final boolean desktopLocked = mDesktopLocked;
if (!appWidgets.isEmpty()) { if (!appWidgets.isEmpty()) {
final LauncherAppWidgetInfo item = appWidgets.removeFirst(); final LauncherAppWidgetInfo item = appWidgets.removeFirst();
final int appWidgetId = item.appWidgetId; final int appWidgetId = item.appWidgetId;
final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo)); if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo));
item.hostView.setAppWidget(appWidgetId, appWidgetInfo); item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
item.hostView.setTag(item); item.hostView.setTag(item);
workspace.addInScreen(item.hostView, item.screen, item.cellX, workspace.addInScreen(item.hostView, item.screen, item.cellX,
item.cellY, item.spanX, item.spanY, !desktopLocked); item.cellY, item.spanX, item.spanY, !desktopLocked);
workspace.requestLayout(); workspace.requestLayout();
} }
@ -1652,7 +1652,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
EditText input = (EditText) dialog.findViewById(R.id.folder_name); EditText input = (EditText) dialog.findViewById(R.id.folder_name);
final CharSequence text = mFolderInfo.title; final CharSequence text = mFolderInfo.title;
input.setText(text); input.setText(text);
input.setSelection(0, text.length()); input.setSelection(0, text.length());
break; break;
} }
} }
@ -1744,22 +1744,23 @@ public final class Launcher extends Activity implements View.OnClickListener, On
* appropriate activity. * appropriate activity.
*/ */
private class CreateShortcut implements DialogInterface.OnClickListener, private class CreateShortcut implements DialogInterface.OnClickListener,
DialogInterface.OnCancelListener { DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
private AddAdapter mAdapter; private AddAdapter mAdapter;
Dialog createDialog() { Dialog createDialog() {
mWaitingForResult = true; mWaitingForResult = true;
mAdapter = new AddAdapter(Launcher.this); mAdapter = new AddAdapter(Launcher.this);
final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
builder.setTitle(getString(R.string.menu_item_add_item)); builder.setTitle(getString(R.string.menu_item_add_item));
builder.setAdapter(mAdapter, this); builder.setAdapter(mAdapter, this);
builder.setInverseBackgroundForced(true); builder.setInverseBackgroundForced(true);
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.setOnCancelListener(this); dialog.setOnCancelListener(this);
dialog.setOnDismissListener(this);
return dialog; return dialog;
} }
@ -1769,6 +1770,10 @@ public final class Launcher extends Activity implements View.OnClickListener, On
cleanup(); cleanup();
} }
public void onDismiss(DialogInterface dialog) {
mWorkspace.unlock();
}
private void cleanup() { private void cleanup() {
mWorkspace.unlock(); mWorkspace.unlock();
dismissDialog(DIALOG_CREATE_SHORTCUT); dismissDialog(DIALOG_CREATE_SHORTCUT);
@ -1780,36 +1785,36 @@ public final class Launcher extends Activity implements View.OnClickListener, On
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Resources res = getResources(); Resources res = getResources();
cleanup(); cleanup();
switch (which) { switch (which) {
case AddAdapter.ITEM_SHORTCUT: { case AddAdapter.ITEM_SHORTCUT: {
// Insert extra item to handle picking application // Insert extra item to handle picking application
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
ArrayList<String> shortcutNames = new ArrayList<String>(); ArrayList<String> shortcutNames = new ArrayList<String>();
shortcutNames.add(res.getString(R.string.group_applications)); shortcutNames.add(res.getString(R.string.group_applications));
bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
ArrayList<ShortcutIconResource> shortcutIcons = ArrayList<ShortcutIconResource> shortcutIcons =
new ArrayList<ShortcutIconResource>(); new ArrayList<ShortcutIconResource>();
shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
R.drawable.ic_launcher_application)); R.drawable.ic_launcher_application));
bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
pickIntent.putExtra(Intent.EXTRA_INTENT, pickIntent.putExtra(Intent.EXTRA_INTENT,
new Intent(Intent.ACTION_CREATE_SHORTCUT)); new Intent(Intent.ACTION_CREATE_SHORTCUT));
pickIntent.putExtra(Intent.EXTRA_TITLE, pickIntent.putExtra(Intent.EXTRA_TITLE,
getText(R.string.title_select_shortcut)); getText(R.string.title_select_shortcut));
pickIntent.putExtras(bundle); pickIntent.putExtras(bundle);
startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT); startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
break; break;
} }
case AddAdapter.ITEM_APPWIDGET: { case AddAdapter.ITEM_APPWIDGET: {
int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
// add the search widget // add the search widget
@ -1832,15 +1837,15 @@ public final class Launcher extends Activity implements View.OnClickListener, On
startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
break; break;
} }
case AddAdapter.ITEM_LIVE_FOLDER: { case AddAdapter.ITEM_LIVE_FOLDER: {
// Insert extra item to handle inserting folder // Insert extra item to handle inserting folder
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
ArrayList<String> shortcutNames = new ArrayList<String>(); ArrayList<String> shortcutNames = new ArrayList<String>();
shortcutNames.add(res.getString(R.string.group_folder)); shortcutNames.add(res.getString(R.string.group_folder));
bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
ArrayList<ShortcutIconResource> shortcutIcons = ArrayList<ShortcutIconResource> shortcutIcons =
new ArrayList<ShortcutIconResource>(); new ArrayList<ShortcutIconResource>();
shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
@ -1853,7 +1858,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
pickIntent.putExtra(Intent.EXTRA_TITLE, pickIntent.putExtra(Intent.EXTRA_TITLE,
getText(R.string.title_select_live_folder)); getText(R.string.title_select_live_folder));
pickIntent.putExtras(bundle); pickIntent.putExtras(bundle);
startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
break; break;
} }
@ -2023,7 +2028,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
static final int MESSAGE_BIND_ITEMS = 0x1; static final int MESSAGE_BIND_ITEMS = 0x1;
static final int MESSAGE_BIND_APPWIDGETS = 0x2; static final int MESSAGE_BIND_APPWIDGETS = 0x2;
static final int MESSAGE_BIND_DRAWER = 0x3; static final int MESSAGE_BIND_DRAWER = 0x3;
// Number of items to bind in every pass // Number of items to bind in every pass
static final int ITEMS_COUNT = 6; static final int ITEMS_COUNT = 6;
@ -2031,7 +2036,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private final LinkedList<LauncherAppWidgetInfo> mAppWidgets; private final LinkedList<LauncherAppWidgetInfo> mAppWidgets;
private final ApplicationsAdapter mDrawerAdapter; private final ApplicationsAdapter mDrawerAdapter;
private final WeakReference<Launcher> mLauncher; private final WeakReference<Launcher> mLauncher;
public boolean mTerminate = false; public boolean mTerminate = false;
DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts, DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts,
@ -2041,12 +2046,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mLauncher = new WeakReference<Launcher>(launcher); mLauncher = new WeakReference<Launcher>(launcher);
mShortcuts = shortcuts; mShortcuts = shortcuts;
mDrawerAdapter = drawerAdapter; mDrawerAdapter = drawerAdapter;
// Sort widgets so active workspace is bound first // Sort widgets so active workspace is bound first
final int currentScreen = launcher.mWorkspace.getCurrentScreen(); final int currentScreen = launcher.mWorkspace.getCurrentScreen();
final int size = appWidgets.size(); final int size = appWidgets.size();
mAppWidgets = new LinkedList<LauncherAppWidgetInfo>(); mAppWidgets = new LinkedList<LauncherAppWidgetInfo>();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
LauncherAppWidgetInfo appWidgetInfo = appWidgets.get(i); LauncherAppWidgetInfo appWidgetInfo = appWidgets.get(i);
if (appWidgetInfo.screen == currentScreen) { if (appWidgetInfo.screen == currentScreen) {
@ -2056,7 +2061,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
} }
} }
} }
public void startBindingItems() { public void startBindingItems() {
obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget(); obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget();
} }
@ -2064,13 +2069,13 @@ public final class Launcher extends Activity implements View.OnClickListener, On
public void startBindingDrawer() { public void startBindingDrawer() {
obtainMessage(MESSAGE_BIND_DRAWER).sendToTarget(); obtainMessage(MESSAGE_BIND_DRAWER).sendToTarget();
} }
public void startBindingAppWidgetsWhenIdle() { public void startBindingAppWidgetsWhenIdle() {
// Ask for notification when message queue becomes idle // Ask for notification when message queue becomes idle
final MessageQueue messageQueue = Looper.myQueue(); final MessageQueue messageQueue = Looper.myQueue();
messageQueue.addIdleHandler(this); messageQueue.addIdleHandler(this);
} }
public boolean queueIdle() { public boolean queueIdle() {
// Queue is idle, so start binding items // Queue is idle, so start binding items
startBindingAppWidgets(); startBindingAppWidgets();
@ -2087,7 +2092,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
if (launcher == null || mTerminate) { if (launcher == null || mTerminate) {
return; return;
} }
switch (msg.what) { switch (msg.what) {
case MESSAGE_BIND_ITEMS: { case MESSAGE_BIND_ITEMS: {
launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2); launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2);