white layer menu

This commit is contained in:
Pavol Zibrita 2012-06-05 00:39:39 +02:00
parent c254eba2fa
commit 5b3871eac7
4 changed files with 126 additions and 118 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

View file

@ -1,28 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="0dip"
android:paddingBottom="0dip" android:paddingBottom="0dip"
android:paddingLeft="5dip" android:paddingLeft="5dip"
android:paddingRight="5dip" android:paddingRight="5dip"
android:layout_width="wrap_content" android:paddingTop="0dip" >
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_alignParentLeft="true"
android:textSize="15sp"/> android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/check_item"
android:drawableLeft="@drawable/list_activities_poi"
android:gravity="center_vertical"
android:text="@string/layer_poi"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/color_black" />
<CheckBox <CheckBox
android:id="@+id/check_item" android:id="@+id/check_item"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false" /> android:focusable="false" />
</LinearLayout>
</RelativeLayout>

View file

@ -52,20 +52,15 @@ import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView; import android.widget.ListAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -74,6 +69,8 @@ import android.widget.Toast;
*/ */
public class MapActivityLayers { public class MapActivityLayers {
private final MapActivity activity; private final MapActivity activity;
// the order of layer should be preserved ! when you are inserting new layer // the order of layer should be preserved ! when you are inserting new layer
@ -215,36 +212,24 @@ public class MapActivityLayers {
} }
} }
private final class LayerMenuListener {
private final ContextMenuAdapter adapter;
private final OsmandMapTileView mapView;
private final OsmandSettings settings;
DialogInterface dialog;
public void openLayerSelectionDialog(final OsmandMapTileView mapView){ private LayerMenuListener(ContextMenuAdapter adapter,
final OsmandSettings settings = getApplication().getSettings(); OsmandMapTileView mapView, OsmandSettings settings) {
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity); this.adapter = adapter;
adapter.registerSelectedItem(R.string.layer_poi, settings.SHOW_POI_OVER_MAP.get() ? 1 : 0, this.mapView = mapView;
R.drawable.list_activities_poi); this.settings = settings;
adapter.registerSelectedItem(R.string.layer_poi_label, settings.SHOW_POI_LABEL.get() ? 1 : 0,
0);
adapter.registerSelectedItem(R.string.layer_favorites, settings.SHOW_FAVORITES.get() ? 1 : 0,
R.drawable.list_activities_favorites);
adapter.registerSelectedItem(R.string.layer_gpx_layer,
getApplication().getGpxFileToDisplay() != null ? 1 : 0, R.drawable.list_activities_gpx_tracks);
if(routeInfoLayer.couldBeVisible()){
adapter.registerSelectedItem(R.string.layer_route,
routeInfoLayer.isUserDefinedVisible() ? 1 : 0, 0);
}
adapter.registerSelectedItem(R.string.layer_transport, settings.SHOW_TRANSPORT_OVER_MAP.get() ? 1 : 0,
R.drawable.list_activities_transport_stops);
if(TransportRouteHelper.getInstance().routeIsCalculated()){
adapter.registerSelectedItem(R.string.layer_transport_route,
routeInfoLayer.isUserDefinedVisible() ? 1 : 0, 0);
} }
public void setDialog(DialogInterface dialog) {
this.dialog = dialog;
}
OsmandPlugin.registerLayerContextMenu(mapView, adapter, activity); public void onClick(int item, boolean isChecked) {
final OnMultiChoiceClickListener listener = new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int item, boolean isChecked) {
int itemId = adapter.getItemId(item); int itemId = adapter.getItemId(item);
OnContextMenuClick clck = adapter.getClickAdapter(item); OnContextMenuClick clck = adapter.getClickAdapter(item);
if(clck != null) { if(clck != null) {
@ -275,28 +260,56 @@ public class MapActivityLayers {
updateLayers(mapView); updateLayers(mapView);
mapView.refreshMap(); mapView.refreshMap();
} }
}; }
public void openLayerSelectionDialog(final OsmandMapTileView mapView){
final OsmandSettings settings = getApplication().getSettings();
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity);
adapter.registerSelectedItem(R.string.layer_poi, settings.SHOW_POI_OVER_MAP.get() ? 1 : 0,
R.drawable.list_activities_poi);
adapter.registerSelectedItem(R.string.layer_poi_label, settings.SHOW_POI_LABEL.get() ? 1 : 0,
0);
adapter.registerSelectedItem(R.string.layer_favorites, settings.SHOW_FAVORITES.get() ? 1 : 0,
R.drawable.list_activities_favorites);
adapter.registerSelectedItem(R.string.layer_gpx_layer,
getApplication().getGpxFileToDisplay() != null ? 1 : 0, R.drawable.list_activities_gpx_tracks);
if(routeInfoLayer.couldBeVisible()){
adapter.registerSelectedItem(R.string.layer_route,
routeInfoLayer.isUserDefinedVisible() ? 1 : 0, 0);
}
adapter.registerSelectedItem(R.string.layer_transport, settings.SHOW_TRANSPORT_OVER_MAP.get() ? 1 : 0,
R.drawable.list_activities_transport_stops);
if(TransportRouteHelper.getInstance().routeIsCalculated()){
adapter.registerSelectedItem(R.string.layer_transport_route,
routeInfoLayer.isUserDefinedVisible() ? 1 : 0, 0);
}
OsmandPlugin.registerLayerContextMenu(mapView, adapter, activity);
final LayerMenuListener listener = new LayerMenuListener(adapter, mapView, settings);
Builder b = new AlertDialog.Builder(activity); Builder b = new AlertDialog.Builder(activity);
ListView list = new ListView(activity);
// list.setBackgroundColor(white); ListAdapter listAdapter = new ArrayAdapter<String>(
list.setCacheColorHint(activity.getResources().getColor(R.color.color_transparent)); activity,
b.setView(list); R.layout.layers_list_activity_item,
final AlertDialog dlg = b.create(); R.id.title,
final int minWidth = activity.getResources().getDrawable(R.drawable.list_activities_favorites).getMinimumWidth();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(activity, R.layout.layers_list_activity_item,
adapter.getItemNames()){ adapter.getItemNames()){
@Override @Override
public View getView(final int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
View row = activity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null); View v = activity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
((TextView) row.findViewById(R.id.title)).setText(adapter.getItemName(position)); TextView tv = (TextView)v.findViewById(R.id.title);
tv.setText(adapter.getItemName(position));
//Put the image on the TextView
if(adapter.getImageId(position) != 0) { if(adapter.getImageId(position) != 0) {
Drawable d = activity.getResources().getDrawable(adapter.getImageId(position)); tv.setCompoundDrawablesWithIntrinsicBounds(adapter.getImageId(position), 0, 0, 0);
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(d);
} else { } else {
LinearLayout.LayoutParams layoutParams = (android.widget.LinearLayout.LayoutParams) ((ImageView) row.findViewById(R.id.icon)).getLayoutParams(); tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.list_activities_transparent, 0, 0, 0);
layoutParams.leftMargin = minWidth;
} }
final CheckBox ch = ((CheckBox) row.findViewById(R.id.check_item));
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
if(adapter.getSelection(position) == -1){ if(adapter.getSelection(position) == -1){
ch.setVisibility(View.INVISIBLE); ch.setVisibility(View.INVISIBLE);
} else { } else {
@ -304,35 +317,27 @@ public class MapActivityLayers {
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listener.onClick(dlg, position, isChecked); listener.onClick(position, isChecked);
} }
}); });
} }
// row.setOnClickListener(new View.OnClickListener() { return v;
// @Override
// public void onClick(View v) {
// if(selectedList.get(position) >= 0) {
// ch.setChecked(!ch.isChecked());
// } else {
// listener.onClick(dlg, position, selectedList.get(position) > 0);
// }
// }
// });
return row;
} }
}; };
list.setAdapter(arrayAdapter);
list.setOnItemClickListener(new OnItemClickListener() { b.setAdapter(listAdapter, new OnClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onClick(DialogInterface dialog, int position) {
if(adapter.getSelection(position) >= 0) { if(adapter.getSelection(position) >= 0) {
CheckBox ch = ((CheckBox) view.findViewById(R.id.check_item)); listener.onClick(position, !(adapter.getSelection(position) > 0));
ch.setChecked(!ch.isChecked());
} else { } else {
listener.onClick(dlg, position, adapter.getSelection(position) > 0); listener.onClick(position, adapter.getSelection(position) > 0);
} }
} }
}); });
final AlertDialog dlg = b.create();
listener.setDialog(dlg);
dlg.setCanceledOnTouchOutside(true); dlg.setCanceledOnTouchOutside(true);
dlg.show(); dlg.show();
} }