Dark theme for drawer. Issue #1620.

This commit is contained in:
GaidamakUA 2015-09-01 15:58:43 +03:00
parent bbd2dcce37
commit bcd2dc151c
2 changed files with 87 additions and 83 deletions

View file

@ -1,14 +1,5 @@
package net.osmand.plus; package net.osmand.plus;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Typeface; import android.graphics.Typeface;
@ -23,9 +14,21 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import gnu.trove.list.array.TIntArrayList;
public class ContextMenuAdapter { public class ContextMenuAdapter {
private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class);
// Log log = // Log log =
@ -38,6 +41,7 @@ public class ContextMenuAdapter {
public OnRowItemClick() { public OnRowItemClick() {
} }
//boolean return type needed to desribe if drawer needed to be close or not //boolean return type needed to desribe if drawer needed to be close or not
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) { public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item); CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);
@ -53,8 +57,13 @@ public class ContextMenuAdapter {
public class BooleanResult { public class BooleanResult {
private boolean result = false; private boolean result = false;
public void setResult(boolean value) { result = value; } public void setResult(boolean value) {
public boolean getResult() { return result; } result = value;
}
public boolean getResult() {
return result;
}
} }
private final Context ctx; private final Context ctx;
@ -93,11 +102,11 @@ public class ContextMenuAdapter {
return anchor; return anchor;
} }
public int length(){ public int length() {
return items.size(); return items.size();
} }
public int getElementId(int pos){ public int getElementId(int pos) {
return items.get(pos); return items.get(pos);
} }
@ -105,11 +114,11 @@ public class ContextMenuAdapter {
return checkListeners.get(i); return checkListeners.get(i);
} }
public String getItemName(int pos){ public String getItemName(int pos) {
return itemNames.get(pos); return itemNames.get(pos);
} }
public String getItemDescr(int pos){ public String getItemDescr(int pos) {
return itemDescription.get(pos); return itemDescription.get(pos);
} }
@ -136,11 +145,11 @@ public class ContextMenuAdapter {
public Drawable getImage(OsmandApplication ctx, int pos, boolean light) { public Drawable getImage(OsmandApplication ctx, int pos, boolean light) {
int lst = iconList.get(pos); int lst = iconList.get(pos);
if(lst != 0) { if (lst != 0) {
return ctx.getResources().getDrawable(lst); return ctx.getResources().getDrawable(lst);
} }
int lstLight = iconListLight.get(pos); int lstLight = iconListLight.get(pos);
if(lstLight != 0) { if (lstLight != 0) {
return ctx.getIconsCache().getIcon(lstLight, light); return ctx.getIconsCache().getIcon(lstLight, light);
} }
return null; return null;
@ -159,14 +168,14 @@ public class ContextMenuAdapter {
return isCategory.get(pos) > 0; return isCategory.get(pos) > 0;
} }
public Item item(String name){ public Item item(String name) {
Item i = new Item(); Item i = new Item();
i.id = (name.hashCode() << 4) | items.size(); i.id = (name.hashCode() << 4) | items.size();
i.name = name; i.name = name;
return i; return i;
} }
public Item item(int resId){ public Item item(int resId) {
Item i = new Item(); Item i = new Item();
i.id = resId; i.id = resId;
i.name = ctx.getString(resId); i.name = ctx.getString(resId);
@ -219,7 +228,7 @@ public class ContextMenuAdapter {
return this; return this;
} }
public Item description(String descr){ public Item description(String descr) {
this.description = descr; this.description = descr;
return this; return this;
} }
@ -249,9 +258,6 @@ public class ContextMenuAdapter {
cat = b; cat = b;
return this; return this;
} }
} }
public String[] getItemNames() { public String[] getItemNames() {
@ -272,7 +278,7 @@ public class ContextMenuAdapter {
public int getLayoutId(int position) { public int getLayoutId(int position) {
int l = layoutIds.get(position); int l = layoutIds.get(position);
if(l != -1) { if (l != -1) {
return l; return l;
} }
return defaultLayoutId; return defaultLayoutId;
@ -284,13 +290,13 @@ public class ContextMenuAdapter {
} }
public void setChangeAppModeListener(ConfigureMapMenu.OnClickListener changeAppModeListener) { public void setChangeAppModeListener(ConfigureMapMenu.OnClickListener changeAppModeListener) {
this.changeAppModeListener = changeAppModeListener; this.changeAppModeListener = changeAppModeListener;
} }
public ArrayAdapter<?> createListAdapter(final Activity activity, final boolean holoLight) { public ArrayAdapter<?> createListAdapter(final Activity activity, final boolean holoLight) {
// XXX layoutId does not effect layout inflated.
final int layoutId = defaultLayoutId; final int layoutId = defaultLayoutId;
final OsmandApplication app = ((OsmandApplication) activity.getApplication()); final OsmandApplication app = ((OsmandApplication) activity.getApplication());
ArrayAdapter<String> listAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title, ArrayAdapter<String> listAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
@ -298,14 +304,6 @@ public class ContextMenuAdapter {
return listAdapter; 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<String> listAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
getItemNames(), app, holoLight);
return listAdapter;
}
public class ContextMenuArrayAdapter extends ArrayAdapter<String> { public class ContextMenuArrayAdapter extends ArrayAdapter<String> {
private Activity activity; private Activity activity;
private OsmandApplication app; private OsmandApplication app;
@ -324,7 +322,7 @@ public class ContextMenuAdapter {
public View getView(final int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View // User super class to create the View
Integer lid = getLayoutId(position); Integer lid = getLayoutId(position);
if (lid == R.layout.mode_toggles){ if (lid == R.layout.mode_toggles) {
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>(); final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, new View.OnClickListener() { return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, new View.OnClickListener() {
@Override @Override
@ -346,24 +344,29 @@ public class ContextMenuAdapter {
TextView tv = (TextView) convertView.findViewById(R.id.title); TextView tv = (TextView) convertView.findViewById(R.id.title);
tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position)); tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position));
Drawable imageId = getImage(app, position, holoLight); if (layoutId == R.layout.simple_list_menu_item) {
if (imageId != null) { int color = activity.getResources()
if (layoutId == R.layout.simple_list_menu_item) { .getColor(holoLight ? R.color.icon_color : R.color.dash_search_icon_dark);
float density = activity.getResources().getDisplayMetrics().density; Drawable imageId = app.getIconsCache().getPaintedContentIcon(
int paddingInPixels = (int) (24 * density); iconListLight.get(position), color);
int drawableSizeInPixels = (int) (24 * density); // 32 float density = activity.getResources().getDisplayMetrics().density;
imageId.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels); int paddingInPixels = (int) (24 * density);
tv.setCompoundDrawables(imageId, null, null, null); int drawableSizeInPixels = (int) (24 * density); // 32
tv.setCompoundDrawablePadding(paddingInPixels); imageId.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels);
} else { tv.setCompoundDrawables(imageId, null, null, null);
tv.setCompoundDrawablePadding(paddingInPixels);
} else {
Drawable imageId = getImage(app, position, holoLight);
if (imageId != null) {
((ImageView) convertView.findViewById(R.id.icon)).setImageDrawable(imageId); ((ImageView) convertView.findViewById(R.id.icon)).setImageDrawable(imageId);
convertView.findViewById(R.id.icon).setVisibility(View.VISIBLE); convertView.findViewById(R.id.icon).setVisibility(View.VISIBLE);
} else if (convertView.findViewById(R.id.icon) != null) {
convertView.findViewById(R.id.icon).setVisibility(View.GONE);
} }
} else if (convertView.findViewById(R.id.icon) != null){
convertView.findViewById(R.id.icon).setVisibility(View.GONE);
} }
if(isCategory(position)) { if (isCategory(position)) {
tv.setTypeface(Typeface.DEFAULT_BOLD); tv.setTypeface(Typeface.DEFAULT_BOLD);
} else { } else {
tv.setTypeface(null); tv.setTypeface(null);
@ -371,7 +374,7 @@ public class ContextMenuAdapter {
if (convertView.findViewById(R.id.check_item) != null) { if (convertView.findViewById(R.id.check_item) != null) {
final CompoundButton ch = (CompoundButton) convertView.findViewById(R.id.check_item); final CompoundButton ch = (CompoundButton) convertView.findViewById(R.id.check_item);
if(selectedList.get(position) != -1) { if (selectedList.get(position) != -1) {
ch.setOnCheckedChangeListener(null); ch.setOnCheckedChangeListener(null);
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedList.get(position) > 0); ch.setChecked(selectedList.get(position) > 0);
@ -394,9 +397,9 @@ public class ContextMenuAdapter {
} }
} }
if (convertView.findViewById(R.id.ProgressBar) != null){ if (convertView.findViewById(R.id.ProgressBar) != null) {
ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.ProgressBar); ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.ProgressBar);
if(loadingList.get(position) == 1){ if (loadingList.get(position) == 1) {
bar.setVisibility(View.VISIBLE); bar.setVisibility(View.VISIBLE);
} else { } else {
bar.setVisibility(View.INVISIBLE); bar.setVisibility(View.INVISIBLE);
@ -404,8 +407,8 @@ public class ContextMenuAdapter {
} }
String itemDescr = getItemDescr(position); String itemDescr = getItemDescr(position);
if (convertView.findViewById(R.id.descr) != null){ if (convertView.findViewById(R.id.descr) != null) {
((TextView)convertView.findViewById(R.id.descr)).setText(itemDescr); ((TextView) convertView.findViewById(R.id.descr)).setText(itemDescr);
} }
return convertView; return convertView;
} }

View file

@ -232,7 +232,8 @@ public class MapActivity extends AccessibleActivity {
final ListView menuItemsListView = (ListView) findViewById(R.id.menuItems); final ListView menuItemsListView = (ListView) findViewById(R.id.menuItems);
menuItemsListView.setDivider(null); menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = mapActions.createMainOptionsMenu(); final ContextMenuAdapter contextMenuAdapter = mapActions.createMainOptionsMenu();
final ArrayAdapter<?> simpleListAdapter = contextMenuAdapter.createSimpleListAdapter(this, contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
final ArrayAdapter<?> simpleListAdapter = contextMenuAdapter.createListAdapter(this,
settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME); settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME);
menuItemsListView.setAdapter(simpleListAdapter); menuItemsListView.setAdapter(simpleListAdapter);
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {