Bug 975525 - Refresh action mode buttons when activities are uninstalled. r=mfinkle

This commit is contained in:
Wes Johnston 2014-02-21 13:56:40 -08:00
parent 2227210a15
commit 8c599ee8ea
5 changed files with 46 additions and 2 deletions

View File

@ -425,8 +425,12 @@ public abstract class GeckoApp
@Override @Override
public boolean onPreparePanel(int featureId, View view, Menu menu) { 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 onPrepareOptionsMenu(menu);
}
return super.onPreparePanel(featureId, view, menu); return super.onPreparePanel(featureId, view, menu);
} }

View File

@ -26,6 +26,7 @@ import android.widget.ListView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -636,6 +637,18 @@ public class GeckoMenu extends ListView
} }
} }
public void refresh() {
for (Iterator<GeckoMenuItem> i = mPrimaryActionItems.keySet().iterator(); i.hasNext();) {
GeckoMenuItem item = i.next();
item.refreshIfChanged();
}
for (Iterator<GeckoMenuItem> i = mSecondaryActionItems.keySet().iterator(); i.hasNext();) {
GeckoMenuItem item = i.next();
item.refreshIfChanged();
}
}
// Adapter to bind menu items to the list. // Adapter to bind menu items to the list.
private class MenuItemsAdapter extends BaseAdapter { private class MenuItemsAdapter extends BaseAdapter {
private static final int VIEW_TYPE_DEFAULT = 0; private static final int VIEW_TYPE_DEFAULT = 0;

View File

@ -222,6 +222,17 @@ public class GeckoMenuItem implements MenuItem {
return this; return this;
} }
public void refreshIfChanged() {
if (mActionProvider == null)
return;
if (mActionProvider instanceof GeckoActionProvider) {
if (((GeckoActionProvider) mActionProvider).hasChanged()) {
mShowAsActionChangedListener.onShowAsActionChanged(GeckoMenuItem.this);
}
}
}
@Override @Override
public MenuItem setActionView(int resId) { public MenuItem setActionView(int resId) {
return this; return this;

View File

@ -319,6 +319,8 @@ public class ActivityChooserModel extends DataSetObservable {
*/ */
private boolean mReloadActivities = false; private boolean mReloadActivities = false;
private long mLastChanged = 0;
/** /**
* Policy for controlling how the model handles chosen activities. * Policy for controlling how the model handles chosen activities.
*/ */
@ -745,6 +747,7 @@ public class ActivityChooserModel extends DataSetObservable {
ResolveInfo resolveInfo = resolveInfos.get(i); ResolveInfo resolveInfo = resolveInfos.get(i);
mActivities.add(new ActivityResolveInfo(resolveInfo)); mActivities.add(new ActivityResolveInfo(resolveInfo));
} }
mLastChanged = System.currentTimeMillis();
return true; return true;
} }
return false; return false;
@ -1220,7 +1223,11 @@ public class ActivityChooserModel extends DataSetObservable {
} }
mReloadActivities = true; mReloadActivities = true;
} mLastChanged = System.currentTimeMillis();
} }
} }
public long getLastChanged() {
return mLastChanged;
}
}

View File

@ -21,6 +21,7 @@ import android.view.View.OnClickListener;
public class GeckoActionProvider extends ActionProvider { public class GeckoActionProvider extends ActionProvider {
private static int MAX_HISTORY_SIZE = 2; private static int MAX_HISTORY_SIZE = 2;
private long mLastChanged = 0;
/** /**
* A listener to know when a target was selected. * A listener to know when a target was selected.
@ -79,6 +80,14 @@ public class GeckoActionProvider extends ActionProvider {
return onCreateActionView(); return onCreateActionView();
} }
public boolean hasChanged() {
ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName);
long lastChanged = dataModel.getLastChanged();
boolean ret = lastChanged != mLastChanged;
mLastChanged = lastChanged;
return ret;
}
@Override @Override
public boolean hasSubMenu() { public boolean hasSubMenu() {
return true; return true;