From a4d31c18d548a47c63b9e140d392f8b951542f16 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 12 Feb 2020 18:54:25 +0200 Subject: [PATCH] complex button / import layouts --- .../layout/button_with_icon_and_subtext.xml | 93 ++++---- OsmAnd/res/layout/fragment_import.xml | 207 ++++++++++-------- .../res/layout/fragment_import_duplicates.xml | 152 +++++++------ OsmAnd/res/values/attrs.xml | 13 +- OsmAnd/res/values/strings.xml | 10 +- .../net/osmand/plus/helpers/ImportHelper.java | 2 + .../settings/ImportDuplicatesFragment.java | 52 ++++- .../plus/settings/ImportSettingsFragment.java | 88 +------- OsmAnd/src/net/osmand/view/ComplexButton.java | 95 ++++++++ 9 files changed, 406 insertions(+), 306 deletions(-) create mode 100644 OsmAnd/src/net/osmand/view/ComplexButton.java diff --git a/OsmAnd/res/layout/button_with_icon_and_subtext.xml b/OsmAnd/res/layout/button_with_icon_and_subtext.xml index 5fd3a5e087..f9de1da49a 100644 --- a/OsmAnd/res/layout/button_with_icon_and_subtext.xml +++ b/OsmAnd/res/layout/button_with_icon_and_subtext.xml @@ -1,59 +1,56 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="@dimen/dialog_button_ex_height"> - + - + - + - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 9fd2a11f0a..7e223e51a5 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -1,115 +1,130 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="?attr/activity_background_basic" + android:orientation="vertical"> - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index 67d4f244a6..3539093fa6 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -1,81 +1,103 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="?attr/activity_background_basic" + android:orientation="vertical"> - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index f30366f4a0..750eb1993a 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -163,6 +163,15 @@ - + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 776c685c1b..ff41160669 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,13 @@ Thx - Hardy --> + Current items will be replaced with items from the file + Replace all + Keep both + Imported items will be added with prexif + OsmAnd already has elements with the same names as those imported.\n\nSelect an action. + Some items already exist + Select the data to be imported. Direct-to-point Clear recorded data @@ -27,9 +34,6 @@ • Added correct transliteration into the map of Japan\n\n • Added Antarctica map\n\n - OsmAnd already has elements with the same names as those imported.\n\nSelect an action. - Some items already exist - Select the data to be imported. Copy coordinates Reset to default will reset sort order to the default state after installation. Use system screen timeout diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index ecdfdf49aa..7cc1f5f337 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -50,6 +50,8 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.settings.ImportDuplicatesFragment; +import net.osmand.plus.settings.ImportSettingsFragment; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.router.RoutingConfiguration; import net.osmand.util.Algorithms; diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index 37bec1bf7b..faf497d146 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -4,21 +4,25 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.FrameLayout; import net.osmand.plus.R; +import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.base.BaseOsmAndDialogFragment; +import net.osmand.view.ComplexButton; + +import java.util.List; -public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment { +public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implements View.OnClickListener { public static final String TAG = ImportSettingsFragment.class.getSimpleName(); - private FrameLayout replaceAllBtn; + private RecyclerView list; public static void showInstance(@NonNull FragmentManager fm) { ImportDuplicatesFragment fragment = new ImportDuplicatesFragment(); @@ -30,10 +34,48 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_import_duplicates, container, false); setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); - replaceAllBtn = root.findViewById(R.id.replace_all); - + ComplexButton replaceAllBtn = root.findViewById(R.id.replace_all_btn); + ComplexButton keepBothBtn = root.findViewById(R.id.keep_both_btn); + keepBothBtn.setIcon(getPaintedContentIcon(R.drawable.ic_action_keep_both, + getSettings().isLightContent() + ? getResources().getColor(R.color.icon_color_active_light) + : getResources().getColor(R.color.icon_color_active_dark)) + ); + replaceAllBtn.setIcon(getPaintedContentIcon(R.drawable.ic_action_replace, + getSettings().isLightContent() + ? getResources().getColor(R.color.active_buttons_and_links_text_light) + : getResources().getColor(R.color.active_buttons_and_links_text_dark)) + ); + keepBothBtn.setOnClickListener(this); + replaceAllBtn.setOnClickListener(this); + list = root.findViewById(R.id.list); return root; + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.keep_both_btn: { + keepBothItems(); + break; + } + case R.id.replace_all_btn: { + replaceAllItems(); + break; + } + } + } + + private void keepBothItems() { + + } + + private void replaceAllItems() { + + } + + private void importItems(List list) { } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index c8b17c9c68..7910f189f3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -1,87 +1 @@ -package net.osmand.plus.settings; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.FragmentManager; -import android.support.v7.widget.Toolbar; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ExpandableListView; -import android.widget.ExpandableListView.OnGroupClickListener; -import android.widget.ExpandableListView.OnChildClickListener; - -import net.osmand.plus.R; -import net.osmand.plus.SettingsHelper.SettingsItem; -import net.osmand.plus.base.BaseOsmAndDialogFragment; - -import java.util.List; - -public class ImportSettingsFragment extends BaseOsmAndDialogFragment - implements OnChildClickListener, OnGroupClickListener, View.OnClickListener { - - public static final String TAG = ImportSettingsFragment.class.getSimpleName(); - - private ExpandableListView listView; - - private Button selectAllBtn; - - private Button continueBtn; - - private List settingsItems; - - public static void showInstance(@NonNull FragmentManager fm, @NonNull List settingsItems) { - ImportSettingsFragment fragment = new ImportSettingsFragment(); - fragment.setSettingsItems(settingsItems); - fragment.show(fm, TAG); - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View root = inflater.inflate(R.layout.fragment_import, container, false); - setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); - listView = root.findViewById(android.R.id.list); - - return root; - } - - @Override - public void onClick(View view) { - - } - - @Override - public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) { - return false; - } - - @Override - public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) { - return false; - } - - public void setSettingsItems(List settingsItems) { - this.settingsItems = settingsItems; - } - - private void setupToolbar(Toolbar toolbar) { - toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.headline_close_button, - getSettings().isLightContent() - ? getResources().getColor(R.color.active_buttons_and_links_text_light) - : getResources().getColor(R.color.active_buttons_and_links_text_dark))); - toolbar.setNavigationContentDescription(R.string.shared_string_close); - toolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dismiss(); - } - }); - } - - private boolean isNightMode() { - return getSettings().isLightContent(); - } -} +package net.osmand.plus.settings; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnGroupClickListener; import android.widget.ExpandableListView.OnChildClickListener; import net.osmand.plus.R; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.widgets.TextViewEx; import java.util.List; public class ImportSettingsFragment extends BaseOsmAndDialogFragment implements OnChildClickListener, OnGroupClickListener, View.OnClickListener { public static final String TAG = ImportSettingsFragment.class.getSimpleName(); private boolean allSelected; private ExpandableListView listView; private TextViewEx selectBtn; private TextViewEx continueBtn; private List settingsItems; public static void showInstance(@NonNull FragmentManager fm, @NonNull List settingsItems) { ImportSettingsFragment fragment = new ImportSettingsFragment(); fragment.setSettingsItems(settingsItems); fragment.show(fm, TAG); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_import, container, false); setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); continueBtn = root.findViewById(R.id.continue_button); selectBtn = root.findViewById(R.id.select_button); listView = root.findViewById(android.R.id.list); continueBtn.setOnClickListener(this); selectBtn.setOnClickListener(this); return root; } @Override public void onClick(View view) { switch (view.getId()) { case R.id.select_button: { allSelected = !allSelected; selectBtn.setText(allSelected ? R.string.shared_string_deselect_all : R.string.shared_string_select_all); selectDeselectAll(); break; } case R.id.continue_button: { importItems(); break; } } } private void selectDeselectAll() { if (allSelected) { } else { } } private void importItems() { } private boolean checkDuplicates() { return false; } @Override public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) { return false; } @Override public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) { return false; } public void setSettingsItems(List settingsItems) { this.settingsItems = settingsItems; } private void setupToolbar(Toolbar toolbar) { toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.headline_close_button, getSettings().isLightContent() ? getResources().getColor(R.color.active_buttons_and_links_text_light) : getResources().getColor(R.color.active_buttons_and_links_text_dark))); toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/view/ComplexButton.java b/OsmAnd/src/net/osmand/view/ComplexButton.java new file mode 100644 index 0000000000..4ccd53ea4c --- /dev/null +++ b/OsmAnd/src/net/osmand/view/ComplexButton.java @@ -0,0 +1,95 @@ +package net.osmand.view; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; + +import net.osmand.plus.R; +import net.osmand.plus.widgets.TextViewEx; + +public class ComplexButton extends FrameLayout { + + private TextViewEx textTv; + private TextViewEx subTextTv; + private ImageView iconIv; + + public ComplexButton(@NonNull Context context) { + super(context); + inflateView(); + } + + public ComplexButton(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + inflateView(); + initView(attrs); + } + + public ComplexButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + inflateView(); + initView(attrs); + } + + private void inflateView() { + View view = LayoutInflater.from(getContext()).inflate(R.layout.button_with_icon_and_subtext, this); + textTv = view.findViewById(R.id.text); + subTextTv = view.findViewById(R.id.sub_text); + iconIv = view.findViewById(R.id.icon); + } + + private void initView(@Nullable AttributeSet attrs) { + TypedArray a = getContext().getTheme().obtainStyledAttributes( + attrs, + R.styleable.ComplexButton, + 0, 0); + try { + textTv.setText(a.getString(R.styleable.ComplexButton_setText)); + textTv.setTextColor(a.getColor(R.styleable.ComplexButton_setTextColor, Color.WHITE)); + subTextTv.setText(a.getString(R.styleable.ComplexButton_setSubText)); + subTextTv.setTextColor(a.getColor(R.styleable.ComplexButton_setSubTextColor, Color.WHITE)); + iconIv.setImageResource(a.getResourceId(R.styleable.ComplexButton_setIcon, 0)); + } finally { + a.recycle(); + } + } + + public void setText(String text) { + textTv.setText(text); + } + + public void setText(int textRes) { + textTv.setText(textRes); + } + + public void setTextColor(int color) { + textTv.setTextColor(color); + } + + public void setSubText(String subText) { + subTextTv.setText(subText); + } + + public void setSubText(int subTextRes) { + subTextTv.setText(subTextRes); + } + + public void setSubTextColor(int color) { + subTextTv.setTextColor(color); + } + + public void setIcon(int iconRes) { + iconIv.setImageResource(iconRes); + } + + public void setIcon(Drawable drawable) { + iconIv.setImageDrawable(drawable); + } +}