-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeFragment.java
59 lines (49 loc) · 2.04 KB
/
HomeFragment.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
package ca.uwaterloo.cs349;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
public class HomeFragment extends Fragment {
private SharedViewModel mViewModel;
Context context;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
mViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
context = this.getContext();
View root = inflater.inflate(R.layout.fragment_home, container, false);
ViewGroup canvas_view_group = root.findViewById(R.id.canvas_region);
final ViewGroup top_display = root.findViewById(R.id.top_display);
final Button resetBtn = root.findViewById(R.id.reset_button);
final Button recognizeBtn = root.findViewById(R.id.recognize_button);
final DrawingView drawingView = new DrawingView(this.getContext());
drawingView.addButton(resetBtn);
drawingView.addButton(recognizeBtn);
canvas_view_group.addView(drawingView);
recognizeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
top_display.removeAllViews();
for(LinearLayout layout : mViewModel.lookUp(drawingView.getPoints(), context)) {
top_display.addView(layout);
}
}
});
resetBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
top_display.removeAllViews();
drawingView.clearView();
}
});
return root;
}
}