android.appwidget.AppWidgetHost Java Examples

The following examples show how to use android.appwidget.AppWidgetHost. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoInstallsLayout.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AutoInstallsLayout.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: LauncherProvider.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: AddItemActivity.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: AutoInstallsLayout.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: DashboardActivity.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@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);
        U.sendBroadcast(DashboardActivity.this, ACTION_TEMP_HIDE_TASKBAR);
    } catch (ActivityNotFoundException e) {
        U.showToast(DashboardActivity.this, R.string.tb_lock_device_not_supported);
        finish();
    }

    shouldFinish = false;
}
 
Example #7
Source File: AutoInstallsLayout.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: AutoInstallsLayout.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: LauncherProvider.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
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());
    }
}
 
Example #10
Source File: LauncherProvider.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, 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());
    }
}
 
Example #11
Source File: AppWidgetManagerCompatVL.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@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();
    }
}
 
Example #12
Source File: AppWidgetManagerCompatV16.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: AppWidgetManagerCompatV16.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: AutoInstallsLayout.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #15
Source File: AutoInstallsLayout.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: LauncherProvider.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example #17
Source File: AutoInstallsLayout.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
        LayoutParserCallback callback, Resources res,
        int layoutId, String rootTag, int hotseatAllAppsRank) {
    mContext = context;
    mAppWidgetHost = appWidgetHost;
    mCallback = callback;

    mPackageManager = context.getPackageManager();
    mValues = new ContentValues();
    mRootTag = rootTag;

    mSourceRes = res;
    mLayoutId = layoutId;
    mHotseatAllAppsRank = hotseatAllAppsRank;
}
 
Example #18
Source File: AppWidgetManagerCompat.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
public abstract void startConfigActivity(AppWidgetProviderInfo info, int widgetId,
Activity activity, AppWidgetHost host, int requestCode);
 
Example #19
Source File: AppWidgetsRestoredReceiver.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the app widgets whose id has changed during the restore process.
 */
static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds) {
    final ContentResolver cr = context.getContentResolver();
    final List<Integer> idsToRemove = new ArrayList<Integer>();
    final AppWidgetManager widgets = AppWidgetManager.getInstance(context);

    for (int i = 0; i < oldWidgetIds.length; i++) {
        Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);

        final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
        final int state;
        if (LauncherModel.isValidProvider(provider)) {
            // This will ensure that we show 'Click to setup' UI if required.
            state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
        } else {
            state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
        }

        ContentValues values = new ContentValues();
        values.put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]);
        values.put(LauncherSettings.Favorites.RESTORED, state);

        String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) };

        int result = cr.update(Favorites.CONTENT_URI, values,
                "appWidgetId=? and (restored & 1) = 1", widgetIdParams);
        if (result == 0) {
            Cursor cursor = cr.query(Favorites.CONTENT_URI,
                    new String[] {Favorites.APPWIDGET_ID},
                    "appWidgetId=?", widgetIdParams, null);
            try {
                if (!cursor.moveToFirst()) {
                    // The widget no long exists.
                    idsToRemove.add(newWidgetIds[i]);
                }
            } finally {
                cursor.close();
            }
        }
    }
    // Unregister the widget IDs which are not present on the workspace. This could happen
    // when a widget place holder is removed from workspace, before this method is called.
    if (!idsToRemove.isEmpty()) {
        final AppWidgetHost appWidgetHost =
                new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
        new AsyncTask<Void, Void, Void>() {
            public Void doInBackground(Void ... args) {
                for (Integer id : idsToRemove) {
                    appWidgetHost.deleteAppWidgetId(id);
                    Log.e(TAG, "Widget no longer present, appWidgetId=" + id);
                }
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
    }

    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.reloadWorkspace();
    }
}
 
Example #20
Source File: DefaultLayoutParser.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
        LayoutParserCallback callback, Resources sourceRes, int layoutId) {
    super(context, appWidgetHost, callback, sourceRes, layoutId, TAG_FAVORITES);
}
 
Example #21
Source File: DefaultLayoutParser.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
        LayoutParserCallback callback, Resources sourceRes, int layoutId) {
    super(context, appWidgetHost, callback, sourceRes, layoutId, TAG_FAVORITES);
    Log.e(TAG, "Default layout parser initialized");
}
 
Example #22
Source File: AppWidgetsRestoredReceiver.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the app widgets whose id has changed during the restore process.
 */
static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds) {
    final ContentResolver cr = context.getContentResolver();
    final List<Integer> idsToRemove = new ArrayList<Integer>();
    final AppWidgetManager widgets = AppWidgetManager.getInstance(context);

    for (int i = 0; i < oldWidgetIds.length; i++) {
        Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);

        final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
        final int state;
        if (LauncherModel.isValidProvider(provider)) {
            state = LauncherAppWidgetInfo.RESTORE_COMPLETED;
        } else {
            state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
        }

        ContentValues values = new ContentValues();
        values.put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]);
        values.put(LauncherSettings.Favorites.RESTORED, state);

        String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) };

        int result = cr.update(Favorites.CONTENT_URI, values,
                "appWidgetId=? and (restored & 1) = 1", widgetIdParams);
        if (result == 0) {
            Cursor cursor = cr.query(Favorites.CONTENT_URI,
                    new String[] {Favorites.APPWIDGET_ID},
                    "appWidgetId=?", widgetIdParams, null);
            try {
                if (!cursor.moveToFirst()) {
                    // The widget no long exists.
                    idsToRemove.add(newWidgetIds[i]);
                }
            } finally {
                cursor.close();
            }
        }
    }
    // Unregister the widget IDs which are not present on the workspace. This could happen
    // when a widget place holder is removed from workspace, before this method is called.
    if (!idsToRemove.isEmpty()) {
        final AppWidgetHost appWidgetHost =
                new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
        new AsyncTask<Void, Void, Void>() {
            public Void doInBackground(Void ... args) {
                for (Integer id : idsToRemove) {
                    appWidgetHost.deleteAppWidgetId(id);
                    Log.e(TAG, "Widget no longer present, appWidgetId=" + id);
                }
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
    }
}
 
Example #23
Source File: AutoInstallsLayout.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
        LayoutParserCallback callback, Resources res,
        int layoutId, String rootTag) {
    this(context, appWidgetHost, callback, res, layoutId, rootTag,
            LauncherAppState.getInstance().getInvariantDeviceProfile().hotseatAllAppsRank);
}
 
Example #24
Source File: DefaultLayoutParser.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
        LayoutParserCallback callback, Resources sourceRes, int layoutId, String rootTag,
        int hotseatAllAppsRank) {
    super(context, appWidgetHost, callback, sourceRes, layoutId, rootTag, hotseatAllAppsRank);
}
 
Example #25
Source File: AppWidgetManagerCompat.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public abstract void startConfigActivity(AppWidgetProviderInfo info, int widgetId,
Activity activity, AppWidgetHost host, int requestCode);
 
Example #26
Source File: AppWidgetsRestoredReceiver.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the app widgets whose id has changed during the restore process.
 */
static void restoreAppWidgetIds(Context context, PendingResult asyncResult,
        int[] oldWidgetIds, int[] newWidgetIds) {
    final ContentResolver cr = context.getContentResolver();
    final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
    AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);

    for (int i = 0; i < oldWidgetIds.length; i++) {

        final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
        final int state;
        if (LauncherModel.isValidProvider(provider)) {
            // This will ensure that we show 'Click to setup' UI if required.
            state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
        } else {
            state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
        }

        String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) };
        int result = new ContentWriter(context, new ContentWriter.CommitParams(
                "appWidgetId=? and (restored & 1) = 1", widgetIdParams))
                .put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
                .put(LauncherSettings.Favorites.RESTORED, state)
                .commit();

        if (result == 0) {
            Cursor cursor = cr.query(Favorites.CONTENT_URI,
                    new String[] {Favorites.APPWIDGET_ID},
                    "appWidgetId=?", widgetIdParams, null);
            try {
                if (!cursor.moveToFirst()) {
                    // The widget no long exists.
                    appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);
                }
            } finally {
                cursor.close();
            }
        }
    }

    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.getModel().forceReload();
    }
    asyncResult.finish();
}
 
Example #27
Source File: LauncherProvider.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
AppWidgetHost newLauncherWidgetHost() {
    return new AppWidgetHost(mContext, Launcher.APPWIDGET_HOST_ID);
}
 
Example #28
Source File: LauncherProvider.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) {
    int defaultLayout = LauncherAppState.getIDP(getContext()).defaultLayoutId;
    return new DefaultLayoutParser(getContext(), widgetHost,
            mOpenHelper, getContext().getResources(), defaultLayout);
}
 
Example #29
Source File: LauncherProvider.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Loads the default workspace based on the following priority scheme:
 *   1) From the app restrictions
 *   2) From a package provided by play store
 *   3) From a partner configuration APK, already in the system image
 *   4) The default configuration for the particular device
 */
synchronized private void loadDefaultFavoritesIfNecessary() {
    SharedPreferences sp = Utilities.getPrefs(getContext());

    if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {

        AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
        AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction(widgetHost);
        if (loader == null) {
            loader = AutoInstallsLayout.get(getContext(),widgetHost, mOpenHelper);
        }
        if (loader == null) {
            final Partner partner = Partner.get(getContext().getPackageManager());
            if (partner != null && partner.hasDefaultLayout()) {
                final Resources partnerRes = partner.getResources();
                int workspaceResId = partnerRes.getIdentifier(Partner.RES_DEFAULT_LAYOUT,
                        "xml", partner.getPackageName());
                if (workspaceResId != 0) {
                    loader = new DefaultLayoutParser(getContext(), widgetHost,
                            mOpenHelper, partnerRes, workspaceResId);
                }
            }
        }

        final boolean usingExternallyProvidedLayout = loader != null;
        if (loader == null) {
            loader = getDefaultLayoutParser(widgetHost);
        }

        // There might be some partially restored DB items, due to buggy restore logic in
        // previous versions of launcher.
        mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
        // Populate favorites table with initial favorites
        if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0)
                && usingExternallyProvidedLayout) {
            // Unable to load external layout. Cleanup and load the internal layout.
            mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
            mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(),
                    getDefaultLayoutParser(widgetHost));
        }
        clearFlagEmptyDbCreated();
    }
}
 
Example #30
Source File: DefaultLayoutParser.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
        LayoutParserCallback callback, Resources sourceRes, int layoutId) {
    super(context, appWidgetHost, callback, sourceRes, layoutId, TAG_FAVORITES);
}