Skip to content

Instantly share code, notes, and snippets.

@mrleolink
mrleolink / AutoWrapLayout.java
Last active August 29, 2015 14:09
A simple implementation for AutoWrapLayout for TextView
/**
* This f**king code was created by Leo on 11/12/14.
*/
public class AutoWrapLayout extends RelativeLayout {
private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
private static final int DEFAULT_MARGIN = 5; // dp
private int margin;
private LinkedList<String> dataList;
@mrleolink
mrleolink / SingleLineTextView.java
Created June 30, 2014 12:06
A custom TextView that can shrink its text size to fit in a single line
/**
* Forked from: http://androidxref.com/4.1.1/xref/frameworks/base/core/java/com/android/internal/widget/DialogTitle.java
* Created by LeoLink on 2014-06-30.
*/
public class SingleLineTextView extends TextView {
public SingleLineTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setSingleLine();
setEllipsize(TextUtils.TruncateAt.END);
@mrleolink
mrleolink / SoftKeyboardHandledLinearLayout.java
Last active December 21, 2015 04:33
A hack to catch events when soft keyboard comes up/down on Android (Tested on 2.3 and 4.0.4) (For usage: check out my blog post at: http://tech.leolink.net/2014/02/a-hack-to-catch-soft-keyboard-showhide.html)
public class SoftKeyboardHandledLinearLayout extends LinearLayout {
private boolean isKeyboardShown;
private SoftKeyboardVisibilityChangeListener listener;
public SoftKeyboardHandledLinearLayout(Context context) {
super(context);
}
public SoftKeyboardHandledLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@mrleolink
mrleolink / MultiStateDrawable.java
Last active August 29, 2015 13:55
A really useful gist which helps to create pressed state for Android's Button/ImageButton without using additional drawbles
package net.leolink.android.gist;
public class MultiStateDrawable extends LayerDrawable {
// The color filter to apply when the button is pressed
protected ColorFilter _pressedFilter = new LightingColorFilter(Color.GRAY, 1);
public MultiStateDrawable(Drawable d) {
super(new Drawable[] { d });
}
<LinearLayout
android:id="@+id/tutorial_viewpager_container"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/tutorial_rounded_corner_background">
<android.support.v4.view.ViewPager
android:id="@+id/tutorial_viewpager"
android:background="@android:color/transparent"