Skip to content

Instantly share code, notes, and snippets.

View logcat's full-sized avatar

Sergii Golub logcat

View GitHub Profile
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import android.util.Log;
/*
* Copyright (C) 2013 Google, 2014 Stefano Dacchille
*
* 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
public class Transformers {
public static <T> Observable.Transformer<Iterable<T>, T> flatten() {
return new Observable.Transformer<Iterable<T>, T>() {
@Override
public Observable<T> call(Observable<Iterable<T>> iterableObservable) {
return iterableObservable.flatMap(new Func1<Iterable<T>, Observable<T>>() {
@Override
public Observable<T> call(Iterable<T> iterable) {
return Observable.from(iterable);
public static Field getField(Class<?> clazz, String fieldName) {
Class<?> tmpClass = clazz;
do {
try {
Field f = tmpClass.getDeclaredField(fieldName);
f.setAccessible(true);
return f;
} catch (NoSuchFieldException e) {
tmpClass = tmpClass.getSuperclass();
}
@logcat
logcat / giffify.sh
Last active August 29, 2015 14:24 — forked from rock3r/giffify.py
#!/bin/sh
# License for any modification to the original (linked below):
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Sebastiano Poggi wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
# ----------------------------------------------------------------------------
#
# Based upon http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
@logcat
logcat / Locale Activity Rule
Created July 15, 2015 06:50
Android activity role to change and test different locales
public static final Locale FRENCH_LOCALE = new Locale("fr", "FR");
@Rule
public ActivityTestRule<SplashScreenActivity> activityRule = new ActivityTestRule(SplashScreenActivity.class, true, true) {
@Override
protected void beforeActivityLaunched() {
super.beforeActivityLaunched();
Locale.setDefault(FRENCH_LOCALE);
public class Screenshot {
public static final String TAG = Screenshot.class.getSimpleName();
public static void takeScreenshot(String name, Activity activity) {
String testDirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test-screenshots";
File testDir = new File(testDirPath);
testDir.mkdirs();
View scrView = activity.getWindow().getDecorView().getRootView();
@logcat
logcat / TypedCursor.java
Created August 14, 2015 10:36
Android generic cursor with basic binding
import android.annotation.TargetApi;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.os.Build;
import java.lang.reflect.Field;
public class TypedCursor<T> extends CursorWrapper {
private Class<T> aClass;
import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import android.view.View;
public class InstantAutoCompleteTextView extends AppCompatAutoCompleteTextView {
public InstantAutoCompleteTextView(Context context) {
super(context);
@logcat
logcat / DropDownSpinner.java
Last active August 29, 2015 14:27
Based on AppCompatAutoCompleteTextView suggestions
import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
// style it with @style/Widget.AppCompat.Spinner.Underlined