IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Problème développement Live Wallpaper


Sujet :

Android

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 7
    Par défaut Problème développement Live Wallpaper
    Bonjour,

    je développe un fond d'écran animé composé d'une animation de trames.
    Le fond d'écran se compose donc d'une animation de 20 fichiers png.

    J'ai réussi à développer ce que je voulais mais j'ai un problème de performances... Comment pourrais-je améliorer tout cela ?

    Je vous envoie le code du fichier principal ainsi que le projet eclipse


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    package ca.jvsh.livewallpaper;
     
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Matrix;
    import android.graphics.Paint;
    import android.os.Handler;
    import android.service.wallpaper.WallpaperService;
    import android.view.MotionEvent;
    import android.view.SurfaceHolder;
     
    public class LiveWallpaper extends WallpaperService
    {
     
    	public static final String	SHARED_PREFS_NAME	= "livewallpapersettings";
    	private final Handler mHandler = new Handler();
    	public Bitmap myBg;
    	public int idx = 0;
    	public static final int NUM_RES = 20;
     
     
    	@Override
    	public void onCreate() {
    		super.onCreate();
    	}
     
    	@Override
    	public void onDestroy() {
    		super.onDestroy();
    	}
     
    	@Override
    	public Engine onCreateEngine() {
    		return new CubeEngine();
    	}
     
    	class CubeEngine extends Engine {
     
    		private final Paint mPaint = new Paint();
    		private boolean mAnime = true;
    		private Matrix mMatrix = new Matrix();
     
    		private final Runnable mDrawAnim = new Runnable() {
    			@Override
    			public void run() {
    				drawFrame();
    			}
    		};
    		private boolean mVisible;
     
     
    		CubeEngine() {
    			myBg = BitmapFactory.decodeResource(getResources(),R.drawable.n01);
    		}
     
    		@Override
    		public void onCreate(SurfaceHolder surfaceHolder) {
    			super.onCreate(surfaceHolder);
     
    			setTouchEventsEnabled(false);
    		}
     
    		@Override
    		public void onDestroy() {
    			super.onDestroy();
    			mHandler.removeCallbacks(mDrawAnim);
    		}
     
    		@Override
    		public void onVisibilityChanged(boolean visible) {
    			mVisible = visible;
    			if (visible) {
    				drawFrame();
    			} else {
    				mHandler.removeCallbacks(mDrawAnim);
    			}
    		}
     
    		@Override
    		public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    			super.onSurfaceChanged(holder, format, width, height);
     
    			float w = myBg.getWidth();
    			float s = width / w;
    			mMatrix.reset();
    			mMatrix.setScale(s, s);
    			drawFrame();
    		}
     
    		@Override
    		public void onSurfaceCreated(SurfaceHolder holder) {
    			super.onSurfaceCreated(holder);
    		}
     
    		@Override
    		public void onSurfaceDestroyed(SurfaceHolder holder) {
    			super.onSurfaceDestroyed(holder);
    			mVisible = false;
    			mHandler.removeCallbacks(mDrawAnim);
    		}
     
    		@Override
    		public void onOffsetsChanged(float xOffset, float yOffset,
    				float xStep, float yStep, int xPixels, int yPixels) {
    			drawFrame();
    		}
     
     
    		@Override
    		public void onTouchEvent(MotionEvent event) {
    			if (event.getAction() == MotionEvent.ACTION_MOVE) {
    				mAnime = !mAnime;
    			}
    			super.onTouchEvent(event);
    		}
     
     
    		void drawFrame() {
    			final SurfaceHolder holder = getSurfaceHolder();
     
    			Canvas c = null;
    			try {
    				c = holder.lockCanvas();
    				if (c != null) {
    					// draw something
    					drawAnim(c);
    					//drawTouchPoint(c);
    				}
    			} finally {
    				if (c != null) holder.unlockCanvasAndPost(c);
    			}
     
    			// Reschedule the next redraw
    			mHandler.removeCallbacks(mDrawAnim);
    			if (mVisible && mAnime) {
    				mHandler.postDelayed(mDrawAnim, 50 );
    			}
    		}
     
     
    		void drawAnim(Canvas c) {
     
    			if (idx == NUM_RES) {idx = 0;}
    			idx += 1;
    			switch (idx) {
    			    case 0: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n01), mMatrix, mPaint); break;
    			    case 1: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n02), mMatrix, mPaint); break;
    			    case 2: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n03), mMatrix, mPaint); break;
    			    case 3: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n04), mMatrix, mPaint); break;
    			    case 4: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n05), mMatrix, mPaint); break;
    			    case 5: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n06), mMatrix, mPaint); break;
    			    case 6: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n07), mMatrix, mPaint); break;
    			    case 7: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n08), mMatrix, mPaint); break;
    			    case 8: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n09), mMatrix, mPaint); break;
    			    case 9: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n10), mMatrix, mPaint); break;
    			    case 10: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n11), mMatrix, mPaint); break;
    			    case 11: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n12), mMatrix, mPaint); break;
    			    case 12: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n13), mMatrix, mPaint); break;
    			    case 13: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n14), mMatrix, mPaint); break;
    			    case 14: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n15), mMatrix, mPaint); break;
    			    case 15: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n16), mMatrix, mPaint); break;
    			    case 16: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n17), mMatrix, mPaint); break;
    			    case 17: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n18), mMatrix, mPaint); break;
    			    case 18: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n19), mMatrix, mPaint); break;
    			    case 19: c.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.n20), mMatrix, mPaint); break;
     
     
     
    			}
     
    		}
     
     
     
    	}
    }
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Problème développement site web sur IPhone
    Par openeyes dans le forum Développement iOS
    Réponses: 6
    Dernier message: 17/11/2010, 15h31
  2. Problème développement 64 Bit
    Par Algernon2 dans le forum Windows
    Réponses: 8
    Dernier message: 13/07/2010, 17h14
  3. [Javamail] Problème Windows Live Hotmail (POP3)
    Par jeyce dans le forum API standards et tierces
    Réponses: 4
    Dernier message: 30/11/2008, 16h22
  4. Problème Msn Live Messenger
    Par RA dans le forum Windows XP
    Réponses: 6
    Dernier message: 27/05/2007, 18h29
  5. Problème TeX Live
    Par Paenitentia dans le forum Distributions
    Réponses: 2
    Dernier message: 21/05/2006, 18h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo