use of rocks.tbog.tblauncher.ui.LinearAdapter in project TBLauncher by TBog.
the class AppEntry method popupMenuClickHandler.
@Override
protected boolean popupMenuClickHandler(@NonNull final View view, @NonNull LinearAdapter.MenuItem item, int stringId, View parentView) {
Context ctx = view.getContext();
if (item instanceof ShortcutItem) {
TBApplication.behaviour(ctx).beforeLaunchOccurred();
final ShortcutInfo shortcutInfo = ((ShortcutItem) item).shortcutInfo;
parentView.postDelayed(() -> {
Activity activity = Utilities.getActivity(parentView);
if (activity == null)
return;
ShortcutEntry.doOreoLaunch(activity, parentView, shortcutInfo);
TBApplication.behaviour(activity).afterLaunchOccurred();
}, Behaviour.LAUNCH_DELAY);
return true;
}
switch(stringId) {
// return true;
case R.string.menu_app_details:
launchAppDetails(ctx, parentView);
return true;
case R.string.menu_app_store:
launchAppStore(ctx, parentView);
return true;
case R.string.menu_app_uninstall:
launchUninstall(ctx);
return true;
case R.string.menu_app_hibernate:
hibernate(ctx);
return true;
// return true;
case R.string.menu_exclude:
{
LinearAdapter adapter = new LinearAdapter();
ListPopup menu = ListPopup.create(ctx, adapter);
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_exclude_history));
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_exclude_kiss));
menu.setOnItemClickListener((a, v, pos) -> {
LinearAdapter.MenuItem menuItem = ((LinearAdapter) a).getItem(pos);
@StringRes int id = 0;
if (menuItem instanceof LinearAdapter.Item) {
id = ((LinearAdapter.Item) a.getItem(pos)).stringId;
}
switch(id) {
case R.string.menu_exclude_history:
// excludeFromHistory(v.getContext(), appPojo());
Toast.makeText(ctx, "Not Implemented", Toast.LENGTH_LONG).show();
break;
case R.string.menu_exclude_kiss:
// excludeFromKiss(v.getContext(), appPojo(), parent);
Toast.makeText(ctx, "Work in progress", Toast.LENGTH_LONG).show();
break;
}
});
menu.show(parentView);
TBApplication.getApplication(ctx).registerPopup(menu);
return true;
}
case R.string.menu_hide:
if (TBApplication.dataHandler(ctx).addToHidden(this)) {
setHiddenByUser(true);
TBApplication.behaviour(ctx).refreshSearchRecord(this);
// Toast.makeText(ctx, "App "+getName()+" hidden from search", Toast.LENGTH_LONG).show();
}
break;
case R.string.menu_show:
if (TBApplication.dataHandler(ctx).removeFromHidden(this)) {
setHiddenByUser(false);
TBApplication.behaviour(ctx).refreshSearchRecord(this);
// Toast.makeText(ctx, "App "+getName()+" shown in searches", Toast.LENGTH_LONG).show();
}
break;
case R.string.menu_tags_add:
case R.string.menu_tags_edit:
TBApplication.behaviour(ctx).launchEditTagsDialog(this);
return true;
case R.string.menu_app_rename:
launchRenameDialog(ctx);
return true;
case R.string.menu_custom_icon:
TBApplication.behaviour(ctx).launchCustomIconDialog(this);
return true;
}
return super.popupMenuClickHandler(view, item, stringId, parentView);
}
use of rocks.tbog.tblauncher.ui.LinearAdapter in project TBLauncher by TBog.
the class WidgetManager method getConfigPopup.
/**
* Popup with options for all widgets
*
* @param activity used to start the widget select popup
* @return the popup menu
*/
public ListPopup getConfigPopup(Activity activity) {
LinearAdapter adapter = new LinearAdapter();
adapter.add(new LinearAdapter.ItemTitle(activity, R.string.menu_widget_title));
adapter.add(new LinearAdapter.Item(activity, R.string.menu_widget_add));
if (widgetCount() > 0) {
adapter.add(new LinearAdapter.Item(activity, R.string.menu_widget_configure));
adapter.add(new LinearAdapter.Item(activity, R.string.menu_widget_remove));
}
adapter.add(new LinearAdapter.Item(activity, R.string.menu_popup_launcher_settings));
ListPopup menu = ListPopup.create(activity, adapter);
menu.setOnItemClickListener((a, v, pos) -> {
LinearAdapter.MenuItem item = ((LinearAdapter) a).getItem(pos);
@StringRes int stringId = 0;
if (item instanceof LinearAdapter.Item) {
stringId = ((LinearAdapter.Item) a.getItem(pos)).stringId;
}
switch(stringId) {
case R.string.menu_widget_add:
TBApplication.widgetManager(activity).showSelectWidget(activity);
break;
case R.string.menu_widget_configure:
{
ListPopup configWidgetPopup = TBApplication.widgetManager(activity).getWidgetListPopup(R.string.menu_widget_configure);
configWidgetPopup.setOnItemClickListener((a1, v1, pos1) -> {
Object item1 = a1.getItem(pos1);
if (item1 instanceof WidgetPopupItem) {
AppWidgetHostView widgetView = mLayout.getWidget(((WidgetPopupItem) item1).appWidgetId);
if (widgetView == null)
return;
ListPopup popup = getConfigPopup((WidgetView) widgetView);
TBApplication.getApplication(mLayout.getContext()).registerPopup(popup);
popup.show(widgetView, 0.f);
} else if (item1 instanceof PlaceholderPopupItem) {
PlaceholderWidgetRecord placeholder = ((PlaceholderPopupItem) item1).placeholder;
View placeholderView = mLayout.getPlaceholder(placeholder.provider);
if (placeholderView != null)
placeholderView.performClick();
}
});
TBApplication.getApplication(activity).registerPopup(configWidgetPopup);
configWidgetPopup.showCenter(activity.getWindow().getDecorView());
break;
}
case R.string.menu_widget_remove:
showRemoveWidgetPopup();
break;
case R.string.menu_popup_launcher_settings:
// TBApplication.behaviour(v.getContext()).beforeLaunchOccurred();
mLayout.postDelayed(() -> {
Context c = mLayout.getContext();
c.startActivity(new Intent(c, SettingsActivity.class));
// TBApplication.behaviour(c).afterLaunchOccurred();
}, Behaviour.LAUNCH_DELAY);
break;
}
});
return menu;
}
use of rocks.tbog.tblauncher.ui.LinearAdapter in project TBLauncher by TBog.
the class WidgetManager method getConfigPopup.
/**
* Popup with options for the widget in the view
*
* @param view of the widget
* @return the popup menu
*/
protected ListPopup getConfigPopup(WidgetView view) {
final int appWidgetId = view.getAppWidgetId();
Context ctx = mLayout.getContext();
LinearAdapter adapter = new LinearAdapter();
WidgetRecord widget = mWidgets.get(appWidgetId);
if (widget != null) {
addConfigPopupItems(mLayout, adapter, view, widget);
} else {
adapter.add(new LinearAdapter.ItemString("ERROR: Not found"));
}
ListPopup menu = ListPopup.create(ctx, adapter);
menu.setOnItemClickListener((a, v, position) -> handleConfigPopupItemClick(a, view, position));
return menu;
}
use of rocks.tbog.tblauncher.ui.LinearAdapter in project TBLauncher by TBog.
the class EntryItem method inflatePopupMenu.
ListPopup inflatePopupMenu(@NonNull Context context, @NonNull LinearAdapter adapter) {
ListPopup menu = ListPopup.create(context, adapter);
// boolean foundInQuickList = false;
// ArrayList<ModRecord> favRecords = TBApplication.dataHandler(context).getFavorites();
// for (ModRecord fav : favRecords) {
// if (id.equals(fav.record) && fav.isInQuickList()) {
// foundInQuickList = true;
// break;
// }
// }
QuickListProvider provider = TBApplication.dataHandler(context).getQuickListProvider();
// get current Quick List content
List<? extends EntryItem> list = provider != null ? provider.getPojos() : Collections.emptyList();
boolean foundInQuickList = list.contains(this);
if (foundInQuickList) {
// if already in quick list, remove the "Add to QuickList" option
for (int i = 0; i < adapter.getCount(); i += 1) {
LinearAdapter.MenuItem item = adapter.getItem(i);
if (item instanceof LinearAdapter.Item) {
if (((LinearAdapter.Item) item).stringId == R.string.menu_quick_list_add)
adapter.remove(item);
}
}
} else {
// if not in quick list, remove the "Remove from QuickList" option
for (int i = 0; i < adapter.getCount(); i += 1) {
LinearAdapter.MenuItem item = adapter.getItem(i);
if (item instanceof LinearAdapter.Item) {
if (((LinearAdapter.Item) item).stringId == R.string.menu_quick_list_remove)
adapter.remove(item);
}
}
}
if (DebugInfo.itemRelevance(context)) {
String debugTitle = context.getString(R.string.popup_title_debug);
int pos = -1;
// find title
for (int i = 0; i < adapter.getCount(); i += 1) {
if (debugTitle.equals(adapter.getItem(i).toString())) {
pos = i + 1;
break;
}
}
// if title not found, add title
if (pos == -1) {
adapter.add(new LinearAdapter.ItemTitle(debugTitle));
pos = adapter.getCount();
}
// add debug data after title
adapter.add(pos, new LinearAdapter.ItemString("Relevance: " + getRelevance()));
}
return menu;
}
use of rocks.tbog.tblauncher.ui.LinearAdapter in project TBLauncher by TBog.
the class Behaviour method getMenuPopup.
private ListPopup getMenuPopup(Context ctx) {
LinearAdapter adapter = new LinearAdapter();
ListPopup menu = ListPopup.create(ctx, adapter);
adapter.add(new LinearAdapter.ItemTitle(ctx, R.string.menu_popup_title));
adapter.add(new LinearAdapter.Item(ctx, R.string.change_wallpaper));
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_widget_add));
if (TBApplication.widgetManager(ctx).widgetCount() > 0)
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_widget_remove));
adapter.add(new LinearAdapter.ItemTitle(ctx, R.string.menu_popup_title_settings));
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_launcher_settings));
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_tags_manager));
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_tags_menu));
adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_android_settings));
menu.setOnItemClickListener((a, v, pos) -> {
LinearAdapter.MenuItem item = ((LinearAdapter) a).getItem(pos);
@StringRes int stringId = 0;
if (item instanceof LinearAdapter.Item) {
stringId = ((LinearAdapter.Item) a.getItem(pos)).stringId;
}
Context c = mTBLauncherActivity;
if (stringId == R.string.menu_popup_tags_manager) {
launchTagsManagerDialog(mTBLauncherActivity);
} else if (stringId == R.string.menu_popup_tags_menu) {
executeAction("showTagsMenu", "button-menu");
} else if (stringId == R.string.menu_popup_launcher_settings) {
Intent intent = new Intent(mClearButton.getContext(), SettingsActivity.class);
launchIntent(this, mClearButton, intent);
} else if (stringId == R.string.change_wallpaper) {
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
intent = Intent.createChooser(intent, c.getString(R.string.change_wallpaper));
launchIntent(this, mClearButton, intent);
} else if (stringId == R.string.menu_widget_add) {
TBApplication.widgetManager(c).showSelectWidget(mTBLauncherActivity);
} else if (stringId == R.string.menu_widget_remove) {
TBApplication.widgetManager(c).showRemoveWidgetPopup();
} else if (stringId == R.string.menu_popup_android_settings) {
Intent intent = new Intent(Settings.ACTION_SETTINGS);
launchIntent(this, mClearButton, intent);
}
});
return menu;
}
Aggregations