Skip to content

Instantly share code, notes, and snippets.

View subinkrishna's full-sized avatar
🥕

Subinkrishna Gopi subinkrishna

🥕
View GitHub Profile
@subinkrishna
subinkrishna / ProxySample.java
Last active August 29, 2015 14:03
Dynamic object mapping + proxy instances. This can be used to map Android Activity/Fragment instances to appropriate callback instances (especially when callback instances cannot be null).
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class ProxySample {
public static void main(String[] args) {
final Bar a = mapTo("It's a String!", Bar.class, true);
a.doSomething(); // prints [InvocationHandler] doSomething()
@subinkrishna
subinkrishna / styles.xml
Created July 15, 2014 03:02
Customize Android ActionBar overflow icon.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
<item name="android:actionOverflowButtonStyle">@style/ActionBarOverflowButton</item>
</style>
<!-- ActionBar theme -->
<style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
@subinkrishna
subinkrishna / background_card.xml
Last active July 4, 2023 07:49
A simple card background drawable for Android.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_card_selected" android:state_selected="true" />
<item android:drawable="@drawable/background_card_selected" android:state_pressed="true" />
<item android:drawable="@drawable/background_card_default" />
</selector>
@subinkrishna
subinkrishna / .gitignore
Last active August 29, 2015 14:05
My Default .gitignore for Android projects
# Built application files
*.apk
*.ap_
# Files for the dex VM
*.dex
# Java class files
*.class
@subinkrishna
subinkrishna / ViewUtil.java
Last active August 29, 2015 14:06
Set a bitmap as background to a View
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.view.View;
public class ViewUtil {
/**
@subinkrishna
subinkrishna / ParallaxHeadListView.java
Created October 8, 2014 17:22
ListView with parallax header
package com.subinkrishna.android.ui.widget;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.RelativeLayout;
@subinkrishna
subinkrishna / UriBuilder.java
Created October 14, 2014 16:28
A Uri.Builder sample snippet (to build a URL)
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("www.myawesomesite.com")
.appendPath("turtles")
.appendPath("types")
.appendQueryParameter("type", "1")
.appendQueryParameter("sort", "relevance")
.fragment("section-name");
String myUrl = builder.build().toString();
Just learned that when you accidentally merge on the wrong branch and push, there is a way to change it.
git reset --hard [sha-commit-before-merge]
git push [origin] [branch] --force
This will undo the merge and any commits after the merge, so this is useful if you catch your mistake before any more commits happens.
@subinkrishna
subinkrishna / CopyStream.java
Created January 24, 2015 00:11
copyStream() - copies contents from one stream to other
public static void copy(final InputStream in,
final OutputStream out,
final boolean closeStreams) throws IOException {
final int kilobyte = 1024;
byte[] buffer = null;
int count = -1;
if ((null != in) && (null != out)) {
try {
buffer = new byte[kilobyte];
@subinkrishna
subinkrishna / bg_with_bottom_stroke.xml
Created April 1, 2015 21:43
Background resource with a bottom stroke
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFF" />
</shape>
</item>
<item android:top="-1dp" android:left="-1dp" android:right="-1dp">
<shape android:shape="rectangle">