From 4d69a5c014879e21e276b615f3d5f9ffad8833f2 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 12 Feb 2018 19:19:25 +0200 Subject: [PATCH 01/50] Create new input area layout for coordinate input --- .../res/layout/coordinate_input_data_area.xml | 310 ++++++++++++++++++ .../fragment_coordinate_input_dialog.xml | 165 +++------- OsmAnd/res/values-large/sizes.xml | 2 + OsmAnd/res/values/colors.xml | 2 +- OsmAnd/res/values/sizes.xml | 2 + OsmAnd/res/values/strings.xml | 5 + .../CoordinateInputDialogFragment.java | 200 ++++++----- 7 files changed, 486 insertions(+), 200 deletions(-) create mode 100644 OsmAnd/res/layout/coordinate_input_data_area.xml diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml new file mode 100644 index 0000000000..0345b3a537 --- /dev/null +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -0,0 +1,310 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index 0dcd5bd3c4..d7ec3cf751 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -2,32 +2,32 @@ + android:layout_height="match_parent"> + android:layout_height="match_parent" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:orientation="vertical" + tools:background="@color/route_info_bg_dark"> + osmand:contentInsetStart="4dp"> @@ -37,37 +37,38 @@ style="@style/Widget.AppCompat.ActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@drawable/ic_arrow_back" + android:layout_marginEnd="16dp" android:layout_marginRight="16dp" - android:layout_marginEnd="16dp"/> + tools:src="@drawable/ic_arrow_back"/> + tools:textColor="@color/color_white"/> + osmand:typeface="@string/font_roboto_regular"/> @@ -78,117 +79,35 @@ android:focusable="true" android:focusableInTouchMode="true"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - + + android:layout_height="match_parent" + android:clipToPadding="false" + android:paddingBottom="72dp" + android:paddingTop="16dp"/> + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:orientation="vertical"> + android:verticalSpacing="1dp"/> + android:layout_height="56dp" + android:orientation="horizontal"> + android:textSize="@dimen/default_list_text_size"/> diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml index a6b15d4f9c..05499f35b5 100644 --- a/OsmAnd/res/values-large/sizes.xml +++ b/OsmAnd/res/values-large/sizes.xml @@ -187,4 +187,6 @@ 60dp 450dp + + 54dp \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 2ac3eedf22..ab940b6a77 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -300,12 +300,12 @@ #e6e6e6 #2a2f33 - #4257c9 #1b224d #536dfe #2d3980 #9fadfc #ed5421 + #c0c0c0 #78cc5c #fac403 diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index f5395ce360..16d3e196c9 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -260,4 +260,6 @@ 40dp 300dp + + 36dp \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ad57d5f7b0..a77d14986a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,11 @@ 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 --> + E + W + S + N + Optional point name Make as Start Point Current Adds the last stop along the route diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index bdb13ffa46..7564091485 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -8,6 +8,9 @@ import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; @@ -37,21 +40,21 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.GridView; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; 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.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; @@ -88,23 +91,26 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private static final String LONGITUDE_LABEL = "longitude"; private static final String NAME_LABEL = "name"; - private OnMapMarkersSavedListener listener; private List mapMarkers = new ArrayList<>(); + private MapMarkersHelper mapMarkersHelper; + private OnMapMarkersSavedListener listener; + + private View mainView; + private List editTexts = new ArrayList<>(); private CoordinateInputAdapter adapter; + private boolean lightTheme; + private boolean orientationPortrait; + private boolean useOsmandKeyboard = true; private boolean rightHand = true; private boolean goToNextField = true; private int accuracy = 4; - private List textFieldBoxes; - private View mainView; - private IconsCache iconsCache; + private Location location; private Float heading; private boolean locationUpdateStarted; private boolean compassUpdateAllowed = true; - private MapMarkersHelper mapMarkersHelper; - private boolean orientationPortrait; public void setListener(OnMapMarkersSavedListener listener) { this.listener = listener; @@ -113,16 +119,15 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - OsmandApplication app = getMyApplication(); - lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; - int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; - setStyle(STYLE_NO_FRAME, themeId); + lightTheme = getMyApplication().getSettings().isLightContent(); + setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - Dialog dialog = new Dialog(getContext(), getTheme()) { + Context ctx = getContext(); + Dialog dialog = new Dialog(ctx, getTheme()) { @Override public void onBackPressed() { saveMarkers(); @@ -132,10 +137,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm Window window = dialog.getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setStatusBarColor(ContextCompat.getColor(getContext(), lightTheme ? R.color.coordinate_input_status_bar_color_light : R.color.coordinate_input_status_bar_color_dark)); + if (!lightTheme && Build.VERSION.SDK_INT >= 21) { + window.setStatusBarColor(ContextCompat.getColor(ctx, R.color.coordinate_input_status_bar_color_dark)); } } return dialog; @@ -144,18 +147,20 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container); final MapActivity mapActivity = getMapActivity(); - iconsCache = getMyApplication().getIconsCache(); mapMarkersHelper = getMyApplication().getMapMarkersHelper(); orientationPortrait = AndroidUiHelper.isOrientationPortrait(mapActivity); - Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG); - if (coordinateInputBottomSheetDialogFragment != null) { - ((CoordinateInputBottomSheetDialogFragment) coordinateInputBottomSheetDialogFragment).setListener(createCoordinateInputFormatChangeListener()); + Fragment optionsFragment = getChildFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG); + if (optionsFragment != null) { + ((CoordinateInputBottomSheetDialogFragment) optionsFragment).setListener(createCoordinateInputFormatChangeListener()); } - mainView.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { + mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container); + + ImageButton backBtn = (ImageButton) mainView.findViewById(R.id.back_button); + backBtn.setImageDrawable(getActiveIcon(R.drawable.ic_arrow_back)); + backBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveMarkers(); @@ -163,9 +168,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }); - mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(), lightTheme ? R.color.coordinate_input_app_bar_color_light : R.color.coordinate_input_app_bar_color_dark)); - final View optionsButton = mainView.findViewById(R.id.options_button); - optionsButton.setOnClickListener(new View.OnClickListener() { + ((TextView) mainView.findViewById(R.id.toolbar_text)).setTextColor(ContextCompat.getColor(getContext(), + lightTheme ? R.color.color_black : R.color.color_white)); + + mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(), + lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark)); + + mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { View focusedView = getDialog().getCurrentFocus(); @@ -173,27 +182,71 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm focusedView.clearFocus(); AndroidUtils.hideSoftKeyboard(getMapActivity(), focusedView); } - CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); - fragment.setUsedOnMap(false); Bundle args = new Bundle(); args.putBoolean(USE_OSMAND_KEYBOARD, useOsmandKeyboard); args.putBoolean(RIGHT_HAND, rightHand); args.putBoolean(GO_TO_NEXT_FIELD, goToNextField); args.putInt(ACCURACY, accuracy); + CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); fragment.setArguments(args); fragment.setListener(createCoordinateInputFormatChangeListener()); - fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG); + fragment.show(getChildFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG); } }); - textFieldBoxes = new ArrayList<>(); - final OsmandTextFieldBoxes latitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box); - textFieldBoxes.add(latitudeBox); - final OsmandTextFieldBoxes longitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box); - textFieldBoxes.add(longitudeBox); - final OsmandTextFieldBoxes nameBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box); - nameBox.setEndIcon(iconsCache.getIcon(R.drawable.ic_action_keyboard, R.color.coordinate_input_keyboard_icon_color)); - nameBox.getEndIconImageButton().setOnClickListener(new View.OnClickListener() { + addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et, + R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et); + + View.OnClickListener backspaceOnClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(mapActivity, "backspace", Toast.LENGTH_SHORT).show(); + } + }; + + View latSideOfTheWorldBtn = mainView.findViewById(R.id.lat_side_of_the_world_btn); + latSideOfTheWorldBtn.setBackgroundResource(lightTheme + ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); + latSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(mapActivity, "lat side of the world", Toast.LENGTH_SHORT).show(); + } + }); + ((TextView) latSideOfTheWorldBtn.findViewById(R.id.lat_side_of_the_world_tv)).setText(getString(R.string.north_abbreviation)); + ImageView northSideIv = latSideOfTheWorldBtn.findViewById(R.id.north_side_iv); + northSideIv.setImageDrawable(getColoredIcon(R.drawable.ic_action_coordinates_longitude, R.color.dashboard_blue)); + + View lonSideOfTheWorldBtn = mainView.findViewById(R.id.lon_side_of_the_world_btn); + lonSideOfTheWorldBtn.setBackgroundResource(lightTheme + ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); + lonSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(mapActivity, "lon side of the world", Toast.LENGTH_SHORT).show(); + } + }); + ((TextView) lonSideOfTheWorldBtn.findViewById(R.id.lon_side_of_the_world_tv)).setText(getString(R.string.west_abbreviation)); + ImageView westSideIv = lonSideOfTheWorldBtn.findViewById(R.id.west_side_iv); + westSideIv.setImageDrawable(getColoredIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); + + ImageView latBackspaceBtn = (ImageView) mainView.findViewById(R.id.lat_backspace_btn); + latBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_keyboard_backspace)); + latBackspaceBtn.setOnClickListener(backspaceOnClickListener); + + ImageView lonBackspaceBtn = (ImageView) mainView.findViewById(R.id.lon_backspace_btn); + lonBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_keyboard_backspace)); + lonBackspaceBtn.setOnClickListener(backspaceOnClickListener); + + mainView.findViewById(R.id.point_name_divider).setBackgroundColor(ContextCompat + .getColor(getContext(), lightTheme ? R.color.route_info_divider_light : R.color.route_info_divider_dark)); + mainView.findViewById(R.id.point_name_et_container).setBackgroundColor(ContextCompat + .getColor(getContext(), lightTheme ? R.color.route_info_bottom_view_bg_light : R.color.route_info_bottom_view_bg_dark)); + + ImageView pointNameKeyboardBtn = (ImageView) mainView.findViewById(R.id.point_name_keyboard_btn); + pointNameKeyboardBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard)); + pointNameKeyboardBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { View focusedView = getDialog().getCurrentFocus(); @@ -204,12 +257,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } } }); - textFieldBoxes.add(nameBox); registerInputs(); if (savedInstanceState == null) { - latitudeBox.select(); + ((EditText) mainView.findViewById(R.id.lat_first_input_et)).requestFocus(); } registerMainView(); @@ -276,7 +328,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } AndroidUtils.setBackground(mapActivity, keyboardLayout, !lightTheme, lightResId, darkResId); - Object[] keyboardItems = new Object[] { "1", "2", "3", R.drawable.ic_keyboard_next_field, + Object[] keyboardItems = new Object[]{"1", "2", "3", R.drawable.ic_keyboard_next_field, "4", "5", "6", "-", "7", "8", "9", R.drawable.ic_keyboard_backspace, ":", "0", ".", getString(R.string.shared_string_clear)}; @@ -320,7 +372,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (orientationPortrait) { final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon); showHideKeyboardIcon.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_add_button_light_bg : R.drawable.keyboard_item_add_button_dark_bg); - showHideKeyboardIcon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_arrow_down, R.color.keyboard_item_button_text_color)); + showHideKeyboardIcon.setImageDrawable(getColoredIcon(R.drawable.ic_action_arrow_down, R.color.keyboard_item_button_text_color)); showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -365,21 +417,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } } - private void registerInputs() { - View.OnTouchListener textFieldBoxOnTouchListener = new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if (orientationPortrait) { - if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) { - changeOsmandKeyboardVisibility(false); - } else if (useOsmandKeyboard && !isOsmandKeyboardCurrentlyVisible()) { - changeOsmandKeyboardVisibility(true); - } - } - return false; - } - }; + private void addEditTexts(@IdRes int... ids) { + for (int id : ids) { + editTexts.add((EditText) mainView.findViewById(id)); + } + } + private void registerInputs() { TextWatcher textWatcher = new TextWatcher() { private int strLength; @@ -524,15 +568,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }; - for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) { - textFieldBox.getPanel().setOnTouchListener(textFieldBoxOnTouchListener); - EditText editText = textFieldBox.getEditText(); - if (editText.getId() != R.id.name_edit_text) { - editText.addTextChangedListener(textWatcher); + for (EditText et : editTexts) { + if (et.getId() != R.id.point_name_et) { + et.addTextChangedListener(textWatcher); } - editText.setOnTouchListener(inputEditTextOnTouchListener); - editText.setOnLongClickListener(inputEditTextOnLongClickListener); - editText.setOnEditorActionListener(inputTextViewOnEditorActionListener); + et.setOnTouchListener(inputEditTextOnTouchListener); + et.setOnLongClickListener(inputEditTextOnLongClickListener); + et.setOnEditorActionListener(inputTextViewOnEditorActionListener); } changeKeyboardInBoxes(); @@ -580,9 +622,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void changeEditTextSelections() { - for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) { - EditText editText = textFieldBox.getEditText(); - editText.setSelection(editText.getText().length()); + for (EditText et : editTexts) { + et.setSelection(et.getText().length()); } } @@ -595,13 +636,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm mainView.findViewById(R.id.keyboard_grid_view).setVisibility(visibility); mainView.findViewById(R.id.keyboard_divider).setVisibility(visibility); ((ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon)) - .setImageDrawable(iconsCache.getIcon(show ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, R.color.keyboard_item_button_text_color)); + .setImageDrawable(getColoredIcon(show ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, R.color.keyboard_item_button_text_color)); } private void changeKeyboardInBoxes() { - for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) { - textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard); - } +// for (OsmandTextFieldBoxes textFieldBox : editTexts) { +// textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard); +// } } private void switchToNextInput(int id) { @@ -667,11 +708,19 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void clearInputs() { - for (OsmandTextFieldBoxes osmandTextFieldBox : textFieldBoxes) { - osmandTextFieldBox.getEditText().setText(""); - osmandTextFieldBox.deactivate(); + for (EditText et : editTexts) { + et.setText(""); + et.clearFocus(); } - ((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).select(); + ((EditText) mainView.findViewById(R.id.lat_first_input_et)).requestFocus(); + } + + private Drawable getActiveIcon(@DrawableRes int resId) { + return getColoredIcon(resId, lightTheme ? R.color.icon_color : R.color.coordinate_input_active_icon_dark); + } + + private Drawable getColoredIcon(@DrawableRes int resId, @ColorRes int colorResId) { + return getMyApplication().getIconsCache().getIcon(resId, colorResId); } private MapActivity getMapActivity() { @@ -822,7 +871,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm icon = DrawableCompat.wrap(getResources().getDrawable((Integer) item)); DrawableCompat.setTintList(icon, numberColorStateList); } else { - icon = iconsCache.getIcon((Integer) item, R.color.keyboard_item_divider_control_color_dark); + icon = getColoredIcon((Integer) item, R.color.keyboard_item_divider_control_color_dark); } keyboardItemImage.setImageDrawable(icon); } @@ -834,5 +883,4 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm interface OnMapMarkersSavedListener { void onMapMarkersSaved(); } - } From 516be4b8e2c816e5b33a76334138bf6920b6194d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 14 Feb 2018 13:01:51 +0200 Subject: [PATCH 02/50] Rename keyboard item layout; delete unnecessary fields --- ...em.xml => coordinate_input_keyboard_item.xml} | 0 ...em.xml => coordinate_input_keyboard_item.xml} | 0 .../CoordinateInputDialogFragment.java | 16 ++++++---------- 3 files changed, 6 insertions(+), 10 deletions(-) rename OsmAnd/res/layout-land/{input_coordinate_keyboard_item.xml => coordinate_input_keyboard_item.xml} (100%) rename OsmAnd/res/layout/{input_coordinate_keyboard_item.xml => coordinate_input_keyboard_item.xml} (100%) diff --git a/OsmAnd/res/layout-land/input_coordinate_keyboard_item.xml b/OsmAnd/res/layout-land/coordinate_input_keyboard_item.xml similarity index 100% rename from OsmAnd/res/layout-land/input_coordinate_keyboard_item.xml rename to OsmAnd/res/layout-land/coordinate_input_keyboard_item.xml diff --git a/OsmAnd/res/layout/input_coordinate_keyboard_item.xml b/OsmAnd/res/layout/coordinate_input_keyboard_item.xml similarity index 100% rename from OsmAnd/res/layout/input_coordinate_keyboard_item.xml rename to OsmAnd/res/layout/coordinate_input_keyboard_item.xml diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 7564091485..8f3fcab097 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -50,7 +50,6 @@ import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; @@ -92,7 +91,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private static final String NAME_LABEL = "name"; private List mapMarkers = new ArrayList<>(); - private MapMarkersHelper mapMarkersHelper; private OnMapMarkersSavedListener listener; private View mainView; @@ -147,9 +145,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - final MapActivity mapActivity = getMapActivity(); - mapMarkersHelper = getMyApplication().getMapMarkersHelper(); - orientationPortrait = AndroidUiHelper.isOrientationPortrait(mapActivity); + orientationPortrait = AndroidUiHelper.isOrientationPortrait(getActivity()); Fragment optionsFragment = getChildFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG); if (optionsFragment != null) { @@ -201,7 +197,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm View.OnClickListener backspaceOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - Toast.makeText(mapActivity, "backspace", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "backspace", Toast.LENGTH_SHORT).show(); } }; @@ -211,7 +207,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm latSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Toast.makeText(mapActivity, "lat side of the world", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "lat side of the world", Toast.LENGTH_SHORT).show(); } }); ((TextView) latSideOfTheWorldBtn.findViewById(R.id.lat_side_of_the_world_tv)).setText(getString(R.string.north_abbreviation)); @@ -224,7 +220,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm lonSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Toast.makeText(mapActivity, "lon side of the world", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "lon side of the world", Toast.LENGTH_SHORT).show(); } }); ((TextView) lonSideOfTheWorldBtn.findViewById(R.id.lon_side_of_the_world_tv)).setText(getString(R.string.west_abbreviation)); @@ -411,7 +407,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void saveMarkers() { - mapMarkersHelper.addMarkers(mapMarkers); + getMyApplication().getMapMarkersHelper().addMarkers(mapMarkers); if (listener != null) { listener.onMapMarkersSaved(); } @@ -818,7 +814,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { if (convertView == null) { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.input_coordinate_keyboard_item, parent, false); + convertView = LayoutInflater.from(getContext()).inflate(R.layout.coordinate_input_keyboard_item, parent, false); } if (!orientationPortrait) { int keyboardViewHeight = mainView.findViewById(R.id.keyboard_grid_view).getMeasuredHeight(); From 2454fab87254cc60606048195b1ec2d8acceef82 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 14 Feb 2018 13:45:40 +0200 Subject: [PATCH 03/50] Refactor CoordinateInputAdapter and landscape layout for CoordinateInputDialogFragment; add another small fixes --- .../fragment_coordinate_input_dialog.xml | 186 +++++++----------- .../fragment_coordinate_input_dialog.xml | 9 +- .../CoordinateInputDialogFragment.java | 16 +- .../adapters/CoordinateInputAdapter.java | 35 ++-- 4 files changed, 103 insertions(+), 143 deletions(-) diff --git a/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml index db14b92ffb..09a49e41ac 100644 --- a/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml @@ -1,131 +1,81 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index d7ec3cf751..659f7c3273 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -69,16 +69,11 @@ android:textColor="@color/dashboard_blue" android:textSize="@dimen/default_list_text_size" osmand:typeface="@string/font_roboto_regular"/> + - - @@ -151,4 +146,4 @@ - \ No newline at end of file + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 8f3fcab097..cad451ff03 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -155,7 +155,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container); ImageButton backBtn = (ImageButton) mainView.findViewById(R.id.back_button); - backBtn.setImageDrawable(getActiveIcon(R.drawable.ic_arrow_back)); backBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -164,11 +163,16 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }); - ((TextView) mainView.findViewById(R.id.toolbar_text)).setTextColor(ContextCompat.getColor(getContext(), - lightTheme ? R.color.color_black : R.color.color_white)); - - mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(), - lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark)); + if (orientationPortrait) { + backBtn.setImageDrawable(getActiveIcon(R.drawable.ic_arrow_back)); + ((TextView) mainView.findViewById(R.id.toolbar_text)).setTextColor(ContextCompat.getColor(getContext(), + lightTheme ? R.color.color_black : R.color.color_white)); + mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(), + lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark)); + } else { + mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(), + lightTheme ? R.color.actionbar_light_color : R.color.route_info_bottom_view_bg_dark)); + } mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index 88a80266b2..a9ef34202b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -1,5 +1,7 @@ package net.osmand.plus.mapmarkers.adapters; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -19,21 +21,23 @@ import java.util.List; public class CoordinateInputAdapter extends RecyclerView.Adapter { private MapActivity mapActivity; - private boolean nightTheme; private IconsCache iconsCache; private List mapMarkers; + + private boolean nightTheme; + private boolean portrait; + private LatLon location; private Float heading; private boolean useCenter; private int screenOrientation; - private boolean portrait; - public CoordinateInputAdapter (MapActivity mapActivity, List mapMarkers) { + public CoordinateInputAdapter(MapActivity mapActivity, List mapMarkers) { this.mapActivity = mapActivity; - nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent(); iconsCache = mapActivity.getMyApplication().getIconsCache(); - portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); this.mapMarkers = mapMarkers; + nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent(); + portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); } public void setLocation(LatLon location) { @@ -61,16 +65,18 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter Date: Wed, 14 Feb 2018 16:21:15 +0200 Subject: [PATCH 04/50] Landscape layout for CoordinateInputDialogFragment in progress --- .../coordinate_input_keyboard_item.xml | 2 +- .../coordinate_input_land_data_area.xml | 58 ++++ ...oordinate_input_land_keyboard_and_list.xml | 35 +++ ...coordinate_input_land_map_markers_list.xml | 41 --- .../coordinate_input_land_osmand_keyboard.xml | 45 --- .../fragment_coordinate_input_dialog.xml | 3 +- .../CoordinateInputDialogFragment.java | 272 ++++++++---------- 7 files changed, 221 insertions(+), 235 deletions(-) create mode 100644 OsmAnd/res/layout/coordinate_input_land_data_area.xml create mode 100644 OsmAnd/res/layout/coordinate_input_land_keyboard_and_list.xml delete mode 100644 OsmAnd/res/layout/coordinate_input_land_map_markers_list.xml delete mode 100644 OsmAnd/res/layout/coordinate_input_land_osmand_keyboard.xml diff --git a/OsmAnd/res/layout-land/coordinate_input_keyboard_item.xml b/OsmAnd/res/layout-land/coordinate_input_keyboard_item.xml index f2d5cf78c4..b150465c39 100644 --- a/OsmAnd/res/layout-land/coordinate_input_keyboard_item.xml +++ b/OsmAnd/res/layout-land/coordinate_input_keyboard_item.xml @@ -2,7 +2,7 @@ + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/coordinate_input_land_keyboard_and_list.xml b/OsmAnd/res/layout/coordinate_input_land_keyboard_and_list.xml new file mode 100644 index 0000000000..68b5cd1df2 --- /dev/null +++ b/OsmAnd/res/layout/coordinate_input_land_keyboard_and_list.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/coordinate_input_land_map_markers_list.xml b/OsmAnd/res/layout/coordinate_input_land_map_markers_list.xml deleted file mode 100644 index 1189246562..0000000000 --- a/OsmAnd/res/layout/coordinate_input_land_map_markers_list.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/coordinate_input_land_osmand_keyboard.xml b/OsmAnd/res/layout/coordinate_input_land_osmand_keyboard.xml deleted file mode 100644 index bf450ea5aa..0000000000 --- a/OsmAnd/res/layout/coordinate_input_land_osmand_keyboard.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index 659f7c3273..d357476ed8 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -112,8 +112,7 @@ + android:layout_height="56dp"> Date: Wed, 14 Feb 2018 18:38:42 +0200 Subject: [PATCH 05/50] Landscape layout for CoordinateInputDialogFragment in progress; add some refactoring and improvements --- .../res/layout/coordinate_input_data_area.xml | 21 +- OsmAnd/res/values/colors.xml | 2 +- .../CoordinateInputDialogFragment.java | 341 +++++++++--------- 3 files changed, 192 insertions(+), 172 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index 0345b3a537..ce81b6425d 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -80,6 +80,7 @@ android:layout_weight="1" android:hint="xx" android:imeOptions="actionNext" + android:inputType="number" android:maxLines="1" tools:maxLength="2"/> @@ -99,6 +100,7 @@ android:layout_weight="1" android:hint="xx" android:imeOptions="actionNext" + android:inputType="number" android:maxLines="1" tools:maxLength="2"/> @@ -118,6 +120,7 @@ android:layout_weight="1" android:hint="xxxx" android:imeOptions="actionNext" + android:inputType="number" android:maxLines="1" tools:maxLength="4"/> @@ -135,6 +138,12 @@ android:padding="@dimen/content_padding_small" tools:src="@drawable/ic_keyboard_backspace"/> + + @@ -212,6 +221,7 @@ android:layout_weight="1" android:hint="yy" android:imeOptions="actionNext" + android:inputType="number" android:maxLines="1" tools:maxLength="2"/> @@ -231,6 +241,7 @@ android:layout_weight="1" android:hint="yy" android:imeOptions="actionNext" + android:inputType="number" android:maxLines="1" tools:maxLength="2"/> @@ -250,6 +261,7 @@ android:layout_weight="1" android:hint="yyyy" android:imeOptions="actionNext" + android:inputType="number" android:maxLines="1" tools:maxLength="4"/> @@ -267,6 +279,12 @@ android:padding="@dimen/content_padding_small" tools:src="@drawable/ic_keyboard_backspace"/> + + @@ -293,7 +311,8 @@ android:layout_weight="1" android:background="@null" android:hint="@string/optional_point_name" - android:imeOptions="actionDone"/> + android:imeOptions="actionDone" + android:inputType="text"/> #000000 #8a4e00 #13171a + #0d0f0f #0000 @@ -300,7 +301,6 @@ #e6e6e6 #2a2f33 - #1b224d #536dfe #2d3980 #9fadfc diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index be81897492..07ef3c3ac1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -135,7 +135,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); if (!lightTheme && Build.VERSION.SDK_INT >= 21) { - window.setStatusBarColor(ContextCompat.getColor(ctx, R.color.coordinate_input_status_bar_color_dark)); + window.setStatusBarColor(ContextCompat.getColor(ctx, R.color.status_bar_coordinate_input_dark)); } } return dialog; @@ -181,11 +181,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm focusedView.clearFocus(); AndroidUtils.hideSoftKeyboard(getMapActivity(), focusedView); } + Bundle args = new Bundle(); args.putBoolean(USE_OSMAND_KEYBOARD, useOsmandKeyboard); args.putBoolean(RIGHT_HAND, rightHand); args.putBoolean(GO_TO_NEXT_FIELD, goToNextField); args.putInt(ACCURACY, accuracy); + CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); fragment.setUsedOnMap(false); fragment.setArguments(args); @@ -196,8 +198,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm registerMainView(); - if (savedInstanceState == null) { - mainView.findViewById(R.id.lat_first_input_et).requestFocus(); + if (savedInstanceState == null && editTexts.size() > 0) { + editTexts.get(0).requestFocus(); } return mainView; @@ -205,24 +207,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private void registerMainView() { MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return; + } - if (mapActivity != null) { - if (!orientationPortrait) { - LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container); - if (rightHand) { - View.inflate(getContext(), R.layout.coordinate_input_land_data_area, handContainer); - View.inflate(getContext(), R.layout.coordinate_input_land_keyboard_and_list, handContainer); - } else { - View.inflate(getContext(), R.layout.coordinate_input_land_keyboard_and_list, handContainer); - View.inflate(getContext(), R.layout.coordinate_input_land_data_area, handContainer); - } - handContainer.findViewById(R.id.data_area).setBackgroundResource(rightHand - ? R.drawable.bg_contextmenu_shadow_right_light : R.drawable.bg_contextmenu_shadow_left_light); - } - - addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et, - R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et); - + if (orientationPortrait) { View.OnClickListener backspaceOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -230,32 +219,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }; - View latSideOfTheWorldBtn = mainView.findViewById(R.id.lat_side_of_the_world_btn); - latSideOfTheWorldBtn.setBackgroundResource(lightTheme - ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); - latSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(getContext(), "lat side of the world", Toast.LENGTH_SHORT).show(); - } - }); - ((TextView) latSideOfTheWorldBtn.findViewById(R.id.lat_side_of_the_world_tv)).setText(getString(R.string.north_abbreviation)); - ImageView northSideIv = latSideOfTheWorldBtn.findViewById(R.id.north_side_iv); - northSideIv.setImageDrawable(getColoredIcon(R.drawable.ic_action_coordinates_longitude, R.color.dashboard_blue)); - - View lonSideOfTheWorldBtn = mainView.findViewById(R.id.lon_side_of_the_world_btn); - lonSideOfTheWorldBtn.setBackgroundResource(lightTheme - ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); - lonSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(getContext(), "lon side of the world", Toast.LENGTH_SHORT).show(); - } - }); - ((TextView) lonSideOfTheWorldBtn.findViewById(R.id.lon_side_of_the_world_tv)).setText(getString(R.string.west_abbreviation)); - ImageView westSideIv = lonSideOfTheWorldBtn.findViewById(R.id.west_side_iv); - westSideIv.setImageDrawable(getColoredIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); - ImageView latBackspaceBtn = (ImageView) mainView.findViewById(R.id.lat_backspace_btn); latBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_keyboard_backspace)); latBackspaceBtn.setOnClickListener(backspaceOnClickListener); @@ -263,109 +226,150 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm ImageView lonBackspaceBtn = (ImageView) mainView.findViewById(R.id.lon_backspace_btn); lonBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_keyboard_backspace)); lonBackspaceBtn.setOnClickListener(backspaceOnClickListener); + } else { + LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container); + int leftLayoutResId = rightHand ? R.layout.coordinate_input_land_data_area : R.layout.coordinate_input_land_keyboard_and_list; + int rightLayoutResId = rightHand ? R.layout.coordinate_input_land_keyboard_and_list : R.layout.coordinate_input_land_data_area; + View.inflate(getContext(), leftLayoutResId, handContainer); + View.inflate(getContext(), rightLayoutResId, handContainer); + mainView.findViewById(R.id.lat_backspace_btn).setVisibility(View.GONE); + mainView.findViewById(R.id.lon_backspace_btn).setVisibility(View.GONE); + mainView.findViewById(R.id.lat_end_padding).setVisibility(View.VISIBLE); + mainView.findViewById(R.id.lon_end_padding).setVisibility(View.VISIBLE); +// handContainer.findViewById(R.id.data_area).setBackgroundResource(rightHand +// ? R.drawable.bg_contextmenu_shadow_right_light : R.drawable.bg_contextmenu_shadow_left_light); + } - mainView.findViewById(R.id.point_name_divider).setBackgroundColor(ContextCompat - .getColor(getContext(), lightTheme ? R.color.route_info_divider_light : R.color.route_info_divider_dark)); - mainView.findViewById(R.id.point_name_et_container).setBackgroundColor(ContextCompat - .getColor(getContext(), lightTheme ? R.color.route_info_bottom_view_bg_light : R.color.route_info_bottom_view_bg_dark)); + addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et, + R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et); - ImageView pointNameKeyboardBtn = (ImageView) mainView.findViewById(R.id.point_name_keyboard_btn); - pointNameKeyboardBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard)); - pointNameKeyboardBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + View latSideOfTheWorldBtn = mainView.findViewById(R.id.lat_side_of_the_world_btn); + latSideOfTheWorldBtn.setBackgroundResource(lightTheme + ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); + latSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(getContext(), "lat side of the world", Toast.LENGTH_SHORT).show(); + } + }); + ((TextView) latSideOfTheWorldBtn.findViewById(R.id.lat_side_of_the_world_tv)).setText(getString(R.string.north_abbreviation)); + ImageView northSideIv = latSideOfTheWorldBtn.findViewById(R.id.north_side_iv); + northSideIv.setImageDrawable(getColoredIcon(R.drawable.ic_action_coordinates_longitude, R.color.dashboard_blue)); + + View lonSideOfTheWorldBtn = mainView.findViewById(R.id.lon_side_of_the_world_btn); + lonSideOfTheWorldBtn.setBackgroundResource(lightTheme + ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); + lonSideOfTheWorldBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(getContext(), "lon side of the world", Toast.LENGTH_SHORT).show(); + } + }); + ((TextView) lonSideOfTheWorldBtn.findViewById(R.id.lon_side_of_the_world_tv)).setText(getString(R.string.west_abbreviation)); + ImageView westSideIv = lonSideOfTheWorldBtn.findViewById(R.id.west_side_iv); + westSideIv.setImageDrawable(getColoredIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue)); + + mainView.findViewById(R.id.point_name_divider).setBackgroundColor(ContextCompat + .getColor(getContext(), lightTheme ? R.color.route_info_divider_light : R.color.route_info_divider_dark)); + mainView.findViewById(R.id.point_name_et_container).setBackgroundColor(ContextCompat + .getColor(getContext(), lightTheme ? R.color.route_info_bottom_view_bg_light : R.color.route_info_bottom_view_bg_dark)); + + ImageView pointNameKeyboardBtn = (ImageView) mainView.findViewById(R.id.point_name_keyboard_btn); + pointNameKeyboardBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard)); + pointNameKeyboardBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + View focusedView = getDialog().getCurrentFocus(); + if (focusedView != null) { + useOsmandKeyboard = false; + changeKeyboard(); + AndroidUtils.showSoftKeyboard(focusedView); + } + } + }); + + registerInputs(); + + adapter = new CoordinateInputAdapter(mapActivity, mapMarkers); + RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(adapter); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE; + } + }); + + TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button); + addButton.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_add_button_light_bg : R.drawable.keyboard_item_add_button_dark_bg); + addButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + addMapMarker(); + } + }); + + mainView.findViewById(R.id.keyboard_layout).setBackgroundResource(lightTheme ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_menu_dark); + + Object[] keyboardItems = new Object[]{ + "1", "2", "3", R.drawable.ic_keyboard_next_field, + "4", "5", "6", "-", + "7", "8", "9", R.drawable.ic_keyboard_backspace, + ":", "0", ".", getString(R.string.shared_string_clear) + }; + final GridView keyboardGrid = (GridView) mainView.findViewById(R.id.keyboard_grid_view); + keyboardGrid.setBackgroundColor(ContextCompat.getColor(getContext(), lightTheme ? R.color.keyboard_divider_light : R.color.keyboard_divider_dark)); + final KeyboardAdapter keyboardAdapter = new KeyboardAdapter(mapActivity, keyboardItems); + keyboardGrid.setAdapter(keyboardAdapter); + keyboardGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + if (useOsmandKeyboard) { View focusedView = getDialog().getCurrentFocus(); - if (focusedView != null) { - useOsmandKeyboard = false; - changeKeyboard(); - AndroidUtils.showSoftKeyboard(focusedView); - } - } - }); - - registerInputs(); - - RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - adapter = new CoordinateInputAdapter(mapActivity, mapMarkers); - recyclerView.setAdapter(adapter); - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE; - } - }); - - TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button); - addButton.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_add_button_light_bg : R.drawable.keyboard_item_add_button_dark_bg); - addButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - addMapMarker(); - } - }); - - mainView.findViewById(R.id.keyboard_layout).setBackgroundResource(lightTheme ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_menu_dark); - - Object[] keyboardItems = new Object[]{ - "1", "2", "3", R.drawable.ic_keyboard_next_field, - "4", "5", "6", "-", - "7", "8", "9", R.drawable.ic_keyboard_backspace, - ":", "0", ".", getString(R.string.shared_string_clear) - }; - final GridView keyboardGrid = (GridView) mainView.findViewById(R.id.keyboard_grid_view); - keyboardGrid.setBackgroundColor(ContextCompat.getColor(getContext(), lightTheme ? R.color.keyboard_divider_light : R.color.keyboard_divider_dark)); - final KeyboardAdapter keyboardAdapter = new KeyboardAdapter(mapActivity, keyboardItems); - keyboardGrid.setAdapter(keyboardAdapter); - keyboardGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { - if (useOsmandKeyboard) { - View focusedView = getDialog().getCurrentFocus(); - if (focusedView != null && focusedView instanceof EditText) { - EditText focusedEditText = (EditText) focusedView; - switch (i) { - case CLEAR_BUTTON_POSITION: - focusedEditText.setText(""); - break; - case BACKSPACE_BUTTON_POSITION: - String str = focusedEditText.getText().toString(); - if (str.length() > 0) { - str = str.substring(0, str.length() - 1); - focusedEditText.setText(str); - focusedEditText.setSelection(str.length()); - } else { - switchToPreviousInput(focusedEditText.getId()); - } - break; - case SWITCH_TO_NEXT_INPUT_BUTTON_POSITION: - switchToNextInput(focusedEditText.getId()); - break; - default: - focusedEditText.setText(focusedEditText.getText().toString() + keyboardAdapter.getItem(i)); - focusedEditText.setSelection(focusedEditText.getText().length()); - } + if (focusedView != null && focusedView instanceof EditText) { + EditText focusedEditText = (EditText) focusedView; + switch (i) { + case CLEAR_BUTTON_POSITION: + focusedEditText.setText(""); + break; + case BACKSPACE_BUTTON_POSITION: + String str = focusedEditText.getText().toString(); + if (str.length() > 0) { + str = str.substring(0, str.length() - 1); + focusedEditText.setText(str); + focusedEditText.setSelection(str.length()); + } else { + switchEditText(focusedEditText.getId(), false); + } + break; + case SWITCH_TO_NEXT_INPUT_BUTTON_POSITION: + switchEditText(focusedEditText.getId(), true); + break; + default: + focusedEditText.setText(focusedEditText.getText().toString() + keyboardAdapter.getItem(i)); + focusedEditText.setSelection(focusedEditText.getText().length()); } } } - }); + } + }); - final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon); - showHideKeyboardIcon.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_add_button_light_bg : R.drawable.keyboard_item_add_button_dark_bg); - showHideKeyboardIcon.setImageDrawable(getColoredIcon(R.drawable.ic_action_arrow_down, R.color.keyboard_item_button_text_color)); - showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible(); - View focusedView = getDialog().getCurrentFocus(); - if (focusedView != null && !isCurrentlyVisible) { - AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); - } - changeOsmandKeyboardVisibility(!isCurrentlyVisible); + final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon); + showHideKeyboardIcon.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_add_button_light_bg : R.drawable.keyboard_item_add_button_dark_bg); + showHideKeyboardIcon.setImageDrawable(getColoredIcon(R.drawable.ic_action_arrow_down, R.color.keyboard_item_button_text_color)); + showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible(); + View focusedView = getDialog().getCurrentFocus(); + if (focusedView != null && !isCurrentlyVisible) { + AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); } - }); - } + changeOsmandKeyboardVisibility(!isCurrentlyVisible); + } + }); } @Override @@ -431,7 +435,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (pointIndex != -1) { int currentAccuracy = str.substring(pointIndex + 1).length(); if (currentAccuracy >= accuracy) { - switchToNextInput(focusedEditText.getId()); + switchEditText(focusedEditText.getId(), true); } } } @@ -451,7 +455,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (useOsmandKeyboard) { - if (orientationPortrait && !isOsmandKeyboardCurrentlyVisible()) { + if (!isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(true); } EditText editText = (EditText) view; @@ -465,7 +469,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm editText.setInputType(inputType); return true; } else { - if (orientationPortrait && isOsmandKeyboardCurrentlyVisible()) { + if (isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); } return false; @@ -540,7 +544,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_NEXT) { - switchToNextInput(textView.getId()); + switchEditText(textView.getId(), true); } else if (i == EditorInfo.IME_ACTION_DONE) { addMapMarker(); } @@ -557,15 +561,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm et.setOnEditorActionListener(inputTextViewOnEditorActionListener); } - changeKeyboardInBoxes(); changeEditTextSelections(); } private void changeKeyboard() { - if (orientationPortrait && !useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) { + if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); } - changeKeyboardInBoxes(); changeEditTextSelections(); } @@ -615,30 +617,26 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm int visibility = show ? View.VISIBLE : View.GONE; mainView.findViewById(R.id.keyboard_grid_view).setVisibility(visibility); mainView.findViewById(R.id.keyboard_divider).setVisibility(visibility); - ((ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon)) - .setImageDrawable(getColoredIcon(show ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, R.color.keyboard_item_button_text_color)); + ((ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon)).setImageDrawable(getColoredIcon(show + ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, R.color.keyboard_item_button_text_color)); } - private void changeKeyboardInBoxes() { // todo -// for (OsmandTextFieldBoxes textFieldBox : editTexts) { -// textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard); -// } + private void switchEditText(int currentId, boolean toNext) { + int currentInd = getEditTextIndById(currentId); + int newInd = currentInd + (toNext ? 1 : -1); + if (currentInd >= 0 && currentInd < editTexts.size() && newInd >= 0 && newInd < editTexts.size()) { + editTexts.get(newInd).requestFocus(); + } } - private void switchToNextInput(int id) { // todo -// if (id == R.id.latitude_edit_text) { -// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select(); -// } else if (id == R.id.longitude_edit_text) { -// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box)).select(); -// } - } - - private void switchToPreviousInput(int id) { // todo -// if (id == R.id.name_edit_text) { -// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select(); -// } else if (id == R.id.longitude_edit_text) { -// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).select(); -// } + private int getEditTextIndById(int id) { + int res = -1; + for (int i = 0; i < editTexts.size(); i++) { + if (id == editTexts.get(i).getId()) { + return i; + } + } + return res; } private void addMapMarker() { // todo @@ -692,7 +690,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm et.setText(""); et.clearFocus(); } - ((EditText) mainView.findViewById(R.id.lat_first_input_et)).requestFocus(); + if (editTexts.size() > 0) { + editTexts.get(0).requestFocus(); + } } private Drawable getActiveIcon(@DrawableRes int resId) { @@ -834,7 +834,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (lightTheme) { keyboardItemText.setTextColor(dividerControlButton ? dividerControlColorStateList : numberColorStateList); } else { - keyboardItemText.setTextColor(ContextCompat.getColor(getContext(), dividerControlButton ? R.color.keyboard_item_divider_control_color_dark : R.color.keyboard_item_text_color_dark)); + keyboardItemText.setTextColor(ContextCompat.getColor(getContext(), dividerControlButton + ? R.color.keyboard_item_divider_control_color_dark : R.color.keyboard_item_text_color_dark)); } keyboardItemImage.setVisibility(View.GONE); keyboardItemTopSpacing.setVisibility(View.VISIBLE); From 9cc0c2a844ca57202e0a933a8ee79e93d17b6095 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 12:28:38 +0200 Subject: [PATCH 06/50] Clear edit texts list before adding new edit texts; add shadows --- .../fragment_coordinate_input_dialog.xml | 36 +++++++++++++++- .../CoordinateInputDialogFragment.java | 41 +++++++++++-------- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml index 09a49e41ac..5c9fec706f 100644 --- a/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml @@ -76,6 +76,40 @@ android:id="@+id/hand_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="horizontal"/> + android:baselineAligned="false"> + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 07ef3c3ac1..68bc823bfe 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -39,6 +39,7 @@ import android.view.inputmethod.EditorInfo; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.GridView; import android.widget.ImageButton; import android.widget.ImageView; @@ -198,10 +199,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm registerMainView(); - if (savedInstanceState == null && editTexts.size() > 0) { - editTexts.get(0).requestFocus(); - } - return mainView; } @@ -228,20 +225,24 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm lonBackspaceBtn.setOnClickListener(backspaceOnClickListener); } else { LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container); + int leftLayoutResId = rightHand ? R.layout.coordinate_input_land_data_area : R.layout.coordinate_input_land_keyboard_and_list; int rightLayoutResId = rightHand ? R.layout.coordinate_input_land_keyboard_and_list : R.layout.coordinate_input_land_data_area; - View.inflate(getContext(), leftLayoutResId, handContainer); - View.inflate(getContext(), rightLayoutResId, handContainer); - mainView.findViewById(R.id.lat_backspace_btn).setVisibility(View.GONE); - mainView.findViewById(R.id.lon_backspace_btn).setVisibility(View.GONE); - mainView.findViewById(R.id.lat_end_padding).setVisibility(View.VISIBLE); - mainView.findViewById(R.id.lon_end_padding).setVisibility(View.VISIBLE); -// handContainer.findViewById(R.id.data_area).setBackgroundResource(rightHand -// ? R.drawable.bg_contextmenu_shadow_right_light : R.drawable.bg_contextmenu_shadow_left_light); + View leftView = View.inflate(getContext(), leftLayoutResId, null); + View rightView = View.inflate(getContext(), rightLayoutResId, null); + ((FrameLayout) handContainer.findViewById(R.id.left_container)).addView(leftView, 0); + ((FrameLayout) handContainer.findViewById(R.id.right_container)).addView(rightView, 0); + + handContainer.findViewById(R.id.right_shadow).setVisibility(rightHand ? View.VISIBLE : View.GONE); + handContainer.findViewById(R.id.left_shadow).setVisibility(rightHand ? View.GONE : View.VISIBLE); + + handContainer.findViewById(R.id.lat_backspace_btn).setVisibility(View.GONE); + handContainer.findViewById(R.id.lon_backspace_btn).setVisibility(View.GONE); + handContainer.findViewById(R.id.lat_end_padding).setVisibility(View.VISIBLE); + handContainer.findViewById(R.id.lon_end_padding).setVisibility(View.VISIBLE); } - addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et, - R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et); + registerInputs(); View latSideOfTheWorldBtn = mainView.findViewById(R.id.lat_side_of_the_world_btn); latSideOfTheWorldBtn.setBackgroundResource(lightTheme @@ -288,8 +289,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }); - registerInputs(); - adapter = new CoordinateInputAdapter(mapActivity, mapMarkers); RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -402,6 +401,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void addEditTexts(@IdRes int... ids) { + editTexts.clear(); for (int id : ids) { editTexts.add((EditText) mainView.findViewById(id)); } @@ -552,6 +552,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }; + addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et, + R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et); + for (EditText et : editTexts) { if (et.getId() != R.id.point_name_et) { et.addTextChangedListener(textWatcher); @@ -562,6 +565,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } changeEditTextSelections(); + + editTexts.get(0).requestFocus(); } private void changeKeyboard() { @@ -598,8 +603,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void changeHand() { - LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container); - handContainer.removeAllViewsInLayout(); + ((FrameLayout) mainView.findViewById(R.id.left_container)).removeViewAt(0); + ((FrameLayout) mainView.findViewById(R.id.right_container)).removeViewAt(0); registerMainView(); } From 06f3ae09c61464f6111c61c8584cf8ad9948f8dd Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 14:50:39 +0200 Subject: [PATCH 07/50] Add CorrdinateInputFormats --- OsmAnd/res/values/strings.xml | 5 + .../mapmarkers/CoordinateInputFormats.java | 103 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7661a3e5a4..05f81738fb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,11 @@ 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 --> + DD°MM′SS″ + DD.DDDDDD° + DD.DDDDD° + DD°MM.MMMM′ + DD°MM.MMM′ E W S diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java new file mode 100644 index 0000000000..7a8968cf7e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java @@ -0,0 +1,103 @@ +package net.osmand.plus.mapmarkers; + +import android.content.Context; +import android.support.annotation.IntDef; + +import net.osmand.plus.R; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class CoordinateInputFormats { + + public static final int DD_MM_MMM = 0; + public static final int DD_MM_MMMM = 1; + public static final int DD_DDDDD = 2; + public static final int DD_DDDDDD = 3; + public static final int DD_MM_SS = 4; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({DD_MM_MMM, DD_MM_MMMM, DD_DDDDD, DD_DDDDDD, DD_MM_SS}) + @interface CoordinateInputFormatDef { + } + + public static String formatToHumanString(Context ctx, @CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + return ctx.getString(R.string.dd_mm_mmm_format); + case DD_MM_MMMM: + return ctx.getString(R.string.dd_mm_mmmm_format); + case DD_DDDDD: + return ctx.getString(R.string.dd_ddddd_format); + case DD_DDDDDD: + return ctx.getString(R.string.dd_dddddd_format); + case DD_MM_SS: + return ctx.getString(R.string.dd_mm_ss_format); + default: + return "Unknown format"; + } + } + + public static boolean containsThirdPart(@CoordinateInputFormatDef int format) { + return format == DD_MM_MMM || format == DD_MM_MMMM || format == DD_MM_SS; + } + + public static int getSecondPartSymbolsCount(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + case DD_MM_MMMM: + case DD_MM_SS: + return 2; + case DD_DDDDD: + return 5; + case DD_DDDDDD: + return 6; + default: + return 0; + } + } + + public static int getThirdPartSymbolsCount(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + return 3; + case DD_MM_MMMM: + return 4; + case DD_MM_SS: + return 2; + case DD_DDDDD: + case DD_DDDDDD: + default: + return 0; + } + } + + public static String getFirstSeparator(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + case DD_MM_MMMM: + case DD_MM_SS: + return "°"; + case DD_DDDDD: + case DD_DDDDDD: + return "."; + default: + return ""; + } + } + + public static String getSecondSeparator(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + case DD_MM_MMMM: + return "."; + case DD_DDDDD: + case DD_DDDDDD: + return "°"; + case DD_MM_SS: + return "′"; + default: + return ""; + } + } +} From 8b79747599a069f3e1f8ff6d92284cdacdab39c7 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 17:18:29 +0200 Subject: [PATCH 08/50] Change coordinate input options menu; add settings; add some refactoring and improvements --- .../bottom_sheet_item_with_radio_btn.xml | 44 +++++ ...ate_input_options_bottom_sheet_dialog.xml} | 131 +++---------- .../src/net/osmand/plus/OsmandSettings.java | 4 + ...rdinateInputBottomSheetDialogFragment.java | 184 ++++++++---------- .../CoordinateInputDialogFragment.java | 54 ++--- .../mapmarkers/CoordinateInputFormats.java | 17 +- 6 files changed, 177 insertions(+), 257 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml rename OsmAnd/res/layout/{fragment_marker_coordinate_input_options_bottom_sheet_helper.xml => fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml} (56%) diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml b/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml new file mode 100644 index 0000000000..5e4a692f66 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml @@ -0,0 +1,44 @@ + + + + + + + + + + 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_dialog.xml similarity index 56% rename from OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_helper.xml rename to OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml index 4c80f53f51..887d3c7a07 100644 --- a/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_helper.xml +++ b/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml @@ -1,11 +1,12 @@ - + + osmand:typeface="@string/font_roboto_medium" + tools:text="Right" + tools:textColor="@color/map_widget_blue_pressed"/> - - - - - - - - - + android:textSize="@dimen/default_desc_text_size"/> - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"/> @@ -246,4 +165,4 @@ android:textStyle="bold"/> - \ No newline at end of file + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 131394dd8e..f09d14cfb3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -31,6 +31,7 @@ import net.osmand.plus.api.SettingsAPI.SettingsEditor; import net.osmand.plus.dialogs.RateUsBottomSheetDialog; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.mapillary.MapillaryPlugin; +import net.osmand.plus.mapmarkers.CoordinateInputFormats; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.render.RenderingRulesStorage; @@ -718,6 +719,9 @@ public class OsmandSettings { public final CommonPreference SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); + public final CommonPreference COORDS_INPUT_USE_RIGHT_SIDE = new BooleanPreference("coords_input_use_right_side", true).makeGlobal(); + public final CommonPreference COORDS_INPUT_FORMAT = new IntPreference("coords_input_format", CoordinateInputFormats.DD_MM_MMM); + public final CommonPreference USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 23ed66b538..dea0ec8632 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -1,41 +1,39 @@ package net.osmand.plus.mapmarkers; +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.support.annotation.ColorInt; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.support.v7.widget.ListPopupWindow; +import android.support.v4.widget.CompoundButtonCompat; import android.view.ContextThemeWrapper; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RadioButton; import android.widget.TextView; -import net.osmand.AndroidUtils; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.mapmarkers.CoordinateInputFormats.CoordinateInputFormatDef; -import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.ACCURACY; -import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.GO_TO_NEXT_FIELD; -import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.RIGHT_HAND; import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.USE_OSMAND_KEYBOARD; public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "CoordinateInputBottomSheetDialogFragment"; - private View mainView; - private boolean useOsmandKeyboard; - private boolean rightHand; - private boolean goToNextField; - private int accuracy; private CoordinateInputFormatChangeListener listener; + private boolean useOsmandKeyboard; + public void setListener(CoordinateInputFormatChangeListener listener) { this.listener = listener; } @@ -47,111 +45,100 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia Bundle args = getArguments(); if (args != null) { useOsmandKeyboard = args.getBoolean(USE_OSMAND_KEYBOARD); - rightHand = args.getBoolean(RIGHT_HAND); - goToNextField = args.getBoolean(GO_TO_NEXT_FIELD); - accuracy = args.getInt(ACCURACY); } } else { useOsmandKeyboard = savedInstanceState.getBoolean(USE_OSMAND_KEYBOARD); - rightHand = savedInstanceState.getBoolean(RIGHT_HAND); - goToNextField = savedInstanceState.getBoolean(GO_TO_NEXT_FIELD); - accuracy = savedInstanceState.getInt(ACCURACY); } } @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final Context context = getContext(); + final OsmandSettings settings = getMyApplication().getSettings(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_coordinate_input_options_bottom_sheet_helper, container); + View mainView = View.inflate(new ContextThemeWrapper(context, themeRes), + R.layout.fragment_marker_coordinate_input_options_bottom_sheet_dialog, container); if (nightMode) { - ((TextView) mainView.findViewById(R.id.coordinate_input_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + ((TextView) mainView.findViewById(R.id.coordinate_input_title)) + .setTextColor(ContextCompat.getColor(context, R.color.ctx_menu_info_text_dark)); } - ((TextView) mainView.findViewById(R.id.coordinate_input_accuracy_descr)).setText(getString(R.string.coordinate_input_accuracy_description, accuracy)); - - ((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() { + ((CompoundButton) mainView.findViewById(R.id.use_system_keyboard_switch)).setChecked(!useOsmandKeyboard); + + View.OnClickListener itemsOnClickListener = new View.OnClickListener() { @Override - public void onClick(View view) { - useOsmandKeyboard = !useOsmandKeyboard; - ((CompoundButton) mainView.findViewById(R.id.use_system_keyboard_switch)).setChecked(!useOsmandKeyboard); + public void onClick(View v) { if (listener != null) { - listener.onKeyboardChanged(useOsmandKeyboard); + int id = v.getId(); + if (id == R.id.use_system_keyboard_row) { + listener.onKeyboardChanged(!useOsmandKeyboard); + } else if (id == R.id.hand_row) { + OsmandSettings.CommonPreference pref = settings.COORDS_INPUT_USE_RIGHT_SIDE; + pref.set(!pref.get()); + listener.onHandChanged(); + } } + dismiss(); } - }); + }; + + mainView.findViewById(R.id.use_system_keyboard_row).setOnClickListener(itemsOnClickListener); + mainView.findViewById(R.id.cancel_row).setOnClickListener(itemsOnClickListener); View handRow = mainView.findViewById(R.id.hand_row); if (portrait) { handRow.setVisibility(View.GONE); } else { - handRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - rightHand = !rightHand; - populateChangeHandRow(); - if (listener != null) { - listener.onHandChanged(rightHand); - } - } - }); - populateChangeHandRow(); + boolean rightHand = settings.COORDS_INPUT_USE_RIGHT_SIDE.get(); + ((ImageView) mainView.findViewById(R.id.hand_icon)).setImageDrawable(getContentIcon(rightHand + ? R.drawable.ic_action_show_keypad_right : R.drawable.ic_action_show_keypad_left)); + ((TextView) mainView.findViewById(R.id.hand_text_view)).setText(getString(rightHand + ? R.string.shared_string_right : R.string.shared_string_left)); + ((TextView) mainView.findViewById(R.id.hand_text_view)).setTextColor(getResolvedActiveColor()); + handRow.setOnClickListener(itemsOnClickListener); } - ((CompoundButton) mainView.findViewById(R.id.go_to_next_field_switch)).setChecked(goToNextField); - ((ImageView) mainView.findViewById(R.id.go_to_next_field_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_next_field_stroke)); - mainView.findViewById(R.id.go_to_next_field_row).setOnClickListener(new View.OnClickListener() { + View.OnClickListener formatsOnClickListener = new View.OnClickListener() { @Override - public void onClick(View view) { - goToNextField = !goToNextField; - ((CompoundButton) mainView.findViewById(R.id.go_to_next_field_switch)).setChecked(goToNextField); - switchSelectedAccuracy(); + public void onClick(View v) { + int format = (int) v.getTag(); + settings.COORDS_INPUT_FORMAT.set(format); if (listener != null) { - listener.onGoToNextFieldChanged(goToNextField); + listener.onFormatChanged(); } - } - }); - - switchSelectedAccuracy(); - populateSelectedAccuracy(); - - mainView.findViewById(R.id.accuracy_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (goToNextField) { - final ListPopupWindow listPopupWindow = new ListPopupWindow(getContext()); - listPopupWindow.setAnchorView(view); - listPopupWindow.setContentWidth(AndroidUtils.dpToPx(getMyApplication(), 100)); - listPopupWindow.setModal(true); - listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP); - listPopupWindow.setAdapter(new ArrayAdapter<>(getContext(), R.layout.popup_list_text_item, new Integer[]{0, 1, 2, 3, 4, 5, 6})); - listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { - accuracy = i; - populateSelectedAccuracy(); - if (listener != null) { - listener.onAccuracyChanged(accuracy); - } - listPopupWindow.dismiss(); - } - }); - listPopupWindow.show(); - } - } - }); - - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { dismiss(); } - }); + }; + + LinearLayout formatsContainer = (LinearLayout) mainView.findViewById(R.id.formats_container); + Drawable formatIcon = getContentIcon(R.drawable.ic_action_coordinates_latitude); + int selectedFormat = settings.COORDS_INPUT_FORMAT.get(); + for (@CoordinateInputFormatDef int format : CoordinateInputFormats.VALUES) { + boolean selectedRow = format == selectedFormat; + + View row = View.inflate(new ContextThemeWrapper(context, themeRes), + R.layout.bottom_sheet_item_with_radio_btn, null); + row.setTag(format); + row.setOnClickListener(formatsOnClickListener); + + ((ImageView) row.findViewById(R.id.icon_iv)).setImageDrawable(selectedRow + ? getActiveIcon(R.drawable.ic_action_coordinates_latitude) : formatIcon); + TextView nameTv = (TextView) row.findViewById(R.id.name_tv); + nameTv.setText(CoordinateInputFormats.formatToHumanString(context, format)); + if (selectedRow) { + nameTv.setTextColor(getResolvedActiveColor()); + RadioButton rb = (RadioButton) row.findViewById(R.id.radio_button); + rb.setChecked(true); + CompoundButtonCompat.setButtonTintList(rb, ColorStateList.valueOf(getResolvedActiveColor())); + } + + formatsContainer.addView(row); + } setupHeightAndBackground(mainView, R.id.marker_coordinate_input_scroll_view); @@ -161,37 +148,20 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia @Override public void onSaveInstanceState(Bundle outState) { outState.putBoolean(USE_OSMAND_KEYBOARD, useOsmandKeyboard); - outState.putBoolean(RIGHT_HAND, rightHand); - outState.putBoolean(GO_TO_NEXT_FIELD, goToNextField); - outState.putInt(ACCURACY, accuracy); super.onSaveInstanceState(outState); } - private void populateChangeHandRow() { - ((ImageView) mainView.findViewById(R.id.hand_icon)).setImageDrawable(getContentIcon(rightHand ? R.drawable.ic_action_show_keypad_right : R.drawable.ic_action_show_keypad_left)); - ((TextView) mainView.findViewById(R.id.hand_text_view)).setText(getString(rightHand ? R.string.shared_string_right : R.string.shared_string_left)); - ((TextView) mainView.findViewById(R.id.hand_text_view)).setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.color_dialog_buttons_dark : R.color.map_widget_blue_pressed)); - } - - private void populateSelectedAccuracy() { - ((TextView) mainView.findViewById(R.id.selected_accuracy)).setText(String.valueOf(accuracy)); - ((TextView) mainView.findViewById(R.id.selected_accuracy_hint)).setText("00:00." + new String(new char[accuracy]).replace("\0", "0")); - } - - private void switchSelectedAccuracy() { - ((TextView) mainView.findViewById(R.id.selected_accuracy)).setTextColor(ContextCompat.getColor(getContext(), goToNextField ? R.color.map_widget_blue : android.R.color.darker_gray)); - ((ImageView) mainView.findViewById(R.id.accuracy_arrow)).setImageDrawable(goToNextField ? getContentIcon(R.drawable.ic_action_arrow_drop_down) : getIcon(R.drawable.ic_action_arrow_drop_down, android.R.color.darker_gray)); + @ColorInt + private int getResolvedActiveColor() { + return ContextCompat.getColor(getContext(), nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); } interface CoordinateInputFormatChangeListener { void onKeyboardChanged(boolean useOsmandKeyboard); - void onHandChanged(boolean rightHand); - - void onGoToNextFieldChanged(boolean goToNextField); - - void onAccuracyChanged(int accuracy); + void onHandChanged(); + void onFormatChanged(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 68bc823bfe..e36b591afe 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -76,9 +76,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm public static final String TAG = "CoordinateInputDialogFragment"; public static final String USE_OSMAND_KEYBOARD = "use_osmand_keyboard"; - public static final String RIGHT_HAND = "right_hand"; - public static final String GO_TO_NEXT_FIELD = "go_to_next_field"; - public static final String ACCURACY = "accuracy"; private static final int SWITCH_TO_NEXT_INPUT_BUTTON_POSITION = 3; private static final int MINUS_BUTTON_POSITION = 7; @@ -101,9 +98,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean orientationPortrait; private boolean useOsmandKeyboard = true; - private boolean rightHand = true; - private boolean goToNextField = true; - private int accuracy = 4; private Location location; private Float heading; @@ -185,9 +179,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm Bundle args = new Bundle(); args.putBoolean(USE_OSMAND_KEYBOARD, useOsmandKeyboard); - args.putBoolean(RIGHT_HAND, rightHand); - args.putBoolean(GO_TO_NEXT_FIELD, goToNextField); - args.putInt(ACCURACY, accuracy); CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); fragment.setUsedOnMap(false); @@ -224,6 +215,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm lonBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_keyboard_backspace)); lonBackspaceBtn.setOnClickListener(backspaceOnClickListener); } else { + boolean rightHand = getMyApplication().getSettings().COORDS_INPUT_USE_RIGHT_SIDE.get(); LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container); int leftLayoutResId = rightHand ? R.layout.coordinate_input_land_data_area : R.layout.coordinate_input_land_keyboard_and_list; @@ -424,22 +416,20 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void afterTextChanged(Editable editable) { - if (goToNextField) { - View focusedView = getDialog().getCurrentFocus(); - if (focusedView != null && focusedView instanceof EditText) { - EditText focusedEditText = (EditText) focusedView; - String str = focusedEditText.getText().toString(); - int currentLength = str.length(); - if (currentLength > strLength) { - int pointIndex = str.indexOf("."); - if (pointIndex != -1) { - int currentAccuracy = str.substring(pointIndex + 1).length(); - if (currentAccuracy >= accuracy) { - switchEditText(focusedEditText.getId(), true); - } - } - } - } + View focusedView = getDialog().getCurrentFocus(); + if (focusedView != null && focusedView instanceof EditText) { + EditText focusedEditText = (EditText) focusedView; + String str = focusedEditText.getText().toString(); + int currentLength = str.length(); // todo +// if (currentLength > strLength) { +// int pointIndex = str.indexOf("."); +// if (pointIndex != -1) { +// int currentAccuracy = str.substring(pointIndex + 1).length(); +// if (currentAccuracy >= accuracy) { +// switchEditText(focusedEditText.getId(), true); +// } +// } +// } } } }; @@ -578,6 +568,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() { return new CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener() { + @Override public void onKeyboardChanged(boolean useOsmandKeyboard) { CoordinateInputDialogFragment.this.useOsmandKeyboard = useOsmandKeyboard; @@ -585,19 +576,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } @Override - public void onHandChanged(boolean rightHand) { - CoordinateInputDialogFragment.this.rightHand = rightHand; + public void onHandChanged() { changeHand(); } @Override - public void onGoToNextFieldChanged(boolean goToNextField) { - CoordinateInputDialogFragment.this.goToNextField = goToNextField; - } - - @Override - public void onAccuracyChanged(int accuracy) { - CoordinateInputDialogFragment.this.accuracy = accuracy; + public void onFormatChanged() { + Toast.makeText(getContext(), CoordinateInputFormats.formatToHumanString(getContext(), + getMyApplication().getSettings().COORDS_INPUT_FORMAT.get()), Toast.LENGTH_SHORT).show(); } }; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java index 7a8968cf7e..9234ab476e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java @@ -16,6 +16,8 @@ public class CoordinateInputFormats { public static final int DD_DDDDDD = 3; public static final int DD_MM_SS = 4; + public static int[] VALUES = new int[]{DD_MM_MMM, DD_MM_MMMM, DD_DDDDD, DD_DDDDDD, DD_MM_SS}; + @Retention(RetentionPolicy.SOURCE) @IntDef({DD_MM_MMM, DD_MM_MMMM, DD_DDDDD, DD_DDDDDD, DD_MM_SS}) @interface CoordinateInputFormatDef { @@ -33,9 +35,8 @@ public class CoordinateInputFormats { return ctx.getString(R.string.dd_dddddd_format); case DD_MM_SS: return ctx.getString(R.string.dd_mm_ss_format); - default: - return "Unknown format"; } + return "Unknown format"; } public static boolean containsThirdPart(@CoordinateInputFormatDef int format) { @@ -52,9 +53,8 @@ public class CoordinateInputFormats { return 5; case DD_DDDDDD: return 6; - default: - return 0; } + return 0; } public static int getThirdPartSymbolsCount(@CoordinateInputFormatDef int format) { @@ -67,9 +67,8 @@ public class CoordinateInputFormats { return 2; case DD_DDDDD: case DD_DDDDDD: - default: - return 0; } + return 0; } public static String getFirstSeparator(@CoordinateInputFormatDef int format) { @@ -81,9 +80,8 @@ public class CoordinateInputFormats { case DD_DDDDD: case DD_DDDDDD: return "."; - default: - return ""; } + return ""; } public static String getSecondSeparator(@CoordinateInputFormatDef int format) { @@ -96,8 +94,7 @@ public class CoordinateInputFormats { return "°"; case DD_MM_SS: return "′"; - default: - return ""; } + return ""; } } From cdac1a0dc198f59d6540744b69106d68432b52ec Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 17:33:20 +0200 Subject: [PATCH 09/50] Replace spaces with tabs --- .../res/layout/coordinate_input_data_area.xml | 568 +++++++++--------- 1 file changed, 284 insertions(+), 284 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index ce81b6425d..f2d1561c61 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -1,329 +1,329 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + tools:background="@color/ctx_menu_bg_dark"> - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - - + + From 84dc31377c21207113fc84d0fbb20ac19a200ae4 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 17:57:24 +0200 Subject: [PATCH 10/50] Add padding to input area in landscape; replace spaces with tabs --- .../res/layout/coordinate_input_data_area.xml | 14 +++ .../coordinate_input_land_data_area.xml | 93 +++++++++---------- .../CoordinateInputDialogFragment.java | 2 + 3 files changed, 62 insertions(+), 47 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index f2d1561c61..3067e8ea63 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -7,6 +7,13 @@ android:orientation="vertical" tools:background="@color/ctx_menu_bg_dark"> + + + + + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/data_area" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="0.5" + android:orientation="vertical" + tools:layout_width="match_parent"> - + - + - + - + - + - + - - - + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index e36b591afe..1316e19600 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -225,6 +225,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm ((FrameLayout) handContainer.findViewById(R.id.left_container)).addView(leftView, 0); ((FrameLayout) handContainer.findViewById(R.id.right_container)).addView(rightView, 0); + handContainer.findViewById(R.id.input_area_top_padding).setVisibility(View.VISIBLE); + handContainer.findViewById(R.id.point_name_top_space).setVisibility(View.VISIBLE); handContainer.findViewById(R.id.right_shadow).setVisibility(rightHand ? View.VISIBLE : View.GONE); handContainer.findViewById(R.id.left_shadow).setVisibility(rightHand ? View.GONE : View.VISIBLE); From 0b998b1f0b2342386790059c9d64a9ef2a637b8e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 18:49:40 +0200 Subject: [PATCH 11/50] Customize input area for selected format --- .../res/layout/coordinate_input_data_area.xml | 36 +++++----- .../CoordinateInputDialogFragment.java | 65 +++++++++++++++++-- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index 3067e8ea63..e95885c2fa 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -88,27 +88,27 @@ android:hint="xx" android:imeOptions="actionNext" android:inputType="number" - android:maxLines="1" - tools:maxLength="2"/> + android:maxLength="2" + android:maxLines="1"/> + android:textSize="@dimen/dialog_header_text_size" + tools:text="°"/> + android:textSize="@dimen/dialog_header_text_size" + tools:text="."/> @@ -229,27 +229,27 @@ android:hint="yy" android:imeOptions="actionNext" android:inputType="number" - android:maxLines="1" - tools:maxLength="2"/> + android:maxLength="2" + android:maxLines="1"/> + android:textSize="@dimen/dialog_header_text_size" + tools:text="°"/> + android:textSize="@dimen/dialog_header_text_size" + tools:text="."/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 1316e19600..beaafb6a5c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -22,6 +22,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.text.Editable; +import android.text.InputFilter; import android.text.InputType; import android.text.TextWatcher; import android.util.TypedValue; @@ -397,7 +398,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private void addEditTexts(@IdRes int... ids) { editTexts.clear(); for (int id : ids) { - editTexts.add((EditText) mainView.findViewById(id)); + View v = mainView.findViewById(id); + if (v != null && v instanceof EditText && v.getVisibility() == View.VISIBLE) { + editTexts.add((EditText) mainView.findViewById(id)); + } } } @@ -544,8 +548,52 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } }; - addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et, - R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et); + clearInputs(); + + int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get(); + + String firstSeparator = CoordinateInputFormats.getFirstSeparator(format); + int secondPartSymbols = CoordinateInputFormats.getSecondPartSymbolsCount(format); + + ((TextView) mainView.findViewById(R.id.lat_first_separator_tv)).setText(firstSeparator); + ((TextView) mainView.findViewById(R.id.lon_first_separator_tv)).setText(firstSeparator); + + InputFilter[] secondInputFilters = {new InputFilter.LengthFilter(secondPartSymbols)}; + + EditText latSecondEt = (EditText) mainView.findViewById(R.id.lat_second_input_et); + EditText lonSecondEt = (EditText) mainView.findViewById(R.id.lon_second_input_et); + latSecondEt.setFilters(secondInputFilters); + lonSecondEt.setFilters(secondInputFilters); + latSecondEt.setHint(createHint(secondPartSymbols, 'x')); + lonSecondEt.setHint(createHint(secondPartSymbols, 'y')); + + boolean containsThirdPart = CoordinateInputFormats.containsThirdPart(format); + + int visibility = containsThirdPart ? View.VISIBLE : View.GONE; + mainView.findViewById(R.id.lat_second_separator_tv).setVisibility(visibility); + mainView.findViewById(R.id.lon_second_separator_tv).setVisibility(visibility); + mainView.findViewById(R.id.lat_third_input_et).setVisibility(visibility); + mainView.findViewById(R.id.lon_third_input_et).setVisibility(visibility); + + if (containsThirdPart) { + String secondSeparator = CoordinateInputFormats.getSecondSeparator(format); + int thirdPartSymbols = CoordinateInputFormats.getThirdPartSymbolsCount(format); + + ((TextView) mainView.findViewById(R.id.lat_second_separator_tv)).setText(secondSeparator); + ((TextView) mainView.findViewById(R.id.lon_second_separator_tv)).setText(secondSeparator); + + InputFilter[] thirdInputFilters = {new InputFilter.LengthFilter(thirdPartSymbols)}; + + EditText latThirdEt = (EditText) mainView.findViewById(R.id.lat_third_input_et); + EditText lonThirdEt = (EditText) mainView.findViewById(R.id.lon_third_input_et); + latThirdEt.setFilters(thirdInputFilters); + lonThirdEt.setFilters(thirdInputFilters); + latThirdEt.setHint(createHint(thirdPartSymbols, 'x')); + lonThirdEt.setHint(createHint(thirdPartSymbols, 'y')); + } + + addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_third_input_et, + R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_third_input_et, R.id.point_name_et); for (EditText et : editTexts) { if (et.getId() != R.id.point_name_et) { @@ -561,6 +609,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm editTexts.get(0).requestFocus(); } + private String createHint(int symbolsCount, char symbol) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < symbolsCount; i++) { + sb.append(symbol); + } + return sb.toString(); + } + private void changeKeyboard() { if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); @@ -584,8 +640,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onFormatChanged() { - Toast.makeText(getContext(), CoordinateInputFormats.formatToHumanString(getContext(), - getMyApplication().getSettings().COORDS_INPUT_FORMAT.get()), Toast.LENGTH_SHORT).show(); + registerInputs(); } }; } From 481b4618254704bdb04482d082695349c5f5b194 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Feb 2018 11:55:43 +0200 Subject: [PATCH 12/50] Change some colors and fonts in UI --- .../fragment_coordinate_input_dialog.xml | 2 +- .../res/layout/coordinate_input_data_area.xml | 10 +++- .../fragment_coordinate_input_dialog.xml | 2 +- OsmAnd/res/values/attrs.xml | 5 +- OsmAnd/res/values/colors.xml | 3 ++ OsmAnd/res/values/styles.xml | 9 ++++ .../CoordinateInputDialogFragment.java | 51 ++++++++++++------- 7 files changed, 57 insertions(+), 25 deletions(-) diff --git a/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml index 5c9fec706f..5cde1dab18 100644 --- a/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout-land/fragment_coordinate_input_dialog.xml @@ -64,7 +64,7 @@ android:textAllCaps="true" android:textColor="@color/color_white" android:textSize="@dimen/default_list_text_size" - osmand:typeface="@string/font_roboto_regular"/> + osmand:typeface="@string/font_roboto_medium"/> diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index e95885c2fa..71f9a80754 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -89,7 +89,8 @@ android:imeOptions="actionNext" android:inputType="number" android:maxLength="2" - android:maxLines="1"/> + android:maxLines="1" + android:theme="@style/CoordinateInputEditText"/> @@ -128,6 +130,7 @@ android:imeOptions="actionNext" android:inputType="number" android:maxLines="1" + android:theme="@style/CoordinateInputEditText" tools:hint="xxxx" tools:maxLength="4"/> @@ -230,7 +233,8 @@ android:imeOptions="actionNext" android:inputType="number" android:maxLength="2" - android:maxLines="1"/> + android:maxLines="1" + android:theme="@style/CoordinateInputEditText"/> @@ -269,6 +274,7 @@ android:imeOptions="actionNext" android:inputType="number" android:maxLines="1" + android:theme="@style/CoordinateInputEditText" tools:hint="yyyy" tools:maxLength="4"/> diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index d357476ed8..71c558b5f0 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -68,7 +68,7 @@ android:textAllCaps="true" android:textColor="@color/dashboard_blue" android:textSize="@dimen/default_list_text_size" - osmand:typeface="@string/font_roboto_regular"/> + osmand:typeface="@string/font_roboto_medium"/> diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 229b01fd7f..8cdb7c322a 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -32,8 +32,9 @@ - - + + + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index e505f8518c..934e54d43c 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -307,6 +307,9 @@ #9fadfc #ed5421 #c0c0c0 + #ff8800 + #e6e6e6 + #2d3133 #78cc5c #fac403 diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 8320ca0f17..1151421e2f 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -191,6 +191,8 @@ @style/PopupMenuLight @color/keyboard_item_add_button_divider_light + + @color/coordinate_input_edit_text_normal_light + +