Automatically request permission to create widgets (#2103)

This commit is contained in:
Patryk Michalik
2021-03-26 07:36:12 +01:00
committed by GitHub
@@ -307,17 +307,21 @@ public class QsbContainerView extends FrameLayout {
// Return a default widget with setup icon.
View v = QsbWidgetHostView.getDefaultView(container);
if (showSetupIcon) {
requestQsbCreate();
View setupButton = v.findViewById(R.id.btn_qsb_setup);
setupButton.setVisibility(View.VISIBLE);
setupButton.setOnClickListener((v2) -> startActivityForResult(
new Intent(ACTION_APPWIDGET_BIND)
.putExtra(EXTRA_APPWIDGET_ID, mQsbWidgetHost.allocateAppWidgetId())
.putExtra(EXTRA_APPWIDGET_PROVIDER, mWidgetInfo.provider),
REQUEST_BIND_QSB));
setupButton.setOnClickListener((v2) -> requestQsbCreate());
}
return v;
}
void requestQsbCreate() {
startActivityForResult(
new Intent(ACTION_APPWIDGET_BIND)
.putExtra(EXTRA_APPWIDGET_ID, mQsbWidgetHost.allocateAppWidgetId())
.putExtra(EXTRA_APPWIDGET_PROVIDER, mWidgetInfo.provider),
REQUEST_BIND_QSB);
}
/**
* Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}