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
|
package com.example.Test;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
public class HommeActivity extends Activity {
Timer timer;
TimerTask task;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new RenderView(this));
// Le timer
timer = new Timer();
}
/**
* CETTE PARTIE SERT A DESSINER UN POINT OU UN CERCLE SUR MON ACTIVITY
*
*/
class RenderView extends View {
public RenderView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
//la procédure pour dessiner le point
protected void onDraw(final Canvas canvas){
Resources res= getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.mapci);
int Bwidth=bitmap.getWidth();
int Bheight = bitmap.getHeight();
final Paint paint = new Paint();
int iWidth= canvas.getWidth(); // largeur
int iHeight = canvas.getHeight();//hauteur
mettre une image en arriere plan de mon Canvas
canvas.drawBitmap(bitmap, (iWidth-Bwidth)/2, (iHeight-Bheight)/2,null);
final Handler handler = new Handler();
task = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
//couleur du Cercle
paint.setColor(Color.RED);
//dessiner le cercle
canvas.drawCircle(iWidth/2, iHeight/2, 15, paint);
Toast.makeText(getContext(), "Nous sommes ici !", Toast.LENGTH_SHORT).show();
}
});
}
};
timer.schedule(task, 0, 5000);
}
}
} |
Partager