Example usage for android.appwidget AppWidgetProviderInfo WIDGET_CATEGORY_KEYGUARD

List of usage examples for android.appwidget AppWidgetProviderInfo WIDGET_CATEGORY_KEYGUARD

Introduction

In this page you can find the example usage for android.appwidget AppWidgetProviderInfo WIDGET_CATEGORY_KEYGUARD.

Prototype

int WIDGET_CATEGORY_KEYGUARD

To view the source code for android.appwidget AppWidgetProviderInfo WIDGET_CATEGORY_KEYGUARD.

Click Source Link

Document

Indicates that the widget can be displayed on the keyguard.

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;
    }/*w w  w .  j  ava 2 s .c  om*/

    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 ww  .jav a  2s. com*/
    return false;
}

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

@TargetApi(16)
@Override/*w w w . j  a  va2  s  .  com*/
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: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;
    }/*  w  w w.  j av a 2  s  .c om*/

    return false;
}

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 w  w  w.  j  a  va  2 s  .c  o 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);
}