RTL - Step 3 (Menu controller)

This commit is contained in:
Nazar-Kutz 2020-06-11 10:34:54 +03:00
parent 1f1aad2446
commit dafbd22b5d
15 changed files with 78 additions and 70 deletions

View file

@ -71,7 +71,7 @@ public class AudioVideoNoteMenuController extends MenuController {
}
};
rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete);
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
rightTitleButtonController.startIconId = R.drawable.ic_action_delete_dark;
}
updateData();
@ -164,7 +164,7 @@ public class AudioVideoNoteMenuController extends MenuController {
if (!mRecording.isPhoto()) {
if (mPlugin.isPlaying(mRecording)) {
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_control_stop);
leftTitleButtonController.leftIconId = R.drawable.ic_action_rec_stop;
leftTitleButtonController.startIconId = R.drawable.ic_action_rec_stop;
int pos = mPlugin.getPlayingPosition();
String durationStr;
if (pos == -1) {
@ -177,14 +177,14 @@ public class AudioVideoNoteMenuController extends MenuController {
rightTitleButtonController.visible = false;
} else {
leftTitleButtonController.caption = mapActivity.getString(R.string.recording_context_menu_play);
leftTitleButtonController.leftIconId = R.drawable.ic_play_dark;
leftTitleButtonController.startIconId = R.drawable.ic_play_dark;
String durationStr = mRecording.getPlainDuration(accessibilityEnabled);
leftTitleButtonController.needRightText = true;
leftTitleButtonController.rightTextCaption = "" + durationStr;
}
} else {
leftTitleButtonController.caption = mapActivity.getString(R.string.recording_context_menu_show);
leftTitleButtonController.leftIconId = R.drawable.ic_action_view;
leftTitleButtonController.startIconId = R.drawable.ic_action_view;
}
}

View file

@ -628,7 +628,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
Drawable drawable = getIcon(iconResId, bottomButtonsColor);
directionsButton.setTextColor(ContextCompat.getColor(mapActivity, bottomButtonsColor));
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(directionsButton, null, null, drawable, null);
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
directionsButton, null, null, drawable, null);
int contentPaddingHalf = (int) getResources().getDimension(R.dimen.content_padding_half);
directionsButton.setCompoundDrawablePadding(contentPaddingHalf);
directionsButton.setOnClickListener(new View.OnClickListener() {
@ -1147,11 +1148,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
setupButton(leftTitleButtonView, leftTitleButtonController.enabled, title);
if (leftTitleButtonController.visible) {
leftTitleButtonView.setVisibility(View.VISIBLE);
Drawable leftIcon = leftTitleButtonController.getLeftIcon();
Drawable rightIcon = leftTitleButtonController.getRightIcon();
leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
Drawable startIcon = leftTitleButtonController.getStartIcon();
Drawable endIcon = leftTitleButtonController.getEndIcon();
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
leftTitleButton, startIcon, null, endIcon, null);
leftTitleButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half));
((LinearLayout) leftTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
((LinearLayout) leftTitleButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START);
} else {
leftTitleButtonView.setVisibility(View.INVISIBLE);
}
@ -1166,11 +1168,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
setupButton(rightTitleButtonView, rightTitleButtonController.enabled, rightTitleButtonController.caption);
rightTitleButtonView.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
Drawable leftIcon = rightTitleButtonController.getLeftIcon();
Drawable rightIcon = rightTitleButtonController.getRightIcon();
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
Drawable startIcon = rightTitleButtonController.getStartIcon();
Drawable endIcon = rightTitleButtonController.getEndIcon();
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
rightTitleButton, startIcon, null, endIcon, null);
rightTitleButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half));
((LinearLayout) rightTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
((LinearLayout) rightTitleButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START);
} else {
rightTitleButtonView.setVisibility(View.INVISIBLE);
}
@ -1182,11 +1185,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
setupButton(bottomTitleButtonView, bottomTitleButtonController.enabled, bottomTitleButtonController.caption);
bottomTitleButtonView.setVisibility(bottomTitleButtonController.visible ? View.VISIBLE : View.GONE);
Drawable leftIcon = bottomTitleButtonController.getLeftIcon();
Drawable rightIcon = bottomTitleButtonController.getRightIcon();
bottomTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
Drawable startIcon = bottomTitleButtonController.getStartIcon();
Drawable endIcon = bottomTitleButtonController.getEndIcon();
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
bottomTitleButton, startIcon, null, endIcon, null);
bottomTitleButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half));
((LinearLayout) bottomTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
((LinearLayout) bottomTitleButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START);
} else {
bottomTitleButtonView.setVisibility(View.GONE);
}
@ -1206,11 +1210,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
setupButton(leftDownloadButtonView, leftDownloadButtonController.enabled, leftDownloadButtonController.caption);
leftDownloadButtonView.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE);
Drawable leftIcon = leftDownloadButtonController.getLeftIcon();
Drawable rightIcon = leftDownloadButtonController.getRightIcon();
leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
Drawable startIcon = leftDownloadButtonController.getStartIcon();
Drawable endIcon = leftDownloadButtonController.getEndIcon();
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
leftDownloadButton, startIcon, null, endIcon, null);
leftDownloadButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half));
((LinearLayout) leftDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
((LinearLayout) leftDownloadButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START);
} else {
leftDownloadButtonView.setVisibility(View.INVISIBLE);
}
@ -1222,11 +1227,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
setupButton(rightDownloadButtonView, rightDownloadButtonController.enabled, rightDownloadButtonController.caption);
rightDownloadButtonView.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE);
Drawable leftIcon = rightDownloadButtonController.getLeftIcon();
Drawable rightIcon = rightDownloadButtonController.getRightIcon();
rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
Drawable startIcon = rightDownloadButtonController.getStartIcon();
Drawable endIcon = rightDownloadButtonController.getEndIcon();
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
rightDownloadButton, startIcon, null, endIcon, null);
rightDownloadButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half));
((LinearLayout) rightDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
((LinearLayout) rightDownloadButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START);
} else {
rightDownloadButtonView.setVisibility(View.INVISIBLE);
}
@ -1292,11 +1298,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
setupButton(buttonView, buttonController.enabled, buttonController.caption);
buttonView.setVisibility(buttonController.visible ? View.VISIBLE : View.INVISIBLE);
Drawable leftIcon = buttonController.getLeftIcon();
Drawable rightIcon = buttonController.getRightIcon();
buttonText.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
Drawable startIcon = buttonController.getStartIcon();
Drawable endIcon = buttonController.getEndIcon();
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
buttonText, startIcon, null, endIcon, null);
buttonText.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half));
((LinearLayout) buttonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
((LinearLayout) buttonView).setGravity(endIcon != null ? Gravity.END : Gravity.START);
buttonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -1805,7 +1812,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
if (!Algorithms.isEmpty(typeStr)) {
line2Str.append(typeStr);
Drawable icon = menu.getTypeIcon();
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
line2, icon, null, null, null);
line2.setCompoundDrawablePadding(dpToPx(5f));
}
if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) {
@ -1830,7 +1838,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
line3.setVisibility(View.VISIBLE);
line3.setText(subtypeStr);
Drawable icon = menu.getSubtypeIcon();
line3.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
line3, icon, null, null, null);
line3.setCompoundDrawablePadding(dpToPx(5f));
}

View file

@ -659,7 +659,7 @@ public abstract class MenuController extends BaseMenuController implements Colla
}
leftDownloadButtonController.visible = !downloaded;
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
leftDownloadButtonController.startIconId = R.drawable.ic_action_import;
boolean internetConnectionAvailable =
mapActivity.getMyApplication().getSettings().isInternetConnectionAvailable();
@ -712,33 +712,33 @@ public abstract class MenuController extends BaseMenuController implements Colla
public abstract class TitleButtonController {
public String caption = "";
public int leftIconId = 0;
public int rightIconId = 0;
public int startIconId = 0;
public int endIconId = 0;
public boolean needRightText = false;
public String rightTextCaption = "";
public boolean visible = true;
public boolean tintIcon = true;
public Drawable leftIcon;
public Drawable rightIcon;
public Drawable startIcon;
public Drawable endIcon;
public boolean enabled = true;
@Nullable
public Drawable getLeftIcon() {
public Drawable getStartIcon() {
return getIconDrawable(true);
}
@Nullable
public Drawable getRightIcon() {
public Drawable getEndIcon() {
return getIconDrawable(false);
}
@Nullable
private Drawable getIconDrawable(boolean left) {
Drawable drawable = left ? leftIcon : rightIcon;
private Drawable getIconDrawable(boolean start) {
Drawable drawable = start ? startIcon : endIcon;
if (drawable != null) {
return drawable;
}
int resId = left ? leftIconId : rightIconId;
int resId = start ? startIconId : endIconId;
if (resId != 0) {
if (tintIcon) {
return enabled ? getNormalIcon(resId) : getDisabledIcon(resId);
@ -751,11 +751,11 @@ public abstract class MenuController extends BaseMenuController implements Colla
public void clearIcon(boolean left) {
if (left) {
leftIcon = null;
leftIconId = 0;
startIcon = null;
startIconId = 0;
} else {
rightIcon = null;
rightIconId = 0;
endIcon = null;
endIconId = 0;
}
}
@ -893,7 +893,7 @@ public abstract class MenuController extends BaseMenuController implements Colla
};
leftDownloadButtonController.caption =
downloadRegion != null ? downloadRegion.getLocaleName() : mapActivity.getString(R.string.shared_string_download);
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
leftDownloadButtonController.startIconId = R.drawable.ic_action_import;
titleProgressController = new TitleProgressController() {
@Override

View file

@ -201,8 +201,8 @@ public class AMapPointMenuController extends MenuController {
OsmandApplication app = mapActivity.getMyApplication();
titleButtonController.caption = contextMenuButton.getLeftTextCaption();
titleButtonController.rightTextCaption = contextMenuButton.getRightTextCaption();
titleButtonController.leftIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getLeftIconName());
titleButtonController.rightIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getRightIconName());
titleButtonController.startIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getLeftIconName());
titleButtonController.endIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getRightIconName());
titleButtonController.enabled = contextMenuButton.isEnabled();
titleButtonController.tintIcon = contextMenuButton.isTintIcon();

View file

@ -79,7 +79,7 @@ public class AmenityMenuController extends MenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.context_menu_read_article);
leftTitleButtonController.leftIconId = R.drawable.ic_action_read_text;
leftTitleButtonController.startIconId = R.drawable.ic_action_read_text;
}
openingHoursInfo = OpeningHoursParser.getInfo(amenity.getOpeningHours());

View file

@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
@ -41,7 +40,7 @@ public class ImpassibleRoadsMenuController extends MenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_remove);
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
leftTitleButtonController.startIconId = R.drawable.ic_action_delete_dark;
}
@Override

View file

@ -124,7 +124,7 @@ public class MapDataMenuController extends MenuController {
}
};
leftDownloadButtonController.caption = mapActivity.getString(R.string.shared_string_download);
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
leftDownloadButtonController.startIconId = R.drawable.ic_action_import;
rightDownloadButtonController = new TitleButtonController() {
@Override
@ -154,7 +154,7 @@ public class MapDataMenuController extends MenuController {
}
};
rightDownloadButtonController.caption = mapActivity.getString(R.string.download_select_map_types);
rightDownloadButtonController.leftIconId = R.drawable.ic_plugin_srtm;
rightDownloadButtonController.startIconId = R.drawable.ic_plugin_srtm;
bottomTitleButtonController = new TitleButtonController() {
@Override
@ -171,7 +171,7 @@ public class MapDataMenuController extends MenuController {
}
};
bottomTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete);
bottomTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
bottomTitleButtonController.startIconId = R.drawable.ic_action_delete_dark;
titleProgressController = new TitleProgressController() {
@Override
@ -396,7 +396,7 @@ public class MapDataMenuController extends MenuController {
}
leftDownloadButtonController.visible = true;
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
leftDownloadButtonController.startIconId = R.drawable.ic_action_import;
if (backuped) {
leftDownloadButtonController.caption = mapActivity.getString(R.string.local_index_mi_restore);
} else if (indexItem != null) {

View file

@ -48,7 +48,7 @@ public class MapMarkerMenuController extends MenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(mapMarker.history ? R.string.shared_string_restore : R.string.mark_passed);
leftTitleButtonController.leftIcon = createPassedIcon(getPassedIconBgNormalColorId());
leftTitleButtonController.startIcon = createPassedIcon(getPassedIconBgNormalColorId());
if (!mapMarker.history) {
rightTitleButtonController = new TitleButtonController() {
@ -69,7 +69,7 @@ public class MapMarkerMenuController extends MenuController {
}
};
rightTitleButtonController.caption = mapActivity.getString(R.string.make_active);
rightTitleButtonController.leftIcon = createShowOnTopbarIcon(getDeviceTopNormalColorId());
rightTitleButtonController.startIcon = createShowOnTopbarIcon(getDeviceTopNormalColorId());
}
}

View file

@ -39,7 +39,7 @@ public class PointDescriptionMenuController extends MenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.avoid_road);
leftTitleButtonController.leftIconId = R.drawable.ic_action_road_works_dark;
leftTitleButtonController.startIconId = R.drawable.ic_action_road_works_dark;
}
}

View file

@ -52,10 +52,10 @@ public class TargetPointMenuController extends MenuController {
};
if (nav && intermediatePointsCount == 0 && !targetPoint.start) {
leftTitleButtonController.caption = mapActivity.getString(R.string.cancel_navigation);
leftTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark;
leftTitleButtonController.startIconId = R.drawable.ic_action_remove_dark;
} else {
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_remove);
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
leftTitleButtonController.startIconId = R.drawable.ic_action_delete_dark;
}
}

View file

@ -82,11 +82,11 @@ public class TransportRouteController extends MenuController {
rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_next);
if (AndroidUtils.isLayoutRtl(mapActivity)) {
leftTitleButtonController.rightIconId = R.drawable.ic_arrow_forward;
rightTitleButtonController.leftIconId = R.drawable.ic_arrow_back;
leftTitleButtonController.endIconId = R.drawable.ic_arrow_forward;
rightTitleButtonController.startIconId = R.drawable.ic_arrow_back;
} else {
leftTitleButtonController.leftIconId = R.drawable.ic_arrow_back;
rightTitleButtonController.rightIconId = R.drawable.ic_arrow_forward;
leftTitleButtonController.startIconId = R.drawable.ic_arrow_back;
rightTitleButtonController.endIconId = R.drawable.ic_arrow_forward;
}
}

View file

@ -46,7 +46,7 @@ public class EditPOIMenuController extends MenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_upload);
leftTitleButtonController.leftIconId = R.drawable.ic_action_export;
leftTitleButtonController.startIconId = R.drawable.ic_action_export;
rightTitleButtonController = new TitleButtonController() {
@Override
@ -80,7 +80,7 @@ public class EditPOIMenuController extends MenuController {
}
};
rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete);
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
rightTitleButtonController.startIconId = R.drawable.ic_action_delete_dark;
categoryDescr = getCategoryDescr();

View file

@ -42,7 +42,7 @@ public class OsmBugMenuController extends MenuController {
} else {
leftTitleButtonController.caption = mapActivity.getString(R.string.poi_dialog_reopen);
}
leftTitleButtonController.leftIconId = R.drawable.ic_action_note_dark;
leftTitleButtonController.startIconId = R.drawable.ic_action_note_dark;
rightTitleButtonController = new TitleButtonController() {
@Override
@ -54,7 +54,7 @@ public class OsmBugMenuController extends MenuController {
}
};
rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_close);
rightTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark;
rightTitleButtonController.startIconId = R.drawable.ic_action_remove_dark;
updateData();
}

View file

@ -34,7 +34,7 @@ public class ParkingPositionMenuController extends MenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete);
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
leftTitleButtonController.startIconId = R.drawable.ic_action_delete_dark;
}
private void buildParkingDescription(MapActivity mapActivity) {

View file

@ -32,7 +32,7 @@ public class WikivoyageWptPtMenuController extends WptPtMenuController {
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.context_menu_read_article);
leftTitleButtonController.leftIconId = R.drawable.ic_action_read_text;
leftTitleButtonController.startIconId = R.drawable.ic_action_read_text;
}
private static TravelArticle getTravelArticle(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) {