Permalink
Browse files

get clicking on the widget to bring up the configure screen.

  • Loading branch information...
gregkh committed Jun 10, 2010
1 parent 45ef47e commit 13740219b38404c87043545e757a4401f99aad91
@@ -9,6 +9,7 @@
import android.widget.Button;
import android.app.AlertDialog;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
@@ -39,11 +40,13 @@ public void onCancel(DialogInterface Dialog) {
static final private int MENU_ABOUT = 0;
static final private int MENU_EXIT = 1;
+ static final private int MENU_CONFIG = 2;
/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_ABOUT, 0, "About").setIcon(R.drawable.menu_about);
menu.add(0, MENU_EXIT, 0, "Exit").setIcon(R.drawable.menu_close);
+ menu.add(0, MENU_CONFIG, 0, "Configure");
return true;
}
@@ -56,6 +59,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
case MENU_EXIT:
finish();
return true;
+ case MENU_CONFIG:
+ Intent intent = new Intent(this, Configure.class);
+ startActivity(intent);
+ return true;
}
return false;
}
@@ -93,15 +93,15 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.config);
// 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, get out
- if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
- finish();
- }
+// 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, get out
+// if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
+// finish();
+// }
okButton = (Button)findViewById(R.id.myButton);
okButton.setOnClickListener(new View.OnClickListener() {
@@ -1,13 +1,17 @@
package com.kroah.clock;
+import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.util.Log;
+import android.widget.RemoteViews;
public class MedAppWidget extends AppWidgetProvider {
-
+
+ public static final String MODULE = "GREGKHWidget";
@Override
public void onUpdate(Context context,
@@ -21,6 +25,23 @@ public void onUpdate(Context context,
context.startService(new Intent(context, UpdateService.class));
}
+ public static RemoteViews buildUpdate(Context context) {
+
+ Log.d(MODULE, "building widget update");
+ RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_loading);
+
+// ContentResolver resolver = context.getContentResolver();
+// Resources res = context.getResources();
+// Cursor cursor = null;
+
+ // Tie clicking on the button to bring up our configure screen
+ Intent intent = new Intent(context, Configure.class);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ views.setOnClickPendingIntent(R.id.loading, pendingIntent);
+ return views;
+
+ }
+
// final int num_ids = appWidgetIds.length;
// for (int i = 0; i < num_ids; i++) {
//
@@ -32,10 +53,6 @@ public void onUpdate(Context context,
// // Create a remote view
// RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_loading);
-// // Tie clicking on the button to bring up our configure screen
-// Intent intent = new Intent(context, Configure.class);
-// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
-// views.setOnClickPendingIntent(R.id.loading, pendingIntent);
//
// // set the time
//// DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());
@@ -54,14 +54,20 @@ public void run() {
AppWidgetManager manager = AppWidgetManager.getInstance(this);
// ContentResolver resolve = getContentResolver();
+
+ RemoteViews updateViews = null;
+ updateViews = MedAppWidget.buildUpdate(this);
+
// Draw the updated time
- RemoteViews updateViews = new RemoteViews(this.getPackageName(), R.layout.widget_loading);
+
+// RemoteViews updateViews = new RemoteViews(this.getPackageName(), R.layout.widget_loading);
Date date = new Date();
DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());
updateViews.setTextViewText(R.id.loading, format.format(date));
+
ComponentName thisWidget = new ComponentName(this, MedAppWidget.class);
manager.updateAppWidget(thisWidget, updateViews);

0 comments on commit 1374021

Please sign in to comment.