Refactoring. Menu items now has color.

This commit is contained in:
GaidamakUA 2016-03-30 11:00:09 +03:00
parent e3dabb1ada
commit 64735bd505
9 changed files with 88 additions and 116 deletions

View file

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<ImageView
android:layout_marginLeft="14dip"
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="center"
android:layout_gravity="center_vertical"
tools:visibility="visible"
tools:background="@drawable/ic_action_delete_dark"/>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
tools:drawableLeft="@drawable/ic_action_search_dark"
android:layout_marginTop="11dip"
android:layout_marginBottom="11dip"
android:gravity="center_vertical"
android:text="@string/layer_poi"
android:textSize="@dimen/default_list_text_size"
android:textColor="@color/color_black"
android:drawablePadding="24dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical">
<ImageView
android:id="@+id/icon_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone"
android:focusable="false" />
<CheckBox
android:id="@+id/toggle_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:button="@drawable/ic_btn_wocheckbox"
android:focusable="false" />
</LinearLayout>
</LinearLayout>

View file

@ -7,7 +7,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
<android.support.v7.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -17,7 +17,7 @@
android:visibility="gone"
tools:visibility="visible"/>
<TextView
<android.support.v7.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -29,7 +29,7 @@
android:text="@string/layer_poi"
android:textSize="@dimen/default_list_text_size"/>
<ImageView
<android.support.v7.widget.AppCompatImageView
android:id="@+id/icon_settings"
android:layout_width="wrap_content"
android:layout_height="match_parent"

View file

@ -3,7 +3,6 @@ package net.osmand.plus;
import android.app.Activity;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
@ -36,8 +35,7 @@ public class ContextMenuAdapter {
private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class);
@LayoutRes
private int DEFAULT_LAYOUT_ID = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
R.layout.list_menu_item : R.layout.list_menu_item_native;
private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native;
List<ContextMenuItem> items = new ArrayList<>();
private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
@ -47,11 +45,6 @@ public class ContextMenuAdapter {
@Deprecated
public Drawable getImage(OsmandApplication ctx, int position, boolean light) {
@DrawableRes
int lst = items.get(position).getLightIcon();
if (lst != -1) {
return ContextCompat.getDrawable(ctx, lst);
}
@DrawableRes
int lstLight = items.get(position).getLightIcon();
if (lstLight != -1) {

View file

@ -1,19 +1,22 @@
package net.osmand.plus;
import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
public class ContextMenuItem {
@StringRes
private final int titleId;
private String title;
@DrawableRes
private final int icon;
@DrawableRes
private final int lightIcon;
@ColorRes
private final int colorRes;
@DrawableRes
private final int secondaryIcon;
private Boolean selected;
@ -27,16 +30,24 @@ public class ContextMenuItem {
private final ContextMenuAdapter.ItemClickListener itemClickListener;
private final ContextMenuAdapter.OnIntegerValueChangedListener integerListener;
private ContextMenuItem(int titleId, String title, int icon, int lightIcon,
int secondaryIcon, Boolean selected, int progress,
int layout, boolean loading, boolean category,
int pos, String description,
private ContextMenuItem(@StringRes int titleId,
String title,
@DrawableRes int lightIcon,
@ColorRes int colorRes,
@DrawableRes int secondaryIcon,
Boolean selected,
int progress,
@LayoutRes int layout,
boolean loading,
boolean category,
int pos,
String description,
ContextMenuAdapter.ItemClickListener itemClickListener,
ContextMenuAdapter.OnIntegerValueChangedListener integerListener) {
this.titleId = titleId;
this.title = title;
this.icon = icon;
this.lightIcon = lightIcon;
this.colorRes = colorRes;
this.secondaryIcon = secondaryIcon;
this.selected = selected;
this.progress = progress;
@ -49,6 +60,7 @@ public class ContextMenuItem {
this.integerListener = integerListener;
}
@StringRes
public int getTitleId() {
return titleId;
}
@ -57,15 +69,38 @@ public class ContextMenuItem {
return title;
}
@Deprecated
public int getIcon() {
return icon;
}
@DrawableRes
public int getLightIcon() {
return lightIcon;
}
@ColorRes
public int getColorRes() {
return colorRes;
}
@ColorRes
public int getThemedColorRes(Context context) {
if (getColorRes() != -1) {
return getColorRes();
} else {
return getDefaultColorRes(context);
}
}
@ColorInt
public int getThemedColor(Context context) {
return ContextCompat.getColor(context, getThemedColorRes(context));
}
@ColorRes
public static int getDefaultColorRes(Context context) {
final OsmandApplication app = (OsmandApplication) context.getApplicationContext();
boolean light = app.getSettings().isLightContent();
return light ? R.color.icon_color : 0;
}
@DrawableRes
public int getSecondaryIcon() {
return secondaryIcon;
}
@ -78,6 +113,7 @@ public class ContextMenuItem {
return progress;
}
@LayoutRes
public int getLayout() {
return layout;
}
@ -131,22 +167,27 @@ public class ContextMenuItem {
}
public static class ItemBuilder {
@StringRes
private int mTitleId;
private String mTitle;
private int mIcon = -1;
@DrawableRes
private int mLightIcon = -1;
@ColorRes
private int mColor = -1;
@DrawableRes
private int mSecondaryIcon = -1;
private Boolean mSelected = null;
private int mProgress = -1;
@LayoutRes
private int mLayout = -1;
private boolean mLoading = false;
private boolean mCat = false;
private int mPos = -1;
private boolean mIsCategory = false;
private int mPosition = -1;
private String mDescription = null;
private ContextMenuAdapter.ItemClickListener mItemClickListener = null;
private ContextMenuAdapter.OnIntegerValueChangedListener mIntegerListener = null;
public ItemBuilder setTitleId(int titleId, @Nullable Context context) {
public ItemBuilder setTitleId(@StringRes int titleId, @Nullable Context context) {
this.mTitleId = titleId;
if (context != null) {
mTitle = context.getString(titleId);
@ -160,18 +201,17 @@ public class ContextMenuItem {
return this;
}
@Deprecated
public ItemBuilder setIcon(int icon) {
mIcon = icon;
public ItemBuilder setColor(@ColorRes int color) {
mColor = color;
return this;
}
public ItemBuilder setColorIcon(int lightIcon) {
public ItemBuilder setColorIcon(@DrawableRes int lightIcon) {
mLightIcon = lightIcon;
return this;
}
public ItemBuilder setSecondaryIcon(int secondaryIcon) {
public ItemBuilder setSecondaryIcon(@DrawableRes int secondaryIcon) {
mSecondaryIcon = secondaryIcon;
return this;
}
@ -186,7 +226,7 @@ public class ContextMenuItem {
return this;
}
public ItemBuilder setLayout(int layout) {
public ItemBuilder setLayout(@LayoutRes int layout) {
mLayout = layout;
return this;
}
@ -196,13 +236,13 @@ public class ContextMenuItem {
return this;
}
public ItemBuilder setCategory(boolean cat) {
mCat = cat;
public ItemBuilder setCategory(boolean category) {
mIsCategory = category;
return this;
}
public ItemBuilder setPosition(int pos) {
mPos = pos;
public ItemBuilder setPosition(int position) {
mPosition = position;
return this;
}
@ -222,8 +262,8 @@ public class ContextMenuItem {
}
public ContextMenuItem createItem() {
return new ContextMenuItem(mTitleId, mTitle, mIcon, mLightIcon, mSecondaryIcon,
mSelected, mProgress, mLayout, mLoading, mCat, mPos, mDescription,
return new ContextMenuItem(mTitleId, mTitle, mLightIcon, mColor, mSecondaryIcon,
mSelected, mProgress, mLayout, mLoading, mIsCategory, mPosition, mDescription,
mItemClickListener, mIntegerListener);
}
}

View file

@ -198,7 +198,7 @@ public class IntermediatePointsDialog {
final List<TargetPoint> intermediates, final TIntArrayList originalPositions, final boolean[] checkedIntermediates) {
final int padding = (int) (12 * activity.getResources().getDisplayMetrics().density + 0.5f);
final ArrayAdapter<TargetPoint> listadapter = new ArrayAdapter<TargetPoint>(app,
changeOrder? R.layout.change_order_item : R.layout.list_menu_item, R.id.title,
changeOrder? R.layout.change_order_item : R.layout.list_menu_item_native, R.id.title,
intermediates) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {

View file

@ -306,10 +306,11 @@ public class MapActivityLayers {
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder();
builder.setTitle(f.getName());
if (RenderingIcons.containsBigIcon(f.getIconId())) {
builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId()));
builder.setColorIcon(RenderingIcons.getBigIconResourceId(f.getIconId()));
} else {
builder.setIcon(R.drawable.mx_user_defined);
builder.setColorIcon(R.drawable.mx_user_defined);
}
builder.setColor(R.color.color_white);
adapter.addItem(builder.createItem());
}

View file

@ -8,7 +8,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
@ -114,12 +113,7 @@ public class StartGPSStatus extends OsmAndAction {
lp.setMargins(7, 10, 7, 0);
cb.setLayoutParams(lp);
final int layout;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
layout = R.layout.list_menu_item;
} else {
layout = R.layout.list_menu_item_native;
}
final int layout = R.layout.list_menu_item_native;
final ArrayAdapter<GpsStatusApps> adapter = new ArrayAdapter<GpsStatusApps>(mapActivity, layout, GpsStatusApps.values()) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View file

@ -5,7 +5,9 @@ import android.app.Application;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.View;
@ -261,7 +263,6 @@ public class GpxUiHelper {
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
// final int padding = (int) (12 * activity.getResources().getDisplayMetrics().density + 0.5f);
final boolean light = app.getSettings().isLightContent();
final int layout = R.layout.list_menu_item_native;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title,
@ -274,10 +275,12 @@ public class GpxUiHelper {
v = activity.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(adapter.getImage(app, position, light));
ImageView iconView = (ImageView) v.findViewById(R.id.icon);
Drawable icon = ContextCompat.getDrawable(activity, item.getLightIcon());
DrawableCompat.setTint(icon, item.getThemedColor(activity));
iconView.setImageDrawable(icon);
final ArrayAdapter<String> arrayAdapter = this;
icon.setOnClickListener(new View.OnClickListener() {
iconView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (showCurrentGpx && position == 0) {
@ -294,9 +297,9 @@ public class GpxUiHelper {
});
if (showCurrentGpx && position == 0) {
icon.setVisibility(View.INVISIBLE);
iconView.setVisibility(View.INVISIBLE);
} else {
icon.setVisibility(View.VISIBLE);
iconView.setVisibility(View.VISIBLE);
}
TextView tv = (TextView) v.findViewById(R.id.title);
tv.setText(item.getTitle());

View file

@ -302,7 +302,8 @@ public class OsmEditingPlugin extends OsmandPlugin {
if (fragment instanceof AvailableGPXFragment) {
final AvailableGPXFragment f = ((AvailableGPXFragment) fragment);
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity)
.setIcon(R.drawable.ic_action_export)
.setColorIcon(R.drawable.ic_action_export)
.setColor(R.color.color_white)
.setListener(new ItemClickListener() {
@Override