Skip to content

Commit

Permalink
handle screen rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
r-cohen committed May 21, 2018
1 parent 86fd13f commit 9e60853
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add the dependency to the **Module** gradle file:
```gradle
dependencies {
...
compile 'com.github.phearme:bt-scan-selector:1.1.7'
compile 'com.github.phearme:bt-scan-selector:1.1.8'
}
```
Enable databinding in the **Module** grade file:
Expand Down
4 changes: 2 additions & 2 deletions btscanselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 20
versionName "1.1.7"
versionCode 21
versionName "1.1.8"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
5 changes: 1 addition & 4 deletions btscanselector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application android:label="@string/app_name"
android:allowBackup="false">

</application>
<application android:label="@string/app_name"/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
import android.support.v4.app.FragmentActivity;

public class BTScanSelectorBuilder {
private static ABTScanSelectorEventsHandler mHandler;
private static String mTitle;

public static void build(FragmentActivity activity, ABTScanSelectorEventsHandler handler) {
build(activity, handler, null);
}

public static void build(FragmentActivity activity, ABTScanSelectorEventsHandler handler, String title) {
mHandler = handler;
mTitle = title;
BTScanSelectorDialog dialog = new BTScanSelectorDialog();
dialog.setTitle(title);
dialog.setEvents(handler);
dialog.show(activity.getSupportFragmentManager(), "selectbtdevice");
}

public static ABTScanSelectorEventsHandler getHandler() {
return mHandler;
}

public static String getTitle() {
return mTitle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
public class BTScanSelectorDialog extends DialogFragment {
private static int REQUEST_ENABLE_BT = 1;
private static int REQUEST_LOCATION_PERMISSION = 2;
private IBTScanSelectorEvents mEvents;
private String dialogTitle;
BTScanSelectorAdapter mAdapter;
RecyclerView recyclerView;
ProgressBar progressBar;
Expand All @@ -48,6 +46,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
}

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String dialogTitle = BTScanSelectorBuilder.getTitle();
builder.setView(view)
.setCancelable(false)
.setTitle(dialogTitle == null ? getString(R.string.nearbyDevices) : dialogTitle)
Expand Down Expand Up @@ -75,14 +74,6 @@ public void onClick(View view) {
return dialog;
}

public void setEvents(IBTScanSelectorEvents events) {
this.mEvents = events;
}

public void setTitle(String title) {
this.dialogTitle = title;
}

@Override
public void onDestroy() {
if (mAdapter != null && getActivity() != null) {
Expand All @@ -104,15 +95,17 @@ private void bindRecyclerView() {
mAdapter = new BTScanSelectorAdapter(getActivity(), new IBTScanSelectorEvents() {
@Override
public void onDeviceSelected(BluetoothDevice device) {
if (mEvents != null) {
mEvents.onDeviceSelected(device);
ABTScanSelectorEventsHandler events = BTScanSelectorBuilder.getHandler();
if (events != null) {
events.onDeviceSelected(device);
}
BTScanSelectorDialog.this.getDialog().cancel();
}

@Override
public boolean onDeviceFound(BluetoothDevice device) {
return mEvents == null || mEvents.onDeviceFound(device);
ABTScanSelectorEventsHandler events = BTScanSelectorBuilder.getHandler();
return events == null || events.onDeviceFound(device);
}
}, new IBTScanDataEvents() {
@Override
Expand Down

0 comments on commit 9e60853

Please sign in to comment.