Customize input area for selected format
This commit is contained in:
parent
84dc31377c
commit
0b998b1f0b
2 changed files with 78 additions and 23 deletions
|
@ -88,27 +88,27 @@
|
|||
android:hint="xx"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
tools:maxLength="2"/>
|
||||
android:maxLength="2"
|
||||
android:maxLines="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lat_first_separator_tv"
|
||||
android:layout_width="@dimen/context_menu_padding_margin_large"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="°"
|
||||
android:textColor="@color/ctx_menu_bottom_view_secondary_text_color_light"
|
||||
android:textSize="@dimen/dialog_header_text_size"/>
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
tools:text="°"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/lat_second_input_et"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="xx"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
tools:hint="xx"
|
||||
tools:maxLength="2"/>
|
||||
|
||||
<TextView
|
||||
|
@ -116,19 +116,19 @@
|
|||
android:layout_width="@dimen/context_menu_padding_margin_large"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="."
|
||||
android:textColor="@color/ctx_menu_bottom_view_secondary_text_color_light"
|
||||
android:textSize="@dimen/dialog_header_text_size"/>
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
tools:text="."/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/lat_thirst_input_et"
|
||||
android:id="@+id/lat_third_input_et"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="xxxx"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
tools:hint="xxxx"
|
||||
tools:maxLength="4"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -229,27 +229,27 @@
|
|||
android:hint="yy"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
tools:maxLength="2"/>
|
||||
android:maxLength="2"
|
||||
android:maxLines="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lon_first_separator_tv"
|
||||
android:layout_width="@dimen/context_menu_padding_margin_large"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="°"
|
||||
android:textColor="@color/ctx_menu_bottom_view_secondary_text_color_light"
|
||||
android:textSize="@dimen/dialog_header_text_size"/>
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
tools:text="°"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/lon_second_input_et"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="yy"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
tools:hint="yy"
|
||||
tools:maxLength="2"/>
|
||||
|
||||
<TextView
|
||||
|
@ -257,19 +257,19 @@
|
|||
android:layout_width="@dimen/context_menu_padding_margin_large"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="."
|
||||
android:textColor="@color/ctx_menu_bottom_view_secondary_text_color_light"
|
||||
android:textSize="@dimen/dialog_header_text_size"/>
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
tools:text="."/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/lon_thirst_input_et"
|
||||
android:id="@+id/lon_third_input_et"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="yyyy"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
tools:hint="yyyy"
|
||||
tools:maxLength="4"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
|||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.TypedValue;
|
||||
|
@ -397,7 +398,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
private void addEditTexts(@IdRes int... ids) {
|
||||
editTexts.clear();
|
||||
for (int id : ids) {
|
||||
editTexts.add((EditText) mainView.findViewById(id));
|
||||
View v = mainView.findViewById(id);
|
||||
if (v != null && v instanceof EditText && v.getVisibility() == View.VISIBLE) {
|
||||
editTexts.add((EditText) mainView.findViewById(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -544,8 +548,52 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
}
|
||||
};
|
||||
|
||||
addEditTexts(R.id.lat_first_input_et, R.id.lat_second_input_et, R.id.lat_thirst_input_et,
|
||||
R.id.lon_first_input_et, R.id.lon_second_input_et, R.id.lon_thirst_input_et, R.id.point_name_et);
|
||||
clearInputs();
|
||||
|
||||
int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
|
||||
|
||||
String firstSeparator = CoordinateInputFormats.getFirstSeparator(format);
|
||||
int secondPartSymbols = CoordinateInputFormats.getSecondPartSymbolsCount(format);
|
||||
|
||||
((TextView) mainView.findViewById(R.id.lat_first_separator_tv)).setText(firstSeparator);
|
||||
((TextView) mainView.findViewById(R.id.lon_first_separator_tv)).setText(firstSeparator);
|
||||
|
||||
InputFilter[] secondInputFilters = {new InputFilter.LengthFilter(secondPartSymbols)};
|
||||
|
||||
EditText latSecondEt = (EditText) mainView.findViewById(R.id.lat_second_input_et);
|
||||
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);
|
||||
|
||||
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 = CoordinateInputFormats.getSecondSeparator(format);
|
||||
int thirdPartSymbols = CoordinateInputFormats.getThirdPartSymbolsCount(format);
|
||||
|
||||
((TextView) mainView.findViewById(R.id.lat_second_separator_tv)).setText(secondSeparator);
|
||||
((TextView) mainView.findViewById(R.id.lon_second_separator_tv)).setText(secondSeparator);
|
||||
|
||||
InputFilter[] thirdInputFilters = {new InputFilter.LengthFilter(thirdPartSymbols)};
|
||||
|
||||
EditText latThirdEt = (EditText) mainView.findViewById(R.id.lat_third_input_et);
|
||||
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,
|
||||
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.point_name_et) {
|
||||
|
@ -561,6 +609,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
editTexts.get(0).requestFocus();
|
||||
}
|
||||
|
||||
private String createHint(int symbolsCount, char symbol) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < symbolsCount; i++) {
|
||||
sb.append(symbol);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void changeKeyboard() {
|
||||
if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) {
|
||||
changeOsmandKeyboardVisibility(false);
|
||||
|
@ -584,8 +640,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
|
||||
@Override
|
||||
public void onFormatChanged() {
|
||||
Toast.makeText(getContext(), CoordinateInputFormats.formatToHumanString(getContext(),
|
||||
getMyApplication().getSettings().COORDS_INPUT_FORMAT.get()), Toast.LENGTH_SHORT).show();
|
||||
registerInputs();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue