Skip to content

Commit

Permalink
Handbook: overhaul
Browse files Browse the repository at this point in the history
Fixes #12
Fixes #17
  • Loading branch information
nwf committed Sep 22, 2019
1 parent ab06d49 commit abb520a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 27 deletions.
7 changes: 7 additions & 0 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@
android:exported="false" />

<activity android:name=".HandbookActivity"
android:icon="@mipmap/ic_shield_1"
android:label="@string/app_name_hand">
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,27 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.AssetManager;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.net.Uri;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.SearchView;
import android.widget.Toast;

import org.eclipse.paho.client.mqttv3.IMqttMessageListener;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class HandbookActivity extends AppCompatActivity {

public static final String HAND_FILE_NAME = "handbook.html";
private static final String TAG = "CtFwSHandbook";

private CtFwSDisplayTinyChrono mTitleChronoObs;
private WebView mWV;

private void display() {
Expand Down Expand Up @@ -79,11 +62,19 @@ public void onHandbookFetch(MainService.LocalBinder b, CheckedAsyncDownloader.DL
};

private MainService.LocalBinder mSrvBinder;

private void doRegisterObservers() {
mSrvBinder.registerObserver(mSrvObs);
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;
mSrvBinder.registerObserver(mSrvObs);
doRegisterObservers();
mSrvBinder.connect(false);
}

Expand All @@ -99,14 +90,82 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_handbook);

ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setTitle(R.string.app_name_hand_title);
}

mWV = findViewById(R.id.hand_wv);

WebSettings wvs = mWV.getSettings();
wvs.setBuiltInZoomControls(true);
wvs.setDisplayZoomControls(false);

// mWV.setFindListener()

display();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.d(TAG, "onCreateOptionsMenu");
getMenuInflater().inflate(R.menu.handmenu, menu);

Chronometer ch = (Chronometer) menu.findItem(R.id.hand_menu_crono).getActionView();
mTitleChronoObs = new CtFwSDisplayTinyChrono(getResources(), ch);

if (mSrvBinder != null) {
doRegisterObservers();
}

SearchView sv = (SearchView) menu.findItem(R.id.hand_menu_search).getActionView();
sv.setQueryHint("Search handbook...");
sv.setSubmitButtonEnabled(true);

/*
sv.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "sv.OClickL");
}
});
sv.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
Log.d(TAG, "sv.OCloseL");
return false;
}
});
*/

sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mWV.findNext(true);
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
mWV.findAllAsync(newText);
return false;
}
});

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.hand_menu_search:
return true;
}

return false;
}

@Override
public void onStart() {
Log.d(TAG, "onStart");
Expand All @@ -124,14 +183,15 @@ public void onResume() {
super.onResume();

if (mSrvBinder != null) {
mSrvBinder.registerObserver(mSrvObs);
doRegisterObservers();
}
}

@Override
protected void onPause() {
Log.d(TAG, "onPause");
if (mSrvBinder != null) {
mSrvBinder.getGameState().unregisterObserver(mTitleChronoObs);
mSrvBinder.unregisterObserver(mSrvObs);
}

Expand Down
3 changes: 2 additions & 1 deletion mobile/src/main/res/layout/activity_handbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">

<WebView
android:id="@+id/hand_wv"
Expand Down
18 changes: 18 additions & 0 deletions mobile/src/main/res/menu/handmenu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/hand_menu_crono"
android:title="@string/ctfws_chrono_menutext"
app:actionViewClass="android.widget.Chronometer"
app:showAsAction="always" />

<item
android:id="@+id/hand_menu_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/menutext_search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />

</menu>
4 changes: 3 additions & 1 deletion mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<string name="server_default">tcp://ctfws-mqtt.cmukgb.org:1883</string>

<string name="app_name">CMUKGB CtFwS Timer</string>
<string name="app_name_hand">CMUKGB CtFwS Handbook</string>
<string name="app_name_hand">CtFwS Handbook</string>
<string name="app_name_hand_title">Handbook</string>

<string name="ctfws_gameend">Game\nEnd</string>
<string name="ctfws_gamestart">Game\nStart</string>
Expand Down Expand Up @@ -51,6 +52,7 @@
<string name="menutext_prf">Settings</string>
<string name="menutext_quit">Quit</string>
<string name="menutext_reconn">Reconnect</string>
<string name="menutext_search">Search</string>

<string name="mqtt_uri_label">Server URI:</string>
<string name="mqtt_state_label">Server State:</string>
Expand Down

0 comments on commit abb520a

Please sign in to comment.