First pass on accessibility

-> issue 10801717
-> issue 11012432
-> issue 11012764

Change-Id: I9a687a39a358441afd57c0c46b57399ecbf23c36
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index c8e34dd..96d8c19 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -32,6 +32,7 @@
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.support.v4.view.accessibility.AccessibilityEventCompat;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.Log;
@@ -334,6 +335,8 @@
     }
 
     protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+
         // Hook up the page indicator
         ViewGroup parent = (ViewGroup) getParent();
         if (mPageIndicator == null && mPageIndicatorViewId > -1) {
@@ -347,9 +350,19 @@
             }
 
             mPageIndicator.addMarkers(markers, mAllowPagedViewAnimations);
+            mPageIndicator.setOnClickListener(getPageIndicatorClickListener());
+            mPageIndicator.setContentDescription(getPageIndicatorDescription());
         }
     }
 
+    protected String getPageIndicatorDescription() {
+        return getCurrentPageDescription();
+    }
+
+    protected OnClickListener getPageIndicatorClickListener() {
+        return null;
+    }
+
     protected void onDetachedFromWindow() {
         // Unhook the page indicator
         mPageIndicator = null;
@@ -649,6 +662,28 @@
         }
     }
 
+    private void sendScrollAccessibilityEvent() {
+        AccessibilityManager am =
+                (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
+        if (am.isEnabled()) {
+            AccessibilityEvent ev =
+                    AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
+            ev.getText().add("");
+            ev.setItemCount(getChildCount());
+            ev.setFromIndex(mCurrentPage);
+            int action = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
+
+            if (getNextPage() >= mCurrentPage) {
+                action = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
+            } else {
+                action = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
+            }
+
+            ev.setAction(action);
+            sendAccessibilityEventUnchecked(ev);
+        }
+    }
+
     // we moved this functionality to a helper function so SmoothPagedView can reuse it
     protected boolean computeScrollHelper() {
         if (mScroller.computeScrollOffset()) {
@@ -663,6 +698,8 @@
             invalidate();
             return true;
         } else if (mNextPage != INVALID_PAGE) {
+            sendScrollAccessibilityEvent();
+
             mCurrentPage = Math.max(0, Math.min(mNextPage, getPageCount() - 1));
             mNextPage = INVALID_PAGE;
             notifyPageSwitchListener();
@@ -680,14 +717,11 @@
             }
 
             onPostReorderingAnimationCompleted();
-            // Notify the user when the page changes
-            AccessibilityManager accessibilityManager = (AccessibilityManager)
+            AccessibilityManager am = (AccessibilityManager)
                     getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
-            if (accessibilityManager.isEnabled()) {
-                AccessibilityEvent ev =
-                    AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
-                ev.getText().add(getCurrentPageDescription());
-                sendAccessibilityEventUnchecked(ev);
+            if (am.isEnabled()) {
+                // Notify the user when the page changes
+                announceForAccessibility(getCurrentPageDescription());
             }
             return true;
         }
@@ -2133,6 +2167,8 @@
             focusedChild.clearFocus();
         }
 
+        sendScrollAccessibilityEvent();
+
         pageBeginMoving();
         awakenScrollBars(duration);
         if (immediate) {
@@ -2719,11 +2755,6 @@
     public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
         super.onInitializeAccessibilityEvent(event);
         event.setScrollable(true);
-        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
-            event.setFromIndex(mCurrentPage);
-            event.setToIndex(mCurrentPage);
-            event.setItemCount(getChildCount());
-        }
     }
 
     @Override