From b118e9f5a3785daff06f854dfc977ddca1623171 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Sat, 22 Aug 2015 15:55:28 +0300 Subject: [PATCH] icons without paddings --- OsmAnd/res/layout/fragment_edit_poi.xml | 3 +- OsmAnd/res/layout/list_menu_item.xml | 23 ++- OsmAnd/res/layout/main.xml | 100 +++++---- OsmAnd/res/layout/simple_list_menu_item.xml | 14 ++ .../net/osmand/plus/ContextMenuAdapter.java | 193 ++++++++++-------- .../osmand/plus/activities/MapActivity.java | 4 + 6 files changed, 201 insertions(+), 136 deletions(-) create mode 100644 OsmAnd/res/layout/simple_list_menu_item.xml diff --git a/OsmAnd/res/layout/fragment_edit_poi.xml b/OsmAnd/res/layout/fragment_edit_poi.xml index 15f10cc0bc..3da904aca7 100644 --- a/OsmAnd/res/layout/fragment_edit_poi.xml +++ b/OsmAnd/res/layout/fragment_edit_poi.xml @@ -6,7 +6,8 @@ android:layout_height="match_parent" android:background="@color/dashboard_background" android:orientation="vertical" - tools:context="net.osmand.plus.osmedit.EditPoiFragment"> + tools:context="net.osmand.plus.osmedit.EditPoiFragment" + android:clickable="true"> + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/LinearLayout1" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:layout_marginLeft="5dip" + android:layout_marginRight="5dip" + android:background="@color/color_white"> + android:layout_gravity="center_vertical" + tools:visibility="visible" + tools:background="@drawable/ic_action_delete_dark"/> - + android:layout_height="match_parent"> + android:id="@+id/drawer_layout" + android:layout_width="match_parent" + android:layout_height="match_parent"> - + + + + + + + + + + + android:layout_height="match_parent"> - + - + + + + + + - - - - - - + android:layout_gravity="left" + android:background="@color/dashboard_background"/> - - - \ No newline at end of file + \ No newline at end of file diff --git a/OsmAnd/res/layout/simple_list_menu_item.xml b/OsmAnd/res/layout/simple_list_menu_item.xml new file mode 100644 index 0000000000..a827bdda7a --- /dev/null +++ b/OsmAnd/res/layout/simple_list_menu_item.xml @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 3c4f0c33ef..f5ac92efed 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -289,91 +289,116 @@ public class ContextMenuAdapter { public ArrayAdapter createListAdapter(final Activity activity, final boolean holoLight) { final int layoutId = defaultLayoutId; final OsmandApplication app = ((OsmandApplication) activity.getApplication()); - ArrayAdapter listAdapter = new ArrayAdapter(activity, layoutId, R.id.title, - getItemNames()) { - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - // User super class to create the View - View v = convertView; - Integer lid = getLayoutId(position); - if (lid == R.layout.mode_toggles){ - final Set selected = new LinkedHashSet(); - return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, new View.OnClickListener() { - @Override - public void onClick(View view) { - if (selected.size() > 0) { - app.getSettings().APPLICATION_MODE.set(selected.iterator().next()); - notifyDataSetChanged(); - } - if (changeAppModeListener != null) { - changeAppModeListener.onClick(allModes.getResult()); - } - } - }); - } - if (v == null || (v.getTag() != lid)) { - v = activity.getLayoutInflater().inflate(lid, null); - v.setTag(lid); - } - TextView tv = (TextView) v.findViewById(R.id.title); - tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position)); - - Drawable imageId = getImage(app, position, holoLight); - if (imageId != null) { - ((ImageView) v.findViewById(R.id.icon)).setImageDrawable(imageId); - v.findViewById(R.id.icon).setVisibility(View.VISIBLE); - } else if (v.findViewById(R.id.icon) != null){ - v.findViewById(R.id.icon).setVisibility(View.GONE); - } - - if(isCategory(position)) { - tv.setTypeface(Typeface.DEFAULT_BOLD); - } else { - tv.setTypeface(null); - } - - if (v.findViewById(R.id.check_item) != null) { - final CompoundButton ch = (CompoundButton) v.findViewById(R.id.check_item); - if(selectedList.get(position) != -1) { - ch.setOnCheckedChangeListener(null); - ch.setVisibility(View.VISIBLE); - ch.setChecked(selectedList.get(position) > 0); - final ArrayAdapter la = this; - final OnCheckedChangeListener listener = new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - OnContextMenuClick ca = getClickAdapter(position); - selectedList.set(position, isChecked ? 1 : 0); - if (ca != null) { - ca.onContextMenuClick(la, getElementId(position), position, isChecked); - } - } - }; - ch.setOnCheckedChangeListener(listener); - ch.setVisibility(View.VISIBLE); - } else if (ch != null) { - ch.setVisibility(View.GONE); - } - } - - if (v.findViewById(R.id.ProgressBar) != null){ - ProgressBar bar = (ProgressBar) v.findViewById(R.id.ProgressBar); - if(loadingList.get(position) == 1){ - bar.setVisibility(View.VISIBLE); - } else { - bar.setVisibility(View.INVISIBLE); - } - } - - String itemDescr = getItemDescr(position); - if (v.findViewById(R.id.descr) != null){ - ((TextView)v.findViewById(R.id.descr)).setText(itemDescr); - } - return v; - } - }; + ArrayAdapter listAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title, + getItemNames(), app, holoLight); return listAdapter; } + public ArrayAdapter createSimpleListAdapter(final Activity activity, final boolean holoLight) { + final int layoutId = R.layout.simple_list_menu_item; + final OsmandApplication app = ((OsmandApplication) activity.getApplication()); + ArrayAdapter listAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title, + getItemNames(), app, holoLight); + return listAdapter; + } + + public class ContextMenuArrayAdapter extends ArrayAdapter { + private Activity activity; + private OsmandApplication app; + private boolean holoLight; + private int layoutId; + public ContextMenuArrayAdapter(Activity context, int resource, int textViewResourceId, + String[] objects, OsmandApplication app, boolean holoLight) { + super(context, resource, textViewResourceId, objects); + activity = context; + this.app = app; + this.holoLight = holoLight; + layoutId = resource; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + // User super class to create the View + Integer lid = getLayoutId(position); + if (lid == R.layout.mode_toggles){ + final Set selected = new LinkedHashSet(); + return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, new View.OnClickListener() { + @Override + public void onClick(View view) { + if (selected.size() > 0) { + app.getSettings().APPLICATION_MODE.set(selected.iterator().next()); + notifyDataSetChanged(); + } + if (changeAppModeListener != null) { + changeAppModeListener.onClick(allModes.getResult()); + } + } + }); + } + if (convertView == null || (convertView.getTag() != lid)) { + convertView = activity.getLayoutInflater().inflate(lid, null); + convertView.setTag(lid); + } + TextView tv = (TextView) convertView.findViewById(R.id.title); + tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position)); + + Drawable imageId = getImage(app, position, holoLight); + if (imageId != null) { + if (layoutId == R.layout.simple_list_menu_item) { + tv.setCompoundDrawablesWithIntrinsicBounds(imageId, null, null, null); + } else { + ((ImageView) convertView.findViewById(R.id.icon)).setImageDrawable(imageId); + convertView.findViewById(R.id.icon).setVisibility(View.VISIBLE); + } + } else if (convertView.findViewById(R.id.icon) != null){ + convertView.findViewById(R.id.icon).setVisibility(View.GONE); + } + + if(isCategory(position)) { + tv.setTypeface(Typeface.DEFAULT_BOLD); + } else { + tv.setTypeface(null); + } + + if (convertView.findViewById(R.id.check_item) != null) { + final CompoundButton ch = (CompoundButton) convertView.findViewById(R.id.check_item); + if(selectedList.get(position) != -1) { + ch.setOnCheckedChangeListener(null); + ch.setVisibility(View.VISIBLE); + ch.setChecked(selectedList.get(position) > 0); + final ArrayAdapter la = this; + final OnCheckedChangeListener listener = new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + OnContextMenuClick ca = getClickAdapter(position); + selectedList.set(position, isChecked ? 1 : 0); + if (ca != null) { + ca.onContextMenuClick(la, getElementId(position), position, isChecked); + } + } + }; + ch.setOnCheckedChangeListener(listener); + ch.setVisibility(View.VISIBLE); + } else if (ch != null) { + ch.setVisibility(View.GONE); + } + } + + if (convertView.findViewById(R.id.ProgressBar) != null){ + ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.ProgressBar); + if(loadingList.get(position) == 1){ + bar.setVisibility(View.VISIBLE); + } else { + bar.setVisibility(View.INVISIBLE); + } + } + + String itemDescr = getItemDescr(position); + if (convertView.findViewById(R.id.descr) != null){ + ((TextView)convertView.findViewById(R.id.descr)).setText(itemDescr); + } + return convertView; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 9e535713dc..6e17b51a66 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -22,6 +22,8 @@ import android.view.View; import android.view.ViewStub; import android.view.Window; import android.view.WindowManager; +import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -218,6 +220,8 @@ public class MapActivity extends AccessibleActivity { .add(R.id.fragmentContainer, new FirstUsageFragment(), FirstUsageFragment.TAG).commit(); } + ListView menuItemsListView = (ListView) findViewById(R.id.menuItems); + menuItemsListView.setAdapter(mapActions.createMainOptionsMenu().createSimpleListAdapter(this, true)); } private void checkAppInitialization() {