<service android:name="org.eclipse.paho.android.service.MqttService" />
<activity android:name=".AboutActivity" />
+ <activity android:name=".SettingsActivity" />
<service
android:name=".MainService"
}
// TODO should we be using onClick instead for routing?
+ // Cam: According to official documentation, this is the preferred way to into menus, so
+ // we're (overall) fine.
@Override
public boolean onOptionsItemSelected(MenuItem mi) {
switch(mi.getItemId()) {
+ case R.id.menu_prf :
+ startActivity(new Intent(this, SettingsActivity.class));
+ return true;
+ case R.id.menu_about :
+ startActivity(new Intent(this, AboutActivity.class));
+ return true;
+ // Cam: Changing this doesn't appear to do anything? Leaving just in case.
case R.id.menu_mqtt :
DialogFragment d =
StringSettingDialogFragment.newInstance(
R.layout.server_dialog, R.id.server_text, "server", defserver);
d.show(getSupportFragmentManager(),"serverdialog");
return true;
- case R.id.menu_about :
- startActivity(new Intent(this, AboutActivity.class));
- return true;
default:
return super.onOptionsItemSelected(mi);
}
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
+import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
@Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.d("CtFwS", "Conn OK 1");
-
IMqttAsyncClient c = asyncActionToken.getClient();
if (c.equals(mMqc)) {
setMSE(MqttServerEvent.MSE_CONN);
// User-facing notification
// TODO Move to its own display module?
+
+ // The pattern for notification vibration patterns. Maybe we could have multiple for different
+ // events, like flags/jailbreaks?
+ private long[] VIBRATE_PATTERN = {0, 300, 200, 300};
+
+ private void vibrate(long[] pattern) {
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+ // Cam: default value is "false" because we really don't want to be vibrating if we
+ // accidentally lose our preferences somehow
+ if (sp.getBoolean("prf_vibr", false)) {
+ Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
+ v.vibrate(VIBRATE_PATTERN,-1);
+ }
+ else {
+ Log.d("vibrate", "off");
+ }
+ }
+
private ServiceConnection userNoteSC;
private void ensureNotification() {
synchronized(this) {
}
};
}
+ // Cam: Do we need this?
bindService(new Intent(MainService.this, MainService.class), userNoteSC,
Context.BIND_AUTO_CREATE);
startForeground(NOTE_ID_USER, userNoteBuilder.build());
}
private NotificationCompat.Builder userNoteBuilder;
+ // TODO (Cam): It'd be cool if we could make the notification say "you got a flag" or something
+ // for a few seconds after we get messages
private CtFwSGameState.Observer mCgsObserver = new CtFwSGameState.Observer() {
@Override
public void onCtFwSConfigure(CtFwSGameState game) { }
userNoteBuilder.setWhen((now.roundEnd+1)*1000);
userNoteBuilder.setUsesChronometer(true);
if (now.rationale == null || !now.stop) {
+ vibrate(VIBRATE_PATTERN);
// game is afoot!
userNoteBuilder.setContentTitle(
now.rationale == null ? "Game is afoot!" : now.rationale);
@Override
public void onCtFwSFlags(CtFwSGameState game) { }
+ // Cam: Are we just explicitly no-op'ing this, or should we actually display messages?
@Override
public void onCtFwSMessage(CtFwSGameState game, List<CtFwSGameState.Msg> msgs) { }
};
--- /dev/null
+package com.acmetensortoys.ctfwstimer;\r
+\r
+import android.preference.PreferenceActivity;\r
+import android.preference.PreferenceFragment;\r
+import android.os.Bundle;\r
+\r
+// TODO (Cam): changing the server doesn't actually work yet\r
+public class SettingsActivity extends PreferenceActivity {\r
+ @Override\r
+ protected void onCreate(Bundle savedInstanceState) {\r
+ super.onCreate(savedInstanceState);\r
+ getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();\r
+ }\r
+\r
+ public static class SettingsFragment extends PreferenceFragment {\r
+ @Override\r
+ public void onCreate(final Bundle savedInstanceBundle) {\r
+ super.onCreate(savedInstanceBundle);\r
+ addPreferencesFromResource(R.xml.preferences);\r
+ }\r
+ }\r
+}\r
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:visible="true"
+ android:enabled="true"
+ android:title="@string/menutext_prf"
+ android:id="@+id/menu_prf"
+ android:icon="@android:drawable/ic_menu_manage"
+ android:checkable="false"/>
<item
android:visible="true"
android:enabled="true"
<string name="menutext_about">About</string>
<string name="menutext_mqtt">Set MQTT Server</string>
<string name="menutext_mqtt_label">Server URI:</string>
+ <string name="menutext_prf">Settings</string>
<string name="mqtt_header">Connection Metadata:</string>
<string name="mqtt_state_label">Server State:</string>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">\r
+\r
+ <EditTextPreference\r
+ android:selectAllOnFocus="true"\r
+ android:singleLine="true"\r
+ android:key="prf_mqtt_uri"\r
+ android:defaultValue="tcp://ctfws-mqtt.ietfng.org:1883"\r
+ android:title="Change MQTT Server" />\r
+ <CheckBoxPreference\r
+ android:defaultValue="true"\r
+ android:title="Vibrate?"\r
+ android:key="prf_vibr" />\r
+</PreferenceScreen>
\ No newline at end of file