Skip to content

Instantly share code, notes, and snippets.

public class ProgressView extends View {
private static final int DEFAULT_PROGRESS = 0;
private static final int DEFAULT_PROGRESS_MAX = 100;
private static final int DEFAULT_COLOR_BACKGROUND = Color.GRAY;
private static final int DEFAULT_COLOR_PROGRESS = Color.BLUE;
private Paint paintProgress;
private Paint paintProgressBackground;
private int height;
@hrules6872
hrules6872 / build.gradle
Created May 27, 2016 06:52
Gradle – Create a Jar file
android.libraryVariants.all { variant ->
String taskName = "makeJar${variant.name.capitalize()}"
task(taskName, type: Copy) {
String baseFileName = "${project.name}-${variant.name}"
String outputDir = "${buildDir.getPath()}/outputs"
dependsOn "assemble${variant.name.capitalize()}"
from(zipTree("${outputDir}/aar/${baseFileName}.aar"))
into("${outputDir}/jar/")
@hrules6872
hrules6872 / SquareRelativeLayout.java
Last active June 10, 2016 12:58
SquareRelativeLayout
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
this(context, null);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@hrules6872
hrules6872 / TintedProgressBar.java
Created July 22, 2016 08:01
TintedProgressBar
public class TintedProgressBar extends ProgressBar {
public TintedProgressBar(Context context) {
this(context, null);
}
public TintedProgressBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TintedProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
@hrules6872
hrules6872 / ToolTipView.java
Created August 24, 2016 23:44
ToolTipView
/*
* +info: https://gist.github.com/romannurik/3982005
*/
public class ToolTipView {
public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
public static final int LENGTH_LONG = Toast.LENGTH_LONG;
@Retention(RetentionPolicy.CLASS) @IntDef({ LENGTH_SHORT, LENGTH_LONG }) public @interface Duration {
}
@hrules6872
hrules6872 / ManageListeners.java
Last active September 1, 2016 10:04
ManageListeners template
public void addListener(Listener listener) {
if (listeners == null) {
listeners = new ArrayList<>();
}
listeners.add(listener);
}
public void removeListener(Listener listener) {
if (listeners != null) {
int position = listeners.indexOf(listener);
@hrules6872
hrules6872 / ImageCenteredSpan.java
Created February 19, 2015 11:55
Image Centered Span
class ImageCenteredSpan extends ImageSpan {
public ImageCenteredSpan(Drawable d) {
super(d);
}
@Override
public void draw(Canvas canvas, CharSequence text,
int start, int end, float x,
int top, int y, int bottom, Paint paint) {
Drawable b = getDrawable();
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate appCompatDelegate;
@Override protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
@Override protected void onPostCreate(Bundle savedInstanceState) {
@hrules6872
hrules6872 / PlayServicesUtils.java
Created February 22, 2017 12:20
PlayServicesUtils - Get Advertising Id
public class PlayServicesUtils {
private static String advertisingId = "";
private static boolean limitAdTrackingEnabled = false;
private PlayServicesUtils() {
}
public static void prepareAdvertisingId(final Context context) {
if (TextUtils.isEmpty(advertisingId)) {
new Thread(new Runnable() {
@hrules6872
hrules6872 / ReverseIterable.java
Created February 25, 2017 12:51
ReverseIterable
public final class ReverseIterable {
private ReverseIterable() {
}
public static <T> Iterable<T> reverse(final List<T> list) {
return new ListReverseIterable<>(list);
}
private static class ListReverseIterable<T> implements Iterable<T> {
private final List<T> list;