Add buttons

This commit is contained in:
Dima-1 2020-03-12 19:08:19 +02:00
parent b636e4e4ae
commit 9a0a518948
4 changed files with 162 additions and 118 deletions

View file

@ -44,8 +44,8 @@ public class GPXUtilities {
public final static Log log = PlatformUtil.getLog(GPXUtilities.class);
private static final String ICON_NAME_EXTENSION = "icon";
private static final String DEFAULT_ICON_NAME = "special_star";
public static final String BACK_TYPE_EXTENSION = "background";
private static final String DEFAULT_BACK_TYPE = "CIRCLE";
private static final String BACKGROUND_TYPE_EXTENSION = "background";
private static final String DEFAULT_BACKGROUND_TYPE = "CIRCLE";
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$
@ -274,15 +274,15 @@ public class GPXUtilities {
}
public String getBackType() {
String backType = getExtensionsToRead().get(BACK_TYPE_EXTENSION);
String backType = getExtensionsToRead().get(BACKGROUND_TYPE_EXTENSION);
if (backType == null) {
backType = DEFAULT_BACK_TYPE;
backType = DEFAULT_BACKGROUND_TYPE;
}
return backType;
}
public void setBackType(String backType) {
getExtensionsToWrite().put(BACK_TYPE_EXTENSION, backType);
getExtensionsToWrite().put(BACKGROUND_TYPE_EXTENSION, backType);
}
@Override

View file

@ -3,16 +3,16 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:paddingRight="11dp"
android:paddingStart="0dp"
android:paddingLeft="0dp"
android:paddingEnd="11dp"
android:paddingStart="0dp">
android:paddingEnd="9dp"
android:paddingRight="9dp"
android:paddingBottom="4dp">
<ImageView
android:id="@+id/outline"
android:layout_width="46dp"
android:layout_height="46dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:visibility="invisible"
app:srcCompat="@drawable/circle_contour_bg_light" />
@ -20,15 +20,15 @@
android:id="@+id/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_margin="4dp"
android:background="@drawable/bg_point_circle" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="11dp"
android:layout_margin="12dp"
android:clickable="false"
android:visibility="gone"
app:srcCompat="@drawable/mx_special_star_stroked"/>
app:srcCompat="@drawable/mx_special_star_stroked" />
</FrameLayout>

View file

@ -257,6 +257,7 @@
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
tools:itemCount="1"
tools:listitem="@layout/point_group_select_item" />
</LinearLayout>
@ -282,13 +283,22 @@
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/group_name_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
tools:itemCount="1"
tools:listitem="@layout/point_group_select_item" />
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="13dp"
android:layout_marginStart="13dp" />
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="6dp" />
<View
android:layout_width="wrap_content"
@ -337,8 +347,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="13dp"
android:layout_marginStart="13dp" />
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp" />
<View
@ -388,8 +398,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="13dp"
android:layout_marginStart="13dp" />
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp" />
<View
android:layout_width="wrap_content"
@ -409,12 +419,43 @@
<ImageView
android:id="@+id/replace_action_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/replace_all"
android:layout_height="wrap_content"
android:contentDescription="@string/update_existing"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingRight="32dp"
android:paddingTop="21dp"
android:paddingBottom="21dp"
android:src="@drawable/ic_action_replace" />
tools:src="@drawable/ic_action_replace"
android:paddingEnd="32dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/replace_action_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/update_existing"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="@string/update_existing" />
<TextView
android:id="@+id/replace_action_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textSize="@dimen/default_desc_text_size"
android:text="@string/shared_string_delete"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="@string/shared_string_delete" />
</LinearLayout>
</LinearLayout>
<LinearLayout
@ -431,9 +472,21 @@
android:layout_height="wrap_content"
android:contentDescription="@string/delete_point"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_action_delete_dark" />
android:paddingStart="16dp"
android:paddingRight="32dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:src="@drawable/ic_action_delete_dark"
android:paddingEnd="32dp" />
<TextView
android:id="@+id/delete_action_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/shared_string_delete"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="@string/shared_string_delete" />
</LinearLayout>
</LinearLayout>
@ -456,68 +509,10 @@
android:layout_height="1dp"
android:background="?attr/divider_color" />
<LinearLayout
android:id="@+id/buttons_layout"
<include
layout="@layout/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/activity_background_color"
android:orientation="horizontal">
<Button
android:id="@+id/delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:text="@string/shared_string_delete"
android:textColor="?attr/contextMenuButtonColor" />
<Button
android:id="@+id/replace_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:text="@string/update_existing"
android:textColor="?attr/contextMenuButtonColor"
android:visibility="gone" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<Button
android:id="@+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:text="@string/shared_string_cancel"
android:textColor="?attr/contextMenuButtonColor" />
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:text="@string/shared_string_save"
android:textColor="?attr/contextMenuButtonColor" />
</LinearLayout>
android:layout_height="@dimen/dialog_button_ex_height" />
</LinearLayout>
</LinearLayout>

View file

@ -64,11 +64,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
private View view;
private EditText nameEdit;
private ImageView nameIcon;
private Button addDelDescription;
private boolean cancelled;
private boolean nightMode;
private GroupAdapter groupListAdapter;
private String selectedIcon;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -91,7 +89,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
toolbar.setTitle(getToolbarTitle());
final OsmandApplication app = requireMyApplication();
Drawable icBack = app.getUIUtilities().getIcon(R.drawable.ic_arrow_back, nightMode ? R.color.active_buttons_and_links_text_dark : R.color.description_font_and_bottom_sheet_icons);
Drawable icBack = app.getUIUtilities().getIcon(R.drawable.ic_arrow_back,
nightMode ? R.color.active_buttons_and_links_text_dark : R.color.description_font_and_bottom_sheet_icons);
toolbar.setNavigationIcon(icBack);
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@ -114,6 +113,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon);
deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
// ((TextView)view.findViewById(R.id.replace_action_title)).setTextColor(ContextCompat.getColor(app,activeColorResId));
// ((TextView)view.findViewById(R.id.replace_action_description)).setTextColor(ContextCompat.getColor(app,activeColorResId));
// ((TextView)view.findViewById(R.id.delete_action_title)).setTextColor(ContextCompat.getColor(app,activeColorResId));
View groupList = view.findViewById(R.id.group_list_button);
groupList.setOnClickListener(new View.OnClickListener() {
@Override
@ -124,9 +127,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
}
});
Button saveButton = (Button) view.findViewById(R.id.save_button);
saveButton.setTextColor(getResources().getColor(activeColorResId));
view.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
View saveButton = view.findViewById(R.id.right_bottom_button);
saveButton.setVisibility(View.VISIBLE);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -134,8 +137,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
});
Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
cancelButton.setTextColor(getResources().getColor(activeColorResId));
View cancelButton = view.findViewById(R.id.dismiss_button);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -144,21 +146,24 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
});
Button deleteButton = (Button) view.findViewById(R.id.delete_button);
deleteButton.setTextColor(getResources().getColor(activeColorResId));
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deletePressed();
}
});
// Button deleteButton = (Button) view.findViewById(R.id.delete_button);
// deleteButton.setTextColor(getResources().getColor(activeColorResId));
// deleteButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// deletePressed();
// }
// });
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(nightMode, saveButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_save);
TextInputLayout nameCaption = (TextInputLayout) view.findViewById(R.id.name_caption);
nameCaption.setHint(getString(R.string.shared_string_name));
nameEdit = (EditText) view.findViewById(R.id.name_edit);
nameEdit.setText(getNameInitValue());
nameIcon = (ImageView) view.findViewById(R.id.name_icon);
ImageView nameIcon = (ImageView) view.findViewById(R.id.name_icon);
TextView categoryEdit = view.findViewById(R.id.groupName);
if (categoryEdit != null) {
AndroidUtils.setTextPrimaryColor(view.getContext(), categoryEdit, !editor.isLight());
@ -192,20 +197,18 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
if (app.accessibilityEnabled()) {
nameCaption.setFocusable(true);
// categoryCaption.setFocusable(true);
// nameEdit.setHint(R.string.access_hint_enter_name);
// categoryEdit.setHint(R.string.access_hint_enter_category);
// descriptionEdit.setHint(R.string.access_hint_enter_description);
nameEdit.setHint(R.string.access_hint_enter_name);
descriptionEdit.setHint(R.string.access_hint_enter_description);
}
if (editor.isNew()) {
toolbarAction.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId));
deleteButton.setVisibility(View.GONE);
// deleteButton.setVisibility(View.GONE);
descriptionCaption.setVisibility(View.GONE);
deleteIcon.setVisibility(View.GONE);
} else {
toolbarAction.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
deleteButton.setVisibility(View.VISIBLE);
// deleteButton.setVisibility(View.VISIBLE);
deleteIcon.setVisibility(View.VISIBLE);
if (!descriptionEdit.getText().toString().isEmpty() || descriptionCaption.getVisibility() != View.VISIBLE) {
descriptionCaption.setVisibility(View.VISIBLE);
@ -225,8 +228,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
private void createGroupSelector(OsmandApplication app) {
groupListAdapter = new GroupAdapter(app);
GroupAdapter groupListAdapter = new GroupAdapter(app);
groupListAdapter.setItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -238,11 +240,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
});
groupListAdapter.setSelectedItemName(getCategoryInitValue());
LinearLayoutManager layoutManager = new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false);
RecyclerView recyclerView = view.findViewById(R.id.group_recycler_view);
recyclerView.setAdapter(groupListAdapter);
recyclerView.setLayoutManager(layoutManager);
RecyclerView groupRecyclerView = view.findViewById(R.id.group_recycler_view);
groupRecyclerView.setAdapter(groupListAdapter);
groupRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
groupListAdapter.notifyDataSetChanged();
}
@ -319,6 +319,14 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
e.printStackTrace();
}
}
GroupNameAdapter groupNameListAdapter = new GroupNameAdapter();
groupNameListAdapter.setItems(new ArrayList<>(group.keySet()));
RecyclerView groupNameRecyclerView = view.findViewById(R.id.group_name_recycler_view);
groupNameRecyclerView.setAdapter(groupNameListAdapter);
groupNameRecyclerView.setLayoutManager(new LinearLayoutManager(requireMyApplication(), RecyclerView.HORIZONTAL, false));
groupNameListAdapter.notifyDataSetChanged();
for (String name : iconNameList) {
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
}
@ -333,6 +341,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
AndroidUtils.setBackground(backgroundCircle,
UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.bg_point_circle),
ContextCompat.getColor(app, R.color.divider_color_light)));
GradientDrawable rectContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
if (rectContourDrawable != null) {
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 2), ContextCompat.getColor(app, R.color.divider_color_light));
ImageView outline = iconItemView.findViewById(R.id.outline);
outline.setImageDrawable(rectContourDrawable);
}
ImageView icon = iconItemView.findViewById(R.id.icon);
icon.setVisibility(View.VISIBLE);
final int iconRes = app.getResources().getIdentifier("mx_" + iconName, "drawable", app.getPackageName());
@ -702,4 +716,39 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
groupButton = itemView.findViewById(R.id.outlineRect);
}
}
class GroupNameAdapter extends RecyclerView.Adapter<NameViewHolder> {
List<String> items;
public void setItems(List<String> items) {
this.items = items;
}
@NonNull
@Override
public NameViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Button view;
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
view = new Button(requireMyApplication());
return new NameViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull NameViewHolder holder, int position) {
((Button) holder.itemView).setText(items.get(position));
}
@Override
public int getItemCount() {
return items.size();
}
}
static class NameViewHolder extends RecyclerView.ViewHolder {
NameViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}