Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
@virendersran01
virendersran01 / ExifUtil.java
Created November 2, 2019 05:27 — forked from 9re/ExifUtil.java
fix flipped / rotated image by getting exif orientation
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Build;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@virendersran01
virendersran01 / GZipRequest.java
Created January 23, 2020 10:45 — forked from premnirmal/GZipRequest.java
Parse GZip responses using volley
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
@virendersran01
virendersran01 / RealPathUtil.java
Created February 12, 2020 10:51 — forked from tatocaster/RealPathUtil.java
Real Path Utility class for Android, works for all API
public class RealPathUtil {
public static String getRealPath(Context context, Uri fileUri) {
String realPath;
// SDK < API11
if (Build.VERSION.SDK_INT < 11) {
realPath = RealPathUtil.getRealPathFromURI_BelowAPI11(context, fileUri);
}
// SDK >= 11 && SDK < 19
else if (Build.VERSION.SDK_INT < 19) {
@virendersran01
virendersran01 / FileUtils.java
Created February 12, 2020 11:03 — forked from HBiSoft/FileUtils.java
This fixes the issue when selecting a file from Downloads directory as well as the SD Card. This class can be called like this: String sourcePath = FileUtils.getRealPathFromURI_API19(this, data.getData());
import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
@virendersran01
virendersran01 / ScaleToFitWHTransformation.java
Created June 11, 2020 08:09 — forked from jpardogo/ScaleToFitWHTransformation.java
Resize a bitmap respecting the aspect radio. I use a custom transformations with Picasso library. This transformation calculate the new dimension of the bitmap scaling it to fit a specific width or height that we pass as a parameter (usually the biggest size of the imageView where we wanna set the bitmap).
public class ScaleToFitWidthHeightTransform implements Transformation {
private int mSize;
private boolean isHeightScale;
public ScaleToFitWidthHeightTransform(int size, boolean isHeightScale){
mSize =size;
this.isHeightScale = isHeightScale;
}
class FillDrawable(private val color: Int, layers: Array<out Drawable>) : LayerDrawable(layers) {
private val radius: Float = 20f
private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = this@FillDrawable.color
}
private var r = copyBounds()
class ClickDrawable(layers: Array<out Drawable> = arrayOf()) : LayerDrawable(layers) {
private val mask: Drawable =
ColorDrawable(0xFF00FFFF.toInt()).apply { alpha = 0 }
init {
addLayer(mask)
}
class ClickDrawable(layers: Array<out Drawable> = arrayOf()) : LayerDrawable(layers) {
private var wasPressed = false
private var mActive = false
private var canStart = true
private var mBounds = bounds
override fun isStateful(): Boolean {
return true
}
@Override
protected boolean onStateChange(int[] stateSet) {
final boolean changed = super.onStateChange(stateSet);
boolean enabled = false;
boolean pressed = false;
boolean focused = false;
boolean hovered = false;