New projects should follow the Android Gradle project structure that is defined on the Android Gradle plugin user guide. The ribot Boilerplate project is a good reference to start from.
Class names are written in UpperCamelCase.
import android.content.Context; | |
import com.squareup.okhttp.internal.io.FileSystem; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import okio.BufferedSource; | |
import okio.Okio; |
/** | |
* Returns response cached by OkHttp. | |
* | |
* @param url URL used to make original request | |
*/ | |
@Nullable | |
private List<PostModel> getCachedDataIfExist(final String url) { | |
// OkHttpClient saves cache using DiskLruCache, the cached data is stored in the cache dir in the files | |
// which names are created by md5 hash function, e.g. for | |
// http://www.yourserver.com/posts?filter[posts_per_page]=10&page=1 |
import android.text.SpannableStringBuilder; | |
import java.util.ArrayDeque; | |
import java.util.Deque; | |
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE; | |
/** A {@link SpannableStringBuilder} wrapper whose API doesn't make me want to stab my eyes out. */ | |
public class Truss { | |
private final SpannableStringBuilder builder; | |
private final Deque<Span> stack; |
public class DeviceDimensionsHelper { | |
// DeviceDimensionsHelper.getDisplayWidth(context) => (display width in pixels) | |
public static int getDisplayWidth(Context context) { | |
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); | |
return displayMetrics.widthPixels; | |
} | |
// DeviceDimensionsHelper.getDisplayHeight(context) => (display height in pixels) | |
public static int getDisplayHeight(Context context) { | |
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); |
/* | |
* Copyright (C) 2016 Jeff Gilfelt. | |
* | |
* 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 |
New projects should follow the Android Gradle project structure that is defined on the Android Gradle plugin user guide. The ribot Boilerplate project is a good reference to start from.
Class names are written in UpperCamelCase.
/** | |
* Utility class for fonts manipulations. | |
*/ | |
public final class FontFaceUtils { | |
public static final LruCache<String, Typeface> sCache = new LruCache<>(6); | |
private FontFaceUtils() { | |
} |
@NonNull private static Action1<Throwable> handleError(@NonNull final Context context, | |
final boolean isExpected, int stackLevel) { | |
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); | |
final StackTraceElement stackTraceElement = stackTrace[stackLevel]; | |
final String identifyingString = | |
String.format(Locale.getDefault(), "%s : %s (%d)", stackTraceElement.getClassName(), | |
stackTraceElement.getMethodName(), stackTraceElement.getLineNumber()); | |
return new Action1<Throwable>() { | |
@Override public void call(Throwable throwable) { |