Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c022639 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding support for async view loading in RemoteViewsAdapter

> When loadingView is no available, the FirstView is always
loaded on the background thread
> AppWidgetHostView only inflates on the background thread, if
the view has any costly operations

Test: TBD

Change-Id: I701caee7e4e6ba5972d0cf478cb57f8ec950da54
parent 79104efc
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -377,13 +377,13 @@ public class AppWidgetHostView extends FrameLayout {
     * AppWidget provider. Will animate into these new views as needed
     */
    public void updateAppWidget(RemoteViews remoteViews) {
        applyRemoteViews(remoteViews);
        applyRemoteViews(remoteViews, true);
    }

    /**
     * @hide
     */
    protected void applyRemoteViews(RemoteViews remoteViews) {
    protected void applyRemoteViews(RemoteViews remoteViews, boolean useAsyncIfPossible) {
        if (LOGD) Log.d(TAG, "updateAppWidget called mOld=" + mOld);

        boolean recycled = false;
@@ -423,7 +423,7 @@ public class AppWidgetHostView extends FrameLayout {
            mLayoutId = -1;
            mViewMode = VIEW_MODE_DEFAULT;
        } else {
            if (mAsyncExecutor != null) {
            if (mAsyncExecutor != null && useAsyncIfPossible) {
                inflateAsync(remoteViews);
                return;
            }
+12 −1
Original line number Diff line number Diff line
@@ -6284,6 +6284,17 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     * @param intent the intent used to identify the RemoteViewsService for the adapter to connect to.
     */
    public void setRemoteViewsAdapter(Intent intent) {
        setRemoteViewsAdapter(intent, false);
    }

    /** @hide **/
    public Runnable setRemoteViewsAdapterAsync(final Intent intent) {
        return new RemoteViewsAdapter.AsyncRemoteAdapterAction(this, intent);
    }

    /** @hide **/
    @Override
    public void setRemoteViewsAdapter(Intent intent, boolean isAsync) {
        // Ensure that we don't already have a RemoteViewsAdapter that is bound to an existing
        // service handling the specified intent.
        if (mRemoteAdapter != null) {
@@ -6296,7 +6307,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
        mDeferNotifyDataSetChanged = false;
        // Otherwise, create a new RemoteViewsAdapter for binding
        mRemoteAdapter = new RemoteViewsAdapter(getContext(), intent, this);
        mRemoteAdapter = new RemoteViewsAdapter(getContext(), intent, this, isAsync);
        if (mRemoteAdapter.isDataReady()) {
            setAdapter(mRemoteAdapter);
        }
+13 −2
Original line number Diff line number Diff line
@@ -975,8 +975,19 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
     * @param intent the intent used to identify the RemoteViewsService for the adapter to
     *        connect to.
     */
    @android.view.RemotableViewMethod
    @android.view.RemotableViewMethod(asyncImpl="setRemoteViewsAdapterAsync")
    public void setRemoteViewsAdapter(Intent intent) {
        setRemoteViewsAdapter(intent, false);
    }

    /** @hide **/
    public Runnable setRemoteViewsAdapterAsync(final Intent intent) {
        return new RemoteViewsAdapter.AsyncRemoteAdapterAction(this, intent);
    }

    /** @hide **/
    @Override
    public void setRemoteViewsAdapter(Intent intent, boolean isAsync) {
        // Ensure that we don't already have a RemoteViewsAdapter that is bound to an existing
        // service handling the specified intent.
        if (mRemoteViewsAdapter != null) {
@@ -989,7 +1000,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
        }
        mDeferNotifyDataSetChanged = false;
        // Otherwise, create a new RemoteViewsAdapter for binding
        mRemoteViewsAdapter = new RemoteViewsAdapter(getContext(), intent, this);
        mRemoteViewsAdapter = new RemoteViewsAdapter(getContext(), intent, this, isAsync);
        if (mRemoteViewsAdapter.isDataReady()) {
            setAdapter(mRemoteViewsAdapter);
        }
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public class GridView extends AbsListView {
     * through the specified intent.
     * @param intent the intent used to identify the RemoteViewsService for the adapter to connect to.
     */
    @android.view.RemotableViewMethod
    @android.view.RemotableViewMethod(asyncImpl="setRemoteViewsAdapterAsync")
    public void setRemoteViewsAdapter(Intent intent) {
        super.setRemoteViewsAdapter(intent);
    }
+11 −2
Original line number Diff line number Diff line
@@ -455,7 +455,16 @@ public class ImageView extends View {

    /** @hide **/
    public Runnable setImageResourceAsync(@DrawableRes int resId) {
        return new ImageDrawableCallback(getContext().getDrawable(resId), null, resId);
        Drawable d = null;
        if (resId != 0) {
            try {
                d = getContext().getDrawable(resId);
            } catch (Exception e) {
                Log.w(LOG_TAG, "Unable to find resource: " + resId, e);
                resId = 0;
            }
        }
        return new ImageDrawableCallback(d, null, resId);
    }

    /**
@@ -857,7 +866,7 @@ public class ImageView extends View {
            } catch (Exception e) {
                Log.w(LOG_TAG, "Unable to find resource: " + mResource, e);
                // Don't try again.
                mUri = null;
                mResource = 0;
            }
        } else if (mUri != null) {
            d = getDrawableFromUri(mUri);
Loading