Fix context menu height and status bar color

This commit is contained in:
Alexander Sytnyk 2017-11-03 17:32:13 +02:00
parent 17ba0ab6f6
commit 9a7806e76b
2 changed files with 32 additions and 7 deletions

View file

@ -4,7 +4,6 @@ import android.os.Build;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.Window;
public class ColoredStatusBarFragment extends Fragment { public class ColoredStatusBarFragment extends Fragment {
@ -13,11 +12,10 @@ public class ColoredStatusBarFragment extends Fragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (Build.VERSION.SDK_INT >= 21 && getStatusBarColor() != -1) { if (Build.VERSION.SDK_INT >= 21) {
Window window = getActivity().getWindow(); statusBarColor = getActivity().getWindow().getStatusBarColor();
statusBarColor = window.getStatusBarColor();
window.setStatusBarColor(ContextCompat.getColor(getActivity(), getStatusBarColor()));
} }
setupStatusBarColor();
} }
@Override @Override
@ -28,6 +26,12 @@ public class ColoredStatusBarFragment extends Fragment {
} }
} }
protected void setupStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21 && getStatusBarColor() != -1) {
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), getStatusBarColor()));
}
}
@ColorRes @ColorRes
protected int getStatusBarColor() { protected int getStatusBarColor() {
return -1; return -1;

View file

@ -7,7 +7,6 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.util.TypedValue; import android.util.TypedValue;
@ -39,6 +38,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState; import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
@ -55,7 +55,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP; import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
public class MapContextMenuFragment extends Fragment implements DownloadEvents { public class MapContextMenuFragment extends ColoredStatusBarFragment implements DownloadEvents {
public static final String TAG = "MapContextMenuFragment"; public static final String TAG = "MapContextMenuFragment";
public static final float FAB_PADDING_TOP_DP = 4f; public static final float FAB_PADDING_TOP_DP = 4f;
@ -523,6 +523,14 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
return view; return view;
} }
@Override
protected int getStatusBarColor() {
if (menu.getCurrentMenuState() == MenuState.FULL_SCREEN || menu.isLandscapeLayout()) {
return nightMode ? R.color.status_bar_dark : R.color.status_bar_route_light;
}
return nightMode ? R.color.status_bar_transparent_dark : R.color.status_bar_transparent_light;
}
private void updateImageButton(ImageButton button, int iconLightId, int iconDarkId, int bgLightId, int bgDarkId, boolean night) { private void updateImageButton(ImageButton button, int iconLightId, int iconDarkId, int bgLightId, int bgDarkId, boolean night) {
button.setImageDrawable(getMapActivity().getMyApplication().getIconsCache().getIcon(night ? iconDarkId : iconLightId)); button.setImageDrawable(getMapActivity().getMyApplication().getIconsCache().getIcon(night ? iconDarkId : iconLightId));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
@ -1224,13 +1232,25 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
break; break;
case MenuState.FULL_SCREEN: case MenuState.FULL_SCREEN:
posY = -menuTopShadowHeight - dpToPx(SHADOW_HEIGHT_TOP_DP); posY = -menuTopShadowHeight - dpToPx(SHADOW_HEIGHT_TOP_DP);
posY = addStatusBarHeightIfNeeded(posY);
break; break;
default: default:
break; break;
} }
if (!menu.isLandscapeLayout()) {
setupStatusBarColor();
}
return posY; return posY;
} }
private int addStatusBarHeightIfNeeded(int res) {
if (Build.VERSION.SDK_INT >= 21) {
// One pixel is needed to fill a thin gap between the status bar and the fragment.
return res + AndroidUtils.getStatusBarHeight(getActivity()) - 1;
}
return res;
}
private void updateMainViewLayout(int posY) { private void updateMainViewLayout(int posY) {
if (view != null) { if (view != null) {
menuFullHeight = view.getHeight() - posY; menuFullHeight = view.getHeight() - posY;
@ -1356,6 +1376,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
int fabY = y + fabPaddingTopPx; int fabY = y + fabPaddingTopPx;
if (fabY < fabPaddingTopPx) { if (fabY < fabPaddingTopPx) {
fabY = fabPaddingTopPx; fabY = fabPaddingTopPx;
fabY = addStatusBarHeightIfNeeded(fabY);
} }
return fabY; return fabY;
} }