From 8c599ee8ea2dbad5e922c842b32713f86e485c86 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Fri, 21 Feb 2014 13:56:40 -0800 Subject: [PATCH] Bug 975525 - Refresh action mode buttons when activities are uninstalled. r=mfinkle --- mobile/android/base/GeckoApp.java | 6 +++++- mobile/android/base/menu/GeckoMenu.java | 13 +++++++++++++ mobile/android/base/menu/GeckoMenuItem.java | 11 +++++++++++ .../android/base/widget/ActivityChooserModel.java | 9 ++++++++- mobile/android/base/widget/GeckoActionProvider.java | 9 +++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 53a2fc91de5..47904341157 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -425,8 +425,12 @@ public abstract class GeckoApp @Override public boolean onPreparePanel(int featureId, View view, Menu menu) { - if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) + if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) { + if (menu instanceof GeckoMenu) { + ((GeckoMenu) menu).refresh(); + } return onPrepareOptionsMenu(menu); + } return super.onPreparePanel(featureId, view, menu); } diff --git a/mobile/android/base/menu/GeckoMenu.java b/mobile/android/base/menu/GeckoMenu.java index e90679972a3..a0ae5444850 100644 --- a/mobile/android/base/menu/GeckoMenu.java +++ b/mobile/android/base/menu/GeckoMenu.java @@ -26,6 +26,7 @@ import android.widget.ListView; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -636,6 +637,18 @@ public class GeckoMenu extends ListView } } + public void refresh() { + for (Iterator i = mPrimaryActionItems.keySet().iterator(); i.hasNext();) { + GeckoMenuItem item = i.next(); + item.refreshIfChanged(); + } + + for (Iterator i = mSecondaryActionItems.keySet().iterator(); i.hasNext();) { + GeckoMenuItem item = i.next(); + item.refreshIfChanged(); + } + } + // Adapter to bind menu items to the list. private class MenuItemsAdapter extends BaseAdapter { private static final int VIEW_TYPE_DEFAULT = 0; diff --git a/mobile/android/base/menu/GeckoMenuItem.java b/mobile/android/base/menu/GeckoMenuItem.java index b244b18f26f..88df93c8a39 100644 --- a/mobile/android/base/menu/GeckoMenuItem.java +++ b/mobile/android/base/menu/GeckoMenuItem.java @@ -222,6 +222,17 @@ public class GeckoMenuItem implements MenuItem { return this; } + public void refreshIfChanged() { + if (mActionProvider == null) + return; + + if (mActionProvider instanceof GeckoActionProvider) { + if (((GeckoActionProvider) mActionProvider).hasChanged()) { + mShowAsActionChangedListener.onShowAsActionChanged(GeckoMenuItem.this); + } + } + } + @Override public MenuItem setActionView(int resId) { return this; diff --git a/mobile/android/base/widget/ActivityChooserModel.java b/mobile/android/base/widget/ActivityChooserModel.java index 47ddc0175c3..9edfa36a791 100644 --- a/mobile/android/base/widget/ActivityChooserModel.java +++ b/mobile/android/base/widget/ActivityChooserModel.java @@ -319,6 +319,8 @@ public class ActivityChooserModel extends DataSetObservable { */ private boolean mReloadActivities = false; + private long mLastChanged = 0; + /** * Policy for controlling how the model handles chosen activities. */ @@ -745,6 +747,7 @@ public class ActivityChooserModel extends DataSetObservable { ResolveInfo resolveInfo = resolveInfos.get(i); mActivities.add(new ActivityResolveInfo(resolveInfo)); } + mLastChanged = System.currentTimeMillis(); return true; } return false; @@ -1220,7 +1223,11 @@ public class ActivityChooserModel extends DataSetObservable { } mReloadActivities = true; + mLastChanged = System.currentTimeMillis(); } } -} + public long getLastChanged() { + return mLastChanged; + } +} diff --git a/mobile/android/base/widget/GeckoActionProvider.java b/mobile/android/base/widget/GeckoActionProvider.java index 7eb8ff95340..5037730f710 100644 --- a/mobile/android/base/widget/GeckoActionProvider.java +++ b/mobile/android/base/widget/GeckoActionProvider.java @@ -21,6 +21,7 @@ import android.view.View.OnClickListener; public class GeckoActionProvider extends ActionProvider { private static int MAX_HISTORY_SIZE = 2; + private long mLastChanged = 0; /** * A listener to know when a target was selected. @@ -79,6 +80,14 @@ public class GeckoActionProvider extends ActionProvider { return onCreateActionView(); } + public boolean hasChanged() { + ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); + long lastChanged = dataModel.getLastChanged(); + boolean ret = lastChanged != mLastChanged; + mLastChanged = lastChanged; + return ret; + } + @Override public boolean hasSubMenu() { return true;