» »

[Android] Undo/redo system izgubi barvo in velikost

[Android] Undo/redo system izgubi barvo in velikost

messi ::

Lep pozdrav vsem, imam sledeč problem...
Če spremenim barvo ali širino črte/kvadrata/ karkoli, in pritisnem gumb back se vse spremenijo v trenutno širino,..
Ne vem kako bi hranil tako da bi vse stvari obstale, le ta bi izginila, Če ima kdo kako idejo predlog bi prosil, kako to rešiti,..Če se da čimprej, obenem pa pošiljam izvleček kode.

Proti koncu se undo/redo nahaja, vmes so le inicializacije in ostale zadeve.
DrawHandler.java


 
public class DrawHandler {
       
        public Shape mCurrentShape;
        public SHAPES SELECTED_SHAPE = SHAPES.FREEHAND;
        public Paint mPaint;
        public Paint undopaint[];
        public Paint mErasePaint;
        public Paint mCurrentPaint;
        public Panel mPanel;
        public Point mDownPoint;
   
        // static so it will note be destroyed during screen rotations etc..
        private ArrayList<Path> GRAPHICOBJECTS;
        private ArrayList<Path> undonePaths ; 
       // private ArrayList<Path> undonePaths ; 
 
        private OnDrawListener mOnDrawListener;

        public interface OnDrawListener {
              public void onDrawShape(Shape shape, Paint paint); // narišeš shape dokončno
              public void onDrawShapeTemp(Shape shape, Paint paint); // narišeš shape, in ga potem ko je narisan, izbrišeš, če shape ni freehand
              public void onDrawAll(ArrayList<Path>  paths, Paint paint); 
        }
 
    
 
        public DrawHandler() {
                initPaint();
        }
 
        public void setOnDrawListener(OnDrawListener onDrawListener) {
                mOnDrawListener = onDrawListener;
        }
        
        
 
        public Paint getPaint() {
                return mPaint;
        }
       
        public Paint getErasePaint() {
                return mErasePaint;
        }
       
        private void initPaint() {
               
                GRAPHICOBJECTS = new ArrayList<Path>();
                undonePaths = new ArrayList<Path>();
 
                mPaint = new Paint();
                mErasePaint=new Paint();
 
                mPaint.setDither(true);
                mPaint.setColor(Color.rgb(100, 100, 100));
                mPaint.setStyle(Paint.Style.STROKE);
                mPaint.setStrokeJoin(Paint.Join.ROUND);
                mPaint.setStrokeCap(Paint.Cap.ROUND);
                mErasePaint.setDither(true);
                mErasePaint.setColor(Color.rgb(255, 255, 255));
                mErasePaint.setStyle(Paint.Style.STROKE);
                mErasePaint.setStrokeJoin(Paint.Join.ROUND);
                mErasePaint.setStrokeCap(Paint.Cap.ROUND);
                mErasePaint.setStrokeWidth(15);
                setBrushWidth(6);
        }
 
        public void setColor(int color) {
                mPaint.setColor(color);
                
        }
 
        public void setEraseColor(int barva) {
                mErasePaint.setColor(barva);
        }
       
        public void setBrushWidth(int bwidth) {
                mPaint.setStrokeWidth(bwidth);
              //  mErasePaint = new Paint(mPaint);
                //mErasePaint.setARGB(255, 255, 255, 255);
        }
 
        public void setShape(SHAPES shape) {
                SELECTED_SHAPE = shape;
        }
    
   
       
        public void handleTouchEvent(MotionEvent event) {
               
                Point point = new Point(event.getX(), event.getY());
               
                if(SELECTED_SHAPE == SHAPES.ERASE)
                {   mCurrentPaint = mErasePaint;
               
                }
                else
                        mCurrentPaint = mPaint;
               
                switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                        mDownPoint = point;
                        break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_MOVE:
                        setCurrentShape(SELECTED_SHAPE, point);
                        if(mOnDrawListener != null) {
                                if(event.getAction() == MotionEvent.ACTION_MOVE) {
                                        mOnDrawListener.onDrawShapeTemp(mCurrentShape, mCurrentPaint);
                                } else {
                                        mOnDrawListener.onDrawShape(mCurrentShape, mCurrentPaint);
                                }
                                
                        }
                       
                        break;
               
                }
                if(event.getAction() == MotionEvent.ACTION_UP) {
                        GRAPHICOBJECTS.add(mCurrentShape.getPath());
                    //    undopaint.length;
                        mCurrentShape = null;
                }
               
        }

    	public void back() {
    		if(GRAPHICOBJECTS.size()>0)
			{
    		//undonePaths.add(GRAPHICOBJECTS.size()-1,;
    		undonePaths.add(GRAPHICOBJECTS.remove(GRAPHICOBJECTS.size()-1));
    		// GRAPHICOBJECTS.addAll(undonePaths);
    		if(mOnDrawListener != null) {
    		    mOnDrawListener.onDrawAll( GRAPHICOBJECTS, mCurrentPaint);
    		 //   mPanel.invalidate();
    //	GRAPHICOBJECTS.remove(GRAPHICOBJECTS.size()-1);
    		    		      
    		//  mPanel.back();   
    		//invalidate();
    		}}
    		}

		public void next() {
			// TODO Auto-generated method stub
			if(undonePaths.size()>0)
			{
			GRAPHICOBJECTS.add(undonePaths.remove(undonePaths.size()-1));
    		// GRAPHICOBJECTS.addAll(undonePaths);
    		if(mOnDrawListener != null) {
    		    mOnDrawListener.onDrawAll( GRAPHICOBJECTS, mCurrentPaint);
    		    }}
		}

 


Panel.java

public void onDrawAll(ArrayList<Path> paths, Paint paint) {
	// TODO Auto-generated method stub
	 prepareBitmaps();
     synchronized (mCanvas) {
    	 mCanvas.drawARGB(255, 255, 255, 255); // "pobriši" vse 
         mCanvas.drawARGB(255, 255,255, 255); // "pobriši" vse 
    	  for(Path path : paths)
              mCanvas.drawPath(path , paint);
      }
     // updateBitmap(tmpCanvas, tmpBitmap,paths, paint);
     synchronized (mBitmap) {
        // tmpCanvas.drawPath(paths, paint);
         drawBitmap(mBitmap);
 }
	
}


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[Android] Nov tip shranjevanja slike

Oddelek: Programiranje
142194 (1318) urosz
»

[Android] Splošno

Oddelek: Programiranje
352012 (1142) piki12
»

Programiranje problem android

Oddelek: Programiranje
51179 (944) g333kk
»

Android zamenjava pogledov

Oddelek: Programiranje
61086 (907) c00L3r
»

android črta

Oddelek: Programiranje
412411 (1682) g333kk

Več podobnih tem