Skip to content

Commit

Permalink
Add code blocks with language descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertoli committed Nov 21, 2024
1 parent 951e4ef commit 9287907
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 35 deletions.
18 changes: 13 additions & 5 deletions docs/simpleble/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,41 @@ derived classes, which forces us to bring these definitions in externally.
As a module
-----------

To include this dependency module, add the following to your ``settings.gradle`` file::
To include this dependency module, add the following to your ``settings.gradle`` file

.. code-block:: groovy
includeBuild("path/to/simpleble/src/backends/android/simpleble-bridge") {
dependencySubstitution {
substitute module("org.simpleble.android.bridge:simpleble-bridge") with project(":")
}
}
Or, in ``settings.gradle.kts``::
Or, in ``settings.gradle.kts``

.. code-block:: kotlin
includeBuild("path/to/simpleble/src/backends/android/simpleble-bridge") {
dependencySubstitution {
substitute(module("org.simpleble.android.bridge:simpleble-bridge")).using(project(":"))
}
}
**NOTE:** We will provide Maven packages in the future.
.. note::

We will provide Maven packages in the future.

From AAR file
-------------

Place the package on your app's directory, and take note of its path. We'll use ``example-app/app/libs/simpleble-bridge.aar``.
Then, declare the dependency on your app's ``build.gradle{.kts}`` file (note: relative paths begin from your app's module folder)::
Then, declare the dependency on your app's ``build.gradle{.kts}`` file (note: relative paths begin from your app's module folder)

.. code-block:: kotlin
dependencies {
/* ... */
implementation(files('libs/simpleble-bridge.aar'))
implementation(files("libs/simpleble-bridge.aar"))
}
Build Examples
Expand Down
58 changes: 35 additions & 23 deletions docs/simpledroidble/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ which is then used by the Kotlin frontend to perform lower-level tasks.

After this, you will be able to call ``SimpleDroidBle#requestPermissions`` successfully.
This requests the required Android app permissions to the user; namely Bluetooth
access, administration, scanning, and connection. ::
access, administration, scanning, and connection.

.. code-block:: kotlin
import android.app.Activity
import android.os.Bundle
Expand Down Expand Up @@ -57,28 +59,30 @@ static class in Java), which has two main methods.
Having multiple instances (by unbounded calls to ``Adapter#getAdapters``, for example) may cause a memory leak.
This can be accomplished by acquiring said instance either on your app's Application class, or, in a single activity app, on your Activity's viewmodel; and treating the Adapter as a global, singleton object.

The following code snippet shows how to use these functions::
The following code snippet shows how to use these functions

import android.util.Log
import org.simpleble.android.Adapter
.. code-block:: kotlin
import android.util.Log
import org.simpleble.android.Adapter
// We assume simpleble is already set-up
fun listBluetoothDevices() {
if (!Adapter.isBluetoothEnabled()) {
Log.e("Example", "Bluetooth is not enabled")
return
}
// We assume simpleble is already set-up
fun listBluetoothDevices() {
if (!Adapter.isBluetoothEnabled()) {
Log.e("Example", "Bluetooth is not enabled")
return
}
val adapters = Adapter.getAdapters()
if (adapters.isEmpty()) {
Log.e("Example", "No Bluetooth adapters found")
return
}
val adapters = Adapter.getAdapters()
if (adapters.isEmpty()) {
Log.e("Example", "No Bluetooth adapters found")
return
}
val adapter = adapters.first()
Log.i("Example", "Adapter identifier: ${adapter.identifier}")
Log.i("Example", "Adapter address: ${adapter.address}")
}
val adapter = adapters.first()
Log.i("Example", "Adapter identifier: ${adapter.identifier}")
Log.i("Example", "Adapter address: ${adapter.address}")
}
The above code will print the identifier and address of the first adapter found
using ``Adapter#identifier`` and ``Adapter#address``, respectively.
Expand All @@ -96,7 +100,9 @@ This means that events are emitted via ``Flow``s, and consumed mainly in `Kotlin
Once you have a list of available adapters, you can start scanning for
peripherals. To do so, you need to call the ``Adapter#scanFor(Int)`` method.
This will start emitting ``Peripheral`` objects that are in range of the adapter
on the ``Adapter#onScanFound`` flow. ::
on the ``Adapter#onScanFound`` flow.

.. code-block:: kotlin
import android.util.Log
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -132,7 +138,9 @@ which emit a value when scanning either starts or stops, respectively; ``Adapter
which emits whether the ``Adapter`` is currently scanning for devices; and
``Adapter#onScanUpdated``, which emits when a peripheral property has changed.

The following code snippet shows how to use these functions::
The following code snippet shows how to use these functions

.. code-block:: kotlin
import android.util.Log
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -190,7 +198,9 @@ Connecting to a peripheral

Once you have a list of peripherals, you can connect to one of them. To do so,
you can call ``Peripheral#connect()`` on one of the ``Peripheral`` objects
obtained via your ``Adapter``. ::
obtained via your ``Adapter``.

.. code-block:: kotlin
import android.util.Log
import kotlinx.coroutines.CoroutineScope
Expand All @@ -217,7 +227,9 @@ Similarly to the ``Adapter`` class, the ``Peripheral`` class has several flows.
(analogously to ``Adapter#onScanActive``), and ``Peripheral#onDisconnected`` will
emit when the peripheral is finally disconnected from the adapter.

Here is a code sample of the aforementioned flows ::
Here is a code sample of the aforementioned flows

.. code-block:: kotlin
import android.util.Log
import kotlinx.coroutines.CoroutineScope
Expand Down
23 changes: 16 additions & 7 deletions docs/simpledroidble/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,51 @@ From AAR file
-------------

Place the package on your app's directory, and take note of its path. We'll use ``example-app/app/libs/{simpledroidble,simpleble-bridge}.aar``.
Then, declare the dependency on your app's ``build.gradle{.kts}`` file (note: relative paths begin from your app's module folder)::
Then, declare the dependency on your app's ``build.gradle{.kts}`` file (note: relative paths begin from your app's module folder)

.. code-block:: kotlin
dependencies {
/* ... */
implementation(files('libs/simpledroidble.aar', 'libs/simpleble-bridge.aar'))
implementation(files("libs/simpledroidble.aar", "libs/simpleble-bridge.aar"))
}
Consuming Locally
-----------------

If you want to use SimpleDroidBLE as part of your project from a local copy,
you can do so by adding the following to your ``settings.gradle`` or ``settings.gradle.kts`` file.
Make sure this include is before your ``include(":app")`` statement::
Make sure this include is before your ``include(":app")`` statement

.. code-block:: groovy
includeBuild("path/to/simpledroidble") {
dependencySubstitution {
substitute module("org.simpleble.android:simpledroidble") with project(":simpledroidble")
}
}
Or, in Kotlin::
Or, in Kotlin

.. code-block:: kotlin
includeBuild("path/to/simpledroidble") {
dependencySubstitution {
substitute(module("org.simpleble.android:simpledroidble")).using(project(":simpledroidble"))
}
}
Then, inside your ``build.gradle`` or ``build.gradle.kts`` file, you can add the
following dependency::
Then, inside your ``build.gradle`` file, you can add the following dependency

.. code-block:: groovy
dependencies {
implementation "org.simpleble.android:simpledroidble"
}
Kotlin::
If you are using Kotlin (``build.gradle.kts``)

.. code-block:: kotlin
dependencies {
implementation("org.simpleble.android:simpledroidble")
Expand Down

0 comments on commit 9287907

Please sign in to comment.