下面列出了android.appwidget.AppWidgetManager#INVALID_APPWIDGET_ID 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void handleArguments() {
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;
}
SharedPreferences sharedPreferences = getApplication().getSharedPreferences(
Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS);
long categoryCode = sharedPreferences.getLong(
Constants.PREF_WIDGET_CATEGORY_CODE_PREFIX + String.valueOf(mAppWidgetId),
0);
if (categoryCode != 0) {
fetchCategory(categoryCode);
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 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);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
mUpdateWidget = extras.getBoolean(
DynamicIntent.EXTRA_WIDGET_UPDATE, false);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finishActivity();
}
}
/**
* Receives and processes a button pressed intent or state change.
*
* @param context
* @param intent Indicates the pressed button.
*/
@Override
public void onReceive(final Context context, Intent intent) {
String act = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(act)) {
final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId });
}
} else if (SipManager.ACTION_SIP_REGISTRATION_CHANGED.equals(act) || SipManager.ACTION_SIP_ACCOUNT_CHANGED.equals(act)) {
//Thread t = new Thread() {
// public void run() {
updateWidget(context);
// };
//};
//t.start();
}
super.onReceive(context, intent);
}
public static int themePrefToStyleId( Context context, String themeName, SuntimesRiseSetData data )
{
int styleID = R.style.AppTheme_Dark;
if (themeName != null)
{
//noinspection IfCanBeSwitch
if (themeName.equals(THEME_LIGHT))
{
styleID = R.style.AppTheme_Light;
} else if (themeName.equals(THEME_DARK)) {
styleID = R.style.AppTheme_Dark;
} else if (themeName.equals(THEME_DAYNIGHT)) {
if (data == null)
{
data = new SuntimesRiseSetData(context, AppWidgetManager.INVALID_APPWIDGET_ID);
data.initCalculator(context);
}
styleID = (data.isDay() ? R.style.AppTheme_Light : R.style.AppTheme_Dark);
}
}
return styleID;
}
@Override
protected void onMyCreate(Bundle savedInstanceState) {
// 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);
setContentView(R.layout.activity_shot_app_widget_config);
ButterKnife.inject(this);
String[] entries = getResources().getStringArray(R.array.refresh_entries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, entries);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(this);
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();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
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());
}
private void handleIntent(Intent intent) {
String action = intent.getAction();
LogUtils.d("action:" + action);
if (TextUtils.isEmpty(action)) {
finish();
return;
}
long categoryCode = 0;
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
Bundle extras = intent.getExtras();
if (extras != null && extras.containsKey(Constants.INTENT_WIDGET)) {
mAppWidgetId = extras.getInt(Constants.INTENT_WIDGET, AppWidgetManager.INVALID_APPWIDGET_ID);
}
if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
SharedPreferences sharedPreferences = getApplication().getSharedPreferences(
Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS);
categoryCode = sharedPreferences.getLong(
Constants.PREF_WIDGET_CATEGORY_CODE_PREFIX + String.valueOf(mAppWidgetId),
0);
}
if (categoryCode == 0) {
/* Should show category picker dialog at first */
ToastUtils.makeToast(R.string.widget_pick_category_at_first);
showCategoryPicker();
} else {
/* Fetch category from database */
fetchCategory(categoryCode);
}
}
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);
}
/**
* Receives and processes a button pressed intent or state change.
*
* @param context
* @param intent Indicates the pressed button.
*/
@Override
public void onReceive(final Context context, Intent intent) {
String act = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(act)) {
final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId });
}
}
super.onReceive(context, intent);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// 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);
// Set the view layout resource to use.
setContentView(R.layout.appwidget_configure);
// Find the EditText
mAppWidgetPrefix = (EditText)findViewById(R.id.appwidget_prefix);
// Bind the action for the save button.
findViewById(R.id.save_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
mAppWidgetPrefix.setText(loadTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId));
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.mimi_widget_configure);
mAppWidgetText = (EditText) findViewById(R.id.appwidget_text);
findViewById(R.id.add_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
mAppWidgetText.setText(loadTitlePref(MimiWidgetConfigureActivity.this, mAppWidgetId));
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.sticky_note_widget_configure);
findViewById(R.id.add_button).setOnClickListener(mOnClickListener);
noteRepository = new NoteRepository(this);
accountSpinner = (Spinner) findViewById(R.id.spinner_account);
noteSpinner = (Spinner) findViewById(R.id.spinner_note);
localAccountName = getResources().getString(R.string.drawer_account_local);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
mAccountManager = AccountManager.get(this);
initSpinners();
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mContext = this;
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.clock_widget_configure);
//mAppWidgetText = (EditText) findViewById(R.id.appwidget_text);
findViewById(R.id.add_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
//Setup Spinner for Timezone IDs
String[] timezoneIDs = TimeZone.getAvailableIDs();
mTimeZoneSpinner = (Spinner) findViewById(R.id.spinnerTimeZoneIDs);
ArrayAdapter<String> mTZAdpter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, timezoneIDs);
mTZAdpter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mTimeZoneSpinner.setAdapter(mTZAdpter);
mTimeZoneSpinner.setOnItemSelectedListener(this);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// init logging
LoggingHelper.initLogging(OverclockingWidgetConfigureActivity.this);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
this.getSupportActionBar().setTitle(getString(R.string.widget_configure_title));
deviceDbHelper = new DeviceDbHelper(this);
final int deviceCount = initSpinners();
if (deviceCount == 0) {
// show Toast to add a device first
Toast.makeText(this, getString(R.string.widget_add_no_device), Toast.LENGTH_LONG).show();
finish();
return;
}
linLayoutCustomInterval.setVisibility(View.GONE);
}
@Override
public void onCreate(Bundle icicle)
{
setTheme(AppSettings.loadTheme(this));
GetFixUI.themeIcons(this);
super.onCreate(icicle);
initLocale(this);
setResult(RESULT_CANCELED);
setContentView(R.layout.layout_settings);
Context context = SuntimesConfigActivity0.this;
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null)
{
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
reconfigure = extras.getBoolean(EXTRA_RECONFIGURE, false);
}
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
{
Log.w("onCreate", "Invalid widget ID! returning early.");
finish();
overridePendingTransition(R.anim.transition_cancel_in, R.anim.transition_cancel_out);
return;
}
Intent cancelIntent = new Intent();
cancelIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_CANCELED, cancelIntent);
WidgetThemes.initThemes(context);
initViews(context);
loadSettings(context);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.e("TwitterFollower", "onCreate of ConfigActivity called");
super.onCreate(savedInstanceState);
// 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);
setContentView(R.layout.configuration);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
Log.e("TwitterFollower", "WidgetId " + mAppWidgetId);
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
Button button = (Button) findViewById(R.id.finish);
user = (TextView) findViewById(R.id.twitteruser);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Context context = TwitterFollowerConfigActivity.this;
String userName = user.getText().toString();
userName = userName.replaceAll("@", "");
saveTitlePref(context, mAppWidgetId, userName);
Log.e("TwitterFollower", "Config Saved Preference");
// Push widget update to surface with newly set prefix
AppWidgetManager appWidgetManager = AppWidgetManager
.getInstance(context);
Log.e(TAG, "Update Widget from config");
// Trigger the update
TwitterFollowerReceiver.updateAppWidget(
TwitterFollowerConfigActivity.this, appWidgetManager,
mAppWidgetId);
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
});
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
Log.i("TGL", "second widget... load");
setContentView(R.layout.weather_widget_configure);
findViewById(R.id.add_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
mAppWidgetText = (AutoCompleteTextView) findViewById(R.id.appwidget_text);
database = PFASQLiteHelper.getInstance(this);
generator = new AutoCompleteCityTextViewGenerator(getApplicationContext(), database);
generator.generate(mAppWidgetText, 100, EditorInfo.IME_ACTION_DONE, new MyConsumer<City>() {
@Override
public void accept(City city) {
selectedCity = city;
}
}, new Runnable() {
@Override
public void run() {
handleOk();
}
});
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.weather_widget_configure);
findViewById(R.id.add_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
Log.i("TGL", "onCreate");
mAppWidgetText = (AutoCompleteTextView) findViewById(R.id.appwidget_text);
database = PFASQLiteHelper.getInstance(this);
generator = new AutoCompleteCityTextViewGenerator(getApplicationContext(), database);
generator.generate(mAppWidgetText, 100, EditorInfo.IME_ACTION_DONE, new MyConsumer<City>() {
@Override
public void accept(City city) {
selectedCity = city;
}
}, new Runnable() {
@Override
public void run() {
handleOk();
}
});
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.widget_today_configure);
setUpActionBar();
mWidgetPreviewLayout = (RelativeLayout) findViewById(R.id.today_widget);
prevBtn = findViewById(R.id.widget_prev_day_btn);
mWidgetTodaysNameTv = (TextView) findViewById(R.id.widget_todays_name);
nextBtn = findViewById(R.id.widget_next_day_btn);
syncBtn = (ImageButton) findViewById(R.id.widget_sync_btn);
mBgColorSpinner = (Spinner) findViewById(R.id.bg_color_spinner);
setUpColorSpinner(mBgColorSpinner, mBgColorSpinnerListener);
mBgColorSpinner.setSelection(getSpinnerAdapterPosition(loadBgColorDefaultPref()));
mTextColorSpinner = (Spinner) findViewById(R.id.bg_text_color_spinner);
setUpColorSpinner(mTextColorSpinner, mTextColorSpinnerListener);
mTextColorSpinner.setSelection(getSpinnerAdapterPosition(loadTextColorDefaultPref()));
setUpOpacitySeekBar();
findViewById(R.id.ok_btn).setOnClickListener(mOkBtnOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
}
@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);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
setContentView(R.layout.activity_pswidget_on_create);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}