Skip to content

Instantly share code, notes, and snippets.

Christopher Herrera eefret

Block or report user

Report or block eefret

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@eefret
eefret / version-code-as-commit-count.gradle
Created Jun 13, 2017
This automatically sets your version number based on your git commit count.
View version-code-as-commit-count.gradle
defaultConfig {
# Add 10000 to move past old SVN revisions.
versionCode gitCommitCount() + 10000 ?: 0
}
def gitCommitCount() {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--count', 'HEAD'
@eefret
eefret / open-after-build.gradle
Last active Jun 14, 2017
Opens & Highlights the apk in explorer/finder after a release build.
View open-after-build.gradle
applicationVariants.all { variant ->
variant.assemble.doLast {
//If this is a 'release' build, reveal the compiled apk in finder/explorer
if (variant.buildType.name.contains('release')) {
def path = null
variant.outputs.each { output ->
path = "${rootDir}/${project.name}/build/outputs/apk/release/${output.outputFileName}"
}
@eefret
eefret / BaseActivity.java
Last active Jul 7, 2016
KeyboardLayoutListener Example for when you need to hide views or do something when the keyboard is up without relying in the onFocus, also to deal for when you have an item outside your scroll view and the keyboard pulls all the things up
View BaseActivity.java
//Import Utils from somewhere
public class BaseActivity extends Activity {
private ViewTreeObserver.OnGlobalLayoutListener keyboardLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int navigationBarHeight = Utils.getNavigationBarHeight(BaseActivity.this);
int statusBarHeight = Utils.getStatusBarHeight(BaseActivity.this);
// display window size for the app layout
@eefret
eefret / AndroidMarshmallowPermissions.java
Last active Mar 17, 2016
This are some methods I usually use to handle android 6 permissions
View AndroidMarshmallowPermissions.java
/**
* Check whether the passed permissions are granted and if not it requests them.
* @param activity The activity that requires the permissions
* @param requestCode The request code
* @param permissions The permissions you want to grant
*/
public static void requestPermissionsNotAllowed(@NonNull Activity activity,
@NonNull int requestCode,
@NonNull String... permissions){
ArrayList<String> missing = new ArrayList<>(permissions.length);
@eefret
eefret / Normalize android assets
Last active Mar 7, 2016
Sometimes in Android development you find designers that make your assets names with "-" this makes the android compiler to fail as assets cannot have "-", I create this script to solve this problem recursively renaming the files and replacing "-" with "_" plus making them lowercase.
View Normalize android assets
#!/bin/bash
# Normalize assets
# Sometimes in Android development you find designers that make your assets names with "-" this makes
# the android compiler to fail as assets cannot have "-", I create this script to solve this problem
# recursively renaming the files and replacing "-" with "_" plus making them lowercase.
#
# Instructions:
# 1- Move this script to your Android {PROJECT_BASE_FOLDER}/app/src/main/res
# 2- run it with sudo ex: "sudo ./rename_script.sh"
@eefret
eefret / NetworkStateReceiver.java
Created Apr 16, 2015
A Simple but powerfull Network State Receiver for android implementing listeners
View NetworkStateReceiver.java
public class NetworkStateReceiver extends BroadcastReceiver {
protected List<NetworkStateReceiverListener> listeners;
protected Boolean connected;
public NetworkStateReceiver() {
listeners = new ArrayList<NetworkStateReceiverListener>();
connected = null;
}
@eefret
eefret / Logger
Created Sep 29, 2014
Logger class
View Logger
import android.util.Log;
/**
* @author eefret
* Created by Christopher T. Herrera (eefret) on 4/22/2014 [12:41 AM]
* Wrapper class for android Logging utility will select a tag automatically from class, method and line number executed.
*/
public class Logger {
//TODO Create a detail Enum to define the log detail level.
//TODO Create a method that halt every log possible based on the development mode Ex: (PRODUCTION, DEVELOPMENT, DEBUG) that can manage what can be and can't be logged
You can’t perform that action at this time.