Simplified data log manager using radio button to select and deselect different parts of the UI

This commit is contained in:
Graham Jones
2022-02-05 22:31:28 +00:00
parent 4fb83d04c9
commit b53e646cb5
4 changed files with 243 additions and 62 deletions

View File

@@ -6,18 +6,25 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.IBinder;
import android.support.v4.view.MenuCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.SimpleAdapter;
import android.widget.TextView;
@@ -25,6 +32,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -42,6 +50,11 @@ public class LogManagerControlActivity extends AppCompatActivity {
private Integer mUiTimerPeriodFast = 2000; // 2 seconds - we use fast updating while UI is blank and we are waiting for first data
private Integer mUiTimerPeriodSlow = 60000; // 60 seconds - once data has been received and UI populated we only update once per minute.
private Integer UI_MODE_LOCAL = 0;
private Integer UI_MODE_SHARED = 1;
private Integer mUiMode = UI_MODE_SHARED;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(TAG, "onCreate()");
@@ -52,15 +65,34 @@ public class LogManagerControlActivity extends AppCompatActivity {
setContentView(R.layout.activity_log_manager_control);
/* Force display of overflow menu - from stackoverflow
* "how to force use of..."
*/
try {
Log.v(TAG, "trying menubar fiddle...");
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField =
ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
Log.v(TAG, "menuKeyField is not null - configuring....");
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
} else {
Log.v(TAG, "menuKeyField is null - doing nothing...");
}
} catch (Exception e) {
Log.v(TAG, "menubar fiddle exception: " + e.toString());
}
Button authBtn =
(Button) findViewById(R.id.auth_button);
authBtn.setOnClickListener(onAuth);
Button pruneBtn =
(Button) findViewById(R.id.pruneDatabaseBtn);
pruneBtn.setOnClickListener(onPruneBtn);
Button reportSeizureBtn =
(Button) findViewById(R.id.reportSeizureBtn);
reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
//Button pruneBtn =
// (Button) findViewById(R.id.pruneDatabaseBtn);
//pruneBtn.setOnClickListener(onPruneBtn);
//Button reportSeizureBtn =
// (Button) findViewById(R.id.reportSeizureBtn);
//reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
Button remoteDbBtn =
(Button) findViewById(R.id.refresh_button);
remoteDbBtn.setOnClickListener(onRefreshBtn);
@@ -72,6 +104,18 @@ public class LogManagerControlActivity extends AppCompatActivity {
lv.setOnItemClickListener(onRemoteEventListClick);
}
/**
* Create Action Bar
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(TAG, "onCreateOptionsMenu()");
getMenuInflater().inflate(R.menu.log_manager_activity_menu, menu);
MenuCompat.setGroupDividerEnabled(menu, true);
return true;
}
@Override
protected void onStart() {
Log.v(TAG, "onStart()");
@@ -254,6 +298,79 @@ public class LogManagerControlActivity extends AppCompatActivity {
}
} //updateUi();
public void onRadioButtonClicked(View view) {
LinearLayout localDataLl = (LinearLayout) findViewById(R.id.local_data_ll);;
LinearLayout sharedDataLl = (LinearLayout) findViewById(R.id.shared_data_ll);;;
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.local_data_rb:
if (checked) {
// Switch to the local data view
localDataLl.setVisibility(View.VISIBLE);
sharedDataLl.setVisibility(View.GONE);
}
break;
case R.id.shared_data_rb:
if (checked) {
// Switch to the local data view
localDataLl.setVisibility(View.GONE);
sharedDataLl.setVisibility(View.VISIBLE);
}
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "onOptionsItemSelected() : " + item.getItemId() + " selected");
switch (item.getItemId()) {
case R.id.action_authenticate_api:
Log.i(TAG, "action_autheticate_api");
try {
Intent i = new Intent(
getApplicationContext(),
AuthenticateActivity.class);
this.startActivity(i);
} catch (Exception ex) {
Log.i(TAG, "exception starting export activity " + ex.toString());
}
return true;
case R.id.pruneDatabaseMenuItem:
Log.i(TAG, "action_pruneDatabase");
onPruneBtn.onClick(null);
return true;
case R.id.action_report_seizure:
Log.i(TAG, "action_report_seizure");
try {
Intent intent = new Intent(
getApplicationContext(),
ReportSeizureActivity.class);
this.startActivity(intent);
} catch (Exception ex) {
Log.i(TAG, "exception starting Report Seizure activity " + ex.toString());
}
return true;
case R.id.action_settings:
Log.i(TAG, "action_settings");
try {
Intent prefsIntent = new Intent(
getApplicationContext(),
PrefActivity.class);
this.startActivity(prefsIntent);
} catch (Exception ex) {
Log.i(TAG, "exception starting settings activity " + ex.toString());
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
View.OnClickListener onAuth =
new View.OnClickListener() {

View File

@@ -49,74 +49,109 @@
android:layout_height="wrap_content"
android:text="000" />
</LinearLayout>
<!--
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/pruneDatabaseBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prune Database" />
<Button
android:id="@+id/reportSeizureBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report Seizure" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/EventsInLocalDb"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/eventLogListView"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remote_database"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/remoteEventsLv"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/authStatusTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/not_authenticated" />
<Button
android:id="@+id/auth_button"
android:id="@+id/pruneDatabaseBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/authenticate" />
android:text="@string/prune_database" />
<Button
android:id="@+id/reportSeizureBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/report_seizure" />
</LinearLayout>
-->
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/shared_data_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="onRadioButtonClicked"
android:text="@string/shared_data" />
<RadioButton
android:id="@+id/local_data_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="@string/local_data" />
</RadioGroup>
<LinearLayout
android:visibility="gone"
android:id="@+id/local_data_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/EventsInLocalDb"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/eventLogListView"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_marginTop="10dp" />
</LinearLayout>
<Button
android:id="@+id/refresh_button"
android:layout_width="wrap_content"
<LinearLayout
android:visibility="visible"
android:id="@+id/shared_data_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/refreshBtn" />
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remote_database"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/remoteEventsLv"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/authStatusTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/not_authenticated" />
<Button
android:id="@+id/auth_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/authenticate" />
</LinearLayout>
<Button
android:id="@+id/refresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/refreshBtn" />
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,26 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/grp1">
<item
android:id="@+id/pruneDatabaseMenuItem"
android:showAsAction="never|withText"
android:title="@string/prune_database" />
</group>
<group android:id="@+id/grp3">
<item
android:id="@+id/action_report_seizure"
android:enabled="true"
android:icon="@drawable/ic_action_settings"
android:showAsAction="never|withText"
android:title="@string/report_seizure" />
<item
android:id="@+id/action_authenticate_api"
android:enabled="true"
android:icon="@drawable/ic_action_settings"
android:showAsAction="never|withText"
android:title="@string/data_sharing_log_in" />
</group>
</menu>

View File

@@ -294,7 +294,7 @@
<string name="title_activity_authenticate">Log in to OpenSeizureDetector Data Sharing</string>
<string name="logout">Log Out</string>
<string name="logged_in_with_token">Logged in with Token</string>
<string name="local_database">Data on Phone</string>
<string name="local_database">Logged Data Manager</string>
<string name="remote_database">Shared Data</string>
<string name="num_local_events">Number of Events Stored on Phone: </string>
<string name="num_local_datapoints">"Number of Datapoints Stored on Phone: "</string>
@@ -343,4 +343,7 @@
<string name="error_connecting_to_server">Error Connecting to Server</string>
<string name="battery_usage_optimisation_dialog_title">WARNING: Battery Usage Optimisation</string>
<string name="battery_usage_optimisation_dialog_text">WARNING: The Android System Battery Optimisation Settings are configured to \'Optimise\' OpenSeizureDetector. This means it is likely to be shutdown when operating on battery power, so will not work correctly\n\nPlease go into the Phone Settings and search for \'Optimise Battery Usage\' and ensure that OpenSeizureDetector is NOT optimised</string>
<string name="local_data">Local Data</string>
<string name="shared_data">Shared Data</string>
<string name="prune_database">Prune Database</string>
</resources>