Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit c33e96b55298227aea0d64e00823d3a92b12abcd @singpolyma committed Jul 29, 2009
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.singpolyma.ordclock"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/app_icon" android:label="@string/app_name">
+ <!-- Broadcast Receiver that will process AppWidget updates -->
+ <receiver android:name=".OrdClock" android:label="@string/widget_name">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_ordclock" />
+ </receiver>
+ <!-- Service to perform updates -->
+ <service android:name=".OrdClock$UpdateService" />
+ </application>
+ <uses-sdk android:minSdkVersion="3" />
+</manifest>
@@ -0,0 +1,10 @@
+.PHONY: install release debug
+
+debug:
+ ant debug
+
+release:
+ ant release
+
+install:
+ ant reinstall
@@ -0,0 +1,15 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# The name of your application package as defined in the manifest.
+# Used by the 'uninstall' rule.
+#application-package=com.example.myproject
+
+# The name of the source folder.
+#source-folder=src
+
+# The name of the output folder.
+#out-folder=bin
+
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="OrdClock" default="help">
+
+ <!-- The local.properties file is created and updated by the 'android' tool.
+ It contain the path to the SDK. It should *NOT* be checked in in Version
+ Control Systems. -->
+ <property file="local.properties"/>
+
+ <!-- The build.properties file can be created by you and is never touched
+ by the 'android' tool. This is the place to change some of the default property values
+ used by the Ant rules.
+ Here are some properties you may want to change/update:
+
+ application-package
+ the name of your application package as defined in the manifest. Used by the
+ 'uninstall' rule.
+ source-folder
+ the name of the source folder. Default is 'src'.
+ out-folder
+ the name of the output folder. Default is 'bin'.
+
+ Properties related to the SDK location or the project target should be updated
+ using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems.
+
+ -->
+ <property file="build.properties"/>
+
+ <!-- The default.properties file is created and updated by the 'android' tool, as well
+ as ADT.
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems. -->
+ <property file="default.properties"/>
+
+ <!-- Custom Android task to deal with the project target, and import the proper rules.
+ This requires ant 1.6.0 or above. -->
+ <path id="android.antlibs">
+ <pathelement path="${sdk-location}/tools/lib/anttasks.jar" />
+ <pathelement path="${sdk-location}/tools/lib/sdklib.jar" />
+ <pathelement path="${sdk-location}/tools/lib/androidprefs.jar" />
+ <pathelement path="${sdk-location}/tools/lib/apkbuilder.jar" />
+ <pathelement path="${sdk-location}/tools/lib/jarutils.jar" />
+ </path>
+
+ <taskdef name="setup"
+ classname="com.android.ant.SetupTask"
+ classpathref="android.antlibs"/>
+
+ <!-- Execute the Android Setup task that will setup some properties specific to the target,
+ and import the rules files.
+ To customize the rules, copy/paste them below the task, and disable import by setting
+ the import attribute to false:
+ <setup import="false" />
+
+ This will ensure that the properties are setup correctly but that your customized
+ targets are used.
+ -->
+ <setup />
+</project>
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-3
@@ -0,0 +1,10 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must *NOT* be checked in Version Control Systems,
+# as it contains information specific to your local configuration.
+
+# location of the SDK. This is only used by Ant
+# For customization when using a Version Control System, please read the
+# header note.
+sdk-location=/home/singpolyma/code/android
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- The stateful background drawable for a widget -->
+ <item android:state_window_focused="false" android:drawable="@drawable/widget_bg_normal" />
+ <item android:drawable="@drawable/widget_bg_normal" />
+</selector>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,36 @@
+<?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="fill_parent"
+ android:orientation="vertical"
+ style="@style/WidgetBackground">
+
+ <TextView
+ android:id="@+id/day"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="20dip"
+ android:gravity="center"
+ android:text="@string/widget_loading"
+ style="@style/Text.Day" />
+
+ <TextView
+ android:id="@+id/time"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dip"
+ android:gravity="center"
+ android:text=""
+ style="@style/Text.Time" />
+
+ <TextView
+ android:id="@+id/utc"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dip"
+ android:gravity="center"
+ android:text=""
+ style="@style/Text.Time" />
+
+</LinearLayout>
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">OrdClock</string>
+ <string name="widget_name">OrdClock</string>
+ <string name="widget_loading">Loading...</string>
+</resources>
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <style name="WidgetBackground">
+ <item name="android:background">@drawable/widget_bg</item>
+ </style>
+
+ <style name="Text">
+ </style>
+
+ <style name="Text.Day">
+ <item name="android:textSize">30sp</item>
+ <item name="android:textColor">@android:color/black</item>
+ </style>
+
+ <style name="Text.Time">
+ <item name="android:textSize">40sp</item>
+ <item name="android:textColor">@android:color/black</item>
+ </style>
+
+</resources>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="146dip"
+ android:minHeight="146dip"
+ android:initialLayout="@layout/widget_ordclock"
+ android:updatePeriodMillis="60000"
+ />
@@ -0,0 +1,74 @@
+package org.singpolyma.ordclock;
+
+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.os.IBinder;
+import android.text.format.Time;
+import android.util.Log;
+import android.widget.RemoteViews;
+
+import java.text.DecimalFormat;
+import java.util.Locale;
+
+public class OrdClock extends AppWidgetProvider
+{
+ 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, UpdateService.class));
+ }
+
+ public static class UpdateService extends Service {
+ @Override
+ public void onStart(Intent intent, int startId) {
+ // Build the widget update for today
+ RemoteViews updateViews = buildUpdate(this);
+
+ // Push update for this widget to the home screen
+ ComponentName thisWidget = new ComponentName(this, OrdClock.class);
+ AppWidgetManager manager = AppWidgetManager.getInstance(this);
+ manager.updateAppWidget(thisWidget, updateViews);
+ }
+
+ public String fracTime(Time t) {
+ double time = (t.hour*60*60.0 + t.minute*60.0 + t.second) / 86400.0;
+ return new DecimalFormat(".000").format(time);
+ }
+
+ /**
+ * Build a widget update to show the current Wiktionary
+ * "Word of the day." Will block until the online API returns.
+ */
+ public RemoteViews buildUpdate(Context context) {
+ Resources res = context.getResources();
+ RemoteViews updateViews = null;
+
+ // Find current month and day
+ Time today = new Time();
+ today.setToNow();
+
+ Time utc = new Time("UTC");
+ utc.setToNow();
+
+ updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_ordclock);
+ updateViews.setTextViewText(R.id.day, today.format("%Y-%j"));
+
+ updateViews.setTextViewText(R.id.time, fracTime(today));
+ updateViews.setTextViewText(R.id.utc, fracTime(utc)+" Z");
+
+ return updateViews;
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // We don't need to bind to this service
+ return null;
+ }
+ }
+}

0 comments on commit c33e96b

Please sign in to comment.