Merge "Defer loading widget previews until after All Apps transition" into jb-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 20c4a9d..dbeb7bc 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -74,7 +74,7 @@
             android:stateNotNeeded="true"
             android:theme="@style/Theme"
             android:windowSoftInputMode="adjustPan"
-            android:screenOrientation="portrait">
+            android:screenOrientation="nosensor">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.HOME" />
diff --git a/res/layout-sw600dp-port/all_apps_cling.xml b/res/layout-sw600dp-port/all_apps_cling.xml
index 8bf8d15..95d7ff2 100644
--- a/res/layout-sw600dp-port/all_apps_cling.xml
+++ b/res/layout-sw600dp-port/all_apps_cling.xml
@@ -41,8 +41,6 @@
     <Button
         style="@style/ClingButton"
         android:id="@+id/cling_dismiss"
-        android:layout_width="118dp"
-        android:layout_height="54dp"
         android:textSize="24sp"
         android:layout_marginBottom="27dp"
         android:layout_marginRight="36dp"
diff --git a/res/layout-sw600dp-port/folder_cling.xml b/res/layout-sw600dp-port/folder_cling.xml
index d154a5b..1b6c1a0 100644
--- a/res/layout-sw600dp-port/folder_cling.xml
+++ b/res/layout-sw600dp-port/folder_cling.xml
@@ -42,8 +42,6 @@
     <Button
         style="@style/ClingButton"
         android:id="@+id/cling_dismiss"
-        android:layout_width="118dp"
-        android:layout_height="54dp"
         android:textSize="24sp"
         android:layout_marginBottom="27dp"
         android:layout_marginRight="36dp"
diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml
index 19d2152..c2b88d5 100644
--- a/res/values-ru/strings.xml
+++ b/res/values-ru/strings.xml
@@ -75,13 +75,13 @@
     <string name="cab_widget_selection_text" msgid="962527270506951955">"Выбран 1 виджет"</string>
     <string name="cab_folder_selection_text" msgid="8916111874189565067">"Выбрана 1 папка"</string>
     <string name="cab_shortcut_selection_text" msgid="8115847384500412878">"Выбран 1 ярлык"</string>
-    <string name="permlab_install_shortcut" msgid="1201690825493376489">"устанавливать ярлыки"</string>
+    <string name="permlab_install_shortcut" msgid="1201690825493376489">"Установка ярлыков"</string>
     <string name="permdesc_install_shortcut" msgid="8634424803272077038">"Приложение сможет самостоятельно добавлять ярлыки."</string>
     <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"удалять ярлыки"</string>
     <string name="permdesc_uninstall_shortcut" msgid="274355570620220977">"Приложение сможет самостоятельно удалять ярлыки."</string>
-    <string name="permlab_read_settings" msgid="3452408290738106747">"считывать настройки и ярлыки главного экрана"</string>
+    <string name="permlab_read_settings" msgid="3452408290738106747">"Просмотр настроек и ярлыков главного экрана"</string>
     <string name="permdesc_read_settings" msgid="5788109303585403679">"Приложение получит доступ к данным о настройках и ярлыках на главном экране."</string>
-    <string name="permlab_write_settings" msgid="1360567537236705628">"изменять настройки и ярлыки главного экрана"</string>
+    <string name="permlab_write_settings" msgid="1360567537236705628">"Изменение настроек и ярлыков главного экрана"</string>
     <string name="permdesc_write_settings" msgid="8530105489115785531">"Приложение сможет изменять настройки и ярлыки на главном экране."</string>
     <string name="gadget_error_text" msgid="8359351016167075858">"Не удалось загрузить виджет"</string>
     <string name="uninstall_system_app_text" msgid="6429814133777046491">"Это системное приложение, его нельзя удалить."</string>
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index f12da7d..ac6ec88 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -549,13 +549,14 @@
         // TODO: this isn't ideal, but we actually need to delay here. This call is triggered
         // by a broadcast receiver, and in order for it to work correctly, we need to know that
         // the AppWidgetService has already received and processed the same broadcast. Since there
-        // is no guarantee about ordering of broadcast receipt, we just delay here. Ideally,
-        // we should have a more precise way of ensuring the AppWidgetService is up to date.
+        // is no guarantee about ordering of broadcast receipt, we just delay here. This is a
+        // workaround until we add a callback from AppWidgetService to AppWidgetHost when widget
+        // packages are added, updated or removed.
         postDelayed(new Runnable() {
            public void run() {
                updatePackages();
            }
-        }, 500);
+        }, 1500);
     }
 
     public void updatePackages() {
@@ -576,6 +577,9 @@
                 if (minSpanX <= LauncherModel.getCellCountX() &&
                         minSpanY <= LauncherModel.getCellCountY()) {
                     mWidgets.add(widget);
+                } else {
+                    Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" +
+                            widget.minWidth + ", " + widget.minHeight + ")");
                 }
             } else {
                 Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" +
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 9cae5e5..fb29a41 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -703,16 +703,24 @@
             if (lahv != null && lahv.orientationChangedSincedInflation()) {
                 AppWidgetProviderInfo pInfo = lahv.getAppWidgetInfo();
 
-                // Remove the current widget which is inflated with the wrong orientation
-                getWorkspace().getParentCellLayoutForView(lahv).removeView(lahv);
-                // Re-inflate the widget using the correct orientation
-                AppWidgetHostView widget = mAppWidgetHost.createView(this, info.appWidgetId, pInfo);
+                Workspace workspace = getWorkspace();
+                CellLayout parent = workspace.getParentCellLayoutForView(lahv);
 
-                // Add the new widget back
-                widget.setTag(info);
-                info.hostView = widget;
-                getWorkspace().addInScreen(widget, info.container, info.screen,
-                        info.cellX, info.cellY, info.spanX, info.spanY);
+                // It's possible this AppWidgetHostView is associated with a prior Launcher instance
+                // in which case it will not have a parent in the current hierarchy (ie. after rotation).
+                //  In this case we will be re-inflating the widgets anyhow, so it's not a problem.
+                if (parent != null) {
+                    // Remove the current widget which is inflated with the wrong orientation
+                    parent.removeView(lahv);
+                    // Re-inflate the widget using the correct orientation
+                    AppWidgetHostView widget = mAppWidgetHost.createView(this, info.appWidgetId, pInfo);
+
+                    // Add the new widget back
+                    widget.setTag(info);
+                    info.hostView = widget;
+                    getWorkspace().addInScreen(widget, info.container, info.screen,
+                            info.cellX, info.cellY, info.spanX, info.spanY);
+                }
             }
         }
     }