2020
2121import android .content .Context ;
2222import android .content .Intent ;
23- import android .content .pm .ActivityInfo ;
2423import android .content .pm .PackageManager ;
2524import android .content .pm .ResolveInfo ;
26- import android .content .res .Configuration ;
2725import android .content .res .Resources ;
2826import android .content .res .TypedArray ;
2927import android .database .DataSetObserver ;
@@ -175,11 +173,6 @@ public void onGlobalLayout() {
175173 */
176174 private int mDefaultActionButtonContentDescription ;
177175
178- /**
179- * Whether this view has a default activity affordance.
180- */
181- private boolean mHasDefaultActivity ;
182-
183176 /**
184177 * Create a new instance.
185178 *
@@ -252,8 +245,6 @@ public void onChanged() {
252245 Resources resources = context .getResources ();
253246 mListPopupMaxWidth = Math .max (resources .getDisplayMetrics ().widthPixels / 2 ,
254247 resources .getDimensionPixelSize (com .android .internal .R .dimen .config_prefDialogWidth ));
255-
256- updateHasDefaultActivity ();
257248 }
258249
259250 /**
@@ -267,21 +258,6 @@ public void setActivityChooserModel(ActivityChooserModel dataModel) {
267258 }
268259 }
269260
270- @ Override
271- protected void onConfigurationChanged (Configuration newConfig ) {
272- Configuration oldConfig = mContext .getResources ().getConfiguration ();
273- final int changed = oldConfig .diff (newConfig );
274- if ((changed & ActivityInfo .CONFIG_SCREEN_SIZE ) != 0
275- || (changed & ActivityInfo .CONFIG_ORIENTATION ) != 0 ) {
276- updateHasDefaultActivity ();
277- }
278- }
279-
280- private void updateHasDefaultActivity () {
281- mHasDefaultActivity = mContext .getResources ().getBoolean (
282- R .bool .activity_chooser_view_has_default_activity );
283- }
284-
285261 /**
286262 * Sets the background for the button that expands the activity
287263 * overflow list.
@@ -407,8 +383,7 @@ public boolean isShowingPopup() {
407383 protected void onAttachedToWindow () {
408384 super .onAttachedToWindow ();
409385 ActivityChooserModel dataModel = mAdapter .getDataModel ();
410- if (dataModel != null
411- && !dataModel .isRegisteredObserver (mModelDataSetOberver )) {
386+ if (dataModel != null ) {
412387 dataModel .registerObserver (mModelDataSetOberver );
413388 }
414389 mIsAttachedToWindow = true ;
@@ -418,8 +393,7 @@ protected void onAttachedToWindow() {
418393 protected void onDetachedFromWindow () {
419394 super .onDetachedFromWindow ();
420395 ActivityChooserModel dataModel = mAdapter .getDataModel ();
421- if (dataModel != null
422- && dataModel .isRegisteredObserver (mModelDataSetOberver )) {
396+ if (dataModel != null ) {
423397 dataModel .unregisterObserver (mModelDataSetOberver );
424398 }
425399 ViewTreeObserver viewTreeObserver = getViewTreeObserver ();
@@ -522,7 +496,7 @@ private void updateAppearance() {
522496 // Default activity button.
523497 final int activityCount = mAdapter .getActivityCount ();
524498 final int historySize = mAdapter .getHistorySize ();
525- if (mHasDefaultActivity && activityCount > 0 && historySize > 0 ) {
499+ if (activityCount > 0 && historySize > 0 ) {
526500 mDefaultActivityButton .setVisibility (VISIBLE );
527501 ResolveInfo activity = mAdapter .getDefaultActivity ();
528502 PackageManager packageManager = mContext .getPackageManager ();
@@ -538,9 +512,9 @@ private void updateAppearance() {
538512 }
539513 // Activity chooser content.
540514 if (mDefaultActivityButton .getVisibility () == VISIBLE ) {
541- mActivityChooserContent .setBackground (mActivityChooserContentBackground );
515+ mActivityChooserContent .setBackgroundDrawable (mActivityChooserContentBackground );
542516 } else {
543- mActivityChooserContent .setBackground (null );
517+ mActivityChooserContent .setBackgroundDrawable (null );
544518 }
545519 }
546520
@@ -603,7 +577,7 @@ public void onClick(View view) {
603577 // OnLongClickListener#onLongClick
604578 @ Override
605579 public boolean onLongClick (View view ) {
606- if (mHasDefaultActivity && view == mDefaultActivityButton ) {
580+ if (view == mDefaultActivityButton ) {
607581 if (mAdapter .getCount () > 0 ) {
608582 mIsSelectingDefaultActivity = true ;
609583 showPopupUnchecked (mInitialActivityCount );
@@ -656,16 +630,14 @@ private class ActivityChooserViewAdapter extends BaseAdapter {
656630
657631 public void setDataModel (ActivityChooserModel dataModel ) {
658632 ActivityChooserModel oldDataModel = mAdapter .getDataModel ();
659- if (oldDataModel != null ) {
633+ if (oldDataModel != null && isShown () ) {
660634 oldDataModel .unregisterObserver (mModelDataSetOberver );
661635 }
662636 mDataModel = dataModel ;
663- if (dataModel != null ) {
637+ if (dataModel != null && isShown () ) {
664638 dataModel .registerObserver (mModelDataSetOberver );
665- notifyDataSetChanged ();
666- } else {
667- notifyDataSetInvalidated ();
668639 }
640+ notifyDataSetChanged ();
669641 }
670642
671643 @ Override
0 commit comments