Change coordinate input options menu; add settings; add some refactoring and improvements

This commit is contained in:
Alexander Sytnyk 2018-02-15 17:18:29 +02:00
parent 06f3ae09c6
commit 8b79747599
6 changed files with 177 additions and 257 deletions

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
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/content_padding_small"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding_small"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/icon_iv"
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/name_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="@string/dd_mm_mmm_format"/>
<RadioButton
android:id="@+id/radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:saveEnabled="false"/>
</LinearLayout>

View file

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<LinearLayout
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="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<ScrollView
android:id="@+id/marker_coordinate_input_scroll_view"
@ -54,6 +55,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
@ -94,6 +97,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
@ -101,15 +106,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<net.osmand.plus.widgets.TextViewEx
osmand:typeface="@string/font_roboto_medium"
android:id="@+id/hand_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:maxLines="1"
android:textSize="@dimen/default_list_text_size"
tools:textColor="@color/map_widget_blue_pressed"
tools:text="Right"/>
osmand:typeface="@string/font_roboto_medium"
tools:text="Right"
tools:textColor="@color/map_widget_blue_pressed"/>
</LinearLayout>
<View
@ -117,108 +122,22 @@
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:id="@+id/go_to_next_field_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/go_to_next_field_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_keyboard"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/go_to_next_field"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/go_to_next_field_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<TextView
android:id="@+id/coordinate_input_accuracy_descr"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_descr_height"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/bottom_sheet_divider_margin_start"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/bottom_sheet_divider_margin_start"
android:paddingTop="@dimen/content_padding_small"
android:text="@string/coordinates_format"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="@string/coordinate_input_accuracy_description"/>
android:textSize="@dimen/default_desc_text_size"/>
<LinearLayout
android:id="@+id/accuracy_row"
android:id="@+id/formats_container"
android:layout_width="match_parent"
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/content_padding"
android:paddingLeft="@dimen/bottom_sheet_divider_margin_start"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/bottom_sheet_divider_margin_start">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:text="@string/digits_quantity"/>
<TextView
android:id="@+id/selected_accuracy_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="00:00.0"/>
</LinearLayout>
<TextView
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/selected_accuracy"
tools:text="1"/>
<ImageView
android:id="@+id/accuracy_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:src="@drawable/ic_action_arrow_drop_down"/>
</LinearLayout>
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>
@ -246,4 +165,4 @@
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>

View file

@ -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<Boolean> SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile();
public final CommonPreference<Boolean> COORDS_INPUT_USE_RIGHT_SIDE = new BooleanPreference("coords_input_use_right_side", true).makeGlobal();
public final CommonPreference<Integer> COORDS_INPUT_FORMAT = new IntPreference("coords_input_format", CoordinateInputFormats.DD_MM_MMM);
public final CommonPreference<Boolean> USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal();

View file

@ -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<Boolean> 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();
}
}

View file

@ -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();
}
};
}

View file

@ -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 "";
}
}