Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request wansti#1 from bluebrother/master
Browse files Browse the repository at this point in the history
Diverser Kleinkram
  • Loading branch information
wansti committed May 31, 2012
2 parents d2e4654 + b429e52 commit f9cfe6e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 49 deletions.
8 changes: 8 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>StratumsphereStatusWidget</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.stratum0.statuswidget"
android:versionCode="3"
android:versionName="1.0.3" xmlns:android="http://schemas.android.com/apk/res/android">
android:versionName="1.0.5" xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ TODO open space when connected to WiFi (API is missing)

Changelog:

1.0.5 Update all widget instances simultaneously

1.0.4 Indicate running update

1.0.3 Show notification when connected to Stratum0 WiFi
and API retuns status=closed

Expand Down
98 changes: 50 additions & 48 deletions src/org/stratum0/statuswidget/StratumsphereStatusProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,61 +53,63 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
nNotOpen.defaults = Notification.DEFAULT_ALL;
nNotOpen.setLatestEventInfo(context, "Warnung!", "Schnell den Space im IRC als offen makieren.", contentIntent);

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
int currentImage = R.drawable.stratum0_unknown;

// indicate that the status is currently updating
for (int i=0; i<appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
int currentImage = R.drawable.stratum0_unknown;
Date now = new GregorianCalendar().getTime();

//TODO proper number formatting
String text = "Updated:\n";
String upTimeText = "";
if (now.getHours() < 10) text += "0";
text += now.getHours() + ":";
if (now.getMinutes() < 10) text += "0";
text += now.getMinutes();

String jsonText = getStatusFromJSON();
if (jsonText.startsWith("{") && jsonText.endsWith("}")) {
try {
JSONObject jsonObject = new JSONObject(jsonText);
String upTime = jsonObject.getString("since");
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date d = f.parse(upTime);
//TODO Date class probably offers a better way to do this
long upTimeMins = (now.getTime()-d.getTime())/(1000*60) % 60;
long upTimeHours = (now.getTime()-d.getTime())/(1000*60) / 60;
//TODO proper number formatting
if (upTimeHours < 10) upTimeText += "0";
upTimeText += upTimeHours + " ";
if (upTimeMins < 10) upTimeText += "0";
upTimeText += upTimeMins;

if (jsonObject.getBoolean("isOpen")) {
currentImage = R.drawable.stratum0_open;
//dismiss previous useractionrequest
notificationManager.cancel(nID);

String updatingText = "updating ...\n";
views.setTextViewText(R.id.lastUpdateTextView, updatingText);
appWidgetManager.updateAppWidget(appWidgetId, views);
}

String jsonText = getStatusFromJSON();
Date now = new GregorianCalendar().getTime();

String upTimeText = "";
String text = String.format("Updated:\n%02d:%02d", now.getHours(), now.getMinutes());

if (jsonText.startsWith("{") && jsonText.endsWith("}")) {
try {
JSONObject jsonObject = new JSONObject(jsonText);
String upTime = jsonObject.getString("since");
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date d = f.parse(upTime);
long difference = now.getTime() - d.getTime();
//TODO Date class probably offers a better way to do this
long upTimeMins = (difference)/(1000*60) % 60;
long upTimeHours = (difference)/(1000*60) / 60;
upTimeText = String.format("%02d %02d", upTimeHours, upTimeMins);

if (jsonObject.getBoolean("isOpen")) {
currentImage = R.drawable.stratum0_open;
//dismiss previous useractionrequest
notificationManager.cancel(nID);
}
else {
//check if connected to Stratum0 while space status is closed
if (wifiInfo.getSSID() != null && wifiInfo.getSSID().equals("Stratum0")) {
openSpace();
currentImage = R.drawable.stratum0_closed;
upTimeText = "";
text += " WIFI";
//request action from user
notificationManager.notify(nID, nNotOpen);
}
else {
//check if connected to Stratum0 while space status is closed
if (wifiInfo.getSSID() != null && wifiInfo.getSSID().equals("Stratum0")) {
openSpace();
currentImage = R.drawable.stratum0_closed;
upTimeText = "";
text = text + " WIFI";
//request action from user
notificationManager.notify(nID, nNotOpen);
}
else {
//if not on matching SSID (or not anymore) dismiss the notification
currentImage = R.drawable.stratum0_closed;
notificationManager.cancel(nID);
}
//if not on matching SSID (or not anymore) dismiss the notification
currentImage = R.drawable.stratum0_closed;
notificationManager.cancel(nID);
}
} catch (Exception e) {
Log.w(TAG, "Exception " + e);
}
} catch (Exception e) {
Log.w(TAG, "Exception " + e);
}
}
for (int i=0; i<appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];

views.setImageViewResource(R.id.statusImageView, currentImage);
views.setTextViewText(R.id.lastUpdateTextView, text);
Expand Down

0 comments on commit f9cfe6e

Please sign in to comment.