Skip to content

Instantly share code, notes, and snippets.

View vmax's full-sized avatar
🏠
Working from home

Max Vorobev vmax

🏠
Working from home
View GitHub Profile
@vmax
vmax / DateTimeAwareJSONEncoder.py
Created August 31, 2016 11:51
Class that helps to serialize Python datetime/date/timedelta class
class DateTimeAwareJSONEncoder(json.JSONEncoder):
"""
A JSONEncoder subclass for handling objects of types `timedelta`, `datetime` and `date`
"""
def default(self, obj):
if isinstance(obj, datetime):
return {
'__type__': 'datetime',
'year': obj.year,
'month': obj.month,
@vmax
vmax / LayoutTransitionLogger.java
Created July 25, 2016 10:02
Class that helps to debug layout changes animation
package vmax.myway;
import android.animation.LayoutTransition;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
public class LayoutTransitionLogger implements LayoutTransition.TransitionListener {
private String logTAG;
@vmax
vmax / EmptyRecyclerView.java
Last active July 10, 2016 12:29 — forked from meoyawn/EmptyRecyclerView.java
RecyclerView doesn't have an emptyView support, we gotta fix that (but you may also need to show a view when it's non empty, that's why the fork)
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
public class EmptyRecyclerView extends RecyclerView {
private View emptyView, nonEmptyView;
final private AdapterDataObserver observer = new AdapterDataObserver() {
@vmax
vmax / DelayAutoCompleteTextView.java
Created July 10, 2016 12:26
AutoCompleteTextView that delays sending requests to adapter (needed if suggestions are being queried from external API). Also shows progress bar when loading suggestions.
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.ProgressBar;
public class DelayAutoCompleteTextView extends AutoCompleteTextView {
@vmax
vmax / ViewWeightAnimationWrapper.java
Created April 4, 2016 17:57
A wrapper for animating changes of android:weight property of views inside LinearLayout using ObjectAnimator
public class ViewWeightAnimationWrapper {
private View view;
public ViewWeightAnimationWrapper(View view) {
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
this.view = view;
} else {
throw new IllegalArgumentException("The view should have LinearLayout as parent");
}
}