Example usage for android.appwidget AppWidgetManager OPTION_APPWIDGET_MIN_HEIGHT

List of usage examples for android.appwidget AppWidgetManager OPTION_APPWIDGET_MIN_HEIGHT

Introduction

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

Prototype

String OPTION_APPWIDGET_MIN_HEIGHT

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

Click Source Link

Document

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

Usage

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

@TargetApi(16)
@Override/*from  w ww . ja  va 2s .  c  om*/
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId,
        Bundle newOptions) {
    super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
    if (newOptions != null) {
        int newSize;
        if (newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                -1) == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
            newSize = 1;
        } else {
            int height = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
            if (height == 0) {
                newSize = 2;
            } else if (height >= FOUR_CELLS) {
                newSize = 4;
            } else if (height >= THREE_CELLS) {
                newSize = 3;
            } else if (height >= TWO_CELLS) {
                newSize = 2;
            } else {
                newSize = 1;
            }
        }
        int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
        if (size != newSize) {
            ApiAdapterFactory.getApiAdapter().setAppWidgetSize(appWidgetManager, appWidgetId, newSize);
            updateAppWidget(context, appWidgetManager, appWidgetId, -1L);
        }
    }
}

From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java

@TargetApi(16)
@Override/*from www . ja  v  a  2 s  .c  o m*/
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId,
        Bundle newOptions) {
    if (newOptions != null) {
        int size;
        int height = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
        if (height == 0) {
            size = 2;
        } else if (height >= FOUR_CELLS) {
            size = 4;
        } else if (height >= THREE_CELLS) {
            size = 3;
        } else if (height >= TWO_CELLS) {
            size = 2;
        } else {
            size = 1;
        }
        HEIGHT_SIZE.put(appWidgetId, size);
        RemoteViews remoteViews = getRemoteViews(context, -1L, size);
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

@TargetApi(JELLY_BEAN)
private int getLayoutJellyBean(@Nonnull AppWidgetManager manager, int widgetId, Resources resources,
        @Nonnull SimpleTheme theme) {/*from w w w  .j av  a2s .  c om*/
    final Bundle options = manager.getAppWidgetOptions(widgetId);
    if (options == null) {
        return getDefaultLayout(theme);
    }

    final int category = options.getInt(OPTION_APPWIDGET_HOST_CATEGORY, -1);
    if (category == -1) {
        return getDefaultLayout(theme);
    }

    final boolean keyguard = category == WIDGET_CATEGORY_KEYGUARD;
    if (!keyguard) {
        return getDefaultLayout(theme);
    }

    final int widgetMinHeight = App.toPixels(resources.getDisplayMetrics(),
            options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0));
    final int lockScreenMinHeight = resources.getDimensionPixelSize(R.dimen.min_expanded_height_lock_screen);
    final boolean expanded = widgetMinHeight >= lockScreenMinHeight;
    if (expanded) {
        return R.layout.widget_layout_lockscreen;
    } else {
        return R.layout.widget_layout_lockscreen_collapsed;
    }
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

/**
 * Based on the widget size determines whether to use a compact layout. Defaults to false on ICS
 * and below./*from   ww  w . j  a  v  a 2s .  c om*/
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static boolean isCompactLayout(AppWidgetManager appWidgetManager, int appWidgetId) {
    if (AndroidUtils.isJellyBeanOrHigher()) {
        Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
        int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
        return minHeight < DIP_THRESHOLD_COMPACT_LAYOUT;
    }
    return false;
}

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

static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
    Bundle options = null;/*from   w w  w .  j a  v  a 2  s  .  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;//w  ww.j  a va 2  s.c  o  m
    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 ww w. j  a v  a2s .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();
    }//  w  ww  .  j a  v  a  2  s. 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;
}