Skip to content

Instantly share code, notes, and snippets.

@Mariovc
Mariovc / ImagePicker.java
Last active November 29, 2024 16:28
Utility for picking an image from Gallery/Camera with Android Intents
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
@Mariovc
Mariovc / PreferencesManager.java
Last active April 9, 2019 06:36
[Android] Manager to store data in SharedPreferences
import android.content.Context;
import android.content.SharedPreferences;
import com.google.gson.Gson;
/**
* Author: Mario Velasco Casquero
* Date: 30/09/2015
* Email: m3ario@gmail.com
*/
@Mariovc
Mariovc / ImagePickerWithCrop.java
Last active April 27, 2022 14:29
[Android] Advanced utility for picking an image from Gallery/Camera with Android Intents (Crop included)
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
@Mariovc
Mariovc / AspectRatioImageView.java
Last active April 9, 2019 06:35 — forked from JakeWharton/AspectRatioImageView.java
ImageView that respects an aspect ratio applied to a specific measurement.
// Copyright 2012 Square, Inc.
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
/** Maintains an aspect ratio based on either width or height. Disabled by default. */
public class AspectRatioImageView extends ImageView {
// NOTE: These must be kept in sync with the AspectRatioImageView attributes in attrs.xml.
public static final int MEASUREMENT_WIDTH = 0;
@Mariovc
Mariovc / ShareUtils.java
Last active June 9, 2023 17:24
Utility to share text and url on Facebook, Twitter and Whatsapp
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
@Mariovc
Mariovc / Font.java
Last active March 3, 2020 05:52
Cache your created typefaces to avoid memory leaks.
public enum Font {
OXYGEN_REGULAR("Oxygen-Regular.ttf"),
OXYGEN_LIGHT("Oxygen-Light.ttf"),
OXYGEN_BOLD("Oxygen-Bold.ttf"),
GOTHAM_BOOK("Gotham-Book.ttf"),
GOTHAM_LIGHT("Gotham-Light.ttf"),
GOTHAM_MEDIUM("Gotham-Medium.ttf");
private final String path;
@Mariovc
Mariovc / Log.java
Created January 4, 2016 16:47
Android Log class improving the original class to do not log when it is on production and without tag needed
import com.antena3.floox.BuildConfig;
/**
* Author: Mario Velasco Casquero
* Date: 27/08/2015
*/
public class Log {
private static final int MAX_LOG_TAG_LENGTH = 23;
private static final boolean logsAllowed = BuildConfig.DEBUG;
@Mariovc
Mariovc / PhonecallReceiver.java
Last active August 21, 2019 00:28 — forked from ftvs/PhonecallReceiver.java
Detecting an incoming call coming to an Android device. Remember to set the appropriate permissions in AndroidManifest.xml as suggested in the Stackoverflow link. Usage example in comments. Source: http://stackoverflow.com/a/15564021/264619 Explanation: http://gabesechansoftware.com/is-the-phone-ringing/#more-8
package com.gabesechan.android.reusable.receivers;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
@Mariovc
Mariovc / gradle.properties
Last active April 9, 2019 06:34
Speed up your gradle build time using this configuration. Source: https://medium.com/@cesarmcferreira/speeding-up-gradle-builds-619c442113cb#.b9an8un3u
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
@Mariovc
Mariovc / pull-request.md
Last active March 18, 2018 08:08 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: