use of rocks.tbog.tblauncher.ui.WidgetView 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.WidgetView in project TBLauncher by TBog.
the class WidgetManager method addWidgetToLayout.
private void addWidgetToLayout(AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo, WidgetRecord rec) {
View placeholder = mLayout.getPlaceholder(appWidgetInfo.provider);
WidgetLayout.LayoutParams params = null;
if (placeholder != null)
params = (WidgetLayout.LayoutParams) placeholder.getLayoutParams();
if (params == null) {
params = new WidgetLayout.LayoutParams(rec.width, rec.height);
params.leftMargin = rec.left;
params.topMargin = rec.top;
params.screenPage = rec.screen;
params.placement = WidgetLayout.LayoutParams.Placement.MARGIN_TL_AS_POSITION;
}
hostView.setMinimumWidth(appWidgetInfo.minWidth);
hostView.setMinimumHeight(appWidgetInfo.minHeight);
hostView.setAppWidget(rec.appWidgetId, appWidgetInfo);
hostView.updateAppWidgetSize(null, rec.width, rec.height, rec.width, rec.height);
hostView.setOnLongClickListener(v -> {
if (v instanceof WidgetView) {
ListPopup menu = getConfigPopup((WidgetView) v);
TBApplication.getApplication(v.getContext()).registerPopup(menu);
menu.show(v, 0.f);
return true;
}
return false;
});
// replace placeholder (if it exists) with the widget
{
int insertPosition = mLayout.indexOfChild(placeholder);
if (insertPosition != -1)
mLayout.removeViewAt(insertPosition);
mLayout.addView(hostView, insertPosition, params);
}
Context context = mLayout.getContext();
// remove from `mPlaceholders`
{
for (Iterator<PlaceholderWidgetRecord> iterator = mPlaceholders.iterator(); iterator.hasNext(); ) {
PlaceholderWidgetRecord placeholderWidget = iterator.next();
if (placeholderWidget.provider.equals(appWidgetInfo.provider)) {
DBHelper.removeWidgetPlaceholder(context, INVALID_WIDGET_ID, placeholderWidget.provider.flattenToString());
iterator.remove();
}
}
}
}
Aggregations