[android-beginners] Re: Simple Animation Code
ok...i have got a simple animation working in this.. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.frame_animations_layout); imgView = (ImageView)findViewById(R.id.imageView); imgView.setBackgroundResource(R.drawable.frame_animation); in onCreate i have the above.. then later i have frameAnimation = (AnimationDrawable) imgView.getBackground(); frameAnimation.start(); which shows the animation! but..there always is a but i want to show maybe 5-6 animations..depending on events..how would i go about doing this? i have tried changing the imgView.setBackgroundResource(R.drawable.frame_animation1); in my code at a later stage but it doesn't change the resource for me, is this even possible? Thanks, David --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Simple Animation Code
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(Creating, 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;
[android-beginners] Re: Simple Animation Code
On Aug 20, 11:33 am, Kingcrowley kingcrow...@gmail.com 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 android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Simple Animation Code
Maybe i didn't explain it well enough.. The main.xml file is used already, so frame_animations_layout.xml is the layout for this, see below *** ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/ android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent ImageView android:id=@+id/imageView android:layout_width=fill_parent android:layout_height=wrap_content / /LinearLayout the imgview is not set up in onCreate but later on, David * On Aug 21, 9:47 am, skink psk...@gmail.com wrote: On Aug 20, 11:33 am, Kingcrowley kingcrow...@gmail.com 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 android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Simple Animation Code
Kingcrowley wrote: the imgview is not set up in onCreate but later on, hmm, so you setVisibke(View.VISIBLE) and start() your animation on some external event, right? did you try to start() your animation in post's Runnable? post(new Runnable() {...}) pskink --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Simple Animation Code
thx.I will try it. 在 2009/8/21 02:23 時, skink 寫到: On Aug 20, 11:33 am, Kingcrowley kingcrow...@gmail.com 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 android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Simple Animation Code
Hi,In Oncreate method set the setContentView with main.xml file and use imageVeiw id which is defined in the main.xml in u r .java file. public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); // set its background to our AnimationDrawable XML resource. ImageView img = (ImageView)findViewById(R.id.simple_anim); img.setBackgroundResource(R.anim.simple_animation); -- Thank You, Pruthvi Raj G.R On Thu, Aug 20, 2009 at 3:03 PM, Kingcrowley kingcrow...@gmail.com wrote: I am just gonna put in snippets of the code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.frame_animations_layout); (sets View) *** case 0: ImageView imgView = (ImageView)findViewById(R.id.imageView); imgView.setVisibility(ImageView.VISIBLE); imgView.setBackgroundResource(R.drawable.frame_animation); AnimationDrawable frameAnimation = (AnimationDrawable) imgView.getBackground(); if (! frameAnimation.isRunning()) { frameAnimation.start(); } break; * should start animation. The code logically is fine, as in it does get to this code but the animation never appears on sceen. Weirdly if i press the home button, and then switch back to my app it reopens and the animation is then shown as running! Is there a way to bring it to the foreground? or to give it focus easily? Thanks, David --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---