Skip to content

Commit 4e89f60

Browse files
neel1998CloudyPadmal
authored andcommitted
bluetoot hwifi connection option moved to Connect device menu (#1952)
1 parent 982b089 commit 4e89f60

File tree

9 files changed

+92
-154
lines changed

9 files changed

+92
-154
lines changed

app/src/main/java/io/pslab/activity/MainActivity.java

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package io.pslab.activity;
22

3-
import android.app.AlertDialog;
43
import android.app.PendingIntent;
54
import android.app.ProgressDialog;
65
import android.content.BroadcastReceiver;
76
import android.content.Context;
8-
import android.content.DialogInterface;
97
import android.content.Intent;
108
import android.content.IntentFilter;
119
import android.hardware.usb.UsbDevice;
@@ -24,7 +22,6 @@
2422
import android.support.v7.app.AppCompatActivity;
2523
import android.support.v7.widget.Toolbar;
2624
import android.util.Log;
27-
import android.view.LayoutInflater;
2825
import android.view.Menu;
2926
import android.view.MenuInflater;
3027
import android.view.MenuItem;
@@ -41,8 +38,6 @@
4138
import io.pslab.R;
4239
import io.pslab.communication.CommunicationHandler;
4340
import io.pslab.fragment.AboutUsFragment;
44-
import io.pslab.fragment.BluetoothScanFragment;
45-
import io.pslab.fragment.ESPFragment;
4641
import io.pslab.fragment.FAQFragment;
4742
import io.pslab.fragment.HomeFragment;
4843
import io.pslab.fragment.InstrumentsFragment;
@@ -402,53 +397,9 @@ private void attemptToConnectPSLab() {
402397
} else {
403398
initialisationDialog.dismiss();
404399
Toast.makeText(this, getString(R.string.device_not_found), Toast.LENGTH_SHORT).show();
405-
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
406-
.setMessage(getResources().getString(R.string.bluetooth_wifi_scan_dialog))
407-
.setPositiveButton(getResources().getString(R.string.bluetooth_scan_text), new DialogInterface.OnClickListener() {
408-
@Override
409-
public void onClick(DialogInterface dialog, int which) {
410-
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
411-
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
412-
View dialogView = inflater.inflate(R.layout.bluetooth_wifi_dialog_layout, null);
413-
dialogBuilder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
414-
@Override
415-
public void onClick(DialogInterface dialogInterface, int i) {
416-
dialog.cancel();
417-
}
418-
});
419-
420-
dialogView.findViewById(R.id.bluetooth_btn).setOnClickListener(new View.OnClickListener() {
421-
@Override
422-
public void onClick(View view) {
423-
BluetoothScanFragment bluetoothScanFragment = new BluetoothScanFragment();
424-
bluetoothScanFragment.show(getSupportFragmentManager(), "bluetooth");
425-
bluetoothScanFragment.setCancelable(true);
426-
dialog.cancel();
427-
}
428-
});
429-
430-
dialogView.findViewById(R.id.wifi_btn).setOnClickListener(new View.OnClickListener() {
431-
@Override
432-
public void onClick(View view) {
433-
ESPFragment espFragment = new ESPFragment();
434-
espFragment.show(getSupportFragmentManager(), "wifi");
435-
espFragment.setCancelable(true);
436-
dialog.cancel();
437-
}
438-
});
439-
440-
dialogBuilder.setView(dialogView)
441-
.create()
442-
.show();
443-
}
444-
})
445-
.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
446-
@Override
447-
public void onClick(DialogInterface dialog, int which) {
448-
dialog.cancel();
449-
}
450-
}).create();
451-
dialog.show();
400+
navItemIndex = 2;
401+
CURRENT_TAG = TAG_DEVICE;
402+
loadHomeFragment();
452403
}
453404
}
454405
}

app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ public void onReceive(Context context, Intent intent) {
4242
String action = intent.getAction();
4343
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
4444
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
45-
String deviceName = device.getName();
46-
deviceList.add(deviceName);
47-
bluetoothDevices.add(device);
48-
deviceListAdapter.notifyDataSetChanged();
45+
if (device != null) {
46+
String deviceName = device.getName();
47+
deviceList.add(deviceName);
48+
bluetoothDevices.add(device);
49+
deviceListAdapter.notifyDataSetChanged();
50+
}
4951
}
5052
}
5153
};

app/src/main/java/io/pslab/fragment/HomeFragment.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
import android.view.ViewGroup;
1313
import android.webkit.WebView;
1414
import android.webkit.WebViewClient;
15+
import android.widget.Button;
1516
import android.widget.ImageView;
1617
import android.widget.LinearLayout;
1718
import android.widget.ProgressBar;
1819
import android.widget.ScrollView;
1920
import android.widget.TextView;
2021

21-
import io.pslab.R;
22-
import io.pslab.others.InitializationVariable;
23-
2422
import java.io.IOException;
2523

2624
import butterknife.BindView;
2725
import butterknife.ButterKnife;
2826
import butterknife.Unbinder;
27+
import io.pslab.R;
28+
import io.pslab.others.InitializationVariable;
29+
import io.pslab.others.ScienceLabCommon;
2930

3031
import static io.pslab.others.ScienceLabCommon.scienceLab;
3132

@@ -55,6 +56,12 @@ public class HomeFragment extends Fragment {
5556
ProgressBar wvProgressBar;
5657
@BindView(R.id.steps_header_text)
5758
TextView stepsHeader;
59+
@BindView(R.id.bluetooth_btn)
60+
Button bluetoothButton;
61+
@BindView(R.id.wifi_btn)
62+
Button wifiButton;
63+
@BindView(R.id.bluetooth_wifi_option_tv)
64+
TextView bluetoothWifiOption;
5865
private boolean deviceFound = false, deviceConnected = false;
5966
private Unbinder unbinder;
6067

@@ -138,7 +145,32 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
138145
return false;
139146
}
140147
});
148+
if (ScienceLabCommon.scienceLab.isConnected()) {
149+
bluetoothButton.setVisibility(View.GONE);
150+
wifiButton.setVisibility(View.GONE);
151+
bluetoothWifiOption.setVisibility(View.GONE);
152+
} else {
153+
bluetoothButton.setVisibility(View.VISIBLE);
154+
wifiButton.setVisibility(View.VISIBLE);
155+
bluetoothWifiOption.setVisibility(View.VISIBLE);
156+
}
157+
bluetoothButton.setOnClickListener(new View.OnClickListener() {
158+
@Override
159+
public void onClick(View v) {
160+
BluetoothScanFragment bluetoothScanFragment = new BluetoothScanFragment();
161+
bluetoothScanFragment.show(getActivity().getSupportFragmentManager(), "bluetooth");
162+
bluetoothScanFragment.setCancelable(true);
163+
}
164+
});
141165

166+
wifiButton.setOnClickListener(new View.OnClickListener() {
167+
@Override
168+
public void onClick(View v) {
169+
ESPFragment espFragment = new ESPFragment();
170+
espFragment.show(getActivity().getSupportFragmentManager(), "wifi");
171+
espFragment.setCancelable(true);
172+
}
173+
});
142174
return view;
143175
}
144176

app/src/main/res/drawable/ic_bluetooth.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/src/main/res/drawable/ic_wifi.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/src/main/res/layout/bluetooth_wifi_dialog_layout.xml

Lines changed: 0 additions & 74 deletions
This file was deleted.

app/src/main/res/layout/home_fragment.xml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
<LinearLayout
7070
android:layout_width="match_parent"
7171
android:layout_height="wrap_content"
72-
android:layout_marginBottom="@dimen/inst_margin_bottom"
72+
android:layout_marginStart="@dimen/instruction_ll_margin"
7373
android:layout_marginLeft="@dimen/instruction_ll_margin"
74-
android:layout_marginStart="@dimen/instruction_ll_margin">
74+
android:layout_marginBottom="@dimen/inst_margin_bottom">
7575

7676
<TextView
7777
android:layout_width="wrap_content"
@@ -82,18 +82,18 @@
8282
<TextView
8383
android:layout_width="wrap_content"
8484
android:layout_height="wrap_content"
85-
android:layout_marginLeft="@dimen/inst_bullet_margin"
8685
android:layout_marginStart="@dimen/inst_bullet_margin"
86+
android:layout_marginLeft="@dimen/inst_bullet_margin"
8787
android:text="@string/pslab_instruction_1"
8888
android:textSize="@dimen/connect_instruction_text" />
8989
</LinearLayout>
9090

9191
<LinearLayout
9292
android:layout_width="match_parent"
9393
android:layout_height="wrap_content"
94-
android:layout_marginBottom="@dimen/inst_margin_bottom"
94+
android:layout_marginStart="@dimen/instruction_ll_margin"
9595
android:layout_marginLeft="@dimen/instruction_ll_margin"
96-
android:layout_marginStart="@dimen/instruction_ll_margin">
96+
android:layout_marginBottom="@dimen/inst_margin_bottom">
9797

9898
<TextView
9999
android:layout_width="wrap_content"
@@ -104,17 +104,17 @@
104104
<TextView
105105
android:layout_width="wrap_content"
106106
android:layout_height="wrap_content"
107-
android:layout_marginLeft="@dimen/inst_bullet_margin"
108107
android:layout_marginStart="@dimen/inst_bullet_margin"
108+
android:layout_marginLeft="@dimen/inst_bullet_margin"
109109
android:text="@string/pslab_instruction_2"
110110
android:textSize="@dimen/connect_instruction_text" />
111111
</LinearLayout>
112112

113113
<LinearLayout
114114
android:layout_width="match_parent"
115115
android:layout_height="wrap_content"
116-
android:layout_marginLeft="@dimen/instruction_ll_margin"
117-
android:layout_marginStart="@dimen/instruction_ll_margin">
116+
android:layout_marginStart="@dimen/instruction_ll_margin"
117+
android:layout_marginLeft="@dimen/instruction_ll_margin">
118118

119119
<TextView
120120
android:layout_width="wrap_content"
@@ -125,8 +125,8 @@
125125
<TextView
126126
android:layout_width="wrap_content"
127127
android:layout_height="wrap_content"
128-
android:layout_marginLeft="@dimen/inst_bullet_margin"
129128
android:layout_marginStart="@dimen/inst_bullet_margin"
129+
android:layout_marginLeft="@dimen/inst_bullet_margin"
130130
android:text="@string/pslab_instruction_3"
131131
android:textSize="@dimen/connect_instruction_text" />
132132
</LinearLayout>
@@ -144,12 +144,47 @@
144144
android:textStyle="bold"
145145
android:visibility="gone" />
146146

147+
<TextView
148+
android:id="@+id/bluetooth_wifi_option_tv"
149+
android:layout_width="match_parent"
150+
android:layout_height="wrap_content"
151+
android:layout_marginTop="@dimen/bluetooth_heading_margin"
152+
android:gravity="center"
153+
android:text="@string/bluetooth_wifi_connect_option" />
154+
155+
<LinearLayout
156+
android:layout_width="match_parent"
157+
android:layout_height="wrap_content"
158+
android:gravity="top|center"
159+
android:orientation="horizontal">
160+
161+
<Button
162+
android:id="@+id/bluetooth_btn"
163+
android:layout_width="wrap_content"
164+
android:layout_height="wrap_content"
165+
android:layout_margin="@dimen/bluetooth_btn_margin"
166+
android:background="@color/colorPrimary"
167+
android:padding="@dimen/bluetooth_btn_margin"
168+
android:text="@string/bluetooth"
169+
android:textColor="@color/white" />
170+
171+
<Button
172+
android:id="@+id/wifi_btn"
173+
android:layout_width="wrap_content"
174+
android:layout_height="wrap_content"
175+
android:layout_margin="@dimen/bluetooth_btn_margin"
176+
android:background="@color/colorPrimary"
177+
android:padding="@dimen/bluetooth_btn_margin"
178+
android:text="@string/wifi"
179+
android:textColor="@color/white" />
180+
</LinearLayout>
181+
147182
<View
148183
android:layout_width="match_parent"
149184
android:layout_height="@dimen/separator_width"
150185
android:layout_marginLeft="@dimen/separator_margin"
151-
android:layout_marginRight="@dimen/separator_margin"
152186
android:layout_marginTop="@dimen/separator_margin_top"
187+
android:layout_marginRight="@dimen/separator_margin"
153188
android:background="@color/grey_light" />
154189

155190
<TextView

app/src/main/res/values/dimens.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@
218218
<dimen name="btn_min_width">50dp</dimen>
219219
<dimen name="wave_seekbar_margin">20dp</dimen>
220220

221+
<dimen name="bluetooth_btn_margin">10dp</dimen>
222+
<dimen name="bluetooth_heading_margin">20dp</dimen>
221223
<dimen name="device_version_padding">20dp</dimen>
222224
<dimen name="connect_msg_tv_padding">20dp</dimen>
223225
<dimen name="device_desc_padding">20dp</dimen>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<string name="pslab_pinlayout_front">Pin Layout Front</string>
2020
<string name="pslab_pinlayout_back">Pin Layout Back</string>
2121
<string name="bluetooth_connect_menu">Bluetooth Connection</string>
22-
<string name="bluetooth_wifi_scan_dialog">USB device not found. Do you want to scan for Bluetooth or Wifi connection?</string>
22+
<string name="bluetooth_wifi_connect_option">Connect using Bluetooth or Wi-Fi</string>
2323
<string name="bluetooth">Bluetooth</string>
2424
<string name="wifi">WiFi</string>
2525
<string name="bluetooth_scan_text">Scan</string>

0 commit comments

Comments
 (0)