Skip to content

Instantly share code, notes, and snippets.

@fada21
fada21 / Function_getCroppedBitmap
Created January 28, 2014 11:26
Crops a circle out of the thumbnail photo for Android (by Daniel Olshansky @google )
public Bitmap getCroppedBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
paint.setAntiAlias(true);
@fada21
fada21 / Android_pathAnimation_class
Last active August 29, 2015 13:55
PathAnimation class for Android
package com.coolands.open;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* Animation along path
* by Ewan Chou (https://github.com/coocood)
@fada21
fada21 / java_method_md5HashOfString2HexString
Last active August 29, 2015 13:56
Create a MD5-Hash and Dump as a Hex String
public String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
@fada21
fada21 / Android_class_simpleOrientationListener
Last active August 29, 2015 13:56
Detects orientation change
package com.fada21.android.orientation;
import java.util.concurrent.locks.ReentrantLock;
import android.content.Context;
import android.content.res.Configuration;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.WindowManager;
@fada21
fada21 / assets_gfx_instruction_pl
Last active August 29, 2015 13:56
Assety graficzne na androida - instrukcja po polsku
Android, żeby obsłużyć wiele ekranów ma swoją specyfikę.
W najprostszej formie tła próbujemy sobie rozciągnąć lub skropować.
Ikon potrzebujemy w rozmiarze ok 72x72px (telefony) lub 96x96px (tablety),
które się obpowiednio skalują na różnych rozdzielczościach (przeważnie wyglądają marnie na rozdzielczościach innych od hdpi).
To przejdzie. Jednak aby było ładnie potrzebowalibyśmy assetów conajmniej w czterech rozdzielczościach wg proporcji 2:3:4:6.
Te najniższe dla ikon najczęściej przyjmuje się jako 48x48px.
http://stackoverflow.com/questions/11581649/about-android-image-size-and-assets-sizes
// by Chris Banes (http://chris.banes.me/2014/03/27/measuring-text/)
int mTextWidth, mTextHeight; // Our calculated text bounds
Paint mTextPaint = new Paint();
// Now lets calculate the size of the text
Rect textBounds = new Rect();
mTextPaint.getTextBounds(mText, 0, mText.length(), textBounds);
mTextWidth = mTextPaint.measureText(mText); // Use measureText to calculate width
mTextHeight = textBounds.height(); // Use height from getTextBounds()
@fada21
fada21 / PicassoBigCache.java
Last active March 14, 2018 10:34
Disk cache larger size for Picasso OkHttp (use like PicassoBigCache.INSTANCE.getPicassoBigCache(ctx) -> rest as in regular Picasso api .
package com.?
import java.io.File;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.StatFs;
import com.squareup.picasso.Downloader;
@fada21
fada21 / android_OnGlobalLayoutListener
Last active August 29, 2015 14:00
ViewTreeObserver.OnGlobalLayoutListener() handling
{
final ViewTreeObserver viewTreeObserver = someView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
viewTreeObserver.removeGlobalOnLayoutListener(this);
} else {
@fada21
fada21 / scala_snippets.scala
Last active August 6, 2016 16:48
scala snippets
val line2nums = io.StdIn.readLine.split(" ").map(_.toInt)
val lines2nums = io.Source.stdin.getLines().map(_.toInt)
val streamOfInts = Stream.continually(io.StdIn.readInt())
val fib = {
def f(f0:Int, f1:Int): Stream[Int] = f0 #:: f(f1, f0 + f1)
f(0,1)
}
//fib(18)
//fib.take(19).toList
# ubuntu/mint setup tips
# SETUP ============
## =================
# http://mintguide.org/tools/317-make-a-bootable-flash-drive-from-an-iso-image-on-linux-mint.html
# df # lists mounted devices
# sudo dd if=/home/USER/linuxmint.iso of=/dev/sdb
# watch -n5 'sudo kill -USR1 $(pgrep ^dd)' # monitoring dd progress
# git ppa
sudo add-apt-repository ppa:git-core/ppa