-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted activity to kt code & improved custom context syntax
- Loading branch information
1 parent
e03fc23
commit 4cb8367
Showing
5 changed files
with
62 additions
and
74 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
71 changes: 0 additions & 71 deletions
71
app/src/main/java/com/andreacioccarelli/billingprotectorsample/DetectionActivity.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/andreacioccarelli/billingprotectorsample/DetectionActivity.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,56 @@ | ||
package com.andreacioccarelli.billingprotectorsample | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.app.Activity | ||
import android.content.Context | ||
import android.os.Vibrator | ||
import android.support.design.widget.FloatingActionButton | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
|
||
import com.andreacioccarelli.billingprotector.* | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.system.measureTimeMillis | ||
|
||
class DetectionActivity : Activity() { | ||
|
||
private lateinit var bp: BillingProtector | ||
|
||
@SuppressLint("SetTextI18n") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity) | ||
|
||
bp = BillingProtector(this) | ||
runRefresh() | ||
|
||
val fab = findViewById<FloatingActionButton>(R.id.fab) | ||
fab.setOnClickListener { | ||
val vib = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator | ||
vib.vibrate(100) | ||
|
||
runRefresh() | ||
} | ||
} | ||
|
||
private fun runRefresh() = CoroutineScope(Dispatchers.Main).launch { | ||
val millis = measureTimeMillis { updateData() } | ||
val seconds = TimeUnit.MILLISECONDS.toSeconds(millis) | ||
|
||
runOnUiThread { | ||
Toast.makeText(this@DetectionActivity, "Re-computed. time: ${seconds}s", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
private var i = 0 | ||
@SuppressLint("SetTextI18n") | ||
private suspend fun updateData() { | ||
val mxp = findViewById<TextView>(R.id.mxp) | ||
mxp.text = "i=${i++}\nisRootInstalled: ${bp.isRootInstalled()}\npirateAppsList: ${bp.getPirateAppsListAsync()}" | ||
} | ||
} |
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