Skip to content

Instantly share code, notes, and snippets.

public class MLRoundedImageView extends ImageView {
public MLRoundedImageView(Context context) {
super(context);
}
public MLRoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
// enables hardware accelerated rounded corners
// original idea here : http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
/*
* Copyright 2014 Julian Shen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
package com.blogspot.ksoichiro.linktest;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
@vincent1086
vincent1086 / gist:e2017debeb54c2e18374
Created February 23, 2015 14:27
Android Keyboard IME Detected
public class CustomEditText extends EditText {
private KeyImeChange keyImeChangeListener;
public ListenerEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setKeyImeChangeListener(KeyImeChange listener){
keyImeChangeListener = listener;
@vincent1086
vincent1086 / gist:3afa1ea2246b07aef0f5
Created September 10, 2015 11:13
ArrayList to Serializer
public class ObjectSerializer {
public static String serialize(Serializable obj) throws IOException {
if (obj == null){
return "";
}
try {
ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
@vincent1086
vincent1086 / gist:0caa27c98d96b7c22bad
Last active December 28, 2015 16:50
Android WebView HTML Video full screen
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="300dip" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
@vincent1086
vincent1086 / gist:4c3ac59e0a8ac9b260448c4d75e85e07
Created July 31, 2016 08:03
Android - ListAdapter Children Measure
private int measureContentWidth(ListAdapter adapter) {
// Menus don't tend to be long, so this is more sane than it looks.
int width = 0;
View itemView = null;
int itemType = 0;
final int widthMeasureSpec =
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec =
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int count = adapter.getCount();
public final class SampleFactory {
private static final Constructor<?> _CONSTRUCTOR;
private static final String _DEFAULT_IMPLEMENTION = "com.example.vincent.customImpl";
static {
Class<?> clazz = null;
String impl = System.getProperty(_DEFAULT_IMPLEMENTION);
if(impl != null){
try{
clazz = Class.forName(impl);
@vincent1086
vincent1086 / gist:28c997eda7a2de70fdd34be75f5c4d43
Created August 3, 2016 14:08
Android - get class inner variable
//////////////////////////////////////////////////////////
//// @usage getClassField("mPageMargin", ViewPager.class)
//////////////////////////////////////////////////////////
public int getClassField(String fieldName, Class<?> clz) {
try {
Field thisField = clz.getDeclaredField(fieldName);
return thisField.getInt(thisField);
} catch (Exception e) {
throw new RuntimeException("Not found field " + fieldName + ", Error : " + e.getMessage());
}