Merge "Updating version check to use SDK_INT" into ub-launcher3-calgary
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 9c52739..8154c66 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -68,7 +68,7 @@
     <string name="msg_disabled_by_admin" msgid="6898038085516271325">"Désactivé par votre administrateur"</string>
     <string name="accessibility_action_overview" msgid="6257665857640347026">"Vue d\'ensemble"</string>
     <string name="allow_rotation_title" msgid="7728578836261442095">"Autoriser la rotation de l\'écran d\'accueil"</string>
-    <string name="allow_rotation_desc" msgid="8662546029078692509">"Lorsque l\'utilisateur fait pivoter le téléphone"</string>
+    <string name="allow_rotation_desc" msgid="8662546029078692509">"Lorsque vous faites pivoter le téléphone"</string>
     <string name="allow_rotation_blocked_desc" msgid="3212602545192996253">"Le paramètre d\'affichage actuel n\'autorise pas la rotation."</string>
     <string name="package_state_unknown" msgid="7592128424511031410">"Inconnu"</string>
     <string name="abandoned_clean_this" msgid="7610119707847920412">"Supprimer"</string>
diff --git a/res/values-sv/strings.xml b/res/values-sv/strings.xml
index c3e60fc..1d405ba 100644
--- a/res/values-sv/strings.xml
+++ b/res/values-sv/strings.xml
@@ -68,7 +68,7 @@
     <string name="msg_disabled_by_admin" msgid="6898038085516271325">"Inaktiverat av administratören"</string>
     <string name="accessibility_action_overview" msgid="6257665857640347026">"Översikt"</string>
     <string name="allow_rotation_title" msgid="7728578836261442095">"Tillåt rotering av startskärmen"</string>
-    <string name="allow_rotation_desc" msgid="8662546029078692509">"När mobilen roterar"</string>
+    <string name="allow_rotation_desc" msgid="8662546029078692509">"När mobilen vrids"</string>
     <string name="allow_rotation_blocked_desc" msgid="3212602545192996253">"Rotering tillåts inte i de nuvarande skärminställningarna"</string>
     <string name="package_state_unknown" msgid="7592128424511031410">"Okänt"</string>
     <string name="abandoned_clean_this" msgid="7610119707847920412">"Ta bort"</string>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 3f2d186..87ef78b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -161,7 +161,7 @@
     <dimen name="deep_shortcuts_spacing">4dp</dimen>
     <dimen name="deep_shortcuts_drag_view_scale">6dp</dimen>
     <!-- an icon with shortcuts must be dragged this far before the container is removed. -->
-    <dimen name="deep_shortcuts_start_drag_threshold">12dp</dimen>
+    <dimen name="deep_shortcuts_start_drag_threshold">16dp</dimen>
     <dimen name="deep_shortcut_icon_size">36dp</dimen>
     <dimen name="deep_shortcut_padding_start">6dp</dimen>
     <dimen name="deep_shortcut_padding_end">16dp</dimen>
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 084de70..6605654 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -171,7 +171,6 @@
 
     @Override
     public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
-        target.itemType = LauncherLogProto.APP_ICON;
         target.gridX = info.cellX;
         target.gridY = info.cellY;
         targetParent.containerType = LauncherLogProto.HOTSEAT;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 5105c1a..6f61688 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -4318,7 +4318,6 @@
 
     @Override
     public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
-        target.itemType = LauncherLogProto.APP_ICON;
         target.gridX = info.cellX;
         target.gridY = info.cellY;
         target.pageIndex = getCurrentPage();
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index 09076b3..25ed3b8 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -209,12 +209,8 @@
 
     @Override
     public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
-        targetParent.containerType = getContainerType(v);
-    }
-
-    public int getContainerType(View v) {
         if (mApps.hasFilter()) {
-            return LauncherLogProto.SEARCHRESULT;
+            targetParent.containerType = LauncherLogProto.SEARCHRESULT;
         } else {
             if (v instanceof BubbleTextView) {
                 BubbleTextView icon = (BubbleTextView) v;
@@ -223,11 +219,12 @@
                     List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
                     AlphabeticalAppsList.AdapterItem item = items.get(position);
                     if (item.viewType == AllAppsGridAdapter.VIEW_TYPE_PREDICTION_ICON) {
-                        return LauncherLogProto.PREDICTION;
+                        targetParent.containerType = LauncherLogProto.PREDICTION;
+                        return;
                     }
                 }
             }
-            return LauncherLogProto.ALLAPPS;
+            targetParent.containerType = LauncherLogProto.ALLAPPS;
         }
     }
 
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 3684136..96da181 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -1428,7 +1428,6 @@
 
     @Override
     public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) {
-        target.itemType = LauncherLogProto.APP_ICON;
         target.gridX = info.cellX;
         target.gridY = info.cellY;
         target.pageIndex = mContent.getCurrentPage();
diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java
index aad266b..dc04597 100644
--- a/src/com/android/launcher3/logging/LoggerUtils.java
+++ b/src/com/android/launcher3/logging/LoggerUtils.java
@@ -1,5 +1,9 @@
 package com.android.launcher3.logging;
 
+import android.view.View;
+
+import com.android.launcher3.ItemInfo;
+import com.android.launcher3.LauncherSettings;
 import com.android.launcher3.userevent.nano.LauncherLogProto;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -47,17 +51,25 @@
             return typeStr;
         }
         switch(t.itemType){
-            case LauncherLogProto.APP_ICON: typeStr = "ICON"; break;
+            case LauncherLogProto.APP_ICON: typeStr = "APPICON"; break;
             case LauncherLogProto.SHORTCUT: typeStr = "SHORTCUT"; break;
             case LauncherLogProto.WIDGET: typeStr = "WIDGET"; break;
             case LauncherLogProto.DEEPSHORTCUT: typeStr = "DEEPSHORTCUT"; break;
+            case LauncherLogProto.FOLDER_ICON: typeStr = "FOLDERICON"; break;
+
             default: typeStr = "UNKNOWN";
         }
 
-        return typeStr + ", packageHash=" + t.packageNameHash
-                + ", componentHash=" + t.componentHash
-                + ", intentHash=" + t.intentHash
-                + ", grid=(" + t.gridX + "," + t.gridY + "), id=" + t.pageIndex;
+        if (t.packageNameHash != 0) {
+            typeStr += ", packageHash=" + t.packageNameHash;
+        }
+        if (t.componentHash != 0) {
+            typeStr += ", componentHash=" + t.componentHash;
+        }
+        if (t.intentHash != 0) {
+            typeStr += ", intentHash=" + t.intentHash;
+        }
+        return typeStr += ", grid=(" + t.gridX + "," + t.gridY + "), id=" + t.pageIndex;
     }
 
     private static String getControlStr(Target t) {
@@ -116,16 +128,17 @@
         return str + " id=" + t.pageIndex;
     }
 
-
+    /**
+     * Used for launching an event by tapping on an icon.
+     */
     public static LauncherLogProto.LauncherEvent initLauncherEvent(
             int actionType,
-            int childTargetType,
+            View v,
             int parentTargetType){
         LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
 
         event.srcTarget = new LauncherLogProto.Target[2];
-        event.srcTarget[0] = new LauncherLogProto.Target();
-        event.srcTarget[0].type = childTargetType;
+        event.srcTarget[0] = initTarget(v);
         event.srcTarget[1] = new LauncherLogProto.Target();
         event.srcTarget[1].type = parentTargetType;
 
@@ -134,6 +147,9 @@
         return event;
     }
 
+    /**
+     * Used for clicking on controls and buttons.
+     */
     public static LauncherLogProto.LauncherEvent initLauncherEvent(
             int actionType,
             int childTargetType){
@@ -147,4 +163,31 @@
         event.action.type = actionType;
         return event;
     }
+
+    private static Target initTarget(View v) {
+        Target t = new LauncherLogProto.Target();
+        t.type = Target.ITEM;
+        if (!(v.getTag() instanceof ItemInfo)) {
+            return t;
+        }
+        ItemInfo itemInfo = (ItemInfo) v.getTag();
+        switch (itemInfo.itemType) {
+            case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
+                t.itemType = LauncherLogProto.APP_ICON;
+                break;
+            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
+                t.itemType = LauncherLogProto.SHORTCUT;
+                break;
+            case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
+                t.itemType = LauncherLogProto.FOLDER_ICON;
+                break;
+            case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
+                t.itemType = LauncherLogProto.WIDGET;
+                break;
+            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
+                t.itemType = LauncherLogProto.DEEPSHORTCUT;
+                break;
+        }
+        return t;
+    }
 }
diff --git a/src/com/android/launcher3/logging/UserEventDispatcher.java b/src/com/android/launcher3/logging/UserEventDispatcher.java
index e780cc9..e4cc182 100644
--- a/src/com/android/launcher3/logging/UserEventDispatcher.java
+++ b/src/com/android/launcher3/logging/UserEventDispatcher.java
@@ -97,13 +97,16 @@
 
     protected LauncherEvent createLauncherEvent(View v, Intent intent) {
         LauncherEvent event = LoggerUtils.initLauncherEvent(
-                Action.TOUCH, Target.ITEM, Target.CONTAINER);
+                Action.TOUCH, v, Target.CONTAINER);
         event.action.touch = Action.TAP;
 
         // Fill in grid(x,y), pageIndex of the child and container type of the parent
         // TODO: make this percolate up the view hierarchy if needed.
         int idx = 0;
         LaunchSourceProvider provider = getLaunchProviderRecursive(v);
+        if (!(v.getTag() instanceof ItemInfo)) {
+            return null;
+        }
         ItemInfo itemInfo = (ItemInfo) v.getTag();
         provider.fillInLaunchSourceData(v, itemInfo, event.srcTarget[idx], event.srcTarget[idx + 1]);
 
@@ -125,7 +128,11 @@
     }
 
     public void logAppLaunch(View v, Intent intent) {
-        dispatchUserEvent(createLauncherEvent(v, intent), intent);
+        LauncherEvent ev = createLauncherEvent(v, intent);
+        if (ev == null) {
+            return;
+        }
+        dispatchUserEvent(ev, intent);
     }
 
     public void logActionOnControl(int action, int controlType) {
@@ -147,21 +154,21 @@
         dispatchUserEvent(event, null);
     }
 
-    public void logDeepShortcutsOpen(int containerType) {
+    public void logDeepShortcutsOpen(View icon) {
         LauncherEvent event = LoggerUtils.initLauncherEvent(
-                Action.TOUCH, Target.ITEM, Target.CONTAINER);
+                Action.TOUCH, icon, Target.CONTAINER);
+        LaunchSourceProvider provider = getLaunchProviderRecursive(icon);
+        if (!(icon.getTag() instanceof ItemInfo)) {
+            return;
+        }
+        ItemInfo info = (ItemInfo) icon.getTag();
+        provider.fillInLaunchSourceData(icon, info, event.srcTarget[0], event.srcTarget[1]);
         event.action.touch = Action.LONGPRESS;
-        event.srcTarget[0].itemType = LauncherLogProto.DEEPSHORTCUT;
-        event.srcTarget[1].containerType = containerType;
         event.elapsedContainerMillis = System.currentTimeMillis() - mElapsedContainerMillis;
         event.elapsedSessionMillis = System.currentTimeMillis() - mElapsedSessionMillis;
         dispatchUserEvent(event, null);
     }
 
-    public void logDragNDrop() {
-        // TODO
-    }
-
     public void setPredictedApps(List<ComponentKey> predictedApps) {
         mPredictedApps = predictedApps;
     }
@@ -185,17 +192,20 @@
     public void dispatchUserEvent(LauncherEvent ev, Intent intent) {
         if (DEBUG_LOGGING) {
             Log.d(TAG, String.format(Locale.US,
-                    "action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
+                    "\naction:%s\n Source child:%s\tparent:%s",
                     LoggerUtils.getActionStr(ev.action),
                     LoggerUtils.getTargetStr(ev.srcTarget != null ? ev.srcTarget[0] : null),
-                    LoggerUtils.getTargetStr(ev.srcTarget.length > 1 ? ev.srcTarget[1] : null),
+                    LoggerUtils.getTargetStr(ev.srcTarget.length > 1 ? ev.srcTarget[1] : null)));
+            if (ev.destTarget != null && ev.destTarget.length > 0) {
+                Log.d(TAG, String.format(Locale.US,
+                        " Destination child:%s\tparent:%s",
+                        LoggerUtils.getTargetStr(ev.destTarget != null ? ev.destTarget[0] : null),
+                        LoggerUtils.getTargetStr(ev.destTarget.length > 1 ? ev.destTarget[1] : null)));
+            }
+            Log.d(TAG, String.format(Locale.US,
+                    " Elapsed container %d ms session %d ms",
                     ev.elapsedContainerMillis,
                     ev.elapsedSessionMillis));
         }
     }
-
-    public int getPredictedRank(ComponentKey key) {
-        if (mPredictedApps == null) return -1;
-        return mPredictedApps.indexOf(key);
-    }
 }
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
index 450d36d..42086fc 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
@@ -17,15 +17,23 @@
 package com.android.launcher3.shortcuts;
 
 import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import android.view.MotionEvent;
 
 import com.android.launcher3.BubbleTextView;
+import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
 
 /**
  * A {@link BubbleTextView} that has the shortcut icon on the left and drag handle on the right.
  */
 public class DeepShortcutTextView extends BubbleTextView {
+    private final Rect mDragHandleBounds = new Rect();
+    private final int mDragHandleWidth;
+    private boolean mShouldPerformClick = true;
 
     public DeepShortcutTextView(Context context) {
         this(context, null, 0);
@@ -37,10 +45,39 @@
 
     public DeepShortcutTextView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+
+        Resources resources = getResources();
+        mDragHandleWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcut_padding_end)
+                + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drag_handle_size)
+                + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drawable_padding) / 2;
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+        mDragHandleBounds.set(0, 0, mDragHandleWidth, getMeasuredHeight());
+        if (!Utilities.isRtl(getResources())) {
+            mDragHandleBounds.offset(getMeasuredWidth() - mDragHandleBounds.width(), 0);
+        }
     }
 
     @Override
     protected void applyCompoundDrawables(Drawable icon) {
         // The icon is drawn in a separate view.
     }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+            // Ignore clicks on the drag handle (long clicks still start the drag).
+            mShouldPerformClick = !mDragHandleBounds.contains((int) ev.getX(), (int) ev.getY());
+        }
+        return super.onTouchEvent(ev);
+    }
+
+    @Override
+    public boolean performClick() {
+        return mShouldPerformClick && super.performClick();
+    }
 }
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
index 2542df6..cfeccfc 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
@@ -33,7 +33,6 @@
 import android.os.Looper;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.Gravity;
 import android.view.HapticFeedbackConstants;
 import android.view.LayoutInflater;
@@ -54,19 +53,16 @@
 import com.android.launcher3.LauncherAnimUtils;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherModel;
-import com.android.launcher3.LauncherSettings;
 import com.android.launcher3.LauncherViewPropertyAnimator;
 import com.android.launcher3.R;
 import com.android.launcher3.ShortcutInfo;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.Workspace;
 import com.android.launcher3.accessibility.ShortcutMenuAccessibilityDelegate;
-import com.android.launcher3.allapps.AllAppsRecyclerView;
 import com.android.launcher3.compat.UserHandleCompat;
 import com.android.launcher3.dragndrop.DragController;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.dragndrop.DragView;
-import com.android.launcher3.folder.Folder;
 import com.android.launcher3.graphics.TriangleShape;
 import com.android.launcher3.logging.UserEventDispatcher;
 import com.android.launcher3.userevent.nano.LauncherLogProto;
@@ -479,6 +475,7 @@
             }
         } else if (action == MotionEvent.ACTION_UP) {
             cleanupDeferredDrag(true);
+            mLauncher.getUserEventDispatcher().logDeepShortcutsOpen(mDeferredDragIcon);
         } else if (action == MotionEvent.ACTION_CANCEL) {
             // Do not change the source icon visibility if we are already dragging the source icon.
             cleanupDeferredDrag(!mSrcIconDragStarted);
@@ -749,33 +746,11 @@
             container.populateAndShow(icon, ids);
             icon.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                     HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
-            logOpen(launcher, icon);
             return container;
         }
         return null;
     }
 
-    private static void logOpen(Launcher launcher, View icon) {
-        ItemInfo info = (ItemInfo) icon.getTag();
-        long iconContainer = info.container;
-        Folder openFolder = launcher.getWorkspace().getOpenFolder();
-        int containerType;
-        if (iconContainer == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
-            containerType = LauncherLogProto.WORKSPACE;
-        } else if (iconContainer == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
-            containerType = LauncherLogProto.HOTSEAT;
-        } else if (openFolder != null && iconContainer == openFolder.getInfo().id) {
-            containerType = LauncherLogProto.FOLDER;
-        } else if (icon.getParent() instanceof AllAppsRecyclerView) {
-            containerType = ((AllAppsRecyclerView) icon.getParent()).getContainerType(icon);
-        } else {
-            // This should not happen.
-            Log.w(TAG, "Couldn't determine parent of shortcut container");
-            containerType = LauncherLogProto.DEFAULT_CONTAINERTYPE;
-        }
-        launcher.getUserEventDispatcher().logDeepShortcutsOpen(containerType);
-    }
-
     /**
      * Extension of {@link ShortcutInfo} which does not badge the icons.
      */