blob: 56b05aa5af4396e0911f0bccd4783183f3cab8fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/* -*- 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 {
public static final class State {
private final boolean mWasBluetoothEnabled;
private State(boolean aIsBluetoothEnabled) {
mWasBluetoothEnabled = aIsBluetoothEnabled;
}
public boolean wasBluetoothEnabled() {
return mWasBluetoothEnabled;
}
}
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 State getState() {
if (!isAvailable()) {
return null;
}
return new State(getAdapter().isEnabled());
}
public static boolean isStateValid(State aState) {
return aState != null;
}
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: */
|