0

I am developing a new android app, and I've run into a bit of a snag. While everything else works, I want to have it so that when you click on the screen, it exits the program, same as if you click the back button. How do I get around to doing that? Thank you.

package com.example.cory2.draw;

import android.content.Context;
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.Point;
import android.graphics.RectF;
import android.os.Process;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Size;
import android.view.Display;
import android.view.View.OnClickListener;

import android.view.View;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    Intent intent = new Intent(this, MainActivity.class);
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new MyView(this));
    }

    @Override
    public void onClick(View v) {
    }

    public class MyView extends View {
        int x, y;
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.eagle);
        public MyView(Context context) {
            super(context);
            x = 0;
            y = 0;
//              bmp_paint = new Paint();
//              bmp_paint.setTextAlign(Paint.Align.CENTER);
        }

        @Override
        protected void onDraw (Canvas canvas) {
            x = (x + 1) % canvas.getWidth();
            y = (y + 1) % canvas.getHeight();
            int height = canvas.getHeight()/2;
            int width = canvas.getWidth()/2;
            int radius;
            radius = 100;
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.WHITE);
            canvas.drawPaint(paint);
            Bitmap b2 = Bitmap.createScaledBitmap(bmp, canvas.getWidth(), canvas.getHeight(), true);
            canvas.drawBitmap (b2, canvas.getWidth()/2-b2.getWidth()/2, canvas.getHeight()/2-b2.getHeight()/2, null);

            // Use Color.parseColor to define HTML colors
            paint.setColor(Color.parseColor("#CD5C5C"));
            canvas.drawCircle (x/2, y/2, radius, paint);
            canvas.drawRect(width-100, height-100, width+100, height+100, paint);
            invalidate();
        }
    }

    public Bitmap getResizedBitmap(Bitmap bm, int nh, int nw) {
        int width = bm.getWidth();
        int height = bm.getHeight();
        float sw = ((float)nw/width);
        float sh = ((float)nh/height);
        Matrix matrix = new Matrix();
        matrix.postScale(sw, sh);
        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
        return resizedBitmap;
    }
}
2
Contributors
1
Reply
6
Views
2 Months
Discussion Span
Last Post by rproffitt
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.