This commit is contained in:
Alexey Kulish 2015-10-24 23:21:27 +03:00
parent 5eaedc2e7a
commit 16fdc544ed
3 changed files with 62 additions and 7 deletions

View file

@ -55,8 +55,7 @@ public class FavouritePointMenuController extends MenuController {
@Override @Override
public Drawable getLeftIcon() { public Drawable getLeftIcon() {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), 0);
fav.getColor(), getMapActivity().getMapView().getCurrentRotatedTileBox().getDensity());
} }
@Override @Override

View file

@ -13,6 +13,8 @@ import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -41,6 +43,12 @@ public class ObjectSelectionMenu extends BaseMenuController {
this.pointDescription = pointDescription; this.pointDescription = pointDescription;
this.object = object; this.object = object;
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
init();
}
protected void init() {
controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object);
initTitle();
} }
@Override @Override
@ -65,10 +73,6 @@ public class ObjectSelectionMenu extends BaseMenuController {
@Override @Override
public MenuController getMenuController() { public MenuController getMenuController() {
if (controller == null) {
controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object);
initTitle();
}
return controller; return controller;
} }
@ -112,6 +116,12 @@ public class ObjectSelectionMenu extends BaseMenuController {
MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity()); MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity());
objects.add(menuObject); 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) { 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; menu.objects = (LinkedList<MenuObject>) objects;
for (MenuObject menuObject : menu.objects) { for (MenuObject menuObject : menu.objects) {
menuObject.mapActivity = mapActivity; menuObject.mapActivity = mapActivity;
menuObject.init();
} }
} }

View file

@ -3,13 +3,16 @@ package net.osmand.plus.mapcontextmenu.other;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; 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 class ObjectSelectionMenuFragment extends Fragment implements AdapterView.OnItemClickListener {
public static final String TAG = "ObjectSelectionMenuFragment"; public static final String TAG = "ObjectSelectionMenuFragment";
private View view;
private ArrayAdapter<MenuObject> listAdapter; private ArrayAdapter<MenuObject> listAdapter;
private ObjectSelectionMenu menu; private ObjectSelectionMenu menu;
@ -46,13 +50,16 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 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); ListView listView = (ListView) view.findViewById(R.id.list);
listAdapter = createAdapter(); listAdapter = createAdapter();
listView.setAdapter(listAdapter); listView.setAdapter(listAdapter);
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
if (!oldAndroid()) {
runLayoutListener();
}
return view; return view;
} }
@ -86,6 +93,34 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
.addToBackStack(TAG).commit(); .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() { private ArrayAdapter<MenuObject> createAdapter() {
final List<MenuObject> items = menu.getObjects(); final List<MenuObject> items = menu.getObjects();
return new ArrayAdapter<MenuObject>(menu.getMapActivity(), R.layout.menu_obj_list_item, items) { 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() 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);
}
} }