Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
EmmanuelGuther / ParallaxPageTransformer.kt
Last active November 15, 2017 13:52
Android PageTransformer KOTLIN to use with ViewPager
//Use like: vPager.setPageTransformer(true, ParallaxPageTransformer)
class ParallaxPageTransformer : ViewPager.PageTransformer {
override fun transformPage(view: View, position: Float) {
val pageWidth = view.width
when {
position < -1 -> view.alpha = 1f
position <= 1 -> dummyImageView.setTranslationX(-position * (pageWidth / 2)) //Half the normal speed
else -> view.alpha = 1f
@EmmanuelGuther
EmmanuelGuther / ActivityTest.java
Last active December 13, 2017 10:44
AndroidTest instrumentation: Check if activity is was launched
Instrumentation.ActivityMonitor activityBackMonitor = getInstrumentation().addMonitor(StationsActivity.class.getName(), null, false);
//CHECK IF ACTIVITY IS LAUNCHED
StationDetailActivity nextActivity = (StationDetailActivity) getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
// next activity is opened and captured.
assertNotNull(nextActivity);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
@EmmanuelGuther
EmmanuelGuther / AndroidToolbarActivityTest.txt
Created December 13, 2017 10:34
Test your toolbar back button espresso
To not depend on the app locale, you can use the code from Matt Logan by replacing "Navigate up" with R.string.abc_action_bar_up_description:
onView(withContentDescription(R.string.abc_action_bar_up_description)).perform(click());
This helped me a lot because I have an app in more than 5 languages and I had to act like this.
@EmmanuelGuther
EmmanuelGuther / BadgeTabLayout.kt
Last active December 14, 2022 03:08
Add badge to tab layout
package es.cityride.mantapp
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.support.design.widget.TabLayout
import android.util.AttributeSet
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
@EmmanuelGuther
EmmanuelGuther / AppBarAnimation.kt
Created December 15, 2017 12:22
Animate appbar
fun animationAppBarDown(appBar: AppBarLayout) {
object : CountDownTimer(300, 1) {
override fun onTick(millisUntilFinished: Long) {
appBar.translationY = (-appBar.height).toFloat()
}
override fun onFinish() {
appBar.animate()
.translationY(0f)
.setDuration(500).start()
@EmmanuelGuther
EmmanuelGuther / build.gradle
Created January 16, 2018 10:22
Proguard Android use
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
@EmmanuelGuther
EmmanuelGuther / ByteArray.kt
Created January 19, 2018 11:56 — forked from fabiomsr/ByteArray.kt
ByteArray and String extension to add hexadecimal methods in Kotlin
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])
@EmmanuelGuther
EmmanuelGuther / mock_android_context.java
Created January 22, 2018 15:53 — forked from marcouberti/mock_android_context.java
Mock Android Context using Mockito
import org.mockito.Mock;
import static org.mockito.Mockito.when;
@Mock
private Context mockApplicationContext;
@Mock
private Resources mockContextResources;
@Mock
private SharedPreferences mockSharedPreferences;
import android.util.Base64
import java.io.UnsupportedEncodingException
/**
* @param message the message to be encoded
*
* @return the enooded from of the message
*/

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a