Skip to content

Instantly share code, notes, and snippets.

View subinkrishna's full-sized avatar
🥕

Subinkrishna Gopi subinkrishna

🥕
View GitHub Profile
class MyClass {
fun test() {
val str: String = "..."
val result = str.xxx {
print(this) // Receiver
print(it) // Argument
42 // Block return value
}
}
}
@subinkrishna
subinkrishna / JavaGenericsTest.java
Last active July 19, 2018 20:58
[extends vs super] #java #generics #kotlin
import java.util.ArrayList;
import java.util.List;
public class JavaGenericsTest {
public static void main(String[] args) {
List<? super B> l1 = new ArrayList<A>();
// l1.add(new A()); // Nope!
l1.add(new B());
l1.add(new C());
@subinkrishna
subinkrishna / BitmapUtils.java
Created April 24, 2017 15:30 — forked from jayrambhia/BitmapUtils.java
Android Background Blur
public static Bitmap getBitmapFromView(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
view.draw(c);
return bitamp;
}
@subinkrishna
subinkrishna / Views.java
Last active February 22, 2017 19:53
[Views] A utility class to do batch operations on multiple views #tags: android, view, utility
/*
* Copyright (C) 2017 Subinkrishna Gopi
*
* 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
@subinkrishna
subinkrishna / ParcelableSpareBooleanArray.java
Created November 18, 2016 23:07 — forked from PPartisan/ParcelableSpareBooleanArray.java
SparseBooleanArray that is also Parcelable
/**
* SparseBooleanArray that is also Parcelable. Had to put this together so I could pass this to a
* {@code Fragment} bundle.
*/
public class ParcelableSparseBooleanArray extends SparseBooleanArray implements Parcelable {
public ParcelableSparseBooleanArray(){
super();
}
@subinkrishna
subinkrishna / MainActivity.java
Created October 1, 2016 21:46
Sample - Height animation using ObjectAnimator
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Property;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
public class MainActivity extends AppCompatActivity {
@subinkrishna
subinkrishna / Create.java
Created September 9, 2016 19:23
Observable creation with unsubscription
package com.subinkrishna.rx;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import rx.subscriptions.Subscriptions;
@subinkrishna
subinkrishna / TextViewValueAnimation.java
Created July 14, 2016 17:25
Animating the value in the TextView. Eg: change the value in a stock ticker
final Property<TextView, Integer> textValueProperty = new Property<TextView, Integer>(Integer.class, "textValue") {
@Override public Integer get(TextView textView) {
return Integer.parseInt(textView.getText().toString());
}
@Override public void set(TextView textView, Integer value) {
textView.setText(String.valueOf(value));
}
};
@subinkrishna
subinkrishna / TintAndBounds.java
Created May 3, 2016 17:35
Apply tint & bounds to a drawable
/**
* Applies tint & bound to a drawable.
*
* @param context
* @param drawableRes
* @param colorRes
* @param sizeRes
* @return
*/
public static Drawable applyTintAndBounds(Context context,
@subinkrishna
subinkrishna / TextViewBinder.java
Created April 10, 2016 21:05
TextView Binder using Android data binding library - custom font & compound drawable tinting
import android.content.res.AssetManager;
import android.databinding.BindingAdapter;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.Log;
import android.widget.TextView;