"Frame" animation..xml image animation

All your problems with Audio, Video and Images.

"Frame" animation..xml image animation

Postby kingcrowley » Tue Sep 01, 2009 9:03 pm

The animation does not show when it should!..have tried it in a much simpler program and the frame animation works.....weirdly when i press the home button and then when i long press the home button and go back to this app..i can see the animation then! could be me being stupid..or something silly...any ideas?

This code uses these two xml files

*frame_animation_layoout
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. frame_animation (in drawable with the jpgs for the frames..)
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.         android:orientation="vertical" android:layout_width="fill_parent"
  5.         android:layout_height="fill_parent" >
  6.  
  7.         <ImageView android:id="@+id/imageView" android:layout_width="fill_parent"
  8.                 android:layout_height="wrap_content" android:background = "@color/background"/>
  9.  
  10.  
  11. </LinearLayout>
  12.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


and :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
  4. <item android:drawable="@drawable/coloredball1" android:duration="50"/>
  5. <item android:drawable="@drawable/coloredball2" android:duration="50"/>
  6. <item android:drawable="@drawable/coloredball3" android:duration="50"/>
  7.  
  8.  
  9. </animation-list>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package start.MonitorUIv1;
  2.  
  3. public class StartInActivityMonitor extends Activity implements SensorEventListener{
  4.  
  5.         /** Called when the activity is first created. */
  6.         public SensorManager mSensorManager;
  7.         public boolean k= false;
  8.         public float prevX;
  9.         public float prevY;
  10.         public float prevZ;
  11.         public Timer timer;
  12.         public SoundTimeTask ourSound;
  13.         public TTS myTts = null;
  14.         private int warning = 0;
  15.         private String sendTo;
  16.         private String Username;
  17.         public long Duration;
  18.        
  19.         String myMessage = "Need Help!";
  20.        
  21.        
  22.        
  23.         @Override
  24.         public void onCreate(Bundle savedInstanceState) {
  25.                 super.onCreate(savedInstanceState);
  26.  
  27.                 setContentView(R.layout.frame_animations_layout);
  28.                
  29.                 mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
  30.                 mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) , SensorManager.SENSOR_DELAY_UI);
  31.  
  32.                 Bundle extras = getIntent().getExtras();
  33.                 final String tempDuration = extras.getString("myDuration");
  34.                 float myDuration =  Float.parseFloat(tempDuration);
  35.                 Duration = (long) (myDuration * 60 * 1000);
  36.  
  37.                 ourSound = new SoundTimeTask();
  38.                 timer = new Timer();
  39.  
  40.                 timer.schedule(ourSound,Duration, Duration);
  41.  
  42.                 final String tempsendTo = extras.getString("telephoneNumber");
  43.                 sendTo = tempsendTo;
  44.  
  45.                 final String tempUsername = extras.getString("Username");
  46.                 Username = tempUsername;
  47.                
  48.                 myTts = new TTS(this, ttsInitListener, true);
  49.                 myTts.speak("Creatinggggggggg", 0, null);
  50.                
  51.  
  52.         }
  53.         @Override
  54.         public void onAccuracyChanged(Sensor sensor, int accuracy) {
  55.                 // TODO Auto-generated method stub
  56.  
  57.         }
  58.  
  59.         @Override
  60.         public void onSensorChanged(SensorEvent event) {
  61.                 Sensor mySensor = event.sensor;
  62.                 if (mySensor.getType() != Sensor.TYPE_ACCELEROMETER) return;
  63.  
  64.                 if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER){
  65.                         float x = event.values[0];  
  66.                         float y = event.values[1];
  67.                         float z = event.values[2];
  68.  
  69.  
  70.                         if(!k){
  71.                                 prevX = x;
  72.                                 prevY = y;
  73.                                 prevZ = z;
  74.                                 k = true;
  75.                         }
  76.                         float value1 = Math.abs(x) - Math.abs(prevX);
  77.  
  78.  
  79.  
  80.                         if (value1 > 0.4){
  81.                                 warning = 0;
  82.                                 ourSound.cancel();
  83.                                 ourSound = new SoundTimeTask();
  84.                                 timer.schedule(ourSound,Duration, Duration);
  85.                         }
  86.                         prevX = x;
  87.                         prevY = y;
  88.                         prevZ = z;     
  89.  
  90.                 }
  91.  
  92.  
  93.         }
  94.         protected void onStop() {
  95.                 mSensorManager.unregisterListener(this);
  96.                 timer.cancel();
  97.                 super.onStop();
  98.         }
  99.  
  100.         class SoundTimeTask extends TimerTask implements Runnable{
  101.  
  102.                 public void run() {
  103.  
  104.                         switch (warning) {
  105.                         case 0:
  106.                                                
  107.                                 myTts.speak("Hello" + Username, 0, null);
  108.                                
  109.                                 ImageView imgView = (ImageView)findViewById(R.id.imageView);
  110.                                 imgView.setVisibility(View.VISIBLE);
  111.                                
  112.                                 imgView.setBackgroundResource(R.drawable.frame_animation);
  113.                        
  114.                                 AnimationDrawable frameAnimation =
  115.                                         (AnimationDrawable) imgView.getBackground();
  116.                                
  117.  
  118.                                 if (! frameAnimation.isRunning())
  119.                                 {
  120.                                        
  121.                                         frameAnimation.start();
  122.                                 }
  123.                                 imgView.bringToFront();
  124.                                
  125.  
  126.                                 break;
  127.  
  128.                         case 1:
  129.                                 myTts.speak(Username + "How are you?", 0, null);
  130.                                 break;
  131.  
  132.                         case 2:
  133.                                 myTts.speak("Are you ok?" + Username, 0, null);
  134.                                 break;
  135.  
  136.                         case 3:
  137.                                 myTts.speak("Do you require assistance" + Username + "?", 0, null);
  138.                                
  139.                                 break;
  140.  
  141.                         case 4:
  142.                                 myTts.speak("Hello" + Username + "please respond and move phone", 0, null);
  143.                                 break;
  144.  
  145.                         case 5:
  146.  
  147.                                 myTts.speak("Please respond by moving phone, next warning will send a SMS message", 0, null);
  148.  
  149.                                 break;
  150.  
  151.  
  152.                         case 6:
  153.                                 myTts.speak("Sending SMS message to designated contact", 0, null);
  154.                                 SmsManager smsManager = SmsManager.getDefault();
  155.                                 smsManager.sendTextMessage(sendTo,null,myMessage,null,null);
  156.                                 break;
  157.                         }
  158.                         warning++;
  159.  
  160.  
  161.  
  162.                 }
  163.  
  164.         }
  165.  
  166.         private TTS.InitListener ttsInitListener = new TTS.InitListener() {
  167.                 public void onInit(int version) {
  168.  
  169.                 }
  170.         };
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
kingcrowley
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jul 02, 2009 4:34 pm

Top

kind of working....

Postby kingcrowley » Thu Sep 10, 2009 6:32 pm

ok...i have got a simple animation working in this..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle savedInstanceState) {
  2.  
  3.                 super.onCreate(savedInstanceState);
  4.  
  5.  
  6.  
  7.                 setContentView(R.layout.frame_animations_layout);
  8.  
  9.                 imgView = (ImageView)findViewById(R.id.imageView);
  10.  
  11.                 imgView.setBackgroundResource(R.drawable.frame_animation);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


in onCreate i have the above..

then later i have

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. frameAnimation = (AnimationDrawable) imgView.getBackground();
  2.  
  3.                                 frameAnimation.start();
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


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
kingcrowley
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jul 02, 2009 4:34 pm

Postby mrcalonso » Mon Sep 14, 2009 9:28 am

Hi all...

I've experienced similar problems with frame based animations. I also need to display one set of frames or another depending on the situation.

My approach was to have one ImageView for each animation, set all the backgroundResource in onCreate and then, set all to invisible. When the situation requires it, the imageview is set to visible and the animation started but... doesn't work.

I tried to have them all visible, and fire the animation when required and that worked!!

If this can give any clue to somebody, please, reply here.

Thanks!
mrcalonso
Freshman
Freshman
 
Posts: 2
Joined: Mon Sep 14, 2009 9:18 am

Postby kingcrowley » Mon Sep 14, 2009 3:25 pm

I presume you have all the ImageViews laid out so they are all on the screen at one time? This works fine, but makes everything very small obviously.

I was wondering if anyone has a workaround, alternative idea/method to do this?

Thanks,

David
kingcrowley
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jul 02, 2009 4:34 pm

Postby mrcalonso » Tue Sep 15, 2009 8:11 am

When the images are on the screen and visible the animations sequence works fine but is not acceptable because the second step of the animation is visible while the first step is executing.

Trying to solve this situation, I set the second ImageView (which has the second step of the animation) to invisible and the animation doesn't work as the first imageview doesn't dissapear while the second one doesn't appear.

Any idea?
Thanks
mrcalonso
Freshman
Freshman
 
Posts: 2
Joined: Mon Sep 14, 2009 9:18 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 17 guests