Skip to content

Instantly share code, notes, and snippets.

@hector6872
hector6872 / TextViewFont.java
Last active March 30, 2016 09:36
TextViewFont (cached)
public class TextViewFont extends TextView {
public TextViewFont(Context context) {
this(context, null);
}
public TextViewFont(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TextViewFont(Context context, AttributeSet attrs, int defStyleAttr) {
@hector6872
hector6872 / UniversalFragmentPagerAdapter.java
Created February 23, 2016 16:11
UniversalFragmentPagerAdapter
public class UniversalFragmentPagerAdapter extends FragmentPagerAdapter {
private final String[] tabTitles;
private final Fragment[] tabFragments;
public UniversalFragmentPagerAdapter(@NonNull FragmentManager fm, String[] tabTitles,
@NonNull Fragment[] tabFragments) {
super(fm);
if (tabTitles != null && tabTitles.length != tabFragments.length) {
throw new IllegalArgumentException();
}
@hector6872
hector6872 / DebugLog.java
Last active April 6, 2017 10:44
DebugLog
public final class DebugLog {
private static final int LOG_TAG_MAX_LENGTH = 23;
private static final String TEXT_NULL_VALUE = "null value";
private static final String TEXT_SEPARATOR = " ";
private DebugLog() {
}
private static boolean isDebuggable() {
return BuildConfig.DEBUG;
@hector6872
hector6872 / DisplayLeakConnectorView.java
Last active November 29, 2024 12:03
Improved DisplayLeakConnectorView extracted from LeakCanary library
public class DisplayLeakConnectorView extends View {
private static final float DEFAULT_STROKEWIDTH = 4f;
private static final int DEFAULT_COLOR_BRANCH = 0xFFbababa;
private static final int DEFAULT_COLOR_ROOT = 0xFF84a6c5;
private static final int DEFAULT_COLOR_LEAK = 0xFFb1554e;
public static final int TYPE_START = -1;
public static final int TYPE_NODE = 0;
public static final int TYPE_END = 1;
public static final int TYPE_DEFAULT = TYPE_NODE;
@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);
@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 / 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 / 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 / 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 / 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();