List of usage examples for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID
int INVALID_APPWIDGET_ID
To view the source code for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID.
Click Source Link
From source file:ch.fixme.status.Widget.java
public void onReceive(Context ctxt, Intent intent) { String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { // Remove widget alarm int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); PendingIntent pi = PendingIntent.getService(ctxt, widgetId, getIntent(ctxt, widgetId), 0); AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);/*from w w w. j a va2 s .c o m*/ // remove preference SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); Editor edit = prefs.edit(); edit.remove(Main.PREF_API_URL_WIDGET + widgetId); edit.remove(Main.PREF_INIT_WIDGET + widgetId); edit.remove(Main.PREF_LAST_WIDGET + widgetId); edit.remove(Main.PREF_FORCE_WIDGET + widgetId); edit.commit(); // Log.i(Main.TAG, "Remove widget alarm for id=" + widgetId); } else if (intent.hasExtra(WIDGET_IDS) && AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { int[] ids = intent.getExtras().getIntArray(WIDGET_IDS); onUpdate(ctxt, AppWidgetManager.getInstance(ctxt), ids); } else super.onReceive(ctxt, intent); }
From source file:io.github.hidroh.materialistic.appwidget.WidgetConfigActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);//from ww w . j av a 2s . c o m if (getIntent().getExtras() == null || (mAppWidgetId = getIntent().getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)) == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } supportRequestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_widget_config); if (savedInstanceState == null) { Bundle args = new Bundle(); args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); getSupportFragmentManager().beginTransaction() .replace(R.id.widget_preferences, Fragment.instantiate(this, WidgetConfigurationFragment.class.getName(), args), WidgetConfigurationFragment.class.getName()) .commit(); } //noinspection ConstantConditions findViewById(R.id.button_ok).setOnClickListener(v -> configure()); }
From source file:com.dpcsoftware.mn.Widget1Config.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/*from ww w . j a va2s .com*/ wPrefs = getSharedPreferences(App.WIDGET_PREFS_FNAME, MODE_PRIVATE); Intent intent = getIntent(); Bundle extras = intent.getExtras(); wId = AppWidgetManager.INVALID_APPWIDGET_ID; if (extras != null) wId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); else finish(); setContentView(R.layout.widget1_config); resultIntent = new Intent(); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, wId); ActionBar abar = getSupportActionBar(); abar.setTitle("Configuraes do Widget"); SQLiteDatabase db = DatabaseHelper.quickDb(this, DatabaseHelper.MODE_READ); Cursor c = db.rawQuery("SELECT " + Db.Table3._ID + "," + Db.Table3.COLUMN_NGRUPO + " FROM " + Db.Table3.TABLE_NAME + " ORDER BY " + Db.Table3.COLUMN_NGRUPO + " ASC", null); SimpleCursorAdapter sAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, new String[] { Db.Table3.COLUMN_NGRUPO }, new int[] { android.R.id.text1 }, 0); sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp = ((Spinner) findViewById(R.id.spinner1)); sp.setAdapter(sAdapter); }
From source file:ch.fixme.status.Widget_config.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.widget_config); mPrefs = PreferenceManager.getDefaultSharedPreferences(Widget_config.this); getDirTask = new GetDirTask(); getDirTask.execute(ParseGeneric.API_DIRECTORY); Intent intent = getIntent();/*from w w w . j a v a2 s . c om*/ Bundle extras = intent.getExtras(); mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); findViewById(R.id.choose_ok).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Editor edit = mPrefs.edit(); edit.putBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, ((CheckBox) findViewById(R.id.choose_transparency)).isChecked()); edit.commit(); setWidgetAlarm(); finish(); } }); ((CheckBox) findViewById(R.id.choose_transparency)) .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)); ((CheckBox) findViewById(R.id.choose_text)) .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TEXT, Prefs.DEFAULT_WIDGET_TEXT)); ((EditText) findViewById(R.id.choose_update)).addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String inter = s.toString(); if (!"".equals(inter) && !"0".equals(inter)) { Editor edit = mPrefs.edit(); edit.putString(Prefs.KEY_CHECK_INTERVAL, inter); edit.commit(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.tortel.deploytrack.WidgetPickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check for light theme Prefs.load(this); if (Prefs.useLightTheme()) { setTheme(R.style.Theme_DeployThemeLight); }//from w ww. j a v a 2 s . c om setContentView(R.layout.activity_widget_config); Bundle extras = getIntent().getExtras(); if (extras != null) { mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } mResultIntent = new Intent(); //Set it to cancelled until explicitly told to save setResult(RESULT_CANCELED, mResultIntent); mWidgetManager = AppWidgetManager.getInstance(this); mAdapter = new DeploymentFragmentAdapter(this, getSupportFragmentManager()); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(mAdapter); SmartTabLayout indicator = (SmartTabLayout) findViewById(R.id.indicator); indicator.setViewPager(pager); indicator.setOnPageChangeListener(new PageChangeListener()); pager.setCurrentItem(mCurrentPosition); Log.d("WidgetPicker started with mWidgetId " + mWidgetId); }
From source file:net.niyonkuru.koodroid.appwidget.WidgetConfigureActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); final Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { setResult(RESULT_CANCELED, resultValue); finish();/* w ww . j av a2s . c om*/ } // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(this, android.R.layout.select_dialog_singlechoice, null, new String[] { Subscribers.SUBSCRIBER_ID }, new int[] { android.R.id.text1 }, 0); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.choose_subscriber_title); builder.setSingleChoiceItems(mAdapter, 0, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int position) { final Cursor cursor = mAdapter.getCursor(); cursor.moveToPosition(position); ContentValues values = new ContentValues(1); values.put(Settings.SUBSCRIBER, cursor.getString(SubscribersQuery.SUBSCRIBER_ID)); ContentResolver cr = getContentResolver(); cr.insert(Settings.buildAppWidgetUri(mAppWidgetId), values); mResultCode = RESULT_OK; setResult(mResultCode, resultValue); dialog.dismiss(); finish(); } }); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { setResult(RESULT_CANCELED, resultValue); dialog.dismiss(); finish(); } }); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); dialog.cancel(); } }); mAlertDialog = builder.create(); getSupportLoaderManager().initLoader(0, null, this); }
From source file:org.flexlabs.widgets.dualbattery.widgetsettings.WidgetActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startService(new Intent(this, MonitorService.class)); Bundle extras = getIntent().getExtras(); appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); fragments = new Fragment[5]; fragments[0] = new BatteryInfoFragment(); fragments[1] = new PropertiesFragment(); fragments[2] = new FeedbackFragment(); fragments[3] = new DonateFragment(); fragments[4] = new AboutFragment(); titles = new String[5]; titles[0] = getString(R.string.propHeader_BatteryInfo); titles[1] = getString(R.string.propHeader_Properties); titles[2] = getString(R.string.propHeader_Feedback); titles[3] = getString(R.string.propHeader_Donate); titles[4] = getString(R.string.propHeader_About); int screenLayout = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && screenLayout > Configuration.SCREENLAYOUT_SIZE_LARGE) { setContentView(R.layout.preference_list_large); ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, titles);/* w w w . jav a 2 s . c o m*/ mList = (ListView) findViewById(android.R.id.list); mList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mList.setOnItemClickListener(this); mList.setAdapter(adapter); mList.setItemChecked(0, true); mList.performClick(); getSupportFragmentManager().beginTransaction().replace(R.id.prefs, fragments[0]).commit(); } else { setContentView(R.layout.widgetsettings); PagerTabAdapter mPagerAdapter = new PagerTabAdapter(getSupportFragmentManager()); ViewPager mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mPagerAdapter); PageIndicator mIndicator = (TabPageIndicator) findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } if (WidgetSettingsContainer.getUpgradeSwappedSingle(this, appWidgetId)) { new AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.alert_just_swapped) .setPositiveButton("OK", null).show(); } }
From source file:net.olejon.spotcommander.WidgetActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Settings// ww w . j a v a2 s . c om PreferenceManager.setDefaultValues(mContext, R.xml.settings, false); // Allow landscape? if (!mTools.allowLandscape()) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Database mDatabase = new MainSQLiteHelper(mContext).getReadableDatabase(); // Intent setResult(RESULT_CANCELED); final Intent intent = getIntent(); if (intent.getExtras() != null) mAppWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) finish(); // Layout setContentView(R.layout.activity_widget); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.widget_toolbar); toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp); toolbar.setTitle(getString(R.string.widget_title)); setSupportActionBar(toolbar); // Listview mListView = (ListView) findViewById(R.id.widget_list); final View listViewHeader = getLayoutInflater().inflate(R.layout.activity_main_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); final View listViewEmpty = findViewById(R.id.widget_empty); mListView.setEmptyView(listViewEmpty); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mTools.setSharedPreferencesLong("WIDGET_" + mAppWidgetId + "_COMPUTER_ID", id); Intent result = new Intent(); result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, result); finish(); } }); listComputers(); }
From source file:com.lemontruck.thermo.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Find the widget id from the intent. Intent intent = getIntent();/*from www .ja va2s. c o m*/ Bundle extras = intent.getExtras(); if (extras != null) { appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget id, just bail. if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { Log.w(LOG, "Invalid App Id"); finish(); } intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager(), getApplicationContext().getResources()); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. actionBar.setHomeButtonEnabled(false); //actionBar.setDisplayShowTitleEnabled(false); // Set the result to CANCELED. This will cause the widget host to cancel // out of the widget placement if they press the back button. setResult(RESULT_CANCELED); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:com.gelakinetic.inboxwidget.InboxCheckerAppWidgetConfigure.java
/** * This is called when the widget needs configuring. It will check permissions, get accounts, * prompt the user to select an account, and save the widget *//*ww w. j a v a2 s.com*/ @Override public void onResume() { super.onResume(); /* Get the app widget ID we're configuring */ Bundle extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (extras == null || mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { /* Not configuring the widget, just close */ this.finish(); return; } /* Check for required permissions */ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, GmailContract.PERMISSION) != PackageManager.PERMISSION_GRANTED) { /* If the permissions aren't granted, ask for them */ ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.GET_ACCOUNTS, GmailContract.PERMISSION }, REQUEST_CODE); return; } /* All permissions granted, go get the list of accounts */ getAccounts(); }