Skip to content

Instantly share code, notes, and snippets.

@hector6872
hector6872 / TextViewDrawableSize.java
Last active September 8, 2022 12:22
TextViewDrawableSize - CompoundDrawable size
public class TextViewDrawableSize extends TextView {
private static final int DEFAULT_COMPOUND_DRAWABLE_SIZE = -1;
private int compoundDrawableWidth;
private int compoundDrawableHeight;
public TextViewDrawableSize(Context context) {
this(context, null);
}
public TextViewDrawableSize(Context context, AttributeSet attrs) {
@hector6872
hector6872 / RightAlignedHorizontalScrollView.java
Created October 13, 2015 22:15
RightAlignedHorizontalScrollView
public class RightAlignedHorizontalScrollView extends HorizontalScrollView {
private static final boolean DEFAULT_GRAVITY_RIGHT = true;
private static final boolean DEFAULT_AUTOSCROLL = true;
private boolean autoScroll;
private boolean gravityRight;
public RightAlignedHorizontalScrollView(Context context) {
this(context, null);
}
@hector6872
hector6872 / ColorDividerItemDecoration.java
Last active May 28, 2017 15:04
ColorDividerItemDecoration for RecyclerView
public final class ColorDividerItemDecoration extends RecyclerView.ItemDecoration {
private static final int DEFAULT_DIVIDER_COLOR = Color.GRAY;
private static final int DEFAULT_DIVIDER_SIZE_PX = 1;
private static final boolean DEFAULT_DIVIDER_SHOW_FIRST = false;
private static final boolean DEFAULT_DIVIDER_SHOW_LAST = false;
private final boolean showFirstDivider;
private final boolean showLastDivider;
private final Paint paint;
public abstract class BaseActivity extends AppCompatActivity {
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResource());
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
@hector6872
hector6872 / ExampleActivity.java
Created August 12, 2015 07:57
HorizontalScrollViewSelector
int totalItems=10;
horizontalScrollView = (HorizontalScrollViewSelector) findViewById(R.id.horizontalScrollView);
horizontalScrollView.setListener(new HorizontalScrollViewSelector.OnScrollChangedListener() {
@Override
public void onScrollChanged(int totalX, int x) {
items = x * totalItems / maxX);
}
});
public class SafeStringUtils {
public static boolean safeEquals(Object o1, Object o2) {
return o1 != null && o1.equals(o2);
}
public static boolean safeEqualsIgnoreCase(String s1, String s2) {
return s1 != null && s1.equalsIgnoreCase(s2);
}
public static boolean safeIsEmpty(String s) {
@hector6872
hector6872 / ObservableScrollView.java
Created May 7, 2015 14:13
ObservableScrollView
public class ObservableScrollView extends ScrollView {
private static final int DEFAULT_THRESHOLD_DP = 4;
private ScrollDirectionListener scrollDirectionListener;
private int scrollThreshold;
public ObservableScrollView(Context context) {
this(context, null);
}
@hector6872
hector6872 / SquareRelativeLayout.java
Last active June 10, 2016 12:58
SquareRelativeLayout
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
this(context, null);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@hector6872
hector6872 / SpaceItemDecoration.java
Last active April 25, 2020 12:04
Space ItemDecoration for RecyclerView
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
private static final boolean DEFAULT_ADD_SPACE_ABOVE_FIRST_ITEM = false;
private static final boolean DEFAULT_ADD_SPACE_BELOW_LAST_ITEM = false;
private final int space;
private final boolean addSpaceAboveFirstItem;
private final boolean addSpaceBelowLastItem;
public SpaceItemDecoration(int space) {
this(space, DEFAULT_ADD_SPACE_ABOVE_FIRST_ITEM, DEFAULT_ADD_SPACE_BELOW_LAST_ITEM);
@hector6872
hector6872 / OutlineTextView.java
Created April 13, 2015 14:12
Outline TextView
public class OutlineTextView extends TextView {
private static final int DEFAULT_OUTLINE_COLOR = 0xFF000000;
private static final int DEFAULT_OUTLINE_SIZE = 7;
private static final boolean DEFAULT_OUTLINE_STATE = true;
private int outlineColor;
private int outlineSize;
private boolean outlineState;
public OutlineTextView(Context context) {