Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusthiengo committed Apr 7, 2018
0 parents commit 6dd336e
Show file tree
Hide file tree
Showing 73 changed files with 1,486 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/dictionaries/viniciusthiengo.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
applicationId "thiengo.com.br.barcodeleitor"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'

implementation 'me.dm7.barcodescanner:zbar:1.9.8'

/*implementation('me.dm7.barcodescanner:zbar:1.9.8') {
exclude module: 'com.android.support'
}*/

implementation 'pub.devrel:easypermissions:1.2.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package thiengo.com.br.barcodeleitor

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("thiengo.com.br.barcodeleitor", appContext.packageName)
}
}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="thiengo.com.br.barcodeleitor">

<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FullscreenActivity"
android:theme="@style/FullscreenTheme" />
</application>

</manifest>
130 changes: 130 additions & 0 deletions app/src/main/java/thiengo/com/br/barcodeleitor/FullscreenActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package thiengo.com.br.barcodeleitor

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.Window
import android.view.WindowManager
import kotlinx.android.synthetic.main.activity_main.*
import me.dm7.barcodescanner.zbar.Result
import me.dm7.barcodescanner.zbar.ZBarScannerView
import thiengo.com.br.barcodeleitor.util.Database
import thiengo.com.br.barcodeleitor.util.unrecognizedCode


class FullscreenActivity : AppCompatActivity(),
ZBarScannerView.ResultHandler {

var isLocked = false

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

/* Algoritmo de requisição de modo fullscreen. */
requestWindowFeature( Window.FEATURE_NO_TITLE )
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN )

setContentView(R.layout.activity_fullscreen)

/*/*
* Para testes sem o uso efetivo da câmera.
* */
thread {
SystemClock.sleep(2000)
proccessBarcodeResult()
}*/

if( intent != null ){
isLocked = !intent.getBooleanExtra(Database.KEY_IS_LOCKED, false)
lockUnlock()
}
}

override fun onResume() {
super.onResume()
z_bar_scanner.setResultHandler(this)
z_bar_scanner.startCamera()
}

override fun onPause() {
super.onPause()
z_bar_scanner.stopCamera()
}


/* *** Algoritmos de interpretação de barra de código *** */
override fun handleResult( result: Result? ) {
/* Padrão Cláusula */
if( result == null ){
unrecognizedCode(this, {})
return
}

proccessBarcodeResult( result )
z_bar_scanner.resumeCameraPreview(this)
}

fun proccessBarcodeResult( result: Result? = null ){
/* Padrão Cláusula */
if( isLocked ){
return
}

val contents = result?.contents
val barcodeId = result?.barcodeFormat?.id

/*/*
* Para testes sem o uso efetivo da câmera.
* */
val contents = result?.contents ?: "https://www.thiengo.com.br"
val barcodeId = result?.barcodeFormat?.id ?: BarcodeFormat.CODE128.id */

val i = Intent()
i.putExtra( Database.KEY_CONTENTS, contents )
i.putExtra( Database.KEY_BARCODE_ID, barcodeId )
finish( i, Activity.RESULT_OK )
}

/*
* Volta para a atividade principal sempre com o isLocked
* fazendo parte do conteúdo de resposta.
* */
fun finish(intent: Intent, resultAction: Int) {
intent.putExtra(Database.KEY_IS_LOCKED, isLocked)
setResult( resultAction, intent )
finish()
}


/* *** Algoritmos de listeners de clique *** */

/*
* Para voltar ao modo "não fullscreen" antes que algum
* código de barra seja interpretado.
* */
fun closeFullscreen(view: View){
finish( Intent(), Activity.RESULT_CANCELED )
}

/*
* Função responsável por mudar o status de funcionamento
* do algoritmo de interpretação de código de barra
* lido, incluindo a mudança do ícone de apresentação,
* ao usuário, de status do algoritmo de interpretação de
* código.
* */
fun lockUnlock(view: View? = null){
isLocked = !isLocked

if(isLocked){
ib_lock.setImageResource(R.drawable.ic_lock_white_24dp)
}
else{
ib_lock.setImageResource(R.drawable.ic_lock_open_white_24dp)
}
}
}
Loading

0 comments on commit 6dd336e

Please sign in to comment.