/** * Creates workspace loader from an XML resource listed in the app restrictions. * * @return the loader if the restrictions are set and the resource exists; null otherwise. */ private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) { Context ctx = getContext(); UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE); Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName()); if (bundle == null) { return null; } String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME); if (packageName != null) { try { Resources targetResources = ctx.getPackageManager() .getResourcesForApplication(packageName); return AutoInstallsLayout.get(ctx, packageName, targetResources, widgetHost, mOpenHelper); } catch (NameNotFoundException e) { e.printStackTrace(); return null; } } return null; }
private boolean setupWidget() { LauncherAppWidgetProviderInfo widgetInfo = LauncherAppWidgetProviderInfo .fromProviderInfo(this, mRequest.getAppWidgetProviderInfo(this)); if (widgetInfo.minSpanX > mIdp.numColumns || widgetInfo.minSpanY > mIdp.numRows) { // Cannot add widget return false; } mWidgetCell.setPreview(PinItemDragListener.getPreview(mRequest)); mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); mAppWidgetHost = new AppWidgetHost(this, Launcher.APPWIDGET_HOST_ID); mPendingWidgetInfo = new PendingAddWidgetInfo(widgetInfo); mPendingWidgetInfo.spanX = Math.min(mIdp.numColumns, widgetInfo.spanX); mPendingWidgetInfo.spanY = Math.min(mIdp.numRows, widgetInfo.spanY); mWidgetOptions = WidgetHostViewLoader.getDefaultOptionsForWidget(this, mPendingWidgetInfo); WidgetItem item = new WidgetItem(widgetInfo, getPackageManager(), mIdp); mWidgetCell.getWidgetView().setTag(mPendingWidgetInfo); mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache()); mWidgetCell.ensurePreview(); return true; }
AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback, Resources res, int layoutId, String rootTag) { mContext = context; mAppWidgetHost = appWidgetHost; mCallback = callback; mPackageManager = context.getPackageManager(); mValues = new ContentValues(); mRootTag = rootTag; mSourceRes = res; mLayoutId = layoutId; mIdp = LauncherAppState.getIDP(context); mRowCount = mIdp.numRows; mColumnCount = mIdp.numColumns; }
/** * Overriden in tests. */ protected void onEmptyDbCreated() { // Database was just created, so wipe any previous widgets if (mWidgetHostResetHandler != null) { new AppWidgetHost(mContext, Launcher.APPWIDGET_HOST_ID).deleteHost(); mWidgetHostResetHandler.sendMessage(Message.obtain( mWidgetHostResetHandler, ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET, mContext )); } // Set the flag for empty DB Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit(); // When a new DB is created, remove all previously stored managed profile information. ManagedProfileHeuristic.processAllUsers(Collections.<UserHandleCompat>emptyList(), mContext); }
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback, Resources res, int layoutId, String rootTag) { mContext = context; mAppWidgetHost = appWidgetHost; mCallback = callback; mPackageManager = context.getPackageManager(); mValues = new ContentValues(); mRootTag = rootTag; mSourceRes = res; mLayoutId = layoutId; mIdp = LauncherAppState.getInstance().getInvariantDeviceProfile(); mRowCount = mIdp.numRows; mColumnCount = mIdp.numColumns; }
@Override public void onReceive(Context context, Intent intent) { mAppWidgetManager = AppWidgetManager.getInstance(context); mAppWidgetHost = new AppWidgetHost(context, intent.getIntExtra("appWidgetId", -1)); cellId = intent.getIntExtra("cellId", -1); int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); try { startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); } catch (ActivityNotFoundException e) { U.showToast(DashboardActivity.this, R.string.lock_device_not_supported); finish(); } shouldFinish = false; }
DatabaseHelper(Context context) { super(context, LauncherFiles.LAUNCHER_DB, null, DATABASE_VERSION); mContext = context; mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID); // Table creation sometimes fails silently, which leads to a crash loop. // This way, we will try to create a table every time after crash, so the device // would eventually be able to recover. if (!tableExists(TABLE_FAVORITES) || !tableExists(TABLE_WORKSPACE_SCREENS)) { Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate"); // This operation is a no-op if the table already exists. addFavoritesTable(getWritableDatabase(), true); addWorkspacesTable(getWritableDatabase(), true); } // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from // the DB here if (mMaxItemId == -1) { mMaxItemId = initializeMaxItemId(getWritableDatabase()); } if (mMaxScreenId == -1) { mMaxScreenId = initializeMaxScreenId(getWritableDatabase()); } }
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback, Resources res, int layoutId, String rootTag) { mContext = context; mAppWidgetHost = appWidgetHost; mCallback = callback; mPackageManager = context.getPackageManager(); mValues = new ContentValues(); mRootTag = rootTag; mSourceRes = res; mLayoutId = layoutId; InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile(); mHotseatAllAppsRank = idp.hotseatAllAppsRank; mRowCount = idp.numRows; mColumnCount = idp.numColumns; }
public void addProvider(MainActivity m, AppWidgetHost host, AppWidgetManager manager, AppWidgetProviderInfo provider) { int id = host.allocateAppWidgetId(); boolean success; success = manager.bindAppWidgetIdIfAllowed(id, provider.provider); if (success) { AppWidgetHostView hostView = host.createView(getActivity(), id, provider); AppWidgetProviderInfo appWidgetInfo = manager.getAppWidgetInfo(id); LauncherAppWidgetInfo info = new LauncherAppWidgetInfo(id); info.setHostView(hostView); info.getHostView().setAppWidget(id, appWidgetInfo); ItemInfo launcherInfo = attachWidget(info); if (launcherInfo != null) { WidgetPersistance.addDesktopAppWidget(screen, launcherInfo); } } else { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, provider.provider); m.startActivityForResult(intent, MainActivity.REQUEST_BIND_APPWIDGET); } }
static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback) { Pair<String, Resources> customizationApkInfo = Utilities.findSystemApk( ACTION_LAUNCHER_CUSTOMIZATION, context.getPackageManager()); if (customizationApkInfo == null) { return null; } String pkg = customizationApkInfo.first; Resources res = customizationApkInfo.second; int layoutId = res.getIdentifier(LAYOUT_RES, "xml", pkg); if (layoutId == 0) { Log.e(TAG, "Layout definition not found in package: " + pkg); return null; } return new AutoInstallsLayout(context, appWidgetHost, callback, res, layoutId, TAG_WORKSPACE); }
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback, Resources res, int layoutId, String rootTag) { mContext = context; mAppWidgetHost = appWidgetHost; mCallback = callback; mPackageManager = context.getPackageManager(); mValues = new ContentValues(); mRootTag = rootTag; mSourceRes = res; mLayoutId = layoutId; mHotseatAllAppsRank = LauncherAppState.getInstance() .getDynamicGrid().getDeviceProfile().hotseatAllAppsRank; }
@Override public void startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity, AppWidgetHost host, int requestCode) { try { host.startAppWidgetConfigureActivityForResult(activity, widgetId, 0, requestCode, null); } catch (ActivityNotFoundException | SecurityException e) { Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); } }
static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback) { Pair<String, Resources> customizationApkInfo = Utilities.findSystemApk( ACTION_LAUNCHER_CUSTOMIZATION, context.getPackageManager()); if (customizationApkInfo == null) { return null; } return get(context, customizationApkInfo.first, customizationApkInfo.second, appWidgetHost, callback); }
static AutoInstallsLayout get(Context context, String pkg, Resources targetRes, AppWidgetHost appWidgetHost, LayoutParserCallback callback) { InvariantDeviceProfile grid = LauncherAppState.getIDP(context); // Try with grid size and hotseat count String layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES_WITH_HOSTEAT, (int) grid.numColumns, (int) grid.numRows, (int) grid.numHotseatIcons); int layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); // Try with only grid size if (layoutId == 0) { layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES, (int) grid.numColumns, (int) grid.numRows); layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); } // Try the default layout if (layoutId == 0) { layoutId = targetRes.getIdentifier(LAYOUT_RES, "xml", pkg); } if (layoutId == 0) { return null; } return new AutoInstallsLayout(context, appWidgetHost, callback, targetRes, layoutId, TAG_WORKSPACE); }
@Override public void startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity, AppWidgetHost host, int requestCode) { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); intent.setComponent(info.configure); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); Utilities.startActivityForResultSafely(activity, intent, requestCode); }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { createDbIfNotExists(); SqlArguments args = new SqlArguments(uri, selection, selectionArgs); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); if (Binder.getCallingPid() != Process.myPid() && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) { String widgetSelection = TextUtils.isEmpty(args.where) ? "1=1" : args.where; widgetSelection = String.format(Locale.ENGLISH, "%1$s = %2$d AND ( %3$s )", Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET, widgetSelection); try (Cursor c = db.query(Favorites.TABLE_NAME, new String[] { Favorites.APPWIDGET_ID }, widgetSelection, args.args, null, null, null)) { AppWidgetHost host = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID); while (c.moveToNext()) { int widgetId = c.getInt(0); if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { try { host.deleteAppWidgetId(widgetId); } catch (RuntimeException e) { Log.e(TAG, "Error deleting widget id " + widgetId, e); } } } } } int count = db.delete(args.table, args.where, args.args); if (count > 0) { notifyListeners(); reloadLauncherIfExternal(); } return count; }
/** * Creates workspace loader from an XML resource listed in the app restrictions. * * @return the loader if the restrictions are set and the resource exists; null otherwise. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) { // UserManager.getApplicationRestrictions() requires minSdkVersion >= 18 if (!Utilities.ATLEAST_JB_MR2) { return null; } Context ctx = getContext(); UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE); Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName()); if (bundle == null) { return null; } String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME); if (packageName != null) { try { Resources targetResources = ctx.getPackageManager() .getResourcesForApplication(packageName); return AutoInstallsLayout.get(ctx, packageName, targetResources, widgetHost, mOpenHelper); } catch (NameNotFoundException e) { Log.e(TAG, "Target package for restricted profile not found", e); return null; } } return null; }
static AutoInstallsLayout get(Context context, String pkg, Resources targetRes, AppWidgetHost appWidgetHost, LayoutParserCallback callback) { InvariantDeviceProfile grid = LauncherAppState.getInstance().getInvariantDeviceProfile(); // Try with grid size and hotseat count String layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES_WITH_HOSTEAT, (int) grid.numColumns, (int) grid.numRows, (int) grid.numHotseatIcons); int layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); // Try with only grid size if (layoutId == 0) { Log.d(TAG, "Formatted layout: " + layoutName + " not found. Trying layout without hosteat"); layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES, (int) grid.numColumns, (int) grid.numRows); layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); } // Try the default layout if (layoutId == 0) { Log.d(TAG, "Formatted layout: " + layoutName + " not found. Trying the default layout"); layoutId = targetRes.getIdentifier(LAYOUT_RES, "xml", pkg); } if (layoutId == 0) { Log.e(TAG, "Layout definition not found in package: " + pkg); return null; } return new AutoInstallsLayout(context, appWidgetHost, callback, targetRes, layoutId, TAG_WORKSPACE); }
/** * Creates a LauncherAppWidgetInfo corresponding to {@param info} * @param bindWidget if true the info is bound and a valid widgetId is assigned to * the LauncherAppWidgetInfo */ private LauncherAppWidgetInfo createWidgetInfo( LauncherAppWidgetProviderInfo info, boolean bindWidget) { LauncherAppWidgetInfo item = new LauncherAppWidgetInfo( LauncherAppWidgetInfo.NO_ID, info.provider); item.spanX = info.minSpanX; item.spanY = info.minSpanY; item.minSpanX = info.minSpanX; item.minSpanY = info.minSpanY; item.user = mWidgetManager.getUser(info); item.cellX = 0; item.cellY = 1; item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP; if (bindWidget) { PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(mTargetContext, info); pendingInfo.spanX = item.spanX; pendingInfo.spanY = item.spanY; pendingInfo.minSpanX = item.minSpanX; pendingInfo.minSpanY = item.minSpanY; Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(mTargetContext, pendingInfo); AppWidgetHost host = new AppWidgetHost(mTargetContext, Launcher.APPWIDGET_HOST_ID); int widgetId = host.allocateAppWidgetId(); if (!mWidgetManager.bindAppWidgetIdIfAllowed(widgetId, info, options)) { host.deleteAppWidgetId(widgetId); throw new IllegalArgumentException("Unable to bind widget id"); } item.appWidgetId = widgetId; } return item; }
@Override public void onCreate() { super.onCreate(); context = getApplicationContext(); MainScope.oneW = true; sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new AppWidgetHost(this, R.id.APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); System.out.println("Widget ONE"); }
@Override protected void onCreate(Bundle Saved){ super.onCreate(Saved); mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new AppWidgetHost(this, 666); stopService(new Intent(getApplicationContext(), Widget_Floating_one.class)); stopService(new Intent(getApplicationContext(), Widget_Floating_two.class)); stopService(new Intent(getApplicationContext(), Widget_Floating_three.class)); MainScope.oneW = false; MainScope.twoW = false; MainScope.threeW = false; //Shortcuts Size SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); String s = sharedPrefs.getString("sizes", "2"); if(s.equals("1")){ MainScope.widgetH = 1; MainScope.widgetW = 1; } else if(s.equals("2")){ MainScope.widgetH = 130; MainScope.widgetW = 320; } else if(s.equals("3")){ MainScope.widgetH = 300; MainScope.widgetW = 320; } for(int i = 1; i <= 3; i++){ startWidgetService(i); } finish(); }
@Override public void onCreate() { super.onCreate(); context = getApplicationContext(); MainScope.oneW = true; sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new AppWidgetHost(this, R.id.APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); System.out.println("Widget Mini ONE"); }
DatabaseHelper(Context context) { super(context, LauncherFiles.LAUNCHER_DB, null, DATABASE_VERSION); mContext = context; mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID); // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from // the DB here if (mMaxItemId == -1) { mMaxItemId = initializeMaxItemId(getWritableDatabase()); } if (mMaxScreenId == -1) { mMaxScreenId = initializeMaxScreenId(getWritableDatabase()); } }