Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update app to work with newer versions of Android Studio, Gradle plugin etc. #17

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a8deb5b
Update Gradle build files, so that the project works with newer versi…
sandy-8925 Dec 18, 2020
bc533eb
Update buildToolsVersion to 30.0.2
sandy-8925 Dec 18, 2020
a2090b7
Update support libraries version
sandy-8925 Dec 18, 2020
2ea20f1
Gradle build file: Replace compile with implementation etc.
sandy-8925 Dec 18, 2020
dd1ab0e
Update Kotlin runtime version to 1.0.6, seems to no longer match kotl…
sandy-8925 Dec 18, 2020
1bf5c3e
Gradle build file cleanup
sandy-8925 Dec 19, 2020
e9a6df9
Remove unneeded Kotlin runtime dependency
sandy-8925 Dec 19, 2020
58602f2
Remove kotlin-android-extensions plugin and switch over to view bindi…
sandy-8925 Dec 19, 2020
0693406
Set compileSdkVersion to 28, so that we can migrate to Jetpack
sandy-8925 Dec 19, 2020
2affdfa
Migrate to Jetpack
sandy-8925 Dec 19, 2020
9786122
HelpActivity - Code cleanup - Add null check
sandy-8925 Dec 19, 2020
f05b605
Project Gradle build file: Update some classpath versions and remove …
sandy-8925 Dec 19, 2020
1545e53
Update some dependency versions
sandy-8925 Dec 19, 2020
98a2a11
Remove SnackEngage from the project, outdated and has dependency prob…
sandy-8925 Dec 19, 2020
2a216c8
Convert application class to Kotlin
sandy-8925 Dec 19, 2020
4d550f5
Code cleanup, move ViewHolder classes into same file as their respect…
sandy-8925 Dec 19, 2020
00d78eb
Code cleanup
sandy-8925 Dec 19, 2020
005a7fc
Code cleanup
sandy-8925 Dec 19, 2020
dad3ef1
Code cleanup
sandy-8925 Dec 19, 2020
5c073f0
Code cleanup
sandy-8925 Dec 19, 2020
2ffd40c
Merge branch 'master' into modernization
sandy-8925 Dec 21, 2020
f8f514b
Re-add SnackEngage, with the correct dependency, and update to v0.27
sandy-8925 Dec 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'spoon'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'spoon'
}

android {
compileSdkVersion 25
buildToolsVersion "25"
compileSdkVersion 28
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "org.ligi.blexplorer"
Expand All @@ -16,11 +16,15 @@ android {
versionCode 12
versionName "1.2"
archivesBaseName = "BLExplorer-$versionName"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

vectorDrawables.useSupportLibrary = true
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -65,44 +69,43 @@ android {

dependencies {

compile "com.android.support:support-v4:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:cardview-v7:$support_version"
compile "com.android.support:design:$support_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.1'

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-runtime:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

compile 'net.steamcrafted:load-toast:1.0.9'
implementation 'net.steamcrafted:load-toast:1.0.12'

compile 'com.github.ligi:KAXT:0.3'
compile 'com.github.ligi:tracedroid:1.4'
compile 'com.github.ligi:ExtraCompats:0.4'
compile 'com.github.ligi:snackengage:0.9'
implementation 'com.github.ligi:KAXT:1.0'
implementation 'com.github.ligi:tracedroid:3.0'
implementation 'com.github.ligi:ExtraCompats:1.0'
implementation 'com.github.ligi.snackengage:snackengage-playrate:0.27'

androidTestCompile "com.android.support:support-annotations:$support_version"
androidTestCompile "com.android.support:appcompat-v7:$support_version"
androidTestCompile "com.android.support:design:$support_version"
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'androidx.appcompat:appcompat:1.2.0'
androidTestImplementation 'com.google.android.material:material:1.2.1'

androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
androidTestImplementation('androidx.test.espresso:espresso-contrib:3.3.0') {
// http://stackoverflow.com/questions/30578243/why-would-adding-espresso-contrib-cause-an-inflateexception
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}

androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.2')
androidTestCompile 'com.squareup.spoon:spoon-client:1.7.0'
androidTestCompile 'com.squareup.assertj:assertj-android:1.1.1'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'com.jraska:falcon-spoon-compat:1.0.3'
androidTestImplementation('androidx.test.espresso:espresso-web:3.3.0')
androidTestImplementation 'com.squareup.spoon:spoon-client:1.7.0'
androidTestImplementation 'com.squareup.assertj:assertj-android:1.1.1'
androidTestImplementation 'org.mockito:mockito-core:1.9.5'
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestImplementation 'com.jraska:falcon-spoon-compat:1.0.3'

testCompile 'junit:junit:4.12'
testCompile 'com.squareup.assertj:assertj-android:1.1.1'
testCompile "com.android.support:support-annotations:$support_version"
testCompile 'org.mockito:mockito-core:1.9.5'
testImplementation 'junit:junit:4.13.1'
testImplementation 'com.squareup.assertj:assertj-android:1.1.1'
testImplementation 'androidx.annotation:annotation:1.1.0'
testImplementation 'org.mockito:mockito-core:1.9.5'

compile 'de.cketti.share:share-intent-builder:0.0.2'
implementation 'de.cketti.share:share-intent-builder:0.0.2'
}
2 changes: 1 addition & 1 deletion android/src/androidTest/java/org/ligi/TheHelpActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ligi;

import android.support.test.rule.ActivityTestRule;
import androidx.test.rule.ActivityTestRule;
import com.jraska.falcon.FalconSpoon;
import org.junit.Rule;
import org.junit.Test;
Expand Down
24 changes: 0 additions & 24 deletions android/src/main/java/org/ligi/blexplorer/App.java

This file was deleted.

22 changes: 22 additions & 0 deletions android/src/main/java/org/ligi/blexplorer/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.ligi.blexplorer

import android.app.Application
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattService
import org.ligi.tracedroid.TraceDroid
import java.util.*

class App : Application() {
override fun onCreate() {
TraceDroid.init(this)
super.onCreate()
}

companion object {
lateinit var gatt: BluetoothGatt
lateinit var service: BluetoothGattService
lateinit var device: BluetoothDevice
var notifyingCharacteristicsUUids: MutableList<UUID> = ArrayList()
}
}
17 changes: 10 additions & 7 deletions android/src/main/java/org/ligi/blexplorer/HelpActivity.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package org.ligi.blexplorer

import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.text.Html
import android.text.method.LinkMovementMethod
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_with_textview.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import org.ligi.blexplorer.databinding.ActivityWithTextviewBinding
import org.ligi.compat.HtmlCompat
import java.io.IOException

class HelpActivity : AppCompatActivity() {

private lateinit var binding: ActivityWithTextviewBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

supportActionBar?.setDisplayHomeAsUpEnabled(true)

setContentView(R.layout.activity_with_textview)
binding = ActivityWithTextviewBinding.inflate(layoutInflater)
setContentView(binding.root)

try {
val open = assets.open("help.html")
content_text.movementMethod = LinkMovementMethod.getInstance()
content_text.text = HtmlCompat.fromHtml(open.bufferedReader().readText(), Html.ImageGetter {
ContextCompat.getDrawable(this, R.drawable.ic_launcher).apply {
binding.contentText.movementMethod = LinkMovementMethod.getInstance()
binding.contentText.text = HtmlCompat.fromHtml(open.bufferedReader().readText(), Html.ImageGetter {
ContextCompat.getDrawable(this, R.drawable.ic_launcher)?.apply {
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
}
}, null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
package org.ligi.blexplorer.characteristics

import android.app.Activity
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCallback
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattDescriptor
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.activity_with_recycler.*
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import de.cketti.shareintentbuilder.ShareIntentBuilder
import org.ligi.blexplorer.App
import org.ligi.blexplorer.R
import org.ligi.blexplorer.databinding.ActivityWithRecyclerBinding
import org.ligi.blexplorer.databinding.ItemCharacteristicBinding
import org.ligi.blexplorer.util.DevicePropertiesDescriber
import java.math.BigInteger
import java.util.*


class CharacteristicActivity : AppCompatActivity() {

private var serviceList: MutableList<BluetoothGattCharacteristic> = ArrayList()
private lateinit var binding : ActivityWithRecyclerBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_with_recycler)
binding = ActivityWithRecyclerBinding.inflate(layoutInflater)
setContentView(binding.root)

supportActionBar?.setDisplayHomeAsUpEnabled(true)

content_list.layoutManager = LinearLayoutManager(this)
binding.contentList.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this)
val adapter = CharacteristicRecycler()
content_list.adapter = adapter
binding.contentList.adapter = adapter

serviceList = App.service.characteristics

Expand Down Expand Up @@ -90,10 +97,11 @@ class CharacteristicActivity : AppCompatActivity() {
}


private inner class CharacteristicRecycler : RecyclerView.Adapter<CharacteristicViewHolder>() {
private inner class CharacteristicRecycler : androidx.recyclerview.widget.RecyclerView.Adapter<CharacteristicViewHolder>() {
override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): CharacteristicViewHolder {
val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.item_characteristic, viewGroup, false)
return CharacteristicViewHolder(v)
val layoutInflater = LayoutInflater.from(viewGroup.context)
val binding = ItemCharacteristicBinding.inflate(layoutInflater, viewGroup, false)
return CharacteristicViewHolder(binding)
}

override fun onBindViewHolder(deviceViewHolder: CharacteristicViewHolder, i: Int) {
Expand All @@ -110,3 +118,80 @@ class CharacteristicActivity : AppCompatActivity() {
return super.onOptionsItemSelected(item)
}
}

private class CharacteristicViewHolder(private val binding: ItemCharacteristicBinding) : RecyclerView.ViewHolder(binding.root) {

private var characteristic: BluetoothGattCharacteristic? = null

fun applyCharacteristic(characteristic: BluetoothGattCharacteristic) {
this.characteristic = characteristic
binding.uuid.text = characteristic.uuid.toString()

if (characteristic.value != null) {
binding.value.text = getValue(characteristic)
} else {
binding.value.text = "no value read yet"
}
binding.type.text = DevicePropertiesDescriber.getProperty(characteristic)
binding.permissions.text = DevicePropertiesDescriber.getPermission(characteristic) + " " + characteristic.descriptors.size

if (characteristic.properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY > 0) {
binding.notify.visibility = View.VISIBLE
binding.notify.isChecked = App.notifyingCharacteristicsUUids.contains(characteristic.uuid)
} else {
binding.notify.visibility = View.GONE
}

if (characteristic.properties and BluetoothGattCharacteristic.PROPERTY_READ > 0) {
binding.read.visibility = View.VISIBLE
} else {
binding.read.visibility = View.GONE
}

binding.read.setOnClickListener {
App.gatt.readCharacteristic(characteristic)
}

binding.share.setOnClickListener {
val activity = binding.root.context as Activity
var text = "characteristic UUID: " + characteristic.uuid.toString() + "\n"
text += "service UUID: " + characteristic.service.uuid.toString() + "\n"
if (characteristic.value != null) {
text += "value: " + getValue(characteristic)
}
activity.startActivity(ShareIntentBuilder.from(activity).text(text).build())

}

binding.notify.setOnCheckedChangeListener { compoundButton, check ->
if (check) {
if (!App.notifyingCharacteristicsUUids.contains(characteristic.uuid)) {
App.notifyingCharacteristicsUUids.add(characteristic.uuid)
}
} else {
App.notifyingCharacteristicsUUids.remove(characteristic.uuid)
}

if (!App.gatt.setCharacteristicNotification(characteristic, check)) {
Toast.makeText(itemView.context, "setCharacteristicNotification returned false", Toast.LENGTH_LONG).show()
} else {

val descriptor = characteristic.descriptors[0]
descriptor.value = if (check) BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE else BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE
if (!App.gatt.writeDescriptor(descriptor)) {
Toast.makeText(itemView.context, "Could not write descriptor for notification", Toast.LENGTH_LONG).show()
}
}
}
}


private fun getValue(characteristic: BluetoothGattCharacteristic): String {
return BigInteger(1, characteristic.value).toString(16) +
" = " +
characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0) +
" = " +
characteristic.getStringValue(0)
}

}
Loading