use of android.appwidget.AppWidgetManager in project platform_frameworks_base by android.
the class TestAppWidgetProvider method onReceive.
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "intent=" + intent);
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
Log.d(TAG, "ENABLED");
} else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
Log.d(TAG, "DISABLED");
} else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
Log.d(TAG, "UPDATE");
// BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
Bundle extras = intent.getExtras();
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
// END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
SharedPreferences prefs = context.getSharedPreferences(TestAppWidgetProvider.PREFS_NAME, 0);
String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");
AppWidgetManager gm = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
if (false) {
gm.updateAppWidget(appWidgetIds, views);
} else {
gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost", "com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
}
}
}
use of android.appwidget.AppWidgetManager in project ADWLauncher2 by boombuler.
the class Workspace method removeItems.
void removeItems(final ArrayList<ShortcutInfo> apps) {
final int count = getChildCount();
final PackageManager manager = getContext().getPackageManager();
final AppWidgetManager widgets = AppWidgetManager.getInstance(getContext());
final HashSet<String> packageNames = new HashSet<String>();
final int appCount = apps.size();
for (int i = 0; i < appCount; i++) {
final ComponentName component = apps.get(i).intent.getComponent();
if (component != null)
packageNames.add(component.getPackageName());
}
for (int i = 0; i < count; i++) {
final CellLayout layout = (CellLayout) getChildAt(i);
// Avoid ANRs by treating each screen separately
post(new Runnable() {
public void run() {
final ArrayList<View> childrenToRemove = new ArrayList<View>();
childrenToRemove.clear();
int childCount = layout.getChildCount();
for (int j = 0; j < childCount; j++) {
final View view = layout.getChildAt(j);
Object tag = view.getTag();
if (tag instanceof ShortcutInfo) {
final ShortcutInfo info = (ShortcutInfo) tag;
final Intent intent = info.intent;
final ComponentName name = intent.getComponent();
if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {
for (String packageName : packageNames) {
if (packageName.equals(name.getPackageName())) {
mLauncher.getModel().deleteItemFromDatabase(mLauncher, info);
childrenToRemove.add(view);
}
}
}
} else if (tag instanceof UserFolderInfo) {
final UserFolderInfo info = (UserFolderInfo) tag;
final ArrayList<ShortcutInfo> contents = info.contents;
final ArrayList<ShortcutInfo> toRemove = new ArrayList<ShortcutInfo>(1);
final int contentsCount = contents.size();
boolean removedFromFolder = false;
for (int k = 0; k < contentsCount; k++) {
final ShortcutInfo appInfo = contents.get(k);
final Intent intent = appInfo.intent;
final ComponentName name = intent.getComponent();
if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {
for (String packageName : packageNames) {
if (packageName.equals(name.getPackageName())) {
toRemove.add(appInfo);
mLauncher.getModel().deleteItemFromDatabase(mLauncher, appInfo);
removedFromFolder = true;
}
}
}
}
contents.removeAll(toRemove);
if (removedFromFolder) {
final Folder folder = getOpenFolder();
if (folder != null)
folder.notifyDataSetChanged();
}
} else if (tag instanceof LiveFolderInfo) {
final LiveFolderInfo info = (LiveFolderInfo) tag;
final Uri uri = info.uri;
final ProviderInfo providerInfo = manager.resolveContentProvider(uri.getAuthority(), 0);
if (providerInfo != null) {
for (String packageName : packageNames) {
if (packageName.equals(providerInfo.packageName)) {
mLauncher.getModel().deleteItemFromDatabase(mLauncher, info);
childrenToRemove.add(view);
}
}
}
} else if (tag instanceof LauncherAppWidgetInfo) {
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag;
final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(info.appWidgetId);
if (provider != null) {
for (String packageName : packageNames) {
if (packageName.equals(provider.provider.getPackageName())) {
mLauncher.getModel().deleteItemFromDatabase(mLauncher, info);
childrenToRemove.add(view);
}
}
}
}
}
childCount = childrenToRemove.size();
for (int j = 0; j < childCount; j++) {
View child = childrenToRemove.get(j);
layout.removeViewInLayout(child);
if (child instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) child);
}
}
if (childCount > 0) {
layout.requestLayout();
layout.invalidate();
}
}
});
}
}
use of android.appwidget.AppWidgetManager in project glimmr by brk3.
the class StackWidgetProvider method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if (BuildConfig.DEBUG)
Log.d(TAG, "onReceive");
AppWidgetManager mgr = AppWidgetManager.getInstance(context);
if (intent.getAction().equals(ACTION_START_VIEWER)) {
//int appWidgetId = intent.getIntExtra(
// AppWidgetManager.EXTRA_APPWIDGET_ID,
// AppWidgetManager.INVALID_APPWIDGET_ID);
int viewIndex = intent.getIntExtra(VIEW_INDEX, 0);
String photoListFile = intent.getStringExtra(PhotoViewerActivity.KEY_PHOTO_LIST_FILE);
Intent photoViewer = new Intent(context, PhotoViewerActivity.class);
photoViewer.putExtra(PhotoViewerActivity.KEY_START_INDEX, viewIndex);
photoViewer.setAction(PhotoViewerActivity.ACTION_VIEW_PHOTOLIST);
photoViewer.putExtra(PhotoViewerActivity.KEY_PHOTO_LIST_FILE, photoListFile);
photoViewer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
photoViewer.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(photoViewer);
} else if (intent.getAction().equals(ACTION_REFRESH)) {
if (BuildConfig.DEBUG)
Log.d(TAG, "got action_refresh");
int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
mgr.notifyAppWidgetViewDataChanged(appWidgetId, R.id.stack_view);
}
super.onReceive(context, intent);
}
use of android.appwidget.AppWidgetManager in project AndroidSDK-RecipeBook by gabu.
the class MyActivity method onCreate.
@Override
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity);
// EditText
EditText editText = (EditText) findViewById(R.id.EditText01);
// Widget の id を受け取る
final Uri uri = getIntent().getData();
// 過去のデータを表示
if (uri != null) {
int id = (int) ContentUris.parseId(uri);
editText.setText(loadText(id));
}
// Button
Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = MyActivity.this;
AppWidgetManager manager = AppWidgetManager.getInstance(context);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
EditText editText = (EditText) findViewById(R.id.EditText01);
CharSequence text = editText.getText();
if (uri != null) {
int id = (int) ContentUris.parseId(uri);
Log.d("MyActivity", "id:" + id);
// 入力された値を保存
saveText(id, text);
// Widget 表示を更新
remoteViews.setTextViewText(R.id.TextView01, text);
manager.updateAppWidget(id, remoteViews);
}
finish();
}
});
}
use of android.appwidget.AppWidgetManager in project iosched by google.
the class ScheduleWidgetProvider method onReceive.
@Override
public void onReceive(final Context context, Intent widgetIntent) {
final String action = widgetIntent.getAction();
if (REFRESH_ACTION.equals(action)) {
LOGD(TAG, "received REFRESH_ACTION from widget");
final boolean shouldSync = widgetIntent.getBooleanExtra(EXTRA_PERFORM_SYNC, false);
// Trigger sync
Account chosenAccount = AccountUtils.getActiveAccount(context);
if (shouldSync && chosenAccount != null) {
SyncHelper.requestManualSync();
}
// Notify the widget that the list view needs to be updated.
final AppWidgetManager mgr = AppWidgetManager.getInstance(context);
final ComponentName cn = new ComponentName(context, ScheduleWidgetProvider.class);
mgr.notifyAppWidgetViewDataChanged(mgr.getAppWidgetIds(cn), R.id.widget_schedule_list);
}
super.onReceive(context, widgetIntent);
}
Aggregations