(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| public class MyApp extends Application { | |
| @Override | |
| public void onCreate() { | |
| TypefaceUtil.overrideFont(getApplicationContext(), "SERIF", "fonts/Roboto-Regular.ttf"); // font from assets: "assets/fonts/Roboto-Regular.ttf | |
| } | |
| } |
| /** | |
| * ArcUtils.java | |
| * | |
| * Copyright (c) 2014 BioWink GmbH. | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| * of this software and associated documentation files (the "Software"), to deal | |
| * in the Software without restriction, including without limitation the rights | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| * copies of the Software, and to permit persons to whom the Software is |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import rx.Observable; | |
| import rx.subjects.PublishSubject; | |
| import rx.subjects.SerializedSubject; | |
| import rx.subjects.Subject; | |
| /** | |
| * Simple pass-thru event bus with error handling and reconnect. | |
| */ | |
| public class EventBus { |
| import java.io.InputStream; | |
| import java.io.OutputStream; | |
| public interface Converter { | |
| public <T> T fromJson(InputStream in, Class<T> clazz) throws ConversionException; | |
| public <T> void toJson(OutputStream os, T object) throws ConversionException; | |
| public class ConversionException extends Exception { | |
| public ConversionException(Throwable throwable) { |
| // status bar height | |
| int statusBarHeight = 0; | |
| int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); | |
| if (resourceId > 0) { | |
| statusBarHeight = getResources().getDimensionPixelSize(resourceId); | |
| } | |
| // action bar height | |
| int actionBarHeight = 0; | |
| final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes( |
| def buildConfigAndResStringField(variant, name, value) { | |
| variant.resValue 'string', name.toLowerCase(), value | |
| variant.buildConfigField 'String', name, "\"$value\"" | |
| } | |
| afterEvaluate { | |
| android.applicationVariants.all { variant -> | |
| variant.resValue 'string', 'application_id', variant.applicationId | |
| buildConfigAndResStringField variant, "ACCOUNT_TYPE", variant.applicationId | |
| buildConfigAndResStringField variant, "CONTENT_AUTHORITY", variant.applicationId + ".provider" |
| public class ArcToBezier { | |
| /** | |
| * Usage: | |
| * | |
| * javac ArcToBezier.java | |
| * java ArcToBezier x0 y0 x1 x2 rx ry theta large-arc-flag sweep-flag | |
| * | |
| * where (x0, y0) are the starting points of the arc, and the rest of the | |
| * arguments correspond to the values in the elliptical arc curve command: |
| <?xml version="1.0" encoding="utf-8"?> | |
| <!-- | |
| Copyright 2016 Google Inc. | |
| 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 |
| import android.support.v7.widget.RecyclerView; | |
| public class RecyclerViewSwipeListener extends RecyclerView.OnFlingListener { | |
| private static final int SWIPE_VELOCITY_THRESHOLD = 2000; | |
| boolean mIsScrollingVertically; | |
| // change swipe listener depending on whether we are scanning items horizontally or vertically | |
| RecyclerViewSwipeListener(boolean vertical) { |