Landscape layout for CoordinateInputDialogFragment in progress

This commit is contained in:
Alexander Sytnyk 2018-02-14 16:21:15 +02:00
parent 2454fab872
commit 8bcd9b6caa
7 changed files with 221 additions and 235 deletions

View file

@ -2,7 +2,7 @@
<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="match_parent"
android:layout_height="50dp"
android:orientation="vertical">
<View

View file

@ -0,0 +1,58 @@
<?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:id="@+id/data_area"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
tools:layout_width="match_parent">
<include layout="@layout/coordinate_input_data_area"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<View
android:id="@+id/keyboard_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/keyboard_controls_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/add_marker_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@string/shared_string_add"
android:textAllCaps="true"
android:textColor="@color/keyboard_item_button_text_color"
android:textSize="@dimen/default_list_text_size"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="?attr/keyboard_controls_divider"/>
<ImageView
android:id="@+id/show_hide_keyboard_icon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:scaleType="center"
tools:src="@drawable/ic_action_arrow_down"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
tools:layout_width="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/markers_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="72dp"
android:paddingTop="16dp"/>
<FrameLayout
android:id="@+id/keyboard_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<GridView
android:id="@+id/keyboard_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="1dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"/>
</FrameLayout>
</FrameLayout>

View file

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:layout_weight="0.55"
android:layout_width="0dp"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/map_markers_layout"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="8dp"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
osmand:cardUseCompatPadding="true"
osmand:cardCornerRadius="2dp">
<android.support.v7.widget.RecyclerView
android:nestedScrollingEnabled="false"
android:id="@+id/markers_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="8dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_weight="0.45"
android:id="@+id/keyboard_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<GridView
android:id="@+id/keyboard_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="53dp"
android:horizontalSpacing="1dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/keyboard_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/keyboard_controls_divider"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/add_marker_button"
android:layout_width="match_parent"
android:layout_height="52dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@string/shared_string_add"
android:textAllCaps="true"
android:textColor="@color/keyboard_item_button_text_color"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>
</FrameLayout>

View file

@ -112,8 +112,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal">
android:layout_height="56dp">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/add_marker_button"

View file

@ -60,7 +60,6 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.util.LocationParser;
import net.osmand.util.MapUtils;
@ -195,6 +194,32 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
});
registerMainView();
if (savedInstanceState == null) {
mainView.findViewById(R.id.lat_first_input_et).requestFocus();
}
return mainView;
}
private void registerMainView() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (!orientationPortrait) {
LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container);
if (rightHand) {
View.inflate(getContext(), R.layout.coordinate_input_land_data_area, handContainer);
View.inflate(getContext(), R.layout.coordinate_input_land_keyboard_and_list, handContainer);
} else {
View.inflate(getContext(), R.layout.coordinate_input_land_keyboard_and_list, handContainer);
View.inflate(getContext(), R.layout.coordinate_input_land_data_area, handContainer);
}
handContainer.findViewById(R.id.data_area).setBackgroundResource(rightHand
? R.drawable.bg_contextmenu_shadow_right_light : R.drawable.bg_contextmenu_shadow_left_light);
}
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);
@ -260,44 +285,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
registerInputs();
if (savedInstanceState == null) {
((EditText) mainView.findViewById(R.id.lat_first_input_et)).requestFocus();
}
registerMainView();
return mainView;
}
private void registerMainView() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (!orientationPortrait) {
LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container);
if (rightHand) {
View.inflate(getContext(), R.layout.coordinate_input_land_map_markers_list, handContainer);
View.inflate(getContext(), R.layout.coordinate_input_land_osmand_keyboard, handContainer);
} else {
View.inflate(getContext(), R.layout.coordinate_input_land_osmand_keyboard, handContainer);
View.inflate(getContext(), R.layout.coordinate_input_land_map_markers_list, handContainer);
}
}
final View mapMarkersLayout = mainView.findViewById(R.id.map_markers_layout);
RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new CoordinateInputAdapter(mapActivity, mapMarkers);
if (mapMarkersLayout != null) {
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
mapMarkersLayout.setVisibility(adapter.isEmpty() ? View.GONE : View.VISIBLE);
}
});
}
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
@ -316,22 +306,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
});
View keyboardLayout = mainView.findViewById(R.id.keyboard_layout);
int lightResId;
int darkResId;
if (orientationPortrait) {
lightResId = R.drawable.bg_bottom_menu_light;
darkResId = R.drawable.bg_bottom_menu_dark;
} else {
lightResId = rightHand ? R.drawable.bg_contextmenu_shadow_left_light : R.drawable.bg_contextmenu_shadow_right_light;
darkResId = lightResId;
}
AndroidUtils.setBackground(mapActivity, keyboardLayout, !lightTheme, lightResId, darkResId);
mainView.findViewById(R.id.keyboard_layout).setBackgroundResource(lightTheme ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_menu_dark);
Object[] keyboardItems = new Object[]{"1", "2", "3", R.drawable.ic_keyboard_next_field,
Object[] keyboardItems = new Object[]{
"1", "2", "3", R.drawable.ic_keyboard_next_field,
"4", "5", "6", "-",
"7", "8", "9", R.drawable.ic_keyboard_backspace,
":", "0", ".", getString(R.string.shared_string_clear)};
":", "0", ".", getString(R.string.shared_string_clear)
};
final GridView keyboardGrid = (GridView) mainView.findViewById(R.id.keyboard_grid_view);
keyboardGrid.setBackgroundColor(ContextCompat.getColor(getContext(), lightTheme ? R.color.keyboard_divider_light : R.color.keyboard_divider_dark));
final KeyboardAdapter keyboardAdapter = new KeyboardAdapter(mapActivity, keyboardItems);
@ -369,7 +351,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
});
if (orientationPortrait) {
final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon);
showHideKeyboardIcon.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_add_button_light_bg : R.drawable.keyboard_item_add_button_dark_bg);
showHideKeyboardIcon.setImageDrawable(getColoredIcon(R.drawable.ic_action_arrow_down, R.color.keyboard_item_button_text_color));
@ -386,7 +367,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
});
}
}
}
@Override
public void onResume() {
@ -516,13 +496,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
switch (item.getItemId()) {
case R.id.action_copy:
String labelText;
switch (view.getId()) {
case R.id.latitude_edit_text:
labelText = LATITUDE_LABEL;
break;
case R.id.longitude_edit_text:
labelText = LONGITUDE_LABEL;
break;
switch (view.getId()) { // todo
// case R.id.latitude_edit_text:
// labelText = LATITUDE_LABEL;
// break;
// case R.id.longitude_edit_text:
// labelText = LONGITUDE_LABEL;
// break;
case R.id.name_edit_text:
labelText = NAME_LABEL;
break;
@ -639,44 +619,44 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
.setImageDrawable(getColoredIcon(show ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, R.color.keyboard_item_button_text_color));
}
private void changeKeyboardInBoxes() {
private void changeKeyboardInBoxes() { // todo
// for (OsmandTextFieldBoxes textFieldBox : editTexts) {
// textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard);
// }
}
private void switchToNextInput(int id) {
if (id == R.id.latitude_edit_text) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
} else if (id == R.id.longitude_edit_text) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box)).select();
}
private void switchToNextInput(int id) { // todo
// if (id == R.id.latitude_edit_text) {
// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
// } else if (id == R.id.longitude_edit_text) {
// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box)).select();
// }
}
private void switchToPreviousInput(int id) {
if (id == R.id.name_edit_text) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
} else if (id == R.id.longitude_edit_text) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).select();
}
private void switchToPreviousInput(int id) { // todo
// if (id == R.id.name_edit_text) {
// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
// } else if (id == R.id.longitude_edit_text) {
// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).select();
// }
}
private void addMapMarker() {
final String latitude = ((EditText) mainView.findViewById(R.id.latitude_edit_text)).getText().toString();
final String longitude = ((EditText) mainView.findViewById(R.id.longitude_edit_text)).getText().toString();
double lat = parseCoordinate(latitude);
double lon = parseCoordinate(longitude);
if (lat == 0 || lon == 0) {
if (lon == 0) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).setError("", true);
}
if (lat == 0) {
((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).setError("", true);
}
} else {
String name = ((EditText) mainView.findViewById(R.id.name_edit_text)).getText().toString();
addMapMarker(new LatLon(lat, lon), name);
}
private void addMapMarker() { // todo
// final String latitude = ((EditText) mainView.findViewById(R.id.latitude_edit_text)).getText().toString();
// final String longitude = ((EditText) mainView.findViewById(R.id.longitude_edit_text)).getText().toString();
// double lat = parseCoordinate(latitude);
// double lon = parseCoordinate(longitude);
// if (lat == 0 || lon == 0) {
// if (lon == 0) {
// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).setError("", true);
// }
// if (lat == 0) {
// ((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).setError("", true);
// }
// } else {
// String name = ((EditText) mainView.findViewById(R.id.name_edit_text)).getText().toString();
// addMapMarker(new LatLon(lat, lon), name);
// }
}
private double parseCoordinate(String s) {