[Libreoffice-commits] core.git: android/sdremote

Christian Lohmaier lohmaier+LibreOffice at googlemail.com
Thu Jan 16 07:47:35 PST 2014


 android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServerConnection.java |    5 -
 android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java      |    1 
 android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java           |   12 +-
 android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java                  |   46 ----------
 4 files changed, 7 insertions(+), 57 deletions(-)

New commits:
commit 4d6244cc80f1a384d571af2efd539bd3fa3f9291
Author: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
Date:   Sun Dec 15 16:44:12 2013 +0100

    remove BluetoothOperator wrapper
    
    it is just another obfuscating layer of one-command-function calles that
    can as well be called directly.
    
    If you really want to get the path to aquire the bluetooth adapter
    differently, based on a runtime check, a single method to retrieve the
    adapter is enough in any of the classes. No need to wrap the whole
    adapter's api in your own class.
    
    Change-Id: I2c631321dcf8ef143fe58a0a8246e010169409ac

diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServerConnection.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServerConnection.java
index 1056b7d..d58460a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServerConnection.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServerConnection.java
@@ -14,11 +14,10 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.UUID;
 
+import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothSocket;
 
-import org.libreoffice.impressremote.util.BluetoothOperator;
-
 class BluetoothServerConnection implements ServerConnection {
     // Standard UUID for the Serial Port Profile.
     // https://www.bluetooth.org/en-us/specification/assigned-numbers-overview/service-discovery
@@ -32,7 +31,7 @@ class BluetoothServerConnection implements ServerConnection {
 
     private BluetoothSocket buildServerConnection(Server aServer) {
         try {
-            BluetoothDevice aBluetoothServer = BluetoothOperator.getAdapter()
+            BluetoothDevice aBluetoothServer = BluetoothAdapter.getDefaultAdapter()
                 .getRemoteDevice(aServer.getAddress());
 
             return aBluetoothServer.createRfcommSocketToServiceRecord(
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index a8aa85f..cea50e5 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -16,7 +16,6 @@ import android.os.Binder;
 import android.os.IBinder;
 import android.support.v4.content.LocalBroadcastManager;
 
-import org.libreoffice.impressremote.util.BluetoothOperator;
 import org.libreoffice.impressremote.util.Intents;
 
 public class CommunicationService extends Service implements Runnable, MessagesListener, Timer.TimerListener {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
index f5f4fe4..53d85d8 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
@@ -8,13 +8,15 @@
  */
 package org.libreoffice.impressremote.communication;
 
+import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
 import android.os.Build;
 
-import org.libreoffice.impressremote.util.BluetoothOperator;
 import org.libreoffice.impressremote.util.Preferences;
 
 final class PairingProvider {
+    private static final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
+
     private final Preferences mAuthorizedServersPreferences;
 
     private PairingProvider(Context aContext) {
@@ -58,15 +60,11 @@ final class PairingProvider {
     }
 
     private String getPairingDeviceName() {
-        if (!BluetoothOperator.isAvailable()) {
-            return Build.MODEL;
-        }
-
-        if (BluetoothOperator.getAdapter().getName() == null) {
+        if (btAdapter == null || btAdapter.getName() == null) {
             return Build.MODEL;
         }
 
-        return BluetoothOperator.getAdapter().getName();
+        return btAdapter.getName();
     }
 }
 
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
deleted file mode 100644
index 9522838..0000000
--- a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.libreoffice.impressremote.util;
-
-import android.bluetooth.BluetoothAdapter;
-
-public final class BluetoothOperator {
-    private BluetoothOperator() {
-    }
-
-    public static boolean isAvailable() {
-        return getAdapter() != null;
-    }
-
-    public static BluetoothAdapter getAdapter() {
-        // TODO: should be acquired other way on Jelly Bean MR2
-        // Look at the BluetoothAdapter’s docs for details.
-        // It will require to use the latest version of SDK to get needed constant.
-
-        return BluetoothAdapter.getDefaultAdapter();
-    }
-
-    public static void enable() {
-        if (!isAvailable()) {
-            return;
-        }
-
-        getAdapter().enable();
-    }
-
-    public static void disable() {
-        if (!isAvailable()) {
-            return;
-        }
-
-        getAdapter().disable();
-    }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list