Removing more code with API 21 dependencies.

Change-Id: I16c914334ce0694b84626269ae4bb5e83082c739
diff --git a/src/com/android/launcher3/AppsContainerRecyclerView.java b/src/com/android/launcher3/AppsContainerRecyclerView.java
index 4d6b9d4..0cc6514 100644
--- a/src/com/android/launcher3/AppsContainerRecyclerView.java
+++ b/src/com/android/launcher3/AppsContainerRecyclerView.java
@@ -77,8 +77,8 @@
 
         Resources res = context.getResources();
         int fastScrollerSize = res.getDimensionPixelSize(R.dimen.apps_view_fast_scroll_popup_size);
-        mScrollbar = context.getDrawable(R.drawable.apps_list_scrollbar_thumb);
-        mFastScrollerBg = context.getDrawable(R.drawable.apps_list_fastscroll_bg);
+        mScrollbar = res.getDrawable(R.drawable.apps_list_scrollbar_thumb);
+        mFastScrollerBg = res.getDrawable(R.drawable.apps_list_fastscroll_bg);
         mFastScrollerBg.setBounds(0, 0, fastScrollerSize, fastScrollerSize);
         mFastScrollTextPaint = new Paint();
         mFastScrollTextPaint.setColor(Color.WHITE);
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index eb2aa54..63afa30 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -417,10 +417,13 @@
         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 @@
 
         @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 @@
 
         @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 @@
         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 @@
 
         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);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 58c4cf7..4c5bba9 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2448,7 +2448,9 @@
             return;
         }
 
-        if (LauncherAppState.getInstance().getAccessibilityDelegate().onBackPressed()) {
+        LauncherAccessibilityDelegate delegate =
+                LauncherAppState.getInstance().getAccessibilityDelegate();
+        if (delegate != null && delegate.onBackPressed()) {
             return;
         }
 
diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
index e7f49b2..aeef0da 100644
--- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
@@ -7,8 +7,6 @@
 import android.graphics.drawable.Drawable;
 import android.os.Parcel;
 
-import java.lang.reflect.Field;
-
 /**
  * This class is a thin wrapper around the framework AppWidgetProviderInfo class. This class affords
  * a common object for describing both framework provided AppWidgets as well as custom widgets
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index 4a0aaf3..eacf341 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -186,7 +186,8 @@
                     View allAppsButtonView) {
                 // Hide the real page background, and swap in the fake one
                 ((AppsCustomizePagedView) contentView).setPageBackgroundsVisible(false);
-                revealView.setBackground(mLauncher.getDrawable(R.drawable.quantum_panel_dark));
+                revealView.setBackground(
+                        mLauncher.getResources().getDrawable(R.drawable.quantum_panel_dark));
             }
             @Override
             public void onAnimationComplete(View revealView, View contentView, View allAppsButtonView) {
@@ -508,7 +509,8 @@
                 // Hide the real page background, and swap in the fake one
                 pagedView.stopScrolling();
                 pagedView.setPageBackgroundsVisible(false);
-                revealView.setBackground(mLauncher.getDrawable(R.drawable.quantum_panel_dark));
+                revealView.setBackground(
+                        mLauncher.getResources().getDrawable(R.drawable.quantum_panel_dark));
 
                 // Hide the side pages of the Widget tray to avoid some ugly edge cases
                 final View currentPage = pagedView.getPageAt(pagedView.getNextPage());
diff --git a/src/com/android/launcher3/WidgetsContainerView.java b/src/com/android/launcher3/WidgetsContainerView.java
index d0dd733..7004d8b 100644
--- a/src/com/android/launcher3/WidgetsContainerView.java
+++ b/src/com/android/launcher3/WidgetsContainerView.java
@@ -75,11 +75,7 @@
     }
 
     public WidgetsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
-        this(context, attrs, defStyleAttr, 0);
-    }
-
-    public WidgetsContainerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
-        super(context, attrs, defStyleAttr, defStyleRes);
+        super(context, attrs, defStyleAttr);
     }
 
     @Override
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 7d6f59b..92e0132 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -576,7 +576,9 @@
         mScreenOrder.add(insertIndex, screenId);
         addView(newScreen, insertIndex);
 
-        if (LauncherAppState.getInstance().getAccessibilityDelegate().isInAccessibleDrag()) {
+        LauncherAccessibilityDelegate delegate =
+                LauncherAppState.getInstance().getAccessibilityDelegate();
+        if (delegate != null && delegate.isInAccessibleDrag()) {
             newScreen.enableAccessibleDrag(true);
         }
         return screenId;