RTL - Step 3 (Fixes)
This commit is contained in:
parent
cb105deda0
commit
7ba03d94e4
7 changed files with 49 additions and 37 deletions
|
@ -425,6 +425,17 @@ public class AndroidUtils {
|
|||
: ctx.getResources().getColor(R.color.text_color_secondary_light));
|
||||
}
|
||||
|
||||
public static int getPopupMenuWidth(Context ctx, float textSize, List<String> titles) {
|
||||
int width = 0;
|
||||
for (String title : titles) {
|
||||
int titleWidth = getTextWidth(textSize, title);
|
||||
if (titleWidth > width) {
|
||||
width = titleWidth;
|
||||
}
|
||||
}
|
||||
return width + dpToPx(ctx, 34);
|
||||
}
|
||||
|
||||
public static int getTextWidth(float textSize, String text) {
|
||||
Paint paint = new Paint();
|
||||
paint.setTextSize(textSize);
|
||||
|
|
|
@ -12,10 +12,12 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SimplePopUpMenuItemAdapter
|
||||
extends ArrayAdapter<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> {
|
||||
extends ArrayAdapter<SimplePopUpMenuItem> {
|
||||
|
||||
private List<SimplePopUpMenuItem> items;
|
||||
|
||||
|
@ -35,7 +37,7 @@ public class SimplePopUpMenuItemAdapter
|
|||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
if (convertView == null) {
|
||||
convertView = inflater.inflate(R.layout.popup_menu_item, null);
|
||||
convertView = inflater.inflate(R.layout.popup_menu_item, parent, false);
|
||||
}
|
||||
SimplePopUpMenuItem item = getItem(position);
|
||||
if (item != null) {
|
||||
|
|
|
@ -55,10 +55,13 @@ import net.osmand.plus.widgets.TextViewEx;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||
|
||||
import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem;
|
||||
|
||||
public class UiUtilities {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(UiUtilities.class);
|
||||
|
@ -363,15 +366,15 @@ public class UiUtilities {
|
|||
}
|
||||
return screenOrientation;
|
||||
}
|
||||
|
||||
|
||||
public static void setupSnackbar(Snackbar snackbar, boolean nightMode) {
|
||||
setupSnackbar(snackbar, nightMode, null, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
public static void setupSnackbar(Snackbar snackbar, boolean nightMode, Integer maxLines) {
|
||||
setupSnackbar(snackbar, nightMode, null, null, null, maxLines);
|
||||
}
|
||||
|
||||
|
||||
public static void setupSnackbar(Snackbar snackbar, boolean nightMode, @ColorRes Integer backgroundColor,
|
||||
@ColorRes Integer messageColor, @ColorRes Integer actionColor, Integer maxLines) {
|
||||
if (snackbar == null) {
|
||||
|
@ -556,7 +559,7 @@ public class UiUtilities {
|
|||
// label behavior
|
||||
slider.setLabelBehavior(Slider.LABEL_GONE);
|
||||
}
|
||||
|
||||
|
||||
public static void setupDialogButton(boolean nightMode, View buttonView, DialogButtonType buttonType, @StringRes int buttonTextId) {
|
||||
setupDialogButton(nightMode, buttonView, buttonType, buttonView.getContext().getString(buttonTextId));
|
||||
}
|
||||
|
@ -651,23 +654,18 @@ public class UiUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static ListPopupWindow createListPopupWindow(Context themedCtx, View v,
|
||||
List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items,
|
||||
public static ListPopupWindow createListPopupWindow(Context themedCtx,
|
||||
View v, int minWidth,
|
||||
List<SimplePopUpMenuItem> items,
|
||||
final AdapterView.OnItemClickListener listener) {
|
||||
int contentPadding = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||
int contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half);
|
||||
int defaultListTextSize = themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setTextSize(themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size));
|
||||
CharSequence longestTitle = "";
|
||||
for (SimplePopUpMenuItemAdapter.SimplePopUpMenuItem item : items) {
|
||||
if (item.getTitle().length() > longestTitle.length()) {
|
||||
longestTitle = item.getTitle();
|
||||
}
|
||||
List<String> titles = new ArrayList<>();
|
||||
for (SimplePopUpMenuItem item : items) {
|
||||
titles.add(String.valueOf(item.getTitle()));
|
||||
}
|
||||
float titleTextWidth = paint.measureText(longestTitle.toString());
|
||||
float itemWidth = titleTextWidth + contentPadding;
|
||||
float minWidth = v.getWidth();
|
||||
float itemWidth = AndroidUtils.getPopupMenuWidth(themedCtx, defaultListTextSize, titles);
|
||||
|
||||
SimplePopUpMenuItemAdapter adapter =
|
||||
new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items);
|
||||
|
|
|
@ -32,7 +32,6 @@ import net.osmand.data.RotatedTileBox;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SimplePopUpMenuItemAdapter;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
@ -48,6 +47,8 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem;
|
||||
|
||||
public class TrackDetailsMenu {
|
||||
|
||||
@Nullable
|
||||
|
@ -490,6 +491,9 @@ public class TrackDetailsMenu {
|
|||
if (mapActivity == null || gpxItem == null) {
|
||||
return;
|
||||
}
|
||||
final OsmandApplication app = mapActivity.getMyApplication();
|
||||
final UiUtilities ic = app.getUIUtilities();
|
||||
final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
GPXTrackAnalysis analysis = gpxItem.analysis;
|
||||
if (analysis == null || gpxItem.chartTypes == null) {
|
||||
parentView.setVisibility(View.GONE);
|
||||
|
@ -576,9 +580,6 @@ public class TrackDetailsMenu {
|
|||
}
|
||||
});
|
||||
|
||||
final OsmandApplication app = mapActivity.getMyApplication();
|
||||
final UiUtilities ic = app.getUIUtilities();
|
||||
|
||||
GpxUiHelper.setupGPXChart(app, chart, 4);
|
||||
|
||||
List<ILineDataSet> dataSets = new ArrayList<>();
|
||||
|
@ -652,15 +653,15 @@ public class TrackDetailsMenu {
|
|||
yAxis.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context themedContext = UiUtilities.getThemedContext(v.getContext(), true);
|
||||
List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
Context themedContext = UiUtilities.getThemedContext(v.getContext(), nightMode);
|
||||
List<SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
for (GPXDataSetType[] types : availableTypes) {
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
items.add(new SimplePopUpMenuItem(
|
||||
GPXDataSetType.getName(app, types),
|
||||
GPXDataSetType.getImageDrawable(app, types)));
|
||||
}
|
||||
UiUtilities.createListPopupWindow(
|
||||
themedContext, v, items, new AdapterView.OnItemClickListener() {
|
||||
themedContext, v, v.getWidth(), items, new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
GpxDisplayItem gpxItem = getGpxItem();
|
||||
|
@ -695,14 +696,14 @@ public class TrackDetailsMenu {
|
|||
xAxis.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context themedContext = UiUtilities.getThemedContext(v.getContext(), true);
|
||||
List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
Context themedContext = UiUtilities.getThemedContext(v.getContext(), nightMode);
|
||||
List<SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
for (GPXDataSetAxisType type : GPXDataSetAxisType.values()) {
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
items.add(new SimplePopUpMenuItem(
|
||||
app.getString(type.getStringId()), type.getImageDrawable(app)));
|
||||
}
|
||||
UiUtilities.createListPopupWindow(themedContext,
|
||||
v, items, new AdapterView.OnItemClickListener() {
|
||||
v, v.getWidth(), items, new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
GpxDisplayItem gpxItem = getGpxItem();
|
||||
|
|
|
@ -30,6 +30,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
|
|||
private TrackDetailsMenu menu;
|
||||
private View mainView;
|
||||
private boolean paused = true;
|
||||
private boolean nightMode;
|
||||
|
||||
@Nullable
|
||||
private MapActivity getMapActivity() {
|
||||
|
@ -46,7 +47,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
|
|||
Bundle savedInstanceState) {
|
||||
MapActivity mapActivity = requireMapActivity();
|
||||
menu = mapActivity.getTrackDetailsMenu();
|
||||
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
ContextThemeWrapper context =
|
||||
new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.track_details, container, false);
|
||||
|
@ -192,7 +193,6 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
|
|||
if (ctx != null) {
|
||||
boolean portraitMode = AndroidUiHelper.isOrientationPortrait(ctx);
|
||||
boolean landscapeLayout = !portraitMode;
|
||||
boolean nightMode = ctx.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
if (!landscapeLayout) {
|
||||
AndroidUtils.setBackground(ctx, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||
} else {
|
||||
|
|
|
@ -81,9 +81,8 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
|
|||
}
|
||||
int expandType = args.getInt(EXPAND_TYPE_KEY, -1);
|
||||
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.bottom_sheet_item_toolbar_title, null);
|
||||
final View titleView = UiUtilities.getInflater(ctx, nightMode)
|
||||
.inflate(R.layout.bottom_sheet_item_toolbar_title, null);
|
||||
TextView textView = (TextView) titleView.findViewById(R.id.title);
|
||||
textView.setText(R.string.show_along_the_route);
|
||||
|
||||
|
|
|
@ -173,6 +173,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
private SearchUICore searchUICore;
|
||||
private SearchResultListener defaultResultListener;
|
||||
private String searchQuery;
|
||||
private boolean nightMode;
|
||||
|
||||
private LatLon centerLatLon;
|
||||
private net.osmand.Location location = null;
|
||||
|
@ -229,6 +230,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = getMyApplication();
|
||||
nightMode = !app.getSettings().isLightContent();
|
||||
navigationInfo = new NavigationInfo(app);
|
||||
accessibilityAssistant = new AccessibilityAssistant(getActivity());
|
||||
boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
|
@ -242,7 +244,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
Bundle savedInstanceState) {
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false);
|
||||
final boolean nightMode = !app.getSettings().isLightContent();
|
||||
|
||||
toolbarController = new QuickSearchToolbarController();
|
||||
toolbarController.setOnBackButtonClickListener(new OnClickListener() {
|
||||
|
|
Loading…
Reference in a new issue