Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

passing app widget instance ID along

  • Loading branch information...
commit f913eb9ed5f310f27f1deefdebea9045b270bf13 1 parent 07a9e22
@commonsguy authored
View
19 AppWidget/LoremWidget/src/com/commonsware/android/appwidget/lorem/LoremActivity.java
@@ -10,11 +10,12 @@
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
-*/
+ */
package com.commonsware.android.appwidget.lorem;
import android.app.Activity;
+import android.appwidget.AppWidgetManager;
import android.os.Bundle;
import android.widget.Toast;
@@ -22,15 +23,19 @@
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
-
+
String word=getIntent().getStringExtra(WidgetProvider.EXTRA_WORD);
-
- if (word==null) {
+
+ if (word == null) {
word="We did not get a word!";
}
-
- Toast.makeText(this, word, Toast.LENGTH_LONG).show();
-
+
+ Toast.makeText(this,
+ String.format("#%d: %s",
+ getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
+ AppWidgetManager.INVALID_APPWIDGET_ID),
+ word), Toast.LENGTH_LONG).show();
+
finish();
}
}
View
44 AppWidget/LoremWidget/src/com/commonsware/android/appwidget/lorem/LoremViewsFactory.java
@@ -10,8 +10,8 @@
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
-*/
-
+ */
+
package com.commonsware.android.appwidget.lorem;
import android.appwidget.AppWidgetManager;
@@ -21,31 +21,28 @@
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
-public class LoremViewsFactory implements RemoteViewsService.RemoteViewsFactory {
- private static final String[] items={"lorem", "ipsum", "dolor",
- "sit", "amet", "consectetuer",
- "adipiscing", "elit", "morbi",
- "vel", "ligula", "vitae",
- "arcu", "aliquet", "mollis",
- "etiam", "vel", "erat",
- "placerat", "ante",
- "porttitor", "sodales",
- "pellentesque", "augue",
- "purus"};
+public class LoremViewsFactory implements
+ RemoteViewsService.RemoteViewsFactory {
+ private static final String[] items= { "lorem", "ipsum", "dolor",
+ "sit", "amet", "consectetuer", "adipiscing", "elit", "morbi",
+ "vel", "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam",
+ "vel", "erat", "placerat", "ante", "porttitor", "sodales",
+ "pellentesque", "augue", "purus" };
private Context ctxt=null;
private int appWidgetId;
public LoremViewsFactory(Context ctxt, Intent intent) {
- this.ctxt=ctxt;
- appWidgetId=intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID);
+ this.ctxt=ctxt;
+ appWidgetId=
+ intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
+ AppWidgetManager.INVALID_APPWIDGET_ID);
}
-
+
@Override
public void onCreate() {
// no-op
}
-
+
@Override
public void onDestroy() {
// no-op
@@ -58,15 +55,16 @@ public int getCount() {
@Override
public RemoteViews getViewAt(int position) {
- RemoteViews row=new RemoteViews(ctxt.getPackageName(),
- R.layout.row);
-
+ RemoteViews row=
+ new RemoteViews(ctxt.getPackageName(), R.layout.row);
+
row.setTextViewText(android.R.id.text1, items[position]);
Intent i=new Intent();
Bundle extras=new Bundle();
-
+
extras.putString(WidgetProvider.EXTRA_WORD, items[position]);
+ extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
i.putExtras(extras);
row.setOnClickFillInIntent(android.R.id.text1, i);
@@ -77,7 +75,7 @@ public RemoteViews getViewAt(int position) {
public RemoteViews getLoadingView() {
return(null);
}
-
+
@Override
public int getViewTypeCount() {
return(1);
Please sign in to comment.
Something went wrong with that request. Please try again.