From 3d9490ab9520ffe3798539ed1626463a7eb6c9e1 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 24 Mar 2015 17:38:42 -0700 Subject: Removing more code with API 21 dependencies. Change-Id: I16c914334ce0694b84626269ae4bb5e83082c739 --- src/com/android/launcher3/CellLayout.java | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/com/android/launcher3/CellLayout.java') diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index eb2aa547d..63afa3091 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -417,10 +417,13 @@ public class CellLayout extends ViewGroup { protected int intersectsValidDropTarget(int id) { LauncherAccessibilityDelegate delegate = LauncherAppState.getInstance().getAccessibilityDelegate(); - LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo(); + if (delegate == null) { + return -1; + } int y = id % mCountY; int x = id / mCountY; + LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo(); if (dragInfo.dragType == DragType.WIDGET) { // For a widget, every cell must be vacant. In addition, we will return any valid @@ -489,10 +492,15 @@ public class CellLayout extends ViewGroup { @Override protected boolean onPerformActionForVirtualView(int viewId, int action, Bundle args) { + LauncherAccessibilityDelegate delegate = + LauncherAppState.getInstance().getAccessibilityDelegate(); + if (delegate == null) { + return false; + } + if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) { String confirmation = getConfirmationForIconDrop(viewId); - LauncherAppState.getInstance().getAccessibilityDelegate() - .handleAccessibleDrop(CellLayout.this, getItemBounds(viewId), confirmation); + delegate.handleAccessibleDrop(CellLayout.this, getItemBounds(viewId), confirmation); return true; } return false; @@ -500,11 +508,16 @@ public class CellLayout extends ViewGroup { @Override public void onClick(View arg0) { + LauncherAccessibilityDelegate delegate = + LauncherAppState.getInstance().getAccessibilityDelegate(); + if (delegate == null) { + return; + } + int viewId = getViewIdAt(mDownX, mDownY); String confirmation = getConfirmationForIconDrop(viewId); - LauncherAppState.getInstance().getAccessibilityDelegate() - .handleAccessibleDrop(CellLayout.this, getItemBounds(viewId), confirmation); + delegate.handleAccessibleDrop(CellLayout.this, getItemBounds(viewId), confirmation); } @Override @@ -533,10 +546,13 @@ public class CellLayout extends ViewGroup { private String getLocationDescriptionForIconDrop(int id) { LauncherAccessibilityDelegate delegate = LauncherAppState.getInstance().getAccessibilityDelegate(); - LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo(); + if (delegate == null) { + return ""; + } int y = id % mCountY; int x = id / mCountY; + LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo(); Resources res = getContext().getResources(); View child = getChildAt(x, y); @@ -555,11 +571,14 @@ public class CellLayout extends ViewGroup { private String getConfirmationForIconDrop(int id) { LauncherAccessibilityDelegate delegate = - LauncherAppState.getInstance().getAccessibilityDelegate(); - LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo(); + LauncherAppState.getInstance().getAccessibilityDelegate(); + if (delegate == null) { + return ""; + } int y = id % mCountY; int x = id / mCountY; + LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo(); Resources res = getContext().getResources(); View child = getChildAt(x, y); -- cgit v1.2.3