From 27c204643d80df8f316f1c60313ce6b038a457c1 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 28 Sep 2017 19:02:56 +0300 Subject: [PATCH] Add option menu and keyboard styling --- .../fragment_coordinate_input_dialog.xml | 48 ++++- ...r_coordinate_input_bottom_sheet_dialog.xml | 192 +---------------- ...nate_input_options_bottom_sheet_helper.xml | 120 +++++++++++ .../res/layout/marker_coordinate_formats.xml | 199 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 2 + ...rdinateInputBottomSheetDialogFragment.java | 103 ++++++++- .../CoordinateInputDialogFragment.java | 66 ++++-- 7 files changed, 511 insertions(+), 219 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_helper.xml create mode 100644 OsmAnd/res/layout/marker_coordinate_formats.xml diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index f993663744..bd3c04fbbc 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -144,13 +144,14 @@ - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_marker_coordinate_input_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_coordinate_input_bottom_sheet_dialog.xml index f294958fc2..e970fe8da9 100644 --- a/OsmAnd/res/layout/fragment_marker_coordinate_input_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_coordinate_input_bottom_sheet_dialog.xml @@ -42,197 +42,7 @@ android:textColor="?android:textColorSecondary" android:textSize="@dimen/default_desc_text_size"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_helper.xml b/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_helper.xml new file mode 100644 index 0000000000..cd2b841a19 --- /dev/null +++ b/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_helper.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/marker_coordinate_formats.xml b/OsmAnd/res/layout/marker_coordinate_formats.xml new file mode 100644 index 0000000000..e03dad94c8 --- /dev/null +++ b/OsmAnd/res/layout/marker_coordinate_formats.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a788363c22..0c0198ec86 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Coordinates format + Use system keyboard Choose coordinate format before start. You can always change it by tapping Options. Fast Coordinates input Finish diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 08bbba07f8..f2b78c94f8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -1,11 +1,13 @@ package net.osmand.plus.mapmarkers; +import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v7.widget.SwitchCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -13,7 +15,9 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.RadioButton; import android.widget.TextView; import net.osmand.AndroidUtils; @@ -31,7 +35,9 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF private View mainView; private boolean night; private int coordinateFormat = -1; + private boolean useOsmandKeyboard = true; private CoordinateInputFormatChangeListener listener; + private boolean shouldClose; public void setListener(CoordinateInputFormatChangeListener listener) { this.listener = listener; @@ -42,7 +48,10 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF super.onCreate(savedInstanceState); Bundle args = getArguments(); if (args != null) { - coordinateFormat = getArguments().getInt(CoordinateInputDialogFragment.COORDINATE_FORMAT, -1); + coordinateFormat = args.getInt(CoordinateInputDialogFragment.COORDINATE_FORMAT); + useOsmandKeyboard = args.getBoolean(CoordinateInputDialogFragment.USE_OSMAND_KEYBOARD); + } else { + shouldClose = true; } } @@ -54,7 +63,8 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF night = !mapActivity.getMyApplication().getSettings().isLightContent(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_coordinate_input_bottom_sheet_dialog, container); + mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), coordinateFormat == -1 ? + R.layout.fragment_marker_coordinate_input_bottom_sheet_dialog : R.layout.fragment_marker_coordinate_input_options_bottom_sheet_helper, container); if (portrait) { AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } @@ -68,6 +78,7 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF if (coordinateFormat == PointDescription.FORMAT_DEGREES) { degreesIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); degreesText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue)); + ((RadioButton) mainView.findViewById(R.id.degrees_radio_button)).setChecked(true); } else { degreesIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude)); } @@ -78,6 +89,7 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF if (coordinateFormat == PointDescription.FORMAT_MINUTES) { minutesIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); minutesText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue)); + ((RadioButton) mainView.findViewById(R.id.minutes_radio_button)).setChecked(true); } else { minutesIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude)); } @@ -88,6 +100,7 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF if (coordinateFormat == PointDescription.FORMAT_SECONDS) { secondsIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); secondsText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue)); + ((RadioButton) mainView.findViewById(R.id.seconds_radio_button)).setChecked(true); } else { secondsIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude)); } @@ -98,6 +111,7 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF if (coordinateFormat == PointDescription.UTM_FORMAT) { utmIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); utmText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue)); + ((RadioButton) mainView.findViewById(R.id.utm_radio_button)).setChecked(true); } else { utmIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude)); } @@ -108,38 +122,58 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF if (coordinateFormat == PointDescription.OLC_FORMAT) { olcIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); olcText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue)); + ((RadioButton) mainView.findViewById(R.id.olc_radio_button)).setChecked(true); } else { olcIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude)); } olcText.setText(PointDescription.formatToHumanString(getContext(), PointDescription.OLC_FORMAT)); + if (coordinateFormat != -1) { + ((CompoundButton) mainView.findViewById(R.id.use_system_keyboard_switch)).setChecked(!useOsmandKeyboard); + ((ImageView) mainView.findViewById(R.id.use_system_keyboard_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_keyboard)); + mainView.findViewById(R.id.use_system_keyboard_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + useOsmandKeyboard = !useOsmandKeyboard; + ((CompoundButton) mainView.findViewById(R.id.use_system_keyboard_switch)).setChecked(!useOsmandKeyboard); + if (listener != null) { + listener.onKeyboardChanged(useOsmandKeyboard); + } + } + }); + highlightSelectedItem(true); + } + View.OnClickListener formatChangeListener = new View.OnClickListener() { @Override public void onClick(View view) { - int format; + highlightSelectedItem(false); switch (view.getId()) { case R.id.degrees_row: - format = PointDescription.FORMAT_DEGREES; + coordinateFormat = PointDescription.FORMAT_DEGREES; break; case R.id.minutes_row: - format = PointDescription.FORMAT_MINUTES; + coordinateFormat = PointDescription.FORMAT_MINUTES; break; case R.id.seconds_row: - format = PointDescription.FORMAT_SECONDS; + coordinateFormat = PointDescription.FORMAT_SECONDS; break; case R.id.utm_row: - format = PointDescription.UTM_FORMAT; + coordinateFormat = PointDescription.UTM_FORMAT; break; case R.id.olc_row: - format = PointDescription.OLC_FORMAT; + coordinateFormat = PointDescription.OLC_FORMAT; break; default: throw new IllegalArgumentException("Unsupported format"); } + highlightSelectedItem(true); if (listener != null) { - listener.onCoordinateFormatChanged(format); + listener.onCoordinateFormatChanged(coordinateFormat); + } + if (shouldClose) { + dismiss(); } - dismiss(); } }; @@ -153,6 +187,9 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF @Override public void onClick(View view) { dismiss(); + if (shouldClose && listener != null) { + listener.onCancel(); + } } }); @@ -207,12 +244,58 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF } } + @Override + public void onCancel(DialogInterface dialog) { + super.onCancel(dialog); + if (shouldClose && listener != null) { + listener.onCancel(); + } + } + @Override protected Drawable getContentIcon(@DrawableRes int id) { return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); } + private void highlightSelectedItem(boolean check) { + int iconColor = check ? R.color.dashboard_blue : night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color; + int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black); + switch (coordinateFormat) { + case PointDescription.FORMAT_DEGREES: + ((TextView) mainView.findViewById(R.id.degrees_text)).setTextColor(textColor); + ((ImageView) mainView.findViewById(R.id.degrees_icon)).setImageDrawable((getIcon(R.drawable.ic_action_coordinates_latitude, iconColor))); + ((RadioButton) mainView.findViewById(R.id.degrees_radio_button)).setChecked(check); + break; + case PointDescription.FORMAT_MINUTES: + ((TextView) mainView.findViewById(R.id.minutes_text)).setTextColor(textColor); + ((ImageView) mainView.findViewById(R.id.minutes_icon)).setImageDrawable((getIcon(R.drawable.ic_action_coordinates_latitude, iconColor))); + ((RadioButton) mainView.findViewById(R.id.minutes_radio_button)).setChecked(check); + break; + case PointDescription.FORMAT_SECONDS: + ((TextView) mainView.findViewById(R.id.seconds_text)).setTextColor(textColor); + ((ImageView) mainView.findViewById(R.id.seconds_icon)).setImageDrawable((getIcon(R.drawable.ic_action_coordinates_latitude, iconColor))); + ((RadioButton) mainView.findViewById(R.id.seconds_radio_button)).setChecked(check); + break; + case PointDescription.UTM_FORMAT: + ((TextView) mainView.findViewById(R.id.utm_text)).setTextColor(textColor); + ((ImageView) mainView.findViewById(R.id.utm_icon)).setImageDrawable((getIcon(R.drawable.ic_action_coordinates_latitude, iconColor))); + ((RadioButton) mainView.findViewById(R.id.utm_radio_button)).setChecked(check); + break; + case PointDescription.OLC_FORMAT: + ((TextView) mainView.findViewById(R.id.olc_text)).setTextColor(textColor); + ((ImageView) mainView.findViewById(R.id.olc_icon)).setImageDrawable((getIcon(R.drawable.ic_action_coordinates_latitude, iconColor))); + ((RadioButton) mainView.findViewById(R.id.olc_radio_button)).setChecked(check); + break; + } + } + interface CoordinateInputFormatChangeListener { + void onCoordinateFormatChanged(int format); + + void onKeyboardChanged(boolean useOsmandKeyboard); + + void onCancel(); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index af036556c0..1da2a01d58 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -18,8 +18,11 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.GridView; +import android.widget.ImageView; +import net.osmand.AndroidUtils; import net.osmand.data.PointDescription; +import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandTextFieldBoxes; @@ -37,6 +40,7 @@ public class CoordinateInputDialogFragment extends DialogFragment { public static final String TAG = "CoordinateInputDialogFragment"; public static final String COORDINATE_FORMAT = "coordinate_format"; + public static final String USE_OSMAND_KEYBOARD = "use_osmand_keyboard"; private static final int DELETE_BUTTON_POSITION = 9; private static final int CLEAR_BUTTON_POSITION = 11; @@ -47,10 +51,10 @@ public class CoordinateInputDialogFragment extends DialogFragment { private boolean lightTheme; private EditText focusedEditText; private boolean useOsmandKeyboard = true; + private int coordinateFormat = -1; private List textFieldBoxes; private ExtendedEditText nameEditText; private List extendedLatLonEditTexts; - private int coordinateFormat = -1; @Override public void onCreate(Bundle savedInstanceState) { @@ -60,11 +64,9 @@ public class CoordinateInputDialogFragment extends DialogFragment { int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); - if (coordinateFormat == -1) { - CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); - fragment.setListener(createCoordinateInputFormatChangeListener()); - fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG); - } + CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); + fragment.setListener(createCoordinateInputFormatChangeListener()); + fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG); } @Nullable @@ -72,12 +74,11 @@ public class CoordinateInputDialogFragment extends DialogFragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container); final MapActivity mapActivity = getMapActivity(); + final IconsCache ic = getMyApplication().getIconsCache(); - if (coordinateFormat == -1) { - Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG); - if (coordinateInputBottomSheetDialogFragment != null) { - ((CoordinateInputBottomSheetDialogFragment) coordinateInputBottomSheetDialogFragment).setListener(createCoordinateInputFormatChangeListener()); - } + Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG); + if (coordinateInputBottomSheetDialogFragment != null) { + ((CoordinateInputBottomSheetDialogFragment) coordinateInputBottomSheetDialogFragment).setListener(createCoordinateInputFormatChangeListener()); } Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.coordinate_input_toolbar); @@ -96,6 +97,7 @@ public class CoordinateInputDialogFragment extends DialogFragment { CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); Bundle args = new Bundle(); args.putInt(COORDINATE_FORMAT, coordinateFormat); + args.putBoolean(USE_OSMAND_KEYBOARD, useOsmandKeyboard); fragment.setArguments(args); fragment.setListener(createCoordinateInputFormatChangeListener()); fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG); @@ -208,8 +210,11 @@ public class CoordinateInputDialogFragment extends DialogFragment { longitudeEditText.addTextChangedListener(textWatcher); nameEditText.addTextChangedListener(textWatcher); - changeKeyboardInBoxes(useOsmandKeyboard); - changeKeyboardInEditTexts(useOsmandKeyboard); + changeKeyboardInBoxes(); + changeKeyboardInEditTexts(); + + View keyboardLayout = mainView.findViewById(R.id.keyboard_layout); + AndroidUtils.setBackground(mapActivity, keyboardLayout, !lightTheme, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); String[] keyboardItems = new String[] { "1", "2", "3", "4", "5", "6", @@ -240,6 +245,25 @@ public class CoordinateInputDialogFragment extends DialogFragment { } }); + final ImageView showHideKeyBoardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon); + final View keyboardDivider = mainView.findViewById(R.id.keyboard_divider); + showHideKeyBoardIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_down)); + showHideKeyBoardIcon.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int keyboardVisibility = keyboardGrid.getVisibility(); + if (keyboardVisibility == View.VISIBLE) { + keyboardGrid.setVisibility(View.GONE); + keyboardDivider.setVisibility(View.GONE); + showHideKeyBoardIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_up)); + } else { + keyboardGrid.setVisibility(View.VISIBLE); + keyboardDivider.setVisibility(View.VISIBLE); + showHideKeyBoardIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_down)); + } + } + }); + return mainView; } @@ -259,6 +283,18 @@ public class CoordinateInputDialogFragment extends DialogFragment { coordinateFormat = format; changeEditTextLengths(); } + + @Override + public void onKeyboardChanged(boolean useOsmandKeyboard) { + CoordinateInputDialogFragment.this.useOsmandKeyboard = useOsmandKeyboard; + changeKeyboardInBoxes(); + changeKeyboardInEditTexts(); + } + + @Override + public void onCancel() { + dismiss(); + } }; } @@ -277,13 +313,13 @@ public class CoordinateInputDialogFragment extends DialogFragment { } } - public void changeKeyboardInBoxes(boolean useOsmandKeyboard) { + public void changeKeyboardInBoxes() { for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) { textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard); } } - public void changeKeyboardInEditTexts(boolean useOsmandKeyboard) { + public void changeKeyboardInEditTexts() { for (ExtendedEditText extendedEditText : extendedLatLonEditTexts) { extendedEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT); }