Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2015 16:11
Show Gist options
  • Save anonymous/413553224b74a5ef1fcd to your computer and use it in GitHub Desktop.
Save anonymous/413553224b74a5ef1fcd to your computer and use it in GitHub Desktop.
Kindle Fire tablets don't account for the width of the soft key bar when in landscape and the app is in fullscreen mode. Strangely enough when using android:windowTranslucentNavigation in your theme it also seems to use the fullscreen behaviour. Using the official documentation from Amazon I created a small snippet that pads out a view by the ri…
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;
if (Build.MANUFACTURER.equals("Amazon") && isLandscape) {
final int paddingRight;
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;
}
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;
}
return 0;
}
}
@unverbraucht
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment