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
| package com.example.ttc;
*
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
*
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
*
public class MainActivity* extends Activity implements View.OnTouchListener{
****private ArrayList<Noeud> path;
****private Coordonnees dep = new Coordonnees(0,4);
****private Coordonnees fin = new Coordonnees(4,1);
****private Canvas canvas;
****private Graphe g;
****private ImageView imageView;
****@Override
****protected void onCreate(Bundle savedInstanceState) {
********super.onCreate(savedInstanceState);
********setContentView(R.layout.activity_main);
********// charge la map dans une view puis charge la bitmap correspondante dans la view
*********imageView = (ImageView) findViewById(R.id.map1);
*********Drawable d = imageView.getDrawable();
*********Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
*********imageView.setImageBitmap(bitmap);
*********imageView.setOnTouchListener(this);
*********// met le bitmap dans un canvas pour le modifier
*********Toast.makeText(this, "image : " + d.getIntrinsicWidth() + " " + d.getIntrinsicWidth(), Toast.LENGTH_SHORT).show();
*********canvas = new Canvas(bitmap);
*********//on crée une peinture de cercle pour tester que le bitmap se modifie bien
*********//on initialise la peinture
*********Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
*********paint.setColor(Color.LTGRAY);
********//on définie les bord du drawable
*********d.setBounds(0,0,d.getIntrinsicWidth(), d.getIntrinsicHeight());
*********d.draw(canvas);
*********//on dessine un premier point
*********PointView p = new PointView(this, 50, 50);
*********p.draw(canvas);
*********//puis un deuxieme
*********p = new PointView(this, 0,0);
*********p.draw(canvas);
**********
**********
**********
********try{
************InputStream is =* getResources().openRawResource(R.raw.map1);
************ReadMap r = new ReadMap(is);
************g = new Graphe(r.getRead());
************path = g.pathFinder(dep,fin);
*************
********}catch(Exception e){
************e.printStackTrace();
********}
*********
****}
*
****@Override
****public boolean onCreateOptionsMenu(Menu menu) {
********// Inflate the menu; this adds items to the action bar if it is present.
********getMenuInflater().inflate(R.menu.main, menu);
********return true;
****}
*
****@Override
****public boolean onTouch(View v, MotionEvent event) {
********if (event.getAction()==MotionEvent.ACTION_MOVE)
********{****
************//coordonnée du click
************int X = (int)event.getX();
************int Y = (int)event.getY();
************//ce qui va etre les coo du centre de la case
************int cx = X;
************int cy = Y;
************// on incremente jusqu'a trouver le bord d'une case
************while(cx%(canvas.getWidth()/g.getWidth())!=0)
****************cx++;
************while(cy%(canvas.getHeight()/g.getHeight())!=0)
****************cy++;
************//on enleve la moitié du modulo pour etre au centre de la case
************cx = cx-((canvas.getWidth()/g.getWidth())/2);
************cy = cy-((canvas.getHeight()/g.getHeight())/2);
*************
************Toast.makeText(this,"X : "+X+" Y : "+Y+" CX : "+cx+" CY : "+cy, Toast.LENGTH_SHORT).show();
*************
********}
********return true;
****}
*****
*
} |
Partager