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

Commit 2148d43e authored by Adam Cohen's avatar Adam Cohen
Browse files

Fixing widget notifyDataSetChanged() not getting called, issue 5092676

Change-Id: I61a034a77c0c9d07aba71bfabe7a0864ce92c2e9
parent 6c71b63d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -24705,6 +24705,7 @@ package android.widget {
    method public void beforeTextChanged(java.lang.CharSequence, int, int, int);
    method public void clearChoices();
    method public void clearTextFilter();
    method public void deferNotifyDataSetChanged();
    method public int getCacheColorHint();
    method public int getCheckedItemCount();
    method public long[] getCheckedItemIds();
@@ -24920,6 +24921,7 @@ package android.widget {
    ctor public AdapterViewAnimator(android.content.Context, android.util.AttributeSet);
    ctor public AdapterViewAnimator(android.content.Context, android.util.AttributeSet, int);
    method public void advance();
    method public void deferNotifyDataSetChanged();
    method public void fyiWillBeAdvancedByHostKThx();
    method public android.widget.Adapter getAdapter();
    method public android.view.View getCurrentView();
+6 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.RemoteViewsAdapter.RemoteAdapterConnectionCallback;

/**
 * Provides the glue to show AppWidget views. This class offers automatic animation
@@ -276,6 +277,11 @@ public class AppWidgetHostView extends FrameLayout {
            if (adapter instanceof BaseAdapter) {
                BaseAdapter baseAdapter = (BaseAdapter) adapter;
                baseAdapter.notifyDataSetChanged();
            }  else if (adapter == null && adapterView instanceof RemoteAdapterConnectionCallback) {
                // If the adapter is null, it may mean that the RemoteViewsAapter has not yet
                // connected to its associated service, and hence the adapter hasn't been set.
                // In this case, we need to defer the notify call until it has been set.
                ((RemoteAdapterConnectionCallback) adapterView).deferNotifyDataSetChanged();
            }
        }
    }
+18 −1
Original line number Diff line number Diff line
@@ -260,6 +260,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     */
    private RemoteViewsAdapter mRemoteAdapter;

    /**
     * This flag indicates the a full notify is required when the RemoteViewsAdapter connects
     */
    private boolean mDeferNotifyDataSetChanged = false;

    /**
     * Indicates whether the list selector should be drawn on top of the children or behind
     */
@@ -5392,17 +5397,29 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                return;
            }
        }

        mDeferNotifyDataSetChanged = false;
        // Otherwise, create a new RemoteViewsAdapter for binding
        mRemoteAdapter = new RemoteViewsAdapter(getContext(), intent, this);
    }

    /**
     * This defers a notifyDataSetChanged on the pending RemoteViewsAdapter if it has not
     * connected yet.
     */
    public void deferNotifyDataSetChanged() {
        mDeferNotifyDataSetChanged = true;
    }

    /**
     * Called back when the adapter connects to the RemoteViewsService.
     */
    public boolean onRemoteAdapterConnected() {
        if (mRemoteAdapter != mAdapter) {
            setAdapter(mRemoteAdapter);
            if (mDeferNotifyDataSetChanged) {
                mRemoteAdapter.notifyDataSetChanged();
                mDeferNotifyDataSetChanged = false;
            }
            return false;
        } else if (mRemoteAdapter != null) {
            mRemoteAdapter.superNotifyDataSetChanged();
+22 −5
Original line number Diff line number Diff line
@@ -16,16 +16,12 @@

package android.widget;

import java.util.ArrayList;
import java.util.HashMap;

import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -34,6 +30,9 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Base class for a {@link AdapterView} that will perform animations
 * when switching between its views.
@@ -117,6 +116,11 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
     */
    RemoteViewsAdapter mRemoteViewsAdapter;

    /**
     * The remote adapter containing the data to be displayed by this view to be set
     */
    boolean mDeferNotifyDataSetChanged = false;

    /**
     * Specifies whether this is the first time the animator is showing views
     */
@@ -966,7 +970,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
                return;
            }
        }

        mDeferNotifyDataSetChanged = false;
        // Otherwise, create a new RemoteViewsAdapter for binding
        mRemoteViewsAdapter = new RemoteViewsAdapter(getContext(), intent, this);
    }
@@ -981,6 +985,14 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
        return getViewAtRelativeIndex(mActiveOffset);
    }

    /**
     * This defers a notifyDataSetChanged on the pending RemoteViewsAdapter if it has not
     * connected yet.
     */
    public void deferNotifyDataSetChanged() {
        mDeferNotifyDataSetChanged = true;
    }

    /**
     * Called back when the adapter connects to the RemoteViewsService.
     */
@@ -988,6 +1000,11 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
        if (mRemoteViewsAdapter != mAdapter) {
            setAdapter(mRemoteViewsAdapter);

            if (mDeferNotifyDataSetChanged) {
                mRemoteViewsAdapter.notifyDataSetChanged();
                mDeferNotifyDataSetChanged = false;
            }

            // Restore the previous position (see onRestoreInstanceState)
            if (mRestoreWhichChild > -1) {
                setDisplayedChild(mRestoreWhichChild, false);
+6 −0
Original line number Diff line number Diff line
@@ -92,6 +92,12 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
        public boolean onRemoteAdapterConnected();

        public void onRemoteAdapterDisconnected();

        /**
         * This defers a notifyDataSetChanged on the pending RemoteViewsAdapter if it has not
         * connected yet.
         */
        public void deferNotifyDataSetChanged();
    }

    /**