From 439830a7f51ca4ef0bba124c32da150c2a88bc33 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 27 Sep 2017 14:54:24 +0300 Subject: [PATCH 1/5] Fix crash in groups --- .../plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 017e820089..ee065546e5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -281,7 +281,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Wed, 27 Sep 2017 15:13:08 +0300 Subject: [PATCH 2/5] Add UseLocationCard to markers list; add small fixes --- OsmAnd/res/layout/map_marker_item_new.xml | 16 +- OsmAnd/res/layout/use_location_card.xml | 17 +- .../plus/mapmarkers/PlanRouteFragment.java | 14 +- .../adapters/MapMarkersListAdapter.java | 199 ++++++++++-------- 4 files changed, 156 insertions(+), 90 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 98c29f7025..96c4cff626 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -7,11 +7,21 @@ android:descendantFocusability="blocksDescendants" android:orientation="vertical"> - + tools:visibility="visible"> + + + + + + - + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index e571d25b4a..c7b7b3c709 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -27,6 +27,7 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; @@ -161,7 +162,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene toolbarController.setOnBackButtonClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - quit(false); + if (quit(false)) { + MapMarkersDialogFragment.showInstance(mapActivity); + } } }); mapActivity.showTopToolbar(toolbarController); @@ -201,7 +204,14 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); - adapter.notifyDataSetChanged(); + mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); + mapActivity.refreshMap(); + try { + adapter.notifyDataSetChanged(); + } catch (Exception e) { + // to avoid crash because of: + // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling + } } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java index 0648d29be4..8963cba67c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java @@ -22,11 +22,15 @@ import java.util.Date; import java.util.List; import java.util.Locale; -public class MapMarkersListAdapter extends RecyclerView.Adapter +public class MapMarkersListAdapter extends RecyclerView.Adapter implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter { + private static final int USE_LOCATION_CARD_TYPE = 1; + private static final int MARKER_ITEM_TYPE = 2; + private MapActivity mapActivity; private List markers; + private boolean locationCardDisplayed = true; private MapMarkersListAdapterListener listener; private LatLon location; @@ -50,107 +54,121 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter 1) { - month = Character.toUpperCase(month.charAt(0)) + month.substring(1); - } - String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date); - descr = month + " " + day; - } - holder.description.setText(descr); - if (location != null) { - holder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter - ? R.color.color_distance : R.color.color_myloc_distance)); - float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(), - marker.getLatitude(), marker.getLongitude()); - holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); + itemHolder.point.setVisibility(View.VISIBLE); + + itemHolder.iconReorder.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent event) { + if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { + listener.onDragStarted(itemHolder); + } + return false; + } + }); + + itemHolder.title.setText(marker.getName(mapActivity)); + + String descr; + if ((descr = marker.groupName) != null) { + if (descr.equals("")) { + descr = mapActivity.getString(R.string.shared_string_favorites); + } + } else { + Date date = new Date(marker.creationDate); + String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date); + if (month.length() > 1) { + month = Character.toUpperCase(month.charAt(0)) + month.substring(1); + } + String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date); + descr = month + " " + day; + } + itemHolder.description.setText(descr); + + if (location != null) { + itemHolder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter + ? R.color.color_distance : R.color.color_myloc_distance)); + float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(), + marker.getLatitude(), marker.getLongitude()); + itemHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); + } } } @Override public int getItemCount() { - return markers.size(); + return locationCardDisplayed ? markers.size() + 1 : markers.size(); } public MapMarker getItem(int position) { - return markers.get(position); + return markers.get(locationCardDisplayed ? position - 1 : position); } @Override @@ -160,7 +178,10 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter Date: Wed, 27 Sep 2017 17:14:50 +0300 Subject: [PATCH 3/5] Hide quick actions button in Plan Route mode; open markers list by default; fix small bug --- .../plus/mapmarkers/PlanRouteFragment.java | 20 +++++++++++++++++++ .../MapMarkersItemTouchHelperCallback.java | 6 ++++-- .../plus/views/MapQuickActionLayer.java | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index c7b7b3c709..eb82305124 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.mapmarkers; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; @@ -14,6 +15,7 @@ import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -221,6 +223,24 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene markersRv.setLayoutManager(new LinearLayoutManager(getContext())); markersRv.setAdapter(adapter); + if (portrait) { + showMarkersList(); + } else { + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + showMarkersList(); + + ViewTreeObserver obs = mainView.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + } + return view; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java index f8829b793c..32f08e9e0d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java @@ -132,8 +132,10 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback @Override public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { super.clearView(recyclerView, viewHolder); - ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE); - iconHidden = false; + if (iconHidden) { + ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE); + iconHidden = false; + } adapter.onItemDismiss(viewHolder); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index f5129c680a..f08e20539a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -41,6 +41,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe private final ContextMenuLayer contextMenuLayer; private final MeasurementToolLayer measurementToolLayer; + private final MapMarkersLayer mapMarkersLayer; private ImageView contextMarker; private final MapActivity mapActivity; private final OsmandApplication app; @@ -66,6 +67,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe settings = activity.getMyApplication().getSettings(); quickActionRegistry = activity.getMapLayers().getQuickActionRegistry(); measurementToolLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); + mapMarkersLayer = mapActivity.getMapLayers().getMapMarkersLayer(); } @@ -323,6 +325,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInGpxDetailsMode() || measurementToolLayer.isInMeasurementMode() || + mapMarkersLayer.isInPlanRouteMode() || mapActivity.getContextMenu().isVisible() && !mapActivity.getContextMenu().findMenuFragment().get().isRemoving() || mapActivity.getContextMenu().isVisible() && mapActivity.getContextMenu().findMenuFragment().get().isAdded() || mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() && mapActivity.getContextMenu().getMultiSelectionMenu().getFragmentByTag().isAdded() || From ae01e250a92ad6a3337d3995140135f86ba24c54 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 27 Sep 2017 18:07:03 +0300 Subject: [PATCH 4/5] Add on click listeners --- OsmAnd/res/layout/use_location_card.xml | 12 +++++------ .../plus/mapmarkers/PlanRouteFragment.java | 10 ++++++++++ .../adapters/MapMarkersListAdapter.java | 20 ++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/layout/use_location_card.xml b/OsmAnd/res/layout/use_location_card.xml index 4a54f97736..2401f4df67 100644 --- a/OsmAnd/res/layout/use_location_card.xml +++ b/OsmAnd/res/layout/use_location_card.xml @@ -69,8 +69,8 @@ + android:layout_marginLeft="44dp" + android:layout_marginStart="44dp"> Date: Wed, 27 Sep 2017 19:50:33 +0300 Subject: [PATCH 5/5] Make keyboard clickable --- .../fragment_coordinate_input_dialog.xml | 33 +++- .../layout/input_coordinate_keyboard_item.xml | 6 +- OsmAnd/res/values/colors.xml | 2 + .../net/osmand/plus/OsmandTextFieldBoxes.java | 88 ++++++++++ .../CoordinateInputDialogFragment.java | 160 +++++++++++++++--- 5 files changed, 258 insertions(+), 31 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/OsmandTextFieldBoxes.java diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index e1a67fc667..e5c17996b0 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -68,33 +68,41 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:layout_height="wrap_content" + app:labelText="@string/navigate_point_latitude"> - + - + android:layout_height="wrap_content" + app:labelText="@string/navigate_point_longitude"> - + @@ -104,17 +112,24 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:layout_height="wrap_content" + app:labelText="@string/shared_string_name"> - + + + - \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index ddca75eb3b..82634e5bfa 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -264,4 +264,6 @@ #525e66 + #545454 + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/OsmandTextFieldBoxes.java new file mode 100644 index 0000000000..77f321df5f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/OsmandTextFieldBoxes.java @@ -0,0 +1,88 @@ +package net.osmand.plus; + +import android.content.Context; +import android.support.v4.view.ViewCompat; +import android.util.AttributeSet; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; + +public class OsmandTextFieldBoxes extends TextFieldBoxes { + + private boolean useOsmandKeyboard; + + public void setUseOsmandKeyboard(boolean useOsmandKeyboard) { + this.useOsmandKeyboard = useOsmandKeyboard; + } + + public OsmandTextFieldBoxes(Context context) { + super(context); + } + + public OsmandTextFieldBoxes(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public OsmandTextFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + if (editText != null) { + this.panel.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + if(!OsmandTextFieldBoxes.this.isActivated()) { + OsmandTextFieldBoxes.this.activate(true); + } + + OsmandTextFieldBoxes.this.setHasFocus(true); + if (!useOsmandKeyboard) { + OsmandTextFieldBoxes.this.inputMethodManager.showSoftInput(OsmandTextFieldBoxes.this.editText, InputMethodManager.SHOW_IMPLICIT); + } + } + }); + + this.iconImageButton.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + select(); + } + }); + } + } + + public void select() { + if(!OsmandTextFieldBoxes.this.isActivated()) { + OsmandTextFieldBoxes.this.activate(true); + } + + OsmandTextFieldBoxes.this.setHasFocus(true); + if (!useOsmandKeyboard) { + OsmandTextFieldBoxes.this.inputMethodManager.showSoftInput(OsmandTextFieldBoxes.this.editText, InputMethodManager.SHOW_IMPLICIT); + } + } + + @Override + public void activate(boolean animated) { + super.activate(animated); + } + + @Override + protected void deactivate() { + if(this.editText.getText().toString().isEmpty()) { + ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION); + this.editTextLayout.setVisibility(View.INVISIBLE); + if(this.editText.hasFocus()) { + if (!useOsmandKeyboard) { + this.inputMethodManager.hideSoftInputFromWindow(this.editText.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); + } + this.editText.clearFocus(); + } + } + + this.activated = false; + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index e3cc6b2e56..1c9c990f18 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -2,17 +2,22 @@ package net.osmand.plus.mapmarkers; import android.content.Context; import android.os.Bundle; +import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; -import android.support.v4.content.ContextCompat; import android.support.v7.widget.Toolbar; +import android.text.Editable; import android.text.InputType; +import android.text.TextWatcher; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.GridView; @@ -20,14 +25,29 @@ import android.widget.TextView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandTextFieldBoxes; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.widgets.TextViewEx; + +import java.util.ArrayList; +import java.util.List; + +import studio.carbonylgroup.textfieldboxes.ExtendedEditText; public class CoordinateInputDialogFragment extends DialogFragment { + private static final int DELETE_BUTTON_POSITION = 9; + private static final int CLEAR_BUTTON_POSITION = 11; + public static final String TAG = "CoordinateInputDialogFragment"; private boolean lightTheme; + private EditText focusedEditText; + private boolean useOsmandKeyboard = true; + private List textFieldBoxes = new ArrayList<>(); + private List extendedEditTexts = new ArrayList<>(); @Override public void onCreate(Bundle savedInstanceState) { @@ -45,9 +65,6 @@ public class CoordinateInputDialogFragment extends DialogFragment { final MapActivity mapActivity = getMapActivity(); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.coordinate_input_toolbar); - if (!lightTheme) { - toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color)); - } toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @@ -64,47 +81,141 @@ public class CoordinateInputDialogFragment extends DialogFragment { } }); - final EditText latitudeEditText = (EditText) mainView.findViewById(R.id.latitude_edit_text); - final EditText longitudeEditText = (EditText) mainView.findViewById(R.id.longitude_edit_text); - final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text); + 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); + textFieldBoxes.add(nameBox); - View.OnTouchListener editTextOnTouchListener = new View.OnTouchListener() { + final ExtendedEditText latitudeEditText = (ExtendedEditText) mainView.findViewById(R.id.latitude_edit_text); + extendedEditTexts.add(latitudeEditText); + final ExtendedEditText longitudeEditText = (ExtendedEditText) mainView.findViewById(R.id.longitude_edit_text); + extendedEditTexts.add(longitudeEditText); + final ExtendedEditText nameEditText = (ExtendedEditText) mainView.findViewById(R.id.name_edit_text); + extendedEditTexts.add(nameEditText); + + final View.OnFocusChangeListener focusChangeListener = new View.OnFocusChangeListener() { @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - EditText editText = null; + public void onFocusChange(View view, boolean b) { + ExtendedEditText editText = null; + OsmandTextFieldBoxes fieldBox = null; switch (view.getId()) { case R.id.latitude_edit_text: editText = latitudeEditText; + fieldBox = latitudeBox; break; case R.id.longitude_edit_text: editText = longitudeEditText; + fieldBox = longitudeBox; break; case R.id.name_edit_text: editText = nameEditText; + fieldBox = nameBox; break; } - if (editText != null) { - editText.requestFocus(); + if (fieldBox != null) { + if (b) { + fieldBox.setHasFocus(true); + focusedEditText = editText; + } else { + fieldBox.setHasFocus(false); + focusedEditText = null; + } } - return true; } }; - latitudeEditText.setOnTouchListener(editTextOnTouchListener); - longitudeEditText.setOnTouchListener(editTextOnTouchListener); - nameEditText.setOnTouchListener(editTextOnTouchListener); + TextWatcher textWatcher = new TextWatcher() { + int len = 0; + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + if (focusedEditText != null) { + String str = focusedEditText.getText().toString(); + len = str.length(); + } + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + if (focusedEditText != null) { + String str = focusedEditText.getText().toString(); + if(str.length() == 2 && len < str.length()){ + focusedEditText.append(":"); + } else if (str.length() == 5 && len < str.length()) { + focusedEditText.append("."); + } else if (str.length() == 10) { + if (focusedEditText == latitudeEditText) { + longitudeBox.select(); + } else if (focusedEditText == longitudeEditText) { + nameBox.select(); + } + } + } + } + }; + + latitudeEditText.setOnFocusChangeListener(focusChangeListener); + longitudeEditText.setOnFocusChangeListener(focusChangeListener); + nameEditText.setOnFocusChangeListener(focusChangeListener); + + latitudeEditText.addTextChangedListener(textWatcher); + longitudeEditText.addTextChangedListener(textWatcher); + nameEditText.addTextChangedListener(textWatcher); + + changeKeyboardInBoxes(useOsmandKeyboard); + changeKeyboardInEditTexts(useOsmandKeyboard); String[] keyboardItems = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", getString(R.string.shared_string_delete), "0", getString(R.string.shared_string_clear) }; - GridView keyboardGrid = (GridView) mainView.findViewById(R.id.keyboard_grid_view); - KeyboardAdapter keyboardAdapter = new KeyboardAdapter(mapActivity, keyboardItems); + final GridView keyboardGrid = (GridView) mainView.findViewById(R.id.keyboard_grid_view); + 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 (focusedEditText != null) { + switch (i) { + case DELETE_BUTTON_POSITION: + String str = focusedEditText.getText().toString(); + if (str.length() > 0) { + str = str.substring(0, str.length() - 1); + focusedEditText.setText(str); + } + break; + case CLEAR_BUTTON_POSITION: + focusedEditText.setText(""); + break; + default: + focusedEditText.append(keyboardAdapter.getItem(i)); + } + } + } + }); return mainView; } + public void changeKeyboardInBoxes(boolean useOsmandKeyboard) { + for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) { + textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard); + } + } + + public void changeKeyboardInEditTexts(boolean useOsmandKeyboard) { + for (ExtendedEditText extendedEditText : extendedEditTexts) { + extendedEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT); + } + } + private MapActivity getMapActivity() { return (MapActivity) getActivity(); } @@ -128,8 +239,8 @@ public class CoordinateInputDialogFragment extends DialogFragment { private class KeyboardAdapter extends ArrayAdapter { - KeyboardAdapter(@NonNull Context context, String[] items) { - super(context, 0, items); + KeyboardAdapter(@NonNull Context context, @NonNull String[] objects) { + super(context, 0, objects); } @NonNull @@ -139,7 +250,14 @@ public class CoordinateInputDialogFragment extends DialogFragment { convertView = LayoutInflater.from(getContext()).inflate(R.layout.input_coordinate_keyboard_item, parent, false); } - ((TextView) convertView.findViewById(R.id.keyboard_item)).setText(getItem(position)); + TextViewEx keyboardItem = (TextViewEx) convertView.findViewById(R.id.keyboard_item); + if (position == DELETE_BUTTON_POSITION || position == CLEAR_BUTTON_POSITION) { + keyboardItem.setTextSize(getResources().getDimension(R.dimen.default_list_text_size)); + } else { + keyboardItem.setTextSize(getResources().getDimension(R.dimen.map_button_text_size)); + } + + keyboardItem.setText(getItem(position)); return convertView; }