Skip to content

Commit

Permalink
Merge pull request #435 from juliuscanute/gradle-upgrade
Browse files Browse the repository at this point in the history
imp: upgrade compile sdk, fix custom frame
  • Loading branch information
juliansteenbakker authored Nov 1, 2021
2 parents 981ab7a + a845c9e commit 78d4cc7
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 144 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:pedantic/analysis_options.yaml
include: package:flutter_lints/flutter.yaml
8 changes: 3 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'net.touchcapture.qr.flutterqr'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.5.10'
ext.kotlin_version = '1.5.31'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -36,9 +36,7 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildFeatures {
viewBinding = true
}

compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.touchcapture.qr.flutterqr"
xmlns:tools="http://schemas.android.com/tools">
<manifest package="net.touchcapture.qr.flutterqr"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.touchcapture.qr.flutterqr

import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import com.journeyapps.barcodescanner.BarcodeView
import com.journeyapps.barcodescanner.Size

class CustomFramingRectBarcodeView : BarcodeView {
private var bottomOffset = BOTTOM_OFFSET_NOT_SET_VALUE

constructor(context: Context?) : super(context) {}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)

override fun calculateFramingRect(container: Rect, surface: Rect): Rect {
val containerArea = Rect(container)
val intersects =
containerArea.intersect(surface) //adjusts the containerArea (code from super.calculateFramingRect)
val scanAreaRect = super.calculateFramingRect(container, surface)
if (bottomOffset != BOTTOM_OFFSET_NOT_SET_VALUE) { //if the setFramingRect function was called, then we shift the scan area by Y
val scanAreaRectWithOffset = Rect(scanAreaRect)
scanAreaRectWithOffset.bottom -= bottomOffset
scanAreaRectWithOffset.top -= bottomOffset
val belongsToContainer = scanAreaRectWithOffset.intersect(containerArea)
if (belongsToContainer) {
return scanAreaRectWithOffset
}
}
return scanAreaRect
}

fun setFramingRect(rectWidth: Int, rectHeight: Int, bottomOffset: Int) {
this.bottomOffset = bottomOffset
framingRectSize = Size(rectWidth, rectHeight)
}

companion object {
private const val BOTTOM_OFFSET_NOT_SET_VALUE = -1
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,43 @@
package net.touchcapture.qr.flutterqr

import android.app.Activity
import android.content.pm.PackageManager
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.platform.PlatformViewRegistry
import net.touchcapture.qr.flutterqr.Shared.activity

class FlutterQrPlugin : FlutterPlugin, ActivityAware {

/** Plugin registration embedding v1 */
companion object {
@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
FlutterQrPlugin().onAttachedToV1(registrar)
}
}

private fun onAttachedToV1(registrar: PluginRegistry.Registrar) {
Shared.registrar = registrar
onAttachedToEngines(registrar.platformViewRegistry(), registrar.messenger(), registrar.activity())
}

/** Plugin registration embedding v2 */
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
onAttachedToEngines(flutterPluginBinding.platformViewRegistry, flutterPluginBinding.binaryMessenger, Shared.activity)
if (activity != null) {
activity = activity
}
flutterPluginBinding.platformViewRegistry
.registerViewFactory(
"net.touchcapture.qr.flutterqr/qrview", QRViewFactory(flutterPluginBinding.binaryMessenger))
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
}

/** Plugin start for both embedding v1 & v2 */
private fun onAttachedToEngines(platformViewRegistry: PlatformViewRegistry, messenger: BinaryMessenger, activity: Activity?) {
if (activity != null) {
Shared.activity = activity
}
platformViewRegistry
.registerViewFactory(
"net.touchcapture.qr.flutterqr/qrview", QRViewFactory(messenger))
}

override fun onAttachedToActivity(activityPluginBinding: ActivityPluginBinding) {
Shared.activity = activityPluginBinding.activity
activity = activityPluginBinding.activity
Shared.binding = activityPluginBinding
}

override fun onDetachedFromActivityForConfigChanges() {
Shared.activity = null
activity = null
Shared.binding = null
}

override fun onReattachedToActivityForConfigChanges(activityPluginBinding: ActivityPluginBinding) {
Shared.activity = activityPluginBinding.activity
activity = activityPluginBinding.activity
Shared.binding = activityPluginBinding
}

override fun onDetachedFromActivity() {
Shared.activity = null
activity = null
Shared.binding = null
}

Expand Down
10 changes: 3 additions & 7 deletions android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
Shared.binding!!.addRequestPermissionsResultListener(this)
}

if (Shared.registrar != null) {
Shared.registrar!!.addRequestPermissionsResultListener(this)
}

channel.setMethodCallHandler(this)
Shared.activity?.application?.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
override fun onActivityPaused(p0: Activity) {
Expand Down Expand Up @@ -306,14 +302,14 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
permissions: Array<out String>?,
grantResults: IntArray): Boolean {
if(requestCode == Shared.CAMERA_REQUEST_ID + this.id) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
return if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionGranted = true
channel.invokeMethod("onPermissionSet", true)
return true
true
} else {
permissionGranted = false
channel.invokeMethod("onPermissionSet", false)
return false
false
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ object Shared {
const val CAMERA_REQUEST_ID = 513469796
var activity: Activity? = null
var binding: ActivityPluginBinding? = null
var registrar: PluginRegistry.Registrar? = null
}
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
6 changes: 3 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -36,7 +36,7 @@ android {
applicationId "net.touchcapture.qr.flutterqrexample"
// minSdkVersion is determined by Native View.
minSdkVersion 20
targetSdkVersion 30
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -56,7 +56,7 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
8 changes: 2 additions & 6 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
android:label="flutter_qr_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:exported='true'
android:windowSoftInputMode="adjustResize">
<!-- Specify that the launch screen should continue being displayed -->
<!-- until Flutter renders its first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
<!-- Theme to apply as soon as Flutter begins rendering frames -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.5.10'
ext.kotlin_version = '1.5.31'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Dec 10 21:49:57 CET 2020
#Fri Oct 08 10:14:36 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit 78d4cc7

Please sign in to comment.