forked from organicmaps/organicmaps
[android] Add mandatory locale
argument to Java string functions
Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
This commit is contained in:
parent
d4bdcb2149
commit
569b458641
16 changed files with 60 additions and 41 deletions
|
@ -85,8 +85,8 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
|
|||
final Bundle args = new Bundle();
|
||||
args.putString(ARG_TITLE, title);
|
||||
args.putString(ARG_INITIAL, initialText);
|
||||
args.putString(ARG_POSITIVE_BUTTON, positiveBtn == null ? null : positiveBtn.toUpperCase());
|
||||
args.putString(ARG_NEGATIVE_BUTTON, negativeBtn == null ? null : negativeBtn.toUpperCase());
|
||||
args.putString(ARG_POSITIVE_BUTTON, positiveBtn == null ? null : positiveBtn);
|
||||
args.putString(ARG_NEGATIVE_BUTTON, negativeBtn == null ? null : negativeBtn);
|
||||
args.putString(ARG_HINT, hint);
|
||||
args.putInt(ARG_TEXT_LENGTH_LIMIT, textLimit);
|
||||
final EditTextDialogFragment fragment = (EditTextDialogFragment) Fragment.instantiate(parent.requireActivity(), EditTextDialogFragment.class.getName());
|
||||
|
|
|
@ -8,8 +8,6 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
class BottomPanel
|
||||
{
|
||||
private final DownloaderFragment mFragment;
|
||||
|
@ -72,7 +70,7 @@ class BottomPanel
|
|||
|
||||
private void setUpdateAllState(UpdateInfo info)
|
||||
{
|
||||
mButton.setText(String.format(Locale.US, "%s (%s)", mFragment.getString(R.string.downloader_update_all_button),
|
||||
mButton.setText(StringUtils.formatUsingUsLocale("%s (%s)", mFragment.getString(R.string.downloader_update_all_button),
|
||||
StringUtils.getFileSizeString(mFragment.requireContext(), info.totalSize)));
|
||||
mButton.setOnClickListener(mUpdateListener);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.text.TextUtils;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Class representing a single item in countries hierarchy.
|
||||
* Fields are filled by native code.
|
||||
|
@ -161,7 +163,7 @@ public final class CountryItem implements Comparable<CountryItem>
|
|||
", totalSize: " + totalSize +
|
||||
", childCount: " + childCount +
|
||||
", totalChildCount: " + totalChildCount +
|
||||
", progress: " + String.format("%.2f", progress) +
|
||||
", progress: " + StringUtils.formatUsingUsLocale("%.2f", progress) +
|
||||
"% }";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.mapswithme.util.UiUtils;
|
|||
import com.mapswithme.util.Utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class CountrySuggestFragment extends BaseMwmFragment implements View.OnClickListener
|
||||
{
|
||||
|
@ -138,7 +137,7 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl
|
|||
if (mCurrentCountry == null || !isAdded())
|
||||
return;
|
||||
|
||||
mBtnDownloadMap.setText(String.format(Locale.US, "%1$s (%2$s)",
|
||||
mBtnDownloadMap.setText(StringUtils.formatUsingUsLocale("%1$s (%2$s)",
|
||||
getString(R.string.downloader_download_map),
|
||||
StringUtils.getFileSizeString(requireContext(), mCurrentCountry.totalSize)));
|
||||
}
|
||||
|
@ -193,7 +192,8 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl
|
|||
|
||||
private void updateProgress()
|
||||
{
|
||||
String text = String.format(Locale.US, "%1$s %2$.2f%%", getString(R.string.downloader_downloading), mDownloadingCountry.progress);
|
||||
String text = StringUtils.formatUsingUsLocale("%1$s %2$.2f%%", getString(R.string.downloader_downloading),
|
||||
mDownloadingCountry.progress);
|
||||
mTvProgress.setText(text);
|
||||
mWpvDownloadProgress.setProgress(Math.round(mDownloadingCountry.progress));
|
||||
}
|
||||
|
|
|
@ -487,7 +487,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
String searchResultName = mItem.searchResultName;
|
||||
if (!TextUtils.isEmpty(searchResultName))
|
||||
{
|
||||
found = searchResultName.toLowerCase();
|
||||
found = StringUtils.toLowerCase(searchResultName);
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(searchResultName);
|
||||
int start = found.indexOf(mSearchQuery);
|
||||
int end = start + mSearchQuery.length();
|
||||
|
@ -590,7 +590,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
headerId = CountryItem.CATEGORY_AVAILABLE * HEADER_ADS_OFFSET + ci.name.charAt(0);
|
||||
|
||||
if (headerId != prevHeader)
|
||||
mHeaders.put(headerId, ci.name.substring(0, 1).toUpperCase());
|
||||
mHeaders.put(headerId, StringUtils.toUpperCase(ci.name.substring(0, 1)));
|
||||
|
||||
prev = ci.category;
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
void setSearchResultsMode(@NonNull Collection<CountryItem> results, String query)
|
||||
{
|
||||
mSearchResultsMode = true;
|
||||
mSearchQuery = query.toLowerCase();
|
||||
mSearchQuery = StringUtils.toLowerCase(query);
|
||||
|
||||
mItems.clear();
|
||||
mItems.addAll(results);
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.mapswithme.util.StringUtils;
|
|||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
|
||||
{
|
||||
|
@ -141,7 +140,8 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
|
|||
{
|
||||
mProgress.setPending(false);
|
||||
mProgress.setProgress(Math.round(mCurrentCountry.progress));
|
||||
sizeText = String.format(Locale.US, "%1$s %2$.2f%%", mActivity.getString(R.string.downloader_downloading), mCurrentCountry.progress);
|
||||
sizeText = StringUtils.formatUsingUsLocale("%1$s %2$.2f%%",
|
||||
mActivity.getString(R.string.downloader_downloading), mCurrentCountry.progress);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.os.Parcelable;
|
|||
|
||||
import androidx.annotation.IntRange;
|
||||
|
||||
import com.mapswithme.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
@ -35,13 +37,13 @@ public class HoursMinutes implements Parcelable
|
|||
public String toString()
|
||||
{
|
||||
if (m24HourFormat)
|
||||
return String.format(Locale.US, "%02d:%02d", hours, minutes);
|
||||
return StringUtils.formatUsingUsLocale("%02d:%02d", hours, minutes);
|
||||
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, (int)hours);
|
||||
calendar.set(Calendar.MINUTE, (int)minutes);
|
||||
|
||||
SimpleDateFormat fmt12 = new SimpleDateFormat("hh:mm a");
|
||||
SimpleDateFormat fmt12 = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
return fmt12.format(calendar.getTime());
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class HelpFragment extends BaseMwmFragment implements View.OnClickListene
|
|||
// Converts 220131 to locale-dependent date (e.g. 31 January 2022),
|
||||
private String localDate(long v)
|
||||
{
|
||||
final Locale locale = getResources().getConfiguration().locale;
|
||||
final SimpleDateFormat format = new SimpleDateFormat("yyMMdd", locale);
|
||||
final SimpleDateFormat format = new SimpleDateFormat("yyMMdd", Locale.getDefault());
|
||||
final String strVersion = String.valueOf(v);
|
||||
try {
|
||||
final Date date = format.parse(strVersion);
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.mapswithme.maps.search.SearchActivity;
|
|||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.util.KeyValue;
|
||||
import com.mapswithme.util.StorageUtils;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
|
||||
|
@ -95,7 +96,7 @@ public class Factory
|
|||
return null;
|
||||
if (uri.getHost() == null)
|
||||
return null;
|
||||
final String host = uri.getHost().toLowerCase();
|
||||
final String host = StringUtils.toLowerCase(uri.getHost());
|
||||
if (!host.contains("google") && !host.contains("2gis") && !host.contains("openstreetmap"))
|
||||
return null;
|
||||
return new OpenHttpMapsUrlTask(uri.toString());
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
|
@ -90,10 +91,10 @@ public class SearchWheel implements View.OnClickListener
|
|||
@Nullable
|
||||
public static SearchOption fromSearchQuery(@NonNull String query, @NonNull Context context)
|
||||
{
|
||||
final String normalizedQuery = query.trim().toLowerCase();
|
||||
final String normalizedQuery = StringUtils.toLowerCase(query.trim());
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
{
|
||||
final String searchOptionQuery = context.getString(searchOption.mQueryId).trim().toLowerCase();
|
||||
final String searchOptionQuery = StringUtils.toLowerCase(context.getString(searchOption.mQueryId).trim());
|
||||
if (searchOptionQuery.equals(normalizedQuery))
|
||||
return searchOption;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.mapswithme.maps.routing;
|
||||
|
||||
import static androidx.core.app.NotificationCompat.Builder;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
|
@ -17,24 +19,24 @@ import android.widget.RemoteViews;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.location.LocationListener;
|
||||
import com.mapswithme.maps.sound.TtsPlayer;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
|
||||
import static androidx.core.app.NotificationCompat.Builder;
|
||||
|
||||
public class NavigationService extends Service
|
||||
{
|
||||
private static final String TAG = NavigationService.class.getSimpleName();
|
||||
|
||||
public static final String PACKAGE_NAME = NavigationService.class.getPackage().getName();
|
||||
public static final String PACKAGE_NAME_WITH_SERVICE_NAME = PACKAGE_NAME + "." +
|
||||
NavigationService.class.getSimpleName().toLowerCase();
|
||||
StringUtils.toLowerCase(NavigationService.class.getSimpleName());
|
||||
private static final String EXTRA_STOP_SERVICE = PACKAGE_NAME_WITH_SERVICE_NAME + "finish";
|
||||
|
||||
private static final String CHANNEL_ID = "LOCATION_CHANNEL";
|
||||
|
@ -214,7 +216,7 @@ public class NavigationService extends Service
|
|||
final String[] turnNotifications = Framework.nativeGenerateNotifications();
|
||||
if (turnNotifications != null)
|
||||
{
|
||||
mNavigationText = Utils.fixCaseInString(turnNotifications[0]);
|
||||
mNavigationText = StringUtils.fixCaseInString(turnNotifications[0]);
|
||||
TtsPlayer.INSTANCE.playTurnNotifications(getApplicationContext(), turnNotifications);
|
||||
}
|
||||
mRemoteViews.setTextViewText(R.id.navigation_text, mNavigationText);
|
||||
|
|
|
@ -967,8 +967,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
|
|||
}
|
||||
|
||||
// Show whole week time table.
|
||||
Locale locale = getResources().getConfiguration().locale;
|
||||
int firstDayOfWeek = Calendar.getInstance(locale).getFirstDayOfWeek();
|
||||
int firstDayOfWeek = Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek();
|
||||
mOpeningHoursAdapter.setTimetables(timetables, firstDayOfWeek);
|
||||
UiUtils.show(mFullWeekOpeningHours);
|
||||
|
||||
|
@ -1593,7 +1592,8 @@ public class PlacePageView extends NestedScrollViewClickFixed
|
|||
|
||||
StringBuilder sb = new StringBuilder(StringUtils.getFileSizeString(getContext(), country.totalSize));
|
||||
if (country.isExpandable())
|
||||
sb.append(String.format(Locale.US, " • %s: %d", getContext().getString(R.string.downloader_status_maps), country.totalChildCount));
|
||||
sb.append(StringUtils.formatUsingUsLocale(" • %s: %d", getContext().getString(R.string.downloader_status_maps),
|
||||
country.totalChildCount));
|
||||
|
||||
mDownloaderInfo.setText(sb.toString());
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import java.net.URL;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
@ -157,7 +158,8 @@ public final class HttpClient
|
|||
if (header.getKey() == null || header.getValue() == null)
|
||||
continue;
|
||||
|
||||
p.headers.add(new KeyValue(header.getKey().toLowerCase(), TextUtils.join(", ", header.getValue())));
|
||||
p.headers.add(new KeyValue(StringUtils.toLowerCase(header.getKey()), TextUtils.join(", ",
|
||||
header.getValue())));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -66,13 +66,11 @@ public class StringUtils
|
|||
if (value == 0)
|
||||
value = 1;
|
||||
|
||||
return String.format(Locale.US, "%1$d %2$s", value,
|
||||
MwmApplication.from(context).getString(R.string.mb));
|
||||
return formatUsingUsLocale("%1$d %2$s", value, MwmApplication.from(context).getString(R.string.mb));
|
||||
}
|
||||
|
||||
float value = ((float) size / Constants.GB);
|
||||
return String.format(Locale.US, "%1$.1f %2$s", value,
|
||||
MwmApplication.from(context).getString(R.string.gb));
|
||||
return formatUsingUsLocale("%1$.1f %2$s", value, MwmApplication.from(context).getString(R.string.gb));
|
||||
}
|
||||
|
||||
public static boolean isRtl()
|
||||
|
@ -81,6 +79,25 @@ public class StringUtils
|
|||
return Character.getDirectionality(defLocale.getDisplayName(defLocale).charAt(0)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String fixCaseInString(@NonNull String string)
|
||||
{
|
||||
char firstChar = string.charAt(0);
|
||||
return firstChar + toLowerCase(string.substring(1));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String toLowerCase(@NonNull String string)
|
||||
{
|
||||
return string.toLowerCase(Locale.getDefault());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String toUpperCase(@NonNull String string)
|
||||
{
|
||||
return string.toUpperCase(Locale.getDefault());
|
||||
}
|
||||
|
||||
public static class SimpleTextWatcher implements TextWatcher
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -752,13 +752,6 @@ public class Utils
|
|||
return dateFormat.format(calendar.getTime());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String fixCaseInString(@NonNull String string)
|
||||
{
|
||||
char firstChar = string.charAt(0);
|
||||
return firstChar + string.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
private static class SupportInfoWithLogsCallback implements LogsManager.OnZipCompletedListener
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -17,6 +17,8 @@ import androidx.annotation.Nullable;
|
|||
import com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
|
||||
import net.jcip.annotations.ThreadSafe;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -235,7 +237,7 @@ public final class LogsManager
|
|||
sb.append(", security patch level: ").append(Build.VERSION.SECURITY_PATCH);
|
||||
sb.append(", os.version: " + System.getProperty("os.version", "N/A"))
|
||||
.append("\nDevice: ");
|
||||
if (!Build.MODEL.toLowerCase().startsWith(Build.MANUFACTURER.toLowerCase()))
|
||||
if (!StringUtils.toLowerCase(Build.MODEL).startsWith(StringUtils.toLowerCase(Build.MANUFACTURER)))
|
||||
sb.append(Build.MANUFACTURER).append(' ');
|
||||
sb.append(Build.MODEL).append(" (").append(Build.DEVICE).append(')');
|
||||
sb.append("\nSupported ABIs:");
|
||||
|
|
Loading…
Add table
Reference in a new issue