Android add undo feature to finger paint example in api demo

后端 未结 3 1090
时光取名叫无心
时光取名叫无心 2020-12-16 08:58

hi i am trying to add undo feature to finger paint example given in API demo. but i am not able to achieve it. So far i have added all the path that are drawn in a list and

3条回答
  •  旧时难觅i
    2020-12-16 09:27

    When you drawing line for the current process like at now use drawing the like using it finger now store this points into temp_array list. now add this temp_array list into the main array list which will draw all sub array list point like wise here.

    List main_Points = new ArrayList>();
    List temp_point; // this one is for the current drawing
    

    like onTouch()

    onTouch(MotionEvent event){
         int x = (int) event.getX();
         int y = (int) event.getY();
    
         if(event.getAction==MotionEvent.DOWN){
               temp_point = new ArrayList();
               temp_point.add(new Point(x,y);
         }else if(event.getAction==MotionEvent.MOVE){
               if(temp_point!=null)
                  temp_point.add(new Point(x,y);
         }else if(event.getAction==MotionEvent.UP){
               mainPoint.add(temp_point);
               temp_point = null;
         }
         return true;
    }
    

    always re-initialize into onTouch() method in down event and get all the point at move time get the point and store into this list now at up event time store this array list into main list.

    now if you want to undo last or more you can just remove last add temp_point list from the mainPoint array List

提交回复
热议问题