Example usage for android.appwidget AppWidgetManager getAppWidgetOptions

List of usage examples for android.appwidget AppWidgetManager getAppWidgetOptions

Introduction

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

Prototype

public Bundle getAppWidgetOptions(int appWidgetId) 

Source Link

Document

Get the extras associated with a given widget instance.

Usage

From source file:Main.java

public static final boolean isKeyguardWidget(int appWidgetId, Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext());

        return appWidgetManager.getAppWidgetOptions(appWidgetId).getInt(
                AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                -1) == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD;
    }//from  w w w .  jav  a2  s  . c o  m

    return false;
}

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./*  w w  w.  j  a  v a2  s  . 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.ultrafunk.network_info.config.ConfigActivity.java

private static boolean isLockscreenWidget(AppWidgetManager appWidgetManager, int appWidgetId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
        int category = widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1);
        return category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD;
    }/*from www  .  j  a  v a 2  s  . co  m*/

    return false;
}

From source file:org.openbitcoinwidget.WidgetProvider.java

private static boolean isWidgetShownOnLockScreen(AppWidgetManager appWidgetManager, int appWidgetId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // The below functionality was introduced in API version 16 (Jelly Bean)
        Bundle myOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);

        // Get the value of OPTION_APPWIDGET_HOST_CATEGORY
        int category = myOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1);

        // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget
        return category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD;
    }//  w w  w.ja v a 2 s.  c  o m
    return false;
}

From source file:com.androidinspain.deskclock.Utils.java

/**
 * @return {@code true} iff the widget is being hosted in a container where tapping is allowed
 *///  w  w  w . j  av a  2 s .c o m
public static boolean isWidgetClickable(AppWidgetManager widgetManager, int widgetId) {
    final Bundle wo = widgetManager.getAppWidgetOptions(widgetId);
    return wo != null && wo.getInt(OPTION_APPWIDGET_HOST_CATEGORY, -1) != WIDGET_CATEGORY_KEYGUARD;
}

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  a  va 2  s. co m*/
    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:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Update the widget.//from   w  w w  .ja v a 2 s .c  o  m
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
        final int appWidgetId) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), this.mLayoutId);
    final int idFavori = WidgetConfigureActivity.getFavoriIdFromWidget(context, appWidgetId);
    final Favori favori = FavorisViewManager.getInstance().getSingle(context.getContentResolver(), idFavori);

    if (DBG)
        Log.i(LOG_TAG, Integer.toHexString(hashCode()) + " - " + appWidgetId + " - updateAppWidget " + favori);

    // Initialisation du nombre d'horaires
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        final Bundle bundle = appWidgetManager.getAppWidgetOptions(appWidgetId);
        mHoraireLimit = getHorairesCount(context, bundle);
    } else {
        if (mHoraireLimit == -1) {
            mHoraireLimit = context.getResources().getInteger(mHoraireLimitRes);
        }
    }

    if (favori != null) {
        prepareWidgetView(context, views, favori, appWidgetId);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    } else {
        WidgetConfigureActivity.removeWidgetId(context, appWidgetId);
    }
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);

    // Launch setinngs when clicking on the time in the widget only if not a lock screen widget
    Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
            -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
        Intent mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings");
        mIntent.setComponent(component);
        widget.setOnClickPendingIntent(R.id.digital_appwidget,
                PendingIntent.getActivity(context, 0, mIntent, 0));
    }//from ww  w  .j  av  a2  s .  co m

    //cg sai.pan begin
    refreshWifiStatus(context, widget);
    refreshBtStatus(context, widget);
    refreshAirplaneStatus(context, widget,
            Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0);
    mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
    //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0);
    requestLocation(context);
    //cg sai.pan end

    // SPRD for bug421127 add am/pm for widget
    WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
            R.id.the_clock);
    WidgetUtils.setClockSize(context, widget, ratio);

    // Set today's date format
    CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            context.getString(R.string.abbrev_wday_month_day_no_year));
    widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat);
    widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat);

    appWidgetManager.updateAppWidget(appWidgetId, widget);
}