Add some interfaces

Add interfaces to AccessibilityManagerCompat and SearchViewCompat which
define methods previously defined in abstract classes. Make the abstract
classes present before implement the newly added interfaces. Change
method signatures accordingly.

Bug: 29391240
Change-Id: I1ff17ebfbb37f4b77f8f182ef82261b35a32cf25
diff --git a/api/current.txt b/api/current.txt
index 4b9459e..5969a36 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -6544,18 +6544,21 @@
   }
 
   public final class AccessibilityManagerCompat {
-    method public static boolean addAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager, android.support.v4.view.accessibility.AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat);
+    method public static boolean addAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager, android.support.v4.view.accessibility.AccessibilityManagerCompat.AccessibilityStateChangeListener);
     method public static java.util.List<android.accessibilityservice.AccessibilityServiceInfo> getEnabledAccessibilityServiceList(android.view.accessibility.AccessibilityManager, int);
     method public static java.util.List<android.accessibilityservice.AccessibilityServiceInfo> getInstalledAccessibilityServiceList(android.view.accessibility.AccessibilityManager);
     method public static boolean isTouchExplorationEnabled(android.view.accessibility.AccessibilityManager);
-    method public static boolean removeAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager, android.support.v4.view.accessibility.AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat);
+    method public static boolean removeAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager, android.support.v4.view.accessibility.AccessibilityManagerCompat.AccessibilityStateChangeListener);
   }
 
-  public static abstract class AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat {
-    ctor public AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat();
+  public static abstract interface AccessibilityManagerCompat.AccessibilityStateChangeListener {
     method public abstract void onAccessibilityStateChanged(boolean);
   }
 
+  public static abstract deprecated class AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat implements android.support.v4.view.accessibility.AccessibilityManagerCompat.AccessibilityStateChangeListener {
+    ctor public AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat();
+  }
+
   public class AccessibilityNodeInfoCompat {
     ctor public AccessibilityNodeInfoCompat(java.lang.Object);
     method public void addAction(int);
@@ -7181,8 +7184,8 @@
     method public static void setImeOptions(android.view.View, int);
     method public static void setInputType(android.view.View, int);
     method public static void setMaxWidth(android.view.View, int);
-    method public static void setOnCloseListener(android.view.View, android.support.v4.widget.SearchViewCompat.OnCloseListenerCompat);
-    method public static void setOnQueryTextListener(android.view.View, android.support.v4.widget.SearchViewCompat.OnQueryTextListenerCompat);
+    method public static void setOnCloseListener(android.view.View, android.support.v4.widget.SearchViewCompat.OnCloseListener);
+    method public static void setOnQueryTextListener(android.view.View, android.support.v4.widget.SearchViewCompat.OnQueryTextListener);
     method public static void setQuery(android.view.View, java.lang.CharSequence, boolean);
     method public static void setQueryHint(android.view.View, java.lang.CharSequence);
     method public static void setQueryRefinementEnabled(android.view.View, boolean);
@@ -7190,12 +7193,21 @@
     method public static void setSubmitButtonEnabled(android.view.View, boolean);
   }
 
-  public static abstract class SearchViewCompat.OnCloseListenerCompat {
+  public static abstract interface SearchViewCompat.OnCloseListener {
+    method public abstract boolean onClose();
+  }
+
+  public static abstract deprecated class SearchViewCompat.OnCloseListenerCompat implements android.support.v4.widget.SearchViewCompat.OnCloseListener {
     ctor public SearchViewCompat.OnCloseListenerCompat();
     method public boolean onClose();
   }
 
-  public static abstract class SearchViewCompat.OnQueryTextListenerCompat {
+  public static abstract interface SearchViewCompat.OnQueryTextListener {
+    method public abstract boolean onQueryTextChange(java.lang.String);
+    method public abstract boolean onQueryTextSubmit(java.lang.String);
+  }
+
+  public static abstract deprecated class SearchViewCompat.OnQueryTextListenerCompat implements android.support.v4.widget.SearchViewCompat.OnQueryTextListener {
     ctor public SearchViewCompat.OnQueryTextListenerCompat();
     method public boolean onQueryTextChange(java.lang.String);
     method public boolean onQueryTextSubmit(java.lang.String);
diff --git a/compat/ics/android/support/v4/view/accessibility/AccessibilityManagerCompatIcs.java b/compat/ics/android/support/v4/view/accessibility/AccessibilityManagerCompatIcs.java
index 4d4e024..3b5be26 100644
--- a/compat/ics/android/support/v4/view/accessibility/AccessibilityManagerCompatIcs.java
+++ b/compat/ics/android/support/v4/view/accessibility/AccessibilityManagerCompatIcs.java
@@ -27,30 +27,53 @@
  */
 class AccessibilityManagerCompatIcs {
 
-    interface AccessibilityStateChangeListenerBridge {
-        public void onAccessibilityStateChanged(boolean enabled);
+    public static class AccessibilityStateChangeListenerWrapper
+            implements AccessibilityStateChangeListener {
+        Object mListener;
+        AccessibilityStateChangeListenerBridge mListenerBridge;
+
+        public AccessibilityStateChangeListenerWrapper(Object listener,
+                AccessibilityStateChangeListenerBridge listenerBridge) {
+            mListener = listener;
+            mListenerBridge = listenerBridge;
+        }
+
+        @Override
+        public int hashCode() {
+            return mListener == null ? 0 : mListener.hashCode();
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+            AccessibilityStateChangeListenerWrapper other =
+                    (AccessibilityStateChangeListenerWrapper) o;
+            return mListener == null ? other.mListener == null : mListener.equals(other.mListener);
+        }
+
+        @Override
+        public void onAccessibilityStateChanged(boolean enabled) {
+            mListenerBridge.onAccessibilityStateChanged(enabled);
+        }
     }
 
-    public static Object newAccessibilityStateChangeListener(
-            final AccessibilityStateChangeListenerBridge bridge) {
-        return new AccessibilityStateChangeListener() {
-            @Override
-            public void onAccessibilityStateChanged(boolean enabled) {
-                bridge.onAccessibilityStateChanged(enabled);
-            }
-        };
+    interface AccessibilityStateChangeListenerBridge {
+        void onAccessibilityStateChanged(boolean enabled);
     }
 
     public static boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
-            Object listener) {
-        return manager.addAccessibilityStateChangeListener(
-                (AccessibilityStateChangeListener)listener);
+            AccessibilityStateChangeListenerWrapper listener) {
+        return manager.addAccessibilityStateChangeListener(listener);
     }
 
     public static boolean removeAccessibilityStateChangeListener(AccessibilityManager manager,
-            Object listener) {
-        return manager.removeAccessibilityStateChangeListener(
-                (AccessibilityStateChangeListener)listener);
+            AccessibilityStateChangeListenerWrapper listener) {
+        return manager.removeAccessibilityStateChangeListener(listener);
     }
 
     public static List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(
diff --git a/compat/java/android/support/v4/view/accessibility/AccessibilityManagerCompat.java b/compat/java/android/support/v4/view/accessibility/AccessibilityManagerCompat.java
index 734c246c..3ced556 100644
--- a/compat/java/android/support/v4/view/accessibility/AccessibilityManagerCompat.java
+++ b/compat/java/android/support/v4/view/accessibility/AccessibilityManagerCompat.java
@@ -19,6 +19,7 @@
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.os.Build;
 import android.support.v4.view.accessibility.AccessibilityManagerCompatIcs.AccessibilityStateChangeListenerBridge;
+import android.support.v4.view.accessibility.AccessibilityManagerCompatIcs.AccessibilityStateChangeListenerWrapper;
 import android.view.accessibility.AccessibilityManager;
 
 import java.util.Collections;
@@ -31,35 +32,35 @@
 public final class AccessibilityManagerCompat {
 
     interface AccessibilityManagerVersionImpl {
-        public Object newAccessiblityStateChangeListener(
-                AccessibilityStateChangeListenerCompat listener);
-        public boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
-                AccessibilityStateChangeListenerCompat listener);
-        public boolean removeAccessibilityStateChangeListener(AccessibilityManager manager,
-                AccessibilityStateChangeListenerCompat listener);
-        public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(
+        AccessibilityStateChangeListenerWrapper newAccessiblityStateChangeListener(
+                AccessibilityStateChangeListener listener);
+        boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
+                AccessibilityStateChangeListener listener);
+        boolean removeAccessibilityStateChangeListener(AccessibilityManager manager,
+                AccessibilityStateChangeListener listener);
+        List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(
                 AccessibilityManager manager,int feedbackTypeFlags);
-        public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList(
+        List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList(
                 AccessibilityManager manager);
-        public boolean isTouchExplorationEnabled(AccessibilityManager manager);
+        boolean isTouchExplorationEnabled(AccessibilityManager manager);
     }
 
     static class AccessibilityManagerStubImpl implements AccessibilityManagerVersionImpl {
         @Override
-        public Object newAccessiblityStateChangeListener(
-                AccessibilityStateChangeListenerCompat listener) {
+        public AccessibilityStateChangeListenerWrapper newAccessiblityStateChangeListener(
+                AccessibilityStateChangeListener listener) {
             return null;
         }
 
         @Override
         public boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
-                AccessibilityStateChangeListenerCompat listener) {
+                AccessibilityStateChangeListener listener) {
             return false;
         }
 
         @Override
         public boolean removeAccessibilityStateChangeListener(AccessibilityManager manager,
-                AccessibilityStateChangeListenerCompat listener) {
+                AccessibilityStateChangeListener listener) {
             return false;
         }
 
@@ -82,31 +83,30 @@
     }
 
     static class AccessibilityManagerIcsImpl extends AccessibilityManagerStubImpl {
-        
         @Override
-        public Object newAccessiblityStateChangeListener(
-                final AccessibilityStateChangeListenerCompat listener) {
-            return AccessibilityManagerCompatIcs.newAccessibilityStateChangeListener(
-                new AccessibilityStateChangeListenerBridge() {
-                    @Override
-                    public void onAccessibilityStateChanged(boolean enabled) {
-                        listener.onAccessibilityStateChanged(enabled);
-                    }
-                });
+        public AccessibilityStateChangeListenerWrapper newAccessiblityStateChangeListener(
+                final AccessibilityStateChangeListener listener) {
+            return new AccessibilityStateChangeListenerWrapper(listener,
+                    new AccessibilityStateChangeListenerBridge() {
+                        @Override
+                        public void onAccessibilityStateChanged(boolean enabled) {
+                            listener.onAccessibilityStateChanged(enabled);
+                        }
+                    });
         }
 
         @Override
         public boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
-                AccessibilityStateChangeListenerCompat listener) {
+                AccessibilityStateChangeListener listener) {
             return AccessibilityManagerCompatIcs.addAccessibilityStateChangeListener(manager,
-                    listener.mListener);
+                    newAccessiblityStateChangeListener(listener));
         }
 
         @Override
         public boolean removeAccessibilityStateChangeListener(AccessibilityManager manager,
-                final AccessibilityStateChangeListenerCompat listener) {
+                AccessibilityStateChangeListener listener) {
             return AccessibilityManagerCompatIcs.removeAccessibilityStateChangeListener(manager,
-                    listener.mListener);
+                    newAccessiblityStateChangeListener(listener));
         }
 
         @Override
@@ -147,7 +147,7 @@
      * @return True if successfully registered.
      */
     public static boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
-            AccessibilityStateChangeListenerCompat listener) {
+            AccessibilityStateChangeListener listener) {
         return IMPL.addAccessibilityStateChangeListener(manager, listener);
     }
 
@@ -159,7 +159,7 @@
      * @return True if successfully unregistered.
      */
     public static boolean removeAccessibilityStateChangeListener(AccessibilityManager manager,
-            AccessibilityStateChangeListenerCompat listener) {
+            AccessibilityStateChangeListener listener) {
         return IMPL.removeAccessibilityStateChangeListener(manager, listener);
     }
 
@@ -204,21 +204,23 @@
     }
 
     /**
+     * @deprecated Use {@link AccessibilityStateChangeListener} instead.
+     */
+    @Deprecated
+    public static abstract class AccessibilityStateChangeListenerCompat
+            implements AccessibilityStateChangeListener {
+    }
+
+    /**
      * Listener for the accessibility state.
      */
-    public static abstract class AccessibilityStateChangeListenerCompat {
-        final Object mListener;
-
-        public AccessibilityStateChangeListenerCompat() {
-            mListener = IMPL.newAccessiblityStateChangeListener(this);
-        }
-
+    public interface AccessibilityStateChangeListener {
         /**
          * Called back on change in the accessibility state.
          *
          * @param enabled Whether accessibility is enabled.
          */
-        public abstract void onAccessibilityStateChanged(boolean enabled);
+        void onAccessibilityStateChanged(boolean enabled);
     }
 
     private AccessibilityManagerCompat() {}
diff --git a/compat/java/android/support/v4/widget/SearchViewCompat.java b/compat/java/android/support/v4/widget/SearchViewCompat.java
index 48fbc5b..2b69f55 100644
--- a/compat/java/android/support/v4/widget/SearchViewCompat.java
+++ b/compat/java/android/support/v4/widget/SearchViewCompat.java
@@ -34,10 +34,10 @@
         void setSearchableInfo(View searchView, ComponentName searchableComponent);
         void setImeOptions(View searchView, int imeOptions);
         void setInputType(View searchView, int inputType);
-        Object newOnQueryTextListener(OnQueryTextListenerCompat listener);
-        void setOnQueryTextListener(View searchView, Object listener);
-        Object newOnCloseListener(OnCloseListenerCompat listener);
-        void setOnCloseListener(View searchView, Object listener);
+        Object newOnQueryTextListener(OnQueryTextListener listener);
+        void setOnQueryTextListener(View searchView, OnQueryTextListener listener);
+        Object newOnCloseListener(OnCloseListener listener);
+        void setOnCloseListener(View searchView, OnCloseListener listener);
         CharSequence getQuery(View searchView);
         void setQuery(View searchView, CharSequence query, boolean submit);
         void setQueryHint(View searchView, CharSequence hint);
@@ -70,21 +70,21 @@
         }
 
         @Override
-        public Object newOnQueryTextListener(OnQueryTextListenerCompat listener) {
+        public Object newOnQueryTextListener(OnQueryTextListener listener) {
             return null;
         }
 
         @Override
-        public void setOnQueryTextListener(View searchView, Object listener) {
+        public void setOnQueryTextListener(View searchView, OnQueryTextListener listener) {
         }
 
         @Override
-        public Object newOnCloseListener(OnCloseListenerCompat listener) {
+        public Object newOnCloseListener(OnCloseListener listener) {
             return null;
         }
 
         @Override
-        public void setOnCloseListener(View searchView, Object listener) {
+        public void setOnCloseListener(View searchView, OnCloseListener listener) {
         }
 
         @Override
@@ -146,7 +146,7 @@
         }
 
         @Override
-        public Object newOnQueryTextListener(final OnQueryTextListenerCompat listener) {
+        public Object newOnQueryTextListener(final OnQueryTextListener listener) {
             return SearchViewCompatHoneycomb.newOnQueryTextListener(
                     new SearchViewCompatHoneycomb.OnQueryTextListenerCompatBridge() {
                         @Override
@@ -161,13 +161,14 @@
         }
 
         @Override
-        public void setOnQueryTextListener(View searchView, Object listener) {
+        public void setOnQueryTextListener(View searchView, OnQueryTextListener listener) {
             checkIfLegalArg(searchView);
-            SearchViewCompatHoneycomb.setOnQueryTextListener(searchView, listener);
+            SearchViewCompatHoneycomb.setOnQueryTextListener(searchView,
+                    newOnQueryTextListener(listener));
         }
 
         @Override
-        public Object newOnCloseListener(final OnCloseListenerCompat listener) {
+        public Object newOnCloseListener(final OnCloseListener listener) {
             return SearchViewCompatHoneycomb.newOnCloseListener(
                     new SearchViewCompatHoneycomb.OnCloseListenerCompatBridge() {
                         @Override
@@ -178,9 +179,9 @@
         }
 
         @Override
-        public void setOnCloseListener(View searchView, Object listener) {
+        public void setOnCloseListener(View searchView, OnCloseListener listener) {
             checkIfLegalArg(searchView);
-            SearchViewCompatHoneycomb.setOnCloseListener(searchView, listener);
+            SearchViewCompatHoneycomb.setOnCloseListener(searchView, newOnCloseListener(listener));
         }
 
         @Override
@@ -342,20 +343,30 @@
      * @param listener the listener object that receives callbacks when the user performs
      *     actions in the SearchView such as clicking on buttons or typing a query.
      */
-    public static void setOnQueryTextListener(View searchView, OnQueryTextListenerCompat listener) {
-        IMPL.setOnQueryTextListener(searchView, listener.mListener);
+    public static void setOnQueryTextListener(View searchView, OnQueryTextListener listener) {
+        IMPL.setOnQueryTextListener(searchView, listener);
+    }
+
+    /**
+     * @deprecated Use {@link OnQueryTextListener} instead.
+     */
+    @Deprecated
+    public static abstract class OnQueryTextListenerCompat implements OnQueryTextListener {
+        @Override
+        public boolean onQueryTextSubmit(String query) {
+            return false;
+        }
+
+        @Override
+        public boolean onQueryTextChange(String newText) {
+            return false;
+        }
     }
 
     /**
      * Callbacks for changes to the query text.
      */
-    public static abstract class OnQueryTextListenerCompat {
-        final Object mListener;
-
-        public OnQueryTextListenerCompat() {
-            mListener = IMPL.newOnQueryTextListener(this);
-        }
-
+    public interface OnQueryTextListener {
         /**
          * Called when the user submits the query. This could be due to a key press on the
          * keyboard or due to pressing a submit button.
@@ -368,9 +379,7 @@
          * @return true if the query has been handled by the listener, false to let the
          * SearchView perform the default action.
          */
-        public boolean onQueryTextSubmit(String query) {
-            return false;
-        }
+        boolean onQueryTextSubmit(String query);
 
         /**
          * Called when the query text is changed by the user.
@@ -380,9 +389,7 @@
          * @return false if the SearchView should perform the default action of showing any
          * suggestions if available, true if the action was handled by the listener.
          */
-        public boolean onQueryTextChange(String newText) {
-            return false;
-        }
+        boolean onQueryTextChange(String newText);
     }
 
     /**
@@ -391,29 +398,32 @@
      * @param searchView The SearchView in which to register the listener.
      * @param listener the listener to call when the user closes the SearchView.
      */
-    public static void setOnCloseListener(View searchView, OnCloseListenerCompat listener) {
-        IMPL.setOnCloseListener(searchView, listener.mListener);
+    public static void setOnCloseListener(View searchView, OnCloseListener listener) {
+        IMPL.setOnCloseListener(searchView, listener);
+    }
+
+    /**
+     * @deprecated Use {@link OnCloseListener} instead.
+     */
+    @Deprecated
+    public static abstract class OnCloseListenerCompat implements OnCloseListener {
+        @Override
+        public boolean onClose() {
+            return false;
+        }
     }
 
     /**
      * Callback for closing the query UI.
      */
-    public static abstract class OnCloseListenerCompat {
-        final Object mListener;
-
-        public OnCloseListenerCompat() {
-            mListener = IMPL.newOnCloseListener(this);
-        }
-
+    public interface OnCloseListener {
         /**
          * The user is attempting to close the SearchView.
          *
          * @return true if the listener wants to override the default behavior of clearing the
          * text field and dismissing it, false otherwise.
          */
-        public boolean onClose() {
-            return false;
-        }
+        boolean onClose();
     }
 
     /**