Search in sources :

Example 41 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project k-9 by k9mail.

the class UnreadWidgetConfiguration method onAccountSelected.

@Override
protected void onAccountSelected(BaseAccount account) {
    // Save widget configuration
    String accountUuid = account.getUuid();
    saveAccountUuid(this, mAppWidgetId, accountUuid);
    // Update widget
    Context context = getApplicationContext();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    UnreadWidgetProvider.updateWidget(context, appWidgetManager, mAppWidgetId, accountUuid);
    // Let the caller know that the configuration was successful
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
    setResult(RESULT_OK, resultValue);
    finish();
}
Also used : Context(android.content.Context) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent)

Example 42 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project k-9 by k9mail.

the class UnreadWidgetProvider method updateUnreadCount.

/**
     * Trigger update for all of our unread widgets.
     *
     * @param context
     *         The {@code Context} object to use for the broadcast intent.
     */
public static void updateUnreadCount(Context context) {
    Context appContext = context.getApplicationContext();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(appContext);
    ComponentName thisWidget = new ComponentName(appContext, UnreadWidgetProvider.class);
    int[] widgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
    Intent intent = new Intent(context, UnreadWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
    context.sendBroadcast(intent);
}
Also used : Context(android.content.Context) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 43 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project Shuttle by timusus.

the class BaseWidgetConfigure method onClick.

@Override
public void onClick(View view) {
    if (view.getId() == R.id.btn_done) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
        RemoteViews remoteViews = new RemoteViews(this.getPackageName(), mLayoutId);
        BaseWidgetProvider.setupButtons(this, remoteViews, mAppWidgetId, getRootViewId());
        appWidgetManager.updateAppWidget(mAppWidgetId, remoteViews);
        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
        setResult(RESULT_OK, resultValue);
        // Send broadcast intent to any running MediaPlaybackService so it can
        // wrap around with an immediate update.
        Intent updateIntent = new Intent(MusicService.ServiceCommand.SERVICE_COMMAND);
        updateIntent.putExtra(MusicService.MediaButtonCommand.CMD_NAME, getUpdateCommandString());
        updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId });
        updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
        sendBroadcast(updateIntent);
        finish();
    }
    if (view.getId() == R.id.btn_background_color) {
        DialogUtils.showCustomColorPickerDialog(this, ColorUtils.adjustAlpha(mBackgroundColor, mAlpha), color -> {
            mBackgroundColor = color;
            mPrefs.edit().putInt(BaseWidgetProvider.ARG_WIDGET_BACKGROUND_COLOR + mAppWidgetId, color).apply();
            Fragment fragment = mPagerAdapter.getRegisteredFragment(mPager.getCurrentItem());
            if (fragment != null) {
                View fragmentView = fragment.getView();
                if (fragmentView != null) {
                    View layout = fragmentView.findViewById(getRootViewId());
                    layout.setBackgroundColor(ColorUtils.adjustAlpha(mBackgroundColor, mAlpha));
                }
            }
        });
    }
    if (view.getId() == R.id.btn_text_color) {
        DialogUtils.showCustomColorPickerDialog(this, mTextColor, color -> {
            mTextColor = color;
            mPrefs.edit().putInt(BaseWidgetProvider.ARG_WIDGET_TEXT_COLOR + mAppWidgetId, color).apply();
            Fragment fragment = mPagerAdapter.getRegisteredFragment(mPager.getCurrentItem());
            if (fragment != null) {
                View widgetView = fragment.getView();
                if (widgetView != null) {
                    TextView text1 = (TextView) widgetView.findViewById(R.id.text1);
                    TextView text2 = (TextView) widgetView.findViewById(R.id.text2);
                    TextView text3 = (TextView) widgetView.findViewById(R.id.text3);
                    if (text1 != null) {
                        text1.setTextColor(mTextColor);
                    }
                    if (text2 != null) {
                        text2.setTextColor(mTextColor);
                    }
                    if (text3 != null) {
                        text3.setTextColor(mTextColor);
                    }
                }
            }
        });
    }
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent) TextView(android.widget.TextView) WidgetFragment(com.simplecity.amp_library.ui.fragments.WidgetFragment) Fragment(android.support.v4.app.Fragment) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 44 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project qksms by moezbhatti.

the class WidgetProvider method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Log.v(TAG, "onReceive intent: " + intent);
    String action = intent.getAction();
    // needs to update.
    if (ACTION_NOTIFY_DATASET_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class));
        // We need to update all Mms appwidgets on the home screen.
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.conversation_list);
    } else {
        super.onReceive(context, intent);
    }
}
Also used : AppWidgetProvider(android.appwidget.AppWidgetProvider) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 45 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project Fairphone by Kwamecorp.

the class GappsInstallerHelper method updateGoogleAppsIntallerWidgets.

private void updateGoogleAppsIntallerWidgets() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(mContext, GoogleAppsInstallerWidget.class));
    if (appWidgetIds.length > 0) {
        new GoogleAppsInstallerWidget().onUpdate(mContext, appWidgetManager, appWidgetIds);
    }
}
Also used : GoogleAppsInstallerWidget(org.fairphone.widgets.gapps.GoogleAppsInstallerWidget) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Aggregations

AppWidgetManager (android.appwidget.AppWidgetManager)53 ComponentName (android.content.ComponentName)33 RemoteViews (android.widget.RemoteViews)26 Intent (android.content.Intent)21 PendingIntent (android.app.PendingIntent)12 Bundle (android.os.Bundle)12 SharedPreferences (android.content.SharedPreferences)7 Context (android.content.Context)5 View (android.view.View)4 Uri (android.net.Uri)3 AppWidgetProvider (android.appwidget.AppWidgetProvider)2 PackageManager (android.content.pm.PackageManager)2 Cursor (android.database.Cursor)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Account (android.accounts.Account)1 Service (android.app.Service)1 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 ContentResolver (android.content.ContentResolver)1