Added system logging to MainActivity and PrefActivity

This commit is contained in:
Graham Jones
2016-07-25 22:24:26 +01:00
parent c0d4fb3a2c
commit ef0616a143
2 changed files with 20 additions and 3 deletions

View File

@@ -98,6 +98,9 @@ public class MainActivity extends Activity {
//int i = 5/0; // Force exception to test handler. //int i = 5/0; // Force exception to test handler.
mUtil = new OsdUtil(this,serverStatusHandler); mUtil = new OsdUtil(this,serverStatusHandler);
mConnection = new SdServiceConnection(this); mConnection = new SdServiceConnection(this);
mUtil.writeToSysLogFile("");
mUtil.writeToSysLogFile("* MainActivity Started *");
mUtil.writeToSysLogFile("MainActivity.onCreate()");
// Initialise the User Interface // Initialise the User Interface
setContentView(R.layout.main); setContentView(R.layout.main);
@@ -257,6 +260,7 @@ public class MainActivity extends Activity {
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
mUtil.writeToSysLogFile("MainActivity.onStart()");
SharedPreferences SP = PreferenceManager SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
boolean audibleAlarm = SP.getBoolean("AudibleAlarm", true); boolean audibleAlarm = SP.getBoolean("AudibleAlarm", true);
@@ -267,18 +271,21 @@ public class MainActivity extends Activity {
String versionName = mUtil.getAppVersionName(); String versionName = mUtil.getAppVersionName();
tv.setText("OpenSeizureDetector Server Version " + versionName); tv.setText("OpenSeizureDetector Server Version " + versionName);
mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server");
mUtil.bindToServer(this, mConnection); mUtil.bindToServer(this, mConnection);
} }
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
mUtil.writeToSysLogFile("MainActivity.onStop()");
mUtil.unbindFromServer(this, mConnection); mUtil.unbindFromServer(this, mConnection);
} }
private void startServer() { private void startServer() {
mUtil.writeToSysLogFile("MainActivity.startServer()");
Log.v(TAG, "starting Server...");
mUtil.startServer(); mUtil.startServer();
// Change the action bar icon to show the option to stop the service. // Change the action bar icon to show the option to stop the service.
if (mOptionsMenu != null) { if (mOptionsMenu != null) {
@@ -292,6 +299,7 @@ public class MainActivity extends Activity {
} }
private void stopServer() { private void stopServer() {
mUtil.writeToSysLogFile("MainActivity.stopServer()");
Log.v(TAG, "stopping Server..."); Log.v(TAG, "stopping Server...");
mUtil.stopServer(); mUtil.stopServer();
// Change the action bar icon to show the option to start the service. // Change the action bar icon to show the option to start the service.
@@ -611,15 +619,18 @@ public class MainActivity extends Activity {
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
mUtil.writeToSysLogFile("MainActivity.onPause()");
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
mUtil.writeToSysLogFile("MainActivity.onResume()");
} }
private void showAbout() { private void showAbout() {
mUtil.writeToSysLogFile("MainActivity.showAbout()");
View aboutView = getLayoutInflater().inflate(R.layout.about_layout, null, false); View aboutView = getLayoutInflater().inflate(R.layout.about_layout, null, false);
String versionName = mUtil.getAppVersionName(); String versionName = mUtil.getAppVersionName();
Log.v(TAG, "showAbout() - version name = " + versionName); Log.v(TAG, "showAbout() - version name = " + versionName);
@@ -631,11 +642,11 @@ public class MainActivity extends Activity {
builder.show(); builder.show();
} }
class ResponseHandler extends Handler { static class ResponseHandler extends Handler {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
Log.v(TAG, "Message=" + message.toString()); Log.v(TAG, "Message=" + message.toString());
} }
} }
} }

View File

@@ -57,6 +57,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
mContext = getApplicationContext(); mContext = getApplicationContext();
mUtil = new OsdUtil(mContext,mHandler); mUtil = new OsdUtil(mContext,mHandler);
mUtil.writeToSysLogFile("PrefActvity.onCreate()");
} }
/** /**
@@ -108,6 +109,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
mUtil.writeToSysLogFile("PrefActvity.onStart()");
invalidateHeaders(); invalidateHeaders();
Log.v(TAG, "onStart()"); Log.v(TAG, "onStart()");
} }
@@ -123,6 +125,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mUtil.writeToSysLogFile("PrefActvity.onResume()");
Log.v(TAG, "onResume()"); Log.v(TAG, "onResume()");
SharedPreferences SP = PreferenceManager SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
@@ -132,6 +135,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
mUtil.writeToSysLogFile("PrefActvity.onPause()");
SharedPreferences SP = PreferenceManager SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
SP.unregisterOnSharedPreferenceChangeListener(this); SP.unregisterOnSharedPreferenceChangeListener(this);
@@ -140,8 +144,10 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
mUtil.writeToSysLogFile("PrefActvity.onDestroy()");
Log.v(TAG, "onDestroy. mPrefChanged=" + mPrefChanged); Log.v(TAG, "onDestroy. mPrefChanged=" + mPrefChanged);
if (mPrefChanged) { if (mPrefChanged) {
mUtil.writeToSysLogFile("PrefActvity.onDestroy() - settings changed - re-starting....");
mUtil.showToast("Settings Changed - re-starting OpenSeizureDetector...."); mUtil.showToast("Settings Changed - re-starting OpenSeizureDetector....");
Intent intent = new Intent(getApplicationContext(), StartupActivity.class); Intent intent = new Intent(getApplicationContext(), StartupActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);