Skip to content

Instantly share code, notes, and snippets.

@makorowy
makorowy / ConsentsView.kt
Last active March 2, 2019 13:10
Sample for article needs - How to create a compound view?
class ConsentsView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
var onConsentsCheckedChangeListener: (allConsentsChecked: Boolean) -> Unit = {}
init {
LayoutInflater.from(context).inflate(R.layout.consents_view, this, true)
consent1.setOnCheckedChangeListener { _, _ -> validateConsents() }
@makorowy
makorowy / consents_view.xml
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/consentsTitle"
android:layout_width="wrap_content"
@makorowy
makorowy / activity_main.xml
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<include
@makorowy
makorowy / MainActivity.kt
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
consent1.setOnCheckedChangeListener { _, _ -> validateConsents() }
consent2.setOnCheckedChangeListener { _, _ -> validateConsents() }
}
@makorowy
makorowy / activity_main.xml
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
@makorowy
makorowy / MainActivity.kt
Created March 1, 2018 06:35
TensorFlow Hot or Not example. Show the result.
class MainActivity : AppCompatActivity {
//...
private fun classifyAndShowResult(croppedBitmap: Bitmap) {
runInBackground(
Runnable {
val result = classifier.recognizeImage(croppedBitmap)
showResult(result)
})
@makorowy
makorowy / ImageClassifier.kt
Created February 28, 2018 06:57
TensorFlow Hot or Not example. Image classifier.
private const val ENABLE_LOG_STATS = false
class ImageClassifier (
private val inputName: String,
private val outputName: String,
private val imageSize: Long,
private val labels: List<String>,
private val imageBitmapPixels: IntArray,
private val imageNormalizedPixels: FloatArray,
private val results: FloatArray,
@makorowy
makorowy / ImageClassifierFactory.kt
Last active January 17, 2019 09:39
TensorFlow Hot or Not example. Classifier factory.
object ImageClassifierFactory {
fun create(
assetManager: AssetManager,
graphFilePath: String,
labelsFilePath: String,
imageSize: Int,
inputName: String,
outputName: String
): Classifier {
@makorowy
makorowy / MainActivity.kt
Last active March 1, 2018 07:14
TensorFlow Hot or Not example. Classification of the taken photo.
class MainActivity : AppCompatActivity {
//...
private val handler = Handler()
private var photoFilePath = ""
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val file = File(photoFilePath)
if (requestCode == REQUEST_TAKE_PICTURE && file.exists()) {
classifyPhoto(file)
@makorowy
makorowy / Constants.kt
Created February 25, 2018 19:37
TensorFlow - Hot or Not example. Constants.
const val GRAPH_FILE_PATH = "file:///android_asset/graph.pb"
const val LABELS_FILE_PATH = "file:///android_asset/labels.txt"
const val GRAPH_INPUT_NAME = "input"
const val GRAPH_OUTPUT_NAME = "final_result"
const val IMAGE_SIZE = 224