Skip to content

Instantly share code, notes, and snippets.

@hector6872
hector6872 / DRMVPFragmentV4.java
Last active November 29, 2024 12:06
DRMVPFragmentV4 example for DaRealMVP library - https://github.com/hector6872/DaRealMVP
@SuppressWarnings("unchecked") public abstract class DRMVPFragmentV4<P extends DRMVPPresenter<V>, V extends DRMVPView> extends Fragment {
private P presenter;
@CallSuper @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(getLayoutResId(), container, false);
}
@CallSuper @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
presenter = MVPUtils.getDeclaredPresenter(getClass());
presenter.bind((V) this);
@hector6872
hector6872 / DRMVPAppCompatActivity.java
Last active November 29, 2024 12:06
DRMVPAppCompatActivity example for DaRealMVP library - https://github.com/hector6872/DaRealMVP
@SuppressWarnings("unchecked") public abstract class DRMVPAppCompatActivity<P extends DRMVPPresenter<V>, V extends DRMVPView>
extends AppCompatActivity {
private P presenter;
@CallSuper @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResId());
presenter = MVPUtils.getDeclaredPresenter(getClass());
presenter.bind((V) this);
}
@hector6872
hector6872 / StateRecyclerView.java
Last active May 31, 2017 22:00
StateRecyclerView
public class StateRecyclerView extends RecyclerView {
private View emptyView;
private int emptyViewId;
public StateRecyclerView(Context context) {
this(context, null);
}
public StateRecyclerView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
@hector6872
hector6872 / build.gradle
Last active July 17, 2017 17:57
Semantic versioning
def appVersionMajor = 1
def appVersionMinor = 0
def appVersionPatch = 0
def appVersionBuild = 0
appVersionCode = appVersionMajor * 1000000 + appVersionMinor * 10000 + appVersionPatch * 100 + appVersionBuild
appVersionName = "${appVersionMajor}.${appVersionMinor}.${appVersionPatch}"
@hector6872
hector6872 / ReverseIterable.java
Created February 25, 2017 12:51
ReverseIterable
public final class ReverseIterable {
private ReverseIterable() {
}
public static <T> Iterable<T> reverse(final List<T> list) {
return new ListReverseIterable<>(list);
}
private static class ListReverseIterable<T> implements Iterable<T> {
private final List<T> list;
@hector6872
hector6872 / CustomLayout.java
Created February 23, 2017 23:01
Custom Viewgroup: onSaveInstanceState - onRestoreInstanceState http://trickyandroid.com/saving-android-view-state-correctly/
public class CustomLayout extends LinearLayout {
@SuppressWarnings("unchecked") @Override public Parcelable onSaveInstanceState() {
Parcelable saveInstanceState = super.onSaveInstanceState();
SavedState savedState = new SavedState(saveInstanceState);
savedState.childrenStates = new SparseArray();
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).saveHierarchyState(savedState.childrenStates);
}
return savedState;
@hector6872
hector6872 / PlayServicesUtils.java
Created February 22, 2017 12:20
PlayServicesUtils - Get Advertising Id
public class PlayServicesUtils {
private static String advertisingId = "";
private static boolean limitAdTrackingEnabled = false;
private PlayServicesUtils() {
}
public static void prepareAdvertisingId(final Context context) {
if (TextUtils.isEmpty(advertisingId)) {
new Thread(new Runnable() {
@hector6872
hector6872 / DpToPx.java
Last active May 13, 2020 20:26
Android DpToPx converter
int sizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeDp, context.getResources().getDisplayMetrics());
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate appCompatDelegate;
@Override protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
@Override protected void onPostCreate(Bundle savedInstanceState) {
@hector6872
hector6872 / ToolTipView.java
Created August 24, 2016 23:44
ToolTipView
/*
* +info: https://gist.github.com/romannurik/3982005
*/
public class ToolTipView {
public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
public static final int LENGTH_LONG = Toast.LENGTH_LONG;
@Retention(RetentionPolicy.CLASS) @IntDef({ LENGTH_SHORT, LENGTH_LONG }) public @interface Duration {
}