Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to A--C , this is possible for Jellybean and above devices and is simple to implement. Below is the sample code using <code>onAppWidgetOptionsChanged</code> method</p> <pre><code>@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { Log.d(DEBUG_TAG, "Changed dimensions"); // See the dimensions and Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); // Get min width and height. int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); int minHeight = options .getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); // Obtain appropriate widget and update it. appWidgetManager.updateAppWidget(appWidgetId, getRemoteViews(context, minWidth, minHeight)); super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); } /** * Determine appropriate view based on width provided. * * @param minWidth * @param minHeight * @return */ private RemoteViews getRemoteViews(Context context, int minWidth, int minHeight) { // First find out rows and columns based on width provided. int rows = getCellsForSize(minHeight); int columns = getCellsForSize(minWidth); if (columns == 4) { // Get 4 column widget remote view and return } else { // Get appropriate remote view. return new RemoteViews(context.getPackageName(), R.layout.quick_add_widget_3_1); } } /** * Returns number of cells needed for given size of the widget. * * @param size Widget size in dp. * @return Size in number of cells. */ private static int getCellsForSize(int size) { int n = 2; while (70 * n - 30 &lt; size) { ++n; } return n - 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload