-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for timeouts when calling Fit API in the lib, by using th…
…e timeout functionality of PendingResult.
- Loading branch information
Showing
36 changed files
with
489 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
## Version 1.1.0 | ||
|
||
* BREAKING CHANGE: Removed PermissionRequiredException in favor of SecurityException | ||
* Added `RxFit.checkConnection()` Completable. | ||
* Timeouts can now be provided when creating an Observable. Also, a global default timeout for all Fit API requests made through the lib can be set. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 7 additions & 16 deletions
23
library/src/main/java/com/patloew/rxfit/BleClaimDeviceObservable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
package com.patloew.rxfit; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.google.android.gms.common.api.GoogleApiClient; | ||
import com.google.android.gms.common.api.ResultCallback; | ||
import com.google.android.gms.common.api.Status; | ||
import com.google.android.gms.fitness.Fitness; | ||
import com.google.android.gms.fitness.data.BleDevice; | ||
|
||
import rx.Observable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import rx.Observer; | ||
|
||
public class BleClaimDeviceObservable extends BaseObservable<Status> { | ||
|
||
private final BleDevice bleDevice; | ||
private final String deviceAddress; | ||
|
||
static Observable<Status> create(@NonNull RxFit rxFit, @NonNull BleDevice bleDevice) { | ||
return Observable.create(new BleClaimDeviceObservable(rxFit, bleDevice, null)); | ||
} | ||
|
||
static Observable<Status> create(@NonNull RxFit rxFit, @NonNull String deviceAddress) { | ||
return Observable.create(new BleClaimDeviceObservable(rxFit, null, deviceAddress)); | ||
} | ||
|
||
BleClaimDeviceObservable(RxFit rxFit, BleDevice bleDevice, String deviceAddress) { | ||
super(rxFit); | ||
BleClaimDeviceObservable(RxFit rxFit, BleDevice bleDevice, String deviceAddress, Long timeout, TimeUnit timeUnit) { | ||
super(rxFit, timeout, timeUnit); | ||
this.bleDevice = bleDevice; | ||
this.deviceAddress = deviceAddress; | ||
} | ||
|
||
@Override | ||
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Status> observer) { | ||
ResultCallback<Status> resultCallback = new StatusResultCallBack(observer); | ||
|
||
if(bleDevice != null) { | ||
Fitness.BleApi.claimBleDevice(apiClient, bleDevice).setResultCallback(resultCallback); | ||
setupFitnessPendingResult(Fitness.BleApi.claimBleDevice(apiClient, bleDevice), resultCallback); | ||
} else { | ||
Fitness.BleApi.claimBleDevice(apiClient, deviceAddress).setResultCallback(resultCallback); | ||
setupFitnessPendingResult(Fitness.BleApi.claimBleDevice(apiClient, deviceAddress), resultCallback); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 6 additions & 13 deletions
19
library/src/main/java/com/patloew/rxfit/BleStartScanObservable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,29 @@ | ||
package com.patloew.rxfit; | ||
|
||
import android.Manifest; | ||
import android.content.pm.PackageManager; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.RequiresPermission; | ||
import android.support.v4.content.ContextCompat; | ||
|
||
import com.google.android.gms.common.api.GoogleApiClient; | ||
import com.google.android.gms.common.api.Status; | ||
import com.google.android.gms.fitness.Fitness; | ||
import com.google.android.gms.fitness.request.StartBleScanRequest; | ||
|
||
import rx.Observable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import rx.Observer; | ||
|
||
public class BleStartScanObservable extends BaseObservable<Status> { | ||
|
||
private final StartBleScanRequest startBleScanRequest; | ||
|
||
@RequiresPermission("android.permission.BLUETOOTH_ADMIN") | ||
static Observable<Status> create(@NonNull RxFit rxFit, @NonNull StartBleScanRequest startBleScanRequest) { | ||
return Observable.create(new BleStartScanObservable(rxFit, startBleScanRequest)); | ||
} | ||
|
||
BleStartScanObservable(RxFit rxFit, StartBleScanRequest startBleScanRequest) { | ||
super(rxFit); | ||
BleStartScanObservable(RxFit rxFit, StartBleScanRequest startBleScanRequest, Long timeout, TimeUnit timeUnit) { | ||
super(rxFit, timeout, timeUnit); | ||
this.startBleScanRequest = startBleScanRequest; | ||
} | ||
|
||
@SuppressWarnings("MissingPermission") | ||
@Override | ||
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Status> observer) { | ||
//noinspection MissingPermission | ||
Fitness.BleApi.startBleScan(apiClient, startBleScanRequest).setResultCallback(new StatusResultCallBack(observer)); | ||
setupFitnessPendingResult(Fitness.BleApi.startBleScan(apiClient, startBleScanRequest), new StatusResultCallBack(observer)); | ||
} | ||
} |
15 changes: 5 additions & 10 deletions
15
library/src/main/java/com/patloew/rxfit/BleStopScanObservable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
package com.patloew.rxfit; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.google.android.gms.common.api.GoogleApiClient; | ||
import com.google.android.gms.common.api.Status; | ||
import com.google.android.gms.fitness.Fitness; | ||
import com.google.android.gms.fitness.request.BleScanCallback; | ||
|
||
import rx.Observable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import rx.Observer; | ||
|
||
public class BleStopScanObservable extends BaseObservable<Status> { | ||
|
||
private final BleScanCallback bleScanCallback; | ||
|
||
static Observable<Status> create(@NonNull RxFit rxFit, @NonNull BleScanCallback bleScanCallback) { | ||
return Observable.create(new BleStopScanObservable(rxFit, bleScanCallback)); | ||
} | ||
|
||
BleStopScanObservable(RxFit rxFit, BleScanCallback bleScanCallback) { | ||
super(rxFit); | ||
BleStopScanObservable(RxFit rxFit, BleScanCallback bleScanCallback, Long timeout, TimeUnit timeUnit) { | ||
super(rxFit, timeout, timeUnit); | ||
this.bleScanCallback = bleScanCallback; | ||
} | ||
|
||
@Override | ||
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Status> observer) { | ||
Fitness.BleApi.stopBleScan(apiClient, bleScanCallback).setResultCallback(new StatusResultCallBack(observer)); | ||
setupFitnessPendingResult(Fitness.BleApi.stopBleScan(apiClient, bleScanCallback), new StatusResultCallBack(observer)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
library/src/main/java/com/patloew/rxfit/CheckConnectionCompletable.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
library/src/main/java/com/patloew/rxfit/CheckConnectionObservable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.patloew.rxfit; | ||
|
||
import com.google.android.gms.common.api.GoogleApiClient; | ||
|
||
import rx.Observer; | ||
|
||
public class CheckConnectionObservable extends BaseObservable<Void> { | ||
|
||
CheckConnectionObservable(RxFit rxFit) { | ||
super(rxFit, null, null); | ||
} | ||
|
||
@Override | ||
protected void onGoogleApiClientReady(GoogleApiClient apiClient, Observer<? super Void> observer) { | ||
observer.onCompleted(); | ||
} | ||
} |
Oops, something went wrong.