Skip to content

Instantly share code, notes, and snippets.

View JonathandelaSen's full-sized avatar
🌔

Jonathan de la Sen Minaya JonathandelaSen

🌔
View GitHub Profile
public class DpsPxsConversion {
public static float dpFromPx(final Context context, float px) {
return px / context.getResources().getDisplayMetrics().density;
}
public static float pxFromDp(final Context context, float dp) {
return dp * context.getResources().getDisplayMetrics().density;
}
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.content.Context;
import android.text.format.DateUtils;
import com.example.jonathan.medsblaprueba.R;
import com.example.jonathan.medsblaprueba.models.chat.ChatAbstract;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@JonathandelaSen
JonathandelaSen / UtilsSaveFile.java
Created August 18, 2017 07:06
Utility Android Class for saving files
import android.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
@JonathandelaSen
JonathandelaSen / UtilsBitmap.java
Last active August 18, 2017 07:07
Utility Android class for bitmap operation
public class UtilsBitmap {
public static Bitmap drawableToBitmap(Drawable drawable){
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
@JonathandelaSen
JonathandelaSen / .java
Created March 13, 2017 09:27
Android Colorize icons
public static void colorize(int color, ImageView... ivs) {
for (ImageView iv : ivs) {
iv.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
@JonathandelaSen
JonathandelaSen / .java
Last active March 11, 2017 11:43
Android Get screen size
public static float getScreenWidthDps(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return displayMetrics.widthPixels / displayMetrics.density;
}
public static float getScreenWidthPxs(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
}