Skip to content

Instantly share code, notes, and snippets.

View subinkrishna's full-sized avatar
🥕

Subinkrishna Gopi subinkrishna

🥕
View GitHub Profile
@subinkrishna
subinkrishna / Recyclable.java
Created April 1, 2016 16:51
RecyclerView.Adapter implementation that works like android.widget.Adapter
package com.subinkrishna.ui;
/**
* @author Subinkrishna Gopi
*/
public interface Recyclable<T> {
void recycle(T object);
}
@subinkrishna
subinkrishna / CustomTypefaceSpan.java
Created March 30, 2016 15:20
Applying custom font to menus
package com.subinkrishna.customfont;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;
public class CustomTypefaceSpan extends TypefaceSpan {
public static TypefaceSpan newInstance(Typeface tf) {
@subinkrishna
subinkrishna / 1_drawable_ic_hash_io16.xml
Created March 18, 2016 12:44 — forked from nickbutcher/1_drawable_ic_hash_io16.xml
Animated Stroke. The google I/O website this year (https://google.com/io) has some funky animated lettering. I especially liked the animated stroke around the letters and wondered how you might implement that on Android. Turns out that AnimatedVectorDrawable makes this very easy! Here's how it looks: https://twitter.com/crafty/status/71077957997…
<?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
/**
* Returns new color with alpha applied.
*
* @param color
* @param alpha
* @return
*/
public static int getColorWithAlpha(@ColorInt int color,
@FloatRange(from=0.0, to=1.0) float alpha) {
return (int) (0xFF * alpha) << 24 | color & 0xFFFFFF;
@subinkrishna
subinkrishna / DividerDecoration.java
Last active April 1, 2016 16:53
Divider ItemDecoration for RecyclerView.
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
@subinkrishna
subinkrishna / CustomRowView.java
Created October 13, 2015 16:06 — forked from devunwired/CustomRowView.java
Custom View Example for drawing raw text and images
public class CustomRowView extends View {
private CharSequence mText;
private Layout mTextLayout;
private TextPaint mTextPaint;
private Drawable mImageDrawable;
public CustomRowView(Context context) {
this(context, null);
@subinkrishna
subinkrishna / colors.xml
Last active September 16, 2015 20:36 — forked from mpost/colors.xml
This gist demonstrates how to create an animated pause/resume media playback button for Android. It uses animated vector drawables and state transitions to orchestrate the effect. Some background: https://plus.google.com/u/0/+MoritzPost/posts/3EFF8uC7jXv
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="action_pause">#FF8F00</color>
<color name="action_resume">#43A047</color>
</resources>
@subinkrishna
subinkrishna / RemoveAllFacebookGroupMembers.js
Last active October 21, 2015 17:08
This JavaScript removes all members in a Facebook group.
// STEPS:
// 1. Go to the group's page
// 2. Choose "Members"
// 3. Open JavaScript console in your browser, preferably Firefox or Chrome
// 4. Paste this code and hit ENTER
var deleteAllGroupMembers = (function () {
var deleteAllGroupMembers = {};
// the facebook ids of the users that will not be removed.
// IMPORTANT: add your own facebook id here so that the script will not remove yourself!
@subinkrishna
subinkrishna / CommaEllipsize.java
Created August 13, 2015 15:54
TextUtils.commaEllipsize() sample
TextView title = (TextView) view.findViewById(R.id.listitemThreadsTitle);
title.setVisibility(View.VISIBLE);
TextPaint p = title.getPaint();
String strTitle = "Moe, Joe, Isaac, Bethany, Cornelius, Charlie";
title.setText(strTitle);
float avail = title.getMeasuredWidth();
CharSequence ch = TextUtils.commaEllipsize(strTitle, p, avail, "one more", "%d more");
title.setText(ch);
// In your library you need to tell gradle to build every time every variant:
android {
publishNonDefault true
}
// Then in your application, since recently I guess, you can do this:
dependencies {
(...)
devCompile project(path: ':lib', configuration: 'devDebug') // or 'devRelease'
storeCompile project(path: ':lib', configuration: 'storeRelease') // or 'storeDebug'