Java Code Examples for android.appwidget.AppWidgetManager#getAppWidgetOptions()

The following examples show how to use android.appwidget.AppWidgetManager#getAppWidgetOptions() . 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: WidgetProvider.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setLayout(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Bundle options = appWidgetManager.getAppWidgetOptions(widgetId);
    boolean isSmall = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) < 110;
    boolean isSingleLine = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) < 110;

    SparseArray<PendingIntent> map = new SparseArray<>();
    map.put(R.id.iv_launch_app, pendingIntentLaunchApp(context, widgetId));
    map.put(R.id.iv_add_record, pendingIntentAddRecord(context, widgetId));
    map.put(R.id.iv_add_mind, pendingIntentAddMind(context, widgetId));
    map.put(R.id.iv_add_photo, pendingIntentAddPhoto(context, widgetId));
    map.put(R.id.iv_add_sketch, pendingIntentAddSketch(context, widgetId));
    map.put(R.id.iv_setting, pendingIntentSetting(context, widgetId));

    RemoteViews views = getRemoteViews(context, widgetId, isSmall, isSingleLine, map);

    appWidgetManager.updateAppWidget(widgetId, views);
}
 
Example 2
Source File: SuntimesWidget0.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
protected static int[] widgetSizeDp(Context context, AppWidgetManager appWidgetManager, int appWidgetId, int[] defSize)
{
    int[] mustFitWithinDp = {defSize[0], defSize[1]};
    //Log.d("widgetSizeDp", "0: must fit:  [" + mustFitWithinDp[0] + ", " + mustFitWithinDp[1] + "]");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
        int[]  sizePortrait = { widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH),   // dp values
                widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT) };
        int[]  sizeLandscape = { widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH),
                widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) };

        //Log.d("widgetSizeDp", "portrait:  [" + sizePortrait[0] + ", " + sizePortrait[1] + "]");
        //Log.d("widgetSizeDp", "landscape: [" + sizeLandscape[0] + ", " + sizeLandscape[1] + "]");
        //Toast toast = Toast.makeText(context, "[" + sizePortrait[0] + ", " + sizePortrait[1] + "]; " + "[" + sizeLandscape[0] + ", " + sizeLandscape[1] + "]", Toast.LENGTH_SHORT);
        //toast.show();

        mustFitWithinDp[0] = Math.min( sizePortrait[0], sizeLandscape[0] );
        mustFitWithinDp[1] = Math.min( sizePortrait[1], sizeLandscape[1] );
        //Log.d("widgetSizeDp", "1: must fit:  [" + mustFitWithinDp[0] + ", " + mustFitWithinDp[1] + "]");
    }
    return mustFitWithinDp;
}
 
Example 3
Source File: SuntimesWidget0.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
protected static int[] widgetMaxSizeDp(Context context, AppWidgetManager appWidgetManager, int appWidgetId, int[] defSize)
{
    int[] mustFitWithinDp = {defSize[0], defSize[1]};
    //Log.d("widgetSizeDp", "0: must fit:  [" + mustFitWithinDp[0] + ", " + mustFitWithinDp[1] + "]");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
        int[]  sizePortrait = { widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH),   // dp values
                widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT) };
        int[]  sizeLandscape = { widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH),
                widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) };

        //Log.d("widgetSizeDp", "portrait:  [" + sizePortrait[0] + ", " + sizePortrait[1] + "]");
        //Log.d("widgetSizeDp", "landscape: [" + sizeLandscape[0] + ", " + sizeLandscape[1] + "]");
        //Toast toast = Toast.makeText(context, "[" + sizePortrait[0] + ", " + sizePortrait[1] + "]; " + "[" + sizeLandscape[0] + ", " + sizeLandscape[1] + "]", Toast.LENGTH_SHORT);
        //toast.show();

        mustFitWithinDp[0] = Math.max( sizePortrait[0], sizeLandscape[0] );
        mustFitWithinDp[1] = Math.max( sizePortrait[1], sizeLandscape[1] );
        //Log.d("widgetSizeDp", "1: must fit:  [" + mustFitWithinDp[0] + ", " + mustFitWithinDp[1] + "]");
    }
    return mustFitWithinDp;
}
 
Example 4
Source File: ProfileListWidgetProvider.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
private static void doOnUpdate(Context context, AppWidgetManager appWidgetManager, int appWidgetId, boolean fromOnUpdate)
{
    Bundle widgetIdOptions;
    widgetIdOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    boolean isLargeLayout = setLayoutParams(context, appWidgetManager, appWidgetId, widgetIdOptions);
    DataWrapper dataWrapper = new DataWrapper(context.getApplicationContext(), false, 0, false);
    RemoteViews widget = buildLayout(context, appWidgetId, isLargeLayout, dataWrapper);
    try {
        appWidgetManager.updateAppWidget(appWidgetId, widget);
    } catch (Exception e) {
        PPApplication.recordException(e);
    }

    if (!fromOnUpdate) {
        if (isLargeLayout) {
            if (!ApplicationPreferences.applicationWidgetListGridLayout)
                appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_profile_list);
            else
                appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_profile_grid);
        }
    }
}
 
Example 5
Source File: UnreadAppWidgetProvider.java    From ghwatch with Apache License 2.0 6 votes vote down vote up
/**
 * Determine appropriate widget view based on size.
 */
private RemoteViews getRemoteViews(Context context,AppWidgetManager appWidgetManager, int appWidgetId) {
  // 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);
  // First find out rows and columns based on width provided.
  int rows = getCellsForSize(minHeight);
  int columns = getCellsForSize(minWidth);

  if (columns == 1) {
    return new RemoteViews(context.getPackageName(),
            R.layout.widget_unread_1);
  } else {
    return new RemoteViews(context.getPackageName(),
            R.layout.widget_unread);
  }
}
 
Example 6
Source File: StatsWidget.java    From Hangar with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Tools.HangarLog("onReceive [" + this.getClass().getCanonicalName() + "]");

    AppWidgetManager mgr = AppWidgetManager.getInstance(context);

    int[] ids = mgr.getAppWidgetIds(new ComponentName(context, StatsWidget.class));

    for(int id : ids) {
        Tools.HangarLog("per id: " + id);
        try {
            Bundle options=mgr.getAppWidgetOptions(id);
            updateAppWidget(context, mgr, id, options);
        } catch (Exception e) {
            e.printStackTrace();
            Tools.HangarLog("NPE onReceive");
        }
    }
    super.onReceive(context, intent);
}
 
Example 7
Source File: AppsWidget.java    From Hangar with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Tools.HangarLog("onReceive [" + this.getClass().getCanonicalName() + "]");
    AppWidgetManager mgr = AppWidgetManager.getInstance(context);

    int[] ids = mgr.getAppWidgetIds(new ComponentName(context, AppsWidget.class));

    for(int id : ids) {
        Tools.HangarLog("per id: " + id);
        try {
            Bundle options=mgr.getAppWidgetOptions(id);
            updateAppWidget(context, mgr, id, options);
        } catch (Exception e) {
            e.printStackTrace();
            Tools.HangarLog("NPE onReceive");
        }
    }
    super.onReceive(context, intent);
}
 
Example 8
Source File: DynamicAppWidgetProvider.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Update widget width and height according to the current orientation.
 *
 * @param context The context associated with this widget provider.
 * @param appWidgetManager The app widget manager.
 * @param appWidgetId The app widget id to update the dimensions.
 */
protected void updateWidgetDimensions(@NonNull Context context,
        @NonNull AppWidgetManager appWidgetManager, int appWidgetId) {
    if (DynamicSdkUtils.is16()) {
        Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
        if (context.getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE) {
            mWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
            mHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
        } else {
            mWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
            mHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
        }
    }
}
 
Example 9
Source File: WidgetUtils.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
static Size getSize(Context context, AppWidgetManager appWidgetManager, int widgetId, float aspectRatio) {
    Bundle options = appWidgetManager.getAppWidgetOptions(widgetId);
    boolean isPort = context.getResources().getBoolean(R.bool.isPort);
    int w = options.getInt(isPort ? AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH : AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
    int h = options.getInt(isPort ? AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT : AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
    return new Size(w, h, aspectRatio);
}
 
Example 10
Source File: TodayWidgetIntentService.java    From Advanced_Android_Development with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int getWidgetWidthFromOptions(AppWidgetManager appWidgetManager, int appWidgetId) {
    Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (options.containsKey(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)) {
        int minWidthDp = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
        // The width returned is in dp, but we'll convert it to pixels to match the other widths
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidthDp,
                displayMetrics);
    }
    return  getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
}
 
Example 11
Source File: WidgetUtils.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
static Size getSize(Context context, AppWidgetManager appWidgetManager, int widgetId, float aspectRatio) {
    Bundle options = appWidgetManager.getAppWidgetOptions(widgetId);
    boolean isPort = context.getResources().getBoolean(R.bool.isPort);
    int w = options.getInt(isPort ? AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH : AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
    int h = options.getInt(isPort ? AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT : AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
    return new Size(w, h, aspectRatio);
}
 
Example 12
Source File: WidgetProvider.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
        updateWidget(context, appWidgetManager, appWidgetId, newOptions);
    }
}
 
Example 13
Source File: GraphUtils.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
protected static int[] getWidgetSize(Context context, int appWidgetId) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(
            context.getApplicationContext());

    AppWidgetProviderInfo providerInfo = appWidgetManager.getAppWidgetInfo(appWidgetId);

    int mWidgetLandWidth = providerInfo.minWidth;
    int mWidgetPortHeight = providerInfo.minHeight;
    int mWidgetPortWidth = providerInfo.minWidth;
    int mWidgetLandHeight = providerInfo.minHeight;

    Bundle mAppWidgetOptions = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mAppWidgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    }

    if (mAppWidgetOptions != null
            && mAppWidgetOptions
            .getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) > 0) {

        mWidgetPortWidth = mAppWidgetOptions
                .getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
        mWidgetLandWidth = mAppWidgetOptions
                .getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
        mWidgetLandHeight = mAppWidgetOptions
                .getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
        mWidgetPortHeight = mAppWidgetOptions
                .getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
    } else {
        mWidgetLandWidth = providerInfo.minWidth;
        mWidgetPortHeight = providerInfo.minHeight;
        mWidgetPortWidth = providerInfo.minWidth;
        mWidgetLandHeight = providerInfo.minHeight;
    }

    int mWidgetWidthPerOrientation = mWidgetPortWidth;
    int mWidgetHeightPerOrientation = mWidgetPortHeight;
    if (!isPortrait(context)) {
        mWidgetWidthPerOrientation = mWidgetLandWidth;
        mWidgetHeightPerOrientation = mWidgetLandHeight;
    }
    int[] size = new int[2];
    if (AppPreference.isWidgetGraphNativeScaled(context)) {
        size[0] = mWidgetWidthPerOrientation;
        size[1] = mWidgetHeightPerOrientation;
        return size;
    }
    size[0] = dipToPixels(context, mWidgetWidthPerOrientation);
    size[1] = dipToPixels(context, mWidgetHeightPerOrientation);
    return size;
}
 
Example 14
Source File: BarWidgetProvider.java    From android with Apache License 2.0 4 votes vote down vote up
private boolean useLongDates(AppWidgetManager awm, int id) {
    Bundle opt = awm.getAppWidgetOptions(id);
    int minWidth = opt.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
    return minWidth > 350;
}
 
Example 15
Source File: Api16Adapter.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
public int getAppWidgetSize(AppWidgetManager appWidgetManager, int appWidgetId) {
  Bundle bundle = appWidgetManager.getAppWidgetOptions(appWidgetId);
  return bundle.getInt(APP_WIDGET_SIZE_KEY, getAppWidgetSizeDefault(bundle));
}
 
Example 16
Source File: SuntimesWidget0.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(17)
public static int widgetCategory(AppWidgetManager appWidgetManager, int appWidgetId)
{
    Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    return widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY);
}