Merge remote-tracking branch 'origin/master'

This commit is contained in:
Rosty 2016-12-21 18:19:07 +02:00
commit 6cc44e601e
9 changed files with 601 additions and 1 deletions

View file

@ -0,0 +1,52 @@
<?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:layout_width="match_parent"
android:layout_height="16dp"
android:clickable="false"
android:orientation="vertical">
<include layout="@layout/card_bottom_divider"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<include layout="@layout/card_top_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="?attr/bg_color"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:visibility="gone"
android:paddingRight="16dp">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/TextAppearance.ListItemCategoryTitle"
tools:text="Live updates"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/toggle_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
</LinearLayout>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/custom_toolbar"
android:layout_width="match_parent"
android:background="@color/actionbar_light_color"
android:layout_height="?android:attr/actionBarSize"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/ctx_menu_info_view_bg"
/>
</LinearLayout>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:background="?attr/bg_color"
android:paddingRight="16dp"
android:paddingTop="8dp">
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="Screen 1"/>
</FrameLayout>

View file

@ -0,0 +1,82 @@
<?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:layout_width="match_parent"
android:background="?attr/bg_color"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/searchListItemLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/handle_view"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:focusable="false"
android:scaleType="centerInside"
android:src="@drawable/ic_action_reorder"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"
android:src="@drawable/ic_action_flag_dark"
android:scaleType="centerInside"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:layout_marginLeft="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Add marker"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="Action 1"/>
</LinearLayout>
<ImageView
android:id="@+id/closeImageButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_action_remove_dark"
android:scaleType="centerInside"/>
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
</LinearLayout>

View file

@ -2458,4 +2458,7 @@ If you need help with OsmAnd application, please contact our support team: suppo
<string name="number_of_edits">Number of edits</string>
<string name="reports_for">Report for</string>
<string name="file_name_containes_illegal_char">File name contains illegal character</string>
<string name="configure_screen_quick_action">Quick action</string>
<string name="quick_action_item_action">Action %d</string>
<string name="quick_action_item_screen">Screen %d</string>
</resources>

View file

@ -0,0 +1,48 @@
package net.osmand.plus.quickaction;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
/**
* Created by okorsun on 20.12.16.
*/
public class QuickActionItem {
private static final int HEADER_VALUE = -1;
private final int nameRes;
private final int drawableRes;
public QuickActionItem(@StringRes int nameRes, @DrawableRes int drawableRes) {
this.nameRes = nameRes;
this.drawableRes = drawableRes;
}
private QuickActionItem(){
nameRes = HEADER_VALUE;
drawableRes = HEADER_VALUE;
}
public static QuickActionItem createHeaderItem() {
return new QuickActionItem();
}
public int getNameRes() {
return nameRes;
}
public int getDrawableRes() {
return drawableRes;
}
public boolean isHeader() {
return nameRes == HEADER_VALUE;
}
// public interface QuickActionListItem{
// int getNameRes();
// int getDrawableRes();
// boolean isHeader();
// }
}

View file

@ -0,0 +1,53 @@
package net.osmand.plus.quickaction;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
/**
* Created by okorsun on 21.12.16.
*/
public class QuickActionItemTouchHelperCallback extends ItemTouchHelper.Callback {
OnItemMoveCallback itemMoveCallback;
public QuickActionItemTouchHelperCallback(OnItemMoveCallback itemMoveCallback) {
this.itemMoveCallback = itemMoveCallback;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
int swipeFlags = 0;
return !isaHeaderType(viewHolder) ? makeMovementFlags(dragFlags, swipeFlags) : 0;
}
@Override
public boolean isItemViewSwipeEnabled() {
return false;
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return itemMoveCallback.onMove(recyclerView, viewHolder, target);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
}
private boolean isaHeaderType(RecyclerView.ViewHolder viewHolder) {
return viewHolder.getItemViewType() == QuickActionListFragment.QuickActionAdapter.SCREEN_HEADER_TYPE;
}
interface OnItemMoveCallback {
boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target);
}
}

View file

@ -0,0 +1,269 @@
package net.osmand.plus.quickaction;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.R.id.toolbar;
/**
* Created by okorsun on 20.12.16.
*/
public class QuickActionListFragment extends BaseOsmAndFragment {
public static final String TAG = QuickActionListFragment.class.getSimpleName();
RecyclerView quickActionRV;
QuickActionAdapter adapter;
ItemTouchHelper touchHelper;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.quick_action_list, container, false);
quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view);
// quickActionRV.setBackgroundColor(
// getResources().getColor(
// getMyApplication().getSettings().isLightContent() ? R.color.bg_color_light
// : R.color.bg_color_dark));
adapter = new QuickActionAdapter(new OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
touchHelper.startDrag(viewHolder);
}
});
quickActionRV.setAdapter(adapter);
quickActionRV.setLayoutManager(new LinearLayoutManager(getContext()));
ItemTouchHelper.Callback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter);
touchHelper = new ItemTouchHelper(touchHelperCallback);
touchHelper.attachToRecyclerView(quickActionRV);
adapter.addItems(createMockDada());
Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar);
Drawable back = getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY);
toolbar.setNavigationIcon(back);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
toolbar.setTitle(R.string.configure_screen_quick_action);
toolbar.setTitleTextColor(ContextCompat.getColor(getContext(), R.color.color_white));
return view;
}
private List<QuickActionItem> createMockDada() {
List<QuickActionItem> result = new ArrayList<>();
for (int i = 0; i < 5; i ++){
result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark));
result.add(new QuickActionItem(R.string.poi, R.drawable.ic_action_flag_dark));
result.add(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark));
}
return result;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
}
public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
public static final int SCREEN_ITEM_TYPE = 1;
public static final int SCREEN_HEADER_TYPE = 2;
private static final int ITEMS_IN_GROUP = 6;
private List<QuickActionItem> itemsList = new ArrayList<>();
private final OnStartDragListener onStartDragListener;
public QuickActionAdapter(OnStartDragListener onStartDragListener){
this.onStartDragListener = onStartDragListener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (viewType == SCREEN_ITEM_TYPE)
return new QuickActionItemVH(inflater.inflate(R.layout.quick_action_list_item, parent, false));
else
return new QuickActionHeaderVH(inflater.inflate(R.layout.quick_action_list_header, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int viewType = getItemViewType(position);
QuickActionItem item = itemsList.get(position);
if (viewType == SCREEN_ITEM_TYPE) {
final QuickActionItemVH itemVH = (QuickActionItemVH) holder;
itemVH.title.setText(item.getNameRes());
itemVH.subTitle.setText(getResources().getString(R.string.quick_action_item_action, getActionPosition(position)));
itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getDrawableRes()));
itemVH.handleView.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reorder));
itemVH.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) ==
MotionEvent.ACTION_DOWN) {
onStartDragListener.onStartDrag(itemVH);
}
return false;
}
});
LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0);
} else {
QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder;
headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_action, position/(ITEMS_IN_GROUP + 1) + 1));
}
}
@Override
public int getItemCount() {
return itemsList.size();
}
@Override
public int getItemViewType(int position) {
return itemsList.get(position).isHeader() ? SCREEN_HEADER_TYPE : SCREEN_ITEM_TYPE;
}
public void deleteItem(int position) {
itemsList.remove(position);
notifyItemRemoved(position);
}
public void addItems(List<QuickActionItem> data) {
List<QuickActionItem> resultList = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
if (i % ITEMS_IN_GROUP == 0)
resultList.add(QuickActionItem.createHeaderItem());
resultList.add(data.get(i));
}
itemsList = resultList;
notifyDataSetChanged();
}
private int getActionPosition(int globalPosition) {
return globalPosition % (ITEMS_IN_GROUP + 1);
}
private boolean isShortDivider(int globalPosition) {
return getActionPosition(globalPosition) == ITEMS_IN_GROUP || (globalPosition + 1) == getItemCount();
}
private int dpToPx(float dp) {
Resources r = getActivity().getResources();
return (int) TypedValue.applyDimension(
COMPLEX_UNIT_DIP,
dp,
r.getDisplayMetrics()
);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
if (viewHolder.getItemViewType() == SCREEN_HEADER_TYPE || target.getItemViewType() == SCREEN_HEADER_TYPE)
return false;
else {
int selectedPosition = viewHolder.getAdapterPosition();
int targetPosition = target.getAdapterPosition();
Collections.swap(itemsList, selectedPosition, targetPosition);
if (selectedPosition - targetPosition < -1){
notifyItemMoved(selectedPosition, targetPosition);
notifyItemMoved(targetPosition - 1, selectedPosition);
} else if (selectedPosition - targetPosition > 1) {
notifyItemMoved(selectedPosition, targetPosition);
notifyItemMoved(targetPosition + 1, selectedPosition);
} else {
notifyItemMoved(selectedPosition, targetPosition);
}
notifyItemChanged(selectedPosition);
notifyItemChanged(targetPosition);
return true;
}
}
public class QuickActionItemVH extends RecyclerView.ViewHolder {
public TextView title;
public TextView subTitle;
public ImageView icon;
public View divider;
public ImageView handleView;
public QuickActionItemVH(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
subTitle = (TextView) itemView.findViewById(R.id.subtitle);
icon = (ImageView) itemView.findViewById(R.id.imageView);
divider = itemView.findViewById(R.id.divider);
handleView = (ImageView) itemView.findViewById(R.id.handle_view);
itemView.findViewById(R.id.closeImageButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
QuickActionAdapter.this.deleteItem(getAdapterPosition());
}
});
}
}
public class QuickActionHeaderVH extends RecyclerView.ViewHolder {
public TextView headerName;
public QuickActionHeaderVH(View itemView) {
super(itemView);
headerName = (TextView) itemView.findViewById(R.id.header);
}
}
}
public interface OnStartDragListener {
void onStartDrag(RecyclerView.ViewHolder viewHolder);
}
}

View file

@ -24,6 +24,7 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
@ -36,7 +37,6 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.zip.GZIPOutputStream;
public class MapWidgetRegistry {
@ -358,6 +358,7 @@ public class MapWidgetRegistry {
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
addQuickActionControl(map, cm, mode);
// Right panel
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
@ -384,6 +385,57 @@ public class MapWidgetRegistry {
return leftWidgetSet;
}
private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter,
final ApplicationMode mode) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity)
.setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem());
boolean selected = true;
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.configure_screen_quick_action, mapActivity)
.setIcon(R.drawable.map_quick_action)
.setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setSecondaryIcon( R.drawable.ic_action_additional_option)
.setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
setVisibility(adapter, position, isChecked, false);
return false;
}
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
int slideInAnim = R.anim.slide_in_bottom;
int slideOutAnim = R.anim.slide_out_bottom;
mapActivity.getSupportFragmentManager().beginTransaction()
.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
.add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG)
.addToBackStack(QuickActionListFragment.TAG).commitAllowingStateLoss();
return true;
}
private void setVisibility(ArrayAdapter<ContextMenuItem> adapter,
int position,
boolean visible,
boolean collapsed) {
// MapWidgetRegistry.this.setVisibility(r, visible, collapsed);
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
ContextMenuItem item = adapter.getItem(position);
item.setSelected(visible);
item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
})
.createItem());
}
private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter,
Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
for (final MapWidgetRegInfo r : groupTitle) {