From 90dc1a4ba8250af9b7fb444e953cd1c1e093f6eb Mon Sep 17 00:00:00 2001 From: Hardy Date: Sun, 23 Feb 2020 10:18:42 +0100 Subject: [PATCH 01/30] Confirmation dialog for 'Clear recorded data' (cherry picked from commit f5886ee577f65df161ccb827e6408d80f606d603) --- .../plus/monitoring/OsmandMonitoringPlugin.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 1009ea771e..e6fab01a86 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -288,7 +288,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { public void controlDialog(final Activity activity, final boolean showTrackSelection) { final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); - boolean nightMode; + final boolean nightMode; if (activity instanceof MapActivity) { nightMode = app.getDaynightHelper().isNightModeForMapControls(); } else { @@ -328,7 +328,17 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { startGPXMonitoring(activity, showTrackSelection); } } else if (item == R.string.clear_recorded_data) { - app.getSavingTrackHelper().clearRecordedData(true); + AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode)); + builder.setTitle(R.string.clear_recorded_data); + builder.setMessage(R.string.are_you_sure); + builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton( + R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + app.getSavingTrackHelper().clearRecordedData(true); + } + }); + builder.show(); } else if(item == R.string.gpx_monitoring_stop) { stopRecording(); } else if(item == R.string.gpx_start_new_segment) { From ceb0a5ab887ad33b86e84f3bf7af86bd7c946e67 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 27 Feb 2020 13:44:59 +0200 Subject: [PATCH 02/30] Change clear data dialog --- OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/monitoring/OsmandMonitoringPlugin.java | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6984349329..345cde9a3f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Are you sure you want to clear recorded data? Custom profile Angle: %s° Angle diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index e6fab01a86..8ed174678e 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -329,10 +329,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { } } else if (item == R.string.clear_recorded_data) { AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode)); - builder.setTitle(R.string.clear_recorded_data); - builder.setMessage(R.string.are_you_sure); - builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton( - R.string.shared_string_ok, new DialogInterface.OnClickListener() { + builder.setTitle(R.string.clear_recorded_data_warning); + builder.setNegativeButton(R.string.shared_string_no, null).setPositiveButton( + R.string.shared_string_clear, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { app.getSavingTrackHelper().clearRecordedData(true); From beab9512b970ab71ffda064736795d7528caec54 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 27 Feb 2020 14:26:19 +0200 Subject: [PATCH 03/30] fix import list header on lower versions --- OsmAnd/res/layout/list_item_description_header.xml | 2 +- OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/list_item_description_header.xml b/OsmAnd/res/layout/list_item_description_header.xml index 7d0a15d436..1a8c777b87 100644 --- a/OsmAnd/res/layout/list_item_description_header.xml +++ b/OsmAnd/res/layout/list_item_description_header.xml @@ -2,7 +2,7 @@ Date: Thu, 27 Feb 2020 16:37:05 +0300 Subject: [PATCH 04/30] Fix #8471 --- .../java/net/osmand/search/SearchUICore.java | 35 +++++++++---------- .../net/osmand/search/core/SearchResult.java | 24 ++++++------- .../net/osmand/search/SearchCoreUITest.java | 3 +- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index d244d60a06..520bfad345 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -866,9 +866,9 @@ public class SearchUICore { // -1 - means 1st is less than 2nd return topVisible1 ? -1 : 1; } -// if (o1.getUnknownPhraseMatchWeight() != o2.getUnknownPhraseMatchWeight()) { -// return -Double.compare(o1.getUnknownPhraseMatchWeight(), o2.getUnknownPhraseMatchWeight()); -// } + if (o1.getUnknownPhraseMatchWeight() != o2.getUnknownPhraseMatchWeight()) { + return -Double.compare(o1.getUnknownPhraseMatchWeight(), o2.getUnknownPhraseMatchWeight()); + } if (o1.getFoundWordCount() != o2.getFoundWordCount()) { return -Algorithms.compare(o1.getFoundWordCount(), o2.getFoundWordCount()); } @@ -879,25 +879,24 @@ public class SearchUICore { return Double.compare(s1, s2); } } - int st1 = o1.localeName == null ? -10000 : Algorithms.extractFirstIntegerNumber(o1.localeName); - int st2 = o2.localeName == null ? -10000 : Algorithms.extractFirstIntegerNumber(o2.localeName); + String localeName1 = o1.localeName == null ? "" : o1.localeName; + String localeName2 = o2.localeName == null ? "" : o2.localeName; + int st1 = Algorithms.extractFirstIntegerNumber(localeName1); + int st2 = Algorithms.extractFirstIntegerNumber(localeName2); if (st1 != st2) { return Algorithms.compare(st1, st2); } - String localeName1 = o1.localeName == null ? "" : o1.localeName; - String localeName2 = o2.localeName == null ? "" : o2.localeName; double s1 = o1.getSearchDistance(loc, 1); double s2 = o2.getSearchDistance(loc, 1); - // ???? -// if (o1.parentSearchResult != null && o2.parentSearchResult != null) { -// if (o1.parentSearchResult == o2.parentSearchResult) { -// int cmp = collator.compare(localeName1, localeName2); -// if (cmp != 0) { -// return cmp; -// } -// } -// return Double.compare(s1, s2); -// } + if (o1.parentSearchResult != null && o2.parentSearchResult != null) { + if (o1.parentSearchResult == o2.parentSearchResult) { + int cmp = collator.compare(localeName1, localeName2); + if (cmp != 0) { + return cmp; + } + } + return Double.compare(s1, s2); + } int cmp = collator.compare(localeName1, localeName2); if (cmp != 0) { return cmp; @@ -905,7 +904,7 @@ public class SearchUICore { if (s1 != s2) { return Double.compare(s1, s2); } - boolean am1 = o2.object instanceof Amenity; + boolean am1 = o1.object instanceof Amenity; boolean am2 = o2.object instanceof Amenity; if (am1 != am2) { return Boolean.compare(am1, am2); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index b08d901bdc..93f0acfafd 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -29,26 +29,26 @@ public class SearchResult { public boolean firstUnknownWordMatches = true; public boolean unknownPhraseMatches = false; + public SearchResult(SearchPhrase sp) { + this.requiredSearchPhrase = sp; + } + public double getUnknownPhraseMatchWeight() { + return getUnknownPhraseMatchWeight(false); + } + + private double getUnknownPhraseMatchWeight(boolean isHouse) { double res = 0; - boolean isHouse = objectType == ObjectType.HOUSE; + isHouse = isHouse || objectType == ObjectType.HOUSE; if (unknownPhraseMatches) { - res = ObjectType.getTypeWeight(objectType); + res = isHouse ? ObjectType.getTypeWeight(ObjectType.HOUSE) : ObjectType.getTypeWeight(objectType); } - if (res == 0 && parentSearchResult != null && parentSearchResult.unknownPhraseMatches) { - if (isHouse && parentSearchResult.objectType == ObjectType.STREET) { - res = ObjectType.getTypeWeight(ObjectType.HOUSE); - } else { - res = ObjectType.getTypeWeight(parentSearchResult.objectType); - } + if (res == 0 && parentSearchResult != null) { + return parentSearchResult.getUnknownPhraseMatchWeight(isHouse); } return res; } - public SearchResult(SearchPhrase sp) { - this.requiredSearchPhrase = sp; - } - public int getFoundWordCount() { int inc = 0; if (firstUnknownWordMatches) { diff --git a/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java b/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java index 48bd610345..80d92b7bf1 100644 --- a/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java +++ b/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java @@ -222,8 +222,7 @@ public class SearchCoreUITest { }); if (files != null) { for (File f : files) { - // FIXME -// testSearchImpl(f); + testSearchImpl(f); } } } From 72cdeb2ffb04f8a86707b6a487cf064bdb2979c5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 27 Feb 2020 15:47:37 +0200 Subject: [PATCH 05/30] Test fix --- .../java/net/osmand/search/SearchUICore.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 520bfad345..6612ddd4cf 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -888,15 +888,20 @@ public class SearchUICore { } double s1 = o1.getSearchDistance(loc, 1); double s2 = o2.getSearchDistance(loc, 1); - if (o1.parentSearchResult != null && o2.parentSearchResult != null) { - if (o1.parentSearchResult == o2.parentSearchResult) { - int cmp = collator.compare(localeName1, localeName2); - if (cmp != 0) { - return cmp; - } - } - return Double.compare(s1, s2); + double ps1 = o1.parentSearchResult == null ? 0 : o1.parentSearchResult.getSearchDistance(loc); + double ps2 = o2.parentSearchResult == null ? 0 : o2.parentSearchResult.getSearchDistance(loc); + if (ps1 != ps2) { + return Double.compare(ps1, ps2); } +// if (o1.parentSearchResult != null && o2.parentSearchResult != null) { +// if (o1.parentSearchResult == o2.parentSearchResult) { +// int cmp = collator.compare(localeName1, localeName2); +// if (cmp != 0) { +// return cmp; +// } +// } +// return Double.compare(s1, s2); +// } int cmp = collator.compare(localeName1, localeName2); if (cmp != 0) { return cmp; From fc65678ce44a0045e194dc6d839898a7b3c00dbc Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 27 Feb 2020 15:53:01 +0200 Subject: [PATCH 06/30] Improve search --- .../src/main/java/net/osmand/search/SearchUICore.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 6612ddd4cf..309101f720 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -893,15 +893,6 @@ public class SearchUICore { if (ps1 != ps2) { return Double.compare(ps1, ps2); } -// if (o1.parentSearchResult != null && o2.parentSearchResult != null) { -// if (o1.parentSearchResult == o2.parentSearchResult) { -// int cmp = collator.compare(localeName1, localeName2); -// if (cmp != 0) { -// return cmp; -// } -// } -// return Double.compare(s1, s2); -// } int cmp = collator.compare(localeName1, localeName2); if (cmp != 0) { return cmp; From 0dc6c36b99cab135bee936b7d4668e2a521ecdd2 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 27 Feb 2020 16:04:18 +0200 Subject: [PATCH 07/30] Refresh TextFieldBoxes library --- OsmAnd/build.gradle | 2 +- .../res/layout/preference_dropdown_list.xml | 12 ++--- .../SaveAsTrackBottomSheetDialogFragment.java | 3 -- .../OnSaveCurrentTrackFragment.java | 1 - .../EditTextPreferenceBottomSheet.java | 8 ++-- .../plus/widgets/OsmandTextFieldBoxes.java | 47 ------------------- 6 files changed, 8 insertions(+), 65 deletions(-) diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index e52705773c..1de4d7f005 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -495,7 +495,7 @@ dependencies { exclude group: 'com.android.support' } implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1' - implementation ("com.github.HITGIF:TextFieldBoxes:1.3.5"){ + implementation ("com.github.HITGIF:TextFieldBoxes:1.4.4"){ exclude group: 'com.android.support' } diff --git a/OsmAnd/res/layout/preference_dropdown_list.xml b/OsmAnd/res/layout/preference_dropdown_list.xml index 58d5baedba..9f3bb7945f 100644 --- a/OsmAnd/res/layout/preference_dropdown_list.xml +++ b/OsmAnd/res/layout/preference_dropdown_list.xml @@ -7,6 +7,7 @@ android:orientation="vertical"> + android:layout_marginBottom="@dimen/content_padding_half"> @@ -44,13 +45,6 @@ - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java index 0c893db19b..dab783ff26 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java @@ -105,9 +105,6 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text); nameEditText.setText(displayedName); nameEditText.setTextColor(ContextCompat.getColor(getContext(), textPrimaryColor)); - if (textBox instanceof OsmandTextFieldBoxes) { - ((OsmandTextFieldBoxes) textBox).activate(true); - } mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java index 6765a435c1..4ca4097e0a 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java @@ -86,7 +86,6 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text); nameEditText.setText(savedGpxName); nameEditText.setTextColor(ContextCompat.getColor(ctx, textPrimaryColor)); - textBox.activate(true); nameEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java index 3868fcc6f2..07b29c57f4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java @@ -7,8 +7,8 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.view.View; +import android.view.ViewGroup; import android.widget.EditText; -import android.widget.RelativeLayout; import net.osmand.AndroidUtils; import net.osmand.plus.ApplicationMode; @@ -50,9 +50,9 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet { editText = view.findViewById(R.id.edit_text); editText.setText(text); - RelativeLayout editTextLayout = view.findViewById(R.id.text_field_boxes_editTextLayout); - if (editTextLayout != null && editTextLayout.getLayoutParams() instanceof RelativeLayout.LayoutParams) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) editTextLayout.getLayoutParams(); + ViewGroup editTextLayout = view.findViewById(R.id.text_field_boxes_editTextLayout); + if (editTextLayout != null && editTextLayout.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) editTextLayout.getLayoutParams(); params.setMargins(params.leftMargin, AndroidUtils.dpToPx(ctx, 9), params.rightMargin, params.bottomMargin); } diff --git a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java index 7449a29a0c..565abc93b3 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java +++ b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java @@ -1,14 +1,10 @@ package net.osmand.plus.widgets; import android.content.Context; -import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.view.View; import android.view.inputmethod.InputMethodManager; -import net.osmand.plus.R; - -import studio.carbonylgroup.textfieldboxes.ExtendedEditText; import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; public class OsmandTextFieldBoxes extends TextFieldBoxes { @@ -63,47 +59,4 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes { performClick(); } - @Override - public void activate(boolean animated) { - super.activate(animated); - } - - @Override - public void deactivate() { - if(this.editText.getText().toString().isEmpty()) { - ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION); - this.editTextLayout.setVisibility(View.INVISIBLE); - if(this.editText.hasFocus()) { - if (!useOsmandKeyboard) { - this.inputMethodManager.hideSoftInputFromWindow(this.editText.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); - } - this.editText.clearFocus(); - } - } - - this.activated = false; - } - - public ExtendedEditText getEditText() { - return editText; - } - - @Override - protected void makeCursorBlink() { - CharSequence hintCache = this.editText.getHint(); - this.editText.setHint(" "); - this.editText.setHint(hintCache); - } - - @Override - public void setError(String errorText, boolean giveFocus) { - super.setError(errorText, giveFocus); - this.findViewById(R.id.text_field_boxes_bottom).setVisibility(View.VISIBLE); - } - - @Override - public void removeError() { - super.removeError(); - this.findViewById(R.id.text_field_boxes_bottom).setVisibility(View.GONE); - } } From f7a6be3a18d3231b1ffcdc6525cb548fa53d3555 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 28 Feb 2020 13:15:10 +0200 Subject: [PATCH 08/30] Fix free plugins availability (cherry picked from commit 4e55ebfcd3f2c60d628743724095eed82c558066) --- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 2 +- OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 5e5d4afedd..5cd53c72db 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -294,7 +294,7 @@ public abstract class OsmandPlugin { } protected boolean pluginAvailable(OsmandApplication app) { - return checkPluginPackage(app, this); + return checkPluginPackage(app, this) || !isPaid(); } public static boolean checkPluginPackage(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index 62070b42b2..0760b9839e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -335,6 +335,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } protected void onPostExecute(OsmBugResult obj) { + if (activity == null || activity.isFinishing() || activity.isActivityDestroyed()) { + return; + } if (obj != null && obj.warning == null) { if (local == osmbugsUtil) { Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show(); From 0497fa172dd60257a5844f245b745846caa6bd4d Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 28 Feb 2020 16:12:52 +0200 Subject: [PATCH 09/30] import ui fix --- OsmAnd/res/layout/fragment_import.xml | 18 ++++++------------ .../res/layout/fragment_import_duplicates.xml | 12 +++++------- OsmAnd/res/layout/list_item_header_import.xml | 7 ++++++- OsmAnd/res/values/sizes.xml | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 29d43b823e..c5049179cc 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -53,9 +53,7 @@ android:gravity="start|center_vertical" android:maxLines="1" android:paddingLeft="@dimen/content_padding_small" - android:paddingTop="@dimen/content_padding_half" android:paddingRight="@dimen/content_padding_small" - android:paddingBottom="@dimen/content_padding_half" android:text="@string/shared_string_select_all" android:textColor="?attr/active_color_basic" android:textSize="@dimen/default_desc_text_size" @@ -80,12 +78,10 @@ android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:ellipsize="end" - android:gravity="end|center_vertical" + android:gravity="center" android:maxLines="1" android:paddingLeft="@dimen/content_padding_small" - android:paddingTop="@dimen/content_padding_half" android:paddingRight="@dimen/content_padding_small" - android:paddingBottom="@dimen/content_padding_half" android:text="@string/shared_string_continue" android:textColor="?attr/dlg_btn_primary_text" android:textSize="@dimen/default_desc_text_size" @@ -109,6 +105,9 @@ android:layout_width="match_parent" android:layout_height="@dimen/toolbar_height_expanded" android:background="?attr/colorPrimary" + osmand:expandedTitleMarginBottom="@dimen/content_padding_small" + osmand:expandedTitleMarginEnd="@dimen/content_padding" + osmand:expandedTitleMarginStart="@dimen/content_padding" osmand:collapsedTitleTextAppearance="@style/AppBarTitle" osmand:expandedTitleGravity="start|bottom" osmand:expandedTitleTextAppearance="@style/AppBarTitle" @@ -116,6 +115,8 @@ - - diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index a12f52d4b6..9f8dad5f48 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -112,6 +112,9 @@ android:layout_width="match_parent" android:layout_height="@dimen/toolbar_height_expanded" android:background="?attr/colorPrimary" + osmand:expandedTitleMarginBottom="@dimen/content_padding_small" + osmand:expandedTitleMarginEnd="@dimen/content_padding" + osmand:expandedTitleMarginStart="@dimen/content_padding" osmand:collapsedTitleTextAppearance="@style/AppBarTitle" osmand:expandedTitleGravity="start|bottom" osmand:expandedTitleTextAppearance="@style/AppBarTitle" @@ -122,6 +125,8 @@ android:layout_width="match_parent" android:layout_height="@dimen/toolbar_height" android:minHeight="@dimen/toolbar_height" + osmand:titleMarginEnd="0dp" + osmand:titleMarginStart="0dp" osmand:layout_collapseMode="pin" osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed" osmand:title="@string/import_duplicates_title"> @@ -130,13 +135,6 @@ - - diff --git a/OsmAnd/res/layout/list_item_header_import.xml b/OsmAnd/res/layout/list_item_header_import.xml index 381f2df543..a1915cf2fe 100644 --- a/OsmAnd/res/layout/list_item_header_import.xml +++ b/OsmAnd/res/layout/list_item_header_import.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + xmlns:osmand="http://schemas.android.com/apk/res-auto" android:orientation="vertical"> 56dp 56dp - 112dp + 96dp 36dp 80dp From ead1fa4c4b94bee9c7b6122df0a75ced07db43fc Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 28 Feb 2020 18:27:57 +0200 Subject: [PATCH 10/30] Fix "Master Profile" is not clickable --- OsmAnd/res/layout/preference_dropdown_list.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/layout/preference_dropdown_list.xml b/OsmAnd/res/layout/preference_dropdown_list.xml index 9f3bb7945f..78e57317f9 100644 --- a/OsmAnd/res/layout/preference_dropdown_list.xml +++ b/OsmAnd/res/layout/preference_dropdown_list.xml @@ -7,7 +7,6 @@ android:orientation="vertical"> + + \ No newline at end of file From c87177782af212d1741add54cba831a5ab033365 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 28 Feb 2020 18:36:39 +0200 Subject: [PATCH 11/30] Remove unnecessary code --- .../plus/widgets/OsmandTextFieldBoxes.java | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java index 565abc93b3..9f6aed3c9e 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java +++ b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java @@ -2,15 +2,11 @@ package net.osmand.plus.widgets; import android.content.Context; import android.util.AttributeSet; -import android.view.View; -import android.view.inputmethod.InputMethodManager; import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; public class OsmandTextFieldBoxes extends TextFieldBoxes { - private boolean useOsmandKeyboard; - public OsmandTextFieldBoxes(Context context) { super(context); } @@ -23,40 +19,4 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes { super(context, attrs, defStyleAttr); } - public void setUseOsmandKeyboard(boolean useOsmandKeyboard) { - this.useOsmandKeyboard = useOsmandKeyboard; - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - if (editText != null) { - this.panel.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - select(); - } - }); - - this.iconImageButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - select(); - } - }); - } - } - - public void select() { - if(!OsmandTextFieldBoxes.this.isActivated()) { - OsmandTextFieldBoxes.this.activate(true); - } - - OsmandTextFieldBoxes.this.setHasFocus(true); - if (!useOsmandKeyboard) { - OsmandTextFieldBoxes.this.inputMethodManager.showSoftInput(OsmandTextFieldBoxes.this.editText, InputMethodManager.SHOW_IMPLICIT); - } - performClick(); - } - } From 22ea47b7223c61de8c88bfac724e34035c3cbf21 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Tue, 3 Mar 2020 15:24:21 +0200 Subject: [PATCH 12/30] Fix RTL (LTR) layouts and code problems --- OsmAnd/res/layout/dashboard_toolbar.xml | 174 ++++++++++-------- .../layout/expandable_list_item_category.xml | 111 +++++------ OsmAnd/res/layout/fragment_search_list.xml | 6 +- OsmAnd/res/layout/gpx_track_item.xml | 34 ++-- OsmAnd/res/layout/list_menu_item_native.xml | 79 +++++--- OsmAnd/res/layout/local_index_list_item.xml | 111 +++++------ ...main_menu_drawer_btn_configure_profile.xml | 4 +- .../main_menu_drawer_btn_switch_profile.xml | 6 +- .../res/layout/map_context_menu_fragment.xml | 46 ++--- OsmAnd/res/layout/order_poi_list_item.xml | 1 - .../layout/quick_action_add_dialog_item.xml | 6 +- .../quick_action_deletable_list_item.xml | 4 +- OsmAnd/res/layout/route_info_card.xml | 2 +- OsmAnd/res/layout/search_fav_list_item.xml | 6 +- OsmAnd/res/layout/search_list_item.xml | 6 +- .../layout/select_gpx_appearance_title.xml | 28 +-- .../layout/two_line_with_images_list_item.xml | 4 +- OsmAnd/src/net/osmand/AndroidUtils.java | 35 ++++ .../net/osmand/plus/ContextMenuAdapter.java | 3 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 31 +++- .../activities/FavoritesSearchFragment.java | 2 + .../activities/FavoritesTreeFragment.java | 8 +- .../base/MenuBottomSheetDialogFragment.java | 1 + .../osmand/plus/dashboard/DashboardOnMap.java | 2 + .../plus/download/DownloadActivity.java | 2 + .../download/ui/DownloadGroupViewHolder.java | 21 ++- .../ui/DownloadResourceGroupFragment.java | 24 ++- .../plus/download/ui/ItemViewHolder.java | 2 + .../net/osmand/plus/helpers/GpxUiHelper.java | 3 +- .../plus/liveupdates/LiveUpdatesFragment.java | 2 + .../plus/liveupdates/ReportsFragment.java | 2 + .../MapContextMenuFragment.java | 6 +- .../plus/mapcontextmenu/MenuBuilder.java | 38 ++-- .../builders/AmenityMenuBuilder.java | 12 +- .../builders/GpxItemMenuBuilder.java | 5 +- .../mapmarkers/MapMarkersDialogFragment.java | 1 + .../OptionsBottomSheetDialogFragment.java | 2 + .../adapters/MapMarkersActiveAdapter.java | 1 + .../adapters/MapMarkersGroupsAdapter.java | 20 +- .../adapters/MapMarkersHistoryAdapter.java | 12 +- .../adapters/MapMarkersListAdapter.java | 1 + .../plus/myplaces/AvailableGPXFragment.java | 2 + .../plus/poi/RearrangePoiFiltersFragment.java | 21 ++- .../plus/profiles/EditProfilesFragment.java | 16 +- .../quickaction/QuickActionListFragment.java | 2 + .../MapRouteInfoMenu.java | 4 +- .../QuickSearchCoordinatesFragment.java | 1 + .../search/QuickSearchDialogFragment.java | 2 + .../plus/search/QuickSearchListAdapter.java | 4 +- .../plus/settings/BaseSettingsFragment.java | 1 + 50 files changed, 548 insertions(+), 369 deletions(-) diff --git a/OsmAnd/res/layout/dashboard_toolbar.xml b/OsmAnd/res/layout/dashboard_toolbar.xml index 348a1e4307..8c0eed7069 100644 --- a/OsmAnd/res/layout/dashboard_toolbar.xml +++ b/OsmAnd/res/layout/dashboard_toolbar.xml @@ -10,90 +10,106 @@ app:contentInsetLeft="4dp" app:contentInsetStart="4dp"> - - - - - - - + android:gravity="center_vertical" + android:orientation="horizontal"> - + - + + - + - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/expandable_list_item_category.xml b/OsmAnd/res/layout/expandable_list_item_category.xml index 4343a05ea3..14c9dcbce2 100644 --- a/OsmAnd/res/layout/expandable_list_item_category.xml +++ b/OsmAnd/res/layout/expandable_list_item_category.xml @@ -15,67 +15,74 @@ - + android:background="?attr/expandable_list_item_background" > - - - - - + android:layout_marginStart="@dimen/list_content_padding"> - + - + - + + + + + + + + + diff --git a/OsmAnd/res/layout/fragment_search_list.xml b/OsmAnd/res/layout/fragment_search_list.xml index 89424bd151..bc0eea6acc 100644 --- a/OsmAnd/res/layout/fragment_search_list.xml +++ b/OsmAnd/res/layout/fragment_search_list.xml @@ -24,12 +24,12 @@ android:id="@+id/searchEditText" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginLeft="16dp" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginStart="@dimen/content_padding" android:background="@null" android:gravity="center_vertical" android:lines="1" - tools:text="Search request" - android:layout_marginStart="16dp" /> + tools:text="Search request" /> + android:layout_marginLeft="@dimen/dialog_content_margin" + android:layout_marginStart="@dimen/dialog_content_margin" + android:gravity="center_vertical"> + android:focusableInTouchMode="false" /> + android:orientation="vertical"> @@ -198,9 +200,9 @@ android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" - android:paddingRight="@dimen/list_content_padding" - android:gravity="center_vertical" - android:paddingEnd="@dimen/list_content_padding" /> + android:layout_marginRight="@dimen/list_content_padding" + android:layout_marginEnd="@dimen/list_content_padding" + android:gravity="center_vertical" /> + android:visibility="gone" /> diff --git a/OsmAnd/res/layout/list_menu_item_native.xml b/OsmAnd/res/layout/list_menu_item_native.xml index 40a5860f6f..1a484146da 100644 --- a/OsmAnd/res/layout/list_menu_item_native.xml +++ b/OsmAnd/res/layout/list_menu_item_native.xml @@ -13,43 +13,62 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="24dp" + android:layout_marginStart="24dp" android:gravity="center" android:visibility="gone" - tools:visibility="visible" - android:layout_marginStart="24dp" /> + tools:visibility="visible" /> - + android:layout_marginTop="@dimen/content_padding_small" + android:layout_marginBottom="@dimen/content_padding_small" + android:layout_weight="1"> - + - - + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/local_index_list_item.xml b/OsmAnd/res/layout/local_index_list_item.xml index ab39d8fb66..2f4b900dda 100644 --- a/OsmAnd/res/layout/local_index_list_item.xml +++ b/OsmAnd/res/layout/local_index_list_item.xml @@ -1,77 +1,84 @@ - - - - - + android:minHeight="@dimen/list_item_height"> + android:orientation="horizontal" + android:layout_marginLeft="@dimen/list_content_padding" + android:layout_marginStart="@dimen/list_content_padding"> - + android:layout_marginRight="@dimen/local_index_check_right_margin" + android:layout_marginEnd="@dimen/local_index_check_right_margin" + android:layout_marginTop="@dimen/favorites_icon_top_margin" + android:focusable="false" + android:visibility="gone"/> + + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:orientation="vertical"> + android:textColor="?android:textColorPrimary" + android:textSize="@dimen/default_list_text_size" + tools:text="Bangladesh"/> + + + + + + + + + - - - \ No newline at end of file + \ No newline at end of file diff --git a/OsmAnd/res/layout/main_menu_drawer_btn_configure_profile.xml b/OsmAnd/res/layout/main_menu_drawer_btn_configure_profile.xml index 1ab1910af6..c3efbab785 100644 --- a/OsmAnd/res/layout/main_menu_drawer_btn_configure_profile.xml +++ b/OsmAnd/res/layout/main_menu_drawer_btn_configure_profile.xml @@ -43,9 +43,9 @@ + android:paddingStart="@dimen/context_menu_padding_margin_default" + android:paddingEnd="@dimen/context_menu_padding_margin_default" + android:paddingTop="3dp"> + tools:src="@drawable/ic_action_opening_hour_16" /> + tools:visibility="visible"> + tools:visibility="visible"> + tools:visibility="visible"> + android:orientation="vertical"> + tools:textColor="?attr/contextMenuButtonColor" /> + tools:textColor="?attr/contextMenuButtonColor" /> diff --git a/OsmAnd/res/layout/order_poi_list_item.xml b/OsmAnd/res/layout/order_poi_list_item.xml index c3a56f7a2f..1fe14f3a31 100644 --- a/OsmAnd/res/layout/order_poi_list_item.xml +++ b/OsmAnd/res/layout/order_poi_list_item.xml @@ -51,7 +51,6 @@ android:paddingRight="@dimen/content_padding" android:paddingTop="@dimen/content_padding_half" android:paddingBottom="@dimen/content_padding_half" - android:singleLine="true" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" osmand:typeface="@string/font_roboto_regular" diff --git a/OsmAnd/res/layout/quick_action_add_dialog_item.xml b/OsmAnd/res/layout/quick_action_add_dialog_item.xml index 342f650b19..901a43ab45 100644 --- a/OsmAnd/res/layout/quick_action_add_dialog_item.xml +++ b/OsmAnd/res/layout/quick_action_add_dialog_item.xml @@ -8,10 +8,10 @@ android:minHeight="48dp" android:paddingRight="24dp" android:paddingLeft="24dp" - android:background="?attr/selectableItemBackground" - android:orientation="horizontal" android:paddingStart="24dp" - android:paddingEnd="24dp"> + android:paddingEnd="24dp" + android:background="?attr/selectableItemBackground" + android:orientation="horizontal"> + tools:text="Add marker" /> diff --git a/OsmAnd/res/layout/search_list_item.xml b/OsmAnd/res/layout/search_list_item.xml index f823df926c..14531a3a05 100644 --- a/OsmAnd/res/layout/search_list_item.xml +++ b/OsmAnd/res/layout/search_list_item.xml @@ -58,11 +58,11 @@ android:layout_weight="1" android:ellipsize="end" android:maxLines="2" - android:paddingRight="16dp" + android:layout_marginRight="16dp" + android:layout_marginEnd="16dp" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" - tools:text="Amsterdam" - android:paddingEnd="16dp" /> + tools:text="Amsterdam" /> + android:layout_marginStart="24dp"> + android:layout_marginTop="@dimen/content_padding_half" + android:layout_marginRight="@dimen/content_padding_half" + android:layout_marginEnd="@dimen/content_padding_half" + android:orientation="horizontal"> + android:orientation="horizontal"> + android:layout_marginRight="@dimen/content_padding_half" + android:layout_marginEnd="@dimen/content_padding_half" + android:textAppearance="@style/TextAppearance.ListItemTitle" /> + android:layout_marginLeft="@dimen/list_content_padding" + android:layout_marginStart="@dimen/list_content_padding"> = Build.VERSION_CODES.JELLY_BEAN_MR1) { + tv.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); + } else { + tv.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); + } + } + + public static ArrayList getChildrenViews(ViewGroup vg) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < vg.getChildCount(); i++) { + View child = vg.getChildAt(i); + result.add(child); + } + return result; + } + + public static void setPadding(View view, int start, int top, int end, int bottom) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + view.setPaddingRelative(start, top, end, bottom); + } else { + view.setPadding(start, top, end, bottom); + } + } + + public static void setMargins(ViewGroup.MarginLayoutParams layoutParams, int start, int top, int end, int bottom) { + layoutParams.setMargins(start, top, end, bottom); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + layoutParams.setMarginStart(start); + layoutParams.setMarginEnd(end); + } + } public static int getLayoutDirection(@NonNull Context ctx) { Locale currentLocale = ctx.getResources().getConfiguration().locale; diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index de7b4e7b07..01cf01da9d 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -213,7 +213,7 @@ public class ContextMenuAdapter { TextView title = convertView.findViewById(R.id.title); title.setText(item.getTitle()); - + if (layoutId == R.layout.main_menu_drawer_btn_switch_profile) { ImageView icon = convertView.findViewById(R.id.icon); icon.setImageDrawable(mIconsCache.getIcon(item.getIcon(), colorResId)); @@ -340,7 +340,6 @@ public class ContextMenuAdapter { drawable.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { tv.setCompoundDrawablesRelative(drawable, null, null, null); - UiUtilities.setupLayoutDirection(tv); } else { tv.setCompoundDrawables(drawable, null, null, null); } diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index fde5357591..25c668955f 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -15,6 +15,7 @@ import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; +import android.support.annotation.RequiresApi; import android.support.annotation.StringRes; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; @@ -38,6 +39,7 @@ import net.osmand.data.LatLon; import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.widgets.TextViewEx; +import java.util.ArrayList; import java.util.Locale; import gnu.trove.map.hash.TLongObjectHashMap; @@ -387,11 +389,36 @@ public class UiUtilities { image.setRotationY(rotation); } - public static void setupLayoutDirection(View layout) { - int direction = AndroidUtils.getLayoutDirection(layout.getContext()); + public static void setupLayoutDirection(View view) { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { + return; + } + int layoutDirection = AndroidUtils.getLayoutDirection(view.getContext()); + if (view instanceof ViewGroup) { + setupLayoutDirection(view, layoutDirection); + ArrayList childrenViews = AndroidUtils.getChildrenViews((ViewGroup) view); + if (childrenViews != null) { + for (View child : childrenViews) { + setupLayoutDirection(child); + } + } + } else if (view instanceof TextView) { + int textDirection = layoutDirection == + ViewCompat.LAYOUT_DIRECTION_RTL ? + View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR; + setupTextDirection((TextView) view, textDirection); + } + } + + private static void setupLayoutDirection(View layout, int direction) { ViewCompat.setLayoutDirection(layout, direction); } + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) + private static void setupTextDirection(TextView text, int direction) { + text.setTextDirection(direction); + } + public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) { int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light); int[][] states = new int[][] { diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java index c34b5af973..b8317c51c0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java @@ -44,6 +44,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.util.Algorithms; @@ -480,6 +481,7 @@ public class FavoritesSearchFragment extends DialogFragment { } } ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant); + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index abb2ce2a38..83f241e450 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -46,6 +46,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -173,8 +174,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen View searchView = inflater.inflate(R.layout.search_fav_list_item, null); searchView.setBackgroundResource(light ? R.color.list_background_color_light : R.color.list_background_color_dark); TextView title = (TextView) searchView.findViewById(R.id.title); - title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); - title.setHint(R.string.shared_string_search); + Drawable searchIcon = getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(title, searchIcon, null, null, null); searchView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -237,6 +238,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen listView.setSelection(selection); } } + UiUtilities.setupLayoutDirection(view); return view; } @@ -904,6 +906,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen } else { ch.setVisibility(View.GONE); } + UiUtilities.setupLayoutDirection(row); return row; } @@ -1007,6 +1010,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen row.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE); ch.setVisibility(View.GONE); } + UiUtilities.setupLayoutDirection(row); return row; } diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 68a5958d50..d8d1d5d8ca 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -110,6 +110,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } updateBottomButtons(); setupHeightAndBackground(mainView); + UiUtilities.setupLayoutDirection(mainView); return mainView; } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 5b3d0d0b83..2b0c44dcd4 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -344,6 +344,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo backPressed(); } }); + int layoutDirection = AndroidUtils.getLayoutDirection(mapActivity); + UiUtilities.rotateImageByLayoutDirection(back, layoutDirection); if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) { settingsButton.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index fd778cfb2a..0fc2d4bc36 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -46,6 +46,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.MapActivity; @@ -141,6 +142,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo final View downloadProgressLayout = findViewById(R.id.downloadProgressLayout); downloadProgressLayout.setVisibility(View.VISIBLE); updateDescriptionTextWithSize(this, downloadProgressLayout); + UiUtilities.setupLayoutDirection(downloadProgressLayout); int currentTab = DOWNLOAD_TAB_NUMBER; String tab = getIntent() == null || getIntent().getExtras() == null ? null : getIntent().getExtras().getString(TAB_TO_OPEN); if (tab != null) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java index 86ef9e6995..2c5547fc83 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java @@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.widget.TextView; +import net.osmand.AndroidUtils; import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivity; @@ -26,20 +27,20 @@ public class DownloadGroupViewHolder { } private Drawable getIconForGroup(DownloadResourceGroup group) { - Drawable iconLeft; + Drawable iconStart; if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_TTS) { - iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up); + iconStart = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up); } else if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.FONTS) { - iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language); + iconStart = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language); } else { UiUtilities cache = ctx.getMyApplication().getUIUtilities(); if (isParentWorld(group) || isParentWorld(group.getParentGroup())) { - iconLeft = cache.getThemedIcon(R.drawable.ic_world_globe_dark); + iconStart = cache.getThemedIcon(R.drawable.ic_world_globe_dark); } else { DownloadResourceGroup ggr = group .getSubGroupById(DownloadResourceGroup.DownloadResourceGroupType.REGION_MAPS.getDefaultId()); - iconLeft = cache.getThemedIcon(R.drawable.ic_map); + iconStart = cache.getThemedIcon(R.drawable.ic_map); if (ggr != null && ggr.getIndividualResources() != null) { IndexItem item = null; for (IndexItem ii : ggr.getIndividualResources()) { @@ -53,21 +54,21 @@ public class DownloadGroupViewHolder { } if (item != null) { if (item.isOutdated()) { - iconLeft = cache.getIcon(R.drawable.ic_map, R.color.color_distance); + iconStart = cache.getIcon(R.drawable.ic_map, R.color.color_distance); } else { - iconLeft = cache.getIcon(R.drawable.ic_map, R.color.color_ok); + iconStart = cache.getIcon(R.drawable.ic_map, R.color.color_ok); } } } } } - return iconLeft; + return iconStart; } public void bindItem(DownloadResourceGroup group) { - Drawable iconLeft = getIconForGroup(group); - textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); String name = group.getName(ctx); textView.setText(name); + Drawable iconStart = getIconForGroup(group); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(textView, iconStart, null, null, null); } } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index b46836ba0e..f30c0db279 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.view.MenuItemCompat; @@ -131,6 +132,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow listView.setOnChildClickListener(this); listAdapter = new DownloadResourceGroupAdapter(activity); listView.setAdapter(listAdapter); + UiUtilities.setupLayoutDirection(view); return view; } @@ -525,6 +527,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow public DownloadGroupViewHolder(DownloadActivity ctx, View v) { this.ctx = ctx; textView = (TextView) v.findViewById(R.id.title); + UiUtilities.setupLayoutDirection(textView); } private boolean isParentWorld(DownloadResourceGroup group) { @@ -533,20 +536,20 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow } private Drawable getIconForGroup(DownloadResourceGroup group) { - Drawable iconLeft; + Drawable iconStart; if (group.getType() == DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroupType.VOICE_TTS) { - iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up); + iconStart = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up); } else if (group.getType() == DownloadResourceGroupType.FONTS) { - iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language); + iconStart = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language); } else { UiUtilities cache = ctx.getMyApplication().getUIUtilities(); if (isParentWorld(group) || isParentWorld(group.getParentGroup())) { - iconLeft = cache.getThemedIcon(R.drawable.ic_world_globe_dark); + iconStart = cache.getThemedIcon(R.drawable.ic_world_globe_dark); } else { DownloadResourceGroup ggr = group .getSubGroupById(DownloadResourceGroupType.REGION_MAPS.getDefaultId()); - iconLeft = cache.getThemedIcon(R.drawable.ic_map); + iconStart = cache.getThemedIcon(R.drawable.ic_map); if (ggr != null && ggr.getIndividualResources() != null) { IndexItem item = null; for (IndexItem ii : ggr.getIndividualResources()) { @@ -560,22 +563,22 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow } if (item != null) { if (item.isOutdated()) { - iconLeft = cache.getIcon(R.drawable.ic_map, R.color.color_distance); + iconStart = cache.getIcon(R.drawable.ic_map, R.color.color_distance); } else { - iconLeft = cache.getIcon(R.drawable.ic_map, R.color.color_ok); + iconStart = cache.getIcon(R.drawable.ic_map, R.color.color_ok); } } } } } - return iconLeft; + return iconStart; } public void bindItem(DownloadResourceGroup group) { - Drawable iconLeft = getIconForGroup(group); - textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); String name = group.getName(ctx); textView.setText(name); + Drawable iconStart = getIconForGroup(group); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(textView, iconStart, null, null, null); } } @@ -675,6 +678,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow Resources.Theme theme = ctx.getTheme(); theme.resolveAttribute(R.attr.activity_background_color, typedValue, true); v.setBackgroundColor(typedValue.data); + UiUtilities.setupLayoutDirection(v); return v; } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 89ab85263c..1a53729f1f 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -21,6 +21,7 @@ import android.widget.Toast; import net.osmand.map.WorldRegion; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.activities.LocalIndexInfo; @@ -98,6 +99,7 @@ public class ItemViewHolder { textColorPrimary = typedValue.data; theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true); textColorSecondary = typedValue.data; + UiUtilities.setupLayoutDirection(view); } public void setShowRemoteDate(boolean showRemoteDate) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 9db441bc31..be7cefd79a 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -604,6 +604,7 @@ public class GpxUiHelper { builder.setTitle(R.string.show_gpx); } else { final View apprTitleView = View.inflate(new ContextThemeWrapper(activity, themeRes), R.layout.select_gpx_appearance_title, null); + UiUtilities.setupLayoutDirection(apprTitleView); final OsmandSettings.CommonPreference prefWidth = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR); @@ -619,7 +620,7 @@ public class GpxUiHelper { popup.setAnchorView(apprTitleView); popup.setContentWidth(AndroidUtils.dpToPx(activity, 200f)); popup.setModal(true); - popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP); + popup.setDropDownGravity(Gravity.END | Gravity.TOP); popup.setVerticalOffset(AndroidUtils.dpToPx(activity, -48f)); popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f)); final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(new ContextThemeWrapper(activity, themeRes), diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index dceab09fdd..1781ffda27 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -37,6 +37,7 @@ import android.widget.TextView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.LocalIndexHelper; import net.osmand.plus.activities.LocalIndexInfo; @@ -435,6 +436,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc } else { divider.setVisibility(View.VISIBLE); } + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java index 456b720968..5a6e69c185 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java @@ -31,6 +31,7 @@ import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.liveupdates.CountrySelectionFragment.CountryItem; @@ -207,6 +208,7 @@ public class ReportsFragment extends BaseOsmAndFragment implements CountrySelect inactiveColor = getColorFromAttr(R.attr.plugin_details_install_header_bg); textColorPrimary = getColorFromAttr(android.R.attr.textColorPrimary); textColorSecondary = getColorFromAttr(android.R.attr.textColorSecondary); + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 9d8bd58b2d..2358f29cd4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -627,8 +627,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } Drawable drawable = getIcon(iconResId, bottomButtonsColor); directionsButton.setTextColor(ContextCompat.getColor(mapActivity, bottomButtonsColor)); - directionsButton.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); - directionsButton.setCompoundDrawablePadding(dpToPx(8)); + 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() { @Override public void onClick(View view) { @@ -662,6 +663,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } }; + UiUtilities.setupLayoutDirection(view); created = true; return view; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 377df7a9dd..02d2ee28d4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -561,7 +561,7 @@ public class MenuBuilder { ImageView iconView = new ImageView(view.getContext()); LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f)); - llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f)); + AndroidUtils.setMargins(llIconParams, dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f)); llIconParams.gravity = Gravity.CENTER_VERTICAL; iconView.setLayoutParams(llIconParams); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); @@ -574,7 +574,7 @@ public class MenuBuilder { llText.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT); llTextViewParams.weight = 1f; - llTextViewParams.setMargins(0, 0, dpToPx(10f), 0); + AndroidUtils.setMargins(llTextViewParams, 0, 0, dpToPx(10f), 0); llTextViewParams.gravity = Gravity.CENTER_VERTICAL; llText.setLayoutParams(llTextViewParams); ll.addView(llText); @@ -583,7 +583,7 @@ public class MenuBuilder { if (!Algorithms.isEmpty(textPrefix)) { textPrefixView = new TextViewEx(view.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0); + AndroidUtils.setMargins(llTextParams, icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0); textPrefixView.setLayoutParams(llTextParams); textPrefixView.setTypeface(FontCache.getRobotoRegular(view.getContext())); textPrefixView.setTextSize(12); @@ -597,7 +597,8 @@ public class MenuBuilder { // Primary text TextViewEx textView = new TextViewEx(view.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(textPrefixView != null ? 2f : (secondaryText != null ? 10f : 8f)), 0, dpToPx(secondaryText != null ? 6f : 8f)); + AndroidUtils.setMargins(llTextParams, + icon != null ? 0 : dpToPx(16f), dpToPx(textPrefixView != null ? 2f : (secondaryText != null ? 10f : 8f)), 0, dpToPx(secondaryText != null ? 6f : 8f)); textView.setLayoutParams(llTextParams); textView.setTypeface(FontCache.getRobotoRegular(view.getContext())); textView.setTextSize(16); @@ -628,7 +629,7 @@ public class MenuBuilder { if (!TextUtils.isEmpty(secondaryText)) { TextViewEx textViewSecondary = new TextViewEx(view.getContext()); LinearLayout.LayoutParams llTextSecondaryParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextSecondaryParams.setMargins(icon != null ? 0 : dpToPx(16f), 0, 0, dpToPx(6f)); + AndroidUtils.setMargins(llTextSecondaryParams, icon != null ? 0 : dpToPx(16f), 0, 0, dpToPx(6f)); textViewSecondary.setLayoutParams(llTextSecondaryParams); textViewSecondary.setTypeface(FontCache.getRobotoRegular(view.getContext())); textViewSecondary.setTextSize(14); @@ -642,7 +643,7 @@ public class MenuBuilder { TextViewEx buttonTextView = new TextViewEx(view.getContext()); LinearLayout.LayoutParams buttonTextViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); buttonTextViewParams.gravity = Gravity.CENTER_VERTICAL; - buttonTextViewParams.setMargins(dpToPx(8), 0, dpToPx(8), 0); + AndroidUtils.setMargins(buttonTextViewParams, dpToPx(8), 0, dpToPx(8), 0); buttonTextView.setLayoutParams(buttonTextViewParams); buttonTextView.setTypeface(FontCache.getRobotoMedium(view.getContext())); buttonTextView.setAllCaps(true); @@ -661,7 +662,7 @@ public class MenuBuilder { ll.addView(llIconCollapse); LinearLayout.LayoutParams llIconCollapseParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f)); - llIconCollapseParams.setMargins(0, dpToPx(12f), dpToPx(24f), dpToPx(12f)); + AndroidUtils.setMargins(llIconCollapseParams, 0, dpToPx(12f), dpToPx(24f), dpToPx(12f)); llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL; iconViewCollapse.setLayoutParams(llIconCollapseParams); iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE); @@ -721,6 +722,7 @@ public class MenuBuilder { }); } + UiUtilities.setupLayoutDirection(baseView); ((LinearLayout) view).addView(baseView); rowBuilt(); @@ -826,7 +828,7 @@ public class MenuBuilder { Button buttonView = new Button(view.getContext()); LinearLayout.LayoutParams llBtnParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); buttonView.setLayoutParams(llBtnParams); - buttonView.setPadding(dpToPx(10f), 0, dpToPx(10f), 0); + AndroidUtils.setPadding(buttonView, dpToPx(10f), 0, dpToPx(10f), 0); buttonView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); //buttonView.setTextSize(view.getResources().getDimension(resolveAttribute(view.getContext(), R.dimen.default_desc_text_size))); buttonView.setTextColor(view.getResources().getColor(AndroidUtils.resolveAttribute(view.getContext(), R.attr.contextMenuButtonColor))); @@ -850,7 +852,7 @@ public class MenuBuilder { LinearLayout.LayoutParams llHorLineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1f)); llHorLineParams.gravity = Gravity.BOTTOM; if (!matchWidthDivider) { - llHorLineParams.setMargins(dpToPx(64f), 0, 0, 0); + AndroidUtils.setMargins(llHorLineParams, dpToPx(64f), 0, 0, 0); } horizontalLine.setLayoutParams(llHorLineParams); horizontalLine.setBackgroundColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_divider_light : R.color.ctx_menu_bottom_view_divider_dark)); @@ -914,12 +916,12 @@ public class MenuBuilder { baseView.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); baseView.setLayoutParams(llBaseViewParams); - baseView.setPadding(dpToPx(16), 0, dpToPx(16), dpToPx(12)); + AndroidUtils.setPadding(baseView, dpToPx(16), 0, dpToPx(16), dpToPx(12)); baseView.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground)); TextViewEx transportRect = new TextViewEx(view.getContext()); LinearLayout.LayoutParams trParams = new LinearLayout.LayoutParams(dpToPx(32), dpToPx(18)); - trParams.setMargins(0, dpToPx(16), 0, 0); + AndroidUtils.setMargins(trParams, 0, dpToPx(16), 0, 0); transportRect.setLayoutParams(trParams); transportRect.setGravity(Gravity.CENTER); transportRect.setAllCaps(true); @@ -942,7 +944,7 @@ public class MenuBuilder { LinearLayout infoView = new LinearLayout(view.getContext()); infoView.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams infoViewLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - infoViewLayoutParams.setMargins(dpToPx(16), dpToPx(12), dpToPx(16), 0); + AndroidUtils.setMargins(infoViewLayoutParams, dpToPx(16), dpToPx(12), dpToPx(16), 0); infoView.setLayoutParams(infoViewLayoutParams); baseView.addView(infoView); @@ -961,14 +963,14 @@ public class MenuBuilder { LinearLayout typeView = new LinearLayout(view.getContext()); typeView.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams typeViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - typeViewParams.setMargins(0, dpToPx(8), 0, 0); + AndroidUtils.setMargins(typeViewParams, 0, dpToPx(8), 0, 0); typeView.setGravity(Gravity.CENTER); typeView.setLayoutParams(typeViewParams); infoView.addView(typeView); ImageView typeImageView = new ImageView(view.getContext()); LinearLayout.LayoutParams typeImageParams = new LinearLayout.LayoutParams(dpToPx(16), dpToPx(16)); - typeImageParams.setMargins(dpToPx(4), 0, dpToPx(4), 0); + AndroidUtils.setMargins(typeImageParams, dpToPx(4), 0, dpToPx(4), 0); typeImageView.setLayoutParams(typeImageParams); int drawableResId = route.type == null ? R.drawable.ic_action_polygom_dark : route.type.getResourceId(); typeImageView.setImageDrawable(getRowIcon(drawableResId)); @@ -1036,7 +1038,7 @@ public class MenuBuilder { final TextViewEx textView = new TextViewEx(context); textView.setVisibility(collapsed ? View.GONE : View.VISIBLE); LinearLayout.LayoutParams llTextDescParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextDescParams.setMargins(dpToPx(64f), 0, dpToPx(40f), dpToPx(13f)); + AndroidUtils.setMargins(llTextDescParams, dpToPx(64f), 0, dpToPx(40f), dpToPx(13f)); textView.setLayoutParams(llTextDescParams); textView.setTypeface(FontCache.getRobotoRegular(context)); textView.setTextSize(16); @@ -1073,7 +1075,7 @@ public class MenuBuilder { view.setVisibility(collapsed ? View.GONE : View.VISIBLE); LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); if (needMargin) { - llParams.setMargins(dpToPx(64f), 0, dpToPx(12f), 0); + AndroidUtils.setMargins(llParams, dpToPx(64f), 0, dpToPx(12f), 0); } view.setLayoutParams(llParams); return view; @@ -1086,7 +1088,7 @@ public class MenuBuilder { protected TextViewEx buildButtonInCollapsableView(Context context, boolean selected, boolean showAll, boolean singleLine) { TextViewEx button = new TextViewEx(new ContextThemeWrapper(context, light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llWikiButtonParams.setMargins(0, 0, 0, dpToPx(8f)); + AndroidUtils.setMargins(llWikiButtonParams, 0, 0, 0, dpToPx(8f)); //button.setMinimumHeight(dpToPx(36f)); button.setLayoutParams(llWikiButtonParams); button.setTypeface(FontCache.getRobotoRegular(context)); @@ -1101,7 +1103,7 @@ public class MenuBuilder { button.setBackgroundResource(bg); button.setTextSize(14); int paddingSides = dpToPx(10f); - button.setPadding(paddingSides, paddingSides, paddingSides, paddingSides); + AndroidUtils.setPadding(button, paddingSides, paddingSides, paddingSides, paddingSides); if (!selected) { ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(context, !light, R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index eb3e9f7112..865d43edfc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -134,7 +134,7 @@ public class AmenityMenuBuilder extends MenuBuilder { ImageView iconView = new ImageView(view.getContext()); LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f)); - llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f)); + AndroidUtils.setMargins(llIconParams, dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f)); llIconParams.gravity = Gravity.CENTER_VERTICAL; iconView.setLayoutParams(llIconParams); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); @@ -151,7 +151,7 @@ public class AmenityMenuBuilder extends MenuBuilder { if (!Algorithms.isEmpty(textPrefix)) { textPrefixView = new TextView(view.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0); + AndroidUtils.setMargins(llTextParams, icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0); textPrefixView.setLayoutParams(llTextParams); textPrefixView.setTextSize(12); textPrefixView.setTextColor(app.getResources().getColor(R.color.ctx_menu_buttons_text_color)); @@ -163,7 +163,7 @@ public class AmenityMenuBuilder extends MenuBuilder { TextView textView = new TextView(view.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, + AndroidUtils.setMargins(llTextParams, icon == null ? dpToPx(16f) : 0, textPrefixView == null ? (collapsable ? dpToPx(13f) : dpToPx(8f)) : dpToPx(2f), 0, collapsable && textPrefixView == null ? dpToPx(13f) : dpToPx(8f)); textView.setLayoutParams(llTextParams); textView.setTextSize(16); @@ -199,7 +199,7 @@ public class AmenityMenuBuilder extends MenuBuilder { LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT); llTextViewParams.weight = 1f; - llTextViewParams.setMargins(0, 0, dpToPx(10f), 0); + AndroidUtils.setMargins(llTextViewParams, 0, 0, dpToPx(10f), 0); llTextViewParams.gravity = Gravity.CENTER_VERTICAL; llText.setLayoutParams(llTextViewParams); if (textPrefixView != null) { @@ -217,7 +217,7 @@ public class AmenityMenuBuilder extends MenuBuilder { ll.addView(llIconCollapse); LinearLayout.LayoutParams llIconCollapseParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f)); - llIconCollapseParams.setMargins(0, dpToPx(12f), dpToPx(24f), dpToPx(12f)); + AndroidUtils.setMargins(llIconCollapseParams, 0, dpToPx(12f), dpToPx(24f), dpToPx(12f)); llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL; iconViewCollapse.setLayoutParams(llIconCollapseParams); iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE); @@ -247,7 +247,7 @@ public class AmenityMenuBuilder extends MenuBuilder { if (isWiki) { TextViewEx button = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPx(36f)); - llWikiButtonParams.setMargins(dpToPx(16f), 0, 0, dpToPx(16f)); + AndroidUtils.setMargins(llWikiButtonParams, dpToPx(16f), 0, 0, dpToPx(16f)); button.setLayoutParams(llWikiButtonParams); button.setTypeface(FontCache.getRobotoMedium(app)); button.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java index fa79c17c72..d8d5d43e0c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java @@ -10,6 +10,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import net.osmand.AndroidUtils; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; @@ -64,7 +65,7 @@ public class GpxItemMenuBuilder extends MenuBuilder { private void buildIcon(LinearLayout ll, int gpxSmallIconMargin, int iconId) { ImageView icon = new ImageView(ll.getContext()); LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llIconParams.setMargins(0, 0, gpxSmallIconMargin, 0); + AndroidUtils.setMargins(llIconParams, 0, 0, gpxSmallIconMargin, 0); llIconParams.gravity = Gravity.CENTER_VERTICAL; icon.setLayoutParams(llIconParams); icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconId)); @@ -74,7 +75,7 @@ public class GpxItemMenuBuilder extends MenuBuilder { private void buildTextView(LinearLayout ll, int gpxSmallTextMargin, float gpxTextSize, int textColor, String text) { TextView textView = new TextView(ll.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(0, 0, gpxSmallTextMargin, 0); + AndroidUtils.setMargins(llTextParams, 0, 0, gpxSmallTextMargin, 0); textView.setLayoutParams(llTextParams); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, gpxTextSize); textView.setTextColor(textColor); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 0caa56c355..b27bb51596 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -213,6 +213,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm } } }); + UiUtilities.setupLayoutDirection(mainView); return mainView; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java index 32f80ffc7f..065da138af 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java @@ -15,6 +15,7 @@ import android.widget.ImageView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -182,6 +183,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } } }); + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 3d487e3831..3cec9eb93e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -63,6 +63,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter newCards, @NonNull List prevCards) { @@ -953,7 +954,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } }; ll.getViewTreeObserver().addOnGlobalLayoutListener(globalListener); - + UiUtilities.setupLayoutDirection(ll); } private void updateOptionsButtons() { @@ -1007,6 +1008,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } else { // LTR optionsContainer.setPadding(optionsContainer.getPaddingLeft(), optionsContainer.getPaddingTop(), endPadding, optionsContainer.getPaddingBottom()); } + UiUtilities.setupLayoutDirection(optionsContainer); } private void updateControlButtons(MapActivity mapActivity, View mainView) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java index 9463a42981..ebd892fe9e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java @@ -350,6 +350,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os parseLocation(); updateControlsVisibility(); + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 495b341b1e..25b3415aa2 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -71,6 +71,7 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; @@ -676,6 +677,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } }); updateFab(); + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index 016cae3dfd..92edd78975 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -23,6 +23,7 @@ import net.osmand.osm.AbstractPoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; @@ -438,12 +439,13 @@ public class QuickSearchListAdapter extends ArrayAdapter { divider.setLayoutParams(p); } else { LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp1); - p.setMargins(dp56, 0, 0 ,0); + AndroidUtils.setMargins(p, dp56, 0, 0, 0); divider.setLayoutParams(p); } } } ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant); + UiUtilities.setupLayoutDirection(view); return view; } diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index aa478a2705..4f7e75260a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -413,6 +413,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl imageView.setEnabled(enabled); } } + UiUtilities.setupLayoutDirection(holder.itemView); } @SuppressLint("RestrictedApi") From 5447289720f468cd218c01589e268d3ef0384e95 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 4 Mar 2020 10:15:33 +0200 Subject: [PATCH 13/30] Small refactoring Delete useless methods --- OsmAnd/src/net/osmand/AndroidUtils.java | 28 ++++++++++++--------- OsmAnd/src/net/osmand/plus/UiUtilities.java | 21 +++++----------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 94f85dbc39..0ee9a620f1 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -647,24 +647,15 @@ public class AndroidUtils { } public static void setCompoundDrawablesWithIntrinsicBounds(@NonNull TextView tv, Drawable start, Drawable top, Drawable end, Drawable bottom){ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (isSupportRTL()) { tv.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); } else { tv.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); } } - public static ArrayList getChildrenViews(ViewGroup vg) { - ArrayList result = new ArrayList<>(); - for (int i = 0; i < vg.getChildCount(); i++) { - View child = vg.getChildAt(i); - result.add(child); - } - return result; - } - public static void setPadding(View view, int start, int top, int end, int bottom) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (isSupportRTL()) { view.setPaddingRelative(start, top, end, bottom); } else { view.setPadding(start, top, end, bottom); @@ -673,7 +664,7 @@ public class AndroidUtils { public static void setMargins(ViewGroup.MarginLayoutParams layoutParams, int start, int top, int end, int bottom) { layoutParams.setMargins(start, top, end, bottom); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (isSupportRTL()) { layoutParams.setMarginStart(start); layoutParams.setMarginEnd(end); } @@ -684,6 +675,10 @@ public class AndroidUtils { return TextUtilsCompat.getLayoutDirectionFromLocale(currentLocale); } + public static boolean isSupportRTL() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; + } + public static float getFreeSpaceGb(File dir) { if (dir.canRead()) { StatFs fs = new StatFs(dir.getAbsolutePath()); @@ -692,6 +687,15 @@ public class AndroidUtils { return -1; } + public static ArrayList getChildrenViews(ViewGroup vg) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < vg.getChildCount(); i++) { + View child = vg.getChildAt(i); + result.add(child); + } + return result; + } + public static float getTotalSpaceGb(File dir) { if (dir.canRead()) { return (float) (dir.getTotalSpace()) / (1 << 30); diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 25c668955f..9d4fbd07ad 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -390,12 +390,13 @@ public class UiUtilities { } public static void setupLayoutDirection(View view) { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (view == null || !AndroidUtils.isSupportRTL()) { return; } - int layoutDirection = AndroidUtils.getLayoutDirection(view.getContext()); + Context ctx = view.getContext(); + int layoutDirection = AndroidUtils.getLayoutDirection(ctx); if (view instanceof ViewGroup) { - setupLayoutDirection(view, layoutDirection); + view.setLayoutDirection(layoutDirection); ArrayList childrenViews = AndroidUtils.getChildrenViews((ViewGroup) view); if (childrenViews != null) { for (View child : childrenViews) { @@ -403,22 +404,12 @@ public class UiUtilities { } } } else if (view instanceof TextView) { - int textDirection = layoutDirection == - ViewCompat.LAYOUT_DIRECTION_RTL ? + int textDirection = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL ? View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR; - setupTextDirection((TextView) view, textDirection); + view.setTextDirection(textDirection); } } - private static void setupLayoutDirection(View layout, int direction) { - ViewCompat.setLayoutDirection(layout, direction); - } - - @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) - private static void setupTextDirection(TextView text, int direction) { - text.setTextDirection(direction); - } - public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) { int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light); int[][] states = new int[][] { From 1f187e218af9bbfb920a346d8e1457629df6a185 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 4 Mar 2020 10:18:24 +0200 Subject: [PATCH 14/30] Small fixes --- OsmAnd/src/net/osmand/AndroidUtils.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 0ee9a620f1..1a7dfcf05a 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -679,14 +679,6 @@ public class AndroidUtils { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; } - public static float getFreeSpaceGb(File dir) { - if (dir.canRead()) { - StatFs fs = new StatFs(dir.getAbsolutePath()); - return (float) (fs.getBlockSize()) * fs.getAvailableBlocks() / (1 << 30); - } - return -1; - } - public static ArrayList getChildrenViews(ViewGroup vg) { ArrayList result = new ArrayList<>(); for (int i = 0; i < vg.getChildCount(); i++) { @@ -696,6 +688,14 @@ public class AndroidUtils { return result; } + public static float getFreeSpaceGb(File dir) { + if (dir.canRead()) { + StatFs fs = new StatFs(dir.getAbsolutePath()); + return (float) (fs.getBlockSize()) * fs.getAvailableBlocks() / (1 << 30); + } + return -1; + } + public static float getTotalSpaceGb(File dir) { if (dir.canRead()) { return (float) (dir.getTotalSpace()) / (1 << 30); From 83be8db17a0c71dbd3807faf4098906d7d977981 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 4 Mar 2020 13:19:54 +0200 Subject: [PATCH 15/30] Delete 'setLayoutDirection' method. Use style attribute instead --- OsmAnd/res/values/styles.xml | 2 ++ .../net/osmand/plus/ContextMenuAdapter.java | 1 - .../osmand/plus/DialogListItemAdapter.java | 1 - OsmAnd/src/net/osmand/plus/UiUtilities.java | 21 ------------------- .../activities/FavoritesSearchFragment.java | 2 -- .../activities/FavoritesTreeFragment.java | 4 ---- .../base/MenuBottomSheetDialogFragment.java | 1 - .../plus/download/DownloadActivity.java | 2 -- .../ui/DownloadResourceGroupFragment.java | 4 ---- .../plus/download/ui/ItemViewHolder.java | 2 -- .../net/osmand/plus/helpers/GpxUiHelper.java | 1 - .../plus/liveupdates/LiveUpdatesFragment.java | 2 -- .../plus/liveupdates/ReportsFragment.java | 2 -- .../MapContextMenuFragment.java | 1 - .../plus/mapcontextmenu/MenuBuilder.java | 1 - .../mapmarkers/MapMarkersDialogFragment.java | 2 -- .../OptionsBottomSheetDialogFragment.java | 2 -- .../adapters/MapMarkersActiveAdapter.java | 2 -- .../adapters/MapMarkersGroupsAdapter.java | 1 - .../adapters/MapMarkersHistoryAdapter.java | 2 -- .../adapters/MapMarkersListAdapter.java | 1 - .../plus/myplaces/AvailableGPXFragment.java | 3 --- .../plus/poi/RearrangePoiFiltersFragment.java | 1 - .../plus/profiles/EditProfilesFragment.java | 1 - .../quickaction/QuickActionListFragment.java | 2 -- .../MapRouteInfoMenu.java | 3 --- .../QuickSearchCoordinatesFragment.java | 1 - .../search/QuickSearchDialogFragment.java | 2 -- .../plus/search/QuickSearchListAdapter.java | 2 -- .../plus/settings/BaseSettingsFragment.java | 1 - 30 files changed, 2 insertions(+), 71 deletions(-) diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 4e221e33f8..c1e7e91369 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -102,6 +102,7 @@