Simplified data log manager using radio button to select and deselect different parts of the UI
This commit is contained in:
@@ -6,18 +6,25 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.v4.view.MenuCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.RadioButton;
|
||||||
import android.widget.SimpleAdapter;
|
import android.widget.SimpleAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -25,6 +32,7 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
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 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 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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
Log.v(TAG, "onCreate()");
|
Log.v(TAG, "onCreate()");
|
||||||
@@ -52,15 +65,34 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
setContentView(R.layout.activity_log_manager_control);
|
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 authBtn =
|
||||||
(Button) findViewById(R.id.auth_button);
|
(Button) findViewById(R.id.auth_button);
|
||||||
authBtn.setOnClickListener(onAuth);
|
authBtn.setOnClickListener(onAuth);
|
||||||
Button pruneBtn =
|
//Button pruneBtn =
|
||||||
(Button) findViewById(R.id.pruneDatabaseBtn);
|
// (Button) findViewById(R.id.pruneDatabaseBtn);
|
||||||
pruneBtn.setOnClickListener(onPruneBtn);
|
//pruneBtn.setOnClickListener(onPruneBtn);
|
||||||
Button reportSeizureBtn =
|
//Button reportSeizureBtn =
|
||||||
(Button) findViewById(R.id.reportSeizureBtn);
|
// (Button) findViewById(R.id.reportSeizureBtn);
|
||||||
reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
|
//reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
|
||||||
Button remoteDbBtn =
|
Button remoteDbBtn =
|
||||||
(Button) findViewById(R.id.refresh_button);
|
(Button) findViewById(R.id.refresh_button);
|
||||||
remoteDbBtn.setOnClickListener(onRefreshBtn);
|
remoteDbBtn.setOnClickListener(onRefreshBtn);
|
||||||
@@ -72,6 +104,18 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
lv.setOnItemClickListener(onRemoteEventListClick);
|
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
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
Log.v(TAG, "onStart()");
|
Log.v(TAG, "onStart()");
|
||||||
@@ -254,6 +298,79 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
} //updateUi();
|
} //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 =
|
View.OnClickListener onAuth =
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
|
|||||||
@@ -49,23 +49,53 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="000" />
|
android:text="000" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<!--
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/pruneDatabaseBtn"
|
android:id="@+id/pruneDatabaseBtn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Prune Database" />
|
android:text="@string/prune_database" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/reportSeizureBtn"
|
android:id="@+id/reportSeizureBtn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Report Seizure" />
|
android:text="@string/report_seizure" />
|
||||||
</LinearLayout>
|
</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
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
@@ -73,12 +103,19 @@
|
|||||||
android:text="@string/EventsInLocalDb"
|
android:text="@string/EventsInLocalDb"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/eventLogListView"
|
android:id="@+id/eventLogListView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="150dp"
|
android:layout_height="150dp"
|
||||||
android:layout_marginTop="10dp" />
|
android:layout_marginTop="10dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:visibility="visible"
|
||||||
|
android:id="@+id/shared_data_ll"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
@@ -115,8 +152,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/refreshBtn" />
|
android:text="@string/refreshBtn" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
26
app/src/main/res/menu/log_manager_activity_menu.xml
Normal file
26
app/src/main/res/menu/log_manager_activity_menu.xml
Normal 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>
|
||||||
@@ -294,7 +294,7 @@
|
|||||||
<string name="title_activity_authenticate">Log in to OpenSeizureDetector Data Sharing</string>
|
<string name="title_activity_authenticate">Log in to OpenSeizureDetector Data Sharing</string>
|
||||||
<string name="logout">Log Out</string>
|
<string name="logout">Log Out</string>
|
||||||
<string name="logged_in_with_token">Logged in with Token</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="remote_database">Shared Data</string>
|
||||||
<string name="num_local_events">Number of Events Stored on Phone: </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>
|
<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="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_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="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>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user