safely let overlay buttons float

This commit is contained in:
dosiecki 2016-08-04 06:30:34 -07:00
parent 709d46473a
commit e7bc89c15f
5 changed files with 22 additions and 12 deletions

View file

@ -39,7 +39,7 @@
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/reading_overlay_text"
android:layout_marginLeft="1dp"
android:layout_marginLeft="2dp"
android:layout_marginBottom="4dp"
style="?selectorOverlayBackgroundSend"
android:onClick="overlaySend" />
@ -63,7 +63,7 @@
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/reading_overlay_right"
android:layout_marginRight="1dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="4dp"
style="?selectorOverlayBackgroundLeft"
android:onClick="overlayLeft" />

View file

@ -64,6 +64,7 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
/** special value for starting story hash that jumps to the first unread. */
public static final String FIND_FIRST_UNREAD = "FIND_FIRST_UNREAD";
private static final float OVERLAY_ELEVATION_DP = 1.5f;
private static final int OVERLAY_RANGE_TOP_DP = 40;
private static final int OVERLAY_RANGE_BOT_DP = 60;
@ -163,6 +164,14 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
this.pageHistory = new ArrayList<Story>();
ViewUtils.setViewElevation(overlayLeft, OVERLAY_ELEVATION_DP);
ViewUtils.setViewElevation(overlayRight, OVERLAY_ELEVATION_DP);
ViewUtils.setViewElevation(overlayText, OVERLAY_ELEVATION_DP);
ViewUtils.setViewElevation(overlaySend, OVERLAY_ELEVATION_DP);
ViewUtils.setViewElevation(overlayProgress, OVERLAY_ELEVATION_DP);
ViewUtils.setViewElevation(overlayProgressLeft, OVERLAY_ELEVATION_DP);
ViewUtils.setViewElevation(overlayProgressRight, OVERLAY_ELEVATION_DP);
// this likes to default to 'on' for some platforms
enableProgressCircle(overlayProgressLeft, false);
enableProgressCircle(overlayProgressRight, false);

View file

@ -181,16 +181,6 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
Reading activity = (Reading) getActivity();
// the share/save buttons us compound drawables for layout speed, but they
// cannot correctly compute padding. hard resize the icons to use padding.
/*int iconSizePx = UIUtils.dp2px(activity, 30);
Drawable shareButtonIcon = shareButton.getCompoundDrawables()[0];
shareButtonIcon.setBounds(0, 0, iconSizePx, iconSizePx);
shareButton.setCompoundDrawables(shareButtonIcon, null, null, null);
Drawable saveButtonIcon = saveButton.getCompoundDrawables()[0];
saveButtonIcon.setBounds(0, 0, iconSizePx, iconSizePx);
saveButton.setCompoundDrawables(saveButtonIcon, null, null, null);*/
registerForContextMenu(web);
web.setCustomViewLayout(webviewCustomViewLayout);
web.setWebviewWrapperLayout(fragmentScrollview);

View file

@ -71,6 +71,11 @@ public class UIUtils {
return (int) (dp * scale + 0.5f);
}
public static float dp2px(Context context, float dp) {
float scale = context.getResources().getDisplayMetrics().density;
return dp * scale;
}
public static float px2dp(Context context, int px) {
return ((float) px) / context.getResources().getDisplayMetrics().density;
}

View file

@ -81,4 +81,10 @@ public class ViewUtils {
return pm.isPowerSaveMode();
}
public static void setViewElevation(View v, float elevationDP) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
float elevationPX = UIUtils.dp2px(v.getContext(), elevationDP);
v.setElevation(elevationPX);
}
}