Skip to content

Commit 67202ce

Browse files
committed
update scanner fragment
1 parent a675e34 commit 67202ce

5 files changed

Lines changed: 133 additions & 22 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ dependencies {
7070
compile 'com.victor:lib:1.0.4'
7171
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
7272
compile 'com.github.dmytrodanylyk:android-morphing-button:98a4986e56' // commit hash
73+
compile 'com.github.aakira:expandable-layout:1.6.0@aar'
7374

7475
}

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

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class ConnectedFragment extends BaseBackFragment implements View.OnClickL
109109
private Disposable connectionDisposable;
110110
private Observable<RxBleConnection> mConnectionObservable;
111111
private PublishSubject<Boolean> disconnectTriggerSubject = PublishSubject.create();
112+
private int mergeProcessCounter = 0;
112113

113114
// GUI components
114115
private Toolbar mToolbar;
@@ -447,7 +448,7 @@ private void initDelayView() {
447448

448449
connectionDisposable = device.establishConnection(false) // <-- autoConnect flag
449450
.observeOn(AndroidSchedulers.mainThread())
450-
.doFinally(this::dispose)
451+
.doFinally(this::onConnectionDispose)
451452
.subscribe(this::onConnectionReceived, this::onConnectionFailure);
452453
}
453454

@@ -473,33 +474,42 @@ private void morphingBeaconButtonClicked( ) {
473474
singles.add(rxBleConnection.writeCharacteristic(mAlfaAppleBeaconMajorCharacteristic, majorArray));
474475
singles.add(rxBleConnection.writeCharacteristic(mAlfaAppleBeaconMinorCharacteristic, minorArray));
475476
singles.add(rxBleConnection.writeCharacteristic(mAlfaAppleBeaconTxmCharacteristic, txmArray));
476-
477+
mergeProcessCounter = 0;
477478
Single.merge(singles)
478-
.observeOn(AndroidSchedulers.mainThread())
479+
.observeOn(AndroidSchedulers.mainThread())
479480
.subscribe(bytes -> {
480-
Log.d(TAG, String.format("update beacon profile Success"));
481-
morphToCompleted(iBeaconMorphingButton);
481+
Log.d(TAG, String.format("update beacon profile Success %s", ParserUtils.bytesToHex(bytes)));
482+
mergeProcessCounter++;
483+
if (mergeProcessCounter == singles.size()) {
484+
mergeProcessCounter = 0;
485+
morphToCompleted(iBeaconMorphingButton);
486+
}
482487
}, this::onConnectionFailure);
488+
483489
}
484490

485491
private void morphingRadioButtonClicked() {
486492

487493
morphToProcess(radioMorphingButton);
488494
byte[] radioIntervalArray = new byte[2];
489495
byte[] radioTxPowerArray = new byte[1];
490-
radioIntervalArray[0] = (byte)((radioInterval >> 8) & 0xff);
491-
radioIntervalArray[1] = (byte)(radioInterval & 0xff);
496+
radioIntervalArray[0] = (byte)(radioInterval & 0xff);
497+
radioIntervalArray[1] = (byte)((radioInterval >> 8) & 0xff);
492498
radioTxPowerArray[0] = (byte)radioTxPower;
493499

494500
List<Single<byte[]>> singles = new ArrayList<>();
495501
singles.add(rxBleConnection.writeCharacteristic(mAlfaRadioIntervalCharacteristic, radioIntervalArray));
496502
singles.add(rxBleConnection.writeCharacteristic(mAlfaRadioTxPowerCharacteristic, radioTxPowerArray));
497-
503+
mergeProcessCounter = 0;
498504
Single.merge(singles)
499505
.observeOn(AndroidSchedulers.mainThread())
500506
.subscribe(bytes -> {
501507
Log.d(TAG, String.format("update radio profile Success"));
502-
morphToCompleted(radioMorphingButton);
508+
mergeProcessCounter++;
509+
if (mergeProcessCounter == singles.size()) {
510+
mergeProcessCounter = 0;
511+
morphToCompleted(radioMorphingButton);
512+
}
503513
}, this::onConnectionFailure);
504514
}
505515

@@ -534,6 +544,7 @@ private void updateRssi(Long along) {
534544
private void onConnectionReceived(RxBleConnection connection) {
535545
// start discovery
536546
rxBleConnection = connection;
547+
537548
rxBleConnection.discoverServices()
538549
.observeOn(AndroidSchedulers.mainThread())
539550
.subscribe(rxBleDeviceServices -> {
@@ -586,20 +597,16 @@ private void onConnectionReceived(RxBleConnection connection) {
586597
rxBleConnection.readCharacteristic(mAlfaRadioIntervalCharacteristic)
587598
.observeOn(AndroidSchedulers.mainThread())
588599
.subscribe( value -> {
589-
// iBeaconTxmEdit.setText(String.format("%d", (int)value[0]));
590-
int interval = (int)value[1] << 8;
591-
interval = interval | (int)value[0];
592-
radioInterval = interval;
593-
Log.i(TAG, String.format("found Radio interval characteristic %d", interval));
594-
updateRadioIntervalSeekbar(interval);
600+
radioInterval = (value[1] & 0xff) * 0x100 + (value[0] & 0xff);
601+
Log.i(TAG, String.format("found Radio interval characteristic %d", radioInterval));
602+
updateRadioIntervalSeekbar(radioInterval);
595603
}, this::onConnectionFailure);
596604
} else if (character.getUuid().equals(UUID_ALFA_RADIO_CHARACTER_TXPOWER)) {
597605
Log.i(TAG, String.format("found Radio txpower characteristic"));
598606
mAlfaRadioTxPowerCharacteristic = character;
599607
rxBleConnection.readCharacteristic(mAlfaRadioTxPowerCharacteristic)
600608
.observeOn(AndroidSchedulers.mainThread())
601609
.subscribe( value -> {
602-
// iBeaconTxmEdit.setText(String.format("%d", (int)value[0]));
603610
int txpower = (int)value[0] ;
604611
radioTxPower = txpower;
605612
Log.i(TAG, String.format("found Radio txpower characteristic %d", txpower));
@@ -675,7 +682,8 @@ public void onClick(DialogInterface dialog, int which) {
675682
.show();
676683
}
677684

678-
private void dispose() {
685+
private void onConnectionDispose() {
686+
Log.d(TAG, "dispose event");
679687
connectionDisposable = null;
680688
pop();
681689
}
@@ -735,13 +743,23 @@ private void morphToProcess(final IndeterminateProgressButton btnMorph) {
735743
}
736744

737745
private void morphToCompleted(final IndeterminateProgressButton btnMorph) {
738-
btnMorph.unblockTouch();
739-
morphToSuccess(btnMorph);
740746
Handler handler = new Handler();
747+
741748
handler.postDelayed(new Runnable() {
742749
@Override
743750
public void run() {
744-
morphToSquare(btnMorph, 0);
751+
morphToSuccess(btnMorph);
752+
Handler handler2 = new Handler();
753+
// morphToSquare(btnMorph, 1500);
754+
// btnMorph.unblockTouch();
755+
handler2.postDelayed(new Runnable() {
756+
@Override
757+
public void run() {
758+
morphToSquare(btnMorph, 500);
759+
btnMorph.unblockTouch();
760+
761+
}
762+
}, 1500);
745763
}
746764
}, 1500);
747765
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.view.View;
3131
import android.view.ViewGroup;
3232
import android.widget.ProgressBar;
33+
import android.widget.RelativeLayout;
3334
import android.widget.TextView;
3435

3536
import com.alfaloop.android.alfabeacon.MainActivity;
@@ -42,6 +43,8 @@
4243
import com.alfaloop.android.alfabeacon.utility.ParserUtils;
4344
import com.alfaloop.android.alfabeacon.utility.ScanFilterUtils;
4445
import com.alfaloop.android.alfabeacon.utility.UuidUtils;
46+
import com.github.aakira.expandablelayout.ExpandableLayoutListenerAdapter;
47+
import com.github.aakira.expandablelayout.ExpandableLinearLayout;
4548
import com.polidea.rxandroidble2.RxBleClient;
4649
import com.polidea.rxandroidble2.RxBleDevice;
4750
import com.polidea.rxandroidble2.scan.ScanRecord;
@@ -77,6 +80,8 @@ public class ScannerFragment extends BaseMainFragment {
7780
private FloatingActionButton mFloatingActionButton;
7881
private RecyclerViewEmptySupport mRecycleView;
7982
private View mEmptyView;
83+
private ExpandableLinearLayout mExpandableLinearLayout;
84+
private RelativeLayout mExpandableButtonLayout;
8085

8186
public static ScannerFragment newInstance() {
8287
ScannerFragment fragment = new ScannerFragment();
@@ -110,6 +115,27 @@ public void onClick(View v) {
110115
}
111116
});
112117

118+
mExpandableLinearLayout = (ExpandableLinearLayout)view.findViewById(R.id.expandableLayout);
119+
mExpandableLinearLayout.setInRecyclerView(true);
120+
mExpandableLinearLayout.setListener(new ExpandableLayoutListenerAdapter() {
121+
@Override
122+
public void onPreOpen() {
123+
124+
}
125+
126+
@Override
127+
public void onPreClose() {
128+
129+
}
130+
});
131+
132+
mExpandableButtonLayout = (RelativeLayout)view.findViewById(R.id.expandableButton);
133+
mExpandableButtonLayout.setOnClickListener(new View.OnClickListener() {
134+
@Override
135+
public void onClick(final View v) {
136+
}
137+
});
138+
113139
mRecycleView = (RecyclerViewEmptySupport) view.findViewById(R.id.recycle_view);
114140
mRecycleView.setLayoutManager(new LinearLayoutManager(_mActivity));
115141
mAdapter = new DeviceAdapter(_mActivity);
@@ -214,6 +240,10 @@ private void scanResultParser(ScanResult result) {
214240
if (record == null)
215241
return;
216242

243+
// if(result.getRssi() < -58) {
244+
// return;
245+
// }
246+
217247
String deviceName = record.getDeviceName();
218248
List<ParcelUuid> advUuids = record.getServiceUuids();
219249
if (deviceName == null || advUuids == null)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item>
4+
<rotate
5+
android:fromDegrees="45"
6+
android:pivotX="135%"
7+
android:pivotY="15%"
8+
android:toDegrees="45">
9+
<shape android:shape="rectangle">
10+
<solid android:color="@color/myPrimaryWhite" />
11+
</shape>
12+
</rotate>
13+
</item>
14+
</layer-list>

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,54 @@
77
android:fitsSystemWindows="true">
88

99
<include layout="@layout/toolbar"/>
10+
<!-- Filter Bar -->
11+
<RelativeLayout
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content">
14+
<RelativeLayout android:id="@+id/expandableButton"
15+
android:layout_width="48dp"
16+
android:layout_height="48dp"
17+
android:layout_alignParentRight="true"
18+
android:layout_alignParentTop="true"
19+
android:gravity="center">
20+
<View android:layout_width="12dp"
21+
android:layout_height="12dp"
22+
android:background="@drawable/triangle"/>
23+
</RelativeLayout>
24+
<TextView
25+
android:id="@+id/textView"
26+
android:layout_width="match_parent"
27+
android:layout_height="48dp"
28+
android:layout_alignParentTop="true"
29+
android:layout_toLeftOf="@id/expandableButton"
30+
android:gravity="center"
31+
android:padding="8dp"
32+
android:text="
33+
sample.sample.sample.sample.sample.sample.sample.sample.sample.sample.\n
34+
"
35+
android:textColor="@color/myPrimaryWhite"
36+
android:textSize="12sp"/>
37+
<com.github.aakira.expandablelayout.ExpandableLinearLayout
38+
android:id="@+id/expandableLayout"
39+
android:layout_width="match_parent"
40+
android:layout_height="120dp"
41+
android:orientation="vertical"
42+
app:ael_duration="400"
43+
app:ael_expanded="false" >
44+
<TextView
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
android:layout_centerInParent="true"
48+
android:layout_below="@id/textView"
49+
android:gravity="center"
50+
android:text="
51+
sample.sample.sample.sample.sample.sample.sample.sample.sample.sample.\n
52+
"
53+
android:textColor="@color/myPrimaryWhite"
54+
android:textSize="16sp" />
55+
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
56+
</RelativeLayout>
57+
1058
<com.alfaloop.android.alfabeacon.base.RecyclerViewEmptySupport
1159
android:id="@+id/recycle_view"
1260
android:layout_width="match_parent"
@@ -23,8 +71,8 @@
2371
android:layout_width="wrap_content"
2472
android:layout_height="wrap_content">
2573
<ImageView
26-
android:layout_width="wrap_content"
27-
android:layout_height="wrap_content"
74+
android:layout_width="48dp"
75+
android:layout_height="48dp"
2876
android:tint="@color/colorPrimary"
2977
app:srcCompat="@drawable/ic_track_changes_black_48dp"
3078
android:gravity="center"

0 commit comments

Comments
 (0)