forked from eclipse-keyple/keyple-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refact: Demo app, step to kotlin and new features
- Loading branch information
Showing
8 changed files
with
179 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,3 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
|
||
# uncomment keyple_version to force using a specific version of keyple artifacts | ||
# by default, the last version available is used, value '+' | ||
#keyple_version=0.8.0 | ||
|
||
|
||
#keyple components | ||
slf4japi_version = 1.7.25 | ||
slf4jsimple_version = 1.7.25 | ||
slf4jext_version = 1.7.25 | ||
junit_version = 4.12 | ||
|
||
#android log | ||
android_logback_version = 1.1.1-12 | ||
|
||
#android support | ||
android_support_version = 26.1.0 | ||
android_support_constraint_version = 1.0.2 | ||
android_support_test = 1.0.1 | ||
android_support_espresso = 3.0.1 | ||
|
||
android.useAndroidX=true | ||
android.enableJetifier=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 0 additions & 125 deletions
125
...id/omapi/src/main/java/org/eclipse/keyple/example/calypso/android/omapi/MainActivity.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...id/omapi/src/main/kotlin/org/eclipse/keyple/example/calypso/android/omapi/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.eclipse.keyple.example.calypso.android.omapi | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AlertDialog | ||
import kotlinx.coroutines.* | ||
import org.eclipse.keyple.core.seproxy.SeProxyService | ||
import org.eclipse.keyple.core.seproxy.SeReader | ||
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException | ||
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginNotFoundException | ||
import org.eclipse.keyple.plugin.android.omapi.AndroidOmapiPlugin | ||
import org.eclipse.keyple.plugin.android.omapi.AndroidOmapiPluginFactory | ||
import timber.log.Timber | ||
import java.util.* | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
companion object{ | ||
private const val MAX_TRIES = 10 | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
initActionBar() | ||
|
||
/* Get the instance of the SeProxyService (Singleton pattern) */ | ||
val seProxyService = SeProxyService.getInstance() | ||
|
||
/* register Omapi Plugin to the SeProxyService */ | ||
try { | ||
seProxyService.registerPlugin(AndroidOmapiPluginFactory(this)) | ||
} catch (e: KeyplePluginInstantiationException) { | ||
e.printStackTrace() | ||
} | ||
|
||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
//Retrieve OMAPI Readers, can't observed but may take time. | ||
//So we retry every second 10 times | ||
progressBar.visibility = View.VISIBLE | ||
|
||
CoroutineScope(Dispatchers.Main).launch{ | ||
try { | ||
val readers = connectOmapi() | ||
//readers are initialized, we can show the menu | ||
connectOmapiTV.visibility = View.GONE | ||
} catch (e: KeyplePluginNotFoundException) { | ||
Timber.e(e) | ||
showAlertDialog(e) | ||
} catch (e: KeyplePluginInstantiationException){ | ||
Timber.e(e) | ||
showAlertDialog(e) | ||
}finally { | ||
progressBar.visibility = View.INVISIBLE | ||
} | ||
} | ||
} | ||
|
||
private fun initActionBar(){ | ||
setSupportActionBar(toolbar) | ||
val actionBar = supportActionBar | ||
actionBar?.title = "Hello APP" | ||
actionBar?.subtitle = "App subtitle" | ||
actionBar?.setDisplayShowHomeEnabled(true) | ||
actionBar?.setLogo(R.mipmap.ic_launcher) | ||
actionBar?.setDisplayUseLogoEnabled(true) | ||
} | ||
|
||
|
||
@Throws(KeyplePluginNotFoundException::class, KeyplePluginInstantiationException::class) | ||
private suspend fun connectOmapi(): SortedSet<SeReader> = withContext(Dispatchers.IO) { | ||
var readers : SortedSet<SeReader>? = null | ||
for(x in 1..MAX_TRIES){ | ||
readers = SeProxyService.getInstance() | ||
.getPlugin(AndroidOmapiPlugin.PLUGIN_NAME).readers | ||
if(readers == null|| readers.size < 1) { | ||
Timber.d("No readers found in OMAPI Keyple Plugin") | ||
Timber.d("Retrying in 1 second") | ||
delay(1000) | ||
}else{ | ||
Timber.d("Readers Found") | ||
break | ||
} | ||
} | ||
|
||
readers ?: throw KeyplePluginInstantiationException(getString(R.string.error_no_reader_found, MAX_TRIES)) | ||
} | ||
|
||
private fun showAlertDialog(t: Throwable){ | ||
val builder = AlertDialog.Builder(this@MainActivity) | ||
builder.setTitle(R.string.alert_dialog_title) | ||
builder.setMessage(getString(R.string.alert_dialog_message, t.message)) | ||
val dialog = builder.create() | ||
dialog.show() | ||
|
||
} | ||
} |
Oops, something went wrong.