Created
July 6, 2018 08:58
-
-
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
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
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