0

I have the following Java class:

public class TouchEventView extends View {
private Paint paint = new Paint();
private Path path = new Path();

public TouchEventView(Context ctx, AttributeSet attrs)  {
    super(ctx, attrs);

    paint.setAntiAlias(true);
    paint.setColor(Color.BLACK);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(5f);
}

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

@Override
public boolean onTouchEvent(MotionEvent event)  {
    float xPos = event.getX();
    float yPos = event.getY();

    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            path.moveTo(xPos, yPos);
            return true;

        case MotionEvent.ACTION_MOVE:
            path.lineTo(xPos, yPos);
            System.out.println("X: " + xPos + " Y: " + yPos);
            break;
        case MotionEvent.ACTION_UP:
            break; //do nothing, finger up
        default:
            return false;
    }

    //schedule a repaint
    invalidate();
    return true;
}

I want to have an activity, have its own layout and that layout having a couple of buttons, along with this view above as part of the activity's design.

Current layout for this class:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_enter_pw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.islarf6546.gmail.lock_screen_settings.Enter_Pw">




<TextView
    android:text="Draw new password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/textView" />

<!--<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"></RelativeLayout>
-->
<Button
    android:text="Submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/button3"
    android:elevation="0dp" />
</RelativeLayout>
double-beep
  • 3,889
  • 12
  • 24
  • 35
Islarf
  • 149
  • 3
  • 11
  • Possible duplicate of [Declaring a custom android UI element using XML](http://stackoverflow.com/questions/2695646/declaring-a-custom-android-ui-element-using-xml) – litelite Dec 20 '16 at 20:54
  • @litelite Not sure, I could not use this question to solve my problem. – Islarf Dec 20 '16 at 21:43
  • @litelite this question still isn't answer, as that has still not answered my question, and I am yet to find a solution – Islarf Dec 21 '16 at 14:39

0 Answers0