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

View file

@ -232,7 +232,8 @@ public class MapActivity extends AccessibleActivity {
final ListView menuItemsListView = (ListView) findViewById(R.id.menuItems);
menuItemsListView.setDivider(null);
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);
menuItemsListView.setAdapter(simpleListAdapter);
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {