am c5d9527e: am cc9002b1: am 666a30d5: am 63cc80ff: (-s ours) am 1419f206: (-s ours) Reconcile with jb-mr1-release - do not merge

* commit 'c5d9527ef9afcc59e700d3a4f0aa18831c2a9da0':
diff --git a/Android.mk b/Android.mk
index 3519541..8d50bd6 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_STATIC_JAVA_LIBRARIES := android-common android-support-v13
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-LOCAL_SDK_VERSION := current
+LOCAL_SDK_VERSION := 17
 
 LOCAL_PACKAGE_NAME := Launcher2
 LOCAL_CERTIFICATE := shared
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c14b63e..f3ef6c8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -134,7 +134,16 @@
                 <action android:name="android.intent.action.USER_INITIALIZE" />
             </intent-filter>
         </receiver>
-        
+
+        <receiver android:name="com.android.launcher2.PackageChangedReceiver" >
+            <intent-filter>
+                <action android:name="android.intent.action.PACKAGE_CHANGED"/>
+                <action android:name="android.intent.action.PACKAGE_REPLACED"/>
+                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
+                <data android:scheme="package"></data>
+            </intent-filter>
+        </receiver>
+
         <!-- The settings provider contains Home's data, like the workspace favorites -->
         <provider
             android:name="com.android.launcher2.LauncherProvider"
diff --git a/fill_screens.py b/fill_screens.py
index 5841b8e..a887792 100755
--- a/fill_screens.py
+++ b/fill_screens.py
@@ -20,7 +20,7 @@
   "com.android.settings/com.android.settings.Settings",
   "com.android.mms/com.android.mms.ui.ConversationList",
   "com.android.contacts/com.android.contacts.activities.PeopleActivity",
-  "com.android.contacts/com.android.contacts.activities.DialtactsActivity"
+  "com.android.dialer/com.android.dialer.DialtactsActivity"
 ]
 
 def usage():
diff --git a/res/layout-land/all_apps_cling.xml b/res/layout-land/all_apps_cling.xml
index e89d4c1..fccf400 100644
--- a/res/layout-land/all_apps_cling.xml
+++ b/res/layout-land/all_apps_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="40dp"
+        android:layout_marginStart="40dp"
         android:layout_marginTop="40dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -42,7 +42,7 @@
         style="@style/ClingButton"
         android:id="@+id/cling_dismiss"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissAllAppsCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-land/folder_cling.xml b/res/layout-land/folder_cling.xml
index 3d7f4f4..b39fbb1 100644
--- a/res/layout-land/folder_cling.xml
+++ b/res/layout-land/folder_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
+        android:layout_marginStart="20dp"
         android:layout_marginTop="20dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -42,7 +42,7 @@
         style="@style/ClingButton"
         android:id="@+id/cling_dismiss"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissFolderCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-land/hotseat.xml b/res/layout-land/hotseat.xml
index d759196..aebb218 100644
--- a/res/layout-land/hotseat.xml
+++ b/res/layout-land/hotseat.xml
@@ -25,8 +25,8 @@
         android:layout_gravity="center"
         android:paddingTop="@dimen/button_bar_width_left_padding"
         android:paddingBottom="@dimen/button_bar_width_right_padding"
-        android:paddingLeft="@dimen/button_bar_height_top_padding"
-        android:paddingRight="@dimen/button_bar_height_bottom_padding"
+        android:paddingStart="@dimen/button_bar_height_top_padding"
+        android:paddingEnd="@dimen/button_bar_height_bottom_padding"
 
         launcher:cellWidth="@dimen/hotseat_cell_width"
         launcher:cellHeight="@dimen/hotseat_cell_height"
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 051d8b2..8849098 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -35,8 +35,8 @@
             android:id="@+id/workspace"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingLeft="@dimen/workspace_left_padding"
-            android:paddingRight="@dimen/workspace_right_padding"
+            android:paddingStart="@dimen/workspace_left_padding"
+            android:paddingEnd="@dimen/workspace_right_padding"
             android:paddingTop="@dimen/workspace_top_padding"
             android:paddingBottom="@dimen/workspace_bottom_padding"
             launcher:defaultScreen="2"
@@ -58,16 +58,16 @@
             layout="@layout/workspace_divider"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:layout_marginLeft="@dimen/qsb_bar_height"
-            android:layout_gravity="left" />
+            android:layout_marginStart="@dimen/qsb_bar_height"
+            android:layout_gravity="start" />
 
         <include
             android:id="@+id/dock_divider"
             layout="@layout/workspace_divider"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:layout_marginRight="@dimen/button_bar_height"
-            android:layout_gravity="right" />
+            android:layout_marginEnd="@dimen/button_bar_height"
+            android:layout_gravity="end" />
 
         <include
             android:id="@+id/paged_view_indicator"
@@ -80,7 +80,7 @@
             android:id="@+id/hotseat"
             android:layout_width="@dimen/button_bar_height_plus_padding"
             android:layout_height="match_parent"
-            android:layout_gravity="right" />
+            android:layout_gravity="end" />
 
         <include
             android:id="@+id/qsb_bar"
@@ -105,7 +105,7 @@
             android:id="@+id/voice_button_proxy"
             android:layout_width="@dimen/qsb_bar_height"
             android:layout_height="@dimen/app_icon_size"
-            android:layout_gravity="top|left"
+            android:layout_gravity="top|start"
             android:layout_marginTop="64dp"
             android:clickable="true"
             android:onClick="onClickVoiceButton"
diff --git a/res/layout-land/workspace_cling.xml b/res/layout-land/workspace_cling.xml
index b035aa1..43d2a81 100644
--- a/res/layout-land/workspace_cling.xml
+++ b/res/layout-land/workspace_cling.xml
@@ -22,7 +22,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="40dp"
+        android:layout_marginStart="40dp"
         android:layout_marginTop="40dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -44,16 +44,16 @@
         style="@style/ClingText"
         android:layout_width="180dp"
         android:layout_height="wrap_content"
-        android:layout_marginRight="130dp"
-        android:layout_gravity="right|center_vertical"
-        android:gravity="right"
+        android:layout_marginEnd="130dp"
+        android:layout_gravity="end|center_vertical"
+        android:gravity="end"
         android:text="@string/workspace_cling_open_all_apps" />
     <Button
         style="@style/ClingButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissWorkspaceCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-port/all_apps_cling.xml b/res/layout-port/all_apps_cling.xml
index 09414ce..6954fb2 100644
--- a/res/layout-port/all_apps_cling.xml
+++ b/res/layout-port/all_apps_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
+        android:layout_marginStart="20dp"
         android:layout_marginTop="20dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -42,7 +42,7 @@
         style="@style/ClingButton"
         android:id="@+id/cling_dismiss"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissAllAppsCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-port/folder_cling.xml b/res/layout-port/folder_cling.xml
index d2796a0..820675d 100644
--- a/res/layout-port/folder_cling.xml
+++ b/res/layout-port/folder_cling.xml
@@ -20,8 +20,8 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="10dp"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="10dp"
         android:layout_marginTop="@dimen/folderClingMarginTop">
         <LinearLayout
             android:layout_width="match_parent"
@@ -43,7 +43,7 @@
         style="@style/ClingButton"
         android:id="@+id/cling_dismiss"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissFolderCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-port/hotseat.xml b/res/layout-port/hotseat.xml
index 376173a..4ca0bb8 100644
--- a/res/layout-port/hotseat.xml
+++ b/res/layout-port/hotseat.xml
@@ -25,8 +25,8 @@
         android:layout_gravity="center"
         android:paddingTop="@dimen/button_bar_height_top_padding"
         android:paddingBottom="@dimen/button_bar_height_bottom_padding"
-        android:paddingLeft="@dimen/button_bar_width_left_padding"
-        android:paddingRight="@dimen/button_bar_width_right_padding"
+        android:paddingStart="@dimen/button_bar_width_left_padding"
+        android:paddingEnd="@dimen/button_bar_width_right_padding"
 
         launcher:cellWidth="@dimen/hotseat_cell_width"
         launcher:cellHeight="@dimen/hotseat_cell_height"
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index 445c85e..4b45807 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -57,8 +57,8 @@
             android:id="@+id/workspace"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingLeft="@dimen/workspace_left_padding"
-            android:paddingRight="@dimen/workspace_right_padding"
+            android:paddingStart="@dimen/workspace_left_padding"
+            android:paddingEnd="@dimen/workspace_right_padding"
             android:paddingTop="@dimen/workspace_top_padding"
             android:paddingBottom="@dimen/workspace_bottom_padding"
             launcher:defaultScreen="2"
@@ -104,7 +104,7 @@
             android:id="@+id/voice_button_proxy"
             android:layout_width="80dp"
             android:layout_height="@dimen/qsb_bar_height"
-            android:layout_gravity="top|right"
+            android:layout_gravity="top|end"
             android:clickable="true"
             android:onClick="onClickVoiceButton"
             android:importantForAccessibility="no"
diff --git a/res/layout-port/search_bar.xml b/res/layout-port/search_bar.xml
index 8f58fe6..7cf79b8 100644
--- a/res/layout-port/search_bar.xml
+++ b/res/layout-port/search_bar.xml
@@ -29,10 +29,10 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="center_vertical"
-        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
         android:layout_alignParentTop="true"
-        android:layout_toLeftOf="@+id/voice_button_container"
-        android:paddingLeft="8dp"
+        android:layout_toStartOf="@+id/voice_button_container"
+        android:paddingStart="8dp"
         android:onClick="onClickSearchButton"
         android:focusable="true"
         android:clickable="true"
@@ -53,10 +53,10 @@
         android:layout_width="@dimen/search_bar_height"
         android:layout_height="match_parent"
         android:layout_gravity="center_vertical"
-        android:layout_alignParentRight="true"
+        android:layout_alignParentEnd="true"
         android:layout_alignParentTop="true"
-        android:paddingRight="8dp"
-        android:gravity="right"
+        android:paddingEnd="8dp"
+        android:gravity="end"
         android:onClick="onClickVoiceButton"
         android:focusable="true"
         android:clickable="true"
diff --git a/res/layout-port/workspace_cling.xml b/res/layout-port/workspace_cling.xml
index 738e2c5..ca71a3b 100644
--- a/res/layout-port/workspace_cling.xml
+++ b/res/layout-port/workspace_cling.xml
@@ -22,8 +22,8 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="20dp"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="20dp"
         android:layout_marginTop="90dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -45,8 +45,8 @@
         style="@style/ClingText"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="20dp"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="20dp"
         android:layout_marginBottom="130dp"
         android:layout_gravity="bottom"
         android:gravity="center"
@@ -56,7 +56,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissWorkspaceCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-sw600dp-port/all_apps_cling.xml b/res/layout-sw600dp-port/all_apps_cling.xml
index 0498224..fc32c4a 100644
--- a/res/layout-sw600dp-port/all_apps_cling.xml
+++ b/res/layout-sw600dp-port/all_apps_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
+        android:layout_marginStart="20dp"
         android:layout_marginTop="20dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -44,7 +44,7 @@
         android:minWidth="168dp"
         android:textSize="24sp"
         android:layout_marginTop="235dp"
-        android:layout_marginRight="36dp"
-        android:layout_gravity="top|right"
+        android:layout_marginEnd="36dp"
+        android:layout_gravity="top|end"
         android:onClick="dismissAllAppsCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-sw600dp-port/folder_cling.xml b/res/layout-sw600dp-port/folder_cling.xml
index e3a9caa..356bae5 100644
--- a/res/layout-sw600dp-port/folder_cling.xml
+++ b/res/layout-sw600dp-port/folder_cling.xml
@@ -20,8 +20,8 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="10dp"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="10dp"
         android:layout_marginTop="@dimen/folderClingMarginTop">
         <LinearLayout
             android:layout_width="match_parent"
@@ -45,7 +45,7 @@
         android:minWidth="168dp"
         android:textSize="24sp"
         android:layout_marginBottom="27dp"
-        android:layout_marginRight="36dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="36dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissFolderCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout-sw720dp-port/folder_cling.xml b/res/layout-sw720dp-port/folder_cling.xml
index 017d0fd..d4d66dc 100644
--- a/res/layout-sw720dp-port/folder_cling.xml
+++ b/res/layout-sw720dp-port/folder_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="@dimen/cling_text_block_offset_x"
+        android:layout_marginStart="@dimen/cling_text_block_offset_x"
         android:layout_marginTop="@dimen/cling_text_block_offset_y">
         <LinearLayout
             android:layout_width="match_parent"
diff --git a/res/layout-sw720dp/all_apps_cling.xml b/res/layout-sw720dp/all_apps_cling.xml
index 7079b21..d6e19d3 100644
--- a/res/layout-sw720dp/all_apps_cling.xml
+++ b/res/layout-sw720dp/all_apps_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="@dimen/cling_text_block_offset_x"
+        android:layout_marginStart="@dimen/cling_text_block_offset_x"
         android:layout_marginTop="@dimen/cling_text_block_offset_y">
         <LinearLayout
             android:layout_width="match_parent"
diff --git a/res/layout-sw720dp/external_widget_drop_list_item.xml b/res/layout-sw720dp/external_widget_drop_list_item.xml
index a24ad3a..48e333b 100644
--- a/res/layout-sw720dp/external_widget_drop_list_item.xml
+++ b/res/layout-sw720dp/external_widget_drop_list_item.xml
@@ -24,7 +24,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
-        android:layout_marginLeft="20dp"
+        android:layout_marginStart="20dp"
         android:maxWidth="32dp"
         android:maxHeight="32dp"
         android:scaleType="fitCenter"
@@ -33,7 +33,7 @@
         android:id="@+id/provider"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="5dp"
+        android:layout_marginStart="5dp"
         android:gravity="center_vertical"
         android:textSize="18sp" />
 </LinearLayout>
diff --git a/res/layout-sw720dp/folder_cling.xml b/res/layout-sw720dp/folder_cling.xml
index 4188804..f66da7b 100644
--- a/res/layout-sw720dp/folder_cling.xml
+++ b/res/layout-sw720dp/folder_cling.xml
@@ -20,7 +20,7 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="@dimen/cling_text_block_offset_x"
+        android:layout_marginStart="@dimen/cling_text_block_offset_x"
         android:layout_marginTop="@dimen/cling_text_block_offset_y">
         <LinearLayout
             android:layout_width="match_parent"
diff --git a/res/layout-sw720dp/hotseat.xml b/res/layout-sw720dp/hotseat.xml
index bcd5b9d..a8faf36 100644
--- a/res/layout-sw720dp/hotseat.xml
+++ b/res/layout-sw720dp/hotseat.xml
@@ -25,8 +25,8 @@
         android:layout_gravity="center"
         android:paddingTop="@dimen/button_bar_height_top_padding"
         android:paddingBottom="@dimen/button_bar_height_bottom_padding"
-        android:paddingLeft="@dimen/button_bar_width_left_padding"
-        android:paddingRight="@dimen/button_bar_width_right_padding"
+        android:paddingStart="@dimen/button_bar_width_left_padding"
+        android:paddingEnd="@dimen/button_bar_width_right_padding"
 
         launcher:cellWidth="@dimen/hotseat_cell_width"
         launcher:cellHeight="@dimen/hotseat_cell_height"
diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml
index 81a8f37..1fc5322 100644
--- a/res/layout-sw720dp/launcher.xml
+++ b/res/layout-sw720dp/launcher.xml
@@ -57,8 +57,8 @@
             android:id="@+id/workspace"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingLeft="@dimen/workspace_left_padding"
-            android:paddingRight="@dimen/workspace_right_padding"
+            android:paddingStart="@dimen/workspace_left_padding"
+            android:paddingEnd="@dimen/workspace_right_padding"
             android:paddingTop="@dimen/workspace_top_padding"
             android:paddingBottom="@dimen/workspace_bottom_padding"
             launcher:defaultScreen="2"
@@ -104,8 +104,8 @@
             android:id="@+id/voice_button_proxy"
             android:layout_width="80dp"
             android:layout_height="@dimen/qsb_bar_height"
-            android:layout_marginRight="@dimen/qsb_voice_proxy_padding_right"
-            android:layout_gravity="top|right"
+            android:layout_marginEnd="@dimen/qsb_voice_proxy_padding_right"
+            android:layout_gravity="top|end"
             android:clickable="true"
             android:onClick="onClickVoiceButton"
             android:importantForAccessibility="no"
diff --git a/res/layout-sw720dp/market_button.xml b/res/layout-sw720dp/market_button.xml
index 7eaeafa..f1e9959 100644
--- a/res/layout-sw720dp/market_button.xml
+++ b/res/layout-sw720dp/market_button.xml
@@ -18,8 +18,8 @@
     style="@style/MarketButton"
     android:onClick="onClickAppMarketButton"
     android:gravity="center"
-    android:paddingLeft="32dp"
-    android:paddingRight="32dp"
+    android:paddingStart="32dp"
+    android:paddingEnd="32dp"
     android:drawablePadding="10dp"
     android:background="@drawable/tab_widget_indicator_selector"
     android:text="@string/market"
diff --git a/res/layout-sw720dp/search_bar.xml b/res/layout-sw720dp/search_bar.xml
index 8f58fe6..7cf79b8 100644
--- a/res/layout-sw720dp/search_bar.xml
+++ b/res/layout-sw720dp/search_bar.xml
@@ -29,10 +29,10 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="center_vertical"
-        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
         android:layout_alignParentTop="true"
-        android:layout_toLeftOf="@+id/voice_button_container"
-        android:paddingLeft="8dp"
+        android:layout_toStartOf="@+id/voice_button_container"
+        android:paddingStart="8dp"
         android:onClick="onClickSearchButton"
         android:focusable="true"
         android:clickable="true"
@@ -53,10 +53,10 @@
         android:layout_width="@dimen/search_bar_height"
         android:layout_height="match_parent"
         android:layout_gravity="center_vertical"
-        android:layout_alignParentRight="true"
+        android:layout_alignParentEnd="true"
         android:layout_alignParentTop="true"
-        android:paddingRight="8dp"
-        android:gravity="right"
+        android:paddingEnd="8dp"
+        android:gravity="end"
         android:onClick="onClickVoiceButton"
         android:focusable="true"
         android:clickable="true"
diff --git a/res/layout-sw720dp/workspace.xml b/res/layout-sw720dp/workspace.xml
index 5658a4b..bf2abfd 100644
--- a/res/layout-sw720dp/workspace.xml
+++ b/res/layout-sw720dp/workspace.xml
@@ -19,8 +19,8 @@
 <com.android.launcher2.Workspace
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
-    android:paddingLeft="@dimen/workspace_left_padding"
-    android:paddingRight="@dimen/workspace_right_padding"
+    android:paddingStart="@dimen/workspace_left_padding"
+    android:paddingEnd="@dimen/workspace_right_padding"
     android:paddingTop="@dimen/workspace_top_padding"
     android:paddingBottom="@dimen/workspace_bottom_padding"
     launcher:defaultScreen="2"
diff --git a/res/layout-sw720dp/workspace_cling.xml b/res/layout-sw720dp/workspace_cling.xml
index 738e2c5..ca71a3b 100644
--- a/res/layout-sw720dp/workspace_cling.xml
+++ b/res/layout-sw720dp/workspace_cling.xml
@@ -22,8 +22,8 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="20dp"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="20dp"
         android:layout_marginTop="90dp">
         <LinearLayout
             android:layout_width="match_parent"
@@ -45,8 +45,8 @@
         style="@style/ClingText"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="20dp"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="20dp"
         android:layout_marginBottom="130dp"
         android:layout_gravity="bottom"
         android:gravity="center"
@@ -56,7 +56,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginBottom="15dp"
-        android:layout_marginRight="10dp"
-        android:layout_gravity="bottom|right"
+        android:layout_marginEnd="10dp"
+        android:layout_gravity="bottom|end"
         android:onClick="dismissWorkspaceCling" />
 </com.android.launcher2.Cling>
diff --git a/res/layout/add_list_item.xml b/res/layout/add_list_item.xml
index e937d7b..0ae0113 100644
--- a/res/layout/add_list_item.xml
+++ b/res/layout/add_list_item.xml
@@ -21,5 +21,5 @@
     android:textAppearance="?android:attr/textAppearanceLarge"
     android:gravity="center_vertical"
     android:drawablePadding="14dip"
-    android:paddingLeft="15dip"
-    android:paddingRight="15dip" />
+    android:paddingStart="15dip"
+    android:paddingEnd="15dip" />
diff --git a/res/layout/apps_customize_pane.xml b/res/layout/apps_customize_pane.xml
index 41ba9e2..a9d7ded 100644
--- a/res/layout/apps_customize_pane.xml
+++ b/res/layout/apps_customize_pane.xml
@@ -22,8 +22,7 @@
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:visibility="gone"
-        android:layoutDirection="ltr">
+        android:visibility="gone">
         <!-- The layout_width of the tab bar gets overriden to align the content
              with the text in the tabs in AppsCustomizeTabHost. -->
         <FrameLayout
@@ -36,7 +35,8 @@
                 android:id="@android:id/tabs"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:layout_gravity="left"
+                android:layout_gravity="center"
+                android:gravity="start"
                 android:background="@drawable/tab_unselected_holo"
                 android:tabStripEnabled="false"
                 android:divider="@null" />
@@ -45,7 +45,7 @@
                 layout="@layout/market_button"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
-                android:layout_gravity="right" />
+                android:layout_gravity="end" />
         </FrameLayout>
         <FrameLayout
             android:id="@android:id/tabcontent"
diff --git a/res/layout/apps_customize_widget.xml b/res/layout/apps_customize_widget.xml
index abb7508..6bb7943 100644
--- a/res/layout/apps_customize_widget.xml
+++ b/res/layout/apps_customize_widget.xml
@@ -32,8 +32,8 @@
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:paddingTop="@dimen/app_widget_preview_padding_top"
-        android:paddingLeft="@dimen/app_widget_preview_padding_left"
-        android:paddingRight="@dimen/app_widget_preview_padding_right"
+        android:paddingStart="@dimen/app_widget_preview_padding_left"
+        android:paddingEnd="@dimen/app_widget_preview_padding_right"
         android:scaleType="matrix"
         android:background="@drawable/widget_container_holo" />
 
@@ -41,8 +41,8 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="@dimen/app_widget_preview_label_margin_top"
-        android:layout_marginLeft="@dimen/app_widget_preview_label_margin_left"
-        android:layout_marginRight="@dimen/app_widget_preview_label_margin_right"
+        android:layout_marginStart="@dimen/app_widget_preview_label_margin_left"
+        android:layout_marginEnd="@dimen/app_widget_preview_label_margin_right"
         android:orientation="horizontal">
         <!-- The name of the widget. -->
         <TextView xmlns:android="http://schemas.android.com/apk/res/android"
@@ -50,13 +50,14 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="1"
-            android:gravity="left"
+            android:gravity="start"
             android:singleLine="true"
             android:ellipsize="marquee"
             android:fadingEdge="horizontal"
 
             android:textColor="#FFFFFFFF"
-            android:textSize="13sp" />
+            android:textSize="13sp"
+            android:textAlignment="viewStart" />
 
         <!-- The original dimensions of the widget (can't be the same text as above due to different
              style. -->
@@ -65,9 +66,9 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
-            android:layout_marginLeft="5dp"
+            android:layout_marginStart="5dp"
             android:layout_weight="0"
-            android:gravity="left"
+            android:gravity="start"
 
             android:textColor="#FF555555"
             android:textSize="12sp" />
diff --git a/res/layout/appwidget_error.xml b/res/layout/appwidget_error.xml
index 03d4ae4..f5a9148 100644
--- a/res/layout/appwidget_error.xml
+++ b/res/layout/appwidget_error.xml
@@ -19,8 +19,8 @@
     android:layout_height="wrap_content"
     android:paddingTop="10dip"
     android:paddingBottom="10dip"
-    android:paddingLeft="20dip"
-    android:paddingRight="20dip"
+    android:paddingStart="20dip"
+    android:paddingEnd="20dip"
     android:gravity="center"
     android:background="@drawable/bg_appwidget_error"
     android:textAppearance="?android:attr/textAppearanceMediumInverse"
diff --git a/res/layout/custom_workspace_cling.xml b/res/layout/custom_workspace_cling.xml
index 0fdb575..b3e15f5 100644
--- a/res/layout/custom_workspace_cling.xml
+++ b/res/layout/custom_workspace_cling.xml
@@ -26,7 +26,7 @@
         android:textSize="20dp"
         android:textColor="@android:color/holo_blue_light"
         android:text="@string/dummy_custom_cling_error_message"
-        android:gravity="left"
-        android:layout_gravity="bottom|left"
+        android:gravity="start"
+        android:layout_gravity="bottom|start"
     />
 </com.android.launcher2.Cling>
diff --git a/res/layout/drop_target_bar.xml b/res/layout/drop_target_bar.xml
index 5fcddc9..ca3f554 100644
--- a/res/layout/drop_target_bar.xml
+++ b/res/layout/drop_target_bar.xml
@@ -23,7 +23,7 @@
             style="@style/DropTargetButton"
             android:id="@+id/delete_target_text"
             android:text="@string/delete_zone_label_workspace"
-            android:drawableLeft="@drawable/remove_target_selector" />
+            android:drawableStart="@drawable/remove_target_selector" />
     </FrameLayout>
     <FrameLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
@@ -34,6 +34,6 @@
             style="@style/DropTargetButton"
             android:id="@+id/info_target_text"
             android:text="@string/info_target_label"
-            android:drawableLeft="@drawable/info_target_selector" />
+            android:drawableStart="@drawable/info_target_selector" />
     </FrameLayout>
 </merge>
\ No newline at end of file
diff --git a/res/layout/market_button.xml b/res/layout/market_button.xml
index 41e6ec7..4a718c3 100644
--- a/res/layout/market_button.xml
+++ b/res/layout/market_button.xml
@@ -18,8 +18,8 @@
     style="@style/MarketButton"
     android:onClick="onClickAppMarketButton"
     android:gravity="center"
-    android:paddingLeft="16dp"
-    android:paddingRight="16dp"
+    android:paddingStart="16dp"
+    android:paddingEnd="16dp"
     android:background="@drawable/tab_widget_indicator_selector"
     android:contentDescription="@string/market"
     android:shadowColor="@color/workspace_all_apps_and_delete_zone_text_shadow_color"
diff --git a/res/layout/rename_folder.xml b/res/layout/rename_folder.xml
index 75eb504..21a335c 100644
--- a/res/layout/rename_folder.xml
+++ b/res/layout/rename_folder.xml
@@ -25,7 +25,7 @@
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="@string/rename_folder_label"
-        android:gravity="left"
+        android:gravity="start"
         android:textAppearance="?android:attr/textAppearanceMedium" />
             
     <EditText
diff --git a/res/layout/user_folder.xml b/res/layout/user_folder.xml
index af17250..aa4eb1c 100644
--- a/res/layout/user_folder.xml
+++ b/res/layout/user_folder.xml
@@ -26,8 +26,8 @@
         android:id="@+id/folder_content"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:paddingLeft="@dimen/folder_padding"
-        android:paddingRight="@dimen/folder_padding"
+        android:paddingStart="@dimen/folder_padding"
+        android:paddingEnd="@dimen/folder_padding"
         android:paddingTop="@dimen/folder_padding"
         android:paddingBottom="@dimen/folder_padding"
         android:cacheColorHint="#ff333333"
diff --git a/res/layout/workspace_divider.xml b/res/layout/workspace_divider.xml
index c9cbca6..304e532 100644
--- a/res/layout/workspace_divider.xml
+++ b/res/layout/workspace_divider.xml
@@ -15,8 +15,8 @@
 -->
 <ImageView
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:paddingLeft="@dimen/workspace_divider_padding_left"
-    android:paddingRight="@dimen/workspace_divider_padding_right"
+    android:paddingStart="@dimen/workspace_divider_padding_left"
+    android:paddingEnd="@dimen/workspace_divider_padding_right"
     android:paddingTop="@dimen/workspace_divider_padding_top"
     android:paddingBottom="@dimen/workspace_divider_padding_bottom"
     android:scaleType="fitXY"
diff --git a/res/layout/workspace_screen.xml b/res/layout/workspace_screen.xml
index d6e66f6..6538532 100644
--- a/res/layout/workspace_screen.xml
+++ b/res/layout/workspace_screen.xml
@@ -20,8 +20,8 @@
 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
-    android:paddingLeft="@dimen/cell_layout_left_padding"
-    android:paddingRight="@dimen/cell_layout_right_padding"
+    android:paddingStart="@dimen/cell_layout_left_padding"
+    android:paddingEnd="@dimen/cell_layout_right_padding"
     android:paddingTop="@dimen/cell_layout_top_padding"
     android:paddingBottom="@dimen/cell_layout_bottom_padding"
     android:hapticFeedbackEnabled="false"
diff --git a/res/values-ca/strings.xml b/res/values-ca/strings.xml
index dc1f72f..8a0cb9e 100644
--- a/res/values-ca/strings.xml
+++ b/res/values-ca/strings.xml
@@ -93,7 +93,7 @@
     <string name="apps_customize_apps_scroll_format" msgid="5494241912377704885">"Pàgina d\'aplicacions %1$d de %2$d"</string>
     <string name="apps_customize_widgets_scroll_format" msgid="5383009742241717437">"Pàgina de widgets %1$d de %2$d"</string>
     <string name="workspace_cling_title" msgid="738396473989890567">"Personalitza el teu escriptori"</string>
-    <string name="workspace_cling_move_item" msgid="791013895761065070">"Ací pots col·locar les teves aplicacions preferides."</string>
+    <string name="workspace_cling_move_item" msgid="791013895761065070">"Aquí pots col·locar les teves aplicacions preferides."</string>
     <string name="workspace_cling_open_all_apps" msgid="2459977609848572588">"Per veure totes les aplicacions, toca el cercle."</string>
     <string name="all_apps_cling_title" msgid="2559734712581447107">"Tria algunes aplicacions"</string>
     <string name="all_apps_cling_add_item" msgid="5665035103260318891">"Per afegir una aplicació a la pantalla d\'inici, mantén-la premuda."</string>
diff --git a/res/values-cs/strings.xml b/res/values-cs/strings.xml
index dea19f6..1a5aa02 100644
--- a/res/values-cs/strings.xml
+++ b/res/values-cs/strings.xml
@@ -43,7 +43,7 @@
     <string name="group_wallpapers" msgid="1568191644272224858">"Tapety"</string>
     <string name="completely_out_of_space" msgid="1759078539443491182">"Na plochách již není místo."</string>
     <string name="out_of_space" msgid="8365249326091984698">"Na této ploše již není místo."</string>
-    <string name="hotseat_out_of_space" msgid="6304886797358479361">"V části hotseat již není místo."</string>
+    <string name="hotseat_out_of_space" msgid="6304886797358479361">"V sekci hotseat již není místo."</string>
     <string name="invalid_hotseat_item" msgid="6545340627805449250">"Widget je pro hotseat příliš velký."</string>
     <string name="shortcut_installed" msgid="7071557296331322355">"Zástupce <xliff:g id="NAME">%s</xliff:g> byl vytvořen."</string>
     <string name="shortcut_uninstalled" msgid="2129499669449749995">"Zástupce <xliff:g id="NAME">%s</xliff:g> byl odebrán."</string>
diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml
index a049d2e..8e6442c 100644
--- a/res/values-ja/strings.xml
+++ b/res/values-ja/strings.xml
@@ -56,7 +56,7 @@
     <string name="delete_zone_label_all_apps" msgid="6664588234817475108">"アンインストール"</string>
     <string name="delete_target_label" msgid="665300185123139530">"削除"</string>
     <string name="delete_target_uninstall_label" msgid="748894921183769150">"アンインストール"</string>
-    <string name="info_target_label" msgid="4019495079517426980">"アプリケーション情報"</string>
+    <string name="info_target_label" msgid="4019495079517426980">"アプリ情報"</string>
     <string name="accessibility_search_button" msgid="816822994629942611">"検索"</string>
     <string name="accessibility_voice_search_button" msgid="3938249215065842475">"音声検索"</string>
     <string name="accessibility_all_apps_button" msgid="8803738611398979849">"アプリ"</string>
diff --git a/res/values-land/styles.xml b/res/values-land/styles.xml
index 5b9de3e..6c9fd50 100644
--- a/res/values-land/styles.xml
+++ b/res/values-land/styles.xml
@@ -23,7 +23,7 @@
         <item name="android:orientation">vertical</item>
         <item name="android:layout_width">@dimen/qsb_bar_height</item>
         <item name="android:layout_height">match_parent</item>
-        <item name="android:layout_gravity">left</item>
+        <item name="android:layout_gravity">start</item>
     </style>
     <style name="SearchDropTargetBar">
         <item name="android:orientation">vertical</item>
@@ -35,8 +35,8 @@
         <item name="android:layout_gravity">center_horizontal</item>
         <item name="android:paddingTop">@dimen/toolbar_button_vertical_padding</item>
         <item name="android:paddingBottom">@dimen/toolbar_button_vertical_padding</item>
-        <item name="android:paddingLeft">@dimen/toolbar_button_horizontal_padding</item>
-        <item name="android:paddingRight">@dimen/toolbar_button_horizontal_padding</item>
+        <item name="android:paddingStart">@dimen/toolbar_button_horizontal_padding</item>
+        <item name="android:paddingEnd">@dimen/toolbar_button_horizontal_padding</item>
     </style>
     <style name="DropTargetButtonContainer">
         <item name="android:layout_width">match_parent</item>
@@ -49,8 +49,8 @@
         <item name="android:gravity">center</item>
         <item name="android:paddingTop">@dimen/toolbar_button_vertical_padding</item>
         <item name="android:paddingBottom">@dimen/toolbar_button_vertical_padding</item>
-        <item name="android:paddingLeft">@dimen/toolbar_button_horizontal_padding</item>
-        <item name="android:paddingRight">@dimen/toolbar_button_horizontal_padding</item>
+        <item name="android:paddingStart">@dimen/toolbar_button_horizontal_padding</item>
+        <item name="android:paddingEnd">@dimen/toolbar_button_horizontal_padding</item>
         <item name="android:shadowColor">#DD000000</item>
         <item name="android:shadowDx">0.0</item>
         <item name="android:shadowDy">1.0</item>
diff --git a/res/values-sv/strings.xml b/res/values-sv/strings.xml
index 067b5f1..41a3aa3 100644
--- a/res/values-sv/strings.xml
+++ b/res/values-sv/strings.xml
@@ -30,19 +30,19 @@
     <string name="widgets_tab_label" msgid="9145860100000983599">"Widgetar"</string>
     <string name="long_press_widget_to_add" msgid="7395697462851217506">"Tryck länge om du vill flytta en widget."</string>
     <string name="market" msgid="2652226429823445833">"Butik"</string>
-    <string name="external_drop_widget_error" msgid="2285187188524172774">"Objektet kunde inte släppas på den här startsidan."</string>
+    <string name="external_drop_widget_error" msgid="2285187188524172774">"Objektet kunde inte släppas på den här startskärmen."</string>
     <string name="external_drop_widget_pick_title" msgid="7040647073452295370">"Ange vilken widget du vill använda"</string>
     <string name="rename_folder_label" msgid="5646236631298452787">"Mappnamn"</string>
     <string name="rename_folder_title" msgid="4544573104191526550">"Byt namn på mapp"</string>
     <string name="rename_action" msgid="6016003384693240896">"OK"</string>
     <string name="cancel_action" msgid="3811860427489435048">"Avbryt"</string>
-    <string name="menu_item_add_item" msgid="6233177331075781114">"Lägg till på startsidan"</string>
+    <string name="menu_item_add_item" msgid="6233177331075781114">"Lägg till på startskärmen"</string>
     <string name="group_applications" msgid="2103752818818161976">"Appar"</string>
     <string name="group_shortcuts" msgid="9133529424900391877">"Genvägar"</string>
     <string name="group_widgets" msgid="6704978494073105844">"Widgetar"</string>
     <string name="group_wallpapers" msgid="1568191644272224858">"Bakgrundsbilder"</string>
     <string name="completely_out_of_space" msgid="1759078539443491182">"Det finns inte plats för mer på dina startskärmar."</string>
-    <string name="out_of_space" msgid="8365249326091984698">"Det finns inte plats för mer på den här startsidan."</string>
+    <string name="out_of_space" msgid="8365249326091984698">"Det finns inte plats för mer på den här startskärmen."</string>
     <string name="hotseat_out_of_space" msgid="6304886797358479361">"Utrymmet på Hotseat är fullt."</string>
     <string name="invalid_hotseat_item" msgid="6545340627805449250">"Denna widget är för stor för Hotseat."</string>
     <string name="shortcut_installed" msgid="7071557296331322355">"Genvägen \"<xliff:g id="NAME">%s</xliff:g>\" har skapats."</string>
diff --git a/res/values-sw340dp-land/styles.xml b/res/values-sw340dp-land/styles.xml
index 77ce2de..203827d 100644
--- a/res/values-sw340dp-land/styles.xml
+++ b/res/values-sw340dp-land/styles.xml
@@ -23,6 +23,6 @@
         <item name="android:orientation">vertical</item>
         <item name="android:layout_width">@dimen/qsb_bar_height</item>
         <item name="android:layout_height">match_parent</item>
-        <item name="android:layout_gravity">left|center_vertical</item>
+        <item name="android:layout_gravity">start|center_vertical</item>
     </style>
 </resources>
diff --git a/res/values-sw340dp-port/styles.xml b/res/values-sw340dp-port/styles.xml
index b309d85..c9f24b3 100644
--- a/res/values-sw340dp-port/styles.xml
+++ b/res/values-sw340dp-port/styles.xml
@@ -30,13 +30,14 @@
         <item name="android:maxWidth">150dp</item>
     </style>
     <style name="WorkspaceIcon.Portrait.AppsCustomize">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:singleLine">false</item>
         <item name="android:maxLines">2</item>
         <item name="android:background">@null</item>
         <item name="android:paddingTop">4dp</item>
         <item name="android:paddingBottom">0dp</item>
-        <item name="android:paddingLeft">0dp</item>
-        <item name="android:paddingRight">0dp</item>
+        <item name="android:paddingStart">0dp</item>
+        <item name="android:paddingEnd">0dp</item>
         <item name="android:drawablePadding">6dp</item>
     </style>
 </resources>
diff --git a/res/values-sw600dp/styles.xml b/res/values-sw600dp/styles.xml
index 200c0a0..3754304 100644
--- a/res/values-sw600dp/styles.xml
+++ b/res/values-sw600dp/styles.xml
@@ -23,8 +23,8 @@
         <item name="android:layout_height">wrap_content</item>
         <item name="android:paddingTop">10dp</item>
         <item name="android:paddingBottom">15dp</item>
-        <item name="android:paddingLeft">35dp</item>
-        <item name="android:paddingRight">35dp</item>
+        <item name="android:paddingStart">35dp</item>
+        <item name="android:paddingEnd">35dp</item>
         <item name="android:text">@string/cling_dismiss</item>
         <item name="android:textStyle">bold</item>
         <item name="android:background">@drawable/cling_button_bg</item>
diff --git a/res/values-sw720dp/styles.xml b/res/values-sw720dp/styles.xml
index d54c01e..5b24bdf 100644
--- a/res/values-sw720dp/styles.xml
+++ b/res/values-sw720dp/styles.xml
@@ -24,8 +24,8 @@
         <item name="android:layout_height">wrap_content</item>
         <item name="android:paddingTop">10dp</item>
         <item name="android:paddingBottom">15dp</item>
-        <item name="android:paddingLeft">35dp</item>
-        <item name="android:paddingRight">35dp</item>
+        <item name="android:paddingStart">35dp</item>
+        <item name="android:paddingEnd">35dp</item>
         <item name="android:text">@string/cling_dismiss</item>
         <item name="android:textSize">20sp</item>
         <item name="android:textStyle">bold</item>
@@ -53,16 +53,17 @@
 <!-- Workspace -->
     <style name="WorkspaceIcon.Portrait">
         <item name="android:drawablePadding">0dp</item>
-        <item name="android:paddingLeft">4dp</item>
-        <item name="android:paddingRight">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
         <item name="android:paddingTop">@dimen/app_icon_padding_top</item>
         <item name="android:paddingBottom">4dp</item>
         <item name="android:textSize">13sp</item>
     </style>
     <style name="WorkspaceIcon.Portrait.Folder">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:drawablePadding">0dp</item>
-        <item name="android:paddingLeft">4dp</item>
-        <item name="android:paddingRight">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:paddingBottom">0dp</item>
         <item name="android:textSize">13sp</item>
@@ -70,16 +71,17 @@
     </style>
     <style name="WorkspaceIcon.Landscape">
         <item name="android:drawablePadding">0dp</item>
-        <item name="android:paddingLeft">4dp</item>
-        <item name="android:paddingRight">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
         <item name="android:paddingTop">@dimen/app_icon_padding_top</item>
         <item name="android:paddingBottom">4dp</item>
         <item name="android:textSize">13sp</item>
     </style>
     <style name="WorkspaceIcon.Landscape.Folder">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:drawablePadding">0dp</item>
-        <item name="android:paddingLeft">4dp</item>
-        <item name="android:paddingRight">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:paddingBottom">0dp</item>
         <item name="android:textSize">13sp</item>
@@ -95,15 +97,17 @@
     </style>
 
     <style name="WorkspaceIcon.Portrait.AppsCustomize">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:background">@null</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:paddingBottom">0dp</item>
-        <item name="android:paddingLeft">0dp</item>
-        <item name="android:paddingRight">0dp</item>
+        <item name="android:paddingStart">0dp</item>
+        <item name="android:paddingEnd">0dp</item>
         <item name="android:drawablePadding">4dp</item>
         <item name="android:textSize">13sp</item>
     </style>
     <style name="WorkspaceIcon.Landscape.AppsCustomize">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:background">@null</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:paddingBottom">0dp</item>
@@ -111,8 +115,8 @@
         <item name="android:textSize">13sp</item>
     </style>
     <style name="TabIndicator.AppsCustomize">
-        <item name="android:paddingLeft">32dp</item>
-        <item name="android:paddingRight">32dp</item>
+        <item name="android:paddingStart">32dp</item>
+        <item name="android:paddingEnd">32dp</item>
         <item name="android:textSize">14sp</item>
         <item name="android:maxWidth">240dp</item>
     </style>
@@ -123,8 +127,8 @@
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">@dimen/qsb_bar_height</item>
         <item name="android:layout_gravity">top|center_horizontal</item>
-        <item name="android:paddingLeft">@dimen/qsb_padding_left</item>
-        <item name="android:paddingRight">@dimen/qsb_padding_right</item>
+        <item name="android:paddingStart">@dimen/qsb_padding_left</item>
+        <item name="android:paddingEnd">@dimen/qsb_padding_right</item>
     </style>
     <style name="SearchDropTargetBar">
         <item name="android:orientation">horizontal</item>
@@ -147,8 +151,8 @@
         <item name="android:layout_gravity">center</item>
         <item name="android:gravity">center_vertical</item>
         <item name="android:drawablePadding">7.5dp</item>
-        <item name="android:paddingLeft">60dp</item>
-        <item name="android:paddingRight">60dp</item>
+        <item name="android:paddingStart">60dp</item>
+        <item name="android:paddingEnd">60dp</item>
         <item name="android:textColor">#FFFFFFFF</item>
         <item name="android:textSize">16sp</item>
         <item name="android:shadowColor">#393939</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0ea12c4..c0b0fd0 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -46,10 +46,10 @@
          in the Phone UI. [CHAR LIMIT=32] -->
     <string name="market">Shop</string>
     <!-- The format string for the dimensions of a widget in the drawer -->
-    <string name="widget_dims_format" translatable="false">%1$d x %2$d</string>
+    <string name="widget_dims_format" translatable="false">%1$d \u00d7 %2$d</string>
 
     <!-- External-drop widget pick label format string [CHAR_LIMIT=25] -->
-    <string name="external_drop_widget_pick_format" translatable="false">%1$s (%2$d x %3$d)</string>
+    <string name="external_drop_widget_pick_format" translatable="false">%1$s (%2$d \u00d7 %3$d)</string>
     <!-- External-drop widget error string.  This is the error that is shown
          when you drag and item into the homescreen and it is unable to fit,
          or an error is encountered. [CHAR_LIMIT=50] -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index c3fe7ef..872244c 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -29,8 +29,8 @@
         <item name="android:layout_height">wrap_content</item>
         <item name="android:paddingTop">10dp</item>
         <item name="android:paddingBottom">15dp</item>
-        <item name="android:paddingLeft">35dp</item>
-        <item name="android:paddingRight">35dp</item>
+        <item name="android:paddingStart">35dp</item>
+        <item name="android:paddingEnd">35dp</item>
         <item name="android:text">@string/cling_dismiss</item>
         <item name="android:textStyle">bold</item>
         <item name="android:background">@drawable/cling_button_bg</item>
@@ -71,41 +71,45 @@
 
     <style name="WorkspaceIcon.Portrait">
         <item name="android:drawablePadding">@dimen/app_icon_drawable_padding</item>
-        <item name="android:paddingLeft">4dp</item>
-        <item name="android:paddingRight">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
         <item name="android:paddingTop">@dimen/app_icon_padding_top</item>
         <item name="android:paddingBottom">4dp</item>
     </style>
 
     <style name="WorkspaceIcon.Landscape">
         <item name="android:drawablePadding">@dimen/app_icon_drawable_padding_land</item>
-        <item name="android:paddingLeft">4dp</item>
-        <item name="android:paddingRight">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
         <item name="android:paddingTop">@dimen/app_icon_padding_top</item>
         <item name="android:paddingBottom">4dp</item>
     </style>
 
     <style name="WorkspaceIcon.Portrait.Folder">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:drawablePadding">0dp</item>
         <item name="android:paddingTop">@dimen/folder_icon_padding_top</item>
     </style>
     <style name="WorkspaceIcon.Landscape.Folder">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:drawablePadding">0dp</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:layout_marginTop">-2dp</item>
     </style>
 
     <style name="WorkspaceIcon.Portrait.AppsCustomize">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:singleLine">false</item>
         <item name="android:maxLines">2</item>
         <item name="android:background">@null</item>
         <item name="android:paddingTop">0dp</item>
         <item name="android:paddingBottom">0dp</item>
-        <item name="android:paddingLeft">0dp</item>
-        <item name="android:paddingRight">0dp</item>
+        <item name="android:paddingStart">0dp</item>
+        <item name="android:paddingEnd">0dp</item>
         <item name="android:drawablePadding">2dp</item>
     </style>
     <style name="WorkspaceIcon.Landscape.AppsCustomize">
+        <item name="android:shadowRadius">0.0</item> <!-- Don't use text shadow -->
         <item name="android:background">@null</item>
         <item name="android:paddingTop">4dp</item>
         <item name="android:paddingBottom">0dp</item>
@@ -117,8 +121,8 @@
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">@dimen/qsb_bar_height</item>
         <item name="android:layout_gravity">top|center_horizontal</item>
-        <item name="android:paddingLeft">@dimen/qsb_padding_left</item>
-        <item name="android:paddingRight">@dimen/qsb_padding_right</item>
+        <item name="android:paddingStart">@dimen/qsb_padding_left</item>
+        <item name="android:paddingEnd">@dimen/qsb_padding_right</item>
     </style>
     <style name="SearchDropTargetBar">
         <item name="android:orientation">horizontal</item>
@@ -141,8 +145,8 @@
         <item name="android:layout_gravity">center</item>
         <item name="android:gravity">center_vertical</item>
         <item name="android:drawablePadding">7.5dp</item>
-        <item name="android:paddingLeft">25dp</item>
-        <item name="android:paddingRight">25dp</item>
+        <item name="android:paddingStart">25dp</item>
+        <item name="android:paddingEnd">25dp</item>
         <item name="android:textColor">#FFFFFFFF</item>
         <item name="android:textSize">16sp</item>
         <item name="android:singleLine">true</item>
@@ -157,8 +161,8 @@
         <item name="android:layout_width">wrap_content</item>
         <item name="android:layout_height">match_parent</item>
         <item name="android:gravity">center</item>
-        <item name="android:paddingLeft">20dp</item>
-        <item name="android:paddingRight">20dp</item>
+        <item name="android:paddingStart">20dp</item>
+        <item name="android:paddingEnd">20dp</item>
         <item name="android:background">@drawable/tab_widget_indicator_selector</item>
         <item name="android:textColor">?android:attr/textColorPrimary</item>
         <item name="android:textSize">12sp</item>
@@ -172,8 +176,8 @@
     </style>
 
     <style name="MarketButton">
-        <item name="android:paddingLeft">5dp</item>
-        <item name="android:paddingRight">5dp</item>
+        <item name="android:paddingStart">5dp</item>
+        <item name="android:paddingEnd">5dp</item>
         <item name="android:textColor">@color/workspace_all_apps_and_delete_zone_text_color</item>
         <item name="android:textSize">18sp</item>
         <item name="android:shadowColor">@color/workspace_all_apps_and_delete_zone_text_shadow_color</item>
diff --git a/res/xml-sw600dp/default_workspace.xml b/res/xml-sw600dp/default_workspace.xml
index 3afb3b7..0537169 100644
--- a/res/xml-sw600dp/default_workspace.xml
+++ b/res/xml-sw600dp/default_workspace.xml
@@ -61,8 +61,8 @@
 
     <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
     <favorite
-        launcher:packageName="com.android.contacts"
-        launcher:className="com.android.contacts.activities.DialtactsActivity"
+        launcher:packageName="com.android.dialer"
+        launcher:className="com.android.dialer.DialtactsActivity"
         launcher:container="-101"
         launcher:screen="1"
         launcher:x="1"
diff --git a/res/xml/default_workspace.xml b/res/xml/default_workspace.xml
index f2f4240..93338d3 100644
--- a/res/xml/default_workspace.xml
+++ b/res/xml/default_workspace.xml
@@ -61,8 +61,8 @@
 
     <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
     <favorite
-        launcher:packageName="com.android.contacts"
-        launcher:className="com.android.contacts.activities.DialtactsActivity"
+        launcher:packageName="com.android.dialer"
+        launcher:className="com.android.dialer.DialtactsActivity"
         launcher:container="-101"
         launcher:screen="0"
         launcher:x="0"
diff --git a/res/xml/update_workspace.xml b/res/xml/update_workspace.xml
index 44a3f9e..ba35b15 100644
--- a/res/xml/update_workspace.xml
+++ b/res/xml/update_workspace.xml
@@ -19,8 +19,8 @@
          package name. -->
     <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
     <favorite
-        launcher:packageName="com.android.contacts"
-        launcher:className="com.android.contacts.activities.DialtactsActivity"
+        launcher:packageName="com.android.dialer"
+        launcher:className="com.android.dialer.DialtactsActivity"
         launcher:container="-101"
         launcher:screen="0"
         launcher:x="0"
diff --git a/src/com/android/launcher2/AppWidgetResizeFrame.java b/src/com/android/launcher2/AppWidgetResizeFrame.java
index 13ee6f9..0fd39ae 100644
--- a/src/com/android/launcher2/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher2/AppWidgetResizeFrame.java
@@ -96,13 +96,13 @@
         mLeftHandle = new ImageView(context);
         mLeftHandle.setImageResource(R.drawable.widget_resize_handle_left);
         lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 
-                Gravity.LEFT | Gravity.CENTER_VERTICAL);
+                Gravity.START | Gravity.CENTER_VERTICAL);
         addView(mLeftHandle, lp);
 
         mRightHandle = new ImageView(context);
         mRightHandle.setImageResource(R.drawable.widget_resize_handle_right);
         lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 
-                Gravity.RIGHT | Gravity.CENTER_VERTICAL);
+                Gravity.END | Gravity.CENTER_VERTICAL);
         addView(mRightHandle, lp);
 
         mTopHandle = new ImageView(context);
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 4bfeb60..ed834b9 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -30,17 +30,9 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
 import android.graphics.Canvas;
-import android.graphics.ColorMatrix;
-import android.graphics.ColorMatrixColorFilter;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PorterDuff;
+import android.graphics.Point;
 import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.Shader;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.AsyncTask;
 import android.os.Build;
@@ -62,7 +54,6 @@
 import com.android.launcher.R;
 import com.android.launcher2.DropTarget.DragObject;
 
-import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -83,18 +74,8 @@
         LoadWidgetPreviewData
     }
 
-    AsyncTaskPageData(int p, ArrayList<Object> l, ArrayList<Bitmap> si, AsyncTaskCallback bgR,
-            AsyncTaskCallback postR) {
-        page = p;
-        items = l;
-        sourceImages = si;
-        generatedImages = new ArrayList<Bitmap>();
-        maxImageWidth = maxImageHeight = -1;
-        doInBackgroundCallback = bgR;
-        postExecuteCallback = postR;
-    }
     AsyncTaskPageData(int p, ArrayList<Object> l, int cw, int ch, AsyncTaskCallback bgR,
-            AsyncTaskCallback postR) {
+            AsyncTaskCallback postR, WidgetPreviewLoader w) {
         page = p;
         items = l;
         generatedImages = new ArrayList<Bitmap>();
@@ -102,21 +83,14 @@
         maxImageHeight = ch;
         doInBackgroundCallback = bgR;
         postExecuteCallback = postR;
+        widgetPreviewLoader = w;
     }
     void cleanup(boolean cancelled) {
         // Clean up any references to source/generated bitmaps
-        if (sourceImages != null) {
-            if (cancelled) {
-                for (Bitmap b : sourceImages) {
-                    b.recycle();
-                }
-            }
-            sourceImages.clear();
-        }
         if (generatedImages != null) {
             if (cancelled) {
-                for (Bitmap b : generatedImages) {
-                    b.recycle();
+                for (int i = 0; i < generatedImages.size(); i++) {
+                    widgetPreviewLoader.recycleBitmap(items.get(i), generatedImages.get(i));
                 }
             }
             generatedImages.clear();
@@ -130,6 +104,7 @@
     int maxImageHeight;
     AsyncTaskCallback doInBackgroundCallback;
     AsyncTaskCallback postExecuteCallback;
+    WidgetPreviewLoader widgetPreviewLoader;
 }
 
 /**
@@ -167,64 +142,6 @@
     int threadPriority;
 }
 
-abstract class WeakReferenceThreadLocal<T> {
-    private ThreadLocal<WeakReference<T>> mThreadLocal;
-    public WeakReferenceThreadLocal() {
-        mThreadLocal = new ThreadLocal<WeakReference<T>>();
-    }
-
-    abstract T initialValue();
-
-    public void set(T t) {
-        mThreadLocal.set(new WeakReference<T>(t));
-    }
-
-    public T get() {
-        WeakReference<T> reference = mThreadLocal.get();
-        T obj;
-        if (reference == null) {
-            obj = initialValue();
-            mThreadLocal.set(new WeakReference<T>(obj));
-            return obj;
-        } else {
-            obj = reference.get();
-            if (obj == null) {
-                obj = initialValue();
-                mThreadLocal.set(new WeakReference<T>(obj));
-            }
-            return obj;
-        }
-    }
-}
-
-class CanvasCache extends WeakReferenceThreadLocal<Canvas> {
-    @Override
-    protected Canvas initialValue() {
-        return new Canvas();
-    }
-}
-
-class PaintCache extends WeakReferenceThreadLocal<Paint> {
-    @Override
-    protected Paint initialValue() {
-        return null;
-    }
-}
-
-class BitmapCache extends WeakReferenceThreadLocal<Bitmap> {
-    @Override
-    protected Bitmap initialValue() {
-        return null;
-    }
-}
-
-class RectCache extends WeakReferenceThreadLocal<Rect> {
-    @Override
-    protected Rect initialValue() {
-        return new Rect();
-    }
-}
-
 /**
  * The Apps/Customize page that displays all the applications, widgets, and shortcuts.
  */
@@ -267,11 +184,9 @@
 
     // Dimens
     private int mContentWidth;
-    private int mAppIconSize;
     private int mMaxAppCellCountX, mMaxAppCellCountY;
     private int mWidgetCountX, mWidgetCountY;
     private int mWidgetWidthGap, mWidgetHeightGap;
-    private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
     private PagedViewCellLayout mWidgetSpacingLayout;
     private int mNumAppsPages;
     private int mNumWidgetPages;
@@ -323,6 +238,8 @@
     RectCache mCachedAppWidgetPreviewDestRect = new RectCache();
     PaintCache mCachedAppWidgetPreviewPaint = new PaintCache();
 
+    WidgetPreviewLoader mWidgetPreviewLoader;
+
     public AppsCustomizePagedView(Context context, AttributeSet attrs) {
         super(context, attrs);
         mLayoutInflater = LayoutInflater.from(context);
@@ -334,9 +251,6 @@
         mRunningTasks = new ArrayList<AppsCustomizeAsyncTask>();
 
         // Save the default widget preview background
-        Resources resources = context.getResources();
-        mAppIconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size);
-
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0);
         mMaxAppCellCountX = a.getInt(R.styleable.AppsCustomizePagedView_maxAppCellCountX, -1);
         mMaxAppCellCountY = a.getInt(R.styleable.AppsCustomizePagedView_maxAppCellCountY, -1);
@@ -434,6 +348,10 @@
     }
 
     protected void onDataReady(int width, int height) {
+        if (mWidgetPreviewLoader == null) {
+            mWidgetPreviewLoader = new WidgetPreviewLoader(mLauncher);
+        }
+
         // Note that we transpose the counts in portrait so that we get a similar layout
         boolean isLandscape = getResources().getConfiguration().orientation ==
             Configuration.ORIENTATION_LANDSCAPE;
@@ -769,6 +687,8 @@
         Bitmap preview;
         Bitmap outline;
         float scale = 1f;
+        Point previewPadding = null;
+
         if (createItemInfo instanceof PendingAddWidgetInfo) {
             // This can happen in some weird cases involving multi-touch. We can't start dragging
             // the widget if this is null, so we break out.
@@ -788,19 +708,25 @@
             int maxWidth, maxHeight;
             maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
             maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);
-            preview = getWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage,
-                    createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight);
 
-            // Determine the image view drawable scale relative to the preview
-            float[] mv = new float[9];
-            Matrix m = new Matrix();
-            m.setRectToRect(
-                    new RectF(0f, 0f, (float) preview.getWidth(), (float) preview.getHeight()),
-                    new RectF(0f, 0f, (float) previewDrawable.getIntrinsicWidth(),
-                            (float) previewDrawable.getIntrinsicHeight()),
-                    Matrix.ScaleToFit.START);
-            m.getValues(mv);
-            scale = (float) mv[0];
+            int[] previewSizeBeforeScale = new int[1];
+
+            preview = mWidgetPreviewLoader.generateWidgetPreview(createWidgetInfo.componentName,
+                    createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY,
+                    maxWidth, maxHeight, null, previewSizeBeforeScale);
+
+            // Compare the size of the drag preview to the preview in the AppsCustomize tray
+            int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0],
+                    mWidgetPreviewLoader.maxWidthForWidgetPreview(spanX));
+            scale = previewWidthInAppsCustomize / (float) preview.getWidth();
+
+            // The bitmap in the AppsCustomize tray is always the the same size, so there
+            // might be extra pixels around the preview itself - this accounts for that
+            if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) {
+                int padding =
+                        (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2;
+                previewPadding = new Point(padding, 0);
+            }
         } else {
             PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
             Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
@@ -809,7 +735,7 @@
 
             mCanvas.setBitmap(preview);
             mCanvas.save();
-            renderDrawableToBitmap(icon, preview, 0, 0,
+            WidgetPreviewLoader.renderDrawableToBitmap(icon, preview, 0, 0,
                     icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
             mCanvas.restore();
             mCanvas.setBitmap(null);
@@ -828,7 +754,7 @@
         mLauncher.lockScreenOrientation();
         mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
         mDragController.startDrag(image, preview, this, createItemInfo,
-                DragController.DRAG_ACTION_COPY, null, scale);
+                DragController.DRAG_ACTION_COPY, previewPadding, scale);
         outline.recycle();
         preview.recycle();
         return true;
@@ -968,6 +894,9 @@
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         cancelAllTasks();
+        if (mWidgetPreviewLoader != null) {
+            mWidgetPreviewLoader.closeDb();
+        }
     }
 
     public void clearAllWidgetPages() {
@@ -1099,7 +1028,7 @@
             images.add(info.iconBitmap);
         }
 
-        layout.createHardwareLayers();
+        enableHwLayersOnVisiblePages();
     }
 
     /**
@@ -1190,7 +1119,7 @@
                     // do cleanup inside onSyncWidgetPageItems
                     onSyncWidgetPageItems(data);
                 }
-            });
+            }, mWidgetPreviewLoader);
 
         // Ensure that the task is appropriately prioritized and runs in parallel
         AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page,
@@ -1215,181 +1144,6 @@
         layout.measure(widthSpec, heightSpec);
     }
 
-    private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
-        renderDrawableToBitmap(d, bitmap, x, y, w, h, 1f);
-    }
-
-    private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
-            float scale) {
-        if (bitmap != null) {
-            Canvas c = new Canvas(bitmap);
-            c.scale(scale, scale);
-            Rect oldBounds = d.copyBounds();
-            d.setBounds(x, y, x + w, y + h);
-            d.draw(c);
-            d.setBounds(oldBounds); // Restore the bounds
-            c.setBitmap(null);
-        }
-    }
-
-    private Bitmap getShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight) {
-        Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
-        final Canvas c = mCachedShortcutPreviewCanvas.get();
-        if (tempBitmap == null ||
-                tempBitmap.getWidth() != maxWidth ||
-                tempBitmap.getHeight() != maxHeight) {
-            tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
-            mCachedShortcutPreviewBitmap.set(tempBitmap);
-        } else {
-            c.setBitmap(tempBitmap);
-            c.drawColor(0, PorterDuff.Mode.CLEAR);
-            c.setBitmap(null);
-        }
-        // Render the icon
-        Drawable icon = mIconCache.getFullResIcon(info);
-
-        int paddingTop =
-                getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
-        int paddingLeft =
-                getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
-        int paddingRight =
-                getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
-
-        int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
-
-        renderDrawableToBitmap(
-                icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
-
-        Bitmap preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
-        c.setBitmap(preview);
-        Paint p = mCachedShortcutPreviewPaint.get();
-        if (p == null) {
-            p = new Paint();
-            ColorMatrix colorMatrix = new ColorMatrix();
-            colorMatrix.setSaturation(0);
-            p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
-            p.setAlpha((int) (255 * 0.06f));
-            //float density = 1f;
-            //p.setMaskFilter(new BlurMaskFilter(15*density, BlurMaskFilter.Blur.NORMAL));
-            mCachedShortcutPreviewPaint.set(p);
-        }
-        c.drawBitmap(tempBitmap, 0, 0, p);
-        c.setBitmap(null);
-
-        renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
-
-        return preview;
-    }
-
-    private Bitmap getWidgetPreview(ComponentName provider, int previewImage,
-            int iconId, int cellHSpan, int cellVSpan, int maxWidth,
-            int maxHeight) {
-        // Load the preview image if possible
-        String packageName = provider.getPackageName();
-        if (maxWidth < 0) maxWidth = Integer.MAX_VALUE;
-        if (maxHeight < 0) maxHeight = Integer.MAX_VALUE;
-
-        Drawable drawable = null;
-        if (previewImage != 0) {
-            drawable = mPackageManager.getDrawable(packageName, previewImage, null);
-            if (drawable == null) {
-                Log.w(TAG, "Can't load widget preview drawable 0x" +
-                        Integer.toHexString(previewImage) + " for provider: " + provider);
-            }
-        }
-
-        int bitmapWidth;
-        int bitmapHeight;
-        Bitmap defaultPreview = null;
-        boolean widgetPreviewExists = (drawable != null);
-        if (widgetPreviewExists) {
-            bitmapWidth = drawable.getIntrinsicWidth();
-            bitmapHeight = drawable.getIntrinsicHeight();
-        } else {
-            // Generate a preview image if we couldn't load one
-            if (cellHSpan < 1) cellHSpan = 1;
-            if (cellVSpan < 1) cellVSpan = 1;
-
-            BitmapDrawable previewDrawable = (BitmapDrawable) getResources()
-                    .getDrawable(R.drawable.widget_preview_tile);
-            final int previewDrawableWidth = previewDrawable
-                    .getIntrinsicWidth();
-            final int previewDrawableHeight = previewDrawable
-                    .getIntrinsicHeight();
-            bitmapWidth = previewDrawableWidth * cellHSpan; // subtract 2 dips
-            bitmapHeight = previewDrawableHeight * cellVSpan;
-
-            defaultPreview = Bitmap.createBitmap(bitmapWidth, bitmapHeight,
-                    Config.ARGB_8888);
-            final Canvas c = mCachedAppWidgetPreviewCanvas.get();
-            c.setBitmap(defaultPreview);
-            previewDrawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
-            previewDrawable.setTileModeXY(Shader.TileMode.REPEAT,
-                    Shader.TileMode.REPEAT);
-            previewDrawable.draw(c);
-            c.setBitmap(null);
-
-            // Draw the icon in the top left corner
-            int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
-            int smallestSide = Math.min(bitmapWidth, bitmapHeight);
-            float iconScale = Math.min((float) smallestSide
-                    / (mAppIconSize + 2 * minOffset), 1f);
-
-            try {
-                Drawable icon = null;
-                int hoffset =
-                        (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2);
-                int yoffset =
-                        (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
-                if (iconId > 0)
-                    icon = mIconCache.getFullResIcon(packageName, iconId);
-                if (icon != null) {
-                    renderDrawableToBitmap(icon, defaultPreview, hoffset,
-                            yoffset, (int) (mAppIconSize * iconScale),
-                            (int) (mAppIconSize * iconScale));
-                }
-            } catch (Resources.NotFoundException e) {
-            }
-        }
-
-        // Scale to fit width only - let the widget preview be clipped in the
-        // vertical dimension
-        float scale = 1f;
-        if (bitmapWidth > maxWidth) {
-            scale = maxWidth / (float) bitmapWidth;
-        }
-        if (scale != 1f) {
-            bitmapWidth = (int) (scale * bitmapWidth);
-            bitmapHeight = (int) (scale * bitmapHeight);
-        }
-
-        Bitmap preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight,
-                Config.ARGB_8888);
-
-        // Draw the scaled preview into the final bitmap
-        if (widgetPreviewExists) {
-            renderDrawableToBitmap(drawable, preview, 0, 0, bitmapWidth,
-                    bitmapHeight);
-        } else {
-            final Canvas c = mCachedAppWidgetPreviewCanvas.get();
-            final Rect src = mCachedAppWidgetPreviewSrcRect.get();
-            final Rect dest = mCachedAppWidgetPreviewDestRect.get();
-            c.setBitmap(preview);
-            src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight());
-            dest.set(0, 0, preview.getWidth(), preview.getHeight());
-
-            Paint p = mCachedAppWidgetPreviewPaint.get();
-            if (p == null) {
-                p = new Paint();
-                p.setFilterBitmap(true);
-                mCachedAppWidgetPreviewPaint.set(p);
-            }
-            c.drawBitmap(defaultPreview, src, dest, p);
-            c.setBitmap(null);
-        }
-        return preview;
-    }
-
     public void syncWidgetPageItems(final int page, final boolean immediate) {
         int numItemsPerPage = mWidgetCountX * mWidgetCountY;
 
@@ -1429,7 +1183,7 @@
                 createItemInfo.minSpanX = minSpanXY[0];
                 createItemInfo.minSpanY = minSpanXY[1];
 
-                widget.applyFromAppWidgetProviderInfo(info, -1, spanXY);
+                widget.applyFromAppWidgetProviderInfo(info, -1, spanXY, mWidgetPreviewLoader);
                 widget.setTag(createItemInfo);
                 widget.setShortPressListener(this);
             } else if (rawInfo instanceof ResolveInfo) {
@@ -1439,7 +1193,7 @@
                 createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
                 createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
                         info.activityInfo.name);
-                widget.applyFromResolveInfo(mPackageManager, info);
+                widget.applyFromResolveInfo(mPackageManager, info, mWidgetPreviewLoader);
                 widget.setTag(createItemInfo);
             }
             widget.setOnClickListener(this);
@@ -1451,11 +1205,11 @@
             int ix = i % mWidgetCountX;
             int iy = i / mWidgetCountX;
             GridLayout.LayoutParams lp = new GridLayout.LayoutParams(
-                    GridLayout.spec(iy, GridLayout.LEFT),
+                    GridLayout.spec(iy, GridLayout.START),
                     GridLayout.spec(ix, GridLayout.TOP));
             lp.width = cellWidth;
             lp.height = cellHeight;
-            lp.setGravity(Gravity.TOP | Gravity.LEFT);
+            lp.setGravity(Gravity.TOP | Gravity.START);
             if (ix > 0) lp.leftMargin = mWidgetWidthGap;
             if (iy > 0) lp.topMargin = mWidgetHeightGap;
             layout.addView(widget, lp);
@@ -1475,9 +1229,12 @@
                     maxPreviewWidth = maxSize[0];
                     maxPreviewHeight = maxSize[1];
                 }
+
+                mWidgetPreviewLoader.setPreviewSize(
+                        maxPreviewWidth, maxPreviewHeight, mWidgetSpacingLayout);
                 if (immediate) {
                     AsyncTaskPageData data = new AsyncTaskPageData(page, items,
-                            maxPreviewWidth, maxPreviewHeight, null, null);
+                            maxPreviewWidth, maxPreviewHeight, null, null, mWidgetPreviewLoader);
                     loadWidgetPreviewsInBackground(null, data);
                     onSyncWidgetPageItems(data);
                 } else {
@@ -1488,6 +1245,7 @@
                                 maxPreviewWidth, maxPreviewHeight, mWidgetCountX);
                     }
                 }
+                layout.setOnLayoutListener(null);
             }
         });
     }
@@ -1513,23 +1271,7 @@
                 task.syncThreadPriority();
             }
 
-            Object rawInfo = items.get(i);
-            if (rawInfo instanceof AppWidgetProviderInfo) {
-                AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
-                int[] cellSpans = Launcher.getSpanForWidget(mLauncher, info);
-
-                int maxWidth = Math.min(data.maxImageWidth,
-                        mWidgetSpacingLayout.estimateCellWidth(cellSpans[0]));
-                int maxHeight = Math.min(data.maxImageHeight,
-                        mWidgetSpacingLayout.estimateCellHeight(cellSpans[1]));
-                Bitmap b = getWidgetPreview(info.provider, info.previewImage, info.icon,
-                        cellSpans[0], cellSpans[1], maxWidth, maxHeight);
-                images.add(b);
-            } else if (rawInfo instanceof ResolveInfo) {
-                // Fill in the shortcuts information
-                ResolveInfo info = (ResolveInfo) rawInfo;
-                images.add(getShortcutPreview(info, data.maxImageWidth, data.maxImageHeight));
-            }
+            images.add(mWidgetPreviewLoader.getPreview(items.get(i)));
         }
     }
 
@@ -1552,8 +1294,7 @@
                 }
             }
 
-            layout.createHardwareLayer();
-            invalidate();
+            enableHwLayersOnVisiblePages();
 
             // Update all thread priorities
             Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
@@ -1611,6 +1352,7 @@
     // In apps customize, we have a scrolling effect which emulates pulling cards off of a stack.
     @Override
     protected void screenScrolled(int screenCenter) {
+        final boolean isRtl = isLayoutRtl();
         super.screenScrolled(screenCenter);
 
         for (int i = 0; i < getChildCount(); i++) {
@@ -1618,19 +1360,28 @@
             if (v != null) {
                 float scrollProgress = getScrollProgress(screenCenter, v, i);
 
-                float interpolatedProgress =
-                        mZInterpolator.getInterpolation(Math.abs(Math.min(scrollProgress, 0)));
+                float interpolatedProgress;
+                float translationX;
+                float maxScrollProgress = Math.max(0, scrollProgress);
+                float minScrollProgress = Math.min(0, scrollProgress);
+
+                if (isRtl) {
+                    translationX = maxScrollProgress * v.getMeasuredWidth();
+                    interpolatedProgress = mZInterpolator.getInterpolation(Math.abs(maxScrollProgress));
+                } else {
+                    translationX = minScrollProgress * v.getMeasuredWidth();
+                    interpolatedProgress = mZInterpolator.getInterpolation(Math.abs(minScrollProgress));
+                }
                 float scale = (1 - interpolatedProgress) +
                         interpolatedProgress * TRANSITION_SCALE_FACTOR;
-                float translationX = Math.min(0, scrollProgress) * v.getMeasuredWidth();
 
                 float alpha;
-
-                if (scrollProgress < 0) {
-                    alpha = scrollProgress < 0 ? mAlphaInterpolator.getInterpolation(
-                        1 - Math.abs(scrollProgress)) : 1.0f;
+                if (isRtl && (scrollProgress > 0)) {
+                    alpha = mAlphaInterpolator.getInterpolation(1 - Math.abs(maxScrollProgress));
+                } else if (!isRtl && (scrollProgress < 0)) {
+                    alpha = mAlphaInterpolator.getInterpolation(1 - Math.abs(scrollProgress));
                 } else {
-                    // On large screens we need to fade the page as it nears its leftmost position
+                    //  On large screens we need to fade the page as it nears its leftmost position
                     alpha = mLeftScreenAlphaInterpolator.getInterpolation(1 - scrollProgress);
                 }
 
@@ -1639,17 +1390,21 @@
                 int pageHeight = v.getMeasuredHeight();
 
                 if (PERFORM_OVERSCROLL_ROTATION) {
-                    if (i == 0 && scrollProgress < 0) {
+                    float xPivot = isRtl ? 1f - TRANSITION_PIVOT : TRANSITION_PIVOT;
+                    boolean isOverscrollingFirstPage = isRtl ? scrollProgress > 0 : scrollProgress < 0;
+                    boolean isOverscrollingLastPage = isRtl ? scrollProgress < 0 : scrollProgress > 0;
+
+                    if (i == 0 && isOverscrollingFirstPage) {
                         // Overscroll to the left
-                        v.setPivotX(TRANSITION_PIVOT * pageWidth);
+                        v.setPivotX(xPivot * pageWidth);
                         v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                         scale = 1.0f;
                         alpha = 1.0f;
                         // On the first page, we don't want the page to have any lateral motion
                         translationX = 0;
-                    } else if (i == getChildCount() - 1 && scrollProgress > 0) {
+                    } else if (i == getChildCount() - 1 && isOverscrollingLastPage) {
                         // Overscroll to the right
-                        v.setPivotX((1 - TRANSITION_PIVOT) * pageWidth);
+                        v.setPivotX((1 - xPivot) * pageWidth);
                         v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                         scale = 1.0f;
                         alpha = 1.0f;
@@ -1676,6 +1431,48 @@
                 }
             }
         }
+
+        enableHwLayersOnVisiblePages();
+    }
+
+    private void enableHwLayersOnVisiblePages() {
+        final int screenCount = getChildCount();
+
+        getVisiblePages(mTempVisiblePagesRange);
+        int leftScreen = mTempVisiblePagesRange[0];
+        int rightScreen = mTempVisiblePagesRange[1];
+        int forceDrawScreen = -1;
+        if (leftScreen == rightScreen) {
+            // make sure we're caching at least two pages always
+            if (rightScreen < screenCount - 1) {
+                rightScreen++;
+                forceDrawScreen = rightScreen;
+            } else if (leftScreen > 0) {
+                leftScreen--;
+                forceDrawScreen = leftScreen;
+            }
+        } else {
+            forceDrawScreen = leftScreen + 1;
+        }
+
+        for (int i = 0; i < screenCount; i++) {
+            final View layout = (View) getPageAt(i);
+            if (!(leftScreen <= i && i <= rightScreen &&
+                    (i == forceDrawScreen || shouldDrawChild(layout)))) {
+                layout.setLayerType(LAYER_TYPE_NONE, null);
+            }
+        }
+
+        for (int i = 0; i < screenCount; i++) {
+            final View layout = (View) getPageAt(i);
+
+            if (leftScreen <= i && i <= rightScreen &&
+                    (i == forceDrawScreen || shouldDrawChild(layout))) {
+                if (layout.getLayerType() != LAYER_TYPE_HARDWARE) {
+                    layout.setLayerType(LAYER_TYPE_HARDWARE, null);
+                }
+            }
+        }
     }
 
     protected void overScroll(float amount) {
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index 5eb8483..27ceaba 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -264,15 +264,19 @@
                 // Animate the transition
                 ObjectAnimator outAnim = LauncherAnimUtils.ofFloat(mAnimationBuffer, "alpha", 0f);
                 outAnim.addListener(new AnimatorListenerAdapter() {
+                    private void clearAnimationBuffer() {
+                        mAnimationBuffer.setVisibility(View.GONE);
+                        PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(false);
+                        mAnimationBuffer.removeAllViews();
+                        PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(true);
+                    }
                     @Override
                     public void onAnimationEnd(Animator animation) {
-                        mAnimationBuffer.setVisibility(View.GONE);
-                        mAnimationBuffer.removeAllViews();
+                        clearAnimationBuffer();
                     }
                     @Override
                     public void onAnimationCancel(Animator animation) {
-                        mAnimationBuffer.setVisibility(View.GONE);
-                        mAnimationBuffer.removeAllViews();
+                        clearAnimationBuffer();
                     }
                 });
                 ObjectAnimator inAnim = LauncherAnimUtils.ofFloat(mAppsCustomizePane, "alpha", 1f);
diff --git a/src/com/android/launcher2/ButtonDropTarget.java b/src/com/android/launcher2/ButtonDropTarget.java
index 1c9fa5f..ff0813a 100644
--- a/src/com/android/launcher2/ButtonDropTarget.java
+++ b/src/com/android/launcher2/ButtonDropTarget.java
@@ -22,6 +22,7 @@
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import android.view.View;
 import android.widget.TextView;
 
 import com.android.launcher.R;
@@ -70,7 +71,7 @@
     }
 
     protected Drawable getCurrentDrawable() {
-        Drawable[] drawables = getCompoundDrawables();
+        Drawable[] drawables = getCompoundDrawablesRelative();
         for (int i = 0; i < drawables.length; ++i) {
             if (drawables[i] != null) {
                 return drawables[i];
@@ -116,21 +117,39 @@
         outRect.bottom += mBottomDragPadding;
     }
 
-    Rect getIconRect(int itemWidth, int itemHeight, int drawableWidth, int drawableHeight) {
+    private boolean isRtl() {
+        return (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
+    }
+
+    Rect getIconRect(int viewWidth, int viewHeight, int drawableWidth, int drawableHeight) {
         DragLayer dragLayer = mLauncher.getDragLayer();
 
         // Find the rect to animate to (the view is center aligned)
         Rect to = new Rect();
         dragLayer.getViewRectRelativeToSelf(this, to);
-        int width = drawableWidth;
-        int height = drawableHeight;
-        int left = to.left + getPaddingLeft();
-        int top = to.top + (getMeasuredHeight() - height) / 2;
-        to.set(left, top, left + width, top + height);
+
+        final int width = drawableWidth;
+        final int height = drawableHeight;
+
+        final int left;
+        final int right;
+
+        if (isRtl()) {
+            right = to.right - getPaddingRight();
+            left = right - width;
+        } else {
+            left = to.left + getPaddingLeft();
+            right = left + width;
+        }
+
+        final int top = to.top + (getMeasuredHeight() - height) / 2;
+        final int bottom = top +  height;
+
+        to.set(left, top, right, bottom);
 
         // Center the destination rect about the trash icon
-        int xOffset = (int) -(itemWidth - width) / 2;
-        int yOffset = (int) -(itemHeight - height) / 2;
+        final int xOffset = (int) -(viewWidth - width) / 2;
+        final int yOffset = (int) -(viewHeight - height) / 2;
         to.offset(xOffset, yOffset);
 
         return to;
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 7818da4..98fcdea 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -181,6 +181,7 @@
         // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
         // the user where a dragged item will land when dropped.
         setWillNotDraw(false);
+        setClipToPadding(false);
         mLauncher = (Launcher) context;
 
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
diff --git a/src/com/android/launcher2/DeleteDropTarget.java b/src/com/android/launcher2/DeleteDropTarget.java
index 39a0b09..d575b8f 100644
--- a/src/com/android/launcher2/DeleteDropTarget.java
+++ b/src/com/android/launcher2/DeleteDropTarget.java
@@ -154,9 +154,9 @@
         }
 
         if (isUninstall) {
-            setCompoundDrawablesWithIntrinsicBounds(mUninstallDrawable, null, null, null);
+            setCompoundDrawablesRelativeWithIntrinsicBounds(mUninstallDrawable, null, null, null);
         } else {
-            setCompoundDrawablesWithIntrinsicBounds(mRemoveDrawable, null, null, null);
+            setCompoundDrawablesRelativeWithIntrinsicBounds(mRemoveDrawable, null, null, null);
         }
         mCurrentDrawable = (TransitionDrawable) getCurrentDrawable();
 
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java
index 4c42953..3e586bf 100644
--- a/src/com/android/launcher2/DragController.java
+++ b/src/com/android/launcher2/DragController.java
@@ -175,16 +175,18 @@
      *          Makes dragging feel more precise, e.g. you can clip out a transparent border
      */
     public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction,
-            Rect dragRegion, float initialDragViewScale) {
+            Point extraPadding, float initialDragViewScale) {
         int[] loc = mCoordinatesTemp;
         mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
-        int dragLayerX = loc[0] + v.getPaddingLeft() +
+        int viewExtraPaddingLeft = extraPadding != null ? extraPadding.x : 0;
+        int viewExtraPaddingTop = extraPadding != null ? extraPadding.y : 0;
+        int dragLayerX = loc[0] + v.getPaddingLeft() + viewExtraPaddingLeft +
                 (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2);
-        int dragLayerY = loc[1] + v.getPaddingTop() +
+        int dragLayerY = loc[1] + v.getPaddingTop() + viewExtraPaddingTop +
                 (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
 
-        startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion,
-                initialDragViewScale);
+        startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null,
+                null, initialDragViewScale);
 
         if (dragAction == DRAG_ACTION_MOVE) {
             v.setVisibility(View.GONE);
diff --git a/src/com/android/launcher2/InfoDropTarget.java b/src/com/android/launcher2/InfoDropTarget.java
index d6bf5f2..850cc1f 100644
--- a/src/com/android/launcher2/InfoDropTarget.java
+++ b/src/com/android/launcher2/InfoDropTarget.java
@@ -51,7 +51,9 @@
         Resources r = getResources();
         mHoverColor = r.getColor(R.color.info_target_hover_tint);
         mDrawable = (TransitionDrawable) getCurrentDrawable();
-        mDrawable.setCrossFadeEnabled(true);
+        if (null != mDrawable) {
+            mDrawable.setCrossFadeEnabled(true);
+        }
 
         // Remove the text in the Phone UI in landscape
         int orientation = getResources().getConfiguration().orientation;
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index ccf8328..9a5bd47 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -1988,6 +1988,7 @@
                     for (int i=0; i<N; i++) {
                         if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
                         mBgAllAppsList.updatePackage(context, packages[i]);
+                        WidgetPreviewLoader.removeFromDb(context, packages[i]);
                     }
                     break;
                 case OP_REMOVE:
@@ -1995,6 +1996,7 @@
                     for (int i=0; i<N; i++) {
                         if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
                         mBgAllAppsList.removePackage(packages[i]);
+                        WidgetPreviewLoader.removeFromDb(context, packages[i]);
                     }
                     break;
             }
diff --git a/src/com/android/launcher2/PackageChangedReceiver.java b/src/com/android/launcher2/PackageChangedReceiver.java
new file mode 100644
index 0000000..ce08b3a
--- /dev/null
+++ b/src/com/android/launcher2/PackageChangedReceiver.java
@@ -0,0 +1,18 @@
+package com.android.launcher2;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class PackageChangedReceiver extends BroadcastReceiver {
+    @Override
+    public void onReceive(final Context context, Intent intent) {
+        final String packageName = intent.getData().getSchemeSpecificPart();
+
+        if (packageName == null || packageName.length() == 0) {
+            // they sent us a bad intent
+            return;
+        }
+        WidgetPreviewLoader.removeFromDb(context, packageName);
+    }
+}
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 6d5d151..494534c 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -257,6 +257,13 @@
     }
 
     /**
+     * Note: this is a reimplementation of View.isLayoutRtl() since that is currently hidden api.
+     */
+    public boolean isLayoutRtl() {
+        return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
+    }
+
+    /**
      * Called by subclasses to mark that data is ready, and that we can begin loading and laying
      * out pages.
      */
@@ -401,17 +408,28 @@
 
     @Override
     public void scrollTo(int x, int y) {
+        final boolean isRtl = isLayoutRtl();
         mUnboundedScrollX = x;
 
-        if (x < 0) {
+        boolean isXBeforeFirstPage = isRtl ? (x > mMaxScrollX) : (x < 0);
+        boolean isXAfterLastPage = isRtl ? (x < 0) : (x > mMaxScrollX);
+        if (isXBeforeFirstPage) {
             super.scrollTo(0, y);
             if (mAllowOverScroll) {
-                overScroll(x);
+                if (isRtl) {
+                    overScroll(x - mMaxScrollX);
+                } else {
+                    overScroll(x);
+                }
             }
-        } else if (x > mMaxScrollX) {
+        } else if (isXAfterLastPage) {
             super.scrollTo(mMaxScrollX, y);
             if (mAllowOverScroll) {
-                overScroll(x - mMaxScrollX);
+                if (isRtl) {
+                    overScroll(x);
+                } else {
+                    overScroll(x - mMaxScrollX);
+                }
             }
         } else {
             mOverScrollX = x;
@@ -566,7 +584,8 @@
         updateScrollingIndicatorPosition();
 
         if (childCount > 0) {
-            mMaxScrollX = getChildOffset(childCount - 1) - getRelativeChildOffset(childCount - 1);
+            final int index = isLayoutRtl() ? 0 : childCount - 1;
+            mMaxScrollX = getChildOffset(index) - getRelativeChildOffset(index);
         } else {
             mMaxScrollX = 0;
         }
@@ -631,9 +650,13 @@
         if (DEBUG) Log.d(TAG, "PagedView.onLayout()");
         final int verticalPadding = getPaddingTop() + getPaddingBottom();
         final int childCount = getChildCount();
-        int childLeft = getRelativeChildOffset(0);
+        final boolean isRtl = isLayoutRtl();
 
-        for (int i = 0; i < childCount; i++) {
+        final int startIndex = isRtl ? childCount - 1 : 0;
+        final int endIndex = isRtl ? -1 : childCount;
+        final int delta = isRtl ? -1 : 1;
+        int childLeft = getRelativeChildOffset(startIndex);
+        for (int i = startIndex; i != endIndex; i += delta) {
             final View child = getPageAt(i);
             if (child.getVisibility() != View.GONE) {
                 final int childWidth = getScaledMeasuredWidth(child);
@@ -710,6 +733,7 @@
     }
 
     protected int getChildOffset(int index) {
+        final boolean isRtl = isLayoutRtl();
         int[] childOffsets = Float.compare(mLayoutScale, 1f) == 0 ?
                 mChildOffsets : mChildOffsetsWithLayoutScale;
 
@@ -719,8 +743,11 @@
             if (getChildCount() == 0)
                 return 0;
 
-            int offset = getRelativeChildOffset(0);
-            for (int i = 0; i < index; ++i) {
+            final int startIndex = isRtl ? getChildCount() - 1 : 0;
+            final int endIndex = isRtl ? index : index;
+            final int delta = isRtl ? -1 : 1;
+            int offset = getRelativeChildOffset(startIndex);
+            for (int i = startIndex; i != endIndex; i += delta) {
                 offset += getScaledMeasuredWidth(getPageAt(i)) + mPageSpacing;
             }
             if (childOffsets != null) {
@@ -754,28 +781,31 @@
     }
 
     protected void getVisiblePages(int[] range) {
+        final boolean isRtl = isLayoutRtl();
         final int pageCount = getChildCount();
 
         if (pageCount > 0) {
             final int screenWidth = getMeasuredWidth();
-            int leftScreen = 0;
+            int leftScreen = isRtl ? pageCount - 1 : 0;
             int rightScreen = 0;
+            int endIndex = isRtl ? 0 : pageCount - 1;
+            int delta = isRtl ? -1 : 1;
             View currPage = getPageAt(leftScreen);
-            while (leftScreen < pageCount - 1 &&
+            while (leftScreen != endIndex &&
                     currPage.getX() + currPage.getWidth() -
                     currPage.getPaddingRight() < getScrollX()) {
-                leftScreen++;
+                leftScreen += delta;
                 currPage = getPageAt(leftScreen);
             }
             rightScreen = leftScreen;
-            currPage = getPageAt(rightScreen + 1);
-            while (rightScreen < pageCount - 1 &&
+            currPage = getPageAt(rightScreen + delta);
+            while (rightScreen != endIndex &&
                     currPage.getX() - currPage.getPaddingLeft() < getScrollX() + screenWidth) {
-                rightScreen++;
-                currPage = getPageAt(rightScreen + 1);
+                rightScreen += delta;
+                currPage = getPageAt(rightScreen + delta);
             }
-            range[0] = leftScreen;
-            range[1] = rightScreen;
+            range[0] = Math.min(leftScreen, rightScreen);
+            range[1] = Math.max(leftScreen, rightScreen);
         } else {
             range[0] = -1;
             range[1] = -1;
@@ -854,6 +884,7 @@
 
     @Override
     public boolean dispatchUnhandledMove(View focused, int direction) {
+        // XXX-RTL: This will be fixed in a future CL
         if (direction == View.FOCUS_LEFT) {
             if (getCurrentPage() > 0) {
                 snapToPage(getCurrentPage() - 1);
@@ -870,6 +901,7 @@
 
     @Override
     public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
+        // XXX-RTL: This will be fixed in a future CL
         if (mCurrentPage >= 0 && mCurrentPage < getPageCount()) {
             getPageAt(mCurrentPage).addFocusables(views, direction, focusableMode);
         }
@@ -930,14 +962,23 @@
      * Return true if a tap at (x, y) should trigger a flip to the previous page.
      */
     protected boolean hitsPreviousPage(float x, float y) {
-        return (x < getRelativeChildOffset(mCurrentPage) - mPageSpacing);
+        if (isLayoutRtl()) {
+            return (x > (getMeasuredWidth() - getRelativeChildOffset(mCurrentPage) + mPageSpacing));
+        } else {
+            return (x < getRelativeChildOffset(mCurrentPage) - mPageSpacing);
+        }
     }
 
     /**
      * Return true if a tap at (x, y) should trigger a flip to the next page.
      */
     protected boolean hitsNextPage(float x, float y) {
-        return  (x > (getMeasuredWidth() - getRelativeChildOffset(mCurrentPage) + mPageSpacing));
+        if (isLayoutRtl()) {
+            return (x < getRelativeChildOffset(mCurrentPage) - mPageSpacing);
+        } else {
+            return (x > (getMeasuredWidth() - getRelativeChildOffset(mCurrentPage) + mPageSpacing));
+        }
+
     }
 
     @Override
@@ -1269,12 +1310,15 @@
                 // We give flings precedence over large moves, which is why we short-circuit our
                 // test for a large move if a fling has been registered. That is, a large
                 // move to the left and fling to the right will register as a fling to the right.
-                if (((isSignificantMove && deltaX > 0 && !isFling) ||
-                        (isFling && velocityX > 0)) && mCurrentPage > 0) {
+                final boolean isRtl = isLayoutRtl();
+                boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0;
+                boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0;
+                if (((isSignificantMove && !isDeltaXLeft && !isFling) ||
+                        (isFling && !isVelocityXLeft)) && mCurrentPage > 0) {
                     finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1;
                     snapToPageWithVelocity(finalPage, velocityX);
-                } else if (((isSignificantMove && deltaX < 0 && !isFling) ||
-                        (isFling && velocityX < 0)) &&
+                } else if (((isSignificantMove && isDeltaXLeft && !isFling) ||
+                        (isFling && isVelocityXLeft)) &&
                         mCurrentPage < getChildCount() - 1) {
                     finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1;
                     snapToPageWithVelocity(finalPage, velocityX);
@@ -1342,7 +1386,9 @@
                         hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                     }
                     if (hscroll != 0 || vscroll != 0) {
-                        if (hscroll > 0 || vscroll > 0) {
+                        boolean isForwardScroll = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
+                                                         : (hscroll > 0 || vscroll > 0);
+                        if (isForwardScroll) {
                             scrollRight();
                         } else {
                             scrollLeft();
@@ -1400,10 +1446,14 @@
     }
 
     protected int getChildIndexForRelativeOffset(int relativeOffset) {
+        final boolean isRtl = isLayoutRtl();
         final int childCount = getChildCount();
         int left;
         int right;
-        for (int i = 0; i < childCount; ++i) {
+        final int startIndex = isRtl ? childCount - 1 : 0;
+        final int endIndex = isRtl ? -1 : childCount;
+        final int delta = isRtl ? -1 : 1;
+        for (int i = startIndex; i != endIndex; i += delta) {
             left = getRelativeChildOffset(i);
             right = (left + getScaledMeasuredWidth(getPageAt(i)));
             if (left <= relativeOffset && relativeOffset <= right) {
@@ -1839,17 +1889,20 @@
     }
 
     private void updateScrollingIndicatorPosition() {
+        final boolean isRtl = isLayoutRtl();
         if (!isScrollingIndicatorEnabled()) return;
         if (mScrollIndicator == null) return;
         int numPages = getChildCount();
         int pageWidth = getMeasuredWidth();
-        int lastChildIndex = Math.max(0, getChildCount() - 1);
-        int maxScrollX = getChildOffset(lastChildIndex) - getRelativeChildOffset(lastChildIndex);
         int trackWidth = pageWidth - mScrollIndicatorPaddingLeft - mScrollIndicatorPaddingRight;
         int indicatorWidth = mScrollIndicator.getMeasuredWidth() -
                 mScrollIndicator.getPaddingLeft() - mScrollIndicator.getPaddingRight();
 
-        float offset = Math.max(0f, Math.min(1f, (float) getScrollX() / maxScrollX));
+        float scrollPos = isRtl ? mMaxScrollX - getScrollX() : getScrollX();
+        float offset = Math.max(0f, Math.min(1f, (float) scrollPos / mMaxScrollX));
+        if (isRtl) {
+            offset = 1f - offset;
+        }
         int indicatorSpace = trackWidth / numPages;
         int indicatorPos = (int) (offset * (trackWidth - indicatorSpace)) + mScrollIndicatorPaddingLeft;
         if (hasElasticScrollIndicator()) {
diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java
index 6f73e63..9ce177b 100644
--- a/src/com/android/launcher2/PagedViewCellLayout.java
+++ b/src/com/android/launcher2/PagedViewCellLayout.java
@@ -86,17 +86,6 @@
         return mCellHeight;
     }
 
-    void destroyHardwareLayers() {
-        // called when a page is no longer visible (triggered by loadAssociatedPages ->
-        // removeAllViewsOnPage)
-        setLayerType(LAYER_TYPE_NONE, null);
-    }
-
-    void createHardwareLayers() {
-        // called when a page is visible (triggered by loadAssociatedPages -> syncPageItems)
-        setLayerType(LAYER_TYPE_HARDWARE, null);
-    }
-
     @Override
     public void cancelLongPress() {
         super.cancelLongPress();
@@ -133,7 +122,7 @@
     @Override
     public void removeAllViewsOnPage() {
         mChildren.removeAllViews();
-        destroyHardwareLayers();
+        setLayerType(LAYER_TYPE_NONE, null);
     }
 
     @Override
diff --git a/src/com/android/launcher2/PagedViewGridLayout.java b/src/com/android/launcher2/PagedViewGridLayout.java
index 90bfe88..aa9adc0 100644
--- a/src/com/android/launcher2/PagedViewGridLayout.java
+++ b/src/com/android/launcher2/PagedViewGridLayout.java
@@ -98,19 +98,11 @@
         return result;
     }
 
-    void destroyHardwareLayer() {
-        setLayerType(LAYER_TYPE_NONE, null);
-    }
-
-    void createHardwareLayer() {
-        setLayerType(LAYER_TYPE_HARDWARE, null);
-    }
-
     @Override
     public void removeAllViewsOnPage() {
         removeAllViews();
         mOnLayoutListener = null;
-        destroyHardwareLayer();
+        setLayerType(LAYER_TYPE_NONE, null);
     }
 
     @Override
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
index b804ab0..bb5827a 100644
--- a/src/com/android/launcher2/PagedViewWidget.java
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -38,6 +38,7 @@
     static final String TAG = "PagedViewWidgetLayout";
 
     private static boolean sDeletePreviewsWhenDetachedFromWindow = true;
+    private static boolean sRecyclePreviewsWhenDetachedFromWindow = true;
 
     private String mDimensionsFormatString;
     CheckForShortPress mPendingCheckForShortPress = null;
@@ -46,6 +47,8 @@
     static PagedViewWidget sShortpressTarget = null;
     boolean mIsAppWidget;
     private final Rect mOriginalImagePadding = new Rect();
+    private Object mInfo;
+    private WidgetPreviewLoader mWidgetPreviewLoader;
 
     public PagedViewWidget(Context context) {
         this(context, null);
@@ -80,6 +83,10 @@
         sDeletePreviewsWhenDetachedFromWindow = value;
     }
 
+    public static void setRecyclePreviewsWhenDetachedFromWindow(boolean value) {
+        sRecyclePreviewsWhenDetachedFromWindow = value;
+    }
+
     @Override
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();
@@ -88,8 +95,9 @@
             final ImageView image = (ImageView) findViewById(R.id.widget_preview);
             if (image != null) {
                 FastBitmapDrawable preview = (FastBitmapDrawable) image.getDrawable();
-                if (preview != null && preview.getBitmap() != null) {
-                    preview.getBitmap().recycle();
+                if (sRecyclePreviewsWhenDetachedFromWindow &&
+                        mInfo != null && preview != null && preview.getBitmap() != null) {
+                    mWidgetPreviewLoader.recycleBitmap(mInfo, preview.getBitmap());
                 }
                 image.setImageDrawable(null);
             }
@@ -97,8 +105,9 @@
     }
 
     public void applyFromAppWidgetProviderInfo(AppWidgetProviderInfo info,
-            int maxWidth, int[] cellSpan) {
+            int maxWidth, int[] cellSpan, WidgetPreviewLoader loader) {
         mIsAppWidget = true;
+        mInfo = info;
         final ImageView image = (ImageView) findViewById(R.id.widget_preview);
         if (maxWidth > -1) {
             image.setMaxWidth(maxWidth);
@@ -112,10 +121,13 @@
             int vSpan = Math.min(cellSpan[1], LauncherModel.getCellCountY());
             dims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
         }
+        mWidgetPreviewLoader = loader;
     }
 
-    public void applyFromResolveInfo(PackageManager pm, ResolveInfo info) {
+    public void applyFromResolveInfo(
+            PackageManager pm, ResolveInfo info, WidgetPreviewLoader loader) {
         mIsAppWidget = false;
+        mInfo = info;
         CharSequence label = info.loadLabel(pm);
         final ImageView image = (ImageView) findViewById(R.id.widget_preview);
         image.setContentDescription(label);
@@ -125,6 +137,7 @@
         if (dims != null) {
             dims.setText(String.format(mDimensionsFormatString, 1, 1));
         }
+        mWidgetPreviewLoader = loader;
     }
 
     public int[] getPreviewSize() {
diff --git a/src/com/android/launcher2/WidgetPreviewLoader.java b/src/com/android/launcher2/WidgetPreviewLoader.java
new file mode 100644
index 0000000..68813d4
--- /dev/null
+++ b/src/com/android/launcher2/WidgetPreviewLoader.java
@@ -0,0 +1,616 @@
+package com.android.launcher2;
+
+import android.appwidget.AppWidgetProviderInfo;
+import android.content.ComponentName;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.Rect;
+import android.graphics.Shader;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.AsyncTask;
+import android.util.Log;
+
+import com.android.launcher.R;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+abstract class SoftReferenceThreadLocal<T> {
+    private ThreadLocal<SoftReference<T>> mThreadLocal;
+    public SoftReferenceThreadLocal() {
+        mThreadLocal = new ThreadLocal<SoftReference<T>>();
+    }
+
+    abstract T initialValue();
+
+    public void set(T t) {
+        mThreadLocal.set(new SoftReference<T>(t));
+    }
+
+    public T get() {
+        SoftReference<T> reference = mThreadLocal.get();
+        T obj;
+        if (reference == null) {
+            obj = initialValue();
+            mThreadLocal.set(new SoftReference<T>(obj));
+            return obj;
+        } else {
+            obj = reference.get();
+            if (obj == null) {
+                obj = initialValue();
+                mThreadLocal.set(new SoftReference<T>(obj));
+            }
+            return obj;
+        }
+    }
+}
+
+class CanvasCache extends SoftReferenceThreadLocal<Canvas> {
+    @Override
+    protected Canvas initialValue() {
+        return new Canvas();
+    }
+}
+
+class PaintCache extends SoftReferenceThreadLocal<Paint> {
+    @Override
+    protected Paint initialValue() {
+        return null;
+    }
+}
+
+class BitmapCache extends SoftReferenceThreadLocal<Bitmap> {
+    @Override
+    protected Bitmap initialValue() {
+        return null;
+    }
+}
+
+class RectCache extends SoftReferenceThreadLocal<Rect> {
+    @Override
+    protected Rect initialValue() {
+        return new Rect();
+    }
+}
+
+class BitmapFactoryOptionsCache extends SoftReferenceThreadLocal<BitmapFactory.Options> {
+    @Override
+    protected BitmapFactory.Options initialValue() {
+        return new BitmapFactory.Options();
+    }
+}
+
+public class WidgetPreviewLoader {
+    static final String TAG = "WidgetPreviewLoader";
+
+    private int mPreviewBitmapWidth;
+    private int mPreviewBitmapHeight;
+    private String mSize;
+    private Context mContext;
+    private Launcher mLauncher;
+    private PackageManager mPackageManager;
+    private PagedViewCellLayout mWidgetSpacingLayout;
+
+    // Used for drawing shortcut previews
+    private BitmapCache mCachedShortcutPreviewBitmap = new BitmapCache();
+    private PaintCache mCachedShortcutPreviewPaint = new PaintCache();
+    private CanvasCache mCachedShortcutPreviewCanvas = new CanvasCache();
+
+    // Used for drawing widget previews
+    private CanvasCache mCachedAppWidgetPreviewCanvas = new CanvasCache();
+    private RectCache mCachedAppWidgetPreviewSrcRect = new RectCache();
+    private RectCache mCachedAppWidgetPreviewDestRect = new RectCache();
+    private PaintCache mCachedAppWidgetPreviewPaint = new PaintCache();
+    private String mCachedSelectQuery;
+    private BitmapFactoryOptionsCache mCachedBitmapFactoryOptions = new BitmapFactoryOptionsCache();
+
+    private int mAppIconSize;
+    private IconCache mIconCache;
+
+    private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
+
+    private WidgetPreviewCacheDb mDb;
+
+    private HashMap<String, WeakReference<Bitmap>> mLoadedPreviews;
+    private ArrayList<SoftReference<Bitmap>> mUnusedBitmaps;
+    private static HashSet<String> sInvalidPackages;
+
+    static {
+        sInvalidPackages = new HashSet<String>();
+    }
+
+    public WidgetPreviewLoader(Launcher launcher) {
+        mContext = mLauncher = launcher;
+        mPackageManager = mContext.getPackageManager();
+        mAppIconSize = mContext.getResources().getDimensionPixelSize(R.dimen.app_icon_size);
+        mIconCache = ((LauncherApplication) launcher.getApplicationContext()).getIconCache();
+        mDb = new WidgetPreviewCacheDb(mContext);
+        mLoadedPreviews = new HashMap<String, WeakReference<Bitmap>>();
+        mUnusedBitmaps = new ArrayList<SoftReference<Bitmap>>();
+    }
+
+    public void setPreviewSize(int previewWidth, int previewHeight,
+            PagedViewCellLayout widgetSpacingLayout) {
+        mPreviewBitmapWidth = previewWidth;
+        mPreviewBitmapHeight = previewHeight;
+        mSize = previewWidth + "x" + previewHeight;
+        mWidgetSpacingLayout = widgetSpacingLayout;
+    }
+
+    public Bitmap getPreview(final Object o) {
+        String name = getObjectName(o);
+        // check if the package is valid
+        boolean packageValid = true;
+        synchronized(sInvalidPackages) {
+            packageValid = !sInvalidPackages.contains(getObjectPackage(o));
+        }
+        if (!packageValid) {
+            return null;
+        }
+        if (packageValid) {
+            synchronized(mLoadedPreviews) {
+                // check if it exists in our existing cache
+                if (mLoadedPreviews.containsKey(name) && mLoadedPreviews.get(name).get() != null) {
+                    return mLoadedPreviews.get(name).get();
+                }
+            }
+        }
+
+        Bitmap unusedBitmap = null;
+        synchronized(mUnusedBitmaps) {
+            // not in cache; we need to load it from the db
+            while ((unusedBitmap == null || !unusedBitmap.isMutable() ||
+                    unusedBitmap.getWidth() != mPreviewBitmapWidth ||
+                    unusedBitmap.getHeight() != mPreviewBitmapHeight)
+                    && mUnusedBitmaps.size() > 0) {
+                unusedBitmap = mUnusedBitmaps.remove(0).get();
+            }
+            if (unusedBitmap != null) {
+                final Canvas c = mCachedAppWidgetPreviewCanvas.get();
+                c.setBitmap(unusedBitmap);
+                c.drawColor(0, PorterDuff.Mode.CLEAR);
+                c.setBitmap(null);
+            }
+        }
+
+        if (unusedBitmap == null) {
+            unusedBitmap = Bitmap.createBitmap(mPreviewBitmapWidth, mPreviewBitmapHeight,
+                    Bitmap.Config.ARGB_8888);
+        }
+
+        Bitmap preview = null;
+
+        if (packageValid) {
+            preview = readFromDb(name, unusedBitmap);
+        }
+
+        if (preview != null) {
+            synchronized(mLoadedPreviews) {
+                mLoadedPreviews.put(name, new WeakReference<Bitmap>(preview));
+            }
+            return preview;
+        } else {
+            // it's not in the db... we need to generate it
+            final Bitmap generatedPreview = generatePreview(o, unusedBitmap);
+            preview = generatedPreview;
+            if (preview != unusedBitmap) {
+                throw new RuntimeException("generatePreview is not recycling the bitmap " + o);
+            }
+
+            synchronized(mLoadedPreviews) {
+                mLoadedPreviews.put(name, new WeakReference<Bitmap>(preview));
+            }
+
+            // write to db on a thread pool... this can be done lazily and improves the performance
+            // of the first time widget previews are loaded
+            new AsyncTask<Void, Void, Void>() {
+                public Void doInBackground(Void ... args) {
+                    writeToDb(o, generatedPreview);
+                    return null;
+                }
+            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
+
+            return preview;
+        }
+    }
+
+    public void recycleBitmap(Object o, Bitmap bitmapToRecycle) {
+        String name = getObjectName(o);
+        synchronized (mLoadedPreviews) {
+            if (mLoadedPreviews.containsKey(name)) {
+                Bitmap b = mLoadedPreviews.get(name).get();
+                if (b == bitmapToRecycle) {
+                    mLoadedPreviews.remove(name);
+                    if (bitmapToRecycle.isMutable()) {
+                        synchronized (mUnusedBitmaps) {
+                            mUnusedBitmaps.add(new SoftReference<Bitmap>(b));
+                        }
+                    }
+                } else {
+                    throw new RuntimeException("Bitmap passed in doesn't match up");
+                }
+            }
+        }
+    }
+
+    static class WidgetPreviewCacheDb extends SQLiteOpenHelper {
+        final static int DB_VERSION = 2;
+        final static String DB_NAME = "widgetpreviews.db";
+        final static String TABLE_NAME = "shortcut_and_widget_previews";
+        final static String COLUMN_NAME = "name";
+        final static String COLUMN_SIZE = "size";
+        final static String COLUMN_PREVIEW_BITMAP = "preview_bitmap";
+        Context mContext;
+
+        public WidgetPreviewCacheDb(Context context) {
+            super(context, new File(context.getCacheDir(), DB_NAME).getPath(), null, DB_VERSION);
+            // Store the context for later use
+            mContext = context;
+        }
+
+        @Override
+        public void onCreate(SQLiteDatabase database) {
+            database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
+                    COLUMN_NAME + " TEXT NOT NULL, " +
+                    COLUMN_SIZE + " TEXT NOT NULL, " +
+                    COLUMN_PREVIEW_BITMAP + " BLOB NOT NULL, " +
+                    "PRIMARY KEY (" + COLUMN_NAME + ", " + COLUMN_SIZE + ") " +
+                    ");");
+        }
+
+        @Override
+        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+            if (oldVersion != newVersion) {
+                // Delete all the records; they'll be repopulated as this is a cache
+                db.execSQL("DELETE FROM " + TABLE_NAME);
+            }
+        }
+    }
+
+    private static final String WIDGET_PREFIX = "Widget:";
+    private static final String SHORTCUT_PREFIX = "Shortcut:";
+
+    private static String getObjectName(Object o) {
+        // should cache the string builder
+        StringBuilder sb = new StringBuilder();
+        String output;
+        if (o instanceof AppWidgetProviderInfo) {
+            sb.append(WIDGET_PREFIX);
+            sb.append(((AppWidgetProviderInfo) o).provider.flattenToString());
+            output = sb.toString();
+            sb.setLength(0);
+        } else {
+            sb.append(SHORTCUT_PREFIX);
+
+            ResolveInfo info = (ResolveInfo) o;
+            sb.append(new ComponentName(info.activityInfo.packageName,
+                    info.activityInfo.name).flattenToString());
+            output = sb.toString();
+            sb.setLength(0);
+        }
+        return output;
+    }
+
+    private String getObjectPackage(Object o) {
+        if (o instanceof AppWidgetProviderInfo) {
+            return ((AppWidgetProviderInfo) o).provider.getPackageName();
+        } else {
+            ResolveInfo info = (ResolveInfo) o;
+            return info.activityInfo.packageName;
+        }
+    }
+
+    private void writeToDb(Object o, Bitmap preview) {
+        String name = getObjectName(o);
+        SQLiteDatabase db = mDb.getWritableDatabase();
+        ContentValues values = new ContentValues();
+
+        values.put(WidgetPreviewCacheDb.COLUMN_NAME, name);
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        preview.compress(Bitmap.CompressFormat.PNG, 100, stream);
+        values.put(WidgetPreviewCacheDb.COLUMN_PREVIEW_BITMAP, stream.toByteArray());
+        values.put(WidgetPreviewCacheDb.COLUMN_SIZE, mSize);
+        db.insert(WidgetPreviewCacheDb.TABLE_NAME, null, values);
+    }
+
+    public static void removeFromDb(final Context mContext, final String packageName) {
+        synchronized(sInvalidPackages) {
+            sInvalidPackages.add(packageName);
+        }
+        new AsyncTask<Void, Void, Void>() {
+            public Void doInBackground(Void ... args) {
+                SQLiteDatabase db = new WidgetPreviewCacheDb(mContext).getWritableDatabase();
+                db.delete(WidgetPreviewCacheDb.TABLE_NAME,
+                        WidgetPreviewCacheDb.COLUMN_NAME + " LIKE ? OR " +
+                        WidgetPreviewCacheDb.COLUMN_NAME + " LIKE ?", // SELECT query
+                        new String[] {
+                            WIDGET_PREFIX + packageName + "/%",
+                            SHORTCUT_PREFIX + packageName + "/%"} // args to SELECT query
+                            );
+                db.close();
+                synchronized(sInvalidPackages) {
+                    sInvalidPackages.remove(packageName);
+                }
+                return null;
+            }
+        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
+    }
+
+    public void closeDb()  {
+        if (mDb != null) {
+            mDb.close();
+        }
+    }
+
+    private Bitmap readFromDb(String name, Bitmap b) {
+        if (mCachedSelectQuery == null) {
+            mCachedSelectQuery = WidgetPreviewCacheDb.COLUMN_NAME + " = ? AND " +
+                    WidgetPreviewCacheDb.COLUMN_SIZE + " = ?";
+        }
+        SQLiteDatabase db = mDb.getReadableDatabase();
+        Cursor result = db.query(WidgetPreviewCacheDb.TABLE_NAME,
+                new String[] { WidgetPreviewCacheDb.COLUMN_PREVIEW_BITMAP }, // cols to return
+                mCachedSelectQuery, // select query
+                new String[] { name, mSize }, // args to select query
+                null,
+                null,
+                null,
+                null);
+        if (result.getCount() > 0) {
+            result.moveToFirst();
+            byte[] blob = result.getBlob(0);
+            result.close();
+            final BitmapFactory.Options opts = mCachedBitmapFactoryOptions.get();
+            opts.inBitmap = b;
+            opts.inSampleSize = 1;
+            Bitmap out = BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
+            return out;
+        } else {
+            result.close();
+            return null;
+        }
+    }
+
+    public Bitmap generatePreview(Object info, Bitmap preview) {
+        if (preview != null &&
+                (preview.getWidth() != mPreviewBitmapWidth ||
+                preview.getHeight() != mPreviewBitmapHeight)) {
+            throw new RuntimeException("Improperly sized bitmap passed as argument");
+        }
+        if (info instanceof AppWidgetProviderInfo) {
+            return generateWidgetPreview((AppWidgetProviderInfo) info, preview);
+        } else {
+            return generateShortcutPreview(
+                    (ResolveInfo) info, mPreviewBitmapWidth, mPreviewBitmapHeight, preview);
+        }
+    }
+
+    public Bitmap generateWidgetPreview(AppWidgetProviderInfo info, Bitmap preview) {
+        int[] cellSpans = Launcher.getSpanForWidget(mLauncher, info);
+        int maxWidth = maxWidthForWidgetPreview(cellSpans[0]);
+        int maxHeight = maxHeightForWidgetPreview(cellSpans[1]);
+        return generateWidgetPreview(info.provider, info.previewImage, info.icon,
+                cellSpans[0], cellSpans[1], maxWidth, maxHeight, preview, null);
+    }
+
+    public int maxWidthForWidgetPreview(int spanX) {
+        return Math.min(mPreviewBitmapWidth,
+                mWidgetSpacingLayout.estimateCellWidth(spanX));
+    }
+
+    public int maxHeightForWidgetPreview(int spanY) {
+        return Math.min(mPreviewBitmapHeight,
+                mWidgetSpacingLayout.estimateCellHeight(spanY));
+    }
+
+    public Bitmap generateWidgetPreview(ComponentName provider, int previewImage,
+            int iconId, int cellHSpan, int cellVSpan, int maxPreviewWidth, int maxPreviewHeight,
+            Bitmap preview, int[] preScaledWidthOut) {
+        // Load the preview image if possible
+        String packageName = provider.getPackageName();
+        if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE;
+        if (maxPreviewHeight < 0) maxPreviewHeight = Integer.MAX_VALUE;
+
+        Drawable drawable = null;
+        if (previewImage != 0) {
+            drawable = mPackageManager.getDrawable(packageName, previewImage, null);
+            if (drawable == null) {
+                Log.w(TAG, "Can't load widget preview drawable 0x" +
+                        Integer.toHexString(previewImage) + " for provider: " + provider);
+            }
+        }
+
+        int previewWidth;
+        int previewHeight;
+        Bitmap defaultPreview = null;
+        boolean widgetPreviewExists = (drawable != null);
+        if (widgetPreviewExists) {
+            previewWidth = drawable.getIntrinsicWidth();
+            previewHeight = drawable.getIntrinsicHeight();
+        } else {
+            // Generate a preview image if we couldn't load one
+            if (cellHSpan < 1) cellHSpan = 1;
+            if (cellVSpan < 1) cellVSpan = 1;
+
+            BitmapDrawable previewDrawable = (BitmapDrawable) mContext.getResources()
+                    .getDrawable(R.drawable.widget_preview_tile);
+            final int previewDrawableWidth = previewDrawable
+                    .getIntrinsicWidth();
+            final int previewDrawableHeight = previewDrawable
+                    .getIntrinsicHeight();
+            previewWidth = previewDrawableWidth * cellHSpan; // subtract 2 dips
+            previewHeight = previewDrawableHeight * cellVSpan;
+
+            defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight,
+                    Config.ARGB_8888);
+            final Canvas c = mCachedAppWidgetPreviewCanvas.get();
+            c.setBitmap(defaultPreview);
+            previewDrawable.setBounds(0, 0, previewWidth, previewHeight);
+            previewDrawable.setTileModeXY(Shader.TileMode.REPEAT,
+                    Shader.TileMode.REPEAT);
+            previewDrawable.draw(c);
+            c.setBitmap(null);
+
+            // Draw the icon in the top left corner
+            int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
+            int smallestSide = Math.min(previewWidth, previewHeight);
+            float iconScale = Math.min((float) smallestSide
+                    / (mAppIconSize + 2 * minOffset), 1f);
+
+            try {
+                Drawable icon = null;
+                int hoffset =
+                        (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2);
+                int yoffset =
+                        (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
+                if (iconId > 0)
+                    icon = mIconCache.getFullResIcon(packageName, iconId);
+                if (icon != null) {
+                    renderDrawableToBitmap(icon, defaultPreview, hoffset,
+                            yoffset, (int) (mAppIconSize * iconScale),
+                            (int) (mAppIconSize * iconScale));
+                }
+            } catch (Resources.NotFoundException e) {
+            }
+        }
+
+        // Scale to fit width only - let the widget preview be clipped in the
+        // vertical dimension
+        float scale = 1f;
+        if (preScaledWidthOut != null) {
+            preScaledWidthOut[0] = previewWidth;
+        }
+        if (previewWidth > maxPreviewWidth) {
+            scale = maxPreviewWidth / (float) previewWidth;
+        }
+        if (scale != 1f) {
+            previewWidth = (int) (scale * previewWidth);
+            previewHeight = (int) (scale * previewHeight);
+        }
+
+        // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size
+        if (preview == null) {
+            preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
+        }
+
+        // Draw the scaled preview into the final bitmap
+        int x = (preview.getWidth() - previewWidth) / 2;
+        if (widgetPreviewExists) {
+            renderDrawableToBitmap(drawable, preview, x, 0, previewWidth,
+                    previewHeight);
+        } else {
+            final Canvas c = mCachedAppWidgetPreviewCanvas.get();
+            final Rect src = mCachedAppWidgetPreviewSrcRect.get();
+            final Rect dest = mCachedAppWidgetPreviewDestRect.get();
+            c.setBitmap(preview);
+            src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight());
+            dest.set(x, 0, x + previewWidth, previewHeight);
+
+            Paint p = mCachedAppWidgetPreviewPaint.get();
+            if (p == null) {
+                p = new Paint();
+                p.setFilterBitmap(true);
+                mCachedAppWidgetPreviewPaint.set(p);
+            }
+            c.drawBitmap(defaultPreview, src, dest, p);
+            c.setBitmap(null);
+        }
+        return preview;
+    }
+
+    private Bitmap generateShortcutPreview(
+            ResolveInfo info, int maxWidth, int maxHeight, Bitmap preview) {
+        Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
+        final Canvas c = mCachedShortcutPreviewCanvas.get();
+        if (tempBitmap == null ||
+                tempBitmap.getWidth() != maxWidth ||
+                tempBitmap.getHeight() != maxHeight) {
+            tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
+            mCachedShortcutPreviewBitmap.set(tempBitmap);
+        } else {
+            c.setBitmap(tempBitmap);
+            c.drawColor(0, PorterDuff.Mode.CLEAR);
+            c.setBitmap(null);
+        }
+        // Render the icon
+        Drawable icon = mIconCache.getFullResIcon(info);
+
+        int paddingTop = mContext.
+                getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
+        int paddingLeft = mContext.
+                getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
+        int paddingRight = mContext.
+                getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
+
+        int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
+
+        renderDrawableToBitmap(
+                icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
+
+        if (preview != null &&
+                (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight)) {
+            throw new RuntimeException("Improperly sized bitmap passed as argument");
+        } else if (preview == null) {
+            preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
+        }
+
+        c.setBitmap(preview);
+        // Draw a desaturated/scaled version of the icon in the background as a watermark
+        Paint p = mCachedShortcutPreviewPaint.get();
+        if (p == null) {
+            p = new Paint();
+            ColorMatrix colorMatrix = new ColorMatrix();
+            colorMatrix.setSaturation(0);
+            p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
+            p.setAlpha((int) (255 * 0.06f));
+            mCachedShortcutPreviewPaint.set(p);
+        }
+        c.drawBitmap(tempBitmap, 0, 0, p);
+        c.setBitmap(null);
+
+        renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
+
+        return preview;
+    }
+
+
+    public static void renderDrawableToBitmap(
+            Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
+        renderDrawableToBitmap(d, bitmap, x, y, w, h, 1f);
+    }
+
+    private static void renderDrawableToBitmap(
+            Drawable d, Bitmap bitmap, int x, int y, int w, int h,
+            float scale) {
+        if (bitmap != null) {
+            Canvas c = new Canvas(bitmap);
+            c.scale(scale, scale);
+            Rect oldBounds = d.copyBounds();
+            d.setBounds(x, y, x + w, y + h);
+            d.draw(c);
+            d.setBounds(oldBounds); // Restore the bounds
+            c.setBitmap(null);
+        }
+    }
+
+}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 2c44aca..cb9ac55 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -409,6 +409,8 @@
         LauncherApplication app = (LauncherApplication)context.getApplicationContext();
         mIconCache = app.getIconCache();
         setWillNotDraw(false);
+        setClipChildren(false);
+        setClipToPadding(false);
         setChildrenDrawnWithCacheEnabled(true);
 
         final Resources res = getResources();
@@ -1182,18 +1184,6 @@
         }
     }
 
-    float overScrollBackgroundAlphaInterpolator(float r) {
-        float threshold = 0.08f;
-
-        if (r > mOverScrollMaxBackgroundAlpha) {
-            mOverScrollMaxBackgroundAlpha = r;
-        } else if (r < mOverScrollMaxBackgroundAlpha) {
-            r = mOverScrollMaxBackgroundAlpha;
-        }
-
-        return Math.min(r / threshold, 1.0f);
-    }
-
     private void updatePageAlphaValues(int screenCenter) {
         boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;
         if (mWorkspaceFadeInAdjacentScreens &&
@@ -1226,23 +1216,38 @@
 
     @Override
     protected void screenScrolled(int screenCenter) {
+        final boolean isRtl = isLayoutRtl();
         super.screenScrolled(screenCenter);
 
         updatePageAlphaValues(screenCenter);
         enableHwLayersOnVisiblePages();
 
         if (mOverScrollX < 0 || mOverScrollX > mMaxScrollX) {
-            int index = mOverScrollX < 0 ? 0 : getChildCount() - 1;
+            int index = 0;
+            float pivotX = 0f;
+            final float leftBiasedPivot = 0.25f;
+            final float rightBiasedPivot = 0.75f;
+            final int lowerIndex = 0;
+            final int upperIndex = getChildCount() - 1;
+            if (isRtl) {
+                index = mOverScrollX < 0 ? upperIndex : lowerIndex;
+                pivotX = (index == 0 ? leftBiasedPivot : rightBiasedPivot);
+            } else {
+                index = mOverScrollX < 0 ? lowerIndex : upperIndex;
+                pivotX = (index == 0 ? rightBiasedPivot : leftBiasedPivot);
+            }
+
             CellLayout cl = (CellLayout) getChildAt(index);
             float scrollProgress = getScrollProgress(screenCenter, cl, index);
-            cl.setOverScrollAmount(Math.abs(scrollProgress), index == 0);
-            float rotation = - WORKSPACE_OVERSCROLL_ROTATION * scrollProgress;
+            final boolean isLeftPage = (isRtl ? index > 0 : index == 0);
+            cl.setOverScrollAmount(Math.abs(scrollProgress), isLeftPage);
+            float rotation = -WORKSPACE_OVERSCROLL_ROTATION * scrollProgress;
             cl.setRotationY(rotation);
             setFadeForOverScroll(Math.abs(scrollProgress));
             if (!mOverscrollTransformsSet) {
                 mOverscrollTransformsSet = true;
                 cl.setCameraDistance(mDensity * mCameraDistance);
-                cl.setPivotX(cl.getMeasuredWidth() * (index == 0 ? 0.75f : 0.25f));
+                cl.setPivotX(cl.getMeasuredWidth() * pivotX);
                 cl.setPivotY(cl.getMeasuredHeight() * 0.5f);
                 cl.setOverscrollTransformsDirty(true);
             }
@@ -1406,13 +1411,13 @@
                 }
             }
             for (int i = 0; i < screenCount; i++) {
-                final CellLayout layout = (CellLayout) getChildAt(i);
+                final CellLayout layout = (CellLayout) getPageAt(i);
                 if (!(leftScreen <= i && i <= rightScreen && shouldDrawChild(layout))) {
                     layout.disableHardwareLayers();
                 }
             }
             for (int i = 0; i < screenCount; i++) {
-                final CellLayout layout = (CellLayout) getChildAt(i);
+                final CellLayout layout = (CellLayout) getPageAt(i);
                 if (leftScreen <= i && i <= rightScreen && shouldDrawChild(layout)) {
                     layout.enableHardwareLayers();
                 }
@@ -1695,7 +1700,6 @@
                     }
                 }
             }
-            buildPageHardwareLayers();
             anim.setStartDelay(delay);
         }
 
@@ -1715,6 +1719,7 @@
     @Override
     public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
         mIsSwitchingState = true;
+        updateChildrenLayersEnabled(false);
         cancelScrollingIndicatorAnimations();
     }