Skip to content

Commit 8b15ea0

Browse files
committed
Added monitoring support
API support. Refresh in menu
1 parent f254761 commit 8b15ea0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+98
-178
lines changed

bin/Techinc-Notify.apk

13.4 KB
Binary file not shown.

bin/classes.dex

128 Bytes
Binary file not shown.
-62 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-493 Bytes
Binary file not shown.
Binary file not shown.
79 Bytes
Binary file not shown.
5 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
137 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
112 Bytes
Binary file not shown.
1.76 KB
1.25 KB
1.33 KB
1.06 KB
945 Bytes
1.14 KB
2.08 KB
1.33 KB

bin/resources.ap_

12.9 KB
Binary file not shown.

gen/nl/techinc/notify/R.java

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ public static final class attr {
1313
public static final class drawable {
1414
public static final int closed=0x7f020000;
1515
public static final int ic_launcher=0x7f020001;
16-
public static final int open=0x7f020002;
17-
public static final int techinclogo=0x7f020003;
18-
public static final int techinclogo_mono=0x7f020004;
19-
public static final int techinclogo_white=0x7f020005;
16+
public static final int ic_menu_refresh=0x7f020002;
17+
public static final int ic_menu_settings=0x7f020003;
18+
public static final int open=0x7f020004;
19+
public static final int techinclogo=0x7f020005;
20+
public static final int techinclogo_mono=0x7f020006;
21+
public static final int techinclogo_white=0x7f020007;
2022
}
2123
public static final class id {
2224
public static final int label_text=0x7f070000;
25+
public static final int menu_refresh=0x7f070006;
2326
public static final int menu_settings=0x7f070007;
24-
public static final int monitoring=0x7f070004;
25-
public static final int refresh=0x7f070003;
26-
public static final int stateImage=0x7f070006;
27-
public static final int stateWidget=0x7f070005;
27+
public static final int monitoring=0x7f070003;
28+
public static final int stateImage=0x7f070005;
29+
public static final int stateWidget=0x7f070004;
2830
public static final int status=0x7f070002;
2931
public static final int status_label=0x7f070001;
3032
}
@@ -39,34 +41,38 @@ public static final class string {
3941
public static final int app_name=0x7f050000;
4042
public static final int button_refresh=0x7f05000a;
4143
public static final int closed=0x7f050008;
42-
public static final int debug_label=0x7f05001a;
43-
public static final int debug_summary=0x7f05001b;
44-
public static final int disable=0x7f05000d;
45-
public static final int enable=0x7f05000e;
44+
public static final int debug_label=0x7f05001b;
45+
public static final int debug_summary=0x7f05001c;
46+
public static final int dialog_message=0x7f050022;
47+
public static final int disable=0x7f05000e;
48+
public static final int enable=0x7f05000f;
4649
public static final int main_text=0x7f050005;
47-
public static final int menu_settings=0x7f050010;
48-
public static final int monitor_label=0x7f050018;
49-
public static final int monitor_summary=0x7f050019;
50+
public static final int menu_settings=0x7f050011;
51+
public static final int monitor_label=0x7f050019;
52+
public static final int monitor_summary=0x7f05001a;
5053
public static final int monitoring_disabled=0x7f05000c;
5154
public static final int monitoring_enabled=0x7f05000b;
55+
public static final int monitoring_unsupported=0x7f05000d;
56+
public static final int no=0x7f050021;
5257
public static final int notify_closed=0x7f050002;
5358
public static final int notify_open=0x7f050001;
5459
public static final int open=0x7f050007;
55-
public static final int ringtone_label=0x7f050016;
56-
public static final int ringtone_summary=0x7f050017;
60+
public static final int ringtone_label=0x7f050017;
61+
public static final int ringtone_summary=0x7f050018;
5762
public static final int status=0x7f050006;
58-
public static final int suppress_label=0x7f050012;
59-
public static final int suppress_summary=0x7f050013;
63+
public static final int suppress_label=0x7f050013;
64+
public static final int suppress_summary=0x7f050014;
6065
public static final int ticker_closed=0x7f050004;
6166
public static final int ticker_open=0x7f050003;
6267
public static final int unknown=0x7f050009;
63-
public static final int updating=0x7f05000f;
64-
public static final int url_desc=0x7f05001e;
65-
public static final int url_label=0x7f05001c;
66-
public static final int url_summary=0x7f05001d;
67-
public static final int vibrate_label=0x7f050014;
68-
public static final int vibrate_summary=0x7f050015;
69-
public static final int warning=0x7f050011;
68+
public static final int updating=0x7f050010;
69+
public static final int url_desc=0x7f05001f;
70+
public static final int url_label=0x7f05001d;
71+
public static final int url_summary=0x7f05001e;
72+
public static final int vibrate_label=0x7f050015;
73+
public static final int vibrate_summary=0x7f050016;
74+
public static final int warning=0x7f050012;
75+
public static final int yes=0x7f050020;
7076
}
7177
public static final class xml {
7278
public static final int notify_appwidget_info=0x7f040000;

res/drawable-hdpi/ic_menu_refresh.png

3.01 KB
2.26 KB

res/drawable-ldpi/ic_menu_refresh.png

1.25 KB
1.1 KB

res/drawable-mdpi/ic_menu_refresh.png

1.57 KB
1.28 KB
3.59 KB
2.69 KB

res/layout/main.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,17 @@
2323
<TextView
2424
android:id="@+id/status"
2525
android:layout_width="wrap_content"
26-
android:layout_height="wrap_content"
27-
android:layout_alignBaseline="@+id/refresh"
28-
android:textSize="20sp"
29-
android:text="@string/unknown" />
30-
31-
<Button
32-
android:id="@+id/refresh"
33-
android:layout_width="wrap_content"
3426
android:layout_height="wrap_content"
3527
android:layout_below="@+id/status_label"
36-
android:layout_alignParentRight="true"
37-
android:onClick="refresh"
38-
android:text="@string/button_refresh" />
28+
android:textSize="20sp"
29+
android:text="@string/unknown" />
3930

4031
<TextView
4132
android:id="@+id/monitoring"
4233
android:layout_width="wrap_content"
4334
android:layout_height="wrap_content"
44-
android:layout_below="@+id/refresh"
35+
android:layout_alignParentBottom="true"
36+
android:layout_centerHorizontal="true"
4537
android:textSize="20sp"
4638
android:text="@string/monitoring_disabled" />
4739

res/menu/main.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<item android:id="@+id/menu_refresh"
4+
android:title="@string/button_refresh"
5+
android:showAsAction="ifRoom"
6+
android:icon="@drawable/ic_menu_refresh" />
37
<item android:id="@+id/menu_settings"
48
android:title="@string/menu_settings"
5-
android:showAsAction="ifRoom"
6-
android:icon="@android:drawable/ic_menu_preferences" />
9+
android:showAsAction="never"
10+
android:icon="@drawable/ic_menu_settings" />
711
</menu>

res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<string name="button_refresh">Refresh</string>
2121
<string name="monitoring_enabled">Monitoring enabled</string>
2222
<string name="monitoring_disabled">Monitoring disabled</string>
23+
<string name="monitoring_unsupported">Monitoring unsupported</string>
2324
<string name="disable">Disable</string>
2425
<string name="enable">Enable</string>
2526
<string name="updating">Updating…</string>
@@ -33,4 +34,7 @@
3334
<string name="debug_label">Debug mode</string><string name="debug_summary">Enable debug mode.</string>
3435
<string name="url_label">Server URL</string><string name="url_summary">Change the server that the device registers with</string>
3536
<string name="url_desc">For debugging purposes only.\nDo not touch unless you know what you are doing.</string>
37+
38+
<string name="yes">Yes</string><string name="no">No</string>
39+
<string name="dialog_message">In order to apply this setting, the application has to be restarted.\nShutdown now?</string>
3640
</resources>

res/xml/preferences.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@
22
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
33
<CheckBoxPreference android:title="@string/suppress_label" android:summary="@string/suppress_summary" android:key="suppress"/><CheckBoxPreference android:title="@string/vibrate_label" android:summary="@string/vibrate_summary" android:key="vibrate"/>
44
<RingtonePreference android:ringtoneType="notification" android:title="@string/ringtone_label" android:showDefault="true" android:summary="@string/ringtone_summary" android:showSilent="true" android:key="ringtone"/>
5-
<CheckBoxPreference android:key="monitor" android:title="@string/monitor_label" android:summary="@string/monitor_summary" android:enabled="false"/><CheckBoxPreference android:summary="@string/debug_summary" android:key="debug" android:title="@string/debug_label" /><EditTextPreference android:summary="@string/url_summary" android:title="@string/url_label" android:defaultValue="http://techinc.notefaction.jit.su" android:key="url" android:dialogMessage="@string/url_desc" android:dialogTitle="@string/warning" android:dependency="debug"/>
6-
7-
8-
9-
10-
5+
<CheckBoxPreference android:key="gcm_enabled" android:title="@string/monitor_label" android:summary="@string/monitor_summary" android:enabled="true" android:defaultValue="true"/><CheckBoxPreference android:summary="@string/debug_summary" android:key="debug" android:title="@string/debug_label" /><EditTextPreference android:summary="@string/url_summary" android:title="@string/url_label" android:defaultValue="http://techinc.notefaction.jit.su" android:key="url" android:dialogMessage="@string/url_desc" android:dialogTitle="@string/warning" android:dependency="debug"/>
116
</PreferenceScreen>

src/nl/techinc/notify/BootClass.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ public class BootClass extends BroadcastReceiver {
1616
@Override
1717
public void onReceive(Context context, Intent intent) {
1818
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
19-
if(sharedPreferences.getBoolean("monitor", false))
19+
if(sharedPreferences.getBoolean("gcm_enabled", false))
2020
{
21-
GCMRegistrar.checkDevice(context);
22-
GCMRegistrar.checkManifest(context);
2321
final String regId = GCMRegistrar.getRegistrationId(context);
2422
if (regId.equals("")) {
2523
GCMRegistrar.register(context, SENDER_ID);

src/nl/techinc/notify/GCMIntentService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ private void register(final Context context, final String url, final int delayMi
105105
try
106106
{
107107
URLConnection connect = new URL(url).openConnection();
108-
connect.connect();
109108
HttpURLConnection httpConnection = (HttpURLConnection) connect;
109+
httpConnection.addRequestProperty("accept-version", "1.0.x");
110+
connect.connect();
110111
BufferedReader in = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
111112
String input = in.readLine();
112113
in.close();
@@ -161,8 +162,9 @@ private void unregister(final Context context, final String url, final int delay
161162
try
162163
{
163164
URLConnection connect = new URL(url).openConnection();
164-
connect.connect();
165165
HttpURLConnection httpConnection = (HttpURLConnection) connect;
166+
httpConnection.addRequestProperty("accept-version", "1.0.x");
167+
connect.connect();
166168
int response = httpConnection.getResponseCode();
167169
if(!(response == 200))
168170
throw new IOException("Response: "+Integer.toString(response));

src/nl/techinc/notify/NotifyActivity.java

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import android.preference.PreferenceManager;
1313
import android.view.Menu;
1414
import android.view.MenuItem;
15-
import android.view.View;
1615
import android.widget.TextView;
1716

1817
public class NotifyActivity extends Activity {
@@ -30,15 +29,13 @@ public void onReceive(Context context, Intent intent) {
3029
if(action.equals(SpaceState.ACTION_STATE))
3130
{
3231
final TextView statusLabel = (TextView) findViewById(R.id.status);
32+
if(intent.getBooleanExtra("error", false))
33+
{
34+
statusLabel.setText(R.string.unknown);
35+
}
3336
boolean state = intent.getBooleanExtra("state", false);
3437
statusLabel.setText(state ? R.string.open : R.string.closed);
3538
}
36-
else if(action.equals(GCMIntentService.ACTION_REGISTER))
37-
{
38-
boolean enabled = intent.getBooleanExtra("enabled", true);
39-
TextView label = (TextView) findViewById(R.id.monitoring);
40-
label.setText(enabled ? R.string.monitoring_enabled : R.string.monitoring_disabled);
41-
}
4239
}
4340
}
4441

@@ -48,7 +45,7 @@ public void onCreate(Bundle savedInstanceState)
4845
super.onCreate(savedInstanceState);
4946
setContentView(R.layout.main);
5047
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
51-
enableMonitor();
48+
setMonitor();
5249
}
5350

5451
@Override
@@ -57,7 +54,6 @@ public void onResume()
5754
super.onResume();
5855
receiver = new StateReceiver();
5956
registerReceiver(receiver, new IntentFilter(SpaceState.ACTION_STATE));
60-
registerReceiver(receiver, new IntentFilter(GCMIntentService.ACTION_REGISTER));
6157
refresh();
6258
}
6359

@@ -70,11 +66,6 @@ protected void onPause()
7066
receiver = null;
7167
}
7268

73-
public void refresh(View view)
74-
{
75-
refresh();
76-
}
77-
7869
public void refresh()
7970
{
8071
final TextView statusLabel = (TextView) findViewById(R.id.status);
@@ -88,18 +79,21 @@ public void run()
8879
}).start();
8980
}
9081

91-
public void toggleMonitor(View view)
92-
{
93-
boolean oldState = sharedPreferences.getBoolean("monitor", true);
94-
sharedPreferences.edit().putBoolean("monitor", !oldState).commit();
95-
applyMonitor();
96-
}
97-
98-
public void enableMonitor()
82+
public void setMonitor()
9983
{
84+
if(!sharedPreferences.getBoolean("gcm_enabled", true))
85+
return;
10086
TextView label = (TextView) findViewById(R.id.monitoring);
101-
GCMRegistrar.checkDevice(this);
102-
GCMRegistrar.checkManifest(this);
87+
try
88+
{
89+
GCMRegistrar.checkDevice(this);
90+
sharedPreferences.edit().putBoolean("gcm_supported", true).commit();
91+
}
92+
catch (UnsupportedOperationException e)
93+
{
94+
sharedPreferences.edit().putBoolean("gcm_supported", false).putBoolean("gcm_enabled", false).commit();
95+
label.setText(R.string.monitoring_unsupported);
96+
}
10397
final String regId = GCMRegistrar.getRegistrationId(this);
10498
if (regId.equals("")) {
10599
GCMRegistrar.register(this, SENDER_ID);
@@ -109,30 +103,6 @@ public void enableMonitor()
109103
}
110104
}
111105

112-
public void disableMonitor()
113-
{
114-
TextView label = (TextView) findViewById(R.id.monitoring);
115-
if(!GCMRegistrar.isRegistered(this))
116-
{
117-
label.setText(R.string.monitoring_disabled);
118-
return;
119-
}
120-
GCMRegistrar.unregister(this);
121-
label.setText(R.string.updating);
122-
}
123-
124-
public void applyMonitor()
125-
{
126-
if(sharedPreferences.getBoolean("monitor", true))
127-
{
128-
enableMonitor();
129-
}
130-
else
131-
{
132-
disableMonitor();
133-
}
134-
}
135-
136106
@Override
137107
public boolean onCreateOptionsMenu(Menu menu)
138108
{
@@ -143,6 +113,9 @@ public boolean onCreateOptionsMenu(Menu menu)
143113
@Override
144114
public boolean onOptionsItemSelected(MenuItem item) {
145115
switch (item.getItemId()) {
116+
case R.id.menu_refresh:
117+
refresh();
118+
return true;
146119
case R.id.menu_settings:
147120
startActivity(new Intent(this, SettingsActivity.class));
148121
return true;

0 commit comments

Comments
 (0)