Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
EmmanuelGuther / android_aes_encrpytor.java
Created January 25, 2018 07:09 — forked from sdogruyol/android_aes_encrpytor.java
AES Encryption Singleton Class in Android Using CBC / PKCS7Padding
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;
/**
* Created by emmanuelguther on 26/01/2018.
*/
class RepeteableTransitionDrawable(layers: Array<Drawable>) : LayerDrawable(layers) {
/**
* The current state ofx the transition. One of [.TRANSITION_STARTING], [.TRANSITION_RUNNING] and [.TRANSITION_NONE]
*/
private var mTransitionState = TRANSITION_NONE
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@EmmanuelGuther
EmmanuelGuther / activity.kt
Created February 8, 2018 09:59
communicate activity with fragment
fun sendToFragment(message: String) {
FooFragment.foo(message, fooFragmentInstance as FooFragment)
}
@EmmanuelGuther
EmmanuelGuther / CapitalizeFirstLetter.kt
Last active February 15, 2018 09:54
When you want to make sure that a string starts with a capital letter and follows it lowercase
fun capitalizeFirstLetter(string: String?): String? = string?.substring(0, 1)?.toUpperCase() + string?.substring(1)?.toLowerCase()
@EmmanuelGuther
EmmanuelGuther / AccountAuthenticator.java
Created February 19, 2018 12:58 — forked from burgalon/AccountAuthenticator.java
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
@EmmanuelGuther
EmmanuelGuther / ImagePicker.java
Created February 19, 2018 18:55 — forked from Mariovc/ ImagePicker.java
Utility for picking an image from Gallery/Camera with Android Intents
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
@EmmanuelGuther
EmmanuelGuther / RetrofitGetAPIWithAuth.kt
Last active October 11, 2024 10:11
Get rest api with Auth - token and using okhttp Authenticator to manage the refresh token
object RetrofitGetAPIWithAuth {
private val BASE_URL = BuildConfig.API_BASE
private var retrofit: Retrofit? = null
private val tokenLoginModel: TokenLoginModel? = obtainTokenLoginModel()
private val accessToken = tokenLoginModel?.access_token
class HeaderInterceptor : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
@EmmanuelGuther
EmmanuelGuther / roundedBitmap.kt
Created April 15, 2018 08:38
Kotlin function to transform bitmap into roundedBitmap
fun roundedBitmap(bitmap: Bitmap): RoundedBitmapDrawable {
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(Resources.getSystem(), bitmap)
roundedBitmapDrawable.isCircular = true
roundedBitmapDrawable.cornerRadius = Math.max(bitmap.width, bitmap.height) / 2.0f
return roundedBitmapDrawable
}