This commit is contained in:
PavelRatushny 2017-10-27 19:03:57 +03:00
parent 7eb1f932cd
commit 2dbf04b7da
6 changed files with 81 additions and 74 deletions

View file

@ -37,6 +37,12 @@
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"/> android:layout_marginEnd="16dp"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
<net.osmand.plus.OsmandTextFieldBoxes <net.osmand.plus.OsmandTextFieldBoxes
android:id="@+id/latitude_box" android:id="@+id/latitude_box"
android:layout_width="0dp" android:layout_width="0dp"

View file

@ -70,6 +70,12 @@
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
<LinearLayout <LinearLayout
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp"

View file

@ -35,14 +35,7 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes {
this.panel.setOnClickListener(new OnClickListener() { this.panel.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if(!OsmandTextFieldBoxes.this.isActivated()) { select();
OsmandTextFieldBoxes.this.activate(true);
}
OsmandTextFieldBoxes.this.setHasFocus(true);
if (!useOsmandKeyboard) {
OsmandTextFieldBoxes.this.inputMethodManager.showSoftInput(OsmandTextFieldBoxes.this.editText, InputMethodManager.SHOW_IMPLICIT);
}
} }
}); });
@ -71,7 +64,7 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes {
} }
@Override @Override
protected void deactivate() { public void deactivate() {
if(this.editText.getText().toString().isEmpty()) { if(this.editText.getText().toString().isEmpty()) {
ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION); ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION);
this.editTextLayout.setVisibility(View.INVISIBLE); this.editTextLayout.setVisibility(View.INVISIBLE);

View file

@ -207,9 +207,11 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF
super.onStart(); super.onStart();
if (!portrait) { if (!portrait) {
final Window window = getDialog().getWindow(); final Window window = getDialog().getWindow();
WindowManager.LayoutParams params = window.getAttributes(); if (window != null) {
params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); WindowManager.LayoutParams params = window.getAttributes();
window.setAttributes(params); params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
window.setAttributes(params);
}
} }
} }

View file

@ -13,7 +13,6 @@ import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable; import android.text.Editable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
@ -60,6 +59,7 @@ import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN; import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
import static android.content.Context.CLIPBOARD_SERVICE; import static android.content.Context.CLIPBOARD_SERVICE;
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
@ -199,8 +199,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
registerEditTexts(); registerEditTexts();
changeKeyboardInBoxes();
final View mapMarkersLayout = mainView.findViewById(R.id.map_markers_layout); final View mapMarkersLayout = mainView.findViewById(R.id.map_markers_layout);
RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view); RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
@ -233,7 +231,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
LatLon latLon = MapUtils.parseLocation(locPhrase); LatLon latLon = MapUtils.parseLocation(locPhrase);
if (latLon != null) { if (latLon != null) {
String name = nameEditText.getText().toString(); String name = nameEditText.getText().toString();
adapter.addMapMarker(latLon, name); addMapMarker(latLon, name);
} else { } else {
Toast.makeText(getContext(), getString(R.string.wrong_format), Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), getString(R.string.wrong_format), Toast.LENGTH_SHORT).show();
} }
@ -311,6 +309,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
stopLocationUpdate(); stopLocationUpdate();
} }
@Override
public void onSaveInstanceState(Bundle outState) {
}
@Override @Override
public void onDestroyView() { public void onDestroyView() {
Dialog dialog = getDialog(); Dialog dialog = getDialog();
@ -341,6 +343,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) { for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) {
textFieldBox.getPanel().setOnTouchListener(textFieldBoxOnTouchListener); textFieldBox.getPanel().setOnTouchListener(textFieldBoxOnTouchListener);
} }
changeKeyboardInBoxes();
} }
private void registerEditTexts() { private void registerEditTexts() {
@ -431,50 +434,51 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu); popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE)); final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
MenuItem pasteMenuItem = menu.findItem(R.id.action_paste); MenuItem pasteMenuItem = menu.findItem(R.id.action_paste);
if (!(clipboardManager.hasPrimaryClip())) { if (clipboardManager == null || !clipboardManager.hasPrimaryClip() ||
pasteMenuItem.setEnabled(false); !clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
} else if (!(clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {
pasteMenuItem.setEnabled(false); pasteMenuItem.setEnabled(false);
} else { } else {
pasteMenuItem.setEnabled(true); pasteMenuItem.setEnabled(true);
} }
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { if (clipboardManager != null) {
@Override popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) { @Override
switch (item.getItemId()) { public boolean onMenuItemClick(MenuItem item) {
case R.id.action_copy: switch (item.getItemId()) {
String labelText; case R.id.action_copy:
switch (view.getId()) { String labelText;
case R.id.latitude_edit_text: switch (view.getId()) {
labelText = LATITUDE_LABEL; case R.id.latitude_edit_text:
break; labelText = LATITUDE_LABEL;
case R.id.longitude_edit_text: break;
labelText = LONGITUDE_LABEL; case R.id.longitude_edit_text:
break; labelText = LONGITUDE_LABEL;
case R.id.name_edit_text: break;
labelText = NAME_LABEL; case R.id.name_edit_text:
break; labelText = NAME_LABEL;
default: break;
labelText = ""; default:
break; labelText = "";
} break;
ClipData clip = ClipData.newPlainText(labelText, editText.getText().toString()); }
clipboardManager.setPrimaryClip(clip); ClipData clip = ClipData.newPlainText(labelText, editText.getText().toString());
return true; clipboardManager.setPrimaryClip(clip);
case R.id.action_paste: return true;
ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0); case R.id.action_paste:
CharSequence pasteData = pasteItem.getText(); ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0);
if (pasteData != null) { CharSequence pasteData = pasteItem.getText();
String str = editText.getText().toString(); if (pasteData != null) {
editText.setText(str + pasteData.toString()); String str = editText.getText().toString();
editText.setSelection(editText.getText().length()); editText.setText(str + pasteData.toString());
} editText.setSelection(editText.getText().length());
return true; }
return true;
}
return false;
} }
return false; });
} popupMenu.show();
}); }
popupMenu.show();
return true; return true;
} else { } else {
return false; return false;
@ -599,6 +603,21 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} }
} }
public void addMapMarker(LatLon latLon, String name) {
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name);
int colorIndex = mapMarkers.size() > 0 ? mapMarkers.get(mapMarkers.size() - 1).colorIndex : -1;
if (colorIndex == -1) {
colorIndex = 0;
} else {
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
}
MapMarker mapMarker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
mapMarker.history = false;
mapMarker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
mapMarkers.add(mapMarker);
adapter.notifyDataSetChanged();
}
private MapActivity getMapActivity() { private MapActivity getMapActivity() {
return (MapActivity) getActivity(); return (MapActivity) getActivity();
} }

View file

@ -7,19 +7,15 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import java.util.List; import java.util.List;
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> { public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
private MapActivity mapActivity; private MapActivity mapActivity;
@ -118,19 +114,4 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
public MapMarker getItem(int position) { public MapMarker getItem(int position) {
return mapMarkers.get(position); return mapMarkers.get(position);
} }
public void addMapMarker(LatLon latLon, String name) {
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name);
int colorIndex = mapMarkers.size() > 0 ? mapMarkers.get(mapMarkers.size() - 1).colorIndex : -1;
if (colorIndex == -1) {
colorIndex = 0;
} else {
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
}
MapMarker mapMarker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
mapMarker.history = false;
mapMarker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
mapMarkers.add(mapMarker);
notifyDataSetChanged();
}
} }