use of net.osmand.plus.mapmarkers.CoordinateInputFormats.Format in project Osmand by osmandapp.
the class CoordinateInputDialogFragment method enterEditingMode.
private void enterEditingMode(WptPt wptPt) {
selectedWpt = wptPt;
Format format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
double lat = Math.abs(wptPt.lat);
double lon = Math.abs(wptPt.lon);
if (format == Format.DD_MM_MMM || format == Format.DD_MM_MMMM) {
int accuracy = format.getThirdPartSymbolsCount();
updateInputsDdm(true, CoordinateInputFormats.ddToDdm(lat), accuracy);
updateInputsDdm(false, CoordinateInputFormats.ddToDdm(lon), accuracy);
} else if (format == Format.DD_DDDDD || format == Format.DD_DDDDDD) {
int accuracy = format.getSecondPartSymbolsCount();
updateInputsDd(true, lat, accuracy);
updateInputsDd(false, lon, accuracy);
} else if (format == Format.DD_MM_SS) {
updateInputsDms(true, CoordinateInputFormats.ddToDms(lat));
updateInputsDms(false, CoordinateInputFormats.ddToDms(lon));
}
boolean latPositive = wptPt.lat > 0;
if ((latPositive && !north) || (!latPositive && north)) {
updateSideOfTheWorldBtn(mainView.findViewById(R.id.lat_side_of_the_world_btn), true);
}
boolean lonPositive = wptPt.lon > 0;
if ((lonPositive && !east) || (!lonPositive && east)) {
updateSideOfTheWorldBtn(mainView.findViewById(R.id.lon_side_of_the_world_btn), true);
}
((EditText) mainView.findViewById(R.id.point_name_et)).setText(wptPt.name);
((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_edit_point);
TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button);
addButton.setText(R.string.shared_string_apply);
@ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_apply, colorId), null);
showKeyboard();
}
use of net.osmand.plus.mapmarkers.CoordinateInputFormats.Format in project Osmand by osmandapp.
the class CoordinateInputDialogFragment method getStringCoordinate.
private String getStringCoordinate(boolean latitude) {
String firstPart = ((EditText) mainView.findViewById(latitude ? R.id.lat_first_input_et : R.id.lon_first_input_et)).getText().toString();
String secondPart = ((EditText) mainView.findViewById(latitude ? R.id.lat_second_input_et : R.id.lon_second_input_et)).getText().toString();
String thirdPart = ((EditText) mainView.findViewById(latitude ? R.id.lat_third_input_et : R.id.lon_third_input_et)).getText().toString();
if (firstPart.isEmpty() && secondPart.isEmpty() && thirdPart.isEmpty()) {
return "";
}
if (firstPart.isEmpty()) {
firstPart = "0";
}
if (secondPart.isEmpty()) {
secondPart = "0";
}
Format format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
StringBuilder res = new StringBuilder();
if ((latitude && !north) || (!latitude && !east)) {
res.append("-");
}
res.append(firstPart);
if (!secondPart.isEmpty()) {
res.append(format.getFirstSeparator()).append(secondPart);
}
if (!thirdPart.isEmpty() && format.isContainsThirdPart()) {
res.append(format.getSecondSeparator()).append(thirdPart);
}
return res.toString();
}
use of net.osmand.plus.mapmarkers.CoordinateInputFormats.Format in project Osmand by osmandapp.
the class CoordinateInputBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext();
final OsmandSettings settings = getMyApplication().getSettings();
items.add(new TitleItem(getString(R.string.shared_string_options)));
BaseBottomSheetItem editItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_save_to_file)).setTitle(getString(R.string.coord_input_save_as_track)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.saveAsTrack();
}
dismiss();
}
}).create();
items.add(editItem);
items.add(new DividerHalfItem(context));
boolean useOsmandKeyboard = settings.COORDS_INPUT_USE_OSMAND_KEYBOARD.get();
BaseBottomSheetItem useSystemKeyboardItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(!useOsmandKeyboard).setIcon(getContentIcon(R.drawable.ic_action_keyboard)).setTitle(getString(R.string.use_system_keyboard)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onKeyboardChanged();
}
dismiss();
}
}).create();
items.add(useSystemKeyboardItem);
boolean useTwoDigitsLogtitude = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get();
BaseBottomSheetItem twoDigitsLongtitudeItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(useTwoDigitsLogtitude).setIcon(getContentIcon(R.drawable.ic_action_next_field_stroke)).setTitle(getString(R.string.use_two_digits_longitude)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
pref.set(!pref.get());
listener.onInputSettingsChanged();
}
dismiss();
}
}).create();
items.add(twoDigitsLongtitudeItem);
if (!AndroidUiHelper.isOrientationPortrait(getActivity())) {
boolean rightHand = settings.COORDS_INPUT_USE_RIGHT_SIDE.get();
BaseBottomSheetItem showNumberPadItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(rightHand ? R.string.shared_string_right : R.string.shared_string_left)).setDescriptionColorId(getActiveColorId()).setIcon(getContentIcon(rightHand ? R.drawable.ic_action_show_keypad_right : R.drawable.ic_action_show_keypad_left)).setTitle(getString(R.string.show_number_pad)).setLayoutId(R.layout.bottom_sheet_item_with_right_descr).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
CommonPreference<Boolean> pref = settings.COORDS_INPUT_USE_RIGHT_SIDE;
pref.set(!pref.get());
listener.onHandChanged();
}
dismiss();
}
}).create();
items.add(showNumberPadItem);
}
items.add(new SubtitleDividerItem(context));
items.add(new SubtitleItem(getString(R.string.coordinates_format)));
Format selectedFormat = settings.COORDS_INPUT_FORMAT.get();
Drawable formatIcon = getContentIcon(R.drawable.ic_action_coordinates_latitude);
View.OnClickListener formatsOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Format format = (Format) v.getTag();
settings.COORDS_INPUT_FORMAT.set(format);
if (listener != null) {
listener.onInputSettingsChanged();
}
dismiss();
}
};
for (Format format : Format.values()) {
boolean selectedItem = format == selectedFormat;
BaseBottomSheetItem formatItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(selectedItem).setButtonTintList(selectedItem ? ColorStateList.valueOf(getResolvedColor(getActiveColorId())) : null).setIcon(selectedItem ? getActiveIcon(R.drawable.ic_action_coordinates_latitude) : formatIcon).setTitle(format.toHumanString(context)).setTitleColorId(selectedItem ? getActiveColorId() : BaseBottomSheetItem.INVALID_ID).setLayoutId(R.layout.bottom_sheet_item_with_radio_btn).setOnClickListener(formatsOnClickListener).setTag(format).create();
items.add(formatItem);
}
}
use of net.osmand.plus.mapmarkers.CoordinateInputFormats.Format in project Osmand by osmandapp.
the class CoordinateInputDialogFragment method registerInputs.
private void registerInputs() {
TextWatcher textWatcher = new TextWatcher() {
private int strLength;
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
strLength = charSequence.length();
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
View focusedView = getDialog().getCurrentFocus();
if (focusedView != null && focusedView instanceof EditTextEx) {
EditTextEx et = (EditTextEx) focusedView;
int currentLength = et.getText().length();
if (et.getId() == R.id.lon_first_input_et) {
String lonFirstInput = et.getText().toString();
if (currentLength == 2) {
if (lonFirstInput.charAt(0) != '1' && lonFirstInput.charAt(0) != '0') {
switchEditText(et.getId(), true);
}
}
}
if (et.getMaxSymbolsCount() > 0 && currentLength > strLength && currentLength >= et.getMaxSymbolsCount()) {
switchEditText(et.getId(), true);
}
}
}
};
final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
return true;
}
});
View.OnTouchListener inputEditTextOnTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (isOsmandKeyboardOn()) {
if (!isOsmandKeyboardCurrentlyVisible()) {
if (softKeyboardShown) {
if (view.getId() != R.id.point_name_et) {
AndroidUtils.hideSoftKeyboard(getActivity(), view);
shouldShowOsmandKeyboard = true;
} else {
return false;
}
} else {
changeOsmandKeyboardVisibility(true);
}
}
EditText editText = (EditText) view;
int inputType = editText.getInputType();
editText.setInputType(InputType.TYPE_NULL);
boolean doubleTap = gestureDetector.onTouchEvent(motionEvent);
if (!doubleTap) {
editText.onTouchEvent(motionEvent);
editText.setSelection(editText.getText().length());
}
editText.setInputType(inputType);
return true;
} else {
if (isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false);
}
return false;
}
}
};
View.OnLongClickListener inputEditTextOnLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(final View view) {
if (isOsmandKeyboardOn()) {
final EditText inputEditText = (EditText) view;
PopupMenu popupMenu = new PopupMenu(getContext(), inputEditText);
Menu menu = popupMenu.getMenu();
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
MenuItem pasteMenuItem = menu.findItem(R.id.action_paste);
if (clipboardManager == null || !clipboardManager.hasPrimaryClip() || !clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
pasteMenuItem.setEnabled(false);
} else {
pasteMenuItem.setEnabled(true);
}
if (clipboardManager != null) {
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int i = item.getItemId();
if (i == R.id.action_copy) {
ClipData clip = ClipData.newPlainText("", inputEditText.getText().toString());
clipboardManager.setPrimaryClip(clip);
return true;
} else if (i == R.id.action_paste) {
ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0);
CharSequence pasteData = pasteItem.getText();
if (pasteData != null) {
String str = inputEditText.getText().toString();
inputEditText.setText(str + pasteData.toString());
inputEditText.setSelection(inputEditText.getText().length());
}
return true;
}
return false;
}
});
popupMenu.show();
}
return true;
} else {
return false;
}
}
};
TextView.OnEditorActionListener inputTextViewOnEditorActionListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
switchEditText(textView.getId(), true);
} else if (i == EditorInfo.IME_ACTION_DONE) {
addWptPt();
hasUnsavedChanges = true;
}
return false;
}
};
clearInputs();
Format format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
boolean useTwoDigitsLongtitude = getMyApplication().getSettings().COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get();
setupEditTextEx(R.id.lat_first_input_et, format.getFirstPartSymbolsCount(true, useTwoDigitsLongtitude), true);
setupEditTextEx(R.id.lon_first_input_et, format.getFirstPartSymbolsCount(false, useTwoDigitsLongtitude), false);
String firstSeparator = format.getFirstSeparator();
((TextView) mainView.findViewById(R.id.lat_first_separator_tv)).setText(firstSeparator);
((TextView) mainView.findViewById(R.id.lon_first_separator_tv)).setText(firstSeparator);
int secondPartSymbols = format.getSecondPartSymbolsCount();
setupEditTextEx(R.id.lat_second_input_et, secondPartSymbols, true);
setupEditTextEx(R.id.lon_second_input_et, secondPartSymbols, false);
boolean containsThirdPart = format.isContainsThirdPart();
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 = format.getSecondSeparator();
((TextView) mainView.findViewById(R.id.lat_second_separator_tv)).setText(secondSeparator);
((TextView) mainView.findViewById(R.id.lon_second_separator_tv)).setText(secondSeparator);
int thirdPartSymbols = format.getThirdPartSymbolsCount();
setupEditTextEx(R.id.lat_third_input_et, thirdPartSymbols, true);
setupEditTextEx(R.id.lon_third_input_et, thirdPartSymbols, false);
}
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.lon_first_input_et) {
((LinearLayout.LayoutParams) et.getLayoutParams()).weight = editTexts.get(0).getMaxSymbolsCount();
et.requestLayout();
}
if (et.getId() != R.id.point_name_et) {
et.addTextChangedListener(textWatcher);
} else {
et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus && isOsmandKeyboardOn() && (isOsmandKeyboardCurrentlyVisible() || softKeyboardShown)) {
AndroidUtils.hideSoftKeyboard(getActivity(), v);
}
}
});
}
et.setOnTouchListener(inputEditTextOnTouchListener);
et.setOnLongClickListener(inputEditTextOnLongClickListener);
et.setOnEditorActionListener(inputTextViewOnEditorActionListener);
}
changeEditTextSelections();
editTexts.get(0).requestFocus();
}
Aggregations