Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created July 6, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/b2f946bb749557e0415a34b5099b20a6 to your computer and use it in GitHub Desktop.
Save ssaurel/b2f946bb749557e0415a34b5099b20a6 to your computer and use it in GitHub Desktop.
Main Activity of the Android Binary Converter App for the SSaurel's Channel
package com.ssaurel.binaryconverter
import android.app.Activity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.inputmethod.InputMethodManager
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
encodeBtn.setOnClickListener {
encode()
}
decodeBtn.setOnClickListener {
decode()
}
}
private fun encode() {
val txt = textToConvert.text.toString()
val binary = BinaryConverter.strToBinary(txt)
resultTv.text = binary
hideKeyboard()
}
private fun decode() {
val binary = textToConvert.text.toString()
val txt = BinaryConverter.binaryToString(binary)
resultTv.text = txt
hideKeyboard()
}
private fun hideKeyboard() {
val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
var view = currentFocus
if (view == null)
view = View(this)
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment