Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
EmmanuelGuther / CircularImageView.kt
Created April 15, 2018 09:36
Kotlin circular imageview
class CircularImageView : ImageView {
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {}
override fun onDraw(canvas: Canvas) {
@EmmanuelGuther
EmmanuelGuther / HideShowKeyboard.kt
Created May 16, 2018 15:37
Extension function to hide or show keyboard
fun AppCompatActivity.toggleHideShowKeyboard() {
val inputMethodManager = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
when {
inputMethodManager.isActive -> inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
else -> inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0) // hide
}
}
@EmmanuelGuther
EmmanuelGuther / HideKeyboard.kt
Created May 16, 2018 16:30
Kotlin extension function to hide keyboard if it is being shown
fun AppCompatActivity.hideKeyBoard(){
val view = this.currentFocus
if (view != null) {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
@EmmanuelGuther
EmmanuelGuther / Snackbar.kt
Created June 1, 2018 10:58
Kotlin extension function to easy change snackbar text color
fun Snackbar.setTextColor(color: Int): Snackbar {
val tv = view.findViewById(android.support.design.R.id.snackbar_text) as TextView
tv.setTextColor(color)
return this
}
@EmmanuelGuther
EmmanuelGuther / regexStrongPassword.kt
Created June 6, 2018 10:17
REGEX STRONG PASSWORD
Description of this regular expression is as below:
Passwords will contain at least 1 upper case letter
Passwords will contain at least 1 lower case letter
Passwords will contain at least 1 number or special character
Passwords will contain at least 8 characters in length
Password maximum length should not be arbitrarily limited
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
@EmmanuelGuther
EmmanuelGuther / Logout.kt
Created June 6, 2018 11:13
A way to close all activities except one. Android Kotlin
fun closeActivitiesGoLogin(context: Context?) {
val intent = Intent(context, LoginActivity::class.java)
val cn = intent.component
val mainIntent = Intent.makeRestartActivityTask(cn)
context?.startActivity(mainIntent)
}
@EmmanuelGuther
EmmanuelGuther / View.kt
Last active June 20, 2018 14:34
Kotlin function extension to change color animatedly
fun View.changeColorAnimatedly(duration: Long, repeatable: Boolean, startColor: Int, endColor: Int) {
val anim = ObjectAnimator.ofInt(this, "backgroundColor", startColor, endColor)
anim.duration = duration
anim.setEvaluator(ArgbEvaluator())
if (repeatable) {
anim.repeatCount = ValueAnimator.INFINITE
anim.repeatMode = ValueAnimator.REVERSE
}
anim.start()
}
@EmmanuelGuther
EmmanuelGuther / android_screen_size_dimens_folder.txt
Created September 4, 2018 13:04
android screen size dimens folder
values-sw720dp 10.1” tablet 1280x800 mdpi
values-sw600dp 7.0” tablet 1024x600 mdpi
values-sw480dp 5.4” 480x854 mdpi
values-sw480dp 5.1” 480x800 mdpi
values-xxhdpi 5.5" 1080x1920 xxhdpi
values-xxxhdpi 5.5" 1440x2560 xxxhdpi
private fun printKeyHash() {
try {
val info = activity?.packageManager?.getPackageInfo("com.s", PackageManager.GET_SIGNATURES)
for (signature in info!!.signatures!!) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
}
} catch (e: PackageManager.NameNotFoundException) {
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutHeaderNavView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">