-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity2.java
More file actions
107 lines (93 loc) · 4.43 KB
/
Copy pathMainActivity2.java
File metadata and controls
107 lines (93 loc) · 4.43 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package io.github.aleksandarharalanov.registrationapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
public class MainActivity2 extends AppCompatActivity {
private EditText serialNumberEditText;
private EditText descriptionEditText;
private CheckBox statusCheckBox;
private Button nextButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration_details);
serialNumberEditText = findViewById(R.id.editTextText2);
statusCheckBox = findViewById(R.id.checkBox);
descriptionEditText = findViewById(R.id.editTextText3);
nextButton = findViewById(R.id.Button1);
serialNumberEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = s.toString().trim();
boolean isValidSerialNumber = text.length() == 5 && text.startsWith("I") &&
Character.isDigit(text.charAt(1)) &&
text.charAt(1) != '0' &&
Character.isAlphabetic(text.charAt(2)) &&
Character.isAlphabetic(text.charAt(3)) &&
Character.isAlphabetic(text.charAt(4));
statusCheckBox.setEnabled(isValidSerialNumber);
nextButton.setEnabled(true);
}
@Override
public void afterTextChanged(Editable s) {}
});
statusCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (statusCheckBox.isChecked()) {
descriptionEditText.setEnabled(true);
statusCheckBox.setText("Negative");
nextButton.setEnabled(false);
} else {
descriptionEditText.setEnabled(false);
statusCheckBox.setText("Positive");
descriptionEditText.setText("");
nextButton.setEnabled(true);
}
}
});
descriptionEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String description = s.toString().trim();
boolean isValidDescription = description.length() >= 10 && description.length() <= 255;
nextButton.setEnabled(isValidDescription);
}
@Override
public void afterTextChanged(Editable s) {}
});
nextButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
onBackPressed();
return false;
}
});
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity2.this, MainActivity3.class);
String serialNumber = serialNumberEditText.getText().toString().trim();
String result = statusCheckBox.getText().toString();
String defectDescription = descriptionEditText.getText().toString().trim();
String registrantName = getIntent().getStringExtra("registrantName");
intent.putExtra("registrantName", registrantName);
intent.putExtra("serialNumber", serialNumber);
intent.putExtra("testResult", result);
intent.putExtra("defectDescription", defectDescription);
startActivity(intent);
}
});
}
}