Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:13:58+00:00 2026-05-31T06:13:58+00:00

there is class, that draws on canvas some field package com.cerbertek; import android.content.Context; import

  • 0

there is class, that draws on canvas some field

  package com.cerbertek;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Region;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class PlayGameView extends SurfaceView implements SurfaceHolder.Callback {

    private CanvasThread canvasthread;
    private Context mContext;
    private Region firstRec;

    private class CanvasThread extends Thread  {
        private SurfaceHolder _holder;
        private boolean _run = false;

        public CanvasThread(SurfaceHolder surfaceHolder) {
            _holder = surfaceHolder;
        }

        public void setRunning(boolean run) {
            _run = run;
        }

        @Override
        public void run() {
            Canvas  c;
            while (_run) {
                c = null;
                try {
                    c = _holder.lockCanvas(null);
                    synchronized (_holder) {
                        onDraw(c);
                    }
                } finally {
                    if (c != null) {
                        _holder.unlockCanvasAndPost(c);
                    }
                }
            }
        }
    }


    public PlayGameView (Context  context, AttributeSet  attrs) {
        super(context, attrs);
        SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        canvasthread = new CanvasThread(getHolder());
        setFocusable(true);
    }

    @Override
    public void onDraw(Canvas  canvas) {     
            Paint  paint = new Paint (); 
            Bitmap wrench = BitmapFactory.decodeResource(getResources(), R.drawable.wrench);
            canvas.drawColor(Color .BLACK);
            for(int i = 0; i < 4; i++) {
                for(int j = 0; j < 4; j++) {
                    int left = canvas.getWidth()/2 - wrench.getWidth()*2 + j*wrench.getWidth();
                    int top = 0  + i*wrench.getHeight();
                    canvas.drawBitmap(wrench, left, top, null);

                    Log.d(i + " " + j, left+ " " + top);
                }
            }

    }



    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {


    }


    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
        canvasthread.setRunning(true);
        canvasthread.start();
    }


    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
        boolean retry = true;
        canvasthread.setRunning(false);
        while (retry) {
                try {
                        canvasthread.join();
                        retry = false;
                } catch (InterruptedException  e) {
                        // we will try it again and again...
                }
        }
    }
}

so i want to detect where i click on(for exemple there is 2 rects and i want to detect what rect i click on). i can set setOnClickListener to my view, but how to get position of click?
then i want to set the regions while drawing( it is right, yeah? or not?) and in activity i’ll check is click coordinates contains regions

so
1) how can i get coord of click
2) what is the pretty good way to do do all that stuff, because my ideas are poor often

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:13:59+00:00Added an answer on May 31, 2026 at 6:13 am

    Look at the setOnTouchListener.

    The OnTouchListener implements a method with the following signature:

    public boolean onTouch(View v, MotionEvent event)

    The MotionEvent has information about where the touch actually happened. (event.getX() and event.getY())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple GUI app that just draws some graphics on
Is there a class that overwrites the .MainMenu_MenuItem class for the Main Menu? I
Hello is there a class that does a pretty conversion?
Is there a Python class that wraps the file interface (read, write etc.) around
Is there a PHP class/library that would allow me to query an XHTML document
Is there any easy way to create a class that uses IFormatProvider that writes
Is there a built-in .NET class that can replace or work like WinHttp.WinHttpRequest? Thanks!
Is there a C++ Standard Template Library class that provides efficient string concatenation functionality,
Is there a WMI namespace and a class that can be used to obtain
Is there a free alphanumeric barcode font or class that is compatible with Delphi

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.