Back to project page jmjuanesFramework.
The source code is released under:
MIT License
If you think the Android project jmjuanesFramework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package jmjuanes; //from ww w .ja v a 2 s . c o m import jmjuanes.util.Ui; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; public abstract class Screen { //Instructor del juego public GameMain game; //Context private final Context context; //Opciones del bitmap public BitmapFactory.Options opts = new BitmapFactory.Options(); //Constructor @SuppressWarnings("deprecation") public Screen(Context context, GameMain game) { //Guardamos el activity del juego this.game = game; //Guardamos el context this.context = context; opts.inDither = false; opts.inPurgeable = true; opts.inInputShareable = true; } //Para inciar las imagenes public Bitmap NewImg(int id, int newWidth, int newHeight) { //Creamos la imagen a partir del ID Bitmap img = BitmapFactory.decodeResource(context.getResources(), id); //Cogemos la anchura y la altur de la imagen int anc = img.getWidth(); int alt = img.getHeight(); //Calculamos la nueva altura y anchura float scaleWidth = ((float) newWidth*Ui.scale) / anc; float scaleHeight = ((float) newHeight*Ui.scale) / alt; // Create a matrix for the manipulation Matrix matrix = new Matrix(); // Resize the bit map matrix.postScale(scaleWidth, scaleHeight); // Recreate the new Bitmap img = Bitmap.createBitmap(img, 0, 0, anc, alt, matrix, false); //Devolvemos la imagen escalada return img; } //Para iniciar y detener la screen public abstract void Start(); public abstract void Stop(); public abstract void Resume(); //Para dibujar en la screen public abstract void Draw(Canvas canvas); //Para comprobar cuando ha pulsado public abstract void TouchDown(int x, int y); public abstract void TouchMove(int x, int y); public abstract void TouchUp(int x, int y); }