Skip to content

Instantly share code, notes, and snippets.

View rajeefmk's full-sized avatar

RmK rajeefmk

  • Bangalore
View GitHub Profile
@rajeefmk
rajeefmk / IconCounterUtils.java
Created February 2, 2018 10:38
Add counter to any icon
public class IconCounterUtils {
public static void setCounterValue(Context mContext, LayerDrawable icon, int count) {
CounterDrawable mCounterDrawable;
Drawable reuse = icon.findDrawableByLayerId(R.id.ic_counter);
if (reuse != null && reuse instanceof CounterDrawable) {
mCounterDrawable = (CounterDrawable) reuse;
} else {
mCounterDrawable = new CounterDrawable(mContext);
}
@rajeefmk
rajeefmk / AppTextView.java
Last active July 30, 2020 12:05
Custom Textview with helper methods of setting style, font and html support.
public class AppTextView extends TextView {
public Paint paint;
public boolean addStrike = false;
public AppTextView(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) init(attrs);
}
@rajeefmk
rajeefmk / WakeLock.java
Created May 6, 2017 07:53
Code to obtain wake lock.
/**
* Tries to acquire a partial wake lock if not already acquired. Logs errors
* and gives up trying in case the wake lock cannot be acquired.
*/
/**
* Acquire a wake lock if not already acquired.
*
* @param context the context
* @param wakeLock wake lock or null
@rajeefmk
rajeefmk / CustomViewPager
Created May 4, 2017 12:08
View pager which gives call back when user has reached the first or last item and tried swiping left or right.
public class CustomViewPager extends ViewPager {
float mStartDragX;
OnSwipeOutListener mOnSwipeOutListener;
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
@rajeefmk
rajeefmk / CenterImageSpan.java
Created April 29, 2017 15:53
Image Span used to center align the image with surrounding text inside a textview.
package com.hashlearn.common.utils;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.style.DynamicDrawableSpan;
import java.lang.ref.WeakReference;
@rajeefmk
rajeefmk / ImageUtils.java
Last active April 28, 2017 18:00
Utility class for various image related manipulations.
/*
This method will create a spannable which is a displayable styled text. It
also has a custom ImageGetter based on Picasso for loading <img> tags inside the html.
We use this for rendering formulas in challenges
*/
public static Spannable getSpannableHtmlWithImageGetter(AppTextView view, String value) {
PicassoImageGetter imageGetter = new PicassoImageGetter(view);
Spannable html;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
@rajeefmk
rajeefmk / PicassoImageGetter.java
Created April 28, 2017 17:27
ImageGetter used for loading remote urls from <img> tag when loaded inside textview.
public class PicassoImageGetter implements Html.ImageGetter {
private AppTextView textView = null;
public PicassoImageGetter() {
}
public PicassoImageGetter(AppTextView target) {
textView = target;
@rajeefmk
rajeefmk / javascript_resources.md
Created April 16, 2014 18:43 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@rajeefmk
rajeefmk / 0_reuse_code.js
Created April 16, 2014 18:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console