Skip to content

Instantly share code, notes, and snippets.

@rharter
rharter / RevealDrawable.java
Created April 3, 2015 17:41
A Drawable that transitions between two child Drawables based on this Drawable's current level value. The idea here is that the center value (5000) will show the 'selected' Drawable, and any other value will show a transitional value between the 'selected' Drawable and the 'unselected' Drawable.
package com.pixite.fragment.widget;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.Callback;
import android.view.Gravity;
@quanturium
quanturium / SimpleCursorRecyclerAdapter.java
Created April 19, 2015 22:00
Implementation of SimpleCursorAdapter for the new RecyclerView. It extends this gist: https://gist.github.com/quanturium/46541c81aae2a916e31d
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 ARNAUD FRUGIER
*
* 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
@pbakondy
pbakondy / isNotificationEnabled.java
Created July 20, 2015 10:01
Cordova - Push Notifications - Android - How to check notifications are disabled for the application?
// Cordova - Push Notifications - Android
// How to check notifications are disabled for the application?
// Works on Andoid 4.4+ (KitKat)
// Otherwise returns 'true'
// original:
// http://stackoverflow.com/questions/11649151/
public class NotificationsUtils {
@SeongUgJung
SeongUgJung / other publishsubject
Last active August 29, 2015 14:26
publishsubject + flatmap problem
List<ChatChooseItem> chatChooseItems = getMockItems();
List<ChatChooseItem> testList = new ArrayList<>();
PublishSubject<String> publishSubject = PublishSubject.create();
publishSubject
.throttleWithTimeout(300, TimeUnit.MILLISECONDS)
.flatMap(s -> Observable.from(chatChooseItems)
.filter(chatChooseItem -> chatChooseItem.getName().toLowerCase().contains(s.toLowerCase()))
.toSortedList((lhs, rhs) -> lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase()))
)
@ftvs
ftvs / PhonecallReceiver.java
Last active October 26, 2025 18:51
Detecting an incoming call coming to an Android device. Remember to set the appropriate permissions in AndroidManifest.xml as suggested in the Stackoverflow link. Usage example in comments. Source: Gabe Sechan http://stackoverflow.com/a/15564021/264619 Explanation: http://gabesechansoftware.com/is-the-phone-ringing/#more-8
package com.gabesechan.android.reusable.receivers;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
@jvanderwee
jvanderwee / YouTubeHelper.java
Created August 5, 2015 16:39
Extract video id from YouTube url in java
import com.google.inject.Singleton;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Singleton
public class YouTubeHelper {
final String youTubeUrlRegEx = "^(https?)?(://)?(www.)?(m.)?((youtube.com)|(youtu.be))/";
final String[] videoIdRegex = { "\\?vi?=([^&]*)","watch\\?.*v=([^&]*)", "(?:embed|vi?)/([^/?]*)", "^([A-Za-z0-9\\-]*)"};
package productmeister.com.productmeister.view;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.design.widget.AppBarLayout;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@rogerhu
rogerhu / EndlessRecyclerViewScrollListener.java
Last active October 6, 2022 04:42
Endless RecyclerView scrolling for different layout managers
public abstract class EndlessRecyclerViewScrollListener extends RecyclerView.OnScrollListener {
// The minimum amount of items to have below your current scroll position
// before loading more.
private int visibleThreshold = 5;
// The current offset index of data you have loaded
private int currentPage = 0;
// The total number of items in the dataset after the last load
private int previousTotalItemCount = 0;
// True if we are still waiting for the last set of data to load.
private boolean loading = true;
@chonamdoo
chonamdoo / PhonecallReceiver.java
Created January 22, 2016 04:58 — forked from ftvs/PhonecallReceiver.java
Detecting an incoming call coming to an Android device. Remember to set the appropriate permissions in AndroidManifest.xml as suggested in the Stackoverflow link. Usage example in comments. Source: http://stackoverflow.com/a/15564021/264619 Explanation: http://gabesechansoftware.com/is-the-phone-ringing/#more-8
package com.gabesechan.android.reusable.receivers;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
@joinAero
joinAero / BuildProperties.java
Created February 17, 2016 06:58
Android - Helper for accessing os properties.
package cc.cubone.turbo.core.os;
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Enumeration;