本文整理汇总了Java中android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID属性的典型用法代码示例。如果您正苦于以下问题:Java AppWidgetManager.INVALID_APPWIDGET_ID属性的具体用法?Java AppWidgetManager.INVALID_APPWIDGET_ID怎么用?Java AppWidgetManager.INVALID_APPWIDGET_ID使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.appwidget.AppWidgetManager
的用法示例。
在下文中一共展示了AppWidgetManager.INVALID_APPWIDGET_ID属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// 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();
return;
}
setTitle(R.string.unread_widget_select_account);
}
示例2: updateWidget
static boolean updateWidget(Context context, int widgetId, String path) {
if (TextUtils.isEmpty(path) || widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
return false;
}
String name = PFile.getNameWithoutExtension(path);
int requestCode = ScriptWidgets.getRequestCodeForAppWidgetId(widgetId);
Log.d(LOG_TAG, "updateWidget: id = " + widgetId + ", requestCode = " + requestCode + ", path = " + path);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_script_shortcut);
views.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, requestCode,
new Intent(context, RunIntentActivity.class)
.putExtra(CommonUtils.EXTRA_KEY_PATH, path)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT));
views.setTextViewText(R.id.name, name);
appWidgetManager.updateAppWidget(widgetId, views);
ScriptWidgets.setPathForAppWidgetId(widgetId, path);
return true;
}
示例3: onListItemClick
@Override
@SuppressWarnings("unchecked")
protected void onListItemClick(ListView l, View v, int position, long id) {
Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position);
Integer index = (Integer) map.get(KEY_INDEX);
if(appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
SharedPreferences prefs = getSharedPreferences(WIDGET_PREFS, 0);
SharedPreferences.Editor edit = prefs.edit();
edit.putInt(getPrefsKey(appWidgetId), index);
edit.commit();
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
setResult(RESULT_OK, resultValue);
ShortcutWidgetProvider.updateWidget(this);
finish();
}else {
Log.w(THIS_FILE, "Invalid widget ID here...");
}
}
示例4: onReceive
/**
* 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);
}
示例5: onReceive
/**
* 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);
}
示例6: onAccountClicked
@Override
public void onAccountClicked(long accountId, String d, String w) {
if(appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
SharedPreferences prefs = getSharedPreferences(WIDGET_PREFS, 0);
SharedPreferences.Editor edit = prefs.edit();
edit.putLong(getPrefsKey(appWidgetId), accountId);
edit.commit();
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
setResult(RESULT_OK, resultValue);
AccountWidgetProvider.updateWidget(this);
finish();
}else {
Log.w(THIS_FILE, "Invalid widget ID here...");
}
}
示例7: updateWidget
static boolean updateWidget(Context context, int widgetId, String path) {
if (TextUtils.isEmpty(path) || widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
return false;
}
String name = PFiles.getNameWithoutExtension(path);
int requestCode = ScriptWidgets.getRequestCodeForAppWidgetId(widgetId);
Log.d(LOG_TAG, "updateWidget: id = " + widgetId + ", requestCode = " + requestCode + ", path = " + path);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_script_shortcut);
views.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, requestCode,
new Intent(context, RunIntentActivity.class)
.putExtra(ScriptIntents.EXTRA_KEY_PATH, path)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT));
views.setTextViewText(R.id.name, name);
appWidgetManager.updateAppWidget(widgetId, views);
ScriptWidgets.setPathForAppWidgetId(widgetId, path);
return true;
}
示例8: onStartCommand
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand()");
if(intent != null) {
//Try to get extras
String screenState = intent.getStringExtra(ScreenReceiver.SCREEN_STATE);
int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
//Check if intent is coming from ScreenReceiver
if(screenState != null)
handleScreenState(screenState);
//Check if intent came from a Widget click
else if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID)
handleWidgetClick(widgetId);
else
Log.d(TAG, "Error: Got an unknown onStartCommand() in PingWidgetUpdateService");
}
// If service get killed, after returning from here, restart
return START_STICKY;
}
示例9: getAppWidgetIdFromIntent
private int getAppWidgetIdFromIntent() {
Intent arrivedIntent = getIntent();
if (arrivedIntent.getExtras() != null) {
return arrivedIntent.getExtras().getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
return AppWidgetManager.INVALID_APPWIDGET_ID;
}
示例10: processExtras
private void processExtras(Bundle extras) {
if (extras != null) {
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
}
示例11: onCreate
@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.git_hub_journey_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(GitHubJourneyWidgetConfigureActivity.this, mAppWidgetId));
}
示例12: onCreate
@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);
// Find the widget id from the intent.
mBinding = DataBindingUtil.setContentView(this, R.layout.recipe_ingredients_widget_configure);
recipeSpinnerAdapter = new RecipeSpinnerAdapter(this, this);
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mBinding.rvRecipeChoices.setLayoutManager(layoutManager);
mBinding.rvRecipeChoices.setAdapter(recipeSpinnerAdapter);
recipeDatabaseHelper = new RecipeDatabaseHelper(this);
recipeDatabaseHelper.getAllRecipes(this);
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;
}
}
示例13: notifyResult
private void notifyResult(int resultCode) {
if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
// Normal case : set the result and provide back the widget id
Intent intent = new Intent();
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(resultCode, intent);
}
else {
// Error, unknown widget id => just set the result code
setResult(resultCode);
}
}
示例14: onCreate
@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.hi_app_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(HiAppWidgetConfigureActivity.this, mAppWidgetId));
}
示例15: delete
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
createDbIfNotExists();
SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
if (Binder.getCallingPid() != Process.myPid()
&& Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
String widgetSelection = TextUtils.isEmpty(args.where) ? "1=1" : args.where;
widgetSelection = String.format(Locale.ENGLISH, "%1$s = %2$d AND ( %3$s )",
Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET, widgetSelection);
try (Cursor c = db.query(Favorites.TABLE_NAME, new String[] { Favorites.APPWIDGET_ID },
widgetSelection, args.args, null, null, null)) {
AppWidgetHost host = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID);
while (c.moveToNext()) {
int widgetId = c.getInt(0);
if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
try {
host.deleteAppWidgetId(widgetId);
} catch (RuntimeException e) {
Log.e(TAG, "Error deleting widget id " + widgetId, e);
}
}
}
}
}
int count = db.delete(args.table, args.where, args.args);
if (count > 0) {
notifyListeners();
reloadLauncherIfExternal();
}
return count;
}