Skip to content

Commit

Permalink
Update minSDK to 24 for latest ZXing
Browse files Browse the repository at this point in the history
Newer ZXing versions won't work on API levels below 24 because
ZXing requires support for Java 8 now. See;
zxing/zxing#1170

Because this is a major leap forward, this commit also migrates
to AndroidX (since the support library is deprecated) and removes
everything that isn't required anymore.

Development for API levels 9 to 23 will continue in the master
branch. I'm not going to drop support for API levels below 24!
  • Loading branch information
markusfisch committed Nov 14, 2019
1 parent 40c2cc9 commit d5b0d85
Show file tree
Hide file tree
Showing 36 changed files with 138 additions and 183 deletions.
24 changes: 8 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ android {
buildToolsVersion build_tools_version

defaultConfig {
minSdkVersion 9
// check out the "legacy" branch for minSdkVersion 9 to 23
minSdkVersion 24
targetSdkVersion sdk_version

versionCode 45
Expand All @@ -17,7 +18,7 @@ android {
renderscriptTargetApi 24
renderscriptSupportModeEnabled true

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

signingConfigs {
Expand Down Expand Up @@ -48,31 +49,22 @@ android {
signingConfig signingConfigs.config
}
}

lintOptions {
// because at the time of writing, even the latest version
// of RenderScript is raising this error no matter if
// renderscriptTargetApi matches targetSdkVersion
disable 'GradleCompatible'
}
}

dependencies {
androidTestImplementation ('com.android.support.test:runner:1.0.2') {
androidTestImplementation ('androidx.test.ext:junit:1.1.1') {
exclude module: 'support-annotations'
}
androidTestImplementation ('com.android.support.test:rules:1.0.2') {
androidTestImplementation ('androidx.test:rules:1.2.0') {
exclude module: 'support-annotations'
}
testImplementation 'junit:junit:4.12'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
// Do NOT upgrade ZXing because newer versions won't work on API < 24
// https://github.com/zxing/zxing/issues/1170
implementation 'com.google.zxing:core:3.3.3'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.github.markusfisch:CameraView:1.8.4'
implementation 'com.github.markusfisch:ScalingImageView:1.1.4'
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package de.markusfisch.android.binaryeye

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import de.markusfisch.android.binaryeye.rs.Preprocessor
import de.markusfisch.android.binaryeye.zxing.Zxing
Expand All @@ -16,8 +17,7 @@ class PreprocessorTest {
@Test
fun processSamples() {
val zxing = Zxing()
val assets = InstrumentationRegistry.getInstrumentation()
.context.assets
val assets = InstrumentationRegistry.getInstrumentation().context.assets
val pattern = Pattern.compile(
"[0-9]+-([0-9]+)x([0-9]+)-([0-9]+)deg.yuv"
)
Expand All @@ -32,7 +32,7 @@ class PreprocessorTest {
val frameOrientation = m.group(3) ?: return
val frameData = assets.open("yuv/$file").readBytes()
val preprocessor = Preprocessor(
InstrumentationRegistry.getTargetContext(),
ApplicationProvider.getApplicationContext(),
frameWidth.toInt(),
frameHeight.toInt(),
frameOrientation.toInt()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
android:name=".activity.MainActivity"
android:label="@string/app_name"/>
<provider
android:name="android.support.v4.content.FileProvider"
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.markusfisch.android.binaryeye.actions.vtype.vcard
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.ContactsContract
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.actions.IntentAction
Expand Down Expand Up @@ -84,38 +83,36 @@ object VCardAction : IntentAction() {
}
putExtra(ContactsContract.Intents.Insert.POSTAL, addr.value.locationFormat)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
val urls = info["URL"]?.mapNotNull {
it.value.takeIf { url -> url.isNotBlank() }?.let { url ->
ContentValues(2).apply {
put(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE
)
put(ContactsContract.CommonDataKinds.Website.URL, url)
}
val urls = info["URL"]?.mapNotNull {
it.value.takeIf { url -> url.isNotBlank() }?.let { url ->
ContentValues(2).apply {
put(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE
)
put(ContactsContract.CommonDataKinds.Website.URL, url)
}
}
val bDays = info["BDAY"]?.mapNotNull {
it.value.takeIf { day -> day.isNotBlank() }?.let { day ->
ContentValues(3).apply {
put(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE
)
put(
ContactsContract.CommonDataKinds.Event.TYPE,
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY
)
put(ContactsContract.CommonDataKinds.Event.START_DATE, day)
}
}
val bDays = info["BDAY"]?.mapNotNull {
it.value.takeIf { day -> day.isNotBlank() }?.let { day ->
ContentValues(3).apply {
put(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE
)
put(
ContactsContract.CommonDataKinds.Event.TYPE,
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY
)
put(ContactsContract.CommonDataKinds.Event.START_DATE, day)
}
}
putParcelableArrayListExtra(
ContactsContract.Intents.Insert.DATA,
ArrayList(listOfNotNull(urls, bDays).flatten())
)
}
putParcelableArrayListExtra(
ContactsContract.Intents.Insert.DATA,
ArrayList(listOfNotNull(urls, bDays).flatten())
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.CalendarContract
import android.support.annotation.RequiresApi
import androidx.annotation.RequiresApi
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.actions.IntentAction
import de.markusfisch.android.binaryeye.actions.vtype.VTypeParser
Expand All @@ -21,8 +21,7 @@ object VEventAction : IntentAction() {
get() = R.string.vevent_failed

override fun canExecuteOn(data: ByteArray): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
&& VTypeParser.parseVType(String(data)) == "VEVENT"
return VTypeParser.parseVType(String(data)) == "VEVENT"
}

@RequiresApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import android.hardware.Camera
import android.net.Uri
import android.os.Bundle
import android.os.Vibrator
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import androidx.appcompat.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -67,6 +66,7 @@ class CameraActivity : AppCompatActivity() {
resultCode: Int,
resultData: Intent?
) {
super.onActivityResult(requestCode, resultCode, resultData)
when (requestCode) {
PICK_FILE_RESULT_CODE -> {
if (resultCode == Activity.RESULT_OK && resultData != null) {
Expand All @@ -84,12 +84,12 @@ class CameraActivity : AppCompatActivity() {
setContentView(R.layout.activity_camera)

initSystemBars(this)
setSupportActionBar(findViewById(R.id.toolbar) as Toolbar)
setSupportActionBar(findViewById(R.id.toolbar))

vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator

cameraView = findViewById(R.id.camera_view) as CameraView
zoomBar = findViewById(R.id.zoom) as SeekBar
cameraView = findViewById(R.id.camera_view)
zoomBar = findViewById(R.id.zoom)
flashFab = findViewById(R.id.flash)
flashFab.setOnClickListener { toggleTorchMode() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package de.markusfisch.android.binaryeye.activity

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import androidx.appcompat.app.AppCompatActivity
import com.google.zxing.BarcodeFormat
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.app.initSystemBars
Expand All @@ -32,7 +30,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
initSystemBars(this)

setSupportActionBar(findViewById(R.id.toolbar) as Toolbar)
setSupportActionBar(findViewById(R.id.toolbar))
supportActionBar?.setDisplayHomeAsUpEnabled(true)

supportFragmentManager.addOnBackStackChangedListener {
Expand Down Expand Up @@ -92,13 +90,9 @@ class MainActivity : AppCompatActivity() {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra(ENCODE, text)
if (isExternal) {
val flagActivityClearTask =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Intent.FLAG_ACTIVITY_CLEAR_TASK
} else 0
intent.addFlags(
Intent.FLAG_ACTIVITY_NO_HISTORY or
flagActivityClearTask or
Intent.FLAG_ACTIVITY_CLEAR_TASK or
Intent.FLAG_ACTIVITY_NEW_TASK
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import androidx.appcompat.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.app.initSystemBars
Expand All @@ -30,7 +30,7 @@ class PickActivity : AppCompatActivity() {
setContentView(R.layout.activity_pick)
initSystemBars(this)

setSupportActionBar(findViewById(R.id.toolbar) as Toolbar)
setSupportActionBar(findViewById(R.id.toolbar))
supportActionBar?.setDisplayHomeAsUpEnabled(true)

supportFragmentManager.addOnBackStackChangedListener {
Expand Down Expand Up @@ -61,10 +61,10 @@ class PickActivity : AppCompatActivity() {
return
}

cropImageView = findViewById(R.id.image) as CropImageView
cropImageView = findViewById(R.id.image)
cropImageView.setImageBitmap(bitmap)

findViewById(R.id.scan).setOnClickListener {
findViewById<View>(R.id.scan).setOnClickListener {
val detail = crop(
bitmap,
cropImageView.normalizedRectInBounds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.markusfisch.android.binaryeye.activity

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.appcompat.app.AppCompatActivity

class SplashActivity : AppCompatActivity() {
override fun onCreate(state: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.markusfisch.android.binaryeye.app

import android.app.Application
import android.support.v8.renderscript.RenderScript
import androidx.renderscript.RenderScript
import de.markusfisch.android.binaryeye.preference.Preferences
import de.markusfisch.android.binaryeye.repository.DatabaseRepository

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@ package de.markusfisch.android.binaryeye.app

import android.annotation.SuppressLint
import android.content.Context
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v7.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.appcompat.app.AlertDialog
import android.view.View
import de.markusfisch.android.binaryeye.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

fun setFragment(fm: FragmentManager?, fragment: Fragment) {
fun setFragment(
fm: androidx.fragment.app.FragmentManager?,
fragment: androidx.fragment.app.Fragment
) {
fm?.let { getTransaction(fm, fragment).commit() }
}

fun addFragment(fm: FragmentManager?, fragment: Fragment) {
fun addFragment(
fm: androidx.fragment.app.FragmentManager?,
fragment: androidx.fragment.app.Fragment
) {
fm?.let { getTransaction(fm, fragment).addToBackStack(null).commit() }
}

@SuppressLint("CommitTransaction")
private fun getTransaction(
fm: FragmentManager,
fragment: Fragment
fm: androidx.fragment.app.FragmentManager,
fragment: androidx.fragment.app.Fragment
) = fm.beginTransaction().replace(R.id.content_frame, fragment)

suspend inline fun View.useVisibility(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package de.markusfisch.android.binaryeye.app

import android.net.Uri
import android.os.Build

private val nonPrintable = "[\\x00-\\x08\\x0e-\\x1f]".toRegex()

fun hasNonPrintableCharacters(s: String) = nonPrintable.containsMatchIn(s)

fun parseAndNormalizeUri(input: String): Uri = Uri.parse(input).let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) it.normalizeScheme() else it
it.normalizeScheme()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.markusfisch.android.binaryeye.app
import android.app.Activity
import android.content.Context
import android.os.Environment
import android.support.annotation.MainThread
import androidx.annotation.MainThread
import android.widget.EditText
import de.markusfisch.android.binaryeye.R
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package de.markusfisch.android.binaryeye.app
import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

fun hasCameraPermission(activity: Activity, requestCode: Int): Boolean {
return hasPermission(activity, Manifest.permission.CAMERA, requestCode)
Expand Down
Loading

0 comments on commit d5b0d85

Please sign in to comment.