From ef9b018011810681e1e533d3fa6281cdfbe4152c Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 23 Nov 2020 22:57:55 +0200 Subject: [PATCH] Refactoring --- OsmAnd/res/layout/dialog_button_with_icon.xml | 43 +++++++++++++++++++ OsmAnd/res/values/sizes.xml | 1 + .../plus/mapcontextmenu/MenuBuilder.java | 33 +++++--------- .../openplacereviews/OPRWebviewActivity.java | 2 +- 4 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 OsmAnd/res/layout/dialog_button_with_icon.xml diff --git a/OsmAnd/res/layout/dialog_button_with_icon.xml b/OsmAnd/res/layout/dialog_button_with_icon.xml new file mode 100644 index 0000000000..264f884495 --- /dev/null +++ b/OsmAnd/res/layout/dialog_button_with_icon.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 64ab1cc330..c1addc1349 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -249,6 +249,7 @@ 16dp 12dp 8dp + 6dp 8dp 13dp 5dp diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 958af6a0be..b6959beca0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -22,6 +22,7 @@ import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -313,34 +314,22 @@ public class MenuBuilder { private View createAddPhotoButton(Context ctx) { boolean nightMode = getApplication().getDaynightHelper().isNightModeForMapControls(); - View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_dialog_button, null); - LinearLayout buttonLayout = new LinearLayout(ctx); - view.setOnClickListener(new OnClickListener() { + View view = UiUtilities.getInflater(ctx, nightMode).inflate(R.layout.dialog_button_with_icon, null); + int dp6 = ctx.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_title_padding_bottom); + View button = view.findViewById(R.id.button); + UiUtilities.setupDialogButton(nightMode, button, UiUtilities.DialogButtonType.STROKED, + ctx.getString(R.string.shared_string_add_photo), R.drawable.ic_sample); + TextView textView = view.findViewById(R.id.button_text); + textView.setCompoundDrawablePadding(dp6); + button.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { AddPhotosBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); } }); - int dp6 = ctx.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_title_padding_bottom); - int dp8 = ctx.getResources().getDimensionPixelSize(R.dimen.content_padding_half); - int dp12 = ctx.getResources().getDimensionPixelSize(R.dimen.content_padding_small); - int dp16 = ctx.getResources().getDimensionPixelSize(R.dimen.content_padding); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - params.setMargins(dp16, 0, dp16, dp12); - buttonLayout.setLayoutParams(params); - LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, - ctx.getResources().getDimensionPixelSize(R.dimen.dialog_button_height)); - view.setLayoutParams(buttonParams); - buttonLayout.addView(view); - UiUtilities.setupDialogButton(nightMode, buttonLayout, UiUtilities.DialogButtonType.STROKED, - ctx.getString(R.string.shared_string_add_photo), R.drawable.ic_sample); - TextView textView = view.findViewById(R.id.button_text); - textView.setPadding(dp8, 0, dp16, 0); - textView.setCompoundDrawablePadding(dp6); //TODO This feature is under development - buttonLayout.setVisibility(View.VISIBLE); - return buttonLayout; + view.setVisibility(View.VISIBLE); + return view; } private void buildCoordinatesRow(View view) { diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java index 6f97080ffc..293c3b566c 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OPRWebviewActivity.java @@ -58,7 +58,7 @@ public class OPRWebviewActivity extends OsmandActionBarActivity { String title = bundle.getString(KEY_TITLE, ""); titleView.setText(title); } - ColorDrawable colorDrawable = new ColorDrawable(AndroidUtils.getColorFromAttr(app, R.attr.bg_color)); + ColorDrawable colorDrawable = new ColorDrawable(AndroidUtils.getColorFromAttr(this, R.attr.bg_color)); toolbar.setBackgroundDrawable(colorDrawable); final Drawable upArrow = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(this)); upArrow.setColorFilter(ContextCompat.getColor(this, R.color.color_favorite_gray), PorterDuff.Mode.SRC_ATOP);