Skip to content

Instantly share code, notes, and snippets.

@vincent1086
vincent1086 / gist:52bf72856527b9a10a0732d9cdad36b9
Created March 16, 2017 08:14
Android - get TextView or EditText Size
int deviceWidth;
WindowManager wm = (WindowManager) textView.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2){
Point size = new Point();
display.getSize(size);
deviceWidth = size.x;
} else {
deviceWidth = display.getWidth();
}
WindowManager wm = (WindowManager) textView.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2){
Point size = new Point();
display.getSize(size);
deviceWidth = size.x;
} else {
deviceWidth = display.getWidth();
}
@vincent1086
vincent1086 / gist:39a0b6142536d21d83de8b19f62fae45
Last active March 3, 2017 02:04
Android library use gradle build .apk / .aar / .jar
////////////////////////////////
// import library (.aar / .jar)
////////////////////////////////
repositories {
jcenter()
mavenCentral()
mavenLocal()
flatDir{
dirs 'libs'
}
@vincent1086
vincent1086 / gist:b7dc2b998eaaf2d8db5c847109cd5704
Last active March 1, 2017 02:35
Google Map infoWindow child view click event (ps. InfoWindow -> Canvas)
////////////////////
// Layout xml file.
///////////////////
<com.example.widget.MapInfoWindowWrapper
android:id="@+id/map_wrapper"
android:layout_width="match_parent"
android:layout_height="350dp">
<MapView
android:id="@+id/mapview"
@vincent1086
vincent1086 / gist:a2c686a497d37862b785473c30f55e59
Created November 8, 2016 09:15
Android onMeasure() get size
public static int resolveSize(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
result = size;
break;
case MeasureSpec.AT_MOST:
result = Math.min(size, specSize);
@vincent1086
vincent1086 / gist:f9e0feb3035d77699e6f67bddd7dcc39
Created November 5, 2016 17:28
Check Touch outside target view
// Reference : http://stackoverflow.com/questions/6410200/android-detect-if-user-touches-and-drags-out-of-button-region
private Rect rect; // Variable rect to hold the bounds of the view
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
// Construct a rect of the view's bounds
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
if(event.getAction() == MotionEvent.ACTION_MOVE){
// Reference : http://pqovopq.seesaa.net/article/387726362.html
static private void setCursorWindowSize(int size){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
final Class cls = Class.forName("android.database.CursorWindow");
final Field fld = cls.getDeclaredField("sCursorWindowSize");
fld.setAccessible(true);
int before = fld.getInt(null); // default=2048*1024
fld.setInt(null, size * 1024); // extend to
int after = fld.getInt(null);
@vincent1086
vincent1086 / gist:1ca4df897efcf9bc0a4bda771af5636a
Last active May 6, 2022 13:35
Android - TextView Support (ul/ol/li)
import java.util.Vector;
import org.xml.sax.XMLReader;
import android.text.Editable;
import android.text.Html;
import android.text.Spannable;
import android.text.style.BulletSpan;
import android.text.style.LeadingMarginSpan;
import android.text.style.TypefaceSpan;
@vincent1086
vincent1086 / gist:cbd5fd86ac674a237af1e49ec10a4faf
Last active August 29, 2016 09:38
Android - Sliding Custom View
/*
* <declare-styleable name="slideViewSyle">
* <attr name="direction" format="enum">
* <enum name="top" value="0"/>
* <enum name="bottom" value="1" />
* <enum name="left" value="2" />
* <enum name="right" value="3" />
* </attr>
* </declare-styleable>
*
@vincent1086
vincent1086 / gist:132d6411eda947eebc606fdd692e4e9f
Created August 28, 2016 10:41
Android - MapView inside ScrollView fix bug
public class ScrollMapView extends MapView {
private final static String TAG = "ScrollMapView";
public ScrollMapView(Context context) {
super(context);
}
public ScrollMapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);