Permalink
Browse files

Initial Widget implementation

  • Loading branch information...
matburt committed Apr 26, 2010
1 parent 919c61a commit f44f6bfad14063fe8c3ea5fb32c72ca81907485c
View
@@ -3,11 +3,20 @@
package="com.matburt.mobileorg"
android:versionCode="1"
android:versionName="1.0">
- <uses-permission android:name='android.permission.INTERNET'/>
- <uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE'/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:name=".MobileOrgApplication"
android:label="MobileOrg"
android:icon="@drawable/icon">
+ <receiver android:name=".MobileOrgWidget"
+ android:label="MobileOrg Tasks">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider"
+ android:resource="@xml/widget_mobileorg" />
+ </receiver>
+ <service android:name=".MobileOrgWidget$MobileOrgWidgetService" />
<activity android:name="MobileOrgActivity"
android:label="MobileOrg">
<intent-filter>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/widget"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:background="@drawable/widgetb">
+ <TextView
+ android:id="@+id/message"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12dip"
+ android:padding="10dip"
+ android:gravity="center"
+ android:text="WidgetText"/>
+</LinearLayout>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="214dip"
+ android:minHeight="214dip"
+ android:updatePeriodMillis="3600000"
+ android:initialLayout="@layout/widget_mobileorg"
+ />
@@ -0,0 +1,57 @@
+package com.matburt.mobileorg;
+
+import android.app.PendingIntent;
+import android.app.Service;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.net.Uri;
+import android.os.IBinder;
+import android.text.format.Time;
+import android.util.Log;
+import android.widget.RemoteViews;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MobileOrgWidget extends AppWidgetProvider {
+ @Override
+ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
+ int[] appWidgetIds) {
+ // To prevent any ANR timeouts, we perform the update in a service
+ context.startService(new Intent(context,
+ MobileOrgWidgetService.class));
+ }
+
+ public static class MobileOrgWidgetService extends Service {
+ @Override
+ public void onStart(Intent intent, int startId) {
+ // Build the widget update for today
+ RemoteViews updateViews = this.genUpdateDisplay(this);
+
+ // Push update for this widget to the home screen
+ ComponentName thisWidget = new ComponentName(this,
+ MobileOrgWidget.class);
+ AppWidgetManager manager = AppWidgetManager.getInstance(this);
+ manager.updateAppWidget(thisWidget, updateViews);
+ }
+
+ public RemoteViews genUpdateDisplay(Context context) {
+ Resources res = context.getResources();
+ RemoteViews updateViews = null;
+ updateViews = new RemoteViews(context.getPackageName(),
+ R.layout.widget_mobileorg);
+ updateViews.setTextViewText(R.id.message, "Everything worked");
+ return updateViews;
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // We don't need to bind to this service
+ return null;
+ }
+ }
+}

0 comments on commit f44f6bf

Please sign in to comment.