Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
EmmanuelGuther / ListViewToFlatList.js
Last active May 5, 2017 11:01
REACT-NATIVE: ListView to the new FlatView
import React from 'react'
import { Text } from 'react-native'
import FlatList from 'react-native/Libraries/Lists/FlatList'
import dataList from './dataList'
export default class ListViewToFlatList extends React.Component {
renderItem ({ item, index }) {
return <Text>{item}</Text>
}
@EmmanuelGuther
EmmanuelGuther / getFlatList.bash
Created May 5, 2017 11:51 — forked from cooperka/getFlatList.bash
How to download FlatList and its related dependencies directly into your node_modules.
mkdir -p node_modules/react-native/Libraries/Lists/ && \
for file in 'FlatList' 'MetroListView' 'SectionList' 'VirtualizedList' 'VirtualizedSectionList' 'ViewabilityHelper' 'VirtualizeUtils'; \
do curl https://raw.githubusercontent.com/facebook/react-native/master/Libraries/Lists/${file}.js > node_modules/react-native/Libraries/Lists/${file}.js; \
done
@EmmanuelGuther
EmmanuelGuther / gettingNewFlatList.bash
Created May 5, 2017 11:57
At the moment it is not available, we must take it from the master branch
mkdir -p node_modules/react-native/Libraries/Lists/ && \
for file in 'FlatList' 'MetroListView' 'SectionList' 'VirtualizedList' 'VirtualizedSectionList' 'ViewabilityHelper' 'VirtualizeUtils'; \
do curl https://raw.githubusercontent.com/facebook/react-native/master/Libraries/Lists/${file}.js > node_modules/react-native/Libraries/Lists/${file}.js; \
done
@EmmanuelGuther
EmmanuelGuther / latAndlonGenerator.js
Last active May 9, 2017 13:04
These functions are for to generate points uniformly, randomly, and independently within a circle of radius r around a location (x0, y0),
/*These functions are for to generate points uniformly, randomly, and independently
within a circle of radius r around a location (x0, y0),
*/
function latAndlonGenerator (radius) {
const RADIUS_IN_METERS = 70000
let r = RADIUS_IN_METERS / 111300, // Convert meters in degrees (111,300 meters = a degree.)
y0 = 40.416775, // Central point where to generate more coordinates, inside a circle
x0 = -3.70379, // In this case, Madrid.
u = Math.random(),
v = Math.random(),
@EmmanuelGuther
EmmanuelGuther / goToActivity.java
Created August 1, 2017 12:44
ANDROID - Go to activity with transition
private void goToActivity(View view, Activity fromActivity,
final Class<? extends Activity> toActivity) {
Intent i = new Intent(fromActivity, toActivity);
Bundle bundle;
if (Build.VERSION.SDK_INT >= 23) {
bundle = ActivityOptions.makeClipRevealAnimation(view, 0, 0, view.getWidth(),
view.getHeight()).toBundle();
} else {
bundle = ActivityOptions.makeScaleUpAnimation(view, 0, 0, view.getWidth(),
view.getHeight()).toBundle();
@EmmanuelGuther
EmmanuelGuther / SimpleViewAnimation.java
Created August 1, 2017 13:29
ANDROID - Class to animate views
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.animation.AnimationUtils;
public class SimpleViewAnimation {
public static final int SLOW_ANIM = 1900;
public static final int FAST_ANIM = 800;
public static final int DELAY_ANIM_DEFAULT = 500;
@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 / 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'