Add auto switching to the next edit text
This commit is contained in:
parent
69c0a12a6e
commit
900796df8e
4 changed files with 82 additions and 50 deletions
|
@ -80,17 +80,17 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/lat_first_input_et"
|
android:id="@+id/lat_first_input_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:hint="xx"
|
|
||||||
android:imeOptions="actionNext"
|
android:imeOptions="actionNext"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:maxLength="2"
|
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:theme="@style/CoordinateInputEditText"/>
|
android:theme="@style/CoordinateInputEditText"
|
||||||
|
tools:hint="xx"
|
||||||
|
tools:maxLength="2"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/lat_first_separator_tv"
|
android:id="@+id/lat_first_separator_tv"
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
android:textSize="@dimen/dialog_header_text_size"
|
android:textSize="@dimen/dialog_header_text_size"
|
||||||
tools:text="°"/>
|
tools:text="°"/>
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/lat_second_input_et"
|
android:id="@+id/lat_second_input_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -122,7 +122,7 @@
|
||||||
android:textSize="@dimen/dialog_header_text_size"
|
android:textSize="@dimen/dialog_header_text_size"
|
||||||
tools:text="."/>
|
tools:text="."/>
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/lat_third_input_et"
|
android:id="@+id/lat_third_input_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -224,17 +224,17 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/lon_first_input_et"
|
android:id="@+id/lon_first_input_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:hint="yy"
|
|
||||||
android:imeOptions="actionNext"
|
android:imeOptions="actionNext"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:maxLength="2"
|
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:theme="@style/CoordinateInputEditText"/>
|
android:theme="@style/CoordinateInputEditText"
|
||||||
|
tools:hint="yy"
|
||||||
|
tools:maxLength="2"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/lon_first_separator_tv"
|
android:id="@+id/lon_first_separator_tv"
|
||||||
|
@ -245,7 +245,7 @@
|
||||||
android:textSize="@dimen/dialog_header_text_size"
|
android:textSize="@dimen/dialog_header_text_size"
|
||||||
tools:text="°"/>
|
tools:text="°"/>
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/lon_second_input_et"
|
android:id="@+id/lon_second_input_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -266,7 +266,7 @@
|
||||||
android:textSize="@dimen/dialog_header_text_size"
|
android:textSize="@dimen/dialog_header_text_size"
|
||||||
tools:text="."/>
|
tools:text="."/>
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/lon_third_input_et"
|
android:id="@+id/lon_third_input_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -322,7 +322,7 @@
|
||||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||||
tools:background="@color/route_info_bottom_view_bg_dark">
|
tools:background="@color/route_info_bottom_view_bg_dark">
|
||||||
|
|
||||||
<EditText
|
<net.osmand.plus.widgets.EditTextEx
|
||||||
android:id="@+id/point_name_et"
|
android:id="@+id/point_name_et"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
|
@ -23,7 +23,6 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.PopupMenu;
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputFilter;
|
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
@ -63,6 +62,7 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
|
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
|
||||||
|
import net.osmand.plus.widgets.EditTextEx;
|
||||||
import net.osmand.util.LocationParser;
|
import net.osmand.util.LocationParser;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
private OnMapMarkersSavedListener listener;
|
private OnMapMarkersSavedListener listener;
|
||||||
|
|
||||||
private View mainView;
|
private View mainView;
|
||||||
private List<EditText> editTexts = new ArrayList<>();
|
private List<EditTextEx> editTexts = new ArrayList<>();
|
||||||
private CoordinateInputAdapter adapter;
|
private CoordinateInputAdapter adapter;
|
||||||
|
|
||||||
private boolean lightTheme;
|
private boolean lightTheme;
|
||||||
|
@ -415,8 +415,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
editTexts.clear();
|
editTexts.clear();
|
||||||
for (int id : ids) {
|
for (int id : ids) {
|
||||||
View v = mainView.findViewById(id);
|
View v = mainView.findViewById(id);
|
||||||
if (v != null && v instanceof EditText && v.getVisibility() == View.VISIBLE) {
|
if (v != null && v instanceof EditTextEx && v.getVisibility() == View.VISIBLE) {
|
||||||
editTexts.add((EditText) mainView.findViewById(id));
|
editTexts.add((EditTextEx) mainView.findViewById(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -439,19 +439,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable editable) {
|
public void afterTextChanged(Editable editable) {
|
||||||
View focusedView = getDialog().getCurrentFocus();
|
View focusedView = getDialog().getCurrentFocus();
|
||||||
if (focusedView != null && focusedView instanceof EditText) {
|
if (focusedView != null && focusedView instanceof EditTextEx) {
|
||||||
EditText focusedEditText = (EditText) focusedView;
|
EditTextEx et = (EditTextEx) focusedView;
|
||||||
String str = focusedEditText.getText().toString();
|
int currentLength = et.getText().length();
|
||||||
int currentLength = str.length(); // todo
|
if (et.getMaxSymbolsCount() > 0 && currentLength > strLength && currentLength >= et.getMaxSymbolsCount()) {
|
||||||
// if (currentLength > strLength) {
|
switchEditText(et.getId(), true);
|
||||||
// int pointIndex = str.indexOf(".");
|
}
|
||||||
// if (pointIndex != -1) {
|
|
||||||
// int currentAccuracy = str.substring(pointIndex + 1).length();
|
|
||||||
// if (currentAccuracy >= accuracy) {
|
|
||||||
// switchEditText(focusedEditText.getId(), true);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -568,20 +561,17 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
|
|
||||||
int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
|
int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
|
||||||
|
|
||||||
String firstSeparator = CoordinateInputFormats.getFirstSeparator(format);
|
int firstPartSymbols = CoordinateInputFormats.getFirstPartSymbolsCount(format);
|
||||||
int secondPartSymbols = CoordinateInputFormats.getSecondPartSymbolsCount(format);
|
setupEditTextEx(R.id.lat_first_input_et, firstPartSymbols, true);
|
||||||
|
setupEditTextEx(R.id.lon_first_input_et, firstPartSymbols, false);
|
||||||
|
|
||||||
|
String firstSeparator = CoordinateInputFormats.getFirstSeparator(format);
|
||||||
((TextView) mainView.findViewById(R.id.lat_first_separator_tv)).setText(firstSeparator);
|
((TextView) mainView.findViewById(R.id.lat_first_separator_tv)).setText(firstSeparator);
|
||||||
((TextView) mainView.findViewById(R.id.lon_first_separator_tv)).setText(firstSeparator);
|
((TextView) mainView.findViewById(R.id.lon_first_separator_tv)).setText(firstSeparator);
|
||||||
|
|
||||||
InputFilter[] secondInputFilters = {new InputFilter.LengthFilter(secondPartSymbols)};
|
int secondPartSymbols = CoordinateInputFormats.getSecondPartSymbolsCount(format);
|
||||||
|
setupEditTextEx(R.id.lat_second_input_et, secondPartSymbols, true);
|
||||||
EditText latSecondEt = (EditText) mainView.findViewById(R.id.lat_second_input_et);
|
setupEditTextEx(R.id.lon_second_input_et, secondPartSymbols, false);
|
||||||
EditText lonSecondEt = (EditText) mainView.findViewById(R.id.lon_second_input_et);
|
|
||||||
latSecondEt.setFilters(secondInputFilters);
|
|
||||||
lonSecondEt.setFilters(secondInputFilters);
|
|
||||||
latSecondEt.setHint(createHint(secondPartSymbols, 'x'));
|
|
||||||
lonSecondEt.setHint(createHint(secondPartSymbols, 'y'));
|
|
||||||
|
|
||||||
boolean containsThirdPart = CoordinateInputFormats.containsThirdPart(format);
|
boolean containsThirdPart = CoordinateInputFormats.containsThirdPart(format);
|
||||||
|
|
||||||
|
@ -593,19 +583,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
|
|
||||||
if (containsThirdPart) {
|
if (containsThirdPart) {
|
||||||
String secondSeparator = CoordinateInputFormats.getSecondSeparator(format);
|
String secondSeparator = CoordinateInputFormats.getSecondSeparator(format);
|
||||||
int thirdPartSymbols = CoordinateInputFormats.getThirdPartSymbolsCount(format);
|
|
||||||
|
|
||||||
((TextView) mainView.findViewById(R.id.lat_second_separator_tv)).setText(secondSeparator);
|
((TextView) mainView.findViewById(R.id.lat_second_separator_tv)).setText(secondSeparator);
|
||||||
((TextView) mainView.findViewById(R.id.lon_second_separator_tv)).setText(secondSeparator);
|
((TextView) mainView.findViewById(R.id.lon_second_separator_tv)).setText(secondSeparator);
|
||||||
|
|
||||||
InputFilter[] thirdInputFilters = {new InputFilter.LengthFilter(thirdPartSymbols)};
|
int thirdPartSymbols = CoordinateInputFormats.getThirdPartSymbolsCount(format);
|
||||||
|
setupEditTextEx(R.id.lat_third_input_et, thirdPartSymbols, true);
|
||||||
EditText latThirdEt = (EditText) mainView.findViewById(R.id.lat_third_input_et);
|
setupEditTextEx(R.id.lon_third_input_et, thirdPartSymbols, false);
|
||||||
EditText lonThirdEt = (EditText) mainView.findViewById(R.id.lon_third_input_et);
|
|
||||||
latThirdEt.setFilters(thirdInputFilters);
|
|
||||||
lonThirdEt.setFilters(thirdInputFilters);
|
|
||||||
latThirdEt.setHint(createHint(thirdPartSymbols, 'x'));
|
|
||||||
lonThirdEt.setHint(createHint(thirdPartSymbols, 'y'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_third_input_et,
|
addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_third_input_et,
|
||||||
|
@ -625,6 +608,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
editTexts.get(0).requestFocus();
|
editTexts.get(0).requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupEditTextEx(@IdRes int etId, int symbols, boolean lat) {
|
||||||
|
EditTextEx et = (EditTextEx) mainView.findViewById(etId);
|
||||||
|
et.setMaxSymbolsCount(symbols);
|
||||||
|
et.setHint(createHint(symbols, lat ? 'x' : 'y'));
|
||||||
|
}
|
||||||
|
|
||||||
private String createHint(int symbolsCount, char symbol) {
|
private String createHint(int symbolsCount, char symbol) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < symbolsCount; i++) {
|
for (int i = 0; i < symbolsCount; i++) {
|
||||||
|
|
|
@ -43,6 +43,10 @@ public class CoordinateInputFormats {
|
||||||
return format == DD_MM_MMM || format == DD_MM_MMMM || format == DD_MM_SS;
|
return format == DD_MM_MMM || format == DD_MM_MMMM || format == DD_MM_SS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getFirstPartSymbolsCount(@CoordinateInputFormatDef int format) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getSecondPartSymbolsCount(@CoordinateInputFormatDef int format) {
|
public static int getSecondPartSymbolsCount(@CoordinateInputFormatDef int format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case DD_MM_MMM:
|
case DD_MM_MMM:
|
||||||
|
|
39
OsmAnd/src/net/osmand/plus/widgets/EditTextEx.java
Normal file
39
OsmAnd/src/net/osmand/plus/widgets/EditTextEx.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package net.osmand.plus.widgets;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.AppCompatEditText;
|
||||||
|
import android.text.InputFilter.LengthFilter;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
|
||||||
|
public class EditTextEx extends AppCompatEditText {
|
||||||
|
|
||||||
|
private int maxSymbolsCount = -1;
|
||||||
|
|
||||||
|
public int getMaxSymbolsCount() {
|
||||||
|
return maxSymbolsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxSymbolsCount(int maxSymbolsCount) {
|
||||||
|
this.maxSymbolsCount = maxSymbolsCount;
|
||||||
|
setMaxSymbols();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditTextEx(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditTextEx(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditTextEx(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMaxSymbols() {
|
||||||
|
if (maxSymbolsCount > 0) {
|
||||||
|
setFilters(new LengthFilter[]{new LengthFilter(maxSymbolsCount)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue