Create UI for landscape

This commit is contained in:
PavelRatushny 2017-10-26 18:23:10 +03:00
parent fcdc4e5d5c
commit 8809f9b5b4
4 changed files with 232 additions and 23 deletions

View file

@ -0,0 +1,157 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/map_widget_blue"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/coordinate_input_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:paddingTop="12dp"
osmand:contentInsetLeft="54dp"
osmand:contentInsetStart="54dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<net.osmand.plus.OsmandTextFieldBoxes
android:id="@+id/latitude_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
osmand:labelText="@string/navigate_point_latitude">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/latitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</net.osmand.plus.OsmandTextFieldBoxes>
<View
android:layout_width="12dp"
android:layout_height="match_parent"/>
<net.osmand.plus.OsmandTextFieldBoxes
android:id="@+id/longitude_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
osmand:labelText="@string/navigate_point_longitude">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/longitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</net.osmand.plus.OsmandTextFieldBoxes>
<View
android:layout_width="12dp"
android:layout_height="match_parent"/>
<net.osmand.plus.OsmandTextFieldBoxes
android:id="@+id/name_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
osmand:labelText="@string/shared_string_name">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/access_hint_enter_name"
android:inputType="text"/>
</net.osmand.plus.OsmandTextFieldBoxes>
<View
android:layout_width="10dp"
android:layout_height="match_parent"/>
<ImageButton
android:id="@+id/options_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/markers_recycler_view"
android:layout_weight="0.55"
android:layout_width="0dp"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="8dp"/>
<LinearLayout
android:layout_weight="0.45"
android:id="@+id/keyboard_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="@+id/keyboard_grid_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="?attr/dashboard_divider"
android:horizontalSpacing="1dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"/>
<View
android:id="@+id/keyboard_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_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:paddingBottom="6dp"
android:paddingTop="6dp"
android:text="@string/shared_string_add"
android:textAllCaps="true"
android:textColor="?attr/keyboard_item_text_color"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,28 @@
<?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="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_weight="0.1"
android:layout_height="0dp"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/keyboard_item"
android:textAllCaps="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:gravity="center"
android:textColor="?attr/keyboard_item_text_color"
tools:text="3"/>
<View
android:layout_width="match_parent"
android:layout_weight="0.1"
android:layout_height="0dp"/>
</LinearLayout>

View file

@ -5,15 +5,24 @@
android:layout_height="56dp" android:layout_height="56dp"
android:orientation="vertical"> android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_weight="0.1"
android:layout_height="0dp"/>
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:id="@+id/keyboard_item" android:id="@+id/keyboard_item"
android:textAllCaps="true" android:textAllCaps="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_weight="0.8"
android:layout_height="0dp"
android:gravity="center" android:gravity="center"
android:textColor="?attr/keyboard_item_text_color" android:textColor="?attr/keyboard_item_text_color"
tools:text="3"/> tools:text="3"/>
<View
android:layout_width="match_parent"
android:layout_weight="0.1"
android:layout_height="0dp"/>
</LinearLayout> </LinearLayout>

View file

@ -49,6 +49,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities; 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.mapmarkers.adapters.CoordinateInputAdapter; import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -94,6 +95,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private boolean locationUpdateStarted; private boolean locationUpdateStarted;
private boolean compassUpdateAllowed = true; private boolean compassUpdateAllowed = true;
private MapMarkersHelper mapMarkersHelper; private MapMarkersHelper mapMarkersHelper;
private boolean orientationPortrait;
public void setListener(OnMapMarkersSavedListener listener) { public void setListener(OnMapMarkersSavedListener listener) {
this.listener = listener; this.listener = listener;
@ -106,8 +108,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
setStyle(STYLE_NO_FRAME, themeId); setStyle(STYLE_NO_FRAME, themeId);
iconsCache = app.getIconsCache();
mapMarkersHelper = app.getMapMarkersHelper();
CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment();
fragment.setListener(createCoordinateInputFormatChangeListener()); fragment.setListener(createCoordinateInputFormatChangeListener());
@ -131,6 +131,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container); mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container);
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
iconsCache = getMyApplication().getIconsCache();
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
orientationPortrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG); Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG);
if (coordinateInputBottomSheetDialogFragment != null) { if (coordinateInputBottomSheetDialogFragment != null) {
@ -178,7 +181,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
public void onClick(View view) { public void onClick(View view) {
View focusedView = getDialog().getCurrentFocus(); View focusedView = getDialog().getCurrentFocus();
if (focusedView != null) { if (focusedView != null) {
if (isOsmandKeyboardCurrentlyVisible()) { if (orientationPortrait && isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false); changeOsmandKeyboardVisibility(false);
} }
AndroidUtils.showSoftKeyboard(focusedView); AndroidUtils.showSoftKeyboard(focusedView);
@ -232,7 +235,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}); });
View keyboardLayout = mainView.findViewById(R.id.keyboard_layout); View keyboardLayout = mainView.findViewById(R.id.keyboard_layout);
if (orientationPortrait) {
AndroidUtils.setBackground(mapActivity, keyboardLayout, !lightTheme, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); AndroidUtils.setBackground(mapActivity, keyboardLayout, !lightTheme, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}
String[] keyboardItems = new String[] { "1", "2", "3", String[] keyboardItems = new String[] { "1", "2", "3",
"4", "5", "6", "4", "5", "6",
@ -266,6 +271,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} }
}); });
if (orientationPortrait) {
final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon); final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon);
showHideKeyboardIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_arrow_down)); showHideKeyboardIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_arrow_down));
showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() { showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() {
@ -276,9 +282,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
if (focusedView != null && !isCurrentlyVisible) { if (focusedView != null && !isCurrentlyVisible) {
AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
} }
if (orientationPortrait) {
changeOsmandKeyboardVisibility(!isCurrentlyVisible); changeOsmandKeyboardVisibility(!isCurrentlyVisible);
} }
}
}); });
}
return mainView; return mainView;
} }
@ -315,7 +324,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
View.OnTouchListener textFieldBoxOnTouchListener = new View.OnTouchListener() { View.OnTouchListener textFieldBoxOnTouchListener = new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) { if (orientationPortrait && !useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false); changeOsmandKeyboardVisibility(false);
} }
return false; return false;
@ -397,7 +406,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
editText.setInputType(inType); // Restore input type editText.setInputType(inType); // Restore input type
return true; // Consume touch event return true; // Consume touch event
} else { } else {
if (isOsmandKeyboardCurrentlyVisible()) { if (orientationPortrait && isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false); changeOsmandKeyboardVisibility(false);
} }
return false; return false;
@ -519,7 +528,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
@Override @Override
public void onKeyboardChanged(boolean useOsmandKeyboard) { public void onKeyboardChanged(boolean useOsmandKeyboard) {
CoordinateInputDialogFragment.this.useOsmandKeyboard = useOsmandKeyboard; CoordinateInputDialogFragment.this.useOsmandKeyboard = useOsmandKeyboard;
if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) { if (orientationPortrait && !useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false); changeOsmandKeyboardVisibility(false);
} }
changeKeyboardInBoxes(); changeKeyboardInBoxes();
@ -674,6 +683,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
convertView = LayoutInflater.from(getContext()).inflate(R.layout.input_coordinate_keyboard_item, parent, false); convertView = LayoutInflater.from(getContext()).inflate(R.layout.input_coordinate_keyboard_item, parent, false);
convertView.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg); convertView.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg);
} }
if (!orientationPortrait) {
int keyboardViewHeight = mainView.findViewById(R.id.keyboard_grid_view).getMeasuredHeight();
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
int spaceForKeys = keyboardViewHeight - 3 * dividerHeight;
convertView.setMinimumHeight(spaceForKeys / 4);
}
TextView keyboardItem = (TextView) convertView.findViewById(R.id.keyboard_item); TextView keyboardItem = (TextView) convertView.findViewById(R.id.keyboard_item);
if (position == CLEAR_BUTTON_POSITION) { if (position == CLEAR_BUTTON_POSITION) {
TextViewCompat.setAutoSizeTextTypeWithDefaults(keyboardItem, TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE); TextViewCompat.setAutoSizeTextTypeWithDefaults(keyboardItem, TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
@ -687,7 +702,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} }
} }
public interface OnMapMarkersSavedListener { interface OnMapMarkersSavedListener {
void onMapMarkersSaved(); void onMapMarkersSaved();
} }