3636import android .view .View ;
3737import android .view .View .MeasureSpec ;
3838import android .view .ViewGroup ;
39+ import android .widget .RemoteViews .OnClickHandler ;
3940
4041import com .android .internal .widget .IRemoteViewsAdapterConnection ;
4142import com .android .internal .widget .IRemoteViewsFactory ;
@@ -68,6 +69,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
6869 private LayoutInflater mLayoutInflater ;
6970 private RemoteViewsAdapterServiceConnection mServiceConnection ;
7071 private WeakReference <RemoteAdapterConnectionCallback > mCallback ;
72+ private OnClickHandler mRemoteViewsOnClickHandler ;
7173 private FixedSizeRemoteViewsCache mCache ;
7274 private int mVisibleWindowLowerBound ;
7375 private int mVisibleWindowUpperBound ;
@@ -277,11 +279,11 @@ public RemoteViewsFrameLayout(Context context) {
277279 * @param view the RemoteViews that was loaded. If null, the RemoteViews was not loaded
278280 * successfully.
279281 */
280- public void onRemoteViewsLoaded (RemoteViews view ) {
282+ public void onRemoteViewsLoaded (RemoteViews view , OnClickHandler handler ) {
281283 try {
282284 // Remove all the children of this layout first
283285 removeAllViews ();
284- addView (view .apply (getContext (), this ));
286+ addView (view .apply (getContext (), this , handler ));
285287 } catch (Exception e ) {
286288 Log .e (TAG , "Failed to apply RemoteViews." );
287289 }
@@ -330,7 +332,7 @@ public void notifyOnRemoteViewsLoaded(int position, RemoteViews view) {
330332 // Notify all the references for that position of the newly loaded RemoteViews
331333 final LinkedList <RemoteViewsFrameLayout > refs = mReferences .get (pos );
332334 for (final RemoteViewsFrameLayout ref : refs ) {
333- ref .onRemoteViewsLoaded (view );
335+ ref .onRemoteViewsLoaded (view , mRemoteViewsOnClickHandler );
334336 }
335337 refs .clear ();
336338
@@ -421,7 +423,8 @@ public boolean isViewTypeInRange(int typeId) {
421423 }
422424
423425 private RemoteViewsFrameLayout createLoadingView (int position , View convertView ,
424- ViewGroup parent , Object lock , LayoutInflater layoutInflater ) {
426+ ViewGroup parent , Object lock , LayoutInflater layoutInflater , OnClickHandler
427+ handler ) {
425428 // Create and return a new FrameLayout, and setup the references for this position
426429 final Context context = parent .getContext ();
427430 RemoteViewsFrameLayout layout = new RemoteViewsFrameLayout (context );
@@ -433,7 +436,8 @@ private RemoteViewsFrameLayout createLoadingView(int position, View convertView,
433436 if (mUserLoadingView != null ) {
434437 // Try to inflate user-specified loading view
435438 try {
436- View loadingView = mUserLoadingView .apply (parent .getContext (), parent );
439+ View loadingView = mUserLoadingView .apply (parent .getContext (), parent ,
440+ handler );
437441 loadingView .setTagInternal (com .android .internal .R .id .rowTypeId ,
438442 new Integer (0 ));
439443 layout .addView (loadingView );
@@ -448,7 +452,7 @@ private RemoteViewsFrameLayout createLoadingView(int position, View convertView,
448452 // Use the size of the first row as a guide for the size of the loading view
449453 if (mFirstViewHeight < 0 ) {
450454 try {
451- View firstView = mFirstView .apply (parent .getContext (), parent );
455+ View firstView = mFirstView .apply (parent .getContext (), parent , handler );
452456 firstView .measure (
453457 MeasureSpec .makeMeasureSpec (0 , MeasureSpec .UNSPECIFIED ),
454458 MeasureSpec .makeMeasureSpec (0 , MeasureSpec .UNSPECIFIED ));
@@ -815,6 +819,10 @@ public boolean isDataReady() {
815819 return mDataReady ;
816820 }
817821
822+ public void setRemoteViewsOnClickHandler (OnClickHandler handler ) {
823+ mRemoteViewsOnClickHandler = handler ;
824+ }
825+
818826 public void saveRemoteViewsCache () {
819827 final Pair <Intent .FilterComparison , Integer > key = new Pair <Intent .FilterComparison ,
820828 Integer > (new Intent .FilterComparison (mIntent ), mAppWidgetId );
@@ -1102,7 +1110,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
11021110 // Reuse the convert view where possible
11031111 if (layout != null ) {
11041112 if (convertViewTypeId == typeId ) {
1105- rv .reapply (context , convertViewChild );
1113+ rv .reapply (context , convertViewChild , mRemoteViewsOnClickHandler );
11061114 return layout ;
11071115 }
11081116 layout .removeAllViews ();
@@ -1111,7 +1119,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
11111119 }
11121120
11131121 // Otherwise, create a new view to be returned
1114- View newView = rv .apply (context , parent );
1122+ View newView = rv .apply (context , parent , mRemoteViewsOnClickHandler );
11151123 newView .setTagInternal (com .android .internal .R .id .rowTypeId ,
11161124 new Integer (typeId ));
11171125 layout .addView (newView );
@@ -1127,7 +1135,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
11271135 final RemoteViewsMetaData metaData = mCache .getMetaData ();
11281136 synchronized (metaData ) {
11291137 loadingView = metaData .createLoadingView (position , convertView , parent ,
1130- mCache , mLayoutInflater );
1138+ mCache , mLayoutInflater , mRemoteViewsOnClickHandler );
11311139 }
11321140 return loadingView ;
11331141 } finally {
@@ -1140,7 +1148,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
11401148 final RemoteViewsMetaData metaData = mCache .getMetaData ();
11411149 synchronized (metaData ) {
11421150 loadingView = metaData .createLoadingView (position , convertView , parent ,
1143- mCache , mLayoutInflater );
1151+ mCache , mLayoutInflater , mRemoteViewsOnClickHandler );
11441152 }
11451153
11461154 mRequestedViews .add (position , loadingView );
0 commit comments