Skip to content

Commit

Permalink
ThrottledMenuItemClickListener
Browse files Browse the repository at this point in the history
throttle menu click listeners to once a second
  • Loading branch information
forrestguice committed Sep 4, 2023
1 parent 31aba51 commit 8568230
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void onClick(View v)
});
private List<AlarmAddon.EventPickerInfo> alarmPickers = null;

private PopupMenu.OnMenuItemClickListener onMoreMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onMoreMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand Down Expand Up @@ -497,7 +497,7 @@ public boolean onMenuItemClick(MenuItem item)
return false;
}
}
};
});

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void onTrackingModeChanged(Context context, int id)
} else Log.w("EquinoxDialog", "setTrackingMode: invalid item id " + id);
}

private PopupMenu.OnMenuItemClickListener onOverflowMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onOverflowMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand All @@ -304,7 +304,7 @@ public boolean onMenuItemClick(MenuItem item)
return false;
}
}
};
});

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -365,7 +365,7 @@ public void run() { // a submenu may be shown after the pop
}
};

private PopupMenu.OnMenuItemClickListener onContextMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onContextMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand Down Expand Up @@ -424,7 +424,7 @@ public boolean onMenuItemClick(MenuItem item)
return false;
}
}
};
});

protected void shareItem(Context context, Intent itemData) // TODO: refactor to use ViewUtils after v0.15.0 branches are merged
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public void onClick(View v)



private PopupMenu.OnMenuItemClickListener onContextMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onContextMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand Down Expand Up @@ -621,7 +621,7 @@ public void run() {
return false;
}
}
};
});

private void updateContextMenu(Context context, PopupMenu popupMenu)
{
Expand Down Expand Up @@ -702,7 +702,7 @@ private void updateSpeedMenu(Context context, PopupMenu menu)
}
}

private PopupMenu.OnMenuItemClickListener onSpeedMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onSpeedMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand Down Expand Up @@ -732,7 +732,7 @@ public boolean onMenuItemClick(MenuItem item)
return false;
}
}
};
});

protected boolean showTimeZoneMenu(Context context, View view)
{
Expand All @@ -741,7 +741,7 @@ protected boolean showTimeZoneMenu(Context context, View view)
menu.show();
return true;
}
private PopupMenu.OnMenuItemClickListener onTimeZoneMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onTimeZoneMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand All @@ -756,7 +756,7 @@ public boolean onMenuItemClick(MenuItem item)
return (tzID != null);
} else return false;
}
};
});

private void updateMediaButtons()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ private void updateOverflowMenu(Context context, PopupMenu popup)
lunarNoonItem.setChecked(AppSettings.loadShowLunarNoonPref(context));
}
}
private PopupMenu.OnMenuItemClickListener onOverflowMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onOverflowMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand All @@ -707,7 +707,7 @@ public boolean onMenuItemClick(MenuItem item)
return false;
}
}
};
});

/**
* MediaMenu
Expand Down Expand Up @@ -952,7 +952,7 @@ private static void setDataToMenu(Menu m, Intent data)
}
}

private PopupMenu.OnMenuItemClickListener onContextMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onContextMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public boolean onMenuItemClick(MenuItem item)
return false;
}
}
};
});

protected void shareItem(Context context, Intent itemData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import com.forrestguice.suntimeswidget.themes.WidgetThemeListActivity;
import com.forrestguice.suntimeswidget.views.PopupMenuCompat;
import com.forrestguice.suntimeswidget.views.TooltipCompat;
import com.forrestguice.suntimeswidget.views.ViewUtils;

import java.lang.ref.WeakReference;
import java.security.InvalidParameterException;
Expand Down Expand Up @@ -1251,7 +1252,7 @@ protected void showTimeModeMenu(Context context, View v)
protected void prepareTimeModeMenu(Context context, Menu menu) {
}

protected PopupMenu.OnMenuItemClickListener onTimeModeMenuClicked = new PopupMenu.OnMenuItemClickListener()
protected PopupMenu.OnMenuItemClickListener onTimeModeMenuClicked = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -1270,7 +1271,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
return false;
}
}
};
});

protected void showTimeModeHelp()
{
Expand Down Expand Up @@ -1434,7 +1435,7 @@ protected boolean showTimeZoneSortMenu(Context context, View view)
menu.show();
return true;
}
private final PopupMenu.OnMenuItemClickListener onTimeZoneSortMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onTimeZoneSortMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
Expand All @@ -1461,7 +1462,7 @@ public void onSaveSortMode( WidgetTimezones.TimeZoneSort sortMode )
sortActionBase.init(context, spinner_timezone);
return sortActionBase.onActionItemClicked(item.getItemId());
}
};
});

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public static void setChecked(@Nullable MenuItem item, boolean value) {
item.setChecked(value);
}
}
private final PopupMenu.OnMenuItemClickListener onTimeZoneSortMenuClick = new PopupMenu.OnMenuItemClickListener()
private final PopupMenu.OnMenuItemClickListener onTimeZoneSortMenuClick = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item) {
Expand Down Expand Up @@ -658,7 +658,7 @@ public void onSaveSortMode( WidgetTimezones.TimeZoneSort sortMode )
sortActionBase.init(context, spinner_timezone);
return sortActionBase.onActionItemClicked(item.getItemId());
}
};
});

/**
* trigger the time zone ActionMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.forrestguice.suntimeswidget.SuntimesUtils;
import com.forrestguice.suntimeswidget.calculator.SuntimesData;
import com.forrestguice.suntimeswidget.settings.WidgetActions;
import com.forrestguice.suntimeswidget.views.ViewUtils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
Expand Down Expand Up @@ -274,7 +275,7 @@ protected void prepareOverflowMenu(Context context, Menu menu)
}
}

protected PopupMenu.OnMenuItemClickListener onMenuItemClicked = new PopupMenu.OnMenuItemClickListener()
protected PopupMenu.OnMenuItemClickListener onMenuItemClicked = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -301,7 +302,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
return false;
}
}
};
});

public void addAction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.forrestguice.suntimeswidget.SuntimesUtils;
import com.forrestguice.suntimeswidget.calculator.SuntimesData;
import com.forrestguice.suntimeswidget.settings.WidgetActions;
import com.forrestguice.suntimeswidget.views.ViewUtils;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -540,7 +541,7 @@ protected void showOverflowMenu(Context context, View parent)
menu.show();
}

protected PopupMenu.OnMenuItemClickListener onMenuItemClicked = new PopupMenu.OnMenuItemClickListener()
protected PopupMenu.OnMenuItemClickListener onMenuItemClicked = new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -563,7 +564,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
return false;
}
}
};
});

public void saveIntent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.forrestguice.suntimeswidget.settings.WidgetSettings;
import com.forrestguice.suntimeswidget.settings.WidgetThemes;
import com.forrestguice.suntimeswidget.themes.SuntimesTheme;
import com.forrestguice.suntimeswidget.views.ViewUtils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
Expand Down Expand Up @@ -712,7 +713,7 @@ public void showDismissChallengePopup(View v, @NonNull final AlarmClockItem item
c++;
}

popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
popup.setOnMenuItemClickListener(new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -721,7 +722,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
onDismissChallengeResult(itemID);
return true;
}
});
}));

SuntimesUtils.forceActionBarIcons(popup.getMenu());
popup.show();
Expand All @@ -746,7 +747,7 @@ public void showAlarmSoundPopup(View v, @NonNull final AlarmClockItem item)
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.alarmsound, popup.getMenu());

popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
popup.setOnMenuItemClickListener(new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -767,7 +768,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
}
return false;
}
});
}));
SuntimesUtils.forceActionBarIcons(popup.getMenu());
popup.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected void showAlarmTypeMenu(Context context, final AlarmClockItem item, fin
MenuInflater inflater = menu.getMenuInflater();
inflater.inflate(R.menu.alarmtype, menu.getMenu());

menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
menu.setOnMenuItemClickListener(new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -337,7 +337,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
notifyItemChanged();
return true;
}
});
}));

SuntimesUtils.forceActionBarIcons(menu.getMenu());
menu.show();
Expand All @@ -360,7 +360,7 @@ protected void showOverflowMenu(final Context context, final AlarmClockItem item
}
}

menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
menu.setOnMenuItemClickListener(new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -375,7 +375,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
return false;
}
}
});
}));

SuntimesUtils.forceActionBarIcons(menu.getMenu());
menu.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.forrestguice.suntimeswidget.alarmclock.AlarmState;
import com.forrestguice.suntimeswidget.settings.SolarEvents;
import com.forrestguice.suntimeswidget.themes.SuntimesTheme;
import com.forrestguice.suntimeswidget.views.ViewUtils;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -825,7 +826,7 @@ protected void showOverflowMenu(final AlarmClockItem item, final View buttonView
}
}

menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
menu.setOnMenuItemClickListener(new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand Down Expand Up @@ -898,7 +899,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
return false;
}
}
});
}));

SuntimesUtils.forceActionBarIcons(menu.getMenu());
menu.show();
Expand All @@ -916,7 +917,7 @@ protected void showAlarmTypeMenu(final AlarmClockItem item, final View buttonVie
MenuInflater inflater = menu.getMenuInflater();
inflater.inflate(R.menu.alarmtype, menu.getMenu());

menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
menu.setOnMenuItemClickListener(new ViewUtils.ThrottledMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem menuItem)
Expand All @@ -937,7 +938,7 @@ public boolean onMenuItemClick(MenuItem menuItem)
return changeAlarmType(item, AlarmClockItem.AlarmType.ALARM);
}
}
});
}));

SuntimesUtils.forceActionBarIcons(menu.getMenu());
menu.show();
Expand Down
Loading

0 comments on commit 8568230

Please sign in to comment.