Android Animation (in tamil)

597 views

Published on

Dr. Ramkumar Lakshminarayanan article published in Tamil Computer Magazine. The content is about creating Android Animation Application.

Published in: Mobile
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
597
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
55
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android Animation (in tamil)

  1. 1. ݇†ó£Œ´ ÜQ«ñû¬ù à¼õ£‚°õ ðô API è¬÷ õöƒA»œ÷¶. Þî¡ Íô‹ 2® ñŸÁ‹ 3® à¼õƒè¬÷ ༠õ£‚è º®»‹. ÜQ«ñû¬ù ݇†ó£Œ´ 3.0 -™ Þ¼‰¶ Šó£Šð˜†® ÜQ«ñû¡ ñŸÁ‹ MÎ ÜQ«ñû¡ â¡Á Þó‡´ º¬øè¬÷ õöƒA»œ÷¶. Šó£Š ð†® ÜQ«ñûQ™ MÎ ÜQ «ñû¬ù‚ 裆®½‹ ÜFè ðò¡ 𣴠º¬ø Þ¼Šð Šó£Š 𘮠ÜQ«ñû¬ù«ò ÜFè‹ «ð˜ ðò¡ð´ˆ¶Aø£˜èœ. Draw able Resource-™ àœ÷ ðìƒ è¬÷ ªè£‡´‹, ðìƒè¬÷ å¡ø¡ H¡ å¡ø£è 裇Hˆ¶ ÜQ«ñû¬ù à¼õ£‚èô£‹. âO¬ñò£ù ÜQ«ñû¡ å¡P¬ù ༠õ£‚°‹ º¬øJ¬ù 𣘊«ð£‹. ¹Fò Šó£ ü‚† å¡P¬ù ªî£ìƒA Üî¡ ªðò¬ó ݇†ó£Œ®™ ÜQ«ñû¡ animation text âù ªðòK´«õ£‹. Þ‰î ꣡P™ main xme-™ â‰î Mî ñ£Ÿøƒè¬÷»‹ ªêŒò «ð£õ F™¬ô. on draw º¬ø Íô‹ õ†ì ñ£è îèõ™ ²Ÿø «õ‡´‹ â¡ð¬î °P‚è ðò¡ð´Aø¶. Þƒ° canvas J¬ù Parameter Ýè ªè£´‚è «õ‡´‹. «è¡õ£v â¡ð¶ ®ó£ ªñˆî®™ Þ¼‰¶ (Draw) ãŸð´‹ call è¬÷ ¬èò£÷ ðò¡ð´Aø¶. ®ó£M¬ù ðò¡ð´ˆ¶õ 4 裋«ð£ù†èœ (Componets) ðò¡ ð´Aø¶.ܬõ H‚ê™è¬÷¬èò£÷ H†«ñŠ ®ó£‚è¬÷ ¬èò£÷ canvas âŠð® õ¬óò «õ‡´‹, recet, path, text,bitmap ñŸÁ‹ paint (õ¬óîL¡ õ‡íƒèœ ñŸÁ‹ v¬ì™ è¬÷ °P‚è) Þ‰î ꣡P™ ⿈¶è¬÷ circular path-™ ðò¡ð´ˆîŠð´‹. on draw MŸè£ù Gó™-1™ ªè£´‚èŠð†´œ÷¶. Path circle = new Path(); int centerX = canvas.getWidth() / 2; int centerY = canvas.getHeight() / 2; int r = Math.min(centerX, centerY); circle.addCircle(centerX, centerY, r, Direction.CW); Paint paint = new Paint(); paint.setColor(Color.GREEN); paint.setTextSize(30); paint.setAntiAlias(true); canvas.drawTextOnPath(AnimatedTxt, circle, 0, 30, paint); private void createAnim(Canvas canvas) { rotateAnim = new RotateAnimation(0, 360, canvas.getWidth() / 2, canvas.getHeight() / 2); rotateAnim.setRepeatMode(Animation.REVER SE); rotateAnim.setRepeatCount(Animation.INFINI TE); rotateAnim.setDuration(10000L); rotateAnim.setInterpolator(new AccelerateDecelerateInterpolator()); startAnimation(rotateAnim); Gó™-1 Gó™-2 ðì‹-1 ðì‹-2 ðì‹-3
  2. 2. Ý¡†ó£Œ´ -2 Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡ 20 ÜQ«ñû¬ù õ†ìñ£è ªêò™ð´ˆFì, create animation ªñˆî† ðò¡ð´ˆîŠð´‹. rotate animation Íô‹ ¹Fò rotate animation à¼õ£‚è «õ‡´‹. rotation Ýù¶ x,ypane-™ ãŸð´‹. â‰î ¹œO¬ò ªè£‡´ ÜQ«ñû¡ ãŸðìô£‹ â¡ðî¬ù °PŠHìô£‹. 0,0 â¡ ð¶ Þì¶ ð‚èˆF™ àœ÷ ºî™ ¹œO«ò Ý°‹. â‰î ¹œO¬ò»‹ °PŠHìM™¬ô â¡ø£™ 0,0 J¬ù ¹œOò£è ªè£‡´ ÜQ «ñû¡ à¼õ£‚èŠð´‹. AK«ò† ÜQ«ñû QŸè£ù Gó™ 2-™ ªè£´‚èŠð†´œ÷¶. Þ‰î ꣡P™ ªìv‚†®Ÿè£ù îèõL¬ù package com.ram.animationtext; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Path.Direction; import android.os.Bundle; import android.view.View; import android.view.animation.AccelerateDecelerateIn terpolator; import android.view.animation.Animation; import android.view.animation.RotateAnimation; public class AnimationtextActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new GraphicsView(this)); } private static class GraphicsView extends View { private static final String AnimatedTxt = "This Sample Program Shows, Aniamtion Using Path. This is very simple and easy to understand."; private Animation rotateAnim; public GraphicsView(Context context) { super(context); } private void createAnim(Canvas canvas) { rotateAnim = new RotateAnimation(0, 360, canvas.getWidth() / 2, canvas.getHeight() / 2); rotateAnim.setRepeatMode(Animation.REVERS E); rotateAnim.setRepeatCount(Animation.INFINIT E); rotateAnim.setDuration(10000L); rotateAnim.setInterpolator(new AccelerateDecelerateInterpolator()); startAnimation(rotateAnim); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // creates the animation the first time if (rotateAnim == null) { createAnim(canvas); } Path circle = new Path(); int centerX = canvas.getWidth() / 2; int centerY = canvas.getHeight() / 2; int r = Math.min(centerX, centerY); circle.addCircle(centerX, centerY, r, Direction.CW); Paint paint = new Paint(); paint.setColor(Color.GREEN); paint.setTextSize(30); paint.setAntiAlias(true); canvas.drawTextOnPath(AnimatedTxt, circle, 0, 30, paint); } } animated text â¡ø ñ£PLJ™ ªè£´ˆ¶œ «÷£‹. Gó™-3-™ ªì‚v† ÜQ«ñûQŸè£ù º¿ Gó¬ô»‹ ªè£´ˆ¶œ«÷£‹. Þ‰î GóL¬ù 苬ð™ (Compile) ªêŒ¶ ó¡ ªêŒ Gó™-3
  3. 3. package ram.com.graphiceffect; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ComposePathEffect; import android.graphics.CornerPathEffect; import android.graphics.DashPathEffect; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PathDashPathEffect; import android.graphics.PathEffect; import android.graphics.RectF; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; public class GraphiceffectexampleActivity extends Activity { /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } private static class SampleView extends View { private Paint mPaint; private Path mPath; private PathEffect[] mEffects; private int[] mColors; private float mPhase; private static PathEffect makeDash(float phase) { return new DashPathEffect(new float[] { 15, 5, 8, 5 }, phase); } private static void makeEffects(PathEffect[] e, float phase) { e[0] = null; // no effect e[1] = new CornerPathEffect(10); e[2] = new DashPathEffect(new float[] {10, 5, 5, 5}, phase); e[3] = new PathDashPathEffect(makePathDash(), 12, phase, PathDashPathEffect.Style.ROTATE); e[4] = new ComposePathEffect(e[2], e[1]); e[5] = new ComposePathEffect(e[3], e[1]); } public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(6); mPath = makeFollowPath(); mEffects = new PathEffect[6]; mColors = new int[] { Color.BLACK, Color.RED, Color.BLUE, Color.GREEN, Color.MAGENTA, Color.BLACK }; } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); RectF bounds = new RectF(); mPath.computeBounds(bounds, false); canvas.translate(10 - bounds.left, 10 - bounds.top); makeEffects(mEffects, mPhase); mPhase += 1; invalidate(); for (int i = 0; i < mEffects.length; i++) { mPaint.setPathEffect(mEffects[i]); mPaint.setColor(mColors[i]); canvas.drawPath(mPath, mPaint); canvas.translate(0, 28); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: mPath = makeFollowPath(); return true; } return super.onKeyDown(keyCode, event); } private static Path makeFollowPath() { Path p = new Path(); p.moveTo(0, 0); for (int i = 1; i <= 15; i++) { p.lineTo(i*20, (float)Math.random() * 35); } return p; } private static Path makePathDash() { Path p = new Path(); p.moveTo(4, 0); p.lineTo(0, -4); p.lineTo(8, -4); p.lineTo(12, 0); p.lineTo(8, 4); p.lineTo(0, 4); return p; } } } Gó™-4
  4. 4. - ªî£ì¼‹  ðì‹ 1-™ àœ÷¶ «ð£¡ø ÜQ«ñû¡ «î£¡Á‹. Ü´ˆî ꣡ø£è Aó£çH‚ â炆 J¬ù à¼õ£‚°‹ º¬øJ¬ùŠ 𣘊«ð£‹. path effect A÷£ê£ù¶ ݇†ó£Œ´ Aó£çH‚C¡ A÷£vC¬ù Ü®Šð¬ìò£è‚ ªè£‡´œ÷¶. «ðˆ âçªð‚†®¡ «ïó®ò£ù êŠ A÷£vèœ compose path effect ,corner path effect, dash path effect, dis create path effect, path dash path effect ñŸÁ‹ sum path effect «ð£¡ø¬õò£°‹. ¹Fò Šó£ªü‚† å¡P¬ù ªî£ìƒA Üî¡ ªðòK¬ù graphiceffectexample âù ªðòK´ƒ èœ. Þ‰î ꣡P½‹ main xme-™ â‰î ñ£Ÿø º‹ ªêŒòŠ«ð£õF™¬ô. graphiceffectexample activity -J¬ù extend ªêŒ»ñ£Á à¼õ£‚è «õ‡´‹. Ü´ˆîî£è sample view â¡ø extend private static class J¬ù à¼õ£‚A MÎM¬ù extend ªêŒ»ñ£Á à¼õ£‚è «õ‡´‹. on create º¬øJ™ set content view(new sample view(this) â¡Á ªè£´ˆ¶ sample view -M¬ù ðò¡ð´ˆ¶ñ£Á à¼õ£‚è «õ‡´‹. sample view M™ paint path ñŸÁ‹ path effect è¬÷ ðò¡ð´ˆF ÜõŸPŸè£ù ñFŠ¹è¬÷ ªè£´‚è «õ‡´‹. make effect º¬ø Íô‹ patheffect-¡ ܬñŠH¬ù °PŠHì «õ‡´‹. on draw method Íô‹ canvasJ¬ù ðò¡ ð´ˆF ÜQ«ñû¡ ªêò™ð£†´ º¬øJ¬ù °PŠHì «õ‡´‹ Þî¬ù îMó on key down eventJ¬ù ¬èò£À‹ º¬ø»‹ ðò¡ð´ˆîŠ ð†´œ÷¶. on key down-™ KEY CODE-DPAD- CENTER J¬ù Ü¿ˆFù£™ path J¬ù ñ£ŸP ܬñ‚°‹ Gó™ ðò¡ð´ˆîŠ ð†´œ÷¶.KEY CODE-DPAD-CENTER ⃰ Þ¼‚°‹ â¡ðî¬ù ðì‹ 2™ 裇H‚èŠ ð†´œ÷¶. Aó£çH‚v âçªð‚†®Ÿè£ù Gó™4-™ 裇H‚èŠð†´œ ÷¶. ÜŠO«èû¡ ó¡ ªêŒî¾ì¡ ðì‹ 2 ñŸÁ‹ 3-™ àœ÷¶ «ð£¡Á «î£¡Á‹.

×