use of android.appwidget.AppWidgetHostView in project TBLauncher by TBog.
the class WidgetManager method restoreWidget.
// public List<AppWidgetProviderInfo> getWidgetsForPackage(String packageName) {
// List<AppWidgetProviderInfo> providers;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// providers = mAppWidgetManager.getInstalledProvidersForPackage(packageName, null);
// } else {
// providers = new ArrayList<>();
// for (AppWidgetProviderInfo prov : mAppWidgetManager.getInstalledProviders()) {
// if (prov.provider.getPackageName().equals(packageName)) {
// providers.add(prov);
// }
// }
// }
// return providers;
// }
private void restoreWidget(WidgetRecord rec) {
final int appWidgetId = rec.appWidgetId;
Context ctx = mLayout.getContext().getApplicationContext();
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
if (appWidgetInfo == null)
return;
AppWidgetHostView hostView = mAppWidgetHost.createView(ctx, appWidgetId, appWidgetInfo);
addWidgetToLayout(hostView, appWidgetInfo, rec);
}
use of android.appwidget.AppWidgetHostView 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();
}
}
}
}
use of android.appwidget.AppWidgetHostView in project android_packages_apps_Trebuchet by LineageOS.
the class WidgetHostViewLoader method preloadWidget.
/**
* Start preloading the widget.
*/
private boolean preloadWidget() {
final LauncherAppWidgetProviderInfo pInfo = mInfo.info;
if (pInfo.isCustomWidget()) {
return false;
}
final Bundle options = getDefaultOptionsForWidget(mLauncher, mInfo);
// If there is a configuration activity, do not follow thru bound and inflate.
if (mInfo.getHandler().needsConfigure()) {
mInfo.bindOptions = options;
return false;
}
mBindWidgetRunnable = new Runnable() {
@Override
public void run() {
mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
if (LOGD) {
Log.d(TAG, "Binding widget, id: " + mWidgetLoadingId);
}
if (new WidgetManagerHelper(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, pInfo, options)) {
// Widget id bound. Inflate the widget.
mHandler.post(mInflateWidgetRunnable);
}
}
};
mInflateWidgetRunnable = new Runnable() {
@Override
public void run() {
if (LOGD) {
Log.d(TAG, "Inflating widget, id: " + mWidgetLoadingId);
}
if (mWidgetLoadingId == -1) {
return;
}
AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView((Context) mLauncher, mWidgetLoadingId, pInfo);
mInfo.boundWidget = hostView;
// We used up the widget Id in binding the above view.
mWidgetLoadingId = -1;
hostView.setVisibility(View.INVISIBLE);
int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(mInfo);
// We want the first widget layout to be the correct size. This will be important
// for width size reporting to the AppWidgetManager.
DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0], unScaledSize[1]);
lp.x = lp.y = 0;
lp.customPosition = true;
hostView.setLayoutParams(lp);
if (LOGD) {
Log.d(TAG, "Adding host view to drag layer");
}
mLauncher.getDragLayer().addView(hostView);
mView.setTag(mInfo);
}
};
if (LOGD) {
Log.d(TAG, "About to bind/inflate widget");
}
mHandler.post(mBindWidgetRunnable);
return true;
}
use of android.appwidget.AppWidgetHostView in project android_packages_apps_Trebuchet by LineageOS.
the class Launcher method completeTwoStageWidgetDrop.
@Thunk
void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Runnable onCompleteRunnable = null;
int animationType = 0;
AppWidgetHostView boundWidget = null;
if (resultCode == RESULT_OK) {
animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, requestArgs.getWidgetHandler().getProviderInfo(this));
boundWidget = layout;
onCompleteRunnable = new Runnable() {
@Override
public void run() {
completeAddAppWidget(appWidgetId, requestArgs, layout, null);
mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
}
};
} else if (resultCode == RESULT_CANCELED) {
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
}
if (mDragLayer.getAnimatedView() != null) {
mWorkspace.animateWidgetDrop(requestArgs, cellLayout, (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, animationType, boundWidget, true);
} else if (onCompleteRunnable != null) {
// The animated view may be null in the case of a rotation during widget configuration
onCompleteRunnable.run();
}
}
use of android.appwidget.AppWidgetHostView in project android_packages_apps_Trebuchet by LineageOS.
the class SecondaryDropTarget method supportsAccessibilityDrop.
@Override
public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
if (view instanceof AppWidgetHostView) {
if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
setupUi(RECONFIGURE);
return true;
}
return false;
} else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) {
setupUi(DISMISS_PREDICTION);
return true;
}
setupUi(UNINSTALL);
Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
if (uninstallDisabled == null) {
UserManager userManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
Bundle restrictions = userManager.getUserRestrictions(info.user);
uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false) || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false);
mUninstallDisabledCache.put(info.user, uninstallDisabled);
}
// Cancel any pending alarm and set cache expiry after some time
mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
mCacheExpireAlarm.setOnAlarmListener(this);
if (uninstallDisabled) {
return false;
}
if (info instanceof ItemInfoWithIcon) {
ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) {
return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0;
}
}
return getUninstallTarget(info) != null;
}
Aggregations