Skip to content

Instantly share code, notes, and snippets.

@unverbraucht
Created October 26, 2015 16:16
Show Gist options
  • Save unverbraucht/5b5304f38ff3fa66279d to your computer and use it in GitHub Desktop.
Save unverbraucht/5b5304f38ff3fa66279d to your computer and use it in GitHub Desktop.
public class AmazonKindlePaddingGuesser() {
/**
* Certain devices (I'm looking at you, Amazon) don't displace the root of the view
* hierarchy by the width of the status bar.
* See https://developer.amazon.com/public/solutions/devices/fire-tablets/specifications/03-ux-specifications and
* https://developer.amazon.com/appsandservices/solutions/devices/kindle-fire/specifications/01-device-and-feature-specifications for
* more info
* @param layout A layout that should get the right padding applied
* @return the width of the right padding in px
*/
public static int getPadding(final View layout, final Context ctx) {
final int orientation = ctx.getResources().getConfiguration().orientation;
final boolean isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE;
final int paddingRight;
if (Build.MANUFACTURER.equals("Amazon") && isLandscape) {
switch (Build.MODEL) {
case "KFASWI":
case "KFSOWI":
case "KFTT":
// Fire HD7 (2014)
// Fire HD7 (2013)
// Fire HD7 (2012)
// All have 78px
paddingRight = 78;
break;
case "KFTHWA":
case "KFTHWI":
// Fire HDX 7 (2013)
paddingRight = 117;
break;
case "KFAPWA":
case "KFAPWI":
// Fire HDX 8.9 (2013)
paddingRight = 122;
break;
case "KFJWA ":
case "KFJWI":
// Fire HD 8.9 (2012)
paddingRight = 90;
break;
case "KFOT":
// Fire (2012)
paddingRight = 60;
break;
default:
final float scale = ctx.getResources().getDisplayMetrics().density;
// For other tablets we will rely on the OS SDK level. Fire OS 5 is Lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Fire OS 5 has a bar width of 48dp
paddingRight = 0;
} else {
// Just assume that other versions of Fire OS use the same width for now :(
paddingRight = (int) (scale * 48);
}
break;
}
} else {
paddingRight = 0;
}
if (layout != null) {
final int currentPaddingLeft = layout.getPaddingLeft();
final int currentPaddingTop = layout.getPaddingTop();
final int currentPaddingBottom = layout.getPaddingBottom();
layout.setPadding(currentPaddingLeft, currentPaddingTop, paddingRight, currentPaddingBottom);
}
return paddingRight;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment