android.appwidget.AppWidgetManager Java Examples

The following examples show how to use android.appwidget.AppWidgetManager. 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: ConfigureActivityBase.java    From ministocks with MIT License 6 votes vote down vote up
private void setupWidget(int size) {
    // Update the widget when we end configuration
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        setResult(RESULT_OK, resultValue);

        WidgetRepository widgetRepository = new AndroidWidgetRepository(getBaseContext());
        widgetRepository.addWidget(appWidgetId, size);
        WidgetProviderBase.updateWidgetAsync(getApplicationContext(), appWidgetId,
                WidgetProviderBase.UpdateType.VIEW_UPDATE);
    }
    finish();
}
 
Example #2
Source File: WeatherAppWidget.java    From LittleFreshWeather with Apache License 2.0 6 votes vote down vote up
private void renderTime() {
    ComponentName thisWidget = new ComponentName(mContext, WeatherAppWidget.class);
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
    for (int i = 0; i < appWidgetIds.length; ++i) {
        int appWidgetId = appWidgetIds[i];
        RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.app_widget_layout);

        if (mDataDate != null && mDataDate.compareToIgnoreCase(StringUtil.getCurrentDateTime("yyyy-MM-dd")) != 0) {
            views.setTextColor(R.id.tv_app_widget_weather_desc, mContext.getApplicationContext().getResources().getColor(R.color.colorAirFour));
            views.setTextViewText(R.id.tv_app_widget_weather_desc, mContext.getApplicationContext().getString(R.string.data_out_of_date));
        }

        views.setTextViewText(R.id.tv_app_widget_time, StringUtil.getCurrentDateTime("HH:mm"));
        views.setTextViewText(R.id.tv_app_widget_dayofweek, StringUtil.getCurrentDateTime("EEEE"));
        views.setTextViewText(R.id.tv_app_widget_date, StringUtil.getCurrentDateTime("M月d日"));

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }

    renderData(mEntity);

    updateTimeSequence();
    LogUtil.e(TAG, "renderTime");
}
 
Example #3
Source File: FSAppWidgetProvider.java    From android-tutorials-glide with MIT License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.custom_view_futurestudio);

    appWidgetTarget = new AppWidgetTarget(context, remoteViews, R.id.custom_view_image, appWidgetIds) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            super.onResourceReady(resource, glideAnimation);
        }
    };

    Glide
            .with(context.getApplicationContext())
            .load(GlideExampleActivity.eatFoodyImages[3])
            .asBitmap()
            .into(appWidgetTarget);

    pushWidgetUpdate(context, remoteViews);
}
 
Example #4
Source File: Widget.java    From KernelAdiutor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int appWidgetId : appWidgetIds) {
        Intent svcIntent = new Intent(context, WidgetService.class);
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile);
        widget.setRemoteAdapter(R.id.profile_list, svcIntent);

        widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

        appWidgetManager.updateAppWidget(appWidgetId, widget);
    }
}
 
Example #5
Source File: SettingsActivity.java    From WalletCordova with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void onStop() {
    super.onStop();
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);

    try
    {
        final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);

        if (appWidgetIds.length > 0)
        {
            WalletBalanceWidgetProvider.runAsyncTask(this, appWidgetManager, appWidgetIds);
        }
    }
    catch (final RuntimeException x)
    {
    }
}
 
Example #6
Source File: WidgetPickerActivity.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("NewApi")
private void startAppWidgetConfigure(@NonNull AppWidgetProviderInfo appWidget, int id) {
    try {
        if (Device.hasLollipopApi()) {
            mAppWidgetHost.startAppWidgetConfigureActivityForResult(
                    this, id, 0, REQUEST_APPWIDGET_CONFIGURE, null);
        } else {
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
            intent.setComponent(appWidget.configure);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
            startActivityForResult(intent, REQUEST_APPWIDGET_CONFIGURE);
        }
    } catch (Exception e) {
        if (Device.isLge()) {
            CharSequence message = Html.fromHtml(getString(R.string.error_dialog_custom_widget_lg));
            new MaterialDialog.Builder(this)
                    .title(R.string.error_dialog_title)
                    .content(message)
                    .positiveText(android.R.string.ok)
                    .show();
        } else ToastUtils.showLong(this, R.string.error_dialog_title);
    }
}
 
Example #7
Source File: BookmarkWidgetProvider.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    // Handle bookmark-specific updates ourselves because they might be
    // coming in without extras, which AppWidgetProvider then blocks.
    final String action = intent.getAction();
    if (getBookmarkAppWidgetUpdateAction(context).equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
            performUpdate(context, appWidgetManager,
                    new int[] {IntentUtils.safeGetIntExtra(intent,
                            AppWidgetManager.EXTRA_APPWIDGET_ID, -1)});
        } else {
            performUpdate(context, appWidgetManager,
                    appWidgetManager.getAppWidgetIds(getComponentName(context)));
        }
    } else {
        super.onReceive(context, intent);
    }
}
 
Example #8
Source File: Tu123WidgetProvider.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
	final int widgetCount = appWidgetIds.length;
	
	// Load Data.
	if (mFavorites == null || mFavorites.isEmpty())
	{
		initData(context);
	}
	
	for (int i = 0; i < widgetCount; i++)
	{
		int appWidgetId = appWidgetIds[i];
		updateAppWidget(context, appWidgetManager, appWidgetId);
	}
}
 
Example #9
Source File: Widgetv.java    From isu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    boolean su = Tools.SuVersionBool(Tools.SuVersion(context));
    for (int appWidgetId: appWidgetIds) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layoutv);
        if (su) {
            remoteViews.setOnClickPendingIntent(R.id.iSuMain, getPendingSelfIntent(context, ACTION_SU));
            remoteViews.setOnClickPendingIntent(R.id.iSuMonitor, getPendingSelfIntent(context, ACTION_SELINUX));
        } else {
            remoteViews.setTextViewText(R.id.iSuMain, context.getString(R.string.not_available));
            remoteViews.setTextViewText(R.id.iSuMonitor, context.getString(R.string.not_available));
        }
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
    if (su)
        Tools.updateAllWidgets(true, context, R.layout.widget_layoutv, Widgetv.class);
    Tools.closeSU();
}
 
Example #10
Source File: WidgetProvider.java    From Document-Scanner with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

    Intent configIntent1 = new Intent(context, DocumentScannerActivity.class);
    configIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
    configIntent1.putExtra(DocumentScannerActivity.WidgetCameraIntent, true);

    Intent configIntent2 = new Intent(context, OcrCaptureActivity.class);
    configIntent2.putExtra(OcrCaptureActivity.AutoFocus, true);
    configIntent2.putExtra(OcrCaptureActivity.UseFlash, false);
    configIntent2.putExtra(OcrCaptureActivity.WidgetIntent, true);
    Intent configIntent3 = new Intent(context, GalleryGridActivity.class);

    PendingIntent configPendingIntent1 = PendingIntent.getActivity(context, 0, configIntent1, 0);
    PendingIntent configPendingIntent2 = PendingIntent.getActivity(context, 0, configIntent2, 0);
    PendingIntent configPendingIntent3 = PendingIntent.getActivity(context, 0, configIntent3, 0);

    remoteViews.setOnClickPendingIntent(R.id.wb1home, configPendingIntent1);
    remoteViews.setOnClickPendingIntent(R.id.wb2ocr, configPendingIntent2);
    remoteViews.setOnClickPendingIntent(R.id.wb3gallery, configPendingIntent3);

   appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);

}
 
Example #11
Source File: TorchWidgetProvider.java    From Torch with GNU General Public License v3.0 6 votes vote down vote up
public void updateState(Context context, int appWidgetId) {
    RemoteViews mViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    Intent mStateIntent = context.registerReceiver(null,
            new IntentFilter(TorchSwitch.TORCH_STATE_CHANGED));
    boolean on = mStateIntent != null && mStateIntent.getIntExtra("state", 0) != 0;

    SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String mPrefColor = mPreferences.getString(WidgetActivity.KEY_WIDGET_COLOR, context.getString(R.string.red));
    mViews.setInt(R.id.shape, "setColorFilter", Utils.getPrefColor(context, mPrefColor));

    mViews.setOnClickPendingIntent(R.id.button, getLaunchPendingIntent(context, appWidgetId, 0));

    if (on) {
        mViews.setImageViewResource(R.id.widget, widgetState.ON.getImgDrawable());
    } else {
        mViews.setImageViewResource(R.id.widget, widgetState.OFF.getImgDrawable());
    }

    AppWidgetManager mWidgetManager = AppWidgetManager.getInstance(context);
    mWidgetManager.updateAppWidget(appWidgetId, mViews);
}
 
Example #12
Source File: WidgetConfigure.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setResult(RESULT_CANCELED);

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        mOnlyCity = extras.getBoolean("onlyCity", false);
    }

    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        finish();
    }

    cityDialog();

}
 
Example #13
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private AppWidgetProviderInfo findAppWidgetProviderInfo(ComponentName component) {
    if (mWidgetMap == null) {
        List<AppWidgetProviderInfo> widgets =
                AppWidgetManager.getInstance(mContext).getInstalledProviders();
        mWidgetMap = new HashMap<ComponentName, AppWidgetProviderInfo>(widgets.size());
        for (AppWidgetProviderInfo info : widgets) {
            mWidgetMap.put(info.provider, info);
        }
    }
    return mWidgetMap.get(component);
}
 
Example #14
Source File: WidgetThemeListActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void initData(Context context)
{
    data = new SuntimesRiseSetData(context, AppWidgetManager.INVALID_APPWIDGET_ID);   // use app configuration
    data.setCompareMode(WidgetSettings.CompareMode.TOMORROW);
    data.setTimeMode(WidgetSettings.TimeMode.OFFICIAL);
    data.calculate();

    SuntimesRiseSetData noonData = new SuntimesRiseSetData(data);
    noonData.setTimeMode(WidgetSettings.TimeMode.NOON);
    noonData.calculate();
    data.linkData(noonData);
}
 
Example #15
Source File: WidgetProviderClock.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int widgetId) {
    ForegroundService.addNeedy(context, WidgetUtils.WIDGETS_FOREGROUND_NEEDY);
    LocaleUtils.init(context);
    if (!Preferences.SHOW_LEGACY_WIDGET.get())
        WidgetV24.update4x2Clock(context, appWidgetManager, widgetId);
    else
        WidgetLegacy.update4x2Clock(context, appWidgetManager, widgetId);


}
 
Example #16
Source File: OverclockingWidgetView.java    From rpicheck with MIT License 5 votes vote down vote up
public static void stopRefreshing(RemoteViews views, Context context, int appWidgetId) {
    LOGGER.debug("Stopping refresh view for Widget[ID={}].", appWidgetId);
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    views.setViewVisibility(R.id.buttonRefresh, View.VISIBLE);
    views.setViewVisibility(R.id.refreshProgressBar, View.GONE);
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example #17
Source File: EarthquakeListWidget.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdate(Context context,
                     AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
  PendingResult pendingResult = goAsync();
  updateAppWidgets(context, appWidgetManager, appWidgetIds, pendingResult);
}
 
Example #18
Source File: SuntimesConfigActivity2_3x1.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void updateWidgets(Context context, int[] appWidgetIds)
{
    Intent updateIntent = new Intent(context, SuntimesWidget2_3x1.class);
    updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    sendBroadcast(updateIntent);

    //SuntimesWidget2_3x1.updateAppWidget(context, AppWidgetManager.getInstance(context), appWidgetId, SuntimesWidget2_3x1.class, minWidgetSize, new SunPosLayout_3X1_0());
}
 
Example #19
Source File: AccountWidgetProvider.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
       // Update each requested appWidgetId
       for (int widgetId : appWidgetIds) {
       	RemoteViews view = buildUpdate(context, widgetId);
           appWidgetManager.updateAppWidget(widgetId, view);
       }
}
 
Example #20
Source File: UpdateWidgetsAction.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Context context, ContentProviderClient contentProviderClient, RowDataSnapshot<TaskContract.Instances> rowSnapshot, Uri taskUri)
{
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    notifyTaskListDataChanged(appWidgetManager, new ComponentName(context, TaskListWidgetProvider.class));
    notifyTaskListDataChanged(appWidgetManager, new ComponentName(context, TaskListWidgetProviderLarge.class));
}
 
Example #21
Source File: WidgetConfigActivity.java    From homeassist with Apache License 2.0 5 votes vote down vote up
private void performDone() {

        int pos = mListView.getCheckedItemPosition();
        if (pos == -1) {
            Toast.makeText(this, "Please select a control", Toast.LENGTH_SHORT).show();
            return;
        }
        Entity selectedItem = (Entity) mAdapter.getItem(pos);

        int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            appWidgetId = extras.getInt(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID);

            mDatabaseManager.insertWidget(appWidgetId, selectedItem);
            Widget widget = Widget.getInstance(selectedItem, appWidgetId);
            EntityWidgetProvider.updateEntityWidget(this, widget);

            setResult(RESULT_OK);
            finish();
        }
        if (appWidgetId == INVALID_APPWIDGET_ID) {
            Log.i("I am invalid", "I am invalid");
            finish();
        }
    }
 
Example #22
Source File: MptWidgetProvider.java    From android with Apache License 2.0 5 votes vote down vote up
protected void updateWithError(Context context, String error) {
    AppWidgetManager mgr = AppWidgetManager.getInstance(context);
    ComponentName cn = new ComponentName(context, getWidgetClass());
    int[] appWidgetIds = mgr.getAppWidgetIds(cn);

    if (appWidgetIds.length == 0) return;

    for (int appWidgetId : appWidgetIds) {
        RemoteViews layout = buildErrorLayout(mgr, context, appWidgetId, error);
        mgr.updateAppWidget(appWidgetId, layout);
    }
}
 
Example #23
Source File: UpDownWidget.java    From homescreenarcade with GNU General Public License v3.0 5 votes vote down vote up
protected void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.up_down_widget);
    views.setOnClickPendingIntent(R.id.up_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_UP), 0));
    views.setOnClickPendingIntent(R.id.down_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_DOWN), 0));
            
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example #24
Source File: RssfeedWidgetProvider.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
	// user pressed an item or a refresh button
	
	String action = intent.getAction();
	
	if (ACTION_REFRESH.equals(action)) { // refresh data 
		WorkerThread.get().post(new Runnable() {
			@Override public void run() {

				// get data and store it locally
				List<RssItem> feeds = RssFeedProvider.parse("http://www.vogella.com/article.rss");
				InMemoryDataStorage.get().setData(feeds);
				
				// request update for all widgets
                   AppWidgetManager mgr = AppWidgetManager.getInstance(context);
                   int[] widgetIds = mgr.getAppWidgetIds(new ComponentName(context, RssfeedWidgetProvider.class));
                   mgr.notifyAppWidgetViewDataChanged(widgetIds, R.id.feeds_list);

			}
		});
		
	} else if (ACTION_SHOW_LINK.equals(action)) { // show the feed
           String link = intent.getStringExtra(EXT_LINK);
           
           Intent launchIntent = new Intent(context, RssfeedActivity.class);
           launchIntent.putExtra(RssfeedActivity.EXTRA_URL, link);
           launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(launchIntent);
           
	}
	
	super.onReceive(context, intent);
}
 
Example #25
Source File: ExpensesWidgetProvider.java    From Expense-Tracker-App with MIT License 5 votes vote down vote up
@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds){
            Intent expenseDetailActivity = new Intent(context, ExpenseDetailActivity.class);
            Intent mainActivityIntent = new Intent(context, MainActivity.class);

            // Creating stack for builder item click
            TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
            taskStackBuilder.addParentStack(MainActivity.class);
            taskStackBuilder.addNextIntent(mainActivityIntent);
            taskStackBuilder.addNextIntent(expenseDetailActivity);
            PendingIntent itemClickPendingIntent = taskStackBuilder.getPendingIntent(0 ,PendingIntent.FLAG_UPDATE_CURRENT);

            // Create pending intent for clicking the whole view, not an item
            PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Intent widgetServiceIntent = new Intent(context, ExpensesWidgetService.class);
//            widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
//            widgetServiceIntent.setData(Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));

            RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
            remoteView.setOnClickPendingIntent(R.id.general_layout, mainPendingIntent);

            remoteView.setEmptyView(R.id.listViewWidget, R.id.empty_view);
            remoteView.setRemoteAdapter(appWidgetId, R.id.listViewWidget, widgetServiceIntent);
            remoteView.setTextViewText(R.id.tv_total, context.getString(R.string.today_expenses_total, Util.getFormattedCurrency(Expense.getTotalExpensesByDateMode(IDateMode.MODE_TODAY))));
            remoteView.setPendingIntentTemplate(R.id.listViewWidget, itemClickPendingIntent);
            ComponentName component=new ComponentName(context, ExpensesWidgetProvider.class);
            appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listViewWidget);
            appWidgetManager.updateAppWidget(component, remoteView);
        }
    }
 
Example #26
Source File: LessonsWidgetProvider_4_2.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
		int[] appWidgetIds) {
	// TODO Auto-generated method stub
	super.onUpdate(context, appWidgetManager, appWidgetIds);
	// System.out.println("onUpdate");
	// Log.v("zq.whu.zhangshangwuda.ui.lessons.widget_4_2", "onUpdate");
	sendBroadcastToday(context);
}
 
Example #27
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 #28
Source File: YambaWidget.java    From Yamba with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	super.onReceive(context, intent);
	AppWidgetManager appWidgetManager = AppWidgetManager
			.getInstance(context);
	this.onUpdate(context, appWidgetManager, appWidgetManager
			.getAppWidgetIds(new ComponentName(context, YambaWidget.class)));

}
 
Example #29
Source File: WidgetConfigure.java    From writeily-pro with MIT License 5 votes vote down vote up
public final void complete(String directory) {
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(
                AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);

        Context context = getApplicationContext();

        // Store widget filter
        SharedPreferences preferences = context.getSharedPreferences("" + mAppWidgetId, MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(Constants.WIDGET_PATH, directory);
        editor.apply();

        Intent resultValue = new Intent(context, FilesWidgetService.class);
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
        setResult(RESULT_OK, resultValue);

        Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, WriteilyWidgetProvider.class);
        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{mAppWidgetId});
        sendBroadcast(i);

        finish();
    }
}
 
Example #30
Source File: BaseAppWidget.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager,
                     final int[] appWidgetIds) {
    defaultAppWidget(context, appWidgetIds);
    final Intent updateIntent = new Intent(MusicService.APP_WIDGET_UPDATE);
    updateIntent.putExtra(MusicService.EXTRA_APP_WIDGET_NAME, NAME);
    updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    context.sendBroadcast(updateIntent);
}