Example usage for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID

List of usage examples for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID

Introduction

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

Prototype

int INVALID_APPWIDGET_ID

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

Click Source Link

Document

A sentinel value that the AppWidget manager will never return as a appWidgetId.

Usage

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

@DebugLog
@Override/*  ww  w  .  ja va2 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:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    //   Log.e(this.getClass().getSimpleName(), "onReceive(): " + action);

    updateMobileDataViews = true;//from  www.  ja va  2s  . c  om

    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    dataState = telephonyManager.getDataState();
    isMobileDataEnabled = MobileDataUtils.isMobileDataEnabled(context);
    isAirplaneModeOn = MobileDataUtils.isAirplaneModeOn(context);
    isMobileOutOfService = NetworkStateService.isMobileOutOfService();
    isDataRoaming = isDataRoaming(context);
    networkOperatorAndServiceProvider = getNetworkOperatorAndServiceProvider(context);
    dataUsageBytes = NetworkStateService
            .setGetDataUsageBytes(TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes());

    if (Constants.ACTION_DATA_CONNECTION_CHANGED.equals(action)
            || Constants.ACTION_DATA_STATE_CHANGED.equals(action)
            || Constants.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
        // Needed to get around a known bug in Android 5.x: https://code.google.com/p/android/issues/detail?id=78924
        if ((dataState == TelephonyManager.DATA_CONNECTED) && (dataUsageBytes == 0)
                && !NetworkStateService.isWaitingForDataUsage()) {
            NetworkStateService.setWaitingForDataUsage(true);
            Intent serviceIntent = new Intent(context, NetworkStateService.class);
            serviceIntent.setAction(Constants.ACTION_DATA_CONNECTED);
            context.startService(serviceIntent);
        }

        partiallyUpdateWidgets(context);
    } else if (Constants.ACTION_DATA_USAGE_UPDATE.equals(action) || Intent.ACTION_SCREEN_ON.equals(action)) {
        partiallyUpdateWidgets(context);
    } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) {
        partiallyUpdateWidget(context, AppWidgetManager.getInstance(context),
                intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
    }
}

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

/**
 * Sets click listeners for the buttons in the dialog
 *//* www . j  a v  a  2 s.com*/
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: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 . j av  a 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:cn.code.notes.gtask.data.SqlNote.java

public SqlNote(Context context) {
    mContext = context;//from  w  w w.  j a  v  a 2s.  c  o m
    mContentResolver = context.getContentResolver();
    mIsCreate = true;
    mId = INVALID_ID;
    mAlertDate = 0;
    mBgColorId = ResourceParser.getDefaultBgId(context);
    mCreatedDate = System.currentTimeMillis();
    mHasAttachment = 0;
    mModifiedDate = System.currentTimeMillis();
    mParentId = 0;
    mSnippet = "";
    mType = Notes.TYPE_NOTE;
    mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
    mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
    mOriginParent = 0;
    mVersion = 0;
    mDiffNoteValues = new ContentValues();
    mDataList = new ArrayList<SqlData>();
}

From source file:com.github.ajasmin.telususageandroidwidget.ReportAccountErrorActivity.java

private void retriveAppWidgetId() {
    Intent intent = getIntent();//from  w  ww  .j av  a 2s .  c  o  m
    Bundle extras = intent.getExtras();
    appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // Finish the activity if we don't receive an appWidgetId
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
        finish();
}

From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes3.java

/**
 * Switch to the next note (in ordered set of notes).
 * @return true if the note was changed, false otherwise
 *//*  ww  w. ja v  a2 s. com*/
@Override
public boolean showNextNote() {
    if (dataset.isCalculated()) {
        SolarEvents currentNoteMode = WidgetSettings.loadTimeNoteRisePref(context, 0);
        int currentNote = currentNoteMode.ordinal();

        int nextNote = 0;
        if (currentNote < SolarEvents.values().length - 1)
            nextNote = currentNote + 1;

        SolarEvents nextNoteMode = SolarEvents.values()[nextNote];
        WidgetSettings.saveTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID, nextNoteMode);

        //Log.d("showNextNote", "... current = " + currentNote + ", next = " + nextNote + ", mode = " + nextNoteMode.name());
        updateNote(context, dataset.now(), NoteChangedListener.TRANSITION_NEXT);
        return true;

    } else {
        Log.w("showNextNote", "called before data was calculated!");
        return false;
    }
}

From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes2.java

/**
 * Switch to the next note (in ordered set of notes).
 * @return true if the note was changed, false otherwise
 *//*from www  . jav a2 s  .c  o  m*/
@Override
public boolean showNextNote() {
    if (dataset.isCalculated()) {
        //String tag;
        int nextNote, currentNote;
        SolarEvents nextNoteMode;

        Calendar now = dataset.now();

        if (dataset.isNight(now)) {
            // show next "rising" note
            SolarEvents currentNoteMode = WidgetSettings.loadTimeNoteRisePref(context, 0);
            currentNote = currentNoteMode.ordinal();
            nextNote = 0;
            if (hasNextRiseNote(currentNote))
                nextNote = currentNote + 1;

            //tag = "showNextRiseNote";
            nextNoteMode = SolarEvents.values()[nextNote];
            WidgetSettings.saveTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID, nextNoteMode);

        } else {
            // show next "setting" note
            SolarEvents currentNoteMode = WidgetSettings.loadTimeNoteSetPref(context, 0);
            currentNote = currentNoteMode.ordinal();
            nextNote = 4;
            if (hasNextSetNote(currentNote))
                nextNote = currentNote + 1;

            //tag = "showNextSetNote";
            nextNoteMode = SolarEvents.values()[nextNote];
            WidgetSettings.saveTimeNoteSetPref(context, 0, nextNoteMode);
        }

        //Log.d(tag, "... current = " + currentNote + ", next = " + nextNote + ", mode = " + nextNoteMode.name());
        updateNote(context, now, NoteChangedListener.TRANSITION_NEXT);
        return true;

    } else {
        Log.w("showNextNote", "called before data was calculated!");
        return false;
    }
}

From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes3.java

/**
 * Switch to the previous note (in ordered set of notes).
 * @return true if the note was changed, false otherwise
 *///  w  w  w.j  a  v a2  s . c o  m
@Override
public boolean showPrevNote() {
    if (dataset.isCalculated()) {
        SolarEvents currentNoteMode = WidgetSettings.loadTimeNoteRisePref(context,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        int currentNote = currentNoteMode.ordinal();

        int prevNote = SolarEvents.values().length - 1;
        if (currentNote > 0) {
            prevNote = currentNote - 1;
        }

        SolarEvents prevNoteMode = SolarEvents.values()[prevNote];
        WidgetSettings.saveTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID, prevNoteMode);
        updateNote(context, dataset.now(), NoteChangedListener.TRANSITION_PREV);
        return true;

    } else {
        Log.w("showPreviousNote", "called before data was calculated!");
        return false;
    }
}

From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes1.java

/**
 * Switch to the previous note (in ordered set of notes).
 * @return true if the note was changed, false otherwise
 *//*from   ww w.j  av  a  2s  .c  o m*/
@Override
public boolean showPrevNote() {
    if (dataset.isCalculated()) {
        Calendar now = dataset.now();

        if (dataset.isNight(now)) {
            // show previous "rising" note
            SolarEvents currentNoteMode = WidgetSettings.loadTimeNoteRisePref(context,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            int currentNote = currentNoteMode.ordinal();

            int prevNote = 4;
            if (hasPreviousRiseNote(currentNote)) {
                prevNote = currentNote - 1;
            }

            SolarEvents prevNoteMode = SolarEvents.values()[prevNote];
            WidgetSettings.saveTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID, prevNoteMode);

        } else {
            // show previous "setting" note
            SolarEvents currentNoteMode = WidgetSettings.loadTimeNoteSetPref(context,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            int currentNote = currentNoteMode.ordinal();

            int prevNote = 8;
            if (hasPreviousSetNote(currentNote)) {
                prevNote = currentNote - 1;
                if (prevNote < 4)
                    prevNote = 4;
            }

            SolarEvents prevNoteMode = SolarEvents.values()[prevNote];
            WidgetSettings.saveTimeNoteSetPref(context, AppWidgetManager.INVALID_APPWIDGET_ID, prevNoteMode);
        }

        updateNote(context, now, NoteChangedListener.TRANSITION_PREV);
        return true;

    } else {
        Log.w("showPreviousNote", "called before data was calculated!");
        return false;
    }
}