Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-09-25 22:46:23 +02:00
commit c06b2d1874
21 changed files with 833 additions and 36 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch android:src="@drawable/bg_contextmenu_shadow_dark" />
</item>
<item>
<shape>
<solid
android:color="@color/bg_color_dark" />
</shape>
</item>
</layer-list>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch android:src="@drawable/bg_contextmenu_shadow_light" />
</item>
<item>
<shape>
<solid
android:color="@color/bg_color_light" />
</shape>
</item>
</layer-list>

View file

@ -0,0 +1,234 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/point_edit_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
android:background="@drawable/gradient_toolbar"
android:minHeight="@dimen/dashboard_map_toolbar"
android:theme="?attr/toolbar_theme"
app:contentInsetLeft="72dp"
app:contentInsetStart="72dp">
<ImageButton
android:id="@+id/delete_button"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@android:color/transparent"
android:src="@drawable/ic_action_delete_dark"/>
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@android:color/transparent"
android:text="@string/shared_string_save"/>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:id="@+id/title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_point_editor_view"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp">
<TextView
android:id="@+id/header_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_gravity="center_vertical"
android:text="Point info"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="42dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/name_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:scaleType="center"
android:src="@drawable/ic_action_building_number"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/name_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/favourites_edit_dialog_name"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"/>
<EditText
android:id="@+id/name_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp"
android:textColor="?android:textColorPrimary"
android:textColorHint="?android:textColorSecondary"
android:inputType="text"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="42dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/category_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:scaleType="center"
android:src="@drawable/ic_action_building_number"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/category_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/favourites_edit_dialog_name"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"/>
<net.osmand.plus.widgets.AutoCompleteTextViewEx
android:id="@+id/category_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:background="?attr/ctx_menu_info_view_bg"
android:orientation="horizontal">
<LinearLayout
android:layout_width="42dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/description_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:scaleType="center"
android:src="@drawable/ic_action_note_dark"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:orientation="vertical">
<EditText
android:id="@+id/description_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp"
android:maxLines="8"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:textColorHint="?android:textColorSecondary"
android:inputType="textMultiLine"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>

View file

@ -12,6 +12,7 @@
<attr name="bg_color" format="reference" />
<attr name="bg_card" format="reference" />
<attr name="bg_map_context_menu" format="reference" />
<attr name="bg_point_editor_view" format="reference" />
<attr name="ctx_menu_info_view_bg" format="reference" />
<attr name="dashboard_divider" format="reference" />

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="favourites_edit_dialog_title">Favorite informaton</string>
<string name="simulate_your_location_stop_descr">Stop simulating your position</string>
<string name="simulate_your_location_descr">Simulate using recorded GPX or calculated route</string>
<string name="address_unknown">Address is not known yet</string>
@ -2165,6 +2166,7 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="add_favorite_dialog_top_text">Enter favorite name</string>
<string name="add_favorite_dialog_default_favourite_name">Favorite</string>
<string name="add_favorite_dialog_favourite_added_template">Favorite point \'\'{0}\'\' was added successfully.</string>
<string name="favourites_context_menu_add">Add favorite</string>
<string name="favourites_context_menu_edit">Edit favorite</string>
<string name="favourites_context_menu_delete">Delete favorite</string>
<string name="favourites_remove_dialog_msg">Remove favorite point \'%s\'?</string>

View file

@ -67,6 +67,7 @@
<item name="bg_color">@color/bg_color_light</item>
<item name="bg_card">@drawable/bg_card_light</item>
<item name="bg_map_context_menu">@drawable/bg_map_context_menu_light</item>
<item name="bg_point_editor_view">@drawable/bg_point_editor_view_light</item>
<item name="dashboard_divider">@color/dashboard_divider_light</item>
<item name="divider_color">@color/divider_color</item>
<item name="dashboard_button">@drawable/dashboard_button_light</item>
@ -151,6 +152,7 @@
<item name="bg_color">@color/bg_color_dark</item>
<item name="bg_card">@drawable/bg_card_dark</item>
<item name="bg_map_context_menu">@drawable/bg_map_context_menu_dark</item>
<item name="bg_point_editor_view">@drawable/bg_point_editor_view_dark</item>
<item name="dashboard_divider">@color/dashboard_divider_dark</item>
<item name="divider_color">@color/dashboard_divider_dark</item>
<item name="dashboard_button">@drawable/dashboard_button_dark</item>

View file

@ -26,7 +26,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
}
this.name = name;
}
public int getColor() {
return color;
}

View file

@ -189,7 +189,7 @@ public class FavouritesDbHelper {
while (fl) {
fl = false;
for (FavouritePoint fp : fdb.getFavouritePoints()) {
if (fp.getName().equals(name)) {
if (fp.getName().equals(name) && p.getLatitude() != fp.getLatitude() && p.getLongitude() != fp.getLongitude()) {
number++;
index = " (" + number + ")";
name = p.getName() + index;
@ -423,7 +423,14 @@ public class FavouritesDbHelper {
public List<FavoriteGroup> getFavoriteGroups() {
return favoriteGroups;
}
public FavoriteGroup getGroup(FavouritePoint p) {
if (flatGroups.containsKey(p.getCategory())) {
return flatGroups.get(p.getCategory());
} else {
return null;
}
}
private FavouritePoint findFavoriteByAllProperties(String category, String name, double lat, double lon){
if (flatGroups.containsKey(category)) {

View file

@ -66,6 +66,7 @@ import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.helpers.GpxImportHelper;
import net.osmand.plus.helpers.WakeLockHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routing.RoutingHelper;
@ -126,6 +127,7 @@ public class MapActivity extends AccessibleActivity {
private DashboardOnMap dashboardOnMap = new DashboardOnMap(this);
private MapContextMenu contextMenuOnMap;
private FavoritePointEditor favoritePointEditor;
private AppInitializeListener initListener;
private IMapDownloaderCallback downloaderCallback;
private DrawerLayout drawerLayout;
@ -978,6 +980,13 @@ public class MapActivity extends AccessibleActivity {
return contextMenuOnMap;
}
public FavoritePointEditor getFavoritePointEditor() {
if (favoritePointEditor == null) {
favoritePointEditor = new FavoritePointEditor(app, this);
}
return favoritePointEditor;
}
public void openDrawer() {
drawerLayout.openDrawer(Gravity.LEFT);
}

View file

@ -21,9 +21,9 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.mapcontextmenu.sections.AmenityInfoMenuController;
import net.osmand.plus.mapcontextmenu.sections.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.sections.MenuController;
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.details.MenuController;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.OsmandMapLayer;
@ -290,7 +290,7 @@ public class MapContextMenu {
MenuController menuController = null;
if (object != null) {
if (object instanceof Amenity) {
menuController = new AmenityInfoMenuController(app, activity, (Amenity)object);
menuController = new AmenityMenuController(app, activity, (Amenity)object);
if (!Algorithms.isEmpty(typeStr)) {
menuController.addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
}
@ -310,9 +310,11 @@ public class MapContextMenu {
public void buttonFavoritePressed() {
if (object != null && object instanceof FavouritePoint) {
mapActivity.getMapActions().editFavoritePoint((FavouritePoint)object);
mapActivity.getFavoritePointEditor().edit((FavouritePoint)object);
//mapActivity.getMapActions().editFavoritePoint((FavouritePoint) object);
} else {
mapActivity.getMapActions().addFavouritePoint(pointDescription.getLat(), pointDescription.getLon());
mapActivity.getFavoritePointEditor().add(pointDescription);
//mapActivity.getMapActions().addFavouritePoint(pointDescription.getLat(), pointDescription.getLon());
}
}

View file

@ -33,14 +33,14 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.sections.MenuController;
import net.osmand.plus.mapcontextmenu.details.MenuController;
import net.osmand.plus.views.AnimateDraggingMapThread;
import org.apache.commons.logging.Log;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.sections.MenuBuilder.SHADOW_HEIGHT_BOTTOM_DP;
import static net.osmand.plus.mapcontextmenu.sections.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
import static net.osmand.plus.mapcontextmenu.details.MenuBuilder.SHADOW_HEIGHT_BOTTOM_DP;
import static net.osmand.plus.mapcontextmenu.details.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
public class MapContextMenuFragment extends Fragment {

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapcontextmenu.sections;
package net.osmand.plus.mapcontextmenu.details;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
@ -27,11 +27,11 @@ import java.util.Map;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class AmenityInfoMenuBuilder extends MenuBuilder {
public class AmenityMenuBuilder extends MenuBuilder {
private final Amenity amenity;
public AmenityInfoMenuBuilder(OsmandApplication app, final Amenity amenity) {
public AmenityMenuBuilder(OsmandApplication app, final Amenity amenity) {
super(app);
this.amenity = amenity;
}

View file

@ -1,14 +1,14 @@
package net.osmand.plus.mapcontextmenu.sections;
package net.osmand.plus.mapcontextmenu.details;
import android.app.Activity;
import net.osmand.data.Amenity;
import net.osmand.plus.OsmandApplication;
public class AmenityInfoMenuController extends MenuController {
public class AmenityMenuController extends MenuController {
public AmenityInfoMenuController(OsmandApplication app, Activity activity, final Amenity amenity) {
super(new AmenityInfoMenuBuilder(app, amenity), activity);
public AmenityMenuController(OsmandApplication app, Activity activity, final Amenity amenity) {
super(new AmenityMenuBuilder(app, amenity), activity);
}
@Override

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapcontextmenu.sections;
package net.osmand.plus.mapcontextmenu.details;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
@ -70,23 +70,23 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
textView.setAutoLinkMask(Linkify.ALL);
textView.setLinksClickable(true);
if (isDescription) {
textView.setMinLines(1);
textView.setMaxLines(5);
}
// if (isDescription) {
// textView.setMinLines(1);
// textView.setMaxLines(5);
// }
textView.setText(text);
if (textColor > 0) {
textView.setTextColor(view.getResources().getColor(textColor));
}
if (isDescription) {
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//todo: implement edit fav description dialog
//POIMapLayer.showDescriptionDialog(view.getContext(), app, fav);
}
});
}
// if (isDescription) {
// textView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// //todo: implement edit fav description dialog
// //POIMapLayer.showDescriptionDialog(view.getContext(), app, fav);
// }
// });
// }
LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapcontextmenu.sections;
package net.osmand.plus.mapcontextmenu.details;
import android.app.Activity;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapcontextmenu.sections;
package net.osmand.plus.mapcontextmenu.details;
import android.content.Context;
import android.graphics.Bitmap;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapcontextmenu.sections;
package net.osmand.plus.mapcontextmenu.details;
import android.app.Activity;
import android.view.View;

View file

@ -0,0 +1,58 @@
package net.osmand.plus.mapcontextmenu.editors;
import android.os.Bundle;
import net.osmand.data.FavouritePoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
public class FavoritePointEditor extends PointEditor {
private FavouritePoint favorite;
public static final String FRAGMENT_NAME = "FavoritePointEditorFragment";
public FavoritePointEditor(OsmandApplication app, MapActivity mapActivity) {
super(app, mapActivity);
}
@Override
public void saveState(Bundle bundle) {
}
@Override
public void restoreState(Bundle bundle) {
}
@Override
public String getFragmentName() {
return FRAGMENT_NAME;
}
public FavouritePoint getFavorite() {
return favorite;
}
public void add(PointDescription point) {
if (point == null) {
return;
}
isNew = true;
favorite = new FavouritePoint(point.getLat(), point.getLon(), point.getName(), app.getSettings().LAST_FAV_CATEGORY_ENTERED.get());
favorite.setDescription("");
FavoritePointEditorFragment.showInstance(mapActivity);
}
public void edit(FavouritePoint favorite) {
if (favorite == null) {
return;
}
isNew = false;
this.favorite = favorite;
FavoritePointEditorFragment.showInstance(mapActivity);
}
}

View file

@ -0,0 +1,183 @@
package net.osmand.plus.mapcontextmenu.editors;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import java.text.MessageFormat;
public class FavoritePointEditorFragment extends PointEditorFragment {
private FavoritePointEditor editor;
private FavouritePoint favorite;
FavouritesDbHelper helper;
private boolean saved;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
helper = getMyApplication().getFavorites();
editor = getMapActivity().getFavoritePointEditor();
favorite = editor.getFavorite();
}
@Override
public PointEditor getEditor() {
return editor;
}
@Override
public String getToolbarTitle() {
if (editor.isNew()) {
return getMapActivity().getResources().getString(R.string.favourites_context_menu_add);
} else {
return getMapActivity().getResources().getString(R.string.favourites_context_menu_edit);
}
}
public static void showInstance(final MapActivity mapActivity) {
FavoritePointEditor editor = mapActivity.getFavoritePointEditor();
//int slideInAnim = editor.getSlideInAnimation();
//int slideOutAnim = editor.getSlideOutAnimation();
FavoritePointEditorFragment fragment = new FavoritePointEditorFragment();
mapActivity.getSupportFragmentManager().beginTransaction()
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
.add(R.id.fragmentContainer, fragment, editor.getFragmentName())
.addToBackStack(null).commit();
}
@Override
protected boolean wasSaved() {
return saved;
}
@Override
protected void save(final boolean needDismiss) {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), getName(), getCategory());
point.setDescription(getDescription());
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
if (favorite.getName().equals(point.getName()) &&
favorite.getCategory().equals(point.getCategory()) &&
favorite.getDescription().equals(point.getDescription())) {
if (needDismiss) {
dismiss(true);
}
return;
}
if (builder != null) {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (editor.isNew()) {
doAddFavorite(point.getName(), point.getCategory(), point.getDescription());
} else {
helper.editFavouriteName(favorite, point.getName(), point.getCategory(), point.getDescription());
}
getMapActivity().getMapView().refreshMap(true);
if (needDismiss) {
dismiss(true);
}
}
});
builder.create().show();
} else {
if (editor.isNew()) {
doAddFavorite(point.getName(), point.getCategory(), point.getDescription());
} else {
helper.editFavouriteName(favorite, point.getName(), point.getCategory(), point.getDescription());
}
getMapActivity().getMapView().refreshMap(true);
if (needDismiss) {
dismiss(true);
}
}
saved = true;
}
private void doAddFavorite(String name, String category, String description) {
favorite.setName(name);
favorite.setCategory(category);
favorite.setDescription(description);
helper.addFavourite(favorite);
}
@Override
protected void delete(final boolean needDismiss) {
final Resources resources = this.getResources();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.favourites_remove_dialog_msg, favorite.getName()));
builder.setNegativeButton(R.string.shared_string_no, null);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
helper.deleteFavourite(favorite);
if (needDismiss) {
dismiss(true);
}
getMapActivity().getMapView().refreshMap(true);
}
});
builder.create().show();
}
@Override
public String getHeaderText() {
return getMapActivity().getResources().getString(R.string.favourites_edit_dialog_title);
}
@Override
public String getNameValue() {
return favorite.getName();
}
@Override
public String getCategoryValue() {
return favorite.getCategory();
}
@Override
public String getDescriptionValue() {
return favorite.getDescription();
}
@Override
public Drawable getNameIcon() {
return FavoriteImageDrawable.getOrCreate(getMapActivity(), favorite.getColor(), getMapActivity().getMapView().getCurrentRotatedTileBox().getDensity());
}
@Override
public Drawable getCategoryIcon() {
FavouritesDbHelper helper = getMyApplication().getFavorites();
FavouritesDbHelper.FavoriteGroup group = helper.getGroup(favorite);
if (group != null) {
return getIcon(R.drawable.ic_action_folder_stroke, group.color);
} else {
return null;
}
}
public Drawable getIcon(int resId, int color) {
OsmandApplication app = getMyApplication();
Drawable d = app.getResources().getDrawable(resId).mutate();
d.clearColorFilter();
d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
return d;
}
}

View file

@ -0,0 +1,63 @@
package net.osmand.plus.mapcontextmenu.editors;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
public abstract class PointEditor {
protected OsmandApplication app;
protected final MapActivity mapActivity;
protected Object object;
protected boolean isNew;
private boolean portraitMode;
private boolean largeDevice;
public PointEditor(OsmandApplication app, MapActivity mapActivity) {
this.app = app;
this.mapActivity = mapActivity;
portraitMode = AndroidUiHelper.isOrientationPortrait(mapActivity);
largeDevice = AndroidUiHelper.isXLargeDevice(mapActivity);
}
public boolean isNew() {
return isNew;
}
public boolean isLandscapeLayout() {
return !portraitMode && !largeDevice;
}
public int getSlideInAnimation() {
if (isLandscapeLayout()) {
return R.anim.slide_in_left;
} else {
return R.anim.slide_in_bottom;
}
}
public int getSlideOutAnimation() {
if (isLandscapeLayout()) {
return R.anim.slide_out_left;
} else {
return R.anim.slide_out_bottom;
}
}
public abstract void saveState(Bundle bundle);
public abstract void restoreState(Bundle bundle);
public abstract String getFragmentName();
public void hide() {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(getFragmentName());
if (fragment != null)
((PointEditorFragment)fragment).dismiss();
}
}

View file

@ -0,0 +1,212 @@
package net.osmand.plus.mapcontextmenu.editors;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
import java.util.List;
public abstract class PointEditorFragment extends Fragment {
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
getEditor().saveState(outState);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (savedInstanceState != null)
getEditor().restoreState(savedInstanceState);
View view = inflater.inflate(R.layout.point_editor_fragment, container, false);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getToolbarTitle());
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
toolbar.setTitleTextColor(getResources().getColor(getResIdFromAttribute(getMapActivity(), R.attr.pstsTextColor)));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
Button saveButton = (Button)toolbar.findViewById(R.id.save_button);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
savePressed();
}
});
ImageButton deleteButton = (ImageButton)toolbar.findViewById(R.id.delete_button);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deletePressed();
}
});
if (getEditor().isNew()) {
deleteButton.setVisibility(View.GONE);
} else {
saveButton.setVisibility(View.GONE);
}
TextView headerCaption = (TextView) view.findViewById(R.id.header_caption);
headerCaption.setText(getHeaderText());
TextView nameCaption = (TextView) view.findViewById(R.id.name_caption);
nameCaption.setText(getNameText());
TextView categoryCaption = (TextView) view.findViewById(R.id.category_caption);
categoryCaption.setText(getCategoryText());
EditText nameEdit = (EditText) view.findViewById(R.id.name_edit);
nameEdit.setText(getNameValue());
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) view.findViewById(R.id.category_edit);
categoryEdit.setText(getCategoryValue());
categoryEdit.setThreshold(1);
final FavouritesDbHelper helper = getMyApplication().getFavorites();
List<FavouritesDbHelper.FavoriteGroup> gs = helper.getFavoriteGroups();
String[] list = new String[gs.size()];
for(int i = 0; i < list.length; i++) {
list[i] =gs.get(i).name;
}
categoryEdit.setAdapter(new ArrayAdapter<>(getMapActivity(), R.layout.list_textview, list));
EditText descriptionEdit = (EditText) view.findViewById(R.id.description_edit);
descriptionEdit.setText(getDescriptionValue());
ImageView nameImage = (ImageView) view.findViewById(R.id.name_image);
nameImage.setImageDrawable(getNameIcon());
ImageView categoryImage = (ImageView) view.findViewById(R.id.category_image);
categoryImage.setImageDrawable(getCategoryIcon());
ImageView descriptionImage = (ImageView) view.findViewById(R.id.description_image);
descriptionImage.setImageDrawable(getRowIcon(R.drawable.ic_action_note_dark));
return view;
}
public Drawable getRowIcon(int iconId) {
IconsCache iconsCache = getMyApplication().getIconsCache();
boolean light = getMyApplication().getSettings().isLightContent();
return iconsCache.getIcon(iconId,
light ? R.color.icon_color : R.color.icon_color_light);
}
@Override
public void onDestroyView() {
if (!wasSaved() && !getEditor().isNew()) {
save(false);
}
super.onDestroyView();
}
protected void savePressed() {
save(true);
}
protected void deletePressed() {
delete(true);
}
protected abstract boolean wasSaved();
protected abstract void save(boolean needDismiss);
protected abstract void delete(boolean needDismiss);
static int getResIdFromAttribute(final Context ctx, final int attr) {
if (attr == 0)
return 0;
final TypedValue typedvalueattr = new TypedValue();
ctx.getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
}
public abstract PointEditor getEditor();
public abstract String getToolbarTitle();
protected MapActivity getMapActivity() {
return (MapActivity)getActivity();
}
protected OsmandApplication getMyApplication() {
if (getActivity() == null) {
return null;
}
return (OsmandApplication) getActivity().getApplication();
}
public void dismiss() {
dismiss(false);
}
public void dismiss(boolean includingMenu) {
if (includingMenu) {
//getMapActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
getMapActivity().getSupportFragmentManager().popBackStack();
getMapActivity().getMapLayers().getContextMenuLayer().hideMapContextMenuMarker();
getMapActivity().getContextMenu().hide();
} else {
getMapActivity().getSupportFragmentManager().popBackStack();
}
}
public abstract String getHeaderText();
public String getNameText() {
return getMapActivity().getResources().getString(R.string.favourites_edit_dialog_name);
}
public String getCategoryText() {
return getMapActivity().getResources().getString(R.string.favourites_edit_dialog_category);
}
public abstract String getNameValue();
public abstract String getCategoryValue();
public abstract String getDescriptionValue();
public abstract Drawable getNameIcon();
public abstract Drawable getCategoryIcon();
public String getName() {
EditText nameEdit = (EditText) getView().findViewById(R.id.name_edit);
return nameEdit.getText().toString().trim();
}
public String getCategory() {
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) getView().findViewById(R.id.category_edit);
return categoryEdit.getText().toString().trim();
}
public String getDescription() {
EditText descriptionEdit = (EditText) getView().findViewById(R.id.description_edit);
return descriptionEdit.getText().toString().trim();
}
}