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 8807591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:24:19+00:00 2026-06-14T02:24:19+00:00

I am working on an Android application. In my app I am using a

  • 0

I am working on an Android application. In my app I am using a custom view. Now I want to implement onclick in that view. But I failed to do that. ontouch is working fine. Please have a look on my code and help me to fix the issue.

public class ImagePageCurlView extends View implements OnClickListener{

/** Our Log tag */
private final static String TAG = "PageCurlView";

// Debug text paint stuff
private Paint mTextPaint;
private TextPaint mTextPaintShadow;

/** Px / Draw call */
private int mCurlSpeed;

/** Fixed update time used to create a smooth curl animation */
private int mUpdateRate;

/** The initial offset for x and y axis movements */
private int mInitialEdgeOffset;

/** The mode we will use */
private int mCurlMode;

/** Simple curl mode. Curl target will move only in one axis. */
public static final int CURLMODE_SIMPLE = 0;

/** Dynamic curl mode. Curl target will move on both X and Y axis. */
public static final int CURLMODE_DYNAMIC = 1;

/** Enable/Disable debug mode */
private boolean bEnableDebugMode = false;

/** The context which owns us */
private WeakReference<Context> mContext;

/** Handler used to auto flip time based */
private FlipAnimationHandler mAnimationHandler;

/**
 * Maximum radius a page can be flipped, by default it's the width of the
 * view
 */
private float mFlipRadius;

/** Point used to move */
private Vector2D mMovement;

/** The finger position */
private Vector2D mFinger;

/** Movement point form the last frame */
private Vector2D mOldMovement;

/** Page curl edge */
private Paint mCurlEdgePaint;

/** Our points used to define the current clipping paths in our draw call */
private Vector2D mA, mB, mC, mD, mE, mF, mOldF, mOrigin;

/** Left and top offset to be applied when drawing */
private int mCurrentLeft, mCurrentTop;

/** If false no draw call has been done */
private boolean bViewDrawn;

/** Defines the flip direction that is currently considered */
private boolean bFlipRight;

/** If TRUE we are currently auto-flipping */
private boolean bFlipping;

/** TRUE if the user moves the pages */
private boolean bUserMoves;

/** Used to control touch input blocking */
private boolean bBlockTouchInput = false;

/** Enable input after the next draw event */
private boolean bEnableInputAfterDraw = false;

/** LAGACY The current foreground */
private Bitmap mForeground;

/** LAGACY The current background */
private Bitmap mBackground;

/** LAGACY List of pages, this is just temporal */
public ArrayList<Bitmap> mPages;
private ArrayList<Bitmap> mPages1;

/** LAGACY Current selected page */
private  static int mIndex = 0;

private static int cInt=0;

MediaPlayer mediaPlayer;

String[] example = getResources().getStringArray(R.array.example_array);

/**
 * Inner class used to represent a 2D point.
 */
private class Vector2D {
    public float x, y;

    public Vector2D(float x, float y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return "(" + this.x + "," + this.y + ")";
    }

    public float length() {
        return (float) Math.sqrt(x * x + y * y);
    }

    public float lengthSquared() {
        return (x * x) + (y * y);
    }

    public boolean equals(Object o) {
        if (o instanceof Vector2D) {
            Vector2D p = (Vector2D) o;
            return p.x == x && p.y == y;
        }
        return false;
    }

    public Vector2D reverse() {
        return new Vector2D(-x, -y);
    }

    public Vector2D sum(Vector2D b) {
        return new Vector2D(x + b.x, y + b.y);
    }

    public Vector2D sub(Vector2D b) {
        return new Vector2D(x - b.x, y - b.y);
    }

    public float dot(Vector2D vec) {
        return (x * vec.x) + (y * vec.y);
    }

    public float cross(Vector2D a, Vector2D b) {
        return a.cross(b);
    }

    public float cross(Vector2D vec) {
        return x * vec.y - y * vec.x;
    }

    public float distanceSquared(Vector2D other) {
        float dx = other.x - x;
        float dy = other.y - y;

        return (dx * dx) + (dy * dy);
    }

    public float distance(Vector2D other) {
        return (float) Math.sqrt(distanceSquared(other));
    }

    public float dotProduct(Vector2D other) {
        return other.x * x + other.y * y;
    }

    public Vector2D normalize() {
        float magnitude = (float) Math.sqrt(dotProduct(this));
        return new Vector2D(x / magnitude, y / magnitude);
    }

    public Vector2D mult(float scalar) {
        return new Vector2D(x * scalar, y * scalar);
    }
}

/**
 * Inner class used to make a fixed timed animation of the curl effect.
 */
class FlipAnimationHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        ImagePageCurlView.this.FlipAnimationStep();
    }

    public void sleep(long millis) {
        this.removeMessages(0);
        sendMessageDelayed(obtainMessage(0), millis);
    }
}

/**
 * Base
 * 
 * @param context
 */
public ImagePageCurlView(Context context) {
    super(context);
    init(context);
    ResetClipEdge();
    setOnClickListener(this);
    setClickable(true);
}

/**
 * Construct the object from an XML file. Valid Attributes:
 * 
 * @see android.view.View#View(android.content.Context,
 *      android.util.AttributeSet)
 */
public ImagePageCurlView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);

    // Get the data from the XML AttributeSet
    {
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.PageCurlView);

        // Get data
        bEnableDebugMode = a.getBoolean(
                R.styleable.PageCurlView_enableDebugMode, bEnableDebugMode);
        mCurlSpeed = a.getInt(R.styleable.PageCurlView_curlSpeed,
                mCurlSpeed);
        mUpdateRate = a.getInt(R.styleable.PageCurlView_updateRate,
                mUpdateRate);
        mInitialEdgeOffset = a.getInt(
                R.styleable.PageCurlView_initialEdgeOffset,
                mInitialEdgeOffset);
        mCurlMode = a.getInt(R.styleable.PageCurlView_curlMode, mCurlMode);

        Log.i(TAG, "mCurlSpeed: " + mCurlSpeed);
        Log.i(TAG, "mUpdateRate: " + mUpdateRate);
        Log.i(TAG, "mInitialEdgeOffset: " + mInitialEdgeOffset);
        Log.i(TAG, "mCurlMode: " + mCurlMode);

        // recycle object (so it can be used by others)
        a.recycle();
    }

    ResetClipEdge();
}

/**
 * Initialize the view
 */
private final void init(Context context) {
    // Foreground text paint
    cInt=0;

    mTextPaint = new Paint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(16);
    mTextPaint.setColor(0xFF000000);

    // The shadow
    mTextPaintShadow = new TextPaint();
    mTextPaintShadow.setAntiAlias(true);
    mTextPaintShadow.setTextSize(16);
    mTextPaintShadow.setColor(0x00000000);

    // Cache the context
    mContext = new WeakReference<Context>(context);

    // Base padding
    setPadding(3, 3, 3, 3);

    // The focus flags are needed
    setFocusable(true);
    setFocusableInTouchMode(true);

    mMovement = new Vector2D(0, 0);
    mFinger = new Vector2D(0, 0);
    mOldMovement = new Vector2D(0, 0);

    // Create our curl animation handler
    mAnimationHandler = new FlipAnimationHandler();

    // Create our edge paint
    mCurlEdgePaint = new Paint();
    mCurlEdgePaint.setColor(Color.WHITE);
    mCurlEdgePaint.setAntiAlias(true);
    mCurlEdgePaint.setStyle(Paint.Style.FILL);
    mCurlEdgePaint.setShadowLayer(10, -5, 5, 0x99000000);

    // Set the default props, those come from an XML :D
    mCurlSpeed = 200;
    mUpdateRate = 33;
    mInitialEdgeOffset = 20;
    mCurlMode = 1;

    // LEGACY PAGE HANDLING!

    // Create pages

    if(ListingActivity.sFlag){

        ImageActivity.tv.setText(example[ListingActivity.sPosition]);
        // Create some sample images
        mForeground = BitmapFactory.decodeResource(getResources(),
                ImageActivity.ImageIds[ListingActivity.sPosition]);//HomeActivity.mPages.get(0);
        mBackground = BitmapFactory.decodeResource(getResources(),
                ImageActivity.ImageIds[ListingActivity.sPosition+1]);//HomeActivity.mPages.get(1);

    }
    else{

        ImageActivity.tv.setText(example[0]);
        // Create some sample images
        mForeground = BitmapFactory.decodeResource(getResources(),
                ImageActivity.ImageIds[0]);//HomeActivity.mPages.get(0);
        mBackground = BitmapFactory.decodeResource(getResources(),
                ImageActivity.ImageIds[1]);//HomeActivity.mPages.get(1);

    }


}

/**
 * Reset points to it's initial clip edge state
 */
public void ResetClipEdge() {
    // Set our base movement
    mMovement.x = mInitialEdgeOffset;
    mMovement.y = mInitialEdgeOffset;
    mOldMovement.x = 0;
    mOldMovement.y = 0;

    // Now set the points
    // TODO: OK, those points MUST come from our measures and
    // the actual bounds of the view!
    mA = new Vector2D(mInitialEdgeOffset, 0);
    mB = new Vector2D(this.getWidth(), this.getHeight());
    mC = new Vector2D(this.getWidth(), 0);
    mD = new Vector2D(0, 0);
    mE = new Vector2D(0, 0);
    mF = new Vector2D(0, 0);
    mOldF = new Vector2D(0, 0);

    // The movement origin point
    mOrigin = new Vector2D(this.getWidth(), 0);
}

/**
 * Return the context which created use. Can return null if the context has
 * been erased.
 */
private Context GetContext() {
    return mContext.get();
}

/**
 * See if the current curl mode is dynamic
 * 
 * @return TRUE if the mode is CURLMODE_DYNAMIC, FALSE otherwise
 */
public boolean IsCurlModeDynamic() {
    return mCurlMode == CURLMODE_DYNAMIC;
}

/**
 * Set the curl speed.
 * 
 * @param curlSpeed
 *            - New speed in px/frame
 * @throws IllegalArgumentException
 *             if curlspeed < 1
 */
public void SetCurlSpeed(int curlSpeed) {
    if (curlSpeed < 1)
        throw new IllegalArgumentException(
                "curlSpeed must be greated than 0");
    mCurlSpeed = curlSpeed;
}

/**
 * Get the current curl speed
 * 
 * @return int - Curl speed in px/frame
 */
public int GetCurlSpeed() {
    return mCurlSpeed;
}

/**
 * Set the update rate for the curl animation
 * 
 * @param updateRate
 *            - Fixed animation update rate in fps
 * @throws IllegalArgumentException
 *             if updateRate < 1
 */
public void SetUpdateRate(int updateRate) {
    if (updateRate < 1)
        throw new IllegalArgumentException(
                "updateRate must be greated than 0");
    mUpdateRate = updateRate;
}

/**
 * Get the current animation update rate
 * 
 * @return int - Fixed animation update rate in fps
 */
public int GetUpdateRate() {
    return mUpdateRate;
}

/**
 * Set the initial pixel offset for the curl edge
 * 
 * @param initialEdgeOffset
 *            - px offset for curl edge
 * @throws IllegalArgumentException
 *             if initialEdgeOffset < 0
 */
public void SetInitialEdgeOffset(int initialEdgeOffset) {
    if (initialEdgeOffset < 0)
        throw new IllegalArgumentException(
                "initialEdgeOffset can not negative");
    mInitialEdgeOffset = initialEdgeOffset;
}

/**
 * Get the initial pixel offset for the curl edge
 * 
 * @return int - px
 */
public int GetInitialEdgeOffset() {
    return mInitialEdgeOffset;
}


public void SetCurlMode(int curlMode) {
    if (curlMode != CURLMODE_SIMPLE && curlMode != CURLMODE_DYNAMIC)
        throw new IllegalArgumentException("Invalid curlMode");
    mCurlMode = curlMode;
}


public int GetCurlMode() {
    return mCurlMode;
}

/**
 * Enable debug mode. This will draw a lot of data in the view so you can
 * track what is happening
 * 
 * @param bFlag
 *            - boolean flag
 */
public void SetEnableDebugMode(boolean bFlag) {
    bEnableDebugMode = bFlag;
}

/**
 * Check if we are currently in debug mode.
 * 
 * @return boolean - If TRUE debug mode is on, FALSE otherwise.
 */
public boolean IsDebugModeEnabled() {
    return bEnableDebugMode;
}

/**
 * @see android.view.View#measure(int, int)
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int finalWidth, finalHeight;
    finalWidth = measureWidth(widthMeasureSpec);
    finalHeight = measureHeight(heightMeasureSpec);
    setMeasuredDimension(finalWidth, finalHeight);
}

/**
 * Determines the width of this view
 * 
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The width of the view, honoring constraints from measureSpec
 */
private int measureWidth(int measureSpec) {
    int result = 0;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        // We were told how big to be
        result = specSize;
    } else {
        // Measure the text
        result = specSize;
    }

    return result;
}

/**
 * Determines the height of this view
 * 
 * @param measureSpec
 *            A measureSpec packed into an int
 * @return The height of the view, honoring constraints from measureSpec
 */
private int measureHeight(int measureSpec) {
    int result = 0;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {
        // We were told how big to be
        result = specSize;
    } else {
        // Measure the text (beware: ascent is a negative number)
        result = specSize;
    }
    return result;
}



@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!bBlockTouchInput) {

        // Get our finger position
        mFinger.x = event.getX();
        mFinger.y = event.getY();
        int width = getWidth();

        // Depending on the action do what we need to
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mOldMovement.x = mFinger.x;
            mOldMovement.y = mFinger.y;

            // If we moved over the half of the display flip to next
            if (mOldMovement.x > (width >> 1)) {
                mMovement.x = mInitialEdgeOffset;
                mMovement.y = mInitialEdgeOffset;

                // Set the right movement flag
                bFlipRight = true;

            } else {
                // Set the left movement flag
                bFlipRight = false;

                // go to next previous page
                previousView();

                // Set new movement
                mMovement.x = IsCurlModeDynamic() ? width << 1 : width;
                mMovement.y = mInitialEdgeOffset;
            }

            break;
        case MotionEvent.ACTION_UP:
            bUserMoves = false;
            bFlipping = true;
            FlipAnimationStep();


            break;
        case MotionEvent.ACTION_MOVE:
            bUserMoves = true;

            // Get movement
            mMovement.x -= mFinger.x - mOldMovement.x;
            mMovement.y -= mFinger.y - mOldMovement.y;
            mMovement = CapMovement(mMovement, true);

            // Make sure the y value get's locked at a nice level
            if (mMovement.y <= 1)
                mMovement.y = 1;

            // Get movement direction
            if (mFinger.x < mOldMovement.x) {
                bFlipRight = true;
            } else {
                bFlipRight = false;
            }

            // Save old movement values
            mOldMovement.x = mFinger.x;
            mOldMovement.y = mFinger.y;

            // Force a new draw call
            DoPageCurl();
            this.invalidate();
            break;
        }

    }

    // TODO: Only consume event if we need to.
    return true;
}


private Vector2D CapMovement(Vector2D point, boolean bMaintainMoveDir) {
    // Make sure we never ever move too much
    if (point.distance(mOrigin) > mFlipRadius) {
        if (bMaintainMoveDir) {
            // Maintain the direction
            point = mOrigin.sum(point.sub(mOrigin).normalize()
                    .mult(mFlipRadius));
        } else {
            // Change direction
            if (point.x > (mOrigin.x + mFlipRadius))
                point.x = (mOrigin.x + mFlipRadius);
            else if (point.x < (mOrigin.x - mFlipRadius))
                point.x = (mOrigin.x - mFlipRadius);
            point.y = (float) (Math.sin(Math.acos(Math.abs(point.x
                    - mOrigin.x)
                    / mFlipRadius)) * mFlipRadius);
        }
    }
    return point;
}

/**
 * Execute a step of the flip animation
 */
public void FlipAnimationStep() {
    if (!bFlipping)
        return;

    int width = getWidth();

    // No input when flipping
    bBlockTouchInput = true;

    // Handle speed
    float curlSpeed = mCurlSpeed;
    if (!bFlipRight)
        curlSpeed *= -1;

    // Move us
    mMovement.x += curlSpeed;
    mMovement = CapMovement(mMovement, false);

    // Create values
    DoPageCurl();

    // Check for endings :D
    if (mA.x < 1 || mA.x > width - 1) {
        bFlipping = false;
        if (bFlipRight) {
            // SwapViews();
            nextView();
        }
        ResetClipEdge();

        // Create values
        DoPageCurl();

        // Enable touch input after the next draw event
        bEnableInputAfterDraw = true;
    } else {
        mAnimationHandler.sleep(mUpdateRate);
    }

    // Force a new draw call
    this.invalidate();
}

/**
 * Do the page curl depending on the methods we are using
 */
private void DoPageCurl() {
    if (bFlipping) {
        if (IsCurlModeDynamic())
            doDynamicCurl();
        else
            doSimpleCurl();

    } else {
        if (IsCurlModeDynamic())
            doDynamicCurl();
        else
            doSimpleCurl();
    }
}

/**
 * Do a simple page curl effect
 */
private void doSimpleCurl() {
    int width = getWidth();
    int height = getHeight();

    // Calculate point A
    mA.x = width - mMovement.x;
    mA.y = height;

    // Calculate point D
    mD.x = 0;
    mD.y = 0;
    if (mA.x > width / 2) {
        mD.x = width;
        mD.y = height - (width - mA.x) * height / mA.x;
    } else {
        mD.x = 2 * mA.x;
        mD.y = 0;
    }

    // Now calculate E and F taking into account that the line
    // AD is perpendicular to FB and EC. B and C are fixed points.
    double angle = Math
            .atan((height - mD.y) / (mD.x + mMovement.x - width));
    double _cos = Math.cos(2 * angle);
    double _sin = Math.sin(2 * angle);

    // And get F
    mF.x = (float) (width - mMovement.x + _cos * mMovement.x);
    mF.y = (float) (height - _sin * mMovement.x);

    // If the x position of A is above half of the page we are still not
    // folding the upper-right edge and so E and D are equal.
    if (mA.x > width / 2) {
        mE.x = mD.x;
        mE.y = mD.y;
    } else {
        // So get E
        mE.x = (float) (mD.x + _cos * (width - mD.x));
        mE.y = (float) -(_sin * (width - mD.x));
    }
}

/**
 * Calculate the dynamic effect, that one that follows the users finger
 */
private void doDynamicCurl() {
    int width = getWidth();
    int height = getHeight();

    // F will follow the finger, we add a small displacement
    // So that we can see the edge
    mF.x = width - mMovement.x + 0.1f;
    mF.y = height - mMovement.y + 0.1f;

    // Set min points
    if (mA.x == 0) {
        mF.x = Math.min(mF.x, mOldF.x);
        mF.y = Math.max(mF.y, mOldF.y);
    }

    // Get diffs
    float deltaX = width - mF.x;
    float deltaY = height - mF.y;

    float BH = (float) (Math.sqrt(deltaX * deltaX + deltaY * deltaY) / 2);
    double tangAlpha = deltaY / deltaX;
    double alpha = Math.atan(deltaY / deltaX);
    double _cos = Math.cos(alpha);
    double _sin = Math.sin(alpha);

    mA.x = (float) (width - (BH / _cos));
    mA.y = height;

    mD.y = (float) (height - (BH / _sin));
    mD.x = width;

    mA.x = Math.max(0, mA.x);
    if (mA.x == 0) {
        mOldF.x = mF.x;
        mOldF.y = mF.y;
    }

    // Get W
    mE.x = mD.x;
    mE.y = mD.y;

    // Correct
    if (mD.y < 0) {
        mD.x = width + (float) (tangAlpha * mD.y);
        mE.y = 0;
        mE.x = width + (float) (Math.tan(2 * alpha) * mD.y);
    }
}

/**
 * Swap between the fore and back-ground.
 */
@Deprecated
private void SwapViews() {
    Bitmap temp = mForeground;
    mForeground = mBackground;
    mBackground = temp;
}

/**
 * Swap to next view
 */
private void nextView() {


    int foreIndex = mIndex + 1;

    if (foreIndex >= ImageActivity.ImageIds.length) {
        foreIndex = 0;
    }

    ImageActivity.tv.setText(example[foreIndex]);

    int backIndex = foreIndex + 1;
    if (backIndex >= ImageActivity.ImageIds.length) {
        backIndex = 0;
    }
    mIndex = foreIndex;
    setViews(foreIndex, backIndex);
}

/**
 * Swap to previous view
 */
private void previousView() {
    int backIndex = mIndex;
    int foreIndex = backIndex - 1;
    if (foreIndex < 0) {
        foreIndex = ImageActivity.ImageIds.length - 1;
    }

    ImageActivity.tv.setText(example[foreIndex]);

    mIndex = foreIndex;
    setViews(foreIndex, backIndex);
}

/**
 * Set current fore and background
 * 
 * @param foreground
 *            - Foreground view index
 * @param background
 *            - Background view index
 */
private void setViews(int foreground, int background) {
    mForeground = BitmapFactory.decodeResource(getResources(),
            ImageActivity.ImageIds[foreground]);//HomeActivity.mPages.get(foreground);
    mBackground = BitmapFactory.decodeResource(getResources(),
            ImageActivity.ImageIds[background]);//HomeActivity.mPages.get(background);
}

// ---------------------------------------------------------------
// Drawing methods
// ---------------------------------------------------------------

@Override
protected void onDraw(Canvas canvas) {
    // Always refresh offsets
    mCurrentLeft = getLeft();
    mCurrentTop = getTop();

    // Translate the whole canvas
    // canvas.translate(mCurrentLeft, mCurrentTop);

    // We need to initialize all size data when we first draw the view
    if (!bViewDrawn) {
        bViewDrawn = true;
        onFirstDrawEvent(canvas);
    }

    canvas.drawColor(Color.WHITE);

    // Curl pages
    // DoPageCurl();

    // TODO: This just scales the views to the current
    // width and height. We should add some logic for:
    // 1) Maintain aspect ratio
    // 2) Uniform scale
    // 3) ...
    Rect rect = new Rect();
    rect.left = 0;
    rect.top = 0;
    rect.bottom = getHeight();
    rect.right = getWidth();

    // First Page render
    Paint paint = new Paint();

    // Draw our elements
    drawForeground(canvas, rect, paint);
    drawBackground(canvas, rect, paint);
    drawCurlEdge(canvas);

    // Draw any debug info once we are done
    if (bEnableDebugMode)
        drawDebug(canvas);

    // Check if we can re-enable input
    if (bEnableInputAfterDraw) {
        bBlockTouchInput = false;
        bEnableInputAfterDraw = false;
    }

    // Restore canvas
    // canvas.restore();
    this.setOnClickListener(this);
}

/**
 * Called on the first draw event of the view
 * 
 * @param canvas
 */
protected void onFirstDrawEvent(Canvas canvas) {

    mFlipRadius = getWidth();

    ResetClipEdge();
    DoPageCurl();
}

/**
 * Draw the foreground
 * 
 * @param canvas
 * @param rect
 * @param paint
 */
private void drawForeground(Canvas canvas, Rect rect, Paint paint) {
    canvas.drawBitmap(mForeground, null, rect, paint);

    // Draw the page number (first page is 1 in real life :D
    // there is no page number 0 hehe)
    drawPageNum(canvas, mIndex);
}

/**
 * Create a Path used as a mask to draw the background page
 * 
 * @return
 */
private Path createBackgroundPath() {
    Path path = new Path();
    path.moveTo(mA.x, mA.y);
    path.lineTo(mB.x, mB.y);
    path.lineTo(mC.x, mC.y);
    path.lineTo(mD.x, mD.y);
    path.lineTo(mA.x, mA.y);
    return path;
}

/**
 * Draw the background image.
 * 
 * @param canvas
 * @param rect
 * @param paint
 */
private void drawBackground(Canvas canvas, Rect rect, Paint paint) {
    Path mask = createBackgroundPath();

    // Save current canvas so we do not mess it up
    canvas.save();
    canvas.clipPath(mask);
    canvas.drawBitmap(mBackground, null, rect, paint);

    // Draw the page number (first page is 1 in real life :D
    // there is no page number 0 hehe)
    drawPageNum(canvas, mIndex);

    canvas.restore();
}

/**
 * Creates a path used to draw the curl edge in.
 * 
 * @return
 */
private Path createCurlEdgePath() {
    Path path = new Path();
    path.moveTo(mA.x, mA.y);
    path.lineTo(mD.x, mD.y);
    path.lineTo(mE.x, mE.y);
    path.lineTo(mF.x, mF.y);
    path.lineTo(mA.x, mA.y);
    return path;
}

private void drawCurlEdge(Canvas canvas) {
    Path path = createCurlEdgePath();
    canvas.drawPath(path, mCurlEdgePaint);
}

private void drawPageNum(Canvas canvas, int pageNum) {
    mTextPaint.setColor(Color.WHITE);
    String pageNumText = "- " + pageNum + " -";
    drawCentered(canvas, pageNumText,
            canvas.getHeight() - mTextPaint.getTextSize() - 5, mTextPaint,
            mTextPaintShadow);
}

public static void drawTextShadowed(Canvas canvas, String text, float x,
        float y, Paint textPain, Paint shadowPaint) {
    canvas.drawText(text, x - 1, y, shadowPaint);
    canvas.drawText(text, x, y + 1, shadowPaint);
    canvas.drawText(text, x + 1, y, shadowPaint);
    canvas.drawText(text, x, y - 1, shadowPaint);
    canvas.drawText(text, x, y, textPain);
}

public static void drawCentered(Canvas canvas, String text, float y,
        Paint textPain, Paint shadowPaint) {
    float posx = (canvas.getWidth() - textPain.measureText(text)) / 2;
    drawTextShadowed(canvas, text, posx, y, textPain, shadowPaint);
}

/**
 * Draw debug info
 * 
 * @param canvas
 */
private void drawDebug(Canvas canvas) {
    float posX = 10;
    float posY = 20;

    Paint paint = new Paint();
    paint.setStrokeWidth(5);
    paint.setStyle(Style.STROKE);

    paint.setColor(Color.BLACK);
    canvas.drawCircle(mOrigin.x, mOrigin.y, getWidth(), paint);

    paint.setStrokeWidth(3);
    paint.setColor(Color.RED);
    canvas.drawCircle(mOrigin.x, mOrigin.y, getWidth(), paint);

    paint.setStrokeWidth(5);
    paint.setColor(Color.BLACK);
    canvas.drawLine(mOrigin.x, mOrigin.y, mMovement.x, mMovement.y, paint);

    paint.setStrokeWidth(3);
    paint.setColor(Color.RED);
    canvas.drawLine(mOrigin.x, mOrigin.y, mMovement.x, mMovement.y, paint);

    posY = debugDrawPoint(canvas, "A", mA, Color.RED, posX, posY);
    posY = debugDrawPoint(canvas, "B", mB, Color.GREEN, posX, posY);
    posY = debugDrawPoint(canvas, "C", mC, Color.BLUE, posX, posY);
    posY = debugDrawPoint(canvas, "D", mD, Color.CYAN, posX, posY);
    posY = debugDrawPoint(canvas, "E", mE, Color.YELLOW, posX, posY);
    posY = debugDrawPoint(canvas, "F", mF, Color.LTGRAY, posX, posY);
    posY = debugDrawPoint(canvas, "Mov", mMovement, Color.DKGRAY, posX,
            posY);
    posY = debugDrawPoint(canvas, "Origin", mOrigin, Color.MAGENTA, posX,
            posY);
    posY = debugDrawPoint(canvas, "Finger", mFinger, Color.GREEN, posX,
            posY);


}

private float debugDrawPoint(Canvas canvas, String name, Vector2D point,
        int color, float posX, float posY) {
    return debugDrawPoint(canvas, name + " " + point.toString(), point.x,
            point.y, color, posX, posY);
}

private float debugDrawPoint(Canvas canvas, String name, float X, float Y,
        int color, float posX, float posY) {
    mTextPaint.setColor(color);
    drawTextShadowed(canvas, name, posX, posY, mTextPaint, mTextPaintShadow);
    Paint paint = new Paint();
    paint.setStrokeWidth(5);
    paint.setColor(color);
    canvas.drawPoint(X, Y, paint);
    return posY + 15;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    System.out.println("testing click");


}





}

Its working now When I add onclicklistener in every block and change return true to false in ontouchevent. But now ontouch is not working because i change its return type. How can I fix it?

  • 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-06-14T02:24:20+00:00Added an answer on June 14, 2026 at 2:24 am

    The method onTouchEvent is defined in the View and you are just overriding it. Your setOnTouchListener(this); has nothing to do with it.

    Add in all constructors the setOnClickListener(this); and you should be good to go.

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

Sidebar

Related Questions

I'm working on an Android application that will send MMS internally without using the
Now I am working on a Android application. In my app i have to
I am working on an android application. In my app I am using nottification.
I'm working with FlashBuilder 4.6 to develop Android app. In the application there is
I am working on Android Application. Now I have requirement of search the entered
I am working in an android application and I want to work fetch details
I am working on an android application which is sort of an e-reader but
I am working on an Android application that needs to determine the current tee
I am working on an Android application that shows a map with the user's
I am working on an android application. In my app i have to open

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.