Dark theme for drawer. Issue #1620.
This commit is contained in:
parent
bbd2dcce37
commit
bcd2dc151c
2 changed files with 87 additions and 83 deletions
|
@ -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 =
|
||||
|
||||
|
@ -33,11 +36,12 @@ public class ContextMenuAdapter {
|
|||
//boolean return type needed to desribe if drawer needed to be close or not
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked);
|
||||
}
|
||||
|
||||
|
||||
public static abstract class OnRowItemClick implements OnContextMenuClick {
|
||||
|
||||
|
||||
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,10 +57,15 @@ 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;
|
||||
private View anchor;
|
||||
private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
|
||||
|
@ -84,35 +93,35 @@ public class ContextMenuAdapter {
|
|||
public ContextMenuAdapter(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
|
||||
public void setAnchor(View anchor) {
|
||||
this.anchor = anchor;
|
||||
}
|
||||
|
||||
|
||||
public View getAnchor() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public OnContextMenuClick getClickAdapter(int i) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public void setItemName(int pos, String str) {
|
||||
itemNames.set(pos, str);
|
||||
}
|
||||
|
@ -120,7 +129,7 @@ public class ContextMenuAdapter {
|
|||
public void setItemDescription(int pos, String str) {
|
||||
itemDescription.set(pos, str);
|
||||
}
|
||||
|
||||
|
||||
public int getSelection(int pos) {
|
||||
return selectedList.get(pos);
|
||||
}
|
||||
|
@ -128,24 +137,24 @@ public class ContextMenuAdapter {
|
|||
public int getLoading(int pos) {
|
||||
return loadingList.get(pos);
|
||||
}
|
||||
|
||||
|
||||
public void setSelection(int pos, int s) {
|
||||
selectedList.set(pos, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public int getBackgroundColor(Context ctx, boolean holoLight) {
|
||||
if (holoLight) {
|
||||
return ctx.getResources().getColor(R.color.bg_color_light);
|
||||
|
@ -153,26 +162,26 @@ public class ContextMenuAdapter {
|
|||
return ctx.getResources().getColor(R.color.bg_color_dark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isCategory(int pos) {
|
||||
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);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
public class Item {
|
||||
int icon = 0;
|
||||
int lightIcon = 0;
|
||||
|
@ -193,7 +202,7 @@ public class ContextMenuAdapter {
|
|||
this.icon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Item iconColor(int icon) {
|
||||
this.lightIcon = icon;
|
||||
return this;
|
||||
|
@ -213,13 +222,13 @@ public class ContextMenuAdapter {
|
|||
this.loading = loading;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Item layout(int l) {
|
||||
this.layout = l;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item description(String descr){
|
||||
public Item description(String descr) {
|
||||
this.description = descr;
|
||||
return this;
|
||||
}
|
||||
|
@ -249,15 +258,12 @@ public class ContextMenuAdapter {
|
|||
cat = b;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String[] getItemNames() {
|
||||
return itemNames.toArray(new String[itemNames.size()]);
|
||||
}
|
||||
|
||||
|
||||
public void removeItem(int pos) {
|
||||
items.removeAt(pos);
|
||||
itemNames.remove(pos);
|
||||
|
@ -272,34 +278,26 @@ public class ContextMenuAdapter {
|
|||
|
||||
public int getLayoutId(int position) {
|
||||
int l = layoutIds.get(position);
|
||||
if(l != -1) {
|
||||
if (l != -1) {
|
||||
return l;
|
||||
}
|
||||
return defaultLayoutId;
|
||||
return defaultLayoutId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setDefaultLayoutId(int defaultLayoutId) {
|
||||
this.defaultLayoutId = defaultLayoutId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setChangeAppModeListener(ConfigureMapMenu.OnClickListener changeAppModeListener) {
|
||||
this.changeAppModeListener = changeAppModeListener;
|
||||
}
|
||||
|
||||
|
||||
public ArrayAdapter<?> createListAdapter(final Activity activity, final boolean holoLight) {
|
||||
final int layoutId = defaultLayoutId;
|
||||
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
|
||||
ArrayAdapter<String> 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;
|
||||
|
||||
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,
|
||||
getItemNames(), app, holoLight);
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue