/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.support.v13.app;

import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;

import java.util.ArrayList;

/**
 * This is a compatibility version of RemoteViews which simplifies the creation of basic collection
 * widgets (ie. widgets containing {@link android.widget.ListView}, {@link android.widget.GridView},
 * {@link android.widget.StackView} or {@link android.widget.AdapterViewAnimator}). This class
 * provides a compatibility version of the method RemoteViews#setRemoteAdapter(int, ArrayList),
 * introduced in API level 18. For platform versions supporting the new API, this class will act as
 * a simple pass-through, and for prior versions will emulate the new API's behavior.
 *
 * Be sure to include declare {@link RemoteViewsServiceCompat} in your manifest, as specified in
 * the doc for
 * {@link RemoteViewsCompat#setRemoteAdapter(RemoteViews, Context, int, int, ArrayList)}.
 *
 */
public class RemoteViewsCompat {

    static final String EXTRA_VIEW_ID = "android.support.v13.app.EXTRA_VIEW_ID";

    interface RemoteViewsCompatImpl {
        void setRemoteAdapter(RemoteViews rv, Context ctx, int viewId, int widgetId,
                ArrayList<RemoteViews> list);
    }

    static final RemoteViewsCompatImpl IMPL;
    static {
        // TODO: Replace 17 with 18 when the API level gets bumped
        if (android.os.Build.VERSION.SDK_INT < 17) {
            IMPL = new BaseRemoteViewsCompatImpl();
        } else {
            IMPL = new KRemoteViewsCompatImpl();
        }
    }

    /**
     * Compatibility version of RemoteViews#setRemoteAdapter(int, ArrayList).
     *
     * When using this method, it is required that include {@link RemoteViewsServiceCompat}
     * in your manifest:
     *
     * <code>
     *      <service android:name="android.support.v13.app.RemoteViewsServiceCompat"
     *          android:permission="android.permission.BIND_REMOTEVIEWS"
     *          android:exported="false" />
     * </code>
     *
     * @param rv The RemoteViews object.
     * @param ctx Context.
     * @param viewId The id of the AdapterView to which this list of RemoteViews will be applied.
     * @param widgetId The app widget id.
     * @param list The list of RemoteViews which will become the children of the AdapterView.
     */
    public static void setRemoteAdapter(RemoteViews rv, Context ctx, int viewId, int widgetId,
            ArrayList<RemoteViews> list) {
        IMPL.setRemoteAdapter(rv, ctx, viewId, widgetId, list);
    }

    static class BaseRemoteViewsCompatImpl implements RemoteViewsCompatImpl {
        @Override
        public void setRemoteAdapter(RemoteViews rv, Context ctx, int viewId, int widgetId,
                ArrayList<RemoteViews> list) {

            // We embed the widget id and view id into the intent so that it can be used
            // as a unique key for the list of RemoteViews.
            final Intent intent = new Intent(ctx, RemoteViewsServiceCompat.class);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
            intent.putExtra(EXTRA_VIEW_ID, viewId);
            intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

            RemoteViewsListFactory.addOrUpdateListFactory(ctx, intent, widgetId, viewId, list);

            rv.setRemoteAdapter(widgetId, viewId, intent);
        }
    }

    static class KRemoteViewsCompatImpl implements RemoteViewsCompatImpl {
        @Override
        public void setRemoteAdapter(RemoteViews rv, Context ctx, int viewId, int widgetId,
                ArrayList<RemoteViews> list) {
            RemoteViewsCompatK.setRemoteAdapter(rv, viewId, widgetId, list);
        }
    }
}

@@ -989,31 +989,16 @@
  %7B@link 
-android.widget.
 ListView
@@ -1007,31 +1007,16 @@
  %7B@link 
-android.widget.
 GridView
@@ -1017,27 +1017,24 @@
 idView%7D,
-%0A *
  %7B@link 
 android.
@@ -1025,31 +1025,16 @@
  %7B@link 
-android.widget.
 StackVie
@@ -1038,24 +1038,27 @@
 View%7D or
+%0A *
  %7B@link 
 android.
@@ -1049,31 +1049,16 @@
  %7B@link 
-android.widget.
 AdapterV
@@ -1082,19 +1082,16 @@
 is class
-%0A *
  provide
@@ -1129,16 +1129,26 @@
 e method
+%0A * %7B@link
  RemoteV
@@ -1184,20 +1184,18 @@
 rayList)
+%7D
 ,
-%0A *
  introdu
@@ -1227,16 +1227,19 @@
 platform
+%0A *
  version
@@ -1286,19 +1286,16 @@
 l act as
-%0A *
  a simpl
@@ -1323,16 +1323,19 @@
 or prior
+%0A *
  version
@@ -1487,19 +1487,16 @@
  doc for
-%0A *
  %7B@link 
@@ -1506,22 +1506,16 @@
 oteViews
-Compat
 #setRemo
@@ -1528,35 +1528,8 @@
 ter(
-RemoteViews, Context, int, 
 int,
@@ -2186,32 +2186,39 @@
 lity version of 
+%7B@link 
 RemoteViews#setR

Revert 0794d29b: Fix docs build. Do not merge.