Skip to content

Commit

Permalink
do not show second sensor data if only one sensor selected
Browse files Browse the repository at this point in the history
  • Loading branch information
vitas committed Apr 20, 2019
1 parent 46ec973 commit 9ec91a5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BluetoothBaseActivity extends AppCompatActivity {
protected Handler mHandler ;
protected boolean mIsBound;
protected BluetoothPipe mBluetoothPipe;
protected ArrayList<DeviceTag> mDeviceTags;
protected ArrayList<DeviceTag> mDeviceTags = new ArrayList<>();;
protected boolean autoStart;

protected ServiceConnection serviceConnection = new ServiceConnection() {
Expand Down Expand Up @@ -144,9 +144,6 @@ public void onDataReceived(byte[] data, String message) {
mBluetoothPipe.setBluetoothConnectionListener(new BluetoothPipe.BluetoothConnectionListener() {
public void onDeviceConnected(DeviceTag deviceTag) {

if (mDeviceTags == null) {
mDeviceTags = new ArrayList<>();
}
mDeviceTags.add(deviceTag);

Toast.makeText(getApplicationContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public boolean isDiscovery() {
}

public boolean cancelDiscovery() {
return mBluetoothAdapter.cancelDiscovery();
if (mBluetoothAdapter != null) {
return mBluetoothAdapter.cancelDiscovery();
}
return false;
}

public void setupService(BluetoothService blService, Handler handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public void onChanged(@Nullable ThrowGauge user) {
}
});

mGaugeViewModel.setMultiDevice(mDeviceTags.size()>1);

this.RunMode = 0;

mHandler = new DataHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.content.res.ResourcesCompat;
import android.view.View;

import java.text.DecimalFormat;
import java.util.Locale;
Expand All @@ -22,6 +23,7 @@
public class ThrowGaugeViewModel extends AndroidViewModel implements Observable {
private PropertyChangeRegistry callbacks = new PropertyChangeRegistry();
private Handler mHandler;
private boolean mMultiDevice;

@Override
public void addOnPropertyChangedCallback(
Expand Down Expand Up @@ -353,6 +355,10 @@ public Drawable getMaxTravelColor2() {
return ResourcesCompat.getDrawable(getApplication().getResources(), R.drawable.layout_range_green, null);
}

public int getSecondSensorVisible() {
return mMultiDevice?View.VISIBLE:View.GONE;
}

public void setMinTravel(String value){
int d = Integer.parseInt(value);
getThrowGauge().getValue().SetMinTravel(d);
Expand Down Expand Up @@ -426,4 +432,8 @@ public double parseDecimal(String input) throws ParseException {
}
return number.doubleValue();
}

public void setMultiDevice(boolean multiDevice) {
mMultiDevice = multiDevice;
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/layout/throw_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
android:gravity="center|center_horizontal"
android:padding="4dp"
android:text="@{CommandthrowViewModel.Angle2}"
android:visibility="@{CommandthrowViewModel.secondSensorVisible}"
android:textSize="34sp" />

</LinearLayout>
Expand Down Expand Up @@ -132,6 +133,7 @@
android:gravity="center|center_horizontal"
android:padding="4dp"
android:text="@{CommandthrowViewModel.Travel2}"
android:visibility="@{CommandthrowViewModel.secondSensorVisible}"
android:textColor="@android:color/white"
android:textSize="34sp" />

Expand Down Expand Up @@ -178,6 +180,7 @@
android:background="@drawable/rounded_back"
android:gravity="center"
android:text="@{CommandthrowViewModel.MaxTravel2}"
android:visibility="@{CommandthrowViewModel.secondSensorVisible}"
android:textSize="24sp" />

<Button
Expand Down Expand Up @@ -237,6 +240,7 @@
android:background="@drawable/rounded_back"
android:gravity="center"
android:text="@{CommandthrowViewModel.MinTravel2}"
android:visibility="@{CommandthrowViewModel.secondSensorVisible}"
android:textSize="24sp" />

<Button
Expand Down

0 comments on commit 9ec91a5

Please sign in to comment.