]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
About: overhaul
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 22 Sep 2019 13:39:12 +0000 (14:39 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 22 Sep 2019 14:35:53 +0000 (15:35 +0100)
Fixes https://github.com/cmukgb/ctfws-timer-android/issues/15
See also https://github.com/cmukgb/ctfws-timer-android/issues/17

mobile/src/main/java/com/acmetensortoys/ctfwstimer/AboutActivity.java
mobile/src/main/res/layout-land/activity_about.xml
mobile/src/main/res/layout/activity_about.xml
mobile/src/main/res/menu/aboutmenu.xml [new file with mode: 0644]
mobile/src/main/res/values/strings.xml

index 2d01944a55ff5a90f230b06bd822c6ccbdbc6a7e..369219aa16d9bc8c4fde381326900340a3dfb327 100644 (file)
 package com.acmetensortoys.ctfwstimer;
 
 import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
+import android.content.Context;
 import android.content.Intent;
+import android.content.ServiceConnection;
 import android.net.Uri;
+import android.os.Build;
+import android.os.IBinder;
+import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
 import android.view.View;
 import android.webkit.WebView;
+import android.widget.Chronometer;
 import android.widget.TabHost;
+import android.widget.TextView;
+
+import com.acmetensortoys.ctfwstimer.lib.CtFwSGameStateManager;
+
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.SortedSet;
 
 public class AboutActivity extends AppCompatActivity {
 
+    private static final String TAG = "About";
+    private MainService.LocalBinder mSrvBinder;
+    private CtFwSDisplayTinyChrono mTitleChronoObs;
+
+    private static final String TAB_PROG  = "TabProg";
+    private static final String TAB_LIC   = "TabLic";
+    private static final String TAB_DEBUG = "TabDebug";
+
+    private CheckedAsyncDownloader.DL lastDL;
+
+    private TextView mTvDebug;
+
+    private void makeDebugText() {
+        final StringBuffer sb = new StringBuffer("");
+
+        sb.append("Android host version: ");
+        sb.append(Build.VERSION.RELEASE);
+        sb.append(" (SDK ");
+        sb.append(Build.VERSION.SDK_INT);
+        sb.append(")\n");
+
+        sb.append("Source git description: ");
+        sb.append(BuildConfig.gitDescription);
+        sb.append("\n");
+
+        sb.append("\n");
+
+        {
+            if (lastDL != null) {
+                sb.append("Last fetched handbook:\n  result: ");
+                sb.append(lastDL.result);
+                sb.append("\n  checksum: ");
+                for (byte b : Arrays.copyOfRange(lastDL.sha256, 0, 16)) {
+                    sb.append(String.format(Locale.ROOT, "%02x", b));
+                }
+                sb.append("...\n");
+            } else {
+                sb.append("No handbook download attempted.\n");
+            }
+        }
+
+        if (mSrvBinder != null) {
+            CtFwSGameStateManager cgs = mSrvBinder.getGameState();
+
+            sb.append("\nLast game configuration:\n  raw:       ");
+            sb.append(cgs.getLastConfigMessage());
+            sb.append("\n  parsed: ");
+            sb.append(cgs.toMqttConfigMessage());
+            sb.append("\n");
+        } else {
+            sb.append("Null service binder\n");
+        }
+
+        mTvDebug.post(new Runnable() {
+            @Override
+            public void run() {
+                mTvDebug.setText(sb);
+            }
+        });
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_about);
 
+        mTvDebug = (TextView) findViewById(R.id.about_debug_tv);
+        makeDebugText();
+
+        ActionBar ab = getSupportActionBar();
+        if (ab != null) {
+            ab.setTitle(R.string.about_title);
+        }
+
         View iv = findViewById(R.id.about_image);
         iv.setOnClickListener(new View.OnClickListener() {
             @Override
@@ -43,12 +128,131 @@ public class AboutActivity extends AppCompatActivity {
         TabHost th = (TabHost) findViewById(R.id.about_tab_host);
         th.setup();
 
-        th.addTab(th.newTabSpec("TagProg")
+        th.addTab(th.newTabSpec(TAB_PROG)
                 .setContent(R.id.about_tab_program)
-                .setIndicator("Program"));
+                .setIndicator(getResources().getString(R.string.about_tab_program)));
 
-        th.addTab(th.newTabSpec("TagLic")
+        th.addTab(th.newTabSpec(TAB_LIC)
                 .setContent(R.id.about_tab_lic)
-                .setIndicator("Licenses"));
+                .setIndicator(getResources().getString(R.string.about_tab_license)));
+
+        th.addTab(th.newTabSpec(TAB_DEBUG)
+                .setContent(R.id.about_tab_debug)
+                .setIndicator(getResources().getString(R.string.about_tab_debug)));
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.aboutmenu, menu);
+
+        Chronometer ch = (Chronometer) menu.findItem(R.id.about_menu_crono).getActionView();
+        mTitleChronoObs = new CtFwSDisplayTinyChrono(getResources(), ch);
+        if (mSrvBinder != null) {
+            doRegisterObservers();
+        }
+
+        return true;
+    }
+
+    private MainService.Observer mSrvObs = new MainService.Observer() {
+        @Override
+        public void onMqttServerChanged(MainService.LocalBinder b, String sURL) {
+
+        }
+
+        @Override
+        public void onMqttServerEvent(MainService.LocalBinder b, MainService.MqttServerEvent mse) {
+
+        }
+
+        @Override
+        public void onHandbookFetch(MainService.LocalBinder b, CheckedAsyncDownloader.DL dl) {
+            lastDL = dl;
+            makeDebugText();
+        }
+    };
+
+    private CtFwSGameStateManager.Observer mCtFwSObs = new CtFwSGameStateManager.Observer() {
+        @Override
+        public void onCtFwSConfigure(CtFwSGameStateManager game) {
+            makeDebugText();
+        }
+
+        @Override
+        public void onCtFwSNow(CtFwSGameStateManager game, CtFwSGameStateManager.Now now) {
+
+        }
+
+        @Override
+        public void onCtFwSFlags(CtFwSGameStateManager game) {
+
+        }
+
+        @Override
+        public void onCtFwSMessage(CtFwSGameStateManager game, SortedSet<CtFwSGameStateManager.Msg> msgs) {
+
+        }
+    };
+
+    private void doRegisterObservers() {
+        mSrvBinder.registerObserver(mSrvObs);
+        mSrvBinder.getGameState().registerObserver(mCtFwSObs);
+        if (mTitleChronoObs != null) {
+            mSrvBinder.getGameState().registerObserver(mTitleChronoObs);
+        }
+    }
+
+    private final ServiceConnection ctfwssc = new ServiceConnection() {
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            mSrvBinder = (MainService.LocalBinder) service;
+            doRegisterObservers();
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+            mSrvBinder = null;
+        }
+    };
+
+    @Override
+    public void onStart() {
+        Log.d(TAG, "onStart");
+        super.onStart();
+
+        if (mSrvBinder == null) {
+            Intent si = new Intent(this, MainService.class);
+            bindService(si, ctfwssc, Context.BIND_AUTO_CREATE | Context.BIND_ABOVE_CLIENT);
+        }
+    }
+
+    @Override
+    public void onResume() {
+        Log.d(TAG, "onResume");
+        super.onResume();
+
+        if (mSrvBinder != null) {
+            doRegisterObservers();
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        Log.d(TAG, "onPause");
+        if (mSrvBinder != null) {
+            mSrvBinder.getGameState().unregisterObserver(mTitleChronoObs);
+            mSrvBinder.getGameState().unregisterObserver(mCtFwSObs);
+            mSrvBinder.unregisterObserver(mSrvObs);
+        }
+
+        super.onPause();
+    }
+
+    @Override
+    protected void onDestroy() {
+        Log.d(TAG, "onDestroy");
+        unbindService(ctfwssc);
+
+        super.onDestroy();
     }
 }
index ba3ed2bddfda1d10b2966a009f6e91c879c2d240..7f409c09cb39b4765e24941ddd711182217e35ac 100644 (file)
                         android:id="@+id/about_licenses" />
                 </LinearLayout>
 
+                <LinearLayout
+                    android:id="@+id/about_tab_debug"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:orientation="vertical">
+
+                    <TextView
+                        android:id="@+id/about_debug_tv"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"/>
+
+                </LinearLayout>
+
             </FrameLayout>
         </LinearLayout>
     </TabHost>
index 2d2777d3a09dac9991bced2d52ebbdc124b0f6f1..3ae3d29ab854e64af5652b7e540624a03f78110f 100644 (file)
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:id="@+id/about_licenses" />
+
+                </LinearLayout>
+
+                <LinearLayout
+                    android:id="@+id/about_tab_debug"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:orientation="vertical">
+
+                    <TextView
+                        android:id="@+id/about_debug_tv"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"/>
+
                 </LinearLayout>
 
             </FrameLayout>
diff --git a/mobile/src/main/res/menu/aboutmenu.xml b/mobile/src/main/res/menu/aboutmenu.xml
new file mode 100644 (file)
index 0000000..aba983f
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <item
+        android:id="@+id/about_menu_crono"
+        android:title="@string/ctfws_chrono_menutext"
+        app:actionViewClass="android.widget.Chronometer"
+        app:showAsAction="always" />
+
+</menu>
\ No newline at end of file
index 7016d51a6bf51ebfe018fe9f6762b49e384e99ed..8311f623163ff63b838ca2a48feb2c6c08d257a1 100644 (file)
     <string name="wait_long">Stun 60</string>
     <string name="wait_short">Stun 10</string>
 
+    <string name="about_title">CtFwS Timer Info</string>
+    <string name="about_tab_program">Program</string>
+    <string name="about_tab_license">License</string>
+    <string name="about_tab_debug">Debug</string>
     <string name="about_imagealt">The CMUKGB Shield Logo</string>
     <string name="about_text"><![CDATA[
         <center>