Fix
This commit is contained in:
parent
5eaedc2e7a
commit
16fdc544ed
3 changed files with 62 additions and 7 deletions
|
@ -55,8 +55,7 @@ public class FavouritePointMenuController extends MenuController {
|
|||
|
||||
@Override
|
||||
public Drawable getLeftIcon() {
|
||||
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(),
|
||||
fav.getColor(), getMapActivity().getMapView().getCurrentRotatedTileBox().getDensity());
|
||||
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,8 @@ import net.osmand.plus.views.ContextMenuLayer;
|
|||
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -41,6 +43,12 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
this.pointDescription = pointDescription;
|
||||
this.object = object;
|
||||
this.mapActivity = mapActivity;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object);
|
||||
initTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,10 +73,6 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
|
||||
@Override
|
||||
public MenuController getMenuController() {
|
||||
if (controller == null) {
|
||||
controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object);
|
||||
initTitle();
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
|
||||
|
@ -112,6 +116,12 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity());
|
||||
objects.add(menuObject);
|
||||
}
|
||||
Collections.sort(objects, new Comparator<MenuObject>() {
|
||||
@Override
|
||||
public int compare(MenuObject obj1, MenuObject obj2) {
|
||||
return obj1.getTitleStr().compareToIgnoreCase(obj2.getTitleStr());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void show(LatLon latLon, Map<Object, IContextMenuProvider> selectedObjects, MapActivity mapActivity) {
|
||||
|
@ -179,6 +189,7 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
menu.objects = (LinkedList<MenuObject>) objects;
|
||||
for (MenuObject menuObject : menu.objects) {
|
||||
menuObject.mapActivity = mapActivity;
|
||||
menuObject.init();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,16 @@ package net.osmand.plus.mapcontextmenu.other;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
|
@ -28,6 +31,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
|||
public class ObjectSelectionMenuFragment extends Fragment implements AdapterView.OnItemClickListener {
|
||||
public static final String TAG = "ObjectSelectionMenuFragment";
|
||||
|
||||
private View view;
|
||||
private ArrayAdapter<MenuObject> listAdapter;
|
||||
private ObjectSelectionMenu menu;
|
||||
|
||||
|
@ -46,13 +50,16 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
|
|||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
|
||||
view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
|
||||
|
||||
ListView listView = (ListView) view.findViewById(R.id.list);
|
||||
listAdapter = createAdapter();
|
||||
listView.setAdapter(listAdapter);
|
||||
listView.setOnItemClickListener(this);
|
||||
|
||||
if (!oldAndroid()) {
|
||||
runLayoutListener();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -86,6 +93,34 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
|
|||
.addToBackStack(TAG).commit();
|
||||
}
|
||||
|
||||
private void runLayoutListener() {
|
||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
|
||||
int maxHeight = (int) (getScreenHeight() * menu.getHalfScreenMaxHeightKoef());
|
||||
int height = view.findViewById(R.id.main_view).getHeight();
|
||||
|
||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
obs.removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
obs.removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
|
||||
if (height > maxHeight) {
|
||||
ViewGroup.LayoutParams lp = view.getLayoutParams();
|
||||
lp.height = maxHeight;
|
||||
view.setLayoutParams(lp);
|
||||
view.requestLayout();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ArrayAdapter<MenuObject> createAdapter() {
|
||||
final List<MenuObject> items = menu.getObjects();
|
||||
return new ArrayAdapter<MenuObject>(menu.getMapActivity(), R.layout.menu_obj_list_item, items) {
|
||||
|
@ -157,4 +192,14 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
|
|||
r.getDisplayMetrics()
|
||||
);
|
||||
}
|
||||
|
||||
private int getScreenHeight() {
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
return dm.heightPixels;
|
||||
}
|
||||
|
||||
private boolean oldAndroid() {
|
||||
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue