mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-05 15:54:20 +01:00
Added support for Android Wear 2.0 and wear synchronization in China
This commit is contained in:
@@ -183,6 +183,10 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
*/
|
||||
@Override
|
||||
public void onConnected(final Bundle bundle) {
|
||||
// Ensure the Wearable API was connected
|
||||
if (!mWearableSynchronizer.hasConnectedApi())
|
||||
return;
|
||||
|
||||
if (!mPreferences.getBoolean(PREFS_WEAR_SYNCED, false)) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -67,7 +67,7 @@ public class UARTConfigurationSynchronizer {
|
||||
return;
|
||||
|
||||
mGoogleApiClient = new GoogleApiClient.Builder(context)
|
||||
.addApi(Wearable.API)
|
||||
.addApiIfAvailable(Wearable.API)
|
||||
.addConnectionCallbacks(listener)
|
||||
.build();
|
||||
mGoogleApiClient.connect();
|
||||
@@ -82,13 +82,20 @@ public class UARTConfigurationSynchronizer {
|
||||
mGoogleApiClient = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Wearable API has been connected.
|
||||
*/
|
||||
public boolean hasConnectedApi() {
|
||||
return mGoogleApiClient != null && mGoogleApiClient.isConnected() && mGoogleApiClient.hasConnectedApi(Wearable.API);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes the UART configurations between handheld and wearables.
|
||||
* Call this when configuration has been created or altered.
|
||||
* @return pending result
|
||||
*/
|
||||
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
|
||||
if (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
|
||||
if (!hasConnectedApi())
|
||||
return null;
|
||||
|
||||
final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
|
||||
@@ -115,7 +122,7 @@ public class UARTConfigurationSynchronizer {
|
||||
* @return pending result
|
||||
*/
|
||||
public PendingResult<DataApi.DeleteDataItemsResult> onConfigurationDeleted(final long id) {
|
||||
if (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
|
||||
if (!hasConnectedApi())
|
||||
return null;
|
||||
return Wearable.DataApi.deleteDataItems(mGoogleApiClient, id2Uri(id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user