Rewrite UI in ImportGpxBottomSheetDialogFragment; fix some small issues
This commit is contained in:
parent
eb3ed364d8
commit
abbe3284d2
6 changed files with 64 additions and 188 deletions
|
@ -1,142 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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:layout_gravity="bottom"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/import_gpx_scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/import_gpx_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:text="@string/import_file"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/import_gpx_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_descr_height"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="Berlin_CultourTour.gpx can be imported as Favorites points, or as track file."/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/import_as_favorites_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/import_as_favorites_icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_fav_dark"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="@string/import_as_favorites"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/import_as_gpx_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/import_as_gpx_icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_polygom_dark"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="@string/import_as_gpx"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/cancel_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/shared_string_cancel"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textStyle="bold"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -13,7 +13,7 @@ import net.osmand.plus.R;
|
|||
|
||||
public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
||||
|
||||
protected String description;
|
||||
protected CharSequence description;
|
||||
@ColorRes
|
||||
private int descriptionColorId = INVALID_ID;
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
Drawable icon,
|
||||
String title,
|
||||
@ColorRes int titleColorId,
|
||||
String description,
|
||||
CharSequence description,
|
||||
@ColorRes int descriptionColorId) {
|
||||
super(customView, layoutId, clickable, onClickListener, position, icon, title, titleColorId);
|
||||
this.description = description;
|
||||
|
@ -50,11 +50,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
|
||||
public static class Builder extends SimpleBottomSheetItem.Builder {
|
||||
|
||||
protected String description;
|
||||
protected CharSequence description;
|
||||
@ColorRes
|
||||
protected int descriptionColorId = INVALID_ID;
|
||||
|
||||
public Builder setDescription(String description) {
|
||||
public Builder setDescription(CharSequence description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
|||
|
||||
public class DescriptionItem extends BottomSheetItemWithDescription {
|
||||
|
||||
public DescriptionItem(String description) {
|
||||
public DescriptionItem(CharSequence description) {
|
||||
this.description = description;
|
||||
this.layoutId = R.layout.bottom_sheet_item_description;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@ public class DividerHalfItem extends DividerItem {
|
|||
super(context, colorId, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getTopMargin(Context context) {
|
||||
return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_top);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeftMargin(Context context) {
|
||||
return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_start);
|
||||
|
|
|
@ -39,21 +39,28 @@ public class DividerItem extends BaseBottomSheetItem {
|
|||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(app, container, nightMode);
|
||||
|
||||
int marginTopBottom = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
|
||||
int height = AndroidUtils.dpToPx(app, 1);
|
||||
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||
params.setMargins(getLeftMargin(app), marginTopBottom, 0, marginTopBottom);
|
||||
params.setMargins(getLeftMargin(app), getTopMargin(app), 0, getBottomMargin(app));
|
||||
params.height = height;
|
||||
|
||||
view.setMinimumHeight(height);
|
||||
view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode)));
|
||||
}
|
||||
|
||||
protected int getTopMargin(Context context) {
|
||||
return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
|
||||
}
|
||||
|
||||
protected int getLeftMargin(Context context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected int getBottomMargin(Context context) {
|
||||
return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
private int getBgColorId(boolean nightMode) {
|
||||
if (colorId != INVALID_ID) {
|
||||
|
|
|
@ -13,20 +13,18 @@ import android.os.Bundle;
|
|||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
|
@ -39,6 +37,11 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -744,50 +747,53 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
items.add(new TitleItem(getString(R.string.import_file)));
|
||||
|
||||
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_import_gpx_bottom_sheet_dialog, container);
|
||||
|
||||
if (nightMode) {
|
||||
((TextView) mainView.findViewById(R.id.import_gpx_title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark));
|
||||
}
|
||||
|
||||
((ImageView) mainView.findViewById(R.id.import_as_favorites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark));
|
||||
((ImageView) mainView.findViewById(R.id.import_as_gpx_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
|
||||
|
||||
int nameColor = ContextCompat.getColor(getContext(), nightMode ? R.color.osmand_orange : R.color.dashboard_blue);
|
||||
int descrColor = ContextCompat.getColor(getContext(), nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light);
|
||||
int nameColor = getResolvedColor(nightMode ? R.color.osmand_orange : R.color.dashboard_blue);
|
||||
int descrColor = getResolvedColor(nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light);
|
||||
String descr = getString(R.string.import_gpx_file_description);
|
||||
SpannableStringBuilder text = new SpannableStringBuilder(fileName).append(" ").append(descr);
|
||||
text.setSpan(new ForegroundColorSpan(nameColor), 0, fileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
text.setSpan(new ForegroundColorSpan(descrColor), fileName.length() + 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
((TextView) mainView.findViewById(R.id.import_gpx_description)).setText(text);
|
||||
|
||||
mainView.findViewById(R.id.import_as_favorites_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
importHelper.importFavoritesImpl(gpxFile, fileName, false);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
mainView.findViewById(R.id.import_as_gpx_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
importHelper.handleResult(gpxFile, fileName, save, useImportDir, false);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
items.add(new DescriptionItem(text));
|
||||
|
||||
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
BaseBottomSheetItem asFavoritesItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_fav_dark))
|
||||
.setTitle(getString(R.string.import_as_favorites))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
importHelper.importFavoritesImpl(gpxFile, fileName, false);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(asFavoritesItem);
|
||||
|
||||
setupHeightAndBackground(mainView, R.id.import_gpx_scroll_view);
|
||||
items.add(new DividerHalfItem(getContext()));
|
||||
|
||||
return mainView;
|
||||
BaseBottomSheetItem asGpxItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
|
||||
.setTitle(getString(R.string.import_as_gpx))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
importHelper.handleResult(gpxFile, fileName, save, useImportDir, false);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(asGpxItem);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
private int getResolvedColor(@ColorRes int colorId) {
|
||||
return ContextCompat.getColor(getContext(), colorId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue