Example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID

List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID

Introduction

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

Prototype

String EXTRA_APPWIDGET_ID

To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.

Click Source Link

Document

An intent extra that contains one appWidgetId.

Usage

From source file:com.codeskraps.lolo.home.PrefsActivity.java

@Override
public void onBackPressed() {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onBackPressed");
    // This will be called either automatically for you on 2.0
    // or later, or by the code above on earlier versions of the
    // platform.//  w w w  .  ja v  a  2  s  .c o m
    if (Constants.CONFIGURE_ACTION.equals(getIntent().getAction())) {
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            Intent result = new Intent();

            result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            setResult(RESULT_OK, result);
        }
    }
    sendBroadcast(new Intent(Constants.FORCE_WIDGET_UPDATE));

    super.onBackPressed();
}

From source file:org.jraf.android.hellomundo.app.appwidget.webcam.WebcamAppWidgetActionsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("intent=" + StringUtil.toString(getIntent()));
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        mWebcamId = extras.getLong(EXTRA_WEBCAM_ID, Constants.PREF_SELECTED_WEBCAM_ID_DEFAULT);
        mCurrentWebcamId = extras.getLong(EXTRA_CURRENT_WEBCAM_ID, Constants.PREF_SELECTED_WEBCAM_ID_DEFAULT);
    }/*from  w  w w . j  av  a2s . c o m*/
    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        Log.d("Received an invalid appwidget id: abort");
        finish();
        return;
    }

    new TaskFragment(new Task<MainActivity>() {
        private String mName;
        private String mLocation;
        private String mTimeZone;
        private String mPublicId;
        private WebcamType mType;

        @Override
        protected void doInBackground() throws Throwable {
            WebcamCursor cursor = new WebcamSelection().id(mCurrentWebcamId).query(getContentResolver());
            try {
                if (cursor == null || !cursor.moveToFirst()) {
                    throw new Exception("Could not find webcam with id=" + mCurrentWebcamId);
                }
                mName = cursor.getName();
                mLocation = cursor.getLocation();
                mTimeZone = cursor.getTimezone();
                mPublicId = cursor.getPublicId();
                mType = cursor.getType();
            } finally {
                if (cursor != null)
                    cursor.close();
            }
        }

        @Override
        protected void onPostExecuteOk() {
            String title = mName;
            if (mType != WebcamType.USER) {
                String location = mLocation;
                boolean specialCam = Constants.SPECIAL_CAMS.contains(mPublicId);
                if (!specialCam) {
                    location += " - " + DateTimeUtil
                            .getCurrentTimeForTimezone(WebcamAppWidgetActionsActivity.this, mTimeZone);
                }
                title += ", " + location;
            }

            ActionsDialogFragment actionsDialogFragment = ActionsDialogFragment.newInstance(title);
            actionsDialogFragment.show(getSupportFragmentManager(), FRAGMENT_DIALOG);
        }
    }).execute(getSupportFragmentManager());
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager,
        int appWidgetId) {
    // setup intent pointing to RemoteViewsService providing the views for the collection
    Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // When intents are compared, the extras are ignored, so we need to
    // embed the extras into the data so that the extras will not be
    // ignored.//from w ww. j  a v  a2  s.c  o m
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

    // determine layout (current size) and theme (user pref)
    final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId);
    final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId);
    int layoutResId;
    if (isLightTheme) {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light;
    } else {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11;
    }

    // build widget views
    RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId);
    rv.setRemoteAdapter(R.id.list_view, intent);
    // The empty view is displayed when the collection has no items. It
    // should be a sibling of the collection view.
    rv.setEmptyView(R.id.list_view, R.id.empty_view);

    // set the background color
    int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme);
    rv.setInt(R.id.container, "setBackgroundColor", bgColor);

    // determine type specific values
    final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId);
    int showsTabIndex;
    int titleResId;
    int emptyResId;
    if (widgetType == WidgetSettings.Type.UPCOMING) {
        // upcoming
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING;
        titleResId = R.string.upcoming;
        emptyResId = R.string.noupcoming;
    } else if (widgetType == WidgetSettings.Type.RECENT) {
        // recent
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT;
        titleResId = R.string.recent;
        emptyResId = R.string.norecent;
    } else {
        // favorites
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS;
        titleResId = R.string.action_shows_filter_favorites;
        emptyResId = R.string.no_nextepisode;
    }

    // change title and empty view based on type
    rv.setTextViewText(R.id.empty_view, context.getString(emptyResId));
    if (!isCompactLayout) {
        // only regular layout has text title
        rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId));
    }

    // app launch button
    final Intent appLaunchIntent = new Intent(context, ShowsActivity.class)
            .putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex);
    PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent)
            .getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent);

    // item intent template, launches episode detail view
    TaskStackBuilder builder = TaskStackBuilder.create(context);
    builder.addNextIntent(appLaunchIntent);
    builder.addNextIntent(new Intent(context, EpisodesActivity.class));
    rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));

    // settings button
    Intent settingsIntent = new Intent(context, ListWidgetConfigure.class)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    rv.setOnClickPendingIntent(R.id.widget_settings,
            PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    return rv;
}

From source file:com.tortel.deploytrack.WidgetPickerActivity.java

public void onClick(View v) {
    String id = mAdapter.getId(mCurrentPosition);
    switch (v.getId()) {
    case R.id.button_save:
        if (id != null) {
            DatabaseManager db = DatabaseManager.getInstance(this);

            //Get the data
            Deployment deployment = db.getDeployment(id);

            //Save it
            WidgetInfo info = new WidgetInfo(mWidgetId, deployment);
            info.setLightText(mUseLightText);
            db.saveWidgetInfo(info);//from  w  ww.  j  av a 2 s. c o m

            //Set it all up
            RemoteViews remoteView = WidgetProvider.updateWidgetView(this, info);

            mWidgetManager.updateAppWidget(mWidgetId, remoteView);
            mResultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId);
            setResult(RESULT_OK, mResultIntent);

            Log.d("WidgetPicker ending for widgetId " + mWidgetId + " with deployment " + id);
        }
        finish();
        break;
    case R.id.button_cancel:
        finish();
        break;
    case R.id.widget_dark_text:
        mUseLightText = false;
        break;
    case R.id.widget_light_text:
        mUseLightText = true;
        break;
    }
}

From source file:org.opensilk.fuzzyclock.FuzzyWidgetService.java

@DebugLog
@Override//from w w  w  .j a  v  a 2  s  .co  m
public int onStartCommand(Intent intent, int flags, int startId) {
    // No action means we want to reinit everything
    if (intent == null || intent.getAction() == null) {
        mHandler.sendEmptyMessage(UPDATE_SETTINGS);
        mHandler.sendMessage(mHandler.obtainMessage(UPDATE_ALL_WIDGETS, startId));
        // Update the specified widget
    } else if (intent.getAction().startsWith("scheduled_update")) {
        final int id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        if (!sWidgetSettings.containsKey((Integer) id)) {
            mHandler.sendEmptyMessage(UPDATE_SETTINGS);
        }
        if (id != AppWidgetManager.INVALID_APPWIDGET_ID) {
            mHandler.sendMessage(mHandler.obtainMessage(UPDATE_SINGLE_WIDGET, id, startId));
        }
        // A widget was deleted, remove it from our settings map
    } else if (intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_DELETED)) {
        int[] ids = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        if (ids != null) {
            for (int id : ids) {
                cancelUpdate(id);
                new FuzzyPrefs(mContext, id).remove();
                if (sWidgetSettings.containsKey((Integer) id)) {
                    sWidgetSettings.remove((Integer) id);
                }
            }
        }
        mHandler.sendMessage(mHandler.obtainMessage(UPDATE_ALL_WIDGETS, startId));
    }
    return START_STICKY;
}

From source file:org.gnucash.android.ui.widget.WidgetConfigurationActivity.java

/**
 * Sets click listeners for the buttons in the dialog
 *//*from  w  ww .j  a va 2  s  . co  m*/
private void bindListeners() {
    mOkButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = getIntent();
            Bundle extras = intent.getExtras();
            if (extras != null) {
                mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                        AppWidgetManager.INVALID_APPWIDGET_ID);
            }

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

            long accountId = mAccountsSpinner.getSelectedItemId();
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(WidgetConfigurationActivity.this);
            Editor editor = prefs.edit();
            editor.putLong(UxArgument.SELECTED_ACCOUNT_ID + mAppWidgetId, accountId);
            editor.commit();

            updateWidget(WidgetConfigurationActivity.this, mAppWidgetId, accountId);

            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
            setResult(RESULT_OK, resultValue);
            finish();
        }
    });

    mCancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:ru.yandex.subtitles.ui.appwidget.AbstractAppWidget.java

@NonNull
protected PendingIntent createStartConversationIntent(final Context context, final int appWidgetId,
        @Nullable final String phrase) {
    final Intent launchIntent = IntentUtils.createActionIntent(context, getClass(),
            getStartConversationAction());
    launchIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    launchIntent.putExtra(Intent.EXTRA_TEXT, phrase);
    return PendingIntent.getBroadcast(context, appWidgetId, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:at.wada811.dayscounter.view.activity.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // catch UncaughtException
    Thread.setDefaultUncaughtExceptionHandler(new CrashExceptionHandler(getApplicationContext()));
    super.onCreate(savedInstanceState);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    setContentView(R.layout.activity_settings);
    ButterKnife.inject(this);
    // Window size dialog
    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.width = WindowManager.LayoutParams.MATCH_PARENT;
    params.height = WindowManager.LayoutParams.MATCH_PARENT;
    getWindow().setAttributes(params);/*from w  w  w. ja va  2 s. c o  m*/
    LogUtils.d();
    // check Crash report
    File file = ResourceUtils.getFile(this, CrashExceptionHandler.FILE_NAME);
    if (file.exists()) {
        startActivity(new Intent(this, CrashReportActivity.class));
        finish();
        return;
    }
    // AppWidgetId
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }
    LogUtils.d("appWidgetId: " + appWidgetId);

    WidgetModel model = new WidgetModel(this, appWidgetId);
    viewModel = new Widget1x1ViewModel(this, model);
    // Title
    new EditTextBinding(titleEditText).bind(new Func<EditText, String>() {
        @Override
        public String apply(EditText editText) {
            return editText.getText().toString();
        }
    }, viewModel.getTitle(), new EditTextTextChanged() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            titleTextView.setText(viewModel.getTitle().getValue());
        }
    });
    titleEditText.setText(viewModel.getTitle().getValue());
    // Date
    String date = viewModel.getDate().getValue();
    LogUtils.d("date: " + date);
    LocalDateTime dateTime = date != null ? new LocalDateTime(date) : LocalDateTime.now();
    DatePickerBinding datePickerBinding = new DatePickerBinding(datePicker);
    datePickerBinding.bind(new Func<DatePicker, String>() {
        @Override
        public String apply(DatePicker datePicker) {
            return DatePickerUtils.format(datePicker);
        }
    }, viewModel.getDate(), new OnDateChangedListener() {
        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            diffTextView.setText(viewModel.getDiff().getValue());
            diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewModel.getDiffTextSize().getValue());
            daysTextView.setText(viewModel.getComparison().getValue());
        }
    });
    datePicker.init(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth(),
            datePickerBinding.getOnDateChangedListener());
    diffTextView.setText(viewModel.getDiff().getValue());
    diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewModel.getDiffTextSize().getValue());
    daysTextView.setText(viewModel.getComparison().getValue());

    // Button
    submitButton.setOnClickListener(this);
}

From source file:de.micmun.android.workdaystarget.DaysLeftService.java

/**
 * Updates the days to target./*from   w  ww  . ja va 2 s  .c o  m*/
 */
private void updateDays() {
    AppWidgetManager appManager = AppWidgetManager.getInstance(this);
    ComponentName cName = new ComponentName(getApplicationContext(), DaysLeftProvider.class);
    int[] appIds = appManager.getAppWidgetIds(cName);

    DayCalculator dayCalc = new DayCalculator();
    if (!isOnline()) {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            Log.e(TAG, "Interrupted: " + e.getLocalizedMessage());
        }
    }

    for (int appId : appIds) {
        PrefManager pm = new PrefManager(this, appId);
        Calendar target = pm.getTarget();
        boolean[] chkDays = pm.getCheckedDays();
        int days = pm.getLastDiff();

        if (isOnline()) {
            try {
                days = dayCalc.getDaysLeft(target.getTime(), chkDays);
                Map<String, Object> saveMap = new HashMap<String, Object>();
                Long diff = Long.valueOf(days);
                saveMap.put(PrefManager.KEY_DIFF, diff);
                pm.save(saveMap);
            } catch (JSONException e) {
                Log.e(TAG, "ERROR holidays: " + e.getLocalizedMessage());
            }
        } else {
            Log.e(TAG, "No internet connection!");
        }
        RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.appwidget_layout);
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
        String targetStr = df.format(target.getTime());
        rv.setTextViewText(R.id.target, targetStr);
        String dayStr = String.format(Locale.getDefault(), "%d %s", days,
                getResources().getString(R.string.unit));
        rv.setTextViewText(R.id.dayCount, dayStr);

        // put widget id into intent
        Intent configIntent = new Intent(this, ConfigActivity.class);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId);
        configIntent.setData(Uri.parse(configIntent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent pendIntent = PendingIntent.getActivity(this, 0, configIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setOnClickPendingIntent(R.id.widgetLayout, pendIntent);

        // update widget
        appManager.updateAppWidget(appId, rv);
    }
}

From source file:com.android.gallery3d.gadget.WidgetConfigure.java

private void updateWidgetAndFinish(WidgetDatabaseHelper.Entry entry) {
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    RemoteViews views = PhotoAppWidgetProvider.buildWidget(this, mAppWidgetId, entry);
    manager.updateAppWidget(mAppWidgetId, views);
    setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
    finish();/*from   w w w  .j av  a 2  s .c  o m*/
}