4
4
import android .content .Intent ;
5
5
import android .os .Bundle ;
6
6
import android .view .View ;
7
+ import android .view .inputmethod .InputMethodManager ;
7
8
import android .widget .Button ;
8
9
import android .widget .EditText ;
10
+ import android .widget .FrameLayout ;
9
11
import android .widget .Toast ;
10
12
11
13
import androidx .appcompat .app .AppCompatActivity ;
14
16
import androidx .fragment .app .FragmentTransaction ;
15
17
16
18
import com .google .android .gms .vision .barcode .Barcode ;
19
+ import com .google .android .material .snackbar .Snackbar ;
17
20
import com .notbytes .barcode_reader .BarcodeReaderActivity ;
18
21
19
- public class ConnectToUserActivity extends AppCompatActivity {
22
+ public class ConnectToUserActivity extends AppCompatActivity {
20
23
21
24
private static final int BARCODE_READER_ACTIVITY_REQUEST = 1208 ;
22
25
23
26
private EditText ipInput , portInput ;
24
27
private Button connectBtn , scanBtn ;
25
28
private Client myClient ;
26
29
private User user ;
30
+ FrameLayout progressOverlay ;
27
31
28
32
public void setUser (User user ) {
29
33
this .user = user ;
30
34
Intent intent = new Intent (getApplicationContext (), ChatActivity .class );
31
35
intent .putExtra ("user" , myClient .user );
36
+
37
+ progressOverlay .setVisibility (View .INVISIBLE );
32
38
startActivity (intent );
33
39
}
34
40
@@ -41,11 +47,14 @@ protected void onCreate(Bundle savedInstanceState) {
41
47
portInput = findViewById (R .id .portInput );
42
48
connectBtn = findViewById (R .id .connectBtn );
43
49
scanBtn = findViewById (R .id .scan_button );
50
+ progressOverlay = findViewById (R .id .progress_overlay );
51
+
44
52
}
45
53
46
54
@ Override
47
55
protected void onResume () {
48
56
super .onResume ();
57
+ progressOverlay .setVisibility (View .INVISIBLE );
49
58
if (myClient != null && !myClient .isCancelled ())
50
59
myClient .cancel (true );
51
60
}
@@ -65,6 +74,16 @@ protected void onDestroy() {
65
74
}
66
75
67
76
public void connectBtnListener (View view ) {
77
+ if (portInput .getText ().length () < 2 || ipInput .getText ().length () < 2 ){
78
+ Snackbar snackbar = Snackbar
79
+ .make (ipInput , "Please Enter Valid IP Address and/or Port number." , Snackbar .LENGTH_LONG );
80
+ snackbar .show ();
81
+ return ;
82
+ }
83
+
84
+ InputMethodManager imm = (InputMethodManager ) getSystemService (Activity .INPUT_METHOD_SERVICE );
85
+ imm .hideSoftInputFromWindow (portInput .getWindowToken (), 0 );
86
+ progressOverlay .setVisibility (View .VISIBLE );
68
87
myClient = new Client (ipInput .getText ().toString (), Integer .parseInt (portInput .getText ().toString ()), this );
69
88
myClient .execute ();
70
89
}
0 commit comments