altosdroid: Only speak when GUI is running
authorKeith Packard <keithp@keithp.com>
Tue, 17 Feb 2015 05:32:54 +0000 (21:32 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 17 Feb 2015 05:32:54 +0000 (21:32 -0800)
Create voice in onStart, stop it in onStop. This way, if some other
application is in use, the voice won't be annoying you.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java

index 273688d8f553573fc4bc3ef43d200a1bd3294c57..41045f036cf00d61fcca9df035b6d3f6f27b7541 100644 (file)
@@ -352,7 +352,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
-               if (state != null)
+               if (state != null && mAltosVoice != null)
                        mAltosVoice.tell(state, from_receiver);
 
                saved_state = state;
                        mAltosVoice.tell(state, from_receiver);
 
                saved_state = state;
@@ -465,8 +465,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                mStateLayout   = (RelativeLayout) findViewById(R.id.state_container);
                mStateView     = (TextView) findViewById(R.id.state_value);
                mAgeView       = (TextView) findViewById(R.id.age_value);
                mStateLayout   = (RelativeLayout) findViewById(R.id.state_container);
                mStateView     = (TextView) findViewById(R.id.state_value);
                mAgeView       = (TextView) findViewById(R.id.age_value);
-
-               mAltosVoice = new AltosVoice(this);
        }
 
        @Override
        }
 
        @Override
@@ -484,6 +482,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
 
                doBindService();
 
 
                doBindService();
 
+               if (mAltosVoice == null)
+                       mAltosVoice = new AltosVoice(this);
        }
 
        @Override
        }
 
        @Override
@@ -504,6 +504,10 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                if(D) Log.e(TAG, "-- ON STOP --");
 
                doUnbindService();
                if(D) Log.e(TAG, "-- ON STOP --");
 
                doUnbindService();
+               if (mAltosVoice != null) {
+                       mAltosVoice.stop();
+                       mAltosVoice = null;
+               }
        }
 
        @Override
        }
 
        @Override