@Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   if (mDisplay != null) {
     mDisplay.draw(canvas);
   }
 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       mOldX = event.getX();
       mOldY = event.getY();
       return true;
     case MotionEvent.ACTION_MOVE:
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
       float x = mDisplay.getPercentX() * getMeasuredWidth();
       float y = mDisplay.getPercentY() * getMeasuredHeight();
       float deltaX = event.getX() - mOldX;
       float deltaY = event.getY() - mOldY;
       mDisplay.setPercentX((x + deltaX) / getMeasuredWidth());
       mDisplay.setPercentY((y + deltaY) / getMeasuredHeight());
       invalidate();
       postInvalidate();
       break;
   }
   return super.onTouchEvent(event);
 }
  private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LSystemView);

    // Instantiate Display
    String className = typedArray.getString(R.styleable.LSystemView_ls_display_class);
    if (!TextUtils.isEmpty(className)) {
      try {
        mDisplay = (Display) Class.forName(className).newInstance();
      } catch (Exception e) {
        Log.e(TAG, "", e);
      }
    }

    /* Display properties */
    if (mDisplay != null) {
      mDisplay.setDirection(
          typedArray.getFloat(R.styleable.LSystemView_ls_direction, mDisplay.getDirection()));
      mDisplay.setAngle(typedArray.getFloat(R.styleable.LSystemView_ls_angle, mDisplay.getAngle()));
      mDisplay.setStep(typedArray.getFloat(R.styleable.LSystemView_ls_step, mDisplay.getStep()));
      mDisplay.setIterations(
          typedArray.getInteger(R.styleable.LSystemView_ls_iterations, mDisplay.getIterations()));
      mDisplay.setPercentX(
          typedArray.getFraction(
              R.styleable.LSystemView_ls_position_x, 1, 1, mDisplay.getPercentX()));
      mDisplay.setPercentY(
          typedArray.getFraction(
              R.styleable.LSystemView_ls_position_y, 1, 1, mDisplay.getPercentY()));
      mDisplay.setColor(
          typedArray.getColor(R.styleable.LSystemView_ls_paint_color, mDisplay.getColor()));
    }

    typedArray.recycle();
  }