[android-developers] Re: Android custom ImageView fade animation
Hi, I tried it but it doesn't seem to work :( Here's my code in the view that triggers the thread code in the activity: case MotionEvent.ACTION_DOWN: currentTouchIndex = checkForSquareTouch(X, Y); if (currentTouchIndex = 0) { ((MainActivity) this.getContext()) .playSquareAnimation(currentTouchIndex); Activity code: public void playSquareAnimation(int currentTouchIndex) { ranim = AnimationUtils.loadAnimation(this, R.anim.rotate); // view.squares[currentTouchIndex].startAnimation(ranim); runOnUiThread(new Runnable() { public void run() { view.clock.startAnimation(AnimationUtils.loadAnimation( MainActivity.this, R.anim.rotate)); } }); } Any ideas? Do you think my view's onDraw() method is messing around with the animation? On Dec 28, 5:14 am, AlexBonel bonela...@gmail.com wrote: On 28 дек, 00:56, Seb stsiop...@googlemail.com wrote: Hmm I kind of understand... are you able to provide any code or psuedo code though to show how it would fit together? On Dec 25, 5:08 pm, AlexBonel bonela...@gmail.com wrote: For example: public class MyActivity extends Activity { private GameView mGameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); .. // Deffinition of your Activity .. // somewhere (for example in some View.OnXXXListener implementation) runOnUiThread( new Runnable() { @Override public void run() { mGameView.startAnimation(AnimationUtils.loadAnimation(MyActivity.this, R.anim.my_animation)); } } ); } } Is it clear? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
Just to clarify, if I change view.clock.startAnimation(AnimationUtils.loadAnimation( MainActivity.this, R.anim.rotate)); to: view.startAnimation(AnimationUtils.loadAnimation( MainActivity.this, R.anim.rotate)); Then the animation plays, but for the whole view, which isn't what I want On Dec 29, 7:24 pm, Seb stsiop...@googlemail.com wrote: Hi, I tried it but it doesn't seem to work :( Here's my code in the view that triggers the thread code in the activity: case MotionEvent.ACTION_DOWN: currentTouchIndex = checkForSquareTouch(X, Y); if (currentTouchIndex = 0) { ((MainActivity) this.getContext()) .playSquareAnimation(currentTouchIndex); Activity code: public void playSquareAnimation(int currentTouchIndex) { ranim = AnimationUtils.loadAnimation(this, R.anim.rotate); // view.squares[currentTouchIndex].startAnimation(ranim); runOnUiThread(new Runnable() { public void run() { view.clock.startAnimation(AnimationUtils.loadAnimation( MainActivity.this, R.anim.rotate)); } }); } Any ideas? Do you think my view's onDraw() method is messing around with theanimation? On Dec 28, 5:14 am, AlexBonel bonela...@gmail.com wrote: On 28 дек, 00:56, Seb stsiop...@googlemail.com wrote: Hmm I kind of understand... are you able to provide any code or psuedo code though to show how it would fit together? On Dec 25, 5:08 pm, AlexBonel bonela...@gmail.com wrote: For example: public class MyActivity extends Activity { private GameView mGameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); .. // Deffinition of your Activity .. // somewhere (for example in some View.OnXXXListener implementation) runOnUiThread( new Runnable() { @Override public void run() { mGameView.startAnimation(AnimationUtils.loadAnimation(MyActivity.this, R.anim.my_animation)); } } ); } } Is it clear? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
Hmm I kind of understand... are you able to provide any code or psuedo code though to show how it would fit together? On Dec 25, 5:08 pm, AlexBonel bonela...@gmail.com wrote: On 25 дек, 15:31, Seb stsiop...@googlemail.com wrote: But can I still define my animations in XML using your suggested method? Yeah, Why not, just call static AnimationUtils.() with context instance (which is your Activity) and id of youranimationxml and it'll return youAnimationobject that you can pass to your startAnimation() method -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
On 28 дек, 00:56, Seb stsiop...@googlemail.com wrote: Hmm I kind of understand... are you able to provide any code or psuedo code though to show how it would fit together? On Dec 25, 5:08 pm, AlexBonel bonela...@gmail.com wrote: For example: public class MyActivity extends Activity { private GameView mGameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); .. // Deffinition of your Activity .. // somewhere (for example in some View.OnXXXListener implementation) runOnUiThread( new Runnable() { @Override public void run() { mGameView.startAnimation(AnimationUtils.loadAnimation(MyActivity.this, R.anim.my_animation)); } } ); } } Is it clear? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
But can I still define my animations in XML using your suggested method? On Dec 24, 6:27 pm, AlexBonel bonela...@gmail.com wrote: On 23 дек, 07:49, Seb stsiop...@googlemail.com wrote: Brilliant, that's useful, will give that a go. Any advice for the original issue? Well, I have got only one idea, but I think there is another better method to do, but never mind, try to call Activity.runOnUIThread(Runnable) method and pass there a Runnable whereanimationwould be launched. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
On 25 дек, 15:31, Seb stsiop...@googlemail.com wrote: But can I still define my animations in XML using your suggested method? Yeah, Why not, just call static AnimationUtils.() with context instance (which is your Activity) and id of your animation xml and it'll return you Animation object that you can pass to your startAnimation() method -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
On 23 дек, 07:49, Seb stsiop...@googlemail.com wrote: Brilliant, that's useful, will give that a go. Any advice for the original issue? Well, I have got only one idea, but I think there is another better method to do, but never mind, try to call Activity.runOnUIThread(Runnable) method and pass there a Runnable where animation would be launched. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
Brilliant, that's useful, will give that a go. Any advice for the original issue? On Dec 23, 6:51 am, AlexBonel bonela...@gmail.com wrote: Has looked through your code and saw one big perfomance issue: protected void onDraw(Canvas canvas) { Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG); ... } It takes too much time when your try to allocate memory for Paint object. If you work withanimationit always calls invalidate() method which redraws your View. Memory allocation for Paint should be outside of onDraw() method (e.g. when you create your view, in it's constructor) it will give you much better perfomance that you have now. Try to do so and you'll see. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
Bump: Can anyone help? If I define an imageview in my activity and then set an animation for it, then it plays fine. But if I define an image view as a member in my custom view and then try to play its animation, it does not play. Any help is appreciated... On Dec 18, 4:59 pm, Seb stsiop...@googlemail.com wrote: I am creating a game. Most of the computation is done in acustomView class which contains a grid ofcustomSquares which extendimageview. Here's some code to describe what's happening: public class GameView extends View { public Square squares[] = null; public GameView(Context context, AttributeSet a) { super(context, a); setFocusable(true); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); squares = new Square[numSquares]; } public void resetGame() { } public void restartGame() { } public boolean onTouchEvent(MotionEvent event) { int eventaction = event.getAction(); int X = (int)event.getX(); int Y = (int)event.getY(); switch (eventaction) { case MotionEvent.ACTION_DOWN: currentTouchIndex = checkForSquareTouch(X, Y); if(currentTouchIndex = 0) { squares[currentTouchIndex].select(); ((MainActivity)this.getContext()).startSquareAnimation(); . return true; } Thats the main View. Square implementation: public class Square extendsImageView{ public Square(Context context, AttributeSet attrs, int x, int y, int squareWidth, boolean operator, int textS, Typeface f) { super(context, attrs); { this.setImageResource(R.drawable.chalkbox); this.getDrawable().setBounds(x, y, x + squareWidth, y + squareWidth); this.setAlpha(10); } protected void onDraw(Canvas canvas) { Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG); foreground.setStyle(Style.FILL); foreground.setTextSize(textSize); foreground.setColor(Color.WHITE); foreground.setTextScaleX(1); foreground.setTextAlign(Paint.Align.CENTER); foreground.setTypeface(font); int left = this.getDrawable().getBounds().left; int right = this.getDrawable().getBounds().right; int top = this.getDrawable().getBounds().top; int bottom = this.getDrawable().getBounds().bottom; if (invalidMove) { } if (isOperator) { if (text.equals(+)) bottom += 10; if (text.equals(/)) bottom += 5; if (text.equals(x) || text.equals(/)) foreground.setTextSize(textSize - 5); else foreground.setTextSize(textSize); } this.getDrawable().draw(canvas); canvas.drawText(text, (left + right) / 2, ((top + bottom) / 2) + 10, foreground); } Hope that gives you a view of the structure. I'm trying to animate the Square, so that when a player presses on a Square, the Square brightens and then fades again when they lift their finger off. The problem is that the call to square[0].startAnimation() does not seem to be working and theanimationis not playing. Am I doing something wrong? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android custom ImageView fade animation
Has looked through your code and saw one big perfomance issue: protected void onDraw(Canvas canvas) { Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG); ... } It takes too much time when your try to allocate memory for Paint object. If you work with animation it always calls invalidate() method which redraws your View. Memory allocation for Paint should be outside of onDraw() method (e.g. when you create your view, in it's constructor) it will give you much better perfomance that you have now. Try to do so and you'll see. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en