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 / careeradvicecategory.txt
Last active February 3, 2020 07:49
Career Advice category Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:clipToPadding="false"
android:padding="16dp">
@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;
}
@virendersran01
virendersran01 / NavDrawerOnSlide.txt
Created June 23, 2020 08:12
Animated Navigation Drawer with OnSlide
private void animateNavigationDrawer() {
//Add any color or remove it to use the default one!
//To make it transparent use Color.Transparent in side setScrimColor();
//drawerLayout.setScrimColor(Color.TRANSPARENT);
drawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Scale the View based on current slide offset
@virendersran01
virendersran01 / AdapterLiveTemplate.txt
Created June 26, 2020 08:07
Live Template for Recyclerview's Adapter Class Android
public class $ADAPTERNAME$ extends androidx.recyclerview.widget.RecyclerView.Adapter<$ADAPTERNAME$.ViewHolder> {
@androidx.annotation.NonNull
@Override
public ViewHolder onCreateViewHolder(@androidx.annotation.NonNull android.view.ViewGroup parent, int viewType) {
return new ViewHolder(android.view.LayoutInflater.from(parent.getContext()).inflate(R.layout.$LAYOUT$, parent, false));
}
@Override
public void onBindViewHolder(@androidx.annotation.NonNull ViewHolder holder, int position) {
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()