-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateGesture.java
79 lines (67 loc) · 2.9 KB
/
UpdateGesture.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package ca.uwaterloo.cs349;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
public class UpdateGesture {
private SharedViewModel mViewModel;
public UpdateGesture(final ViewGroup parent, final ViewGroup update, SharedViewModel viewModel, Context context, final int index) {
this.mViewModel = viewModel;
final Button okBtn = new Button(context);
okBtn.setText("OK");
final Button clearBtn = new Button(context);
clearBtn.setText("CLEAR");
final Button backBtn = new Button(context);
backBtn.setText("BACK");
final DrawingView drawingView = new DrawingView(context);
update.removeAllViews();
parent.removeAllViews();
parent.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
LinearLayout topButton = new LinearLayout(context);
topButton.setGravity(Gravity.CENTER_HORIZONTAL);
LinearLayout canvas_view_group = new LinearLayout(context);
canvas_view_group.setOrientation(LinearLayout.VERTICAL);
drawingView.addButton(okBtn);
drawingView.addButton(clearBtn);
topButton.addView(okBtn);
topButton.addView(clearBtn);
topButton.addView(backBtn);
parent.addView(topButton);
parent.addView(canvas_view_group);
canvas_view_group.addView(drawingView);
canvas_view_group.getLayoutParams().width = LinearLayout.LayoutParams.MATCH_PARENT;
canvas_view_group.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
clearBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawingView.clearView();
}
});
okBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
update.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
parent.removeAllViews();
mViewModel.update(index, drawingView.getPoints());
drawingView.clearView();
}
});
backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
update.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
parent.removeAllViews();
mViewModel.getUpdate().setValue(!mViewModel.getUpdate().getValue());
}
});
}
}