title: Create canvas path to avoid objects automatically
body: <p>I was working on a canvas path and require to implement more buttons and potentially images in the future. I know how to hard-code to avoid the objects that I do not require, however is there a way to do this easier? Potentially a single line of code...</p>
  
  <p>So basically I have currently created a path to go from Button1 to Button2, without it passing through Button3 but rather going around it. The line I created I have hard-coded this to say go around Button3 but is there an easier way to do this, especially if there are more buttons in the future?</p>
  
  <p><a href="https://i.stack.imgur.com/Cp3oa.png" rel="nofollow noreferrer">Current hard-coded solution image</a></p>
  
  <p>DrawView: </p>
  
  <pre><code>public class DrawView extends View {
  Paint paint = new Paint();
  View startView;
  View endView;
  View obstacle;
  Path path = new Path();
  
  public DrawView(Context context, View startView, View endView, View obstacle) {
      super(context);
      paint.setColor(Color.parseColor("#4CAF50"));
      paint.setStyle(Paint.Style.STROKE);
      paint.setStrokeWidth(15);
      this.startView = startView;
      this.endView = endView;
      this.obstacle = obstacle;
  
      obstacle.setPadding(50, 50, 50, 50);
  
  }
  
  @SuppressLint("NewApi")
  public void onDraw(Canvas canvas) {
  
      path.moveTo(startView.getX() + startView.getWidth() / 2, startView.getY() + startView.getHeight() / 2);
      path.lineTo(obstacle.getX() + obstacle.getWidth() / 2, obstacle.getY());
      path.moveTo(obstacle.getX() + obstacle.getWidth() / 2, obstacle.getY());
      path.lineTo(obstacle.getX() + obstacle.getWidth(), obstacle.getY());
      path.moveTo(obstacle.getX() + obstacle.getWidth(), obstacle.getY());
      path.lineTo(obstacle.getX() + obstacle.getWidth(), obstacle.getY() + obstacle.getHeight());
      path.moveTo(obstacle.getX() + obstacle.getWidth(), obstacle.getY() + obstacle.getHeight());
      path.lineTo(obstacle.getX() + obstacle.getWidth() / 2, obstacle.getY() + obstacle.getHeight());
      path.moveTo(obstacle.getX() + obstacle.getWidth() / 2, obstacle.getY() + obstacle.getHeight());
      path.lineTo(endView.getX() + endView.getWidth() / 2, endView.getY() + endView.getHeight() / 2);
  
  
      canvas.drawPath(path, paint);
  
  
  
  }
  
  
  }
  </code></pre>
  
  <p>MainActivity: </p>
  
  <pre><code>public class MainActivity extends Activity {
  
      DrawView drawView;
      Button b1, b2, b3, clear;
      RelativeLayout rl;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          b1 = findViewById(R.id.Button1);
          b2 = findViewById(R.id.Button2);
          b3 = findViewById(R.id.Button3);
          clear = findViewById(R.id.clear_button);
  
          rl = findViewById(R.id.rl);
  
          b1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  drawView = new DrawView(MainActivity.this, b1, b2, b3);
                  rl.addView(drawView);
              }
          });
  
  
          clear.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  rl.removeAllViewsInLayout();
              }
          });
  
  
      }
  
  }
  </code></pre>
  
  <p>XML:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context="com.example.fyp.linecreator.MainActivity"&gt;
  
  
      &lt;RelativeLayout
          android:id="@+id/rl"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;Button
          android:id="@+id/Button2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerVertical="true"
          android:layout_marginLeft="100dp"
          android:layout_marginStart="100dp"
          android:layout_marginTop="40dp"
          android:text="Button2" /&gt;
  
      &lt;Button
          android:id="@+id/Button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/Button2"
          android:layout_alignParentTop="true"
          android:layout_marginLeft="40dp"
          android:layout_marginTop="4dp"
          android:text="Button1"
          android:layout_marginStart="40dp"
          android:layout_alignStart="@+id/Button2" /&gt;
  
      &lt;Button
          android:id="@+id/Button3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/Button2"
          android:layout_alignLeft="@+id/Button2"
          android:layout_marginBottom="23dp"
          android:layout_marginLeft="35dp"
          android:text="Button3"
          android:layout_alignStart="@+id/Button2"
          android:layout_marginStart="35dp" /&gt;
  
      &lt;Button
          android:id="@+id/clear_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Clear" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>