Skip to content

Instantly share code, notes, and snippets.

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 / 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;
@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 / 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 / PreferencesObjectHelper.java
Created November 14, 2015 00:14
PreferencesObjectHelper - Store and retrieve a class object in SharedPreferences
public class PreferencesObjectHelper<T> {
private static final String TAG = "PreferencesObjectHelper";
private final SharedPreferences preferences;
private final SharedPreferences.Editor editor;
@SuppressLint("CommitPrefEdits")
public PreferencesObjectHelper(Context context, String fileName) {
preferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
editor = preferences.edit();
@hector6872
hector6872 / FindLongestStreak.java
Last active December 7, 2015 09:31
findLongestStreak() method
@IntDef({
FIND_STREAK_LESS_THAN_ZERO, FIND_STREAK_LESS_EQUAL_TO_ZERO, FIND_STREAK_LESS_GREATER_ZERO
}) @Retention(RetentionPolicy.SOURCE) public @interface FIND_STREAK_OPERATOR {
}
public static final int FIND_STREAK_LESS_THAN_ZERO = 0;
public static final int FIND_STREAK_LESS_EQUAL_TO_ZERO = 1;
public static final int FIND_STREAK_LESS_GREATER_ZERO = 2;
public int findLongestStreak(float[] values, @FIND_STREAK_OPERATOR int operator) {
@hector6872
hector6872 / BasePreferenceActivity.java
Created December 5, 2015 18:20
BasePreferenceActivity.java
public abstract class BasePreferenceActivity extends PreferenceActivity {
private AppCompatDelegate appCompatDelegate;
private Toolbar toolbar;
protected abstract int getPreferencesResource();
protected abstract int getLayoutResource();
protected abstract int getTitleResource();
@hector6872
hector6872 / HideSoftKeyboard.java
Created December 21, 2015 14:47
Hide SoftKeyboard
public void hideSoftKeyboard(Activity context) {
View view = context.getCurrentFocus();
if (view == null) {
return;
}
InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
@hector6872
hector6872 / .gitignore
Last active October 22, 2017 18:34
.gitignore
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
@hector6872
hector6872 / UnderlineTextView.java
Last active November 27, 2017 13:10
UnderlineTextView (Java & Kotlin)
public class UnderlineTextView extends TextView {
private Context context;
private int textColor;
public UnderlineTextView(Context context) {
this(context, null);
}
public UnderlineTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);