1919import android .widget .ImageView ;
2020import android .widget .TextView ;
2121
22+ import com .gotenna .sdk .GoTenna ;
2223import com .samourai .txtenna .prefs .PrefsUtil ;
2324
24- import com .gotenna .sdk .bluetooth .GTConnectionManager .GTDeviceType ;
2525import com .samourai .txtenna .utils .goTennaUtil ;
2626
2727public class NetworkingActivity extends AppCompatActivity {
@@ -66,16 +66,6 @@ public void onClick(View view) {
6666 }
6767 });
6868
69- if (goTennaUtil .getInstance (NetworkingActivity .this ).isPaired ()) {
70- String device = getText (R .string .mesh_device_detected2 ) + ": " + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getConnectedGotennaAddress ();
71- mesh_card_detail .setText (device );
72- mesh_card_detail_title .setText (R .string .mesh_device_detected );
73- }
74- else {
75- mesh_card_detail .setText (R .string .rescan_or_buy );
76- mesh_card_detail_title .setText (R .string .mesh_device_detected );
77- }
78-
7969 btRescan = findViewById (R .id .btn_rescan );
8070 if (goTennaUtil .getInstance (NetworkingActivity .this ).isPaired ()) {
8171 btRescan .setText (R .string .unpair_device );
@@ -86,14 +76,10 @@ public void onClick(View view) {
8676 btRescan .setOnClickListener (new View .OnClickListener () {
8777 @ Override
8878 public void onClick (View view ) {
89-
9079 if (goTennaUtil .getInstance (NetworkingActivity .this ).isPaired ()) {
91- goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().disconnect ();
92- goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().clearConnectedGotennaAddress ();
93- goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().scanAndConnect (GTDeviceType .MESH );
94- btRescan .setText (R .string .pair_device );
95- mesh_card_detail .setText (R .string .rescan_or_buy );
96- mesh_card_detail_title .setText (R .string .mesh_device_detected );
80+ goTennaUtil .getInstance (NetworkingActivity .this ).disconnect (NetworkingActivity .this );
81+ btRescan .setText (R .string .mesh_device_disconnecting );
82+ btRescan .setEnabled (false );
9783 }
9884 else {
9985
@@ -105,43 +91,60 @@ public void onClick(View view) {
10591 }
10692
10793 if (hasLocationpermission () && hasBluetoothPermisson ()) {
108- // GTCommandCenter.getInstance().setGoTennaGID(1111111111L, "txTenna", null);
109- if (goTennaUtil .getInstance (NetworkingActivity .this ).isPaired ()) {
110- Log .d ("NetworkingActivity" , "existing connected address:" + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getConnectedGotennaAddress ());
111- String device = getText (R .string .mesh_device_detected2 ) + ": " + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getConnectedGotennaAddress ();
112- btRescan .setText (R .string .pair_device );
113- mesh_card_detail .setText (device );
114- mesh_card_detail_title .setText (R .string .mesh_device_detected );
115- }
116- else {
117- goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().scanAndConnect (GTDeviceType .MESH );
118- Log .d ("NetworkingActivity" , "connected address:" + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getConnectedGotennaAddress ());
119- btRescan .setText (R .string .unpair_device );
120- mesh_card_detail .setText (R .string .rescan_or_buy );
121- mesh_card_detail_title .setText (R .string .mesh_device_detected );
122- }
94+ goTennaUtil .getInstance (NetworkingActivity .this ).connect (NetworkingActivity .this );
95+ btRescan .setText (R .string .mesh_device_scanning );
96+ btRescan .setEnabled (false );
12397 }
12498
12599 }
126-
127100 }
128101 });
129102
103+ Log .d ("NetworkActivity" , "gtConnectionState:" + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getGtConnectionState ());
104+ Log .d ("NetworkActivity" , "connected address:" + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getConnectedGotennaAddress ());
105+ if (goTennaUtil .getInstance (NetworkingActivity .this ).isPaired ()) {
106+ String device = getText (R .string .mesh_device_detected2 ) + ": " + goTennaUtil .getInstance (NetworkingActivity .this ).getGtConnectionManager ().getConnectedGotennaAddress ();
107+ mesh_card_detail .setText (device );
108+ mesh_card_detail_title .setText (R .string .mesh_device_detected );
109+ status_img_mesh .setImageDrawable (getResources ().getDrawable (R .drawable .circle_green ));
110+ }
111+ else {
112+ mesh_card_detail .setText (R .string .rescan_or_buy );
113+ mesh_card_detail_title .setText (R .string .no_mesh_device_detected );
114+ status_img_mesh .setImageDrawable (getResources ().getDrawable (R .drawable .circle_red ));
115+ }
116+
117+ if (GoTenna .tokenIsVerified ()) {
118+ scan ();
119+ }
120+
121+ }
122+
123+ public void setStatusText (String deviceName ) {
124+ if (!deviceName .isEmpty ()) {
125+ Log .d ("NetworkingActivity" , "connected address:" + deviceName );
126+ btRescan .setText (R .string .unpair_device );
127+ String detail = getText (R .string .mesh_device_detected2 ) + ": " + deviceName ;
128+ mesh_card_detail .setText (detail );
129+ mesh_card_detail_title .setText (R .string .mesh_device_detected );
130+ status_img_mesh .setImageDrawable (getResources ().getDrawable (R .drawable .circle_green ));
131+ }
132+ else {
133+ btRescan .setText (R .string .pair_device );
134+ mesh_card_detail .setText (R .string .rescan_or_buy );
135+ mesh_card_detail_title .setText (R .string .no_mesh_device_detected );
136+ status_img_mesh .setImageDrawable (getResources ().getDrawable (R .drawable .circle_red ));
137+ }
138+
139+ btRescan .setEnabled (true );
140+
130141 }
131142
132143 private void changeState (){
133144 TransitionManager .beginDelayedTransition ((ViewGroup ) ConstraintGroup .getParent (), new ChangeBounds ());
134145
135146 int visibility = ConstraintGroup .getVisibility () == View .VISIBLE ? View .GONE : View .VISIBLE ;
136147 ConstraintGroup .setVisibility (visibility );
137-
138- if (visibility == View .GONE ) {
139- status_img_mesh .setImageDrawable (getResources ().getDrawable (R .drawable .circle_green ));
140- mesh_card_detail_title .setText (R .string .mesh_device_detected2 );
141- }else {
142- status_img_mesh .setImageDrawable (getResources ().getDrawable (R .drawable .circle_red ));
143- mesh_card_detail_title .setText (R .string .no_mesh_device_detected );
144- }
145148 }
146149
147150 private boolean hasBluetoothPermisson () {
@@ -174,4 +177,21 @@ private void requestLocationPermission() {
174177
175178 }
176179
180+ private void scan () {
181+
182+ if (!hasBluetoothPermisson ()) {
183+ requestBluetoothPermission ();
184+ }
185+ if (!hasLocationpermission ()) {
186+ requestLocationPermission ();
187+ }
188+
189+ if (hasLocationpermission () && hasBluetoothPermisson ()) {
190+ goTennaUtil .getInstance (NetworkingActivity .this ).connect (NetworkingActivity .this );
191+ btRescan .setText (R .string .mesh_device_scanning );
192+ btRescan .setEnabled (false );
193+ }
194+
195+ }
196+
177197}
0 commit comments