Skip to content

Instantly share code, notes, and snippets.

View doridori's full-sized avatar

Dorian Cussen doridori

View GitHub Profile
@doridori
doridori / ex1.java
Last active August 29, 2015 14:20
Java: Bitshifting Bytes post code samples
byte aByte = -112; //0b1001_0000
byte bByte = (byte) (aByte >> 4); //would expect 0b1111_1001 (-7)
System.out.println(bByte); //-7
byte cByte = (byte) (aByte >>> 4); //would expect 0b0000_1001 (9)
System.out.println(cByte); //-7
@doridori
doridori / GsonObjectPersister.java
Created June 16, 2014 16:34
Standalone Gson Persister for RoboSpice
public final class GsonObjectPersister<T> extends InFileObjectPersister<T>
{
// ============================================================================================
// FIELDS
// ============================================================================================
private final Gson gson;
// ============================================================================================
// CONSTRUCTOR
@doridori
doridori / MyWebView.java
Last active August 29, 2015 14:01
make WebViews computeHorizontalScrollRange() method public
public class MyWebView extends WebView
{
public MyWebView(Context context)
{
super(context);
}
public MyWebView(Context context, AttributeSet attrs)
{
super(context, attrs);
@doridori
doridori / ViewTreeObserver_Ex.java
Last active August 29, 2015 13:56
Grabbing content view dimensions via ViewTreeObserver - all Display methods have no guarantee if they will include system and status bars in height
//inside a fragment. If in an Activity you could use findViewById(Window.ID_ANDROID_CONTENT);
getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
//do something like measure a view etc
View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
Log.d("DISPLAY", content.getWidth() + " x " + content.getHeight());