Fix categories and checkbox

This commit is contained in:
Victor Shcherb 2014-10-21 09:40:53 +02:00
parent b795525ade
commit 122a4ea349
2 changed files with 27 additions and 7 deletions

View file

@ -11,6 +11,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListAdapter;
import android.widget.TextView;
@ -150,8 +152,9 @@ public class ContextMenuAdapter {
isCategory.insert(pos, cat ? 1 : 0);
}
public void setCategory(boolean b) {
public Item setCategory(boolean b) {
cat = b;
return this;
}
}
@ -177,7 +180,7 @@ public class ContextMenuAdapter {
ListAdapter listadapter = new ArrayAdapter<String>(activity, layoutId, R.id.title,
getItemNames()) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
@ -201,7 +204,24 @@ public class ContextMenuAdapter {
}
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
ch.setVisibility(View.GONE);
if(selectedList.get(position) != -1) {
ch.setOnCheckedChangeListener(null);
ch.setVisibility(View.VISIBLE);
ch.setSelected(selectedList.get(position) > 0);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OnContextMenuClick ca = getClickAdapter(position);
if(ca != null) {
ca.onContextMenuClick(getItemId(position), position, isChecked);
}
}
});
ch.setVisibility(View.VISIBLE);
} else {
ch.setVisibility(View.GONE);
}
return v;
}
};

View file

@ -27,7 +27,7 @@ public class ConfigureMapMenu {
public ContextMenuAdapter createListAdapter(final MapActivity ma) {
ContextMenuAdapter adapter = new ContextMenuAdapter(ma);
adapter.item(R.string.layers_category_show).setCategory(true);
adapter.item(R.string.layers_category_show).setCategory(true).reg();
adapter.item(R.string.configure_map).icons(R.drawable.ic_back_drawer_dark, R.drawable.ic_back_drawer_white)
.listen(new OnContextMenuClick() {
@ -92,7 +92,7 @@ public class ConfigureMapMenu {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
LayerMenuListener l = new LayerMenuListener(activity);
adapter.item(R.string.layers_category_show).setCategory(true);
adapter.item(R.string.layers_category_show).setCategory(true).reg();
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
adapter.item(R.string.layer_poi).selected(settings.SHOW_POI_OVER_MAP.get() ? 1 : 0)
.icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light).listen(l).reg();
@ -122,7 +122,7 @@ public class ConfigureMapMenu {
}
private void createRenderingAttributeItems(ContextMenuAdapter adapter, final MapActivity activity) {
adapter.item(R.string.map_widget_map_rendering).setCategory(true);
adapter.item(R.string.map_widget_map_rendering).setCategory(true).reg();
adapter.item(R.string.map_widget_renderer).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(int itemId, int pos, boolean isChecked) {
@ -224,7 +224,7 @@ public class ConfigureMapMenu {
private void createCustomRenderingProperties(RenderingRulesStorage renderer, ContextMenuAdapter adapter , final MapActivity activity){
final OsmandMapTileView view = activity.getMapView();
adapter.item(R.string.map_widget_vector_attributes).setCategory(true);
adapter.item(R.string.map_widget_vector_attributes).setCategory(true).reg();
final OsmandApplication app = view.getApplication();
List<RenderingRuleProperty> customRules = renderer.PROPS.getCustomRules();
for (final RenderingRuleProperty p : customRules) {