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

squid:S1066 - Collapsible if statements should be merged #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 11 additions & 15 deletions src/com/tkjelectronics/balanduino/BalanduinoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,8 @@ protected void onPause() {
Log.d(TAG, "- ON PAUSE -");
// Unregister sensor listeners to prevent the activity from draining the device's battery.
mSensorFusion.unregisterListeners();
if (mChatService != null) { // Send stop command and stop sending graph data command
if (mChatService.getState() == BluetoothChatService.STATE_CONNECTED)
mChatService.write(sendStop + imuStop + statusStop);
if (mChatService != null && mChatService.getState() == BluetoothChatService.STATE_CONNECTED) { // Send stop command and stop sending graph data command
mChatService.write(sendStop + imuStop + statusStop);
}
}

Expand Down Expand Up @@ -404,15 +403,13 @@ public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransac
mChatService.write(imuStop); // Stop sending data
}
}
} else if (checkTab(ViewPagerAdapter.INFO_FRAGMENT) && mChatService != null) {
if (mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
mChatService.write(getInfo); // Update info
if (InfoFragment.mToggleButton != null) {
if (InfoFragment.mToggleButton.isChecked())
mChatService.write(statusBegin); // Request data
else
mChatService.write(statusStop); // Stop sending data
}
} else if (checkTab(ViewPagerAdapter.INFO_FRAGMENT) && mChatService != null && mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
mChatService.write(getInfo); // Update info
if (InfoFragment.mToggleButton != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this check?

if (InfoFragment.mToggleButton.isChecked())
mChatService.write(statusBegin); // Request data
else
mChatService.write(statusStop); // Stop sending data
}
}
if (!checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) { // Needed when the user rotates the screen
Expand All @@ -431,9 +428,8 @@ public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTrans
} else if (checkTab(ViewPagerAdapter.GRAPH_FRAGMENT) && mChatService != null) {
if (mChatService.getState() == BluetoothChatService.STATE_CONNECTED)
mChatService.write(imuStop);
} else if (checkTab(ViewPagerAdapter.INFO_FRAGMENT) && mChatService != null) {
if (mChatService.getState() == BluetoothChatService.STATE_CONNECTED)
mChatService.write(statusStop);
} else if (checkTab(ViewPagerAdapter.INFO_FRAGMENT) && mChatService != null && mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
mChatService.write(statusStop);
}
if (checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard
Expand Down
59 changes: 30 additions & 29 deletions src/com/tkjelectronics/balanduino/GraphFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ public void onClick(View v) {
else
mToggleButton.setText("Start");

if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED && BalanduinoActivity.checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) {
if (((ToggleButton) v).isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuStop); // Stop sending data
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED &&
BalanduinoActivity.checkTab(ViewPagerAdapter.GRAPH_FRAGMENT))
{
if (((ToggleButton) v).isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuStop); // Stop sending data
}
}
});
Expand All @@ -190,30 +191,30 @@ public void onClick(View v) {
}
});

if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED && BalanduinoActivity.checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuStop); // Stop sending data
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED &&
BalanduinoActivity.checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuStop); // Stop sending data
}

return v;
}

public static void updateKalmanValues() {
if (mQangle != null && mQangle.getText() != null) {
if (!(mQangle.getText().toString().equals(BalanduinoActivity.Qangle)))
mQangle.setText(BalanduinoActivity.Qangle);
if (mQangle != null && mQangle.getText() != null &&
!(mQangle.getText().toString().equals(BalanduinoActivity.Qangle))) {
mQangle.setText(BalanduinoActivity.Qangle);
}
if (mQbias != null && mQbias.getText() != null) {
if (!(mQbias.getText().toString().equals(BalanduinoActivity.Qbias)))
if (mQbias != null && mQbias.getText() != null &&
!(mQbias.getText().toString().equals(BalanduinoActivity.Qbias))) {
mQbias.setText(BalanduinoActivity.Qbias);
}
if (mRmeasure != null && mRmeasure.getText() != null) {
if (!(mRmeasure.getText().toString().equals(BalanduinoActivity.Rmeasure)))
mRmeasure.setText(BalanduinoActivity.Rmeasure);
if (mRmeasure != null && mRmeasure.getText() != null &&
!(mRmeasure.getText().toString().equals(BalanduinoActivity.Rmeasure))) {
mRmeasure.setText(BalanduinoActivity.Rmeasure);
}
}

Expand Down Expand Up @@ -256,13 +257,13 @@ public void onResume() {
else
mToggleButton.setText("Start");

if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED && BalanduinoActivity.checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuStop); // Stop sending data
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED &&
BalanduinoActivity.checkTab(ViewPagerAdapter.GRAPH_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.imuStop); // Stop sending data
}
}
}
42 changes: 21 additions & 21 deletions src/com/tkjelectronics/balanduino/InfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ public void onClick(View v) {
else
mToggleButton.setText("Start");

if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED && BalanduinoActivity.checkTab(ViewPagerAdapter.INFO_FRAGMENT)) {
if (((ToggleButton) v).isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusStop); // Stop sending data
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED &&
BalanduinoActivity.checkTab(ViewPagerAdapter.INFO_FRAGMENT)) {
if (((ToggleButton) v).isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusStop); // Stop sending data
}
}
});

if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED && BalanduinoActivity.checkTab(ViewPagerAdapter.INFO_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusStop); // Stop sending data
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED &&
BalanduinoActivity.checkTab(ViewPagerAdapter.INFO_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusStop); // Stop sending data
}

updateView();
Expand Down Expand Up @@ -104,13 +104,13 @@ public void onResume() {
else
mToggleButton.setText("Start");

if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED && BalanduinoActivity.checkTab(ViewPagerAdapter.INFO_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusStop); // Stop sending data
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED &&
BalanduinoActivity.checkTab(ViewPagerAdapter.INFO_FRAGMENT)) {
if (mToggleButton.isChecked())
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusBegin); // Request data
else
BalanduinoActivity.mChatService.write(BalanduinoActivity.statusStop); // Stop sending data
}
}
}
40 changes: 19 additions & 21 deletions src/com/tkjelectronics/balanduino/SettingsDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ public void onClick(View v) {
mRestoreButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
BalanduinoActivity.mChatService.write(BalanduinoActivity.restoreDefaultValues);
Toast.makeText(getSherlockActivity(), "Default values have been restored", Toast.LENGTH_SHORT).show();
dismiss();
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
BalanduinoActivity.mChatService.write(BalanduinoActivity.restoreDefaultValues);
Toast.makeText(getSherlockActivity(), "Default values have been restored", Toast.LENGTH_SHORT).show();
dismiss();
}
}
});
Expand All @@ -140,11 +139,10 @@ public void onClick(View v) {
mPairButtonWii.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
BalanduinoActivity.mChatService.write(BalanduinoActivity.sendPairWithWii);
dismiss();
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
BalanduinoActivity.mChatService.write(BalanduinoActivity.sendPairWithWii);
dismiss();
}
}
});
Expand All @@ -153,11 +151,10 @@ public void onClick(View v) {
mPairButtonPS4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
BalanduinoActivity.mChatService.write(BalanduinoActivity.sendPairWithPS4);
dismiss();
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
BalanduinoActivity.mChatService.write(BalanduinoActivity.sendPairWithPS4);
dismiss();
}
}
});
Expand Down Expand Up @@ -185,11 +182,12 @@ public void onClick(DialogInterface dialog, int id) {
BalanduinoActivity.maxAngle = maxAngle;
BalanduinoActivity.maxTurning = maxTurning;
BalanduinoActivity.backToSpot = backToSpot;
if (BalanduinoActivity.mChatService != null) {
if (BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
int val = backToSpot ? 1 : 0;
BalanduinoActivity.mChatService.write(BalanduinoActivity.setMaxAngle + maxAngle + ";" + BalanduinoActivity.setMaxTurning + maxTurning + ";" + BalanduinoActivity.setBackToSpot + val + ";" + BalanduinoActivity.getSettings);
}
if (BalanduinoActivity.mChatService != null &&
BalanduinoActivity.mChatService.getState() == BluetoothChatService.STATE_CONNECTED) {
int val = backToSpot ? 1 : 0;
BalanduinoActivity.mChatService.write(BalanduinoActivity.setMaxAngle + maxAngle + ";"
+ BalanduinoActivity.setMaxTurning + maxTurning + ";"
+ BalanduinoActivity.setBackToSpot + val + ";" + BalanduinoActivity.getSettings);
}
}
})
Expand Down