Skip to content

Commit a00dfc2

Browse files
committed
Fixed widget
1 parent bde53aa commit a00dfc2

14 files changed

+40
-24
lines changed

AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="nl.techinc.notify"
44

5-
android:versionCode="2"
6-
android:versionName="2.0" >
5+
android:versionCode="4"
6+
android:versionName="2.1.1" >
77

88
<permission android:name="nl.techinc.notify.permission.C2D_MESSAGE" android:protectionLevel="signature" />
99

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ The application can be found on [Google Play](https://github.com/techinc/Techinc
88

99
To-do:
1010

11-
- Make widget clickable
11+
- Retry if failed instead of soft-fail
1212
- Look into deprecating GCM

bin/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="nl.techinc.notify"
44

5-
android:versionCode="2"
6-
android:versionName="2.0" >
5+
android:versionCode="4"
6+
android:versionName="2.1.1" >
77

88
<permission android:name="nl.techinc.notify.permission.C2D_MESSAGE" android:protectionLevel="signature" />
99

bin/Techinc-Notify.apk

195 Bytes
Binary file not shown.

bin/classes.dex

292 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
153 Bytes
Binary file not shown.

bin/resources.ap_

3 Bytes
Binary file not shown.

res/values/strings.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<string name="closed">Closed</string>
1919
<string name="unknown">Unknown</string>
2020
<string name="button_refresh">Refresh</string>
21-
<string name="monitoring_enabled">Monitoring enabled.</string>
22-
<string name="monitoring_disabled">Monitoring disabled.</string>
21+
<string name="monitoring_enabled">Monitoring enabled</string>
22+
<string name="monitoring_disabled">Monitoring disabled</string>
2323
<string name="disable">Disable</string>
2424
<string name="enable">Enable</string>
2525
<string name="updating">Updating…</string>

src/nl/techinc/notify/GCMIntentService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ protected void onMessage(Context context, Intent intent) {
3636
{
3737
if(!sharedPref.getBoolean("debug", false))
3838
return;
39-
stateStr = stateStr.substring(3);
39+
stateStr = new String(stateStr.substring(3));
4040
}
41-
if(!stateStr.equals("closed") || !stateStr.equals("open"))
41+
if(!stateStr.equals("closed") && !stateStr.equals("open"))
4242
return;
4343
boolean state = !(stateStr.equals("closed"));
4444
SpaceState.broadcastState(context, state);
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
package nl.techinc.notify;
22

3-
import java.io.IOException;
4-
53
import android.app.PendingIntent;
64
import android.appwidget.AppWidgetManager;
75
import android.appwidget.AppWidgetProvider;
6+
import android.content.ComponentName;
87
import android.content.Context;
98
import android.content.Intent;
109
import android.widget.RemoteViews;
1110

1211
public class NotifyAppWidgetProvider extends AppWidgetProvider {
13-
12+
1413
public void onUpdate(final Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
1514
{
16-
new Thread(new Runnable() {
17-
public void run()
18-
{
19-
try {
20-
SpaceState.updateState(context);
21-
} catch (IOException e) {
22-
e.printStackTrace();
23-
}
24-
}
25-
}).start();
15+
update(context, SpaceState.state);
2616
for(int appWidgetId : appWidgetIds)
2717
{
2818
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notify_appwidget);
@@ -33,9 +23,27 @@ public void run()
3323
}
3424
}
3525

36-
public static void update(Context context, boolean state)
26+
public void onReceive(Context context, Intent intent)
3727
{
28+
super.onReceive(context, intent);
29+
if(!intent.hasExtra("state"))
30+
return;
31+
boolean state = intent.getBooleanExtra("state", false);
3832
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notify_appwidget);
3933
views.setImageViewResource(R.id.stateImage, state ? R.drawable.open : R.drawable.closed);
34+
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
35+
ComponentName componentName = new ComponentName(context, NotifyAppWidgetProvider.class);
36+
appWidgetManager.updateAppWidget(componentName, views);
37+
}
38+
39+
public static void update(Context context, boolean state)
40+
{
41+
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notify_appwidget);
42+
int resource;
43+
if(state)
44+
resource = R.drawable.open;
45+
else
46+
resource = R.drawable.closed;
47+
views.setImageViewResource(R.id.stateImage, resource);
4048
}
4149
}

src/nl/techinc/notify/SpaceState.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ public static void updateState(Context context) throws IOException
3333
}
3434

3535
public static void broadcastState(Context context, boolean state)
36+
{
37+
SpaceState.state = state;
38+
broadcastState(context);
39+
}
40+
41+
public static void broadcastState(Context context)
3642
{
3743
Intent intent = new Intent();
3844
intent.setAction(ACTION_STATE);
3945
intent.putExtra(PARAM_STATE, state);
4046
context.sendBroadcast(intent);
41-
NotifyAppWidgetProvider.update(context, state);
47+
intent = new Intent(context, NotifyAppWidgetProvider.class);
48+
intent.putExtra(PARAM_STATE, state);
49+
context.sendBroadcast(intent);
4250
}
4351
}

0 commit comments

Comments
 (0)