fix showing two keyboards at the same time and improve scrollToPoint
This commit is contained in:
parent
5477e4a300
commit
263d78d712
2 changed files with 84 additions and 38 deletions
|
@ -12,6 +12,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
|
@ -92,6 +93,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
public static final String TAG = "CoordinateInputDialogFragment";
|
||||
public static final String ADDED_POINTS_NUMBER_KEY = "added_points_number_key";
|
||||
|
||||
private static final double SOFT_KEYBOARD_MIN_DETECTION_SIZE = 0.15;
|
||||
|
||||
private GPXFile newGpxFile;
|
||||
private OnPointsSavedListener listener;
|
||||
private WptPt selectedWpt;
|
||||
|
@ -108,7 +111,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
private boolean orientationPortrait;
|
||||
private boolean hasUnsavedChanges;
|
||||
|
||||
private boolean isSoftKeyboardShown;
|
||||
private boolean softKeyboardShown;
|
||||
private boolean shouldShowOsmandKeyboard;
|
||||
private int keyboardViewHeight;
|
||||
|
||||
private boolean north = true;
|
||||
private boolean east = true;
|
||||
|
||||
|
@ -354,6 +360,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
public void onClick(View view) {
|
||||
if (isOsmandKeyboardCurrentlyVisible()) {
|
||||
changeOsmandKeyboardVisibility(false);
|
||||
if (isOsmandKeyboardOn()) {
|
||||
shouldShowOsmandKeyboard = true;
|
||||
}
|
||||
}
|
||||
for (EditText et : editTexts) {
|
||||
if (et.getId() == R.id.point_name_et) {
|
||||
|
@ -430,9 +439,23 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
clearInputs();
|
||||
}
|
||||
});
|
||||
mainView.findViewById(R.id.keyboard_layout).setBackgroundResource(lightTheme
|
||||
final View keyboardLayout = mainView.findViewById(R.id.keyboard_layout);
|
||||
keyboardLayout.setBackgroundResource(lightTheme
|
||||
? R.drawable.bg_bottom_menu_light : R.drawable.bg_coordinate_input_keyboard_dark);
|
||||
|
||||
keyboardLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
int height = keyboardLayout.getHeight();
|
||||
if (keyboardViewHeight != height) {
|
||||
keyboardViewHeight = height;
|
||||
if (isOsmandKeyboardCurrentlyVisible() && selectedWpt == null) {
|
||||
scrollToPoint(adapter.getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
View keyboardView = mainView.findViewById(R.id.keyboard_view);
|
||||
|
||||
int dividersColorResId = lightTheme ? R.color.keyboard_divider_light : R.color.keyboard_divider_dark;
|
||||
|
@ -495,9 +518,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
if (!isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) {
|
||||
changeOsmandKeyboardVisibility(false);
|
||||
}
|
||||
if (isSoftKeyboardShown || isOsmandKeyboardCurrentlyVisible()) {
|
||||
moveLastPointToTop();
|
||||
}
|
||||
|
||||
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
@ -506,32 +526,42 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
mainView.getWindowVisibleDisplayFrame(r);
|
||||
int screenHeight = mainView.getRootView().getHeight();
|
||||
int keypadHeight = screenHeight - r.bottom;
|
||||
if (!isSoftKeyboardShown) {
|
||||
if (keypadHeight > screenHeight * 0.15) {
|
||||
isSoftKeyboardShown = true;
|
||||
moveLastPointToTop();
|
||||
boolean softKeyboardVisible = keypadHeight > screenHeight * SOFT_KEYBOARD_MIN_DETECTION_SIZE;
|
||||
if (softKeyboardShown && !softKeyboardVisible) {
|
||||
if (shouldShowOsmandKeyboard) {
|
||||
changeOsmandKeyboardVisibility(true);
|
||||
shouldShowOsmandKeyboard = false;
|
||||
}
|
||||
} else if (!softKeyboardShown && softKeyboardVisible && selectedWpt == null) {
|
||||
scrollToPoint(adapter.getItemCount() - 1);
|
||||
}
|
||||
isSoftKeyboardShown = keypadHeight > screenHeight * 0.15;
|
||||
softKeyboardShown = softKeyboardVisible;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void moveLastPointToTop() {
|
||||
final Context ctx = getContext();
|
||||
if (ctx == null) {
|
||||
private void scrollToPoint(WptPt point) {
|
||||
if (point != null) {
|
||||
scrollToPoint(adapter.getItemPosition(point));
|
||||
}
|
||||
}
|
||||
|
||||
private void scrollToPoint(int position) {
|
||||
int itemsSize = adapter.getItemCount();
|
||||
if ((position < 0) || !(itemsSize > 1) || (itemsSize < position)) {
|
||||
return;
|
||||
}
|
||||
if (adapter.getItemCount() > 1) {
|
||||
if (isOsmandKeyboardCurrentlyVisible()) {
|
||||
View keyboardView = mainView.findViewById(R.id.keyboard_layout);
|
||||
keyboardView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
||||
int height = keyboardView.getMeasuredHeight();
|
||||
recyclerView.setPadding(0, AndroidUtils.dpToPx(ctx, 16), 0, height);
|
||||
setPaddingToRecyclerViewBottom(keyboardViewHeight);
|
||||
}
|
||||
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(adapter.getItemCount() - 1, 0);
|
||||
recyclerView.scrollToPosition(position);
|
||||
}
|
||||
|
||||
private void setPaddingToRecyclerViewBottom(int padding) {
|
||||
if (recyclerView.getPaddingBottom() == padding) {
|
||||
return;
|
||||
}
|
||||
recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop(), recyclerView.getPaddingRight(), padding);
|
||||
}
|
||||
|
||||
private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) {
|
||||
|
@ -779,15 +809,17 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
if (isOsmandKeyboardOn()) {
|
||||
if (!isOsmandKeyboardCurrentlyVisible()) {
|
||||
if (isSoftKeyboardShown) {
|
||||
if (softKeyboardShown) {
|
||||
if (view.getId() != R.id.point_name_et) {
|
||||
AndroidUtils.hideSoftKeyboard(getActivity(), view);
|
||||
shouldShowOsmandKeyboard = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
changeOsmandKeyboardVisibility(true);
|
||||
}
|
||||
}
|
||||
EditText editText = (EditText) view;
|
||||
int inputType = editText.getInputType();
|
||||
editText.setInputType(InputType.TYPE_NULL);
|
||||
|
@ -915,7 +947,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (!hasFocus && isOsmandKeyboardOn() && (isOsmandKeyboardCurrentlyVisible() || isSoftKeyboardShown)) {
|
||||
if (!hasFocus && isOsmandKeyboardOn() && (isOsmandKeyboardCurrentlyVisible() || softKeyboardShown)) {
|
||||
AndroidUtils.hideSoftKeyboard(getActivity(), v);
|
||||
}
|
||||
}
|
||||
|
@ -965,7 +997,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
if (useOsmandKeyboard) {
|
||||
AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
|
||||
} else {
|
||||
AndroidUtils.softKeyboardDelayed(focusedView);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AndroidUtils.showSoftKeyboard(focusedView);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
changeEditTextSelections();
|
||||
|
@ -1094,10 +1131,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
} else {
|
||||
mainView.findViewById(R.id.keyboard_layout).setVisibility(visibility);
|
||||
}
|
||||
if (show) {
|
||||
moveLastPointToTop();
|
||||
} else {
|
||||
recyclerView.setPadding(0, AndroidUtils.dpToPx(getMyApplication(), 16), 0, AndroidUtils.dpToPx(getMyApplication(), 72));
|
||||
if (!show) {
|
||||
setPaddingToRecyclerViewBottom(AndroidUtils.dpToPx(getMyApplication(), 72));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1185,9 +1220,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
}
|
||||
if (isOsmandKeyboardOn()) {
|
||||
if (!isOsmandKeyboardCurrentlyVisible()) {
|
||||
if (softKeyboardShown && focusedView != null) {
|
||||
AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
|
||||
shouldShowOsmandKeyboard = true;
|
||||
return;
|
||||
}
|
||||
changeOsmandKeyboardVisibility(true);
|
||||
}
|
||||
} else if (!isSoftKeyboardShown && focusedView != null) {
|
||||
} else if (!softKeyboardShown && focusedView != null) {
|
||||
AndroidUtils.softKeyboardDelayed(focusedView);
|
||||
}
|
||||
}
|
||||
|
@ -1254,10 +1294,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
}
|
||||
if (selectedWpt != null) {
|
||||
updateWpt(getGpx(), null, name, null, 0, lat, lon);
|
||||
scrollToPoint(selectedWpt);
|
||||
dismissEditingMode();
|
||||
} else {
|
||||
addWpt(getGpx(), null, name, null, 0, lat, lon);
|
||||
moveLastPointToTop();
|
||||
scrollToPoint(adapter.getItemCount() - 1);
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
clearInputs();
|
||||
|
|
|
@ -12,7 +12,8 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
@ -23,7 +24,7 @@ import net.osmand.plus.base.FavoriteImageDrawable;
|
|||
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
|
||||
|
||||
public static final String ADAPTER_POSITION_KEY = "adapter_position_key";
|
||||
private GPXUtilities.GPXFile gpx;
|
||||
private GPXFile gpx;
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
|
@ -43,7 +44,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
this.actionsListener = actionsListener;
|
||||
}
|
||||
|
||||
public CoordinateInputAdapter(OsmandApplication app, GPXUtilities.GPXFile gpx) {
|
||||
public CoordinateInputAdapter(OsmandApplication app, GPXFile gpx) {
|
||||
this.app = app;
|
||||
this.gpx = gpx;
|
||||
|
||||
|
@ -62,7 +63,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final MapMarkerItemViewHolder holder, int position) {
|
||||
GPXUtilities.WptPt wpt = getItem(position);
|
||||
WptPt wpt = getItem(position);
|
||||
|
||||
holder.iconDirection.setVisibility(View.VISIBLE);
|
||||
holder.icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false));
|
||||
|
@ -99,10 +100,14 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
}
|
||||
|
||||
|
||||
public GPXUtilities.WptPt getItem(int position) {
|
||||
public WptPt getItem(int position) {
|
||||
return gpx.getPoints().get(position);
|
||||
}
|
||||
|
||||
public int getItemPosition(WptPt wptPt) {
|
||||
return gpx.getPoints().indexOf(wptPt);
|
||||
}
|
||||
|
||||
public void removeItem(int position) {
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
gpx.deleteWptPt(getItem(position));
|
||||
|
@ -110,7 +115,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
|
|||
}
|
||||
}
|
||||
|
||||
public void setGpx(GPXUtilities.GPXFile gpx) {
|
||||
public void setGpx(GPXFile gpx) {
|
||||
this.gpx = gpx;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue