ok been messing around with this for a while and still no luck...
so here is the code in full (probably not great code being honest)
public class StartInActivityMonitor extends Activity implements
SensorEventListener{
/** Called when the activity is first created. */
public SensorManager mSensorManager;
public boolean k= false;
public float prevX;
public float prevY;
public float prevZ;
public Timer timer;
public SoundTimeTask ourSound;
public TTS myTts = null;
private int warning = 0;
private String sendTo;
private String Username;
public long Duration;
// String sendTo = "0833345391";
String myMessage = "Need Help!";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frame_animations_layout);
mSensorManager = (SensorManager)
getSystemService(SENSOR_SERVICE);
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor
(Sensor.TYPE_ACCELEROMETER) , SensorManager.SENSOR_DELAY_UI);
Bundle extras = getIntent().getExtras();
final String tempDuration = extras.getString("myDuration");
float myDuration = Float.parseFloat(tempDuration);
Duration = (long) (myDuration * 60 * 1000);
ourSound = new SoundTimeTask();
timer = new Timer();
timer.schedule(ourSound,Duration, Duration);
final String tempsendTo = extras.getString("telephoneNumber");
sendTo = tempsendTo;
final String tempUsername = extras.getString("Username");
Username = tempUsername;
myTts = new TTS(this, ttsInitListener, true);
myTts.speak("Creatinggggggggg", 0, null);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
Sensor mySensor = event.sensor;
if (mySensor.getType() != Sensor.TYPE_ACCELEROMETER) return;
if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER){
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
if(!k){
prevX = x;
prevY = y;
prevZ = z;
k = true;
}
float value1 = Math.abs(x) - Math.abs(prevX);
if (value1 > 0.4){
warning = 0;
ourSound.cancel();
ourSound = new SoundTimeTask();
timer.schedule(ourSound,Duration, Duration);
}
prevX = x;
prevY = y;
prevZ = z;
}
}
protected void onStop() {
mSensorManager.unregisterListener(this);
timer.cancel();
super.onStop();
}
class SoundTimeTask extends TimerTask implements Runnable{
public void run() {
switch (warning) {
case 0:
ImageView imgView =
(ImageView)findViewById(R.id.imageView);
imgView.setVisibility(View.VISIBLE);
imgView.setBackgroundResource(R.drawable.frame_animation);
AnimationDrawable frameAnimation =
(AnimationDrawable)
imgView.getBackground();
if (! frameAnimation.isRunning())
{
frameAnimation.start();
}
myTts.speak("Hello" + Username, 0, null);
break;
case 1:
myTts.speak(Username + "How are you?", 0, null);
break;
case 2:
myTts.speak("Are you ok?" + Username, 0, null);
break;
case 3:
myTts.speak("Do you require assistance" +
Username + "?", 0,
null);
break;
case 4:
myTts.speak("Hello" + Username + "please
respond and move phone",
0, null);
break;
case 5:
myTts.speak("Please respond by moving phone,
next warning will
send a SMS message", 0, null);
break;
case 6:
myTts.speak("Sending SMS message to designated
contact", 0, null);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(sendTo,null,myMessage,null,null);
break;
}
warning++;
}
}
private TTS.InitListener ttsInitListener = new TTS.InitListener() {
public void onInit(int version) {
}
};
}
On Aug 21, 9:58 am, Breese Kay <[email protected]> wrote:
> thx.I will try it.
>
> 在 2009/8/21 02:23 時, skink 寫到:
>
>
>
> > On Aug 20, 11:33 am, Kingcrowley <[email protected]> wrote:
> >> Weirdly if i press the home button, and then switch back to my app it
> >> reopens and the animation is then shown as running!
>
> >> Thanks,
>
> >> David
>
> > hi, start your animation when view is already visible (not in
> > onCreate)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---