Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bluetooth wifi connection option moved to Connect device menu #1952

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 3 additions & 52 deletions app/src/main/java/io/pslab/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.pslab.activity;

import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
Expand All @@ -24,7 +22,6 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -41,8 +38,6 @@
import io.pslab.R;
import io.pslab.communication.CommunicationHandler;
import io.pslab.fragment.AboutUsFragment;
import io.pslab.fragment.BluetoothScanFragment;
import io.pslab.fragment.ESPFragment;
import io.pslab.fragment.FAQFragment;
import io.pslab.fragment.HomeFragment;
import io.pslab.fragment.InstrumentsFragment;
Expand Down Expand Up @@ -402,53 +397,9 @@ private void attemptToConnectPSLab() {
} else {
initialisationDialog.dismiss();
Toast.makeText(this, getString(R.string.device_not_found), Toast.LENGTH_SHORT).show();
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.setMessage(getResources().getString(R.string.bluetooth_wifi_scan_dialog))
.setPositiveButton(getResources().getString(R.string.bluetooth_scan_text), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.bluetooth_wifi_dialog_layout, null);
dialogBuilder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.cancel();
}
});

dialogView.findViewById(R.id.bluetooth_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
BluetoothScanFragment bluetoothScanFragment = new BluetoothScanFragment();
bluetoothScanFragment.show(getSupportFragmentManager(), "bluetooth");
bluetoothScanFragment.setCancelable(true);
dialog.cancel();
}
});

dialogView.findViewById(R.id.wifi_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ESPFragment espFragment = new ESPFragment();
espFragment.show(getSupportFragmentManager(), "wifi");
espFragment.setCancelable(true);
dialog.cancel();
}
});

dialogBuilder.setView(dialogView)
.create()
.show();
}
})
.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).create();
dialog.show();
navItemIndex = 2;
CURRENT_TAG = TAG_DEVICE;
loadHomeFragment();
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
deviceList.add(deviceName);
bluetoothDevices.add(device);
deviceListAdapter.notifyDataSetChanged();
if (device != null) {
String deviceName = device.getName();
deviceList.add(deviceName);
bluetoothDevices.add(device);
deviceListAdapter.notifyDataSetChanged();
}
}
}
};
Expand Down
38 changes: 35 additions & 3 deletions app/src/main/java/io/pslab/fragment/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;

import io.pslab.R;
import io.pslab.others.InitializationVariable;

import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.pslab.R;
import io.pslab.others.InitializationVariable;
import io.pslab.others.ScienceLabCommon;

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

Expand Down Expand Up @@ -55,6 +56,12 @@ public class HomeFragment extends Fragment {
ProgressBar wvProgressBar;
@BindView(R.id.steps_header_text)
TextView stepsHeader;
@BindView(R.id.bluetooth_btn)
Button bluetoothButton;
@BindView(R.id.wifi_btn)
Button wifiButton;
@BindView(R.id.bluetooth_wifi_option_tv)
TextView bluetoothWifiOption;
private boolean deviceFound = false, deviceConnected = false;
private Unbinder unbinder;

Expand Down Expand Up @@ -138,7 +145,32 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
});
if (ScienceLabCommon.scienceLab.isConnected()) {
bluetoothButton.setVisibility(View.GONE);
wifiButton.setVisibility(View.GONE);
bluetoothWifiOption.setVisibility(View.GONE);
} else {
bluetoothButton.setVisibility(View.VISIBLE);
wifiButton.setVisibility(View.VISIBLE);
bluetoothWifiOption.setVisibility(View.VISIBLE);
}
bluetoothButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BluetoothScanFragment bluetoothScanFragment = new BluetoothScanFragment();
bluetoothScanFragment.show(getActivity().getSupportFragmentManager(), "bluetooth");
bluetoothScanFragment.setCancelable(true);
}
});

wifiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ESPFragment espFragment = new ESPFragment();
espFragment.show(getActivity().getSupportFragmentManager(), "wifi");
espFragment.setCancelable(true);
}
});
return view;
}

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/drawable/ic_bluetooth.xml

This file was deleted.

5 changes: 0 additions & 5 deletions app/src/main/res/drawable/ic_wifi.xml

This file was deleted.

74 changes: 0 additions & 74 deletions app/src/main/res/layout/bluetooth_wifi_dialog_layout.xml

This file was deleted.

55 changes: 45 additions & 10 deletions app/src/main/res/layout/home_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/inst_margin_bottom"
android:layout_marginStart="@dimen/instruction_ll_margin"
android:layout_marginLeft="@dimen/instruction_ll_margin"
android:layout_marginStart="@dimen/instruction_ll_margin">
android:layout_marginBottom="@dimen/inst_margin_bottom">

<TextView
android:layout_width="wrap_content"
Expand All @@ -82,18 +82,18 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/inst_bullet_margin"
android:layout_marginStart="@dimen/inst_bullet_margin"
android:layout_marginLeft="@dimen/inst_bullet_margin"
android:text="@string/pslab_instruction_1"
android:textSize="@dimen/connect_instruction_text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/inst_margin_bottom"
android:layout_marginStart="@dimen/instruction_ll_margin"
android:layout_marginLeft="@dimen/instruction_ll_margin"
android:layout_marginStart="@dimen/instruction_ll_margin">
android:layout_marginBottom="@dimen/inst_margin_bottom">

<TextView
android:layout_width="wrap_content"
Expand All @@ -104,17 +104,17 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/inst_bullet_margin"
android:layout_marginStart="@dimen/inst_bullet_margin"
android:layout_marginLeft="@dimen/inst_bullet_margin"
android:text="@string/pslab_instruction_2"
android:textSize="@dimen/connect_instruction_text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/instruction_ll_margin"
android:layout_marginStart="@dimen/instruction_ll_margin">
android:layout_marginStart="@dimen/instruction_ll_margin"
android:layout_marginLeft="@dimen/instruction_ll_margin">

<TextView
android:layout_width="wrap_content"
Expand All @@ -125,8 +125,8 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/inst_bullet_margin"
android:layout_marginStart="@dimen/inst_bullet_margin"
android:layout_marginLeft="@dimen/inst_bullet_margin"
android:text="@string/pslab_instruction_3"
android:textSize="@dimen/connect_instruction_text" />
</LinearLayout>
Expand All @@ -144,12 +144,47 @@
android:textStyle="bold"
android:visibility="gone" />

<TextView
android:id="@+id/bluetooth_wifi_option_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/bluetooth_heading_margin"
android:gravity="center"
android:text="@string/bluetooth_wifi_connect_option" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:orientation="horizontal">

<Button
android:id="@+id/bluetooth_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/bluetooth_btn_margin"
android:background="@color/colorPrimary"
android:padding="@dimen/bluetooth_btn_margin"
android:text="@string/bluetooth"
android:textColor="@color/white" />

<Button
android:id="@+id/wifi_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/bluetooth_btn_margin"
android:background="@color/colorPrimary"
android:padding="@dimen/bluetooth_btn_margin"
android:text="@string/wifi"
android:textColor="@color/white" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="@dimen/separator_width"
android:layout_marginLeft="@dimen/separator_margin"
android:layout_marginRight="@dimen/separator_margin"
android:layout_marginTop="@dimen/separator_margin_top"
android:layout_marginRight="@dimen/separator_margin"
android:background="@color/grey_light" />

<TextView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@
<dimen name="btn_min_width">50dp</dimen>
<dimen name="wave_seekbar_margin">20dp</dimen>

<dimen name="bluetooth_btn_margin">10dp</dimen>
<dimen name="bluetooth_heading_margin">20dp</dimen>
<dimen name="device_version_padding">20dp</dimen>
<dimen name="connect_msg_tv_padding">20dp</dimen>
<dimen name="device_desc_padding">20dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<string name="pslab_pinlayout_front">Pin Layout Front</string>
<string name="pslab_pinlayout_back">Pin Layout Back</string>
<string name="bluetooth_connect_menu">Bluetooth Connection</string>
<string name="bluetooth_wifi_scan_dialog">USB device not found. Do you want to scan for Bluetooth or Wifi connection?</string>
<string name="bluetooth_wifi_connect_option">Connect using Bluetooth or Wi-Fi</string>
<string name="bluetooth">Bluetooth</string>
<string name="wifi">WiFi</string>
<string name="bluetooth_scan_text">Scan</string>
Expand Down