Curated list of Most commonly used Kotlin Extensions.
This file contains hidden or 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
fun Fragment.isGranted(permission: AppPermission) = run { | |
context?.let { | |
(PermissionChecker.checkSelfPermission(it, permission.permissionName | |
) == PermissionChecker.PERMISSION_GRANTED) | |
} ?: false | |
} | |
fun Fragment.shouldShowRationale(permission: AppPermission) = run { | |
shouldShowRequestPermissionRationale(permission.permissionName) | |
} |
This file contains hidden or 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
/** | |
* Kotlin Extensions for simpler, easier and funw way | |
* of launching of Activities | |
*/ | |
inline fun <reified T : Any> Activity.launchActivity ( | |
requestCode: Int = -1, | |
options: Bundle? = null, | |
noinline init: Intent.() -> Unit = {}) | |
{ |
This file contains hidden or 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 bmutinda.com.androidutils.libs; | |
import android.view.MotionEvent; | |
import android.view.View; | |
/** | |
* Created by Mutinda Boniface on 7/5/2015. | |
*/ | |
public class SwipeEvents implements View.OnTouchListener { | |
private SwipeCallback swipeCallback; |
This file contains hidden or 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
class JsoupOgTagParser(var urlToParse: String) : AsyncTask<Void, Void, Void?>() { | |
private var title: String? = null | |
private var desc: String? = null | |
private var image: String? = null | |
private var url: String? = null | |
private var listener: Listener? = null | |
override fun doInBackground(vararg voids: Void): Void? { | |
val con = Jsoup.connect(urlToParse) |
This file contains hidden or 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
import java.io.UnsupportedEncodingException; | |
import java.security.InvalidAlgorithmParameterException; | |
import java.security.InvalidKeyException; | |
import java.security.NoSuchAlgorithmException; | |
import javax.crypto.BadPaddingException; | |
import javax.crypto.Cipher; | |
import javax.crypto.IllegalBlockSizeException; | |
import javax.crypto.NoSuchPaddingException; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.SecretKeySpec; |
This file contains hidden or 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
You can overwrite the ${USER} variable in the template file with the | |
#set( $VARIABLE = "value") | |
function. Go to Settings -> File and Code Templates -> Includes -> File Header prepend the #set() function call, for example: | |
#set( $USER = "Your name" ) | |
/** | |
* Created by ${USER} on ${DATE}. | |
*/ |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<!-- Red --> | |
<color name="material_red_50">#FFEBEE</color> | |
<color name="material_red_100">#FFCDD2</color> | |
<color name="material_red_200">#EF9A9A</color> | |
<color name="material_red_300">#E57373</color> | |
<color name="material_red_400">#EF5350</color> | |
<color name="material_red_500">#F44336</color> | |
<color name="material_red_600">#E53935</color> |
This file contains hidden or 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
long date = 1407869895000L; // August 12, 2014, 8:58PM | |
// August 12, 2014 (default) | |
DateUtils.formatDateTime(this, date, 0); | |
// Aug 12, 2014 (default with abbreviated month) | |
DateUtils.formatDateTime(this, date, DateUtils.FORMAT_ABBREV_MONTH); | |
// August 12 (date without year) | |
DateUtils.formatDateTime(this, date, DateUtils.FORMAT_NO_YEAR); |
This file contains hidden or 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
import android.app.Activity; | |
import android.content.Context; | |
import android.graphics.Rect; | |
import android.view.View; | |
import android.view.inputmethod.InputMethodManager; | |
public class KeyboardUtils { | |
public static void hideKeyboard(Activity activity) { | |
View view = activity.findViewById(android.R.id.content); |
NewerOlder