Fix orientation change and material in api 16
This commit is contained in:
parent
3e6a495139
commit
eb3094f253
7 changed files with 73 additions and 69 deletions
|
@ -41,6 +41,7 @@
|
||||||
android:layout_marginRight="@dimen/content_padding_small"
|
android:layout_marginRight="@dimen/content_padding_small"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
|
android:saveEnabled="false"
|
||||||
android:clickable="false"
|
android:clickable="false"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:focusableInTouchMode="false" />
|
android:focusableInTouchMode="false" />
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:focusable="true"
|
|
||||||
android:focusableInTouchMode="true"/>
|
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
|
||||||
android:id="@+id/name_text_box"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingEnd="@dimen/content_padding"
|
|
||||||
android:paddingLeft="@dimen/content_padding"
|
|
||||||
android:paddingRight="@dimen/content_padding"
|
|
||||||
android:paddingStart="@dimen/content_padding"
|
|
||||||
app:labelText="@string/shared_string_name">
|
|
||||||
|
|
||||||
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
|
||||||
android:id="@+id/name_edit_text"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -8,7 +8,7 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true"/>
|
android:focusableInTouchMode="true" />
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/name_text_box"
|
android:id="@+id/name_text_box"
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/name_edit_text"
|
android:id="@+id/name_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.plus.mapmarkers;
|
package net.osmand.plus.mapmarkers;
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
|
@ -70,14 +69,10 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
|
||||||
titleTv.setText(openFromCoordinateInput ? R.string.coord_input_save_as_track : R.string.marker_save_as_track);
|
titleTv.setText(openFromCoordinateInput ? R.string.coord_input_save_as_track : R.string.marker_save_as_track);
|
||||||
titleTv.setTextColor(ContextCompat.getColor(getContext(), textPrimaryColor));
|
titleTv.setTextColor(ContextCompat.getColor(getContext(), textPrimaryColor));
|
||||||
TextView descriptionTv = (TextView) mainView.findViewById(R.id.save_as_track_description);
|
TextView descriptionTv = (TextView) mainView.findViewById(R.id.save_as_track_description);
|
||||||
descriptionTv.setText(openFromCoordinateInput ? getString(R.string.coord_input_save_as_track_descr, number) : getString(R.string.marker_save_as_track_descr));
|
descriptionTv.setText(openFromCoordinateInput
|
||||||
int layoutRes;
|
? getString(R.string.coord_input_save_as_track_descr, String.valueOf(number))
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
: getString(R.string.marker_save_as_track_descr));
|
||||||
layoutRes = R.layout.markers_track_name_text_field_box;
|
contentLayout.addView(getLayoutInflater().inflate(R.layout.track_name_edit_text, contentLayout, false), 2);
|
||||||
} else {
|
|
||||||
layoutRes = R.layout.markers_track_name_edit_text;
|
|
||||||
}
|
|
||||||
contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 2);
|
|
||||||
if (portrait) {
|
if (portrait) {
|
||||||
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,17 +29,15 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
|
||||||
|
|
||||||
List<String> items = new ArrayList<>();
|
List<String> items = new ArrayList<>();
|
||||||
|
|
||||||
void setSelectedItemName(String selectedItemName) {
|
|
||||||
this.selectedItemName = selectedItemName;
|
|
||||||
}
|
|
||||||
|
|
||||||
String selectedItemName;
|
String selectedItemName;
|
||||||
OsmandApplication app;
|
OsmandApplication app;
|
||||||
boolean nightMode;
|
boolean nightMode;
|
||||||
|
FolderListAdapterListener listener;
|
||||||
|
|
||||||
FolderListAdapter(OsmandApplication app, boolean nightMode) {
|
FolderListAdapter(OsmandApplication app, boolean nightMode, String folderName) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.nightMode = nightMode;
|
this.nightMode = nightMode;
|
||||||
|
selectedItemName = folderName;
|
||||||
fillGroups();
|
fillGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +83,9 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
|
||||||
selectedItemName = items.get(holder.getAdapterPosition());
|
selectedItemName = items.get(holder.getAdapterPosition());
|
||||||
notifyItemChanged(holder.getAdapterPosition());
|
notifyItemChanged(holder.getAdapterPosition());
|
||||||
notifyItemChanged(previousSelectedPosition);
|
notifyItemChanged(previousSelectedPosition);
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onItemSelected(selectedItemName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
|
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
|
||||||
|
@ -120,14 +121,14 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
|
||||||
return items == null ? 0 : items.size();
|
return items == null ? 0 : items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getSelectedItem() {
|
|
||||||
return selectedItemName;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getItemPosition(String name) {
|
int getItemPosition(String name) {
|
||||||
return items.indexOf(name);
|
return items.indexOf(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(FolderListAdapterListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
static class GroupsViewHolder extends RecyclerView.ViewHolder {
|
static class GroupsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
final TextView groupName;
|
final TextView groupName;
|
||||||
|
@ -141,4 +142,9 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
|
||||||
groupButton = itemView.findViewById(R.id.outlineRect);
|
groupButton = itemView.findViewById(R.id.outlineRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface FolderListAdapterListener {
|
||||||
|
|
||||||
|
void onItemSelected(String item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1033,7 +1033,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
private void openSaveAsNewTrackMenu(MapActivity mapActivity) {
|
private void openSaveAsNewTrackMenu(MapActivity mapActivity) {
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
if (editingCtx.getPointsCount() > 0) {
|
if (editingCtx.getPointsCount() > 0) {
|
||||||
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), this);
|
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
|
||||||
|
this, getSuggestedFileName());
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@ -1329,7 +1330,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
});
|
});
|
||||||
showOnMapToggle.setChecked(true);
|
showOnMapToggle.setChecked(true);
|
||||||
|
|
||||||
String displayedName = getSuggestedFileName(dir);
|
String displayedName = getSuggestedFileName();
|
||||||
nameEt.setText(displayedName);
|
nameEt.setText(displayedName);
|
||||||
nameEt.setSelection(displayedName.length());
|
nameEt.setSelection(displayedName.length());
|
||||||
final boolean[] textChanged = new boolean[1];
|
final boolean[] textChanged = new boolean[1];
|
||||||
|
@ -1388,18 +1389,22 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSuggestedFileName(File dir) {
|
private String getSuggestedFileName() {
|
||||||
GpxData gpxData = editingCtx.getGpxData();
|
GpxData gpxData = editingCtx.getGpxData();
|
||||||
String displayedName;
|
String displayedName;
|
||||||
if (gpxData == null) {
|
if (gpxData == null) {
|
||||||
final String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
|
final String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
|
||||||
displayedName = suggestedName;
|
displayedName = suggestedName;
|
||||||
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app != null) {
|
||||||
|
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||||
File fout = new File(dir, suggestedName + GPX_FILE_EXT);
|
File fout = new File(dir, suggestedName + GPX_FILE_EXT);
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
while (fout.exists()) {
|
while (fout.exists()) {
|
||||||
displayedName = suggestedName + "_" + (++ind);
|
displayedName = suggestedName + "_" + (++ind);
|
||||||
fout = new File(dir, displayedName + GPX_FILE_EXT);
|
fout = new File(dir, displayedName + GPX_FILE_EXT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName());
|
displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName());
|
||||||
}
|
}
|
||||||
|
@ -1639,7 +1644,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final GpxData gpxData = editingCtx.getGpxData();
|
final GpxData gpxData = editingCtx.getGpxData();
|
||||||
String fileName = getSuggestedFileName(mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR));
|
String fileName = getSuggestedFileName();
|
||||||
String actionStr = getString(R.string.plan_route);
|
String actionStr = getString(R.string.plan_route);
|
||||||
boolean editMode = isInEditMode();
|
boolean editMode = isInEditMode();
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
@ -33,10 +34,14 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
||||||
|
|
||||||
public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName();
|
public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName();
|
||||||
private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class);
|
||||||
|
public static final String SHOW_ON_MAP_KEY = "show_on_map_key";
|
||||||
|
public static final String SIMPLIFIED_TRACK_KEY = "simplified_track_key";
|
||||||
|
public static final String FOLDER_NAME_KEY = "folder_name_key";
|
||||||
|
|
||||||
boolean showOnMap;
|
boolean showOnMap;
|
||||||
boolean simplifiedTrack;
|
boolean simplifiedTrack;
|
||||||
String fileName;
|
String fileName;
|
||||||
|
String folderName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
@ -44,11 +49,16 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_KEY);
|
||||||
|
simplifiedTrack = savedInstanceState.getBoolean(SIMPLIFIED_TRACK_KEY);
|
||||||
|
folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
|
||||||
|
}
|
||||||
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||||
|
|
||||||
items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx)));
|
items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx)));
|
||||||
|
|
||||||
View editNameView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.markers_track_name_edit_text,
|
View editNameView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.track_name_edit_text,
|
||||||
null, false);
|
null, false);
|
||||||
TextInputLayout nameTextBox = editNameView.findViewById(R.id.name_text_box);
|
TextInputLayout nameTextBox = editNameView.findViewById(R.id.name_text_box);
|
||||||
nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg);
|
nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg);
|
||||||
|
@ -56,9 +66,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
||||||
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
|
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
|
||||||
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
|
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
|
||||||
nameTextBox.setDefaultHintTextColor(colorStateList);
|
nameTextBox.setDefaultHintTextColor(colorStateList);
|
||||||
if (nameTextBox.getEditText() != null) {
|
TextInputEditText nameText = editNameView.findViewById(R.id.name_edit_text);
|
||||||
AndroidUtils.setHintTextSecondaryColor(app, nameTextBox.getEditText(), nightMode);
|
nameText.setText(fileName);
|
||||||
}
|
|
||||||
BaseBottomSheetItem editFileName = new BaseBottomSheetItem.Builder()
|
BaseBottomSheetItem editFileName = new BaseBottomSheetItem.Builder()
|
||||||
.setCustomView(editNameView)
|
.setCustomView(editNameView)
|
||||||
.create();
|
.create();
|
||||||
|
@ -70,7 +79,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
||||||
|
|
||||||
items.add(new DividerSpaceItem(app, contentPaddingSmall));
|
items.add(new DividerSpaceItem(app, contentPaddingSmall));
|
||||||
|
|
||||||
FolderListAdapter adapter = new FolderListAdapter(app, nightMode);
|
FolderListAdapter adapter = new FolderListAdapter(app, nightMode, folderName);
|
||||||
|
adapter.setListener(createFolderSelectListener());
|
||||||
View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_recyclerview,
|
View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_recyclerview,
|
||||||
null, false);
|
null, false);
|
||||||
View recyclerView = view.findViewById(R.id.recycler_view);
|
View recyclerView = view.findViewById(R.id.recycler_view);
|
||||||
|
@ -131,11 +141,29 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
||||||
items.add(new DividerSpaceItem(app, contentPaddingSmall));
|
items.add(new DividerSpaceItem(app, contentPaddingSmall));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) {
|
private FolderListAdapter.FolderListAdapterListener createFolderSelectListener() {
|
||||||
|
return new FolderListAdapter.FolderListAdapterListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(String item) {
|
||||||
|
folderName = item;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putBoolean(SHOW_ON_MAP_KEY, showOnMap);
|
||||||
|
outState.putBoolean(SIMPLIFIED_TRACK_KEY, simplifiedTrack);
|
||||||
|
outState.putString(FOLDER_NAME_KEY, folderName);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, String fileName) {
|
||||||
try {
|
try {
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment();
|
SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment();
|
||||||
fragment.setTargetFragment(targetFragment, 0);
|
fragment.setTargetFragment(targetFragment, 0);
|
||||||
|
fragment.fileName = fileName;
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
Loading…
Reference in a new issue