Skip to content

Instantly share code, notes, and snippets.

View FoxIvan's full-sized avatar
👨‍🍼
Feeding

Ivan FoxIvan

👨‍🍼
Feeding
View GitHub Profile
@FoxIvan
FoxIvan / styles_toolbar.xml
Created August 23, 2018 07:55
Common style for toolbar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Toolbar" />
<style name="Toolbar.Theme" parent="ThemeOverlay.AppCompat.Light">
<item name="actionMenuTextColor">@android:color/white</item>
<item name="actionMenuTextAppearance">@style/Toolbar.MenuTextAppearance</item>
<item name="android:actionOverflowButtonStyle">@style/Toolbar.OverflowButtonStyle</item>
</style>
@FoxIvan
FoxIvan / toHex.md
Created September 6, 2017 05:23
bytes to hex
  private final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
  
  public static String toHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int byteValue = bytes[i] & 0xFF;
            hexChars[i * 2] = HEX_ARRAY[byteValue >>> 4];
            hexChars[i * 2 + 1] = HEX_ARRAY[byteValue & 0x0F];
 }
@FoxIvan
FoxIvan / build.gradle.md
Last active September 18, 2017 01:51
My mostly used dependencies
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.easyway.rx_iim_app"
        minSdkVersion 19
public class NetworkUtil {
public static boolean isConnected(Context context) {
ConnectivityManager connectManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobileNetwork = connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiNetwork = connectManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo activeNetwork = connectManager.getActiveNetworkInfo();
return (activeNetwork != null && activeNetwork.isConnected())
|| mobileNetwork.isConnected()
@FoxIvan
FoxIvan / DividerItemDecoration.md
Last active May 25, 2017 11:42
ItemDecoration that draws an divider between items in a RecyclerView
public class DividerItemDecoration extends RecyclerView.ItemDecoration {

    private Drawable mDivider;

    public DividerItemDecoration(Context context) {
        mDivider = context.getDrawable(R.drawable.divider);
    }

 @Override
@FoxIvan
FoxIvan / LICENSE.md
Created May 24, 2017 08:29
Apache 2.0 licence

Copyright 2017 FoxIvan

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,

@FoxIvan
FoxIvan / DensityUtil.java
Last active December 7, 2016 09:12
Switch dimen value between different units
public class DensityUtil {
public static int dp2px(Context context, float dpVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpVal, context.getResources().getDisplayMetrics());
}
public static int sp2px(Context context, float spVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
spVal, context.getResources().getDisplayMetrics());
@FoxIvan
FoxIvan / get-date.md
Created August 4, 2016 18:05
Get an accurate date from now on
Date dNow = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(dNow);
calendar.add(Calendar.MONTH, -2);
calendar.add(Calendar.DAYOFMONTH, -2);
Date dBefore = calendar.getTime();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startDate = sdf.format(dBefore);