parent
857f525a44
commit
a4666c2c13
3 changed files with 120 additions and 82 deletions
|
@ -47,6 +47,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/poi_dialog_name"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="text"
|
||||
tools:text="@string/lorem_ipsum"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
@ -80,6 +82,8 @@
|
|||
android:completionThreshold="1"
|
||||
android:drawableRight="@drawable/ic_action_arrow_drop_down"
|
||||
android:hint="@string/poi_dialog_poi_type"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="text"
|
||||
tools:text="@string/lorem_ipsum"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
|
|
@ -30,12 +30,15 @@ import android.view.LayoutInflater;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -76,7 +79,6 @@ public class EditPoiFragment extends DialogFragment {
|
|||
private ViewPager viewPager;
|
||||
private boolean isLocalEdit;
|
||||
private boolean mIsUserInput = true;
|
||||
private EditText poiNameEditText;
|
||||
private EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private AutoCompleteTextView poiTypeEditText;
|
||||
private Node node;
|
||||
|
@ -112,6 +114,8 @@ public class EditPoiFragment extends DialogFragment {
|
|||
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
|
||||
setStyle(STYLE_NO_FRAME, themeId);
|
||||
getActivity().getWindow()
|
||||
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
|
@ -214,7 +218,7 @@ public class EditPoiFragment extends DialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
poiNameEditText = (EditText) view.findViewById(R.id.poiNameEditText);
|
||||
EditText poiNameEditText = (EditText) view.findViewById(R.id.poiNameEditText);
|
||||
poiNameEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
@ -256,27 +260,8 @@ public class EditPoiFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
});
|
||||
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View v, MotionEvent event) {
|
||||
final EditText editText = (EditText) v;
|
||||
final int DRAWABLE_RIGHT = 2;
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (event.getX() >= (editText.getRight()
|
||||
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
||||
- editText.getPaddingRight())) {
|
||||
if (editPoiData.amenity.getType() != null) {
|
||||
DialogFragment dialogFragment =
|
||||
PoiSubTypeDialogFragment.createInstance(editPoiData.amenity);
|
||||
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||
|
||||
Button saveButton = (Button) view.findViewById(R.id.saveButton);
|
||||
int saveButtonTextId = isLocalEdit ? R.string.shared_string_save :
|
||||
|
@ -285,6 +270,25 @@ public class EditPoiFragment extends DialogFragment {
|
|||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
save();
|
||||
|
||||
}
|
||||
});
|
||||
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().remove(EditPoiFragment.this).commit();
|
||||
fragmentManager.popBackStack();
|
||||
}
|
||||
});
|
||||
setAdapterForPoiTypeEditText();
|
||||
setCancelable(false);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void save() {
|
||||
if (TextUtils.isEmpty(poiTypeEditText.getText())) {
|
||||
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type));
|
||||
return;
|
||||
|
@ -340,21 +344,6 @@ public class EditPoiFragment extends DialogFragment {
|
|||
dismiss();
|
||||
}
|
||||
}, getActivity(), mOpenstreetmapUtil);
|
||||
|
||||
}
|
||||
});
|
||||
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().remove(EditPoiFragment.this).commit();
|
||||
fragmentManager.popBackStack();
|
||||
}
|
||||
});
|
||||
updateType(editPoiData.amenity);
|
||||
setCancelable(false);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -462,13 +451,38 @@ public class EditPoiFragment extends DialogFragment {
|
|||
mIsUserInput = true;
|
||||
poiTypeTextInputLayout.setHint(amenity.getType().getTranslation());
|
||||
|
||||
setAdapterForPoiTypeEditText();
|
||||
|
||||
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View v, MotionEvent event) {
|
||||
final EditText editText = (EditText) v;
|
||||
final int DRAWABLE_RIGHT = 2;
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (event.getX() >= (editText.getRight()
|
||||
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
||||
- editText.getPaddingRight())) {
|
||||
if (editPoiData.amenity.getType() != null) {
|
||||
DialogFragment dialogFragment =
|
||||
PoiSubTypeDialogFragment.createInstance(editPoiData.amenity);
|
||||
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setAdapterForPoiTypeEditText() {
|
||||
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, PoiType> s : allTranslatedSubTypes.entrySet()) {
|
||||
if (!subCategories.containsKey(s.getKey())) {
|
||||
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
final ArrayAdapter<Object> adapter = new ArrayAdapter<>(getActivity(),
|
||||
R.layout.list_textview, subCategories.keySet().toArray());
|
||||
poiTypeEditText.setAdapter(adapter);
|
||||
|
@ -477,6 +491,7 @@ public class EditPoiFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Object item = parent.getAdapter().getItem(position);
|
||||
LOG.debug("item=" + item);
|
||||
if (subCategories.containsKey(item)) {
|
||||
String keyName = subCategories.get(item).getKeyName();
|
||||
poiTypeEditText.setText(keyName);
|
||||
|
@ -487,6 +502,7 @@ public class EditPoiFragment extends DialogFragment {
|
|||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
|
@ -614,4 +630,17 @@ public class EditPoiFragment extends DialogFragment {
|
|||
return builder.create();
|
||||
}
|
||||
}
|
||||
|
||||
private TextView.OnEditorActionListener mOnEditorActionListener =
|
||||
new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
save();
|
||||
handled = true;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -27,12 +27,17 @@ public class PoiTypeDialogFragment extends DialogFragment {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final List<PoiCategory> categories = poiTypes.getCategories(false);
|
||||
ArrayList<String> vals = new ArrayList<>(categories.size());
|
||||
ArrayList<PoiCategory> toDelete = new ArrayList<>();
|
||||
// TODO replace with constants
|
||||
for (PoiCategory category : categories) {
|
||||
if (category.getKeyName().equals("user_defined_other")
|
||||
|| category.getKeyName().equals("osmwiki")) continue;
|
||||
|| category.getKeyName().equals("osmwiki")) {
|
||||
toDelete.add(category);
|
||||
} else {
|
||||
vals.add(category.getTranslation());
|
||||
}
|
||||
}
|
||||
categories.removeAll(toDelete);
|
||||
builder.setItems(vals.toArray(new String[vals.size()]), new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
|
Loading…
Reference in a new issue