Skip to content

Instantly share code, notes, and snippets.

@voghDev
voghDev / DepthPageTransformer.kt
Last active March 14, 2018 13:21
Kotlin port of the original DepthPageTransformer class, found in Android SDK documentation
/*
* Copyright (C) 2018 Olmo Gallegos Hernández.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@voghDev
voghDev / findstring.sh
Created January 11, 2018 09:56
Linux alias to find a string inside all files, all folders of current location, recursively
alias findstring='grep -rnw . -e'
@voghDev
voghDev / StringExtensions.kt
Created October 23, 2017 20:42
Kotlin Function that determines if a string starts with an upper-case letter [A-Z]
fun String.startsWithUppercaseLetter() : Boolean {
return this.matches(Regex("[A-Z]{1}.*"))
}
// Very simple test to verify previous function output
@Test
fun `should calculate properly if some strings start with an uppercase letter`() {
assertFalse("lowerCaseString".startsWithUppercaseLetter())
assertTrue("This is a String".startsWithUppercaseLetter())
@voghDev
voghDev / ConfigureDefaultAdapter.kt
Last active October 18, 2017 07:27
Simple extension function to save ArrayAdapter boilerplate
fun Spinner.configureDefaultAdapter(values: List<String>) {
adapter = ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, values)
}
// Example usage:
override fun fillOptionsSpinner(options: List<Int>) {
spn_options.configureDefaultAdapter(options.map { it.toString() })
}
@voghDev
voghDev / BaseTest.kt
Last active September 29, 2017 19:33
Quick workaround to mock a context.getResources().getStringArray(...), in Kotlin
@Mock
lateinit var mockContext: Context
@Mock
lateinit var mockResources: Resources
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
}
@voghDev
voghDev / TopRoundedCornersTransformation.java
Created September 6, 2017 12:16
Picasso transformation that rounds up top-left and top-right corners. Rest of the image remains the same
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Build;
public class TopRoundedTransformation implements com.squareup.picasso.Transformation {
@voghDev
voghDev / ListEntityRendererBuilder.java
Last active November 22, 2016 12:21
ListEntityRendererBuilder
import android.content.Context;
import com.pedrogomez.renderers.Renderer;
import com.pedrogomez.renderers.RendererBuilder;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@voghDev
voghDev / SimpleTabLayout.java
Created November 3, 2016 13:18 — forked from faizsiddiqui/SimpleTabLayout.java
Android Sliding TabLayout with Icons.
package com.example.simpletablayout;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
@voghDev
voghDev / StyledTextView.java
Last active November 3, 2016 08:52
TextView subclass that applies a customized font. You also need FontFactory class, available in the first comment of this gist
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
public class StyledTextView extends TextView {
private static final int NO_STYLE = -1;
public StyledTextView(Context context) {
super(context);
@voghDev
voghDev / AddHeaderInterceptor.java
Last active August 22, 2018 08:44
Retrofit2 interceptor to add headers to HTTP requests
public class AddHeaderInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
builder.addHeader("Authorization", "headerContent");
return chain.proceed(builder.build());
}
}