Fix keyboard show/hide and scroll to selected

This commit is contained in:
Dima-1 2020-04-01 17:51:42 +03:00
parent 22c0b9b04d
commit 0994c6ab21
2 changed files with 24 additions and 24 deletions

View file

@ -15,6 +15,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication;
@ -75,7 +76,8 @@ public class EditCategoryDialogFragment extends DialogFragment {
nameEdit = (EditText)v.findViewById(R.id.edit_name);
nameEdit.setText(name);
nameEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(nameEdit);
colorSpinner = (Spinner)v.findViewById(R.id.edit_color);
final TIntArrayList colors = new TIntArrayList();
final int intColor = color;
@ -151,7 +153,19 @@ public class EditCategoryDialogFragment extends DialogFragment {
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onStop() {
Dialog dialog = getDialog();
if (dialog != null) {
MapActivity mapActivity = (MapActivity) getDialog().getOwnerActivity();
if (mapActivity != null) {
AndroidUtils.hideSoftKeyboard(mapActivity, mapActivity.getCurrentFocus());
}
}
super.onStop();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
saveState(outState);
super.onSaveInstanceState(outState);
}

View file

@ -128,10 +128,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public void onScrollChanged() {
if (scrollViewY != scrollView.getScrollY()) {
scrollViewY = scrollView.getScrollY();
Activity activity = getActivity();
if (activity != null) {
AndroidUtils.hideSoftKeyboard(activity, view);
}
hideKeyboard();
}
}
});
@ -140,12 +137,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action);
view.findViewById(R.id.background_layout).setBackgroundResource(nightMode
? R.color.app_bar_color_dark : R.color.list_background_color_light);
ImageView groupListIcon = (ImageView) view.findViewById(R.id.group_list_button_icon);
groupListIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_group_select_all, activeColorResId));
ImageView replaceIcon = (ImageView) view.findViewById(R.id.replace_action_icon);
replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId));
ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon);
deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
ImageView groupListIcon = (ImageView) view.findViewById(R.id.group_list_button_icon);
groupListIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_group_select_all, activeColorResId));
View groupList = view.findViewById(R.id.group_list_button);
groupList.setOnClickListener(new View.OnClickListener() {
@Override
@ -236,6 +233,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
deleteButton.setVisibility(View.GONE);
descriptionCaption.setVisibility(View.GONE);
deleteIcon.setVisibility(View.GONE);
nameEdit.selectAll();
nameEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(nameEdit);
} else {
toolbarAction.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
deleteButton.setVisibility(View.VISIBLE);
@ -542,17 +542,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
}
@Override
public void onResume() {
super.onResume();
PointEditor editor = getEditor();
if (editor != null && editor.isNew()) {
nameEdit.selectAll();
nameEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(nameEdit);
}
}
@Override
public void onStop() {
super.onStop();
@ -618,12 +607,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
groupListAdapter.fillGroups();
groupListAdapter.setSelectedItemName(name);
groupListAdapter.notifyDataSetChanged();
int position;
int position = 0;
PointEditor editor = getEditor();
if (editor != null && editor.isNew()) {
String lastUsedGroup = getLastUsedGroup();
position = groupListAdapter.getItemPosition(lastUsedGroup);
} else {
if (editor != null) {
position = groupListAdapter.items.size() == groupListAdapter.getItemPosition(name) + 1
? groupListAdapter.getItemPosition(name) + 1
: groupListAdapter.getItemPosition(name);