Example usage for android.appwidget AppWidgetManager OPTION_APPWIDGET_MAX_HEIGHT

List of usage examples for android.appwidget AppWidgetManager OPTION_APPWIDGET_MAX_HEIGHT

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager OPTION_APPWIDGET_MAX_HEIGHT.

Prototype

String OPTION_APPWIDGET_MAX_HEIGHT

To view the source code for android.appwidget AppWidgetManager OPTION_APPWIDGET_MAX_HEIGHT.

Click Source Link

Document

A bundle extra that contains the upper bound on the current width, in dips, of a widget instance.

Usage

From source file:com.zyk.launcher.AsyncTaskCallback.java

static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;/*from ww  w  .ja v a 2s  .  c o  m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, sTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher, info.componentName, null);

        float density = launcher.getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, sTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, sTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, sTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, sTmpRect.bottom - yPaddingDips);
    }
    return options;
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;//ww  w  . ja v a  2  s  .c  om
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
        Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(mLauncher, info.componentName, null);

        float density = getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, mTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, mTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, mTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, mTmpRect.bottom - yPaddingDips);
    }
    return options;
}

From source file:com.android.launcher2.AsyncTaskCallback.java

Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;/*from   w ww  .j  a  v  a 2s  .c  o m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
        Rect padding = AppWidgetHostViewCompat.getDefaultPaddingForWidget(mLauncher, info.componentName, null);

        float density = getResources().getDisplayMetrics().density;
        int xPaddingDips = (int) ((padding.left + padding.right) / density);
        int yPaddingDips = (int) ((padding.top + padding.bottom) / density);

        options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, mTmpRect.left - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, mTmpRect.top - yPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, mTmpRect.right - xPaddingDips);
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, mTmpRect.bottom - yPaddingDips);
    }
    return options;
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

public View getOrCreateQsbBar() {
    if (launcherCallbacksProvidesSearch()) {
        return mLauncherCallbacks.getQsbBar();
    }//from  w  ww  .j ava  2s .  c o m

    if (mQsb == null) {
        AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
        if (searchProvider == null) {
            return null;
        }

        Bundle opts = new Bundle();
        opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);

        // Determine the min and max dimensions of the widget.
        LauncherAppState app = LauncherAppState.getInstance();
        DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
        DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
        float density = getResources().getDisplayMetrics().density;
        Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
        int maxHeight = (int) (searchDimens.y / density);
        int minHeight = maxHeight;
        int maxWidth = (int) ((searchDimens.x / density) / 5) * 3;
        int minWidth = maxWidth;
        if (!landscapeProfile.isVerticalBarLayout()) {
            searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
            maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
            minHeight = (int) Math.min(minHeight, searchDimens.y / density);
            maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
            minWidth = (int) Math.min(minWidth, searchDimens.x / density);
        }
        opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
        opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
        opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
        opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
        if (LOGD) {
            Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight + " maxWidth="
                    + maxWidth + " minWidth=" + minWidth);
        }

        if (mLauncherCallbacks != null) {
            opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
        }

        int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
        AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
        if (!searchProvider.provider.flattenToString().equals(mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
                || (widgetInfo == null) || !widgetInfo.provider.equals(searchProvider.provider)) {
            // A valid widget is not already bound.
            if (widgetId > -1) {
                mAppWidgetHost.deleteAppWidgetId(widgetId);
                widgetId = -1;
            }

            // Try to bind a new widget
            widgetId = View.generateViewId();

            mSharedPrefs.edit().putInt(QSB_WIDGET_ID, widgetId)
                    .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()).apply();
        }

        mAppWidgetHost.setQsbWidgetId(widgetId);

        if (widgetId != -1) {
            mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
            mQsb.setId(R.id.qsb_widget);
            mQsb.updateAppWidgetOptions(opts);

            // on tablets, we don't need this widget taking up the whole screen. It looks better
            // with some padding on the sides
            if (getResources().getBoolean(R.bool.reduce_search_width)) {
                Display display = getWindowManager().getDefaultDisplay();
                Point size = new Point();
                display.getSize(size);
                mQsb.setPadding(size.x / 8, 0, size.x / 8, 0);
            } else {
                mQsb.setPadding(0, 0, 0, 0);
            }

            mSearchDropTargetBar.addView(mQsb);
            mSearchDropTargetBar.setQsbSearchBar(mQsb);

            if (AppSettings.getInstance(this).showSearchBar) {
                createClickableSearch(1);
            } else {
                mQsb.getLayoutParams().width = 0;
            }
        }
    }
    return mQsb;
}