Add support for different coordinate formats
This commit is contained in:
parent
7c8e39d0eb
commit
e72d419e9a
5 changed files with 332 additions and 247 deletions
|
@ -77,7 +77,6 @@
|
|||
|
||||
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||
android:hint="50:00.0000"
|
||||
android:maxLength="10"
|
||||
android:id="@+id/latitude_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
@ -97,7 +96,6 @@
|
|||
|
||||
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||
android:hint="50:00.0000"
|
||||
android:maxLength="10"
|
||||
android:id="@+id/longitude_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
|
|
@ -42,230 +42,197 @@
|
|||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/degrees_frame"
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/degrees_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height">
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
|
||||
<LinearLayout
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/degrees_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
<ImageView
|
||||
android:id="@+id/degrees_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/degrees_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
<TextView
|
||||
android:id="@+id/degrees_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="DDD.DD"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/degrees_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="DDD.DD"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
<RadioButton
|
||||
android:id="@+id/degrees_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/degrees_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/minutes_frame"
|
||||
<LinearLayout
|
||||
android:id="@+id/minutes_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height">
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
|
||||
<LinearLayout
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/minutes_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
<ImageView
|
||||
android:id="@+id/minutes_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/minutes_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
<TextView
|
||||
android:id="@+id/minutes_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="DDD MM.MM"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/minutes_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="DDD MM.MM"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
<RadioButton
|
||||
android:id="@+id/minutes_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/minutes_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/seconds_frame"
|
||||
<LinearLayout
|
||||
android:id="@+id/seconds_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height">
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
|
||||
<LinearLayout
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/seconds_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
<ImageView
|
||||
android:id="@+id/seconds_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/seconds_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
<TextView
|
||||
android:id="@+id/seconds_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="DDD MM SS.SS"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/seconds_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="DDD MM SS.SS"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
<RadioButton
|
||||
android:id="@+id/seconds_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/seconds_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/utm_frame"
|
||||
<LinearLayout
|
||||
android:id="@+id/utm_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height">
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
|
||||
<LinearLayout
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/utm_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
<ImageView
|
||||
android:id="@+id/utm_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/utm_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
<TextView
|
||||
android:id="@+id/utm_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="UTM"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/utm_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="UTM"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
<RadioButton
|
||||
android:id="@+id/utm_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/utm_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/olc_frame"
|
||||
<LinearLayout
|
||||
android:id="@+id/olc_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height">
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
|
||||
<LinearLayout
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/olc_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding">
|
||||
<ImageView
|
||||
android:id="@+id/olc_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/olc_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_coordinates_latitude"/>
|
||||
<TextView
|
||||
android:id="@+id/olc_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="OLC"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/olc_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
tools:text="OLC"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/olc_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
<RadioButton
|
||||
android:id="@+id/olc_radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
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
|
||||
-->
|
||||
<string name="fast_coordinates_input_descr">Choose oordinate format before start. YOu can always change it by tapping Options.</string>
|
||||
<string name="fast_coordinates_input_descr">Choose coordinate format before start. You can always change it by tapping Options.</string>
|
||||
<string name="fast_coordinates_input">Fast Coordinates input</string>
|
||||
<string name="use_location">Use location</string>
|
||||
<string name="add_location_as_first_point_descr">Add your location as first point to plan perfect route.</string>
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -22,8 +23,6 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public final static String TAG = "CoordinateInputBottomSheetDialogFragment";
|
||||
|
@ -31,15 +30,20 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
private boolean portrait;
|
||||
private View mainView;
|
||||
private boolean night;
|
||||
private int coordinateFormat = -1;
|
||||
private CoordinateInputFormatChangeListener listener;
|
||||
|
||||
private Format currentFormat = Format.DEGREES;
|
||||
public void setListener(CoordinateInputFormatChangeListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private enum Format {
|
||||
DEGREES,
|
||||
MINUTES,
|
||||
SECONDS,
|
||||
UTM,
|
||||
OLC
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
coordinateFormat = getArguments().getInt(CoordinateInputDialogFragment.COORDINATE_FORMAT, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -61,49 +65,89 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
|
||||
ImageView degreesIcon = (ImageView) mainView.findViewById(R.id.degrees_icon);
|
||||
TextView degreesText = (TextView) mainView.findViewById(R.id.degrees_text);
|
||||
if (currentFormat == Format.DEGREES) {
|
||||
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
||||
degreesIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue));
|
||||
degreesText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue));
|
||||
} else {
|
||||
degreesIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude));
|
||||
}
|
||||
degreesText.setText(PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_DEGREES));
|
||||
|
||||
ImageView minutesIcon = (ImageView) mainView.findViewById(R.id.minutes_icon);
|
||||
TextView minutesText = (TextView) mainView.findViewById(R.id.minutes_text);
|
||||
if (currentFormat == Format.MINUTES) {
|
||||
if (coordinateFormat == PointDescription.FORMAT_MINUTES) {
|
||||
minutesIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue));
|
||||
minutesText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue));
|
||||
} else {
|
||||
minutesIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude));
|
||||
}
|
||||
minutesText.setText(PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_MINUTES));
|
||||
|
||||
ImageView secondsIcon = (ImageView) mainView.findViewById(R.id.seconds_icon);
|
||||
TextView secondsText = (TextView) mainView.findViewById(R.id.seconds_text);
|
||||
if (currentFormat == Format.SECONDS) {
|
||||
if (coordinateFormat == PointDescription.FORMAT_SECONDS) {
|
||||
secondsIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue));
|
||||
secondsText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue));
|
||||
} else {
|
||||
secondsIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude));
|
||||
}
|
||||
secondsText.setText(PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_SECONDS));
|
||||
|
||||
ImageView utmIcon = (ImageView) mainView.findViewById(R.id.utm_icon);
|
||||
TextView utmText = (TextView) mainView.findViewById(R.id.utm_text);
|
||||
if (currentFormat == Format.UTM) {
|
||||
if (coordinateFormat == PointDescription.UTM_FORMAT) {
|
||||
utmIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue));
|
||||
utmText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue));
|
||||
} else {
|
||||
utmIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude));
|
||||
}
|
||||
utmText.setText(PointDescription.formatToHumanString(getContext(), PointDescription.UTM_FORMAT));
|
||||
|
||||
ImageView olcIcon = (ImageView) mainView.findViewById(R.id.olc_icon);
|
||||
TextView olcText = (TextView) mainView.findViewById(R.id.olc_text);
|
||||
if (currentFormat == Format.OLC) {
|
||||
if (coordinateFormat == PointDescription.OLC_FORMAT) {
|
||||
olcIcon.setImageDrawable(getIcon(R.drawable.ic_action_coordinates_latitude, R.color.dashboard_blue));
|
||||
olcText.setTextColor(ContextCompat.getColor(mapActivity, R.color.dashboard_blue));
|
||||
} else {
|
||||
olcIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_latitude));
|
||||
}
|
||||
olcText.setText(PointDescription.formatToHumanString(getContext(), PointDescription.OLC_FORMAT));
|
||||
|
||||
((TextView) mainView.findViewById(R.id.degrees_text)).setText(PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_DEGREES));
|
||||
((TextView) mainView.findViewById(R.id.minutes_text)).setText(PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_MINUTES));
|
||||
((TextView) mainView.findViewById(R.id.seconds_text)).setText(PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_SECONDS));
|
||||
((TextView) mainView.findViewById(R.id.utm_text)).setText(PointDescription.formatToHumanString(getContext(), PointDescription.UTM_FORMAT));
|
||||
((TextView) mainView.findViewById(R.id.olc_text)).setText(PointDescription.formatToHumanString(getContext(), PointDescription.OLC_FORMAT));
|
||||
View.OnClickListener formatChangeListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int format;
|
||||
switch (view.getId()) {
|
||||
case R.id.degrees_row:
|
||||
format = PointDescription.FORMAT_DEGREES;
|
||||
break;
|
||||
case R.id.minutes_row:
|
||||
format = PointDescription.FORMAT_MINUTES;
|
||||
break;
|
||||
case R.id.seconds_row:
|
||||
format = PointDescription.FORMAT_SECONDS;
|
||||
break;
|
||||
case R.id.utm_row:
|
||||
format = PointDescription.UTM_FORMAT;
|
||||
break;
|
||||
case R.id.olc_row:
|
||||
format = PointDescription.OLC_FORMAT;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported format");
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onCoordinateFormatChanged(format);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
mainView.findViewById(R.id.degrees_row).setOnClickListener(formatChangeListener);
|
||||
mainView.findViewById(R.id.minutes_row).setOnClickListener(formatChangeListener);
|
||||
mainView.findViewById(R.id.seconds_row).setOnClickListener(formatChangeListener);
|
||||
mainView.findViewById(R.id.utm_row).setOnClickListener(formatChangeListener);
|
||||
mainView.findViewById(R.id.olc_row).setOnClickListener(formatChangeListener);
|
||||
|
||||
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -119,7 +163,7 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
final View scrollView = mainView.findViewById(R.id.marker_show_direction_scroll_view);
|
||||
final View scrollView = mainView.findViewById(R.id.marker_coordinate_input_scroll_view);
|
||||
int scrollViewHeight = scrollView.getHeight();
|
||||
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
|
||||
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
|
||||
|
@ -167,4 +211,8 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
protected Drawable getContentIcon(@DrawableRes int id) {
|
||||
return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
|
||||
}
|
||||
|
||||
interface CoordinateInputFormatChangeListener {
|
||||
void onCoordinateFormatChanged(int format);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,33 +2,29 @@ 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.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
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;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.data.PointDescription;
|
||||
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;
|
||||
|
@ -38,16 +34,23 @@ import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
|||
|
||||
public class CoordinateInputDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String TAG = "CoordinateInputDialogFragment";
|
||||
|
||||
public static final String COORDINATE_FORMAT = "coordinate_format";
|
||||
|
||||
private static final int DELETE_BUTTON_POSITION = 9;
|
||||
private static final int CLEAR_BUTTON_POSITION = 11;
|
||||
|
||||
public static final String TAG = "CoordinateInputDialogFragment";
|
||||
private static final int DEGREES_MAX_LENGTH = 8;
|
||||
private static final int MINUTES_MAX_LENGTH = 10;
|
||||
private static final int SECONDS_MAX_LENGTH = 13;
|
||||
|
||||
private boolean lightTheme;
|
||||
private EditText focusedEditText;
|
||||
private boolean useOsmandKeyboard = true;
|
||||
private List<OsmandTextFieldBoxes> textFieldBoxes = new ArrayList<>();
|
||||
private List<ExtendedEditText> extendedEditTexts = new ArrayList<>();
|
||||
private List<OsmandTextFieldBoxes> textFieldBoxes;
|
||||
private ExtendedEditText nameEditText;
|
||||
private List<ExtendedEditText> extendedLatLonEditTexts;
|
||||
private int coordinateFormat = -1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -57,8 +60,11 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
|
||||
setStyle(STYLE_NO_FRAME, themeId);
|
||||
|
||||
CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment();
|
||||
fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG);
|
||||
if (coordinateFormat == -1) {
|
||||
CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment();
|
||||
fragment.setListener(createCoordinateInputFormatChangeListener());
|
||||
fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -67,6 +73,13 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
final View mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container);
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
|
||||
if (coordinateFormat == -1) {
|
||||
Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG);
|
||||
if (coordinateInputBottomSheetDialogFragment != null) {
|
||||
((CoordinateInputBottomSheetDialogFragment) coordinateInputBottomSheetDialogFragment).setListener(createCoordinateInputFormatChangeListener());
|
||||
}
|
||||
}
|
||||
|
||||
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.coordinate_input_toolbar);
|
||||
|
||||
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back));
|
||||
|
@ -80,10 +93,16 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
optionsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(COORDINATE_FORMAT, coordinateFormat);
|
||||
fragment.setArguments(args);
|
||||
fragment.setListener(createCoordinateInputFormatChangeListener());
|
||||
fragment.show(getMapActivity().getSupportFragmentManager(), 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);
|
||||
|
@ -91,12 +110,12 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
final OsmandTextFieldBoxes nameBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box);
|
||||
textFieldBoxes.add(nameBox);
|
||||
|
||||
extendedLatLonEditTexts = new ArrayList<>();
|
||||
final ExtendedEditText latitudeEditText = (ExtendedEditText) mainView.findViewById(R.id.latitude_edit_text);
|
||||
extendedEditTexts.add(latitudeEditText);
|
||||
extendedLatLonEditTexts.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);
|
||||
extendedLatLonEditTexts.add(longitudeEditText);
|
||||
nameEditText = (ExtendedEditText) mainView.findViewById(R.id.name_edit_text);
|
||||
|
||||
final View.OnFocusChangeListener focusChangeListener = new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
|
@ -147,16 +166,33 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (focusedEditText != null) {
|
||||
if (focusedEditText != null && focusedEditText != nameEditText) {
|
||||
String str = focusedEditText.getText().toString();
|
||||
if(str.length() == 2 && len < str.length()){
|
||||
focusedEditText.append(":");
|
||||
} else if (str.length() == 5 && len < str.length()) {
|
||||
int strLength = str.length();
|
||||
if (strLength == 2 && len < strLength) {
|
||||
String strToAppend;
|
||||
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
||||
strToAppend = ".";
|
||||
} else {
|
||||
strToAppend = ":";
|
||||
}
|
||||
focusedEditText.append(strToAppend);
|
||||
} else if (strLength == 5 && coordinateFormat != PointDescription.FORMAT_DEGREES && len < strLength) {
|
||||
String strToAppend;
|
||||
if (coordinateFormat == PointDescription.FORMAT_MINUTES) {
|
||||
strToAppend = ".";
|
||||
} else {
|
||||
strToAppend = ":";
|
||||
}
|
||||
focusedEditText.append(strToAppend);
|
||||
} else if (strLength == 8 && coordinateFormat == PointDescription.FORMAT_SECONDS && len < strLength) {
|
||||
focusedEditText.append(".");
|
||||
} else if (str.length() == 10) {
|
||||
} else if ((strLength == DEGREES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_DEGREES)
|
||||
|| (strLength == MINUTES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_MINUTES)
|
||||
|| (strLength == SECONDS_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_SECONDS)) {
|
||||
if (focusedEditText == latitudeEditText) {
|
||||
longitudeBox.select();
|
||||
} else if (focusedEditText == longitudeEditText) {
|
||||
} else {
|
||||
nameBox.select();
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +243,40 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
focusedEditText = null;
|
||||
if (getDialog() != null && getRetainInstance()) {
|
||||
getDialog().setDismissMessage(null);
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() {
|
||||
return new CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener() {
|
||||
@Override
|
||||
public void onCoordinateFormatChanged(int format) {
|
||||
coordinateFormat = format;
|
||||
changeEditTextLengths();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void changeEditTextLengths() {
|
||||
int maxLength;
|
||||
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
||||
maxLength = DEGREES_MAX_LENGTH;
|
||||
} else if (coordinateFormat == PointDescription.FORMAT_MINUTES) {
|
||||
maxLength = MINUTES_MAX_LENGTH;
|
||||
} else {
|
||||
maxLength = SECONDS_MAX_LENGTH;
|
||||
}
|
||||
InputFilter[] filtersArray = new InputFilter[] {new InputFilter.LengthFilter(maxLength)};
|
||||
for (ExtendedEditText extendedEditText : extendedLatLonEditTexts) {
|
||||
extendedEditText.setFilters(filtersArray);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeKeyboardInBoxes(boolean useOsmandKeyboard) {
|
||||
for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) {
|
||||
textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard);
|
||||
|
@ -214,9 +284,10 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
public void changeKeyboardInEditTexts(boolean useOsmandKeyboard) {
|
||||
for (ExtendedEditText extendedEditText : extendedEditTexts) {
|
||||
for (ExtendedEditText extendedEditText : extendedLatLonEditTexts) {
|
||||
extendedEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
nameEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
|
@ -233,6 +304,7 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
return false;
|
||||
}
|
||||
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
|
|
Loading…
Reference in a new issue