Skip to content

Commit 8f27c07

Browse files
committed
fix bug: connection failed
1 parent 015715b commit 8f27c07

5 files changed

Lines changed: 48 additions & 28 deletions

File tree

0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.alfaloop.android.alfabeacon"
88
minSdkVersion 21
99
targetSdkVersion 26
10-
versionCode 4
11-
versionName "0.4"
10+
versionCode 5
11+
versionName "0.5"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
externalNativeBuild {
1414
cmake {

app/src/main/java/com/alfaloop/android/alfabeacon/adapter/DeviceAdapter.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
import java.util.ArrayList;
3535
import java.util.List;
3636

37-
public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHolder> implements Filterable {
37+
public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHolder> implements Filterable{
3838

3939
public interface OnItemClickListener {
40-
void onItemClick(int position);
41-
void onConnectClick(int position);
40+
void onConnectClick(LeBeacon beacon);
4241
}
4342

4443
private ItemFilter mFilter = new ItemFilter();
@@ -77,7 +76,7 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
7776

7877
@Override
7978
public void onBindViewHolder(MyViewHolder holder, int position) {
80-
LeBeacon item = mFilterItems.get(position);
79+
final LeBeacon item = mFilterItems.get(position);
8180

8281
if (item.getType() == LeBeacon.LEBEACON_TYPE_AA) {
8382
holder.imvBeaconType.setImageResource(R.drawable.ic_beacon_alfa_aa);
@@ -106,7 +105,7 @@ public void onBindViewHolder(MyViewHolder holder, int position) {
106105
@Override
107106
public void onClick(View v) {
108107
if (itemClickListener != null) {
109-
itemClickListener.onConnectClick(position);
108+
itemClickListener.onConnectClick(item);
110109
}
111110
}
112111
});
@@ -115,13 +114,21 @@ public void onClick(View v) {
115114
@Override
116115
public void onClick(View v) {
117116
if (itemClickListener != null) {
118-
itemClickListener.onItemClick(position);
117+
itemClickListener.onConnectClick(item);
119118
}
120119
}
121120
});
122121

123122
if (item.getiBeacon() != null) {
124123
holder.vBeaconContainer.setVisibility(View.VISIBLE);
124+
holder.vBeaconContainer.setOnClickListener(new View.OnClickListener() {
125+
@Override
126+
public void onClick(View v) {
127+
if (itemClickListener != null) {
128+
itemClickListener.onConnectClick(item);
129+
}
130+
}
131+
});
125132
holder.vIBeacon.setVisibility(View.VISIBLE);
126133
holder.tvIBeaconUuid.setText(String.format("UUID • %s", item.getiBeacon().getUuid()));
127134
holder.tvIBeaconMajor.setText(String.format("Major • %d", item.getiBeacon().getMajor()));

app/src/main/java/com/alfaloop/android/alfabeacon/fragment/ConnectedFragment.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
**/
1616
package com.alfaloop.android.alfabeacon.fragment;
1717

18+
import android.bluetooth.BluetoothDevice;
1819
import android.bluetooth.BluetoothGattCharacteristic;
1920
import android.bluetooth.BluetoothGattService;
2021
import android.content.DialogInterface;
@@ -107,8 +108,6 @@ public class ConnectedFragment extends BaseBackFragment implements View.OnClickL
107108
private RxBleClient rxBleClient;
108109
private RxBleConnection rxBleConnection;
109110
private Disposable connectionDisposable;
110-
private Observable<RxBleConnection> mConnectionObservable;
111-
private PublishSubject<Boolean> disconnectTriggerSubject = PublishSubject.create();
112111
private int mergeProcessCounter = 0;
113112

114113
// GUI components
@@ -192,9 +191,12 @@ private void initView(View view) {
192191
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
193192
@Override
194193
public void onClick(View v) {
195-
if (connectionDisposable != null)
194+
// RxBleDevice rxdevice = rxBleClient.getBleDevice(macAddress);
195+
// RxBleConnection.RxBleConnectionState state = rxdevice.getConnectionState();
196+
// if (state == )
197+
if (connectionDisposable != null) {
196198
connectionDisposable.dispose();
197-
// _mActivity.onBackPressed();
199+
}
198200
}
199201
});
200202

@@ -280,10 +282,14 @@ public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
280282
}
281283
@Override
282284
public void afterTextChanged(Editable editable) {
283-
int major = Integer.parseInt(iBeaconMajorEdit.getText().toString());
284-
if (major < 0 || major > 65535) {
285+
/* if (iBeaconMajorEdit.getText().length() > 0) {
286+
int major = Integer.parseInt(iBeaconMajorEdit.getText().toString());
287+
if (major > 65535) {
288+
iBeaconMajorEdit.setText("65535");
289+
}
290+
} else {
285291
iBeaconMajorEdit.setText("0");
286-
}
292+
}*/
287293
}
288294
});
289295
iBeaconMajorEdit.setOnFocusChangeListener(this);
@@ -297,10 +303,14 @@ public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
297303
}
298304
@Override
299305
public void afterTextChanged(Editable editable) {
300-
int major = Integer.parseInt(iBeaconMinorEdit.getText().toString());
301-
if (major < 0 || major > 65535) {
306+
/* if (iBeaconMinorEdit.getText().length() > 0) {
307+
int major = Integer.parseInt(iBeaconMinorEdit.getText().toString());
308+
if (major > 65535) {
309+
iBeaconMinorEdit.setText("65535");
310+
}
311+
} else {
302312
iBeaconMinorEdit.setText("0");
303-
}
313+
}*/
304314
}
305315
});
306316
iBeaconMinorEdit.setOnFocusChangeListener(this);

app/src/main/java/com/alfaloop/android/alfabeacon/fragment/ScannerFragment.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
package com.alfaloop.android.alfabeacon.fragment;
1717

1818
import android.animation.ObjectAnimator;
19+
import android.bluetooth.BluetoothAdapter;
1920
import android.bluetooth.BluetoothDevice;
21+
import android.bluetooth.BluetoothGattServer;
22+
import android.bluetooth.BluetoothManager;
23+
import android.content.Context;
2024
import android.os.Bundle;
2125
import android.os.ParcelUuid;
2226
import android.support.annotation.Nullable;
@@ -138,17 +142,8 @@ private void initView(View view) {
138142
mAdapter = new DeviceAdapter(_mActivity);
139143
mAdapter.setItemClickListener(new DeviceAdapter.OnItemClickListener() {
140144
@Override
141-
public void onItemClick(int position) {
145+
public void onConnectClick(LeBeacon beacon) {
142146
stopScan();
143-
List<LeBeacon> valueList = new ArrayList<LeBeacon>(mLeBeaconHashMap.values());
144-
LeBeacon beacon = valueList.get(position);
145-
start(ConnectedFragment.newInstance(beacon));
146-
}
147-
@Override
148-
public void onConnectClick(int position) {
149-
stopScan();
150-
List<LeBeacon> valueList = new ArrayList<LeBeacon>(mLeBeaconHashMap.values());
151-
LeBeacon beacon = valueList.get(position);
152147
start(ConnectedFragment.newInstance(beacon));
153148
}
154149
});
@@ -220,6 +215,9 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
220215
@Override
221216
public void onClick(final View v) {
222217
mExpandLayout.toggle();
218+
if (mExpandLayout.isExpanded()) {
219+
hideSoftInput();
220+
}
223221
}
224222
});
225223

@@ -294,6 +292,11 @@ public void onFocusChange(View v, boolean hasFocus) {
294292
}
295293
}
296294

295+
@Override
296+
public void onSupportVisible() {
297+
super.onSupportVisible();
298+
}
299+
297300
@Override
298301
public void onDestroyView() {
299302
super.onDestroyView();

0 commit comments

Comments
 (0)