Disable controller buttons

This commit is contained in:
PavelRatushny 2017-12-28 14:57:35 +02:00
parent 39b5b3e0b2
commit afcbc5d648
6 changed files with 88 additions and 24 deletions

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/route_info_bg_dark" />
<stroke
android:width="1dp"
android:color="@color/route_info_divider_dark" />
<corners android:radius="3dp" />
</shape>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/route_info_bg_light" />
<stroke
android:width="1dp"
android:color="@color/route_info_divider_light" />
<corners android:radius="3dp" />
</shape>

View file

@ -352,6 +352,8 @@
<color name="ctx_menu_bottom_view_divider_dark">#222526</color>
<color name="ctx_menu_bottom_view_url_color_light">#536dfe</color>
<color name="ctx_menu_bottom_view_url_color_dark">#d28521</color>
<color name="ctx_menu_controller_disabled_text_color_light">#b3b3b3</color>
<color name="ctx_menu_controller_disabled_text_color_dark">#666666</color>
<color name="route_info_bg_light">#ffffff</color>
<color name="route_info_bg_dark">#17191a</color>

View file

@ -152,21 +152,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
mapZoom = map.getZoom();
}
ColorStateList buttonColorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{}
},
new int[] {
getResources().getColor(nightMode ? R.color.ctx_menu_controller_button_text_color_dark_p : R.color.ctx_menu_controller_button_text_color_light_p),
getResources().getColor(nightMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n)
}
);
// Left title button
final View leftTitleButtonView = view.findViewById(R.id.title_button_view);
((TextView) leftTitleButtonView.findViewById(R.id.title_button)).setTextColor(buttonColorStateList);
leftTitleButtonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
leftTitleButtonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -179,8 +166,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Right title button
final View rightTitleButtonView = view.findViewById(R.id.title_button_right_view);
((TextView) rightTitleButtonView.findViewById(R.id.title_button_right)).setTextColor(buttonColorStateList);
rightTitleButtonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
rightTitleButtonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -193,8 +178,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Left download button
final View leftDownloadButtonView = view.findViewById(R.id.download_button_left_view);
((TextView) leftDownloadButtonView.findViewById(R.id.download_button_left)).setTextColor(buttonColorStateList);
leftDownloadButtonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
leftDownloadButtonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -207,8 +190,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Right download button
final View rightDownloadButtonView = (View) view.findViewById(R.id.download_button_right_view);
((TextView) rightDownloadButtonView.findViewById(R.id.download_button_right)).setTextColor(buttonColorStateList);
rightDownloadButtonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
rightDownloadButtonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -221,8 +202,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Bottom title button
final View bottomTitleButtonView = view.findViewById(R.id.title_button_bottom_view);
((TextView) bottomTitleButtonView.findViewById(R.id.title_button_bottom)).setTextColor(buttonColorStateList);
bottomTitleButtonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
bottomTitleButtonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -713,7 +692,29 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
origMarkerY = box.getCenterPixelY();
}
private void updateButtonsAndProgress() {
private void enableDisableButtons(View buttonView, TextView button, boolean enabled) {
if (enabled) {
ColorStateList buttonColorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{}
},
new int[] {
getResources().getColor(nightMode ? R.color.ctx_menu_controller_button_text_color_dark_p : R.color.ctx_menu_controller_button_text_color_light_p),
getResources().getColor(nightMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n)
}
);
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
button.setTextColor(buttonColorStateList);
} else {
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_disabled_bg_dark: R.drawable.context_menu_controller_disabled_bg_light);
button.setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_controller_disabled_text_color_dark : R.color.ctx_menu_controller_disabled_text_color_light));
}
button.setEnabled(enabled);
}
public void updateButtonsAndProgress() {
if (view != null) {
TitleButtonController leftTitleButtonController = menu.getLeftTitleButtonController();
TitleButtonController rightTitleButtonController = menu.getRightTitleButtonController();
@ -732,6 +733,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
final TextView leftTitleButton = (TextView) view.findViewById(R.id.title_button);
final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
if (leftTitleButtonController != null) {
enableDisableButtons(leftTitleButtonView, leftTitleButton, leftTitleButtonController.enabled);
leftTitleButton.setText(leftTitleButtonController.caption);
if (leftTitleButtonController.visible) {
leftTitleButtonView.setVisibility(View.VISIBLE);
@ -759,6 +761,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
final View rightTitleButtonView = view.findViewById(R.id.title_button_right_view);
final TextView rightTitleButton = (TextView) view.findViewById(R.id.title_button_right);
if (rightTitleButtonController != null) {
enableDisableButtons(rightTitleButtonView, rightTitleButton, rightTitleButtonController.enabled);
rightTitleButton.setText(rightTitleButtonController.caption);
rightTitleButtonView.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
@ -775,6 +778,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
final View bottomTitleButtonView = view.findViewById(R.id.title_button_bottom_view);
final TextView bottomTitleButton = (TextView) view.findViewById(R.id.title_button_bottom);
if (bottomTitleButtonController != null) {
enableDisableButtons(bottomTitleButtonView, bottomTitleButton, bottomTitleButtonController.enabled);
bottomTitleButton.setText(bottomTitleButtonController.caption);
bottomTitleButtonView.setVisibility(bottomTitleButtonController.visible ? View.VISIBLE : View.GONE);
@ -799,6 +803,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
final View leftDownloadButtonView = view.findViewById(R.id.download_button_left_view);
final TextView leftDownloadButton = (TextView) view.findViewById(R.id.download_button_left);
if (leftDownloadButtonController != null) {
enableDisableButtons(leftDownloadButtonView, leftDownloadButton, leftDownloadButtonController.enabled);
leftDownloadButton.setText(leftDownloadButtonController.caption);
leftDownloadButtonView.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE);
@ -815,6 +820,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
final View rightDownloadButtonView = view.findViewById(R.id.download_button_right_view);
final TextView rightDownloadButton = (TextView) view.findViewById(R.id.download_button_right);
if (rightDownloadButtonController != null) {
enableDisableButtons(rightDownloadButtonView, rightDownloadButton, rightDownloadButtonController.enabled);
rightDownloadButton.setText(rightDownloadButtonController.caption);
rightDownloadButtonView.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE);
@ -966,6 +972,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
this.initLayout = true;
this.centered = true;
}
updateButtonsAndProgress();
runLayoutListener();
}
}

View file

@ -538,6 +538,7 @@ public abstract class MenuController extends BaseMenuController {
public boolean needColorizeIcon = true;
public Drawable leftIcon;
public Drawable rightIcon;
public boolean enabled = true;
public Drawable getLeftIcon() {
if (leftIcon != null) {
@ -545,7 +546,7 @@ public abstract class MenuController extends BaseMenuController {
}
if (leftIconId != 0) {
if (needColorizeIcon) {
return getIcon(leftIconId, isLight() ? R.color.map_widget_blue : R.color.osmand_orange);
return getIcon(leftIconId, getColorRes());
}
return ContextCompat.getDrawable(getMapActivity(), leftIconId);
} else {
@ -559,7 +560,7 @@ public abstract class MenuController extends BaseMenuController {
}
if (rightIconId != 0) {
if (needColorizeIcon) {
return getIcon(rightIconId, isLight() ? R.color.map_widget_blue : R.color.osmand_orange);
return getIcon(rightIconId, getColorRes());
}
return ContextCompat.getDrawable(getMapActivity(), rightIconId);
} else {
@ -567,6 +568,16 @@ public abstract class MenuController extends BaseMenuController {
}
}
private int getColorRes() {
int colorRes;
if (enabled) {
colorRes = isLight() ? R.color.map_widget_blue : R.color.osmand_orange;
} else {
colorRes = isLight() ? R.color.ctx_menu_controller_disabled_text_color_dark : R.color.ctx_menu_controller_disabled_text_color_light;
}
return colorRes;
}
public abstract void buttonPressed();
}

View file

@ -152,6 +152,22 @@ public class TransportRouteController extends MenuController {
}
}
private void updateControllers() {
boolean previousStopEnabled = false;
final int previousStop = getPreviousStop();
if (previousStop != -1) {
previousStopEnabled = true;
}
leftTitleButtonController.enabled = previousStopEnabled;
boolean nextStopEnabled = false;
final int nextStop = getNextStop();
if (nextStop != -1) {
nextStopEnabled = true;
}
rightTitleButtonController.enabled = nextStopEnabled;
}
private void showTransportStop(TransportStop stop) {
if (mapContextMenu != null) {
transportRoute.stop = stop;
@ -159,6 +175,8 @@ public class TransportRouteController extends MenuController {
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE,
transportRoute.getDescription(getMapActivity().getMyApplication(), false));
updateControllers();
LatLon stopLocation = stop.getLocation();
if (mapContextMenu.isVisible()) {
mapContextMenu.updateMapCenter(stopLocation);