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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:30:51+00:00 2026-06-14T16:30:51+00:00

In my android application user do signature in the form in my app. the

  • 0

In my android application user do signature in the form in my app. the signature has to be edit , cleer, save. i do save and clear. but edit not work i used code below

mContent = (LinearLayout) findViewById(R.id.linearLayout);
mSignature = new signature(this, null);
mSignature.setBackgroundColor(Color.WHITE);
mContent.addView(mSignature, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
mClear = (Button)findViewById(R.id.clear);
mGetSign = (Button)findViewById(R.id.getsign);
mGetSign.setEnabled(false);
mCancel = (Button)findViewById(R.id.cancel);
mView = mContent;

mClear.setOnClickListener(new OnClickListener() 
    {        
        public void onClick(View v) 
        {
            Log.v("log_tag", "Panel Cleared");

            mSignature.clear();
            mGetSign.setEnabled(false);
        }
    });

    mGetSign.setOnClickListener(new OnClickListener() 
    {        
        public void onClick(View v) 
        {
            Log.v("log_tag", "Panel Saved");

                mView.setDrawingCacheEnabled(true);
                mSignature.save(mView);
                Bundle b = new Bundle();
                b.putString("status", "done");
                b.putParcelable("data", mBitmap);
                Intent intent = new Intent();
                intent.putExtras(b);
                setResult(RESULT_OK,intent);   
                finish();
            }

    });

    mCancel.setOnClickListener(new OnClickListener() 
    {        
        public void onClick(View v) 
        {
            Log.v("log_tag", "Panel Canceled");
            Bundle b = new Bundle();
            b.putString("status", "cancel");
            Intent intent = new Intent();
            intent.putExtras(b);
            setResult(RESULT_OK,intent);  
            finish();
        }
    });

}

@Override
protected void onDestroy() {
    Log.w("GetSignature", "onDestory");
    super.onDestroy();
}


public class signature extends View 
    {
        private static final float STROKE_WIDTH = 5f;
        private static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;
        private Paint paint = new Paint();
        private Path path = new Path();

        private float lastTouchX;
        private float lastTouchY;
        private final RectF dirtyRect = new RectF();

        public signature(Context context, AttributeSet attrs) 
        {
            super(context, attrs);
            paint.setAntiAlias(true);
            paint.setColor(Color.BLACK);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeJoin(Paint.Join.ROUND);
            paint.setStrokeWidth(STROKE_WIDTH);
        }

        public void save(View v) 
        {
            Log.v("log_tag", "Width: " + v.getWidth());
            Log.v("log_tag", "Height: " + v.getHeight());


            if(mBitmap == null)
            {
                mBitmap =  Bitmap.createBitmap (mContent.getWidth(), mContent.getHeight(), Bitmap.Config.RGB_565);;

            }


            Canvas canvas = new Canvas(mBitmap);

            try
            {
                FileOutputStream mFileOutStream = new FileOutputStream(mypath);

                v.draw(canvas); 
                mBitmap.compress(Bitmap.CompressFormat.PNG, 90, mFileOutStream); 

                mFileOutStream.flush();
                mFileOutStream.close();

               // String url = Images.Media.insertImage(getContentResolver(), mBitmap, "title", null);
               // Log.v("log_tag","url: " + url);
                //In case you want to delete the file
                //boolean deleted = mypath.delete();
                //Log.v("log_tag","deleted: " + mypath.toString() + deleted);
                //If you want to convert the image to string use base64 converter

            }
            catch(Exception e) 
            { 
                Log.v("log_tag", e.toString()); 
            } 
        }

        public void clear() 
        {
            path.reset();
          invalidate();
        }

        @Override
        protected void onDraw(Canvas canvas) 
        {
            canvas.drawPath(path, paint);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) 
        {
            float eventX = event.getX();
            float eventY = event.getY();
            mGetSign.setEnabled(true);

            switch (event.getAction()) 
            {
            case MotionEvent.ACTION_DOWN:
                path.moveTo(eventX, eventY);
                lastTouchX = eventX;
                lastTouchY = eventY;
                return true;

            case MotionEvent.ACTION_MOVE:

            case MotionEvent.ACTION_UP:

                resetDirtyRect(eventX, eventY);
                int historySize = event.getHistorySize();
                for (int i = 0; i < historySize; i++) 
                {
                    float historicalX = event.getHistoricalX(i);
                    float historicalY = event.getHistoricalY(i);
                    expandDirtyRect(historicalX, historicalY);
                    path.lineTo(historicalX, historicalY);
                }
                path.lineTo(eventX, eventY);
                break;

            default:
                debug("Ignored touch event: " + event.toString());
                return false;
            }

            invalidate((int) (dirtyRect.left - HALF_STROKE_WIDTH),
                    (int) (dirtyRect.top - HALF_STROKE_WIDTH),
                    (int) (dirtyRect.right + HALF_STROKE_WIDTH),
                    (int) (dirtyRect.bottom + HALF_STROKE_WIDTH));

            lastTouchX = eventX;
            lastTouchY = eventY;

            return true;
        }

        private void debug(String string){
        }

        private void expandDirtyRect(float historicalX, float historicalY) 
        {
            if (historicalX < dirtyRect.left) 
            {
                dirtyRect.left = historicalX;
            } 
            else if (historicalX > dirtyRect.right) 
            {
                dirtyRect.right = historicalX;
            }

            if (historicalY < dirtyRect.top) 
            {
                dirtyRect.top = historicalY;
            } 
            else if (historicalY > dirtyRect.bottom) 
            {
                dirtyRect.bottom = historicalY;
            }
        }

        private void resetDirtyRect(float eventX, float eventY) 
        {
            dirtyRect.left = Math.min(lastTouchX, eventX);
            dirtyRect.right = Math.max(lastTouchX, eventX);
            dirtyRect.top = Math.min(lastTouchY, eventY);
            dirtyRect.bottom = Math.max(lastTouchY, eventY);
        }
    }
  • 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-14T16:30:52+00:00Added an answer on June 14, 2026 at 4:30 pm

    Probably this Custom View will help. In your XML, just use me.other.SignatureView

    package me.other;
    
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Path;
    import android.os.SystemClock;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.view.View;
    
    /**
     * A simple view to capture a path traced onto the screen. Initially intended to be used to captures signatures.
     * 
     * @author Andrew Crichton
     * @version 0.1
     */
    public class SignatureView extends View {
        @SuppressWarnings("unused")
        private Path mPath;
        private Paint mPaint; 
        private Paint bgPaint = new Paint(Color.TRANSPARENT);
    
        private Bitmap mBitmap;
        private Canvas mCanvas;
    
        private float curX, curY;
    
        private static final int TOUCH_TOLERANCE = 4;
        private static final int STROKE_WIDTH = 4;
    
        public SignatureView(Context context) {
            super(context);
            init();
        }
        public SignatureView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
        public SignatureView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init();
        }
        private void init() {
            setFocusable(true);
            mPath = new Path();
            mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            mPaint.setColor(Color.WHITE);
            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setStrokeWidth(STROKE_WIDTH);
        }
        public void setSigColor(int color) {
            mPaint.setColor(color);
        }
        public void setSigColor(int a, int red, int green, int blue) {
            mPaint.setARGB(a, red, green, blue);
        }
        public boolean clearSignature() {
            if (mBitmap != null)
                createFakeMotionEvents();
            if (mCanvas != null) {
                mCanvas.drawColor(Color.BLACK);
                mCanvas.drawPaint(bgPaint);
                mPath.reset();
                invalidate();
            }
            else {
                return false;
            }
            return true;
        }
        public Bitmap getImage() {
            return this.mBitmap;
        }
        public void setImage(Bitmap bitmap) {
            this.mBitmap = bitmap;
            this.invalidate();
        }
        @Override
        protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
            int bitmapWidth = mBitmap != null ? mBitmap.getWidth() : 0;
            int bitmapHeight = mBitmap != null ? mBitmap.getWidth() : 0;
            if (bitmapWidth >= width && bitmapHeight >= height) 
                return;
            if (bitmapWidth < width) 
                bitmapWidth = width;
            if (bitmapHeight < height) 
                bitmapHeight = height;
            Bitmap newBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
            Canvas newCanvas = new Canvas();
            newCanvas.setBitmap(newBitmap);
            if (mBitmap != null) 
                newCanvas.drawBitmap(mBitmap, 0, 0, null);
            mBitmap = newBitmap;
            mCanvas = newCanvas;
        }
        private void createFakeMotionEvents() {
            MotionEvent downEvent = MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis()+100, MotionEvent.ACTION_DOWN, 1f, 1f ,0);
            MotionEvent upEvent = MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis()+100, MotionEvent.ACTION_UP, 1f, 1f ,0);
            onTouchEvent(downEvent);
            onTouchEvent(upEvent);
        }
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.BLACK);
            canvas.drawBitmap(mBitmap, 0, 0, mPaint); 
            canvas.drawPath(mPath, mPaint);
        }
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            float x = event.getX();
            float y = event.getY();
    
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                touchDown(x, y);
                break;
            case MotionEvent.ACTION_MOVE:
                touchMove(x, y);
                break;
            case MotionEvent.ACTION_UP:
                touchUp();
                break;
            }
            invalidate();
            return true;
        }
        /**----------------------------------------------------------
         * Private methods
         **---------------------------------------------------------*/
    
        private void touchDown(float x, float y) {
            mPath.reset();
            mPath.moveTo(x, y);
            curX = x;
            curY = y;
        }
    
        private void touchMove(float x, float y) {
            float dx = Math.abs(x - curX);
            float dy = Math.abs(y - curY);
            if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
                mPath.quadTo(curX, curY, (x + curX)/2, (y + curY)/2);
                curX = x;
                curY = y;
            }
        }
    
        private void touchUp() {
            mPath.lineTo(curX, curY);
            if (mCanvas == null) {
                mCanvas = new Canvas();
                mCanvas.setBitmap(mBitmap);
            }
            mCanvas.drawPath(mPath, mPaint);
            mPath.reset();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Android application has a form that the user has to fill in. I
In order for the user to control the volume , my android application has
Steps: User starts app from Android Market application User clicks Start child stack: ActivityMain
hi working with simple android application that shows address of the user but this
In my android application ,user has to register by agreeing the terms and condition
Im using google analytics to track the user in my android application, but in
I need to capture user signature in my application and save it into sdcard
I am making an android application to show the position of a user on
I am developing an Android application which always listen voice from user. It works
I'm writing an android application which purpouse is to determine the user position via

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.