Merge pull request #9619 from osmandapp/9055_allow_to_edit_address

9055 allow to edit address
This commit is contained in:
Vitaliy 2020-08-20 17:35:58 +03:00 committed by GitHub
commit fcf8f94daa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 372 additions and 98 deletions

View file

@ -11,16 +11,18 @@ public class AFavorite extends AidlParams {
private double lon;
private String name;
private String description;
private String address;
private String category;
private String color;
private boolean visible;
public AFavorite(double lat, double lon, String name, String description,
public AFavorite(double lat, double lon, String name, String description, String address,
String category, String color, boolean visible) {
this.lat = lat;
this.lon = lon;
this.name = name;
this.description = description;
this.address = address;
this.category = category;
this.color = color;
this.visible = visible;
@ -58,6 +60,8 @@ public class AFavorite extends AidlParams {
return description;
}
public String getAddress() { return address; }
public String getCategory() {
return category;
}
@ -76,6 +80,7 @@ public class AFavorite extends AidlParams {
bundle.putDouble("lon", lon);
bundle.putString("name", name);
bundle.putString("description", description);
bundle.putString("address", address);
bundle.putString("category", category);
bundle.putString("color", color);
bundle.putBoolean("visible", visible);
@ -87,6 +92,7 @@ public class AFavorite extends AidlParams {
lon = bundle.getDouble("lon");
name = bundle.getString("name");
description = bundle.getString("description");
address = bundle.getString("address");
category = bundle.getString("category");
color = bundle.getString("color");
visible = bundle.getBoolean("visible");

View file

@ -21,8 +21,8 @@
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?attr/card_and_list_background_basic"
osmand:subtitleTextColor="?android:textColorPrimary"
app:contentInsetStartWithNavigation="@dimen/toolbar_inset_start_with_navigation"
osmand:subtitleTextColor="?android:textColorPrimary"
osmand:theme="@style/ThemeOverlay.AppCompat.ActionBar"
osmand:titleTextColor="?android:textColorPrimary">
@ -69,8 +69,8 @@
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:id="@+id/name_caption"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -89,8 +89,8 @@
android:minHeight="@dimen/favorites_list_item_height"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:scrollHorizontally="false"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/lorem_ipsum" />
@ -103,14 +103,69 @@
android:id="@+id/name_icon"
android:layout_width="@dimen/favorites_icon_size"
android:layout_height="@dimen/favorites_icon_size"
android:padding="@dimen/favorites_icon_padding"
android:layout_gravity="end"
android:layout_margin="@dimen/content_padding_small"
android:contentDescription="@string/icon"
android:padding="@dimen/favorites_icon_padding"
app:srcCompat="@drawable/ic_action_home_dark" />
</FrameLayout>
<LinearLayout
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_small"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/address_caption"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:hint="@string/shared_string_address"
app:boxBackgroundColor="@color/material_text_input_layout_bg"
app:hintAnimationEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/address_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:minHeight="@dimen/favorites_list_item_height"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/lorem_ipsum" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/address_button"
android:layout_width="wrap_content"
android:layout_height="@dimen/context_menu_buttons_bottom_height"
android:layout_marginStart="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginTop="@dimen/content_padding_small"
android:drawablePadding="8dp"
android:duplicateParentState="true"
android:gravity="center"
android:paddingStart="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half"
android:text="@string/add_address"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/add_address" />
<LinearLayout
android:id="@+id/description"
android:layout_width="match_parent"
@ -120,15 +175,16 @@
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:id="@+id/description_caption"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:hint="@string/shared_string_description"
app:boxBackgroundColor="@color/material_text_input_layout_bg">
app:boxBackgroundColor="@color/material_text_input_layout_bg"
app:hintAnimationEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/description_edit"
@ -139,8 +195,8 @@
android:minHeight="@dimen/favorites_list_item_height"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/lorem_ipsum" />
@ -153,16 +209,17 @@
android:layout_height="@dimen/context_menu_buttons_bottom_height"
android:layout_marginStart="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half"
android:drawablePadding="8dp"
android:duplicateParentState="true"
android:gravity="center"
android:paddingStart="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half"
android:text="@string/add_description"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
android:duplicateParentState="true"
android:text="@string/add_description"
tools:text="@string/add_description"
android:paddingStart="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding_half"/>
tools:text="@string/add_description" />
<View
android:layout_width="match_parent"
@ -174,8 +231,8 @@
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/toolbar_height"
android:paddingBottom="@dimen/content_padding_half"
android:orientation="vertical">
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_half">
<LinearLayout
android:layout_width="match_parent"
@ -227,8 +284,8 @@
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
app:srcCompat="@drawable/ic_action_folder"
android:contentDescription="@string/shared_string_list" />
android:contentDescription="@string/shared_string_list"
app:srcCompat="@drawable/ic_action_folder" />
</LinearLayout>
</LinearLayout>
@ -242,18 +299,18 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/group_recycler_view"
android:paddingLeft="@dimen/content_padding_half"
android:paddingStart="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingStart="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
tools:itemCount="3"
tools:orientation="horizontal"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/point_editor_group_select_item" />
tools:listitem="@layout/point_editor_group_select_item"
tools:orientation="horizontal" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
@ -262,13 +319,13 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
android:letterSpacing="@dimen/description_letter_spacing"
android:textColor="?android:textColorSecondary"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
android:text="@string/add_hidden_group_info"
android:visibility="gone" />
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
android:visibility="gone"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<View
@ -293,16 +350,16 @@
android:id="@+id/group_name_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
tools:itemCount="3"
tools:orientation="horizontal"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/point_editor_icon_category_item" />
tools:listitem="@layout/point_editor_icon_category_item"
tools:orientation="horizontal" />
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_icon"
@ -361,6 +418,7 @@
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginBottom="@dimen/content_padding_half" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
@ -405,11 +463,11 @@
android:id="@+id/select_shape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginBottom="@dimen/content_padding_half" />
android:layout_marginBottom="@dimen/content_padding_half"
android:gravity="start" />
<View
android:layout_width="match_parent"
@ -479,11 +537,11 @@
android:id="@+id/delete_action_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_gravity="center_vertical"
android:contentDescription="@string/delete_point"
app:srcCompat="@drawable/ic_action_delete_dark" />

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="access_hint_enter_address">Enter address</string>
<string name="add_address">Add address</string>
<string name="delete_address">Delete address</string>
<string name="attach_to_the_roads">Attach to the roads</string>
<string name="nearest_point">Nearest point</string>
<string name="start_of_the_track">Start of the track</string>

View file

@ -967,7 +967,7 @@ public class OsmandAidlApi {
return false;
}
boolean updateFavorite(String prevName, String prevCategory, double prevLat, double prevLon, String newName, String newCategory, String newDescription, double newLat, double newLon) {
boolean updateFavorite(String prevName, String prevCategory, double prevLat, double prevLon, String newName, String newCategory, String newDescription, String newAddress, double newLat, double newLon) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritePoint> favorites = favoritesHelper.getFavouritePoints();
for (FavouritePoint f : favorites) {
@ -977,8 +977,8 @@ public class OsmandAidlApi {
favoritesHelper.editFavourite(f, newLat, newLon);
}
if (!newName.equals(f.getName()) || !newDescription.equals(f.getDescription()) ||
!newCategory.equals(f.getCategory())) {
favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription);
!newCategory.equals(f.getCategory()) || !newAddress.equals(f.getAddress())) {
favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription,newAddress);
}
refreshMap();
return true;

View file

@ -311,7 +311,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
AFavorite newFav = params.getFavoriteNew();
if (prevFav != null && newFav != null) {
return api.updateFavorite(prevFav.getName(), prevFav.getCategory(), prevFav.getLat(), prevFav.getLon(),
newFav.getName(), newFav.getCategory(), newFav.getDescription(), newFav.getLat(), newFav.getLon());
newFav.getName(), newFav.getCategory(), newFav.getDescription(), newFav.getAddress(), newFav.getLat(), newFav.getLon());
}
}
return false;

View file

@ -314,7 +314,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
AFavorite newFav = params.getFavoriteNew();
if (prevFav != null && newFav != null) {
return api.updateFavorite(prevFav.getName(), prevFav.getCategory(), prevFav.getLat(), prevFav.getLon(),
newFav.getName(), newFav.getCategory(), newFav.getDescription(), newFav.getLat(), newFav.getLon());
newFav.getName(), newFav.getCategory(), newFav.getDescription(), newFav.getAddress(), newFav.getLat(), newFav.getLon());
}
}
return false;

View file

@ -9,16 +9,18 @@ public class AFavorite implements Parcelable {
private double lon;
private String name;
private String description;
private String address;
private String category;
private String color;
private boolean visible;
public AFavorite(double lat, double lon, String name, String description,
public AFavorite(double lat, double lon, String name, String description, String address,
String category, String color, boolean visible) {
this.lat = lat;
this.lon = lon;
this.name = name;
this.description = description;
this.address = address;
this.category = category;
this.color = color;
this.visible = visible;
@ -56,6 +58,8 @@ public class AFavorite implements Parcelable {
return description;
}
public String getAddress() { return address; }
public String getCategory() {
return category;
}
@ -77,6 +81,7 @@ public class AFavorite implements Parcelable {
out.writeString(category);
out.writeString(color);
out.writeByte((byte) (visible ? 1 : 0));
out.writeString(address);
}
private void readFromParcel(Parcel in) {
@ -87,6 +92,7 @@ public class AFavorite implements Parcelable {
category = in.readString();
color = in.readString();
visible = in.readByte() != 0;
address = in.readString();
}
@Override

View file

@ -2,6 +2,7 @@ package net.osmand.plus;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -102,7 +103,7 @@ public class FavouritesDbHelper {
}
public int getColor() {
return color;
return color;
}
public boolean isVisible() {
@ -128,6 +129,17 @@ public class FavouritesDbHelper {
}
}
public Drawable getColoredIconForGroup(String groupName) {
String groupIdName = FavoriteGroup.convertDisplayNameToGroupIdName(context, groupName);
FavoriteGroup favoriteGroup = getGroup(groupIdName);
if (favoriteGroup != null) {
int color = favoriteGroup.getColor() == 0 ?
context.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor();
return context.getUIUtilities().getPaintedIcon(R.drawable.ic_action_group_name_16, color);
}
return null;
}
public int getColorWithCategory(FavouritePoint point, int defaultColor) {
int color = 0;
if (point.getColor() != 0) {
@ -183,10 +195,10 @@ public class FavouritesDbHelper {
if (fp.getColor() == 0xFF000000 || fp.getColor() == ContextCompat.getColor(context, R.color.color_favorite)) {
fp.setColor(0);
}
if (fp.getBackgroundType() == FavouritePoint.DEFAULT_BACKGROUND_TYPE){
if (fp.getBackgroundType() == FavouritePoint.DEFAULT_BACKGROUND_TYPE) {
fp.setBackgroundType(null);
}
if(fp.getIconId()== FavouritePoint.DEFAULT_UI_ICON_ID){
if (fp.getIconId() == FavouritePoint.DEFAULT_UI_ICON_ID) {
fp.setIconId(0);
}
FavoriteGroup group = getOrCreateGroup(fp, 0);
@ -472,11 +484,12 @@ public class FavouritesDbHelper {
return builder.toString();
}
public boolean editFavouriteName(FavouritePoint p, String newName, String category, String descr) {
public boolean editFavouriteName(FavouritePoint p, String newName, String category, String descr, String address) {
String oldCategory = p.getCategory();
p.setName(newName);
p.setCategory(category);
p.setDescription(descr);
p.setAddress(address);
if (!oldCategory.equals(category)) {
FavoriteGroup old = flatGroups.get(oldCategory);
if (old != null) {
@ -884,7 +897,7 @@ public class FavouritesDbHelper {
private static final String FAVOURITE_COL_LAT = "latitude"; //$NON-NLS-1$
private static final String FAVOURITE_COL_LON = "longitude"; //$NON-NLS-1$
private static final String FAVOURITE_TABLE_CREATE = "CREATE TABLE " + FAVOURITE_TABLE_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$
FAVOURITE_COL_NAME + " TEXT, " + FAVOURITE_COL_CATEGORY + " TEXT, " + //$NON-NLS-1$ //$NON-NLS-2$
FAVOURITE_COL_NAME + " TEXT, " + FAVOURITE_COL_CATEGORY + " TEXT, " + //$NON-NLS-1$ //$NON-NLS-2$
FAVOURITE_COL_LAT + " double, " + FAVOURITE_COL_LON + " double);"; //$NON-NLS-1$ //$NON-NLS-2$
private SQLiteConnection conn;
@ -925,7 +938,7 @@ public class FavouritesDbHelper {
try {
SQLiteCursor query = db
.rawQuery(
"SELECT " + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + "," + FAVOURITE_COL_LON + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"SELECT " + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + "," + FAVOURITE_COL_LON + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
FAVOURITE_TABLE_NAME, null);
cachedFavoritePoints.clear();
if (query != null && query.moveToFirst()) {

View file

@ -1042,7 +1042,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
}
FavoritePointEditor favoritePointEditor = getFavoritePointEditor();
if (favoritePointEditor != null) {
favoritePointEditor.add(getLatLon(), title, originObjectName);
favoritePointEditor.add(getLatLon(), title, getStreetStr(), originObjectName);
}
}
});

View file

@ -57,7 +57,6 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType;
@ -67,19 +66,20 @@ import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.TransportStopsLayer;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.plus.views.layers.TransportStopsLayer;
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.router.TransportRouteResult;
import net.osmand.util.Algorithms;
@ -166,14 +166,14 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private int screenOrientation;
private boolean created;
private boolean transportBadgesCreated;
private UpdateLocationViewCache updateLocationViewCache;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
@ -605,7 +605,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
containerLayoutListener = new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View view, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (!transportBadgesCreated) {
createTransportBadges();
}
@ -674,11 +674,11 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
private View getActionView(ContextMenuItem contextMenuItem,
final int position,
final ContextMenuAdapter mainAdapter,
final ContextMenuAdapter additionalAdapter,
final ContextMenuItemClickListener mainListener,
final ContextMenuItemClickListener additionalListener) {
final int position,
final ContextMenuAdapter mainAdapter,
final ContextMenuAdapter additionalAdapter,
final ContextMenuItemClickListener mainListener,
final ContextMenuItemClickListener additionalListener) {
UiUtilities uiUtilities = requireMyApplication().getUIUtilities();
LayoutInflater inflater = UiUtilities.getInflater(getMyApplication(), nightMode);
View view = inflater.inflate(R.layout.context_menu_action_item, null);
@ -780,7 +780,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
return false;
}
private float getToolbarAlpha(int y) {
float a = 0;
if (menu != null && !menu.isLandscapeLayout()) {
@ -827,7 +827,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
v.setAlpha(alpha);
if (visible && v.getVisibility() != View.VISIBLE) {
v.setVisibility(View.VISIBLE);
} else if (!visible && v.getVisibility() == View.VISIBLE) {
} else if (!visible && v.getVisibility() == View.VISIBLE) {
v.setVisibility(View.INVISIBLE);
}
}
@ -835,7 +835,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private void updateVisibility(View v, boolean visible) {
if (visible && v.getVisibility() != View.VISIBLE) {
v.setVisibility(View.VISIBLE);
} else if (!visible && v.getVisibility() == View.VISIBLE) {
} else if (!visible && v.getVisibility() == View.VISIBLE) {
v.setVisibility(View.INVISIBLE);
}
}
@ -1021,7 +1021,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust,
final int previousMenuState, final int newMenuState, int dZoom) {
final int previousMenuState, final int newMenuState, int dZoom) {
final int posY = getPosY(currentY, needCloseMenu, previousMenuState);
if (getViewY() != posY || dZoom != 0) {
if (posY < getViewY()) {
@ -1146,7 +1146,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
Typeface typeface = FontCache.getRobotoRegular(context);
title.setSpan(new CustomTypefaceSpan(typeface), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
title.setSpan(new ForegroundColorSpan(
ContextCompat.getColor(context, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)),
ContextCompat.getColor(context, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)),
startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
setupButton(leftTitleButtonView, leftTitleButtonController.enabled, title);
@ -1620,7 +1620,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
return dpToPx(32);
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void runLayoutListener() {
if (view != null) {
@ -1709,7 +1709,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
- (newMenuTopShadowAllHeight - menuTopShadowAllHeight));
} else {
menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight
- titleButtonHeight - downloadButtonsHeight - titleBottomButtonHeight - additionalButtonsHeight - titleProgressHeight-line3Height;
- titleButtonHeight - downloadButtonsHeight - titleBottomButtonHeight - additionalButtonsHeight - titleProgressHeight - line3Height;
menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight())
+ (line2MeasuredHeight - line2LineCount * line2LineHeight);
menuButtonsHeight = view.findViewById(R.id.context_menu_bottom_buttons).getHeight()
@ -1800,13 +1800,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private void setAddressLocation() {
if (view != null) {
// Text line 1
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
TextView line1 = view.findViewById(R.id.context_menu_line1);
line1.setText(menu.getTitleStr());
toolbarTextView.setText(menu.getTitleStr());
// Text line 2
LinearLayout line2layout = (LinearLayout) view.findViewById(R.id.context_menu_line2_layout);
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
LinearLayout line2layout = view.findViewById(R.id.context_menu_line2_layout);
TextView line2 = view.findViewById(R.id.context_menu_line2);
if (menu.hasCustomAddressLine()) {
line2layout.removeAllViews();
menu.buildCustomAddressLine(line2layout);
@ -1823,7 +1822,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) {
if (line2Str.length() > 0) {
line2Str.append(": ");
line2Str.append(", ");
}
line2Str.append(streetStr);
}
@ -2200,7 +2199,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
public static boolean showInstance(final MapContextMenu menu, final MapActivity mapActivity,
final boolean centered) {
final boolean centered) {
try {
if (menu.getLatLon() == null || mapActivity == null || mapActivity.isActivityDestroyed()) {

View file

@ -11,8 +11,10 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.PointImageDrawable;
@ -23,6 +25,7 @@ import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragmentNew;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.util.OpeningHoursParser;
import net.osmand.view.GravityDrawable;
import java.util.List;
@ -150,9 +153,30 @@ public class FavouritePointMenuController extends MenuController {
}
}
@NonNull
@Override
public String getSubtypeStr() {
return fav.getAddress();
}
@Override
public Drawable getSecondLineTypeIcon() {
return getIcon(R.drawable.ic_action_group_name_16, isLight() ? R.color.icon_color_default_light : R.color.ctx_menu_bottom_view_icon_dark);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
FavouritesDbHelper helper = app.getFavorites();
String group = fav.getCategory();
if (helper.getGroup(group) != null) {
Drawable line2icon = helper.getColoredIconForGroup(group);
GravityDrawable gravityIcon = new GravityDrawable(line2icon);
gravityIcon.setBoundsFrom(line2icon);
return gravityIcon;
} else {
int colorId = isLight() ? R.color.icon_color_default_light : R.color.ctx_menu_bottom_view_icon_dark;
return getIcon(R.drawable.ic_action_group_name_16, colorId);
}
}
return null;
}
@Override
@ -193,6 +217,6 @@ public class FavouritePointMenuController extends MenuController {
if (originObject instanceof Amenity) {
AmenityMenuController.addTypeMenuItem((Amenity) originObject, builder);
}
}
}
}
}

View file

@ -27,7 +27,7 @@ public class FavoritePointEditor extends PointEditor {
return favorite;
}
public void add(LatLon latLon, String title, String originObjectName) {
public void add(LatLon latLon, String title, String address, String originObjectName) {
MapActivity mapActivity = getMapActivity();
if (latLon == null || mapActivity == null) {
return;
@ -39,6 +39,7 @@ public class FavoritePointEditor extends PointEditor {
}
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory);
favorite.setDescription("");
favorite.setAddress(address.isEmpty() ? title : address);
favorite.setOriginObjectName(originObjectName);
FavoritePointEditorFragmentNew.showInstance(mapActivity);
}
@ -61,6 +62,7 @@ public class FavoritePointEditor extends PointEditor {
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName);
favorite.setDescription("");
favorite.setAddress("");
favorite.setOriginObjectName(originObjectName);
FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill);

View file

@ -192,12 +192,13 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue());
point.setAddress(getAddressTextValue());
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
if (favorite.getName().equals(point.getName()) &&
favorite.getCategory().equals(point.getCategory()) &&
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription())) {
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription()) &&
Algorithms.stringsEqual(favorite.getAddress(),point.getAddress())) {
if (needDismiss) {
dismiss(false);
}
@ -208,25 +209,25 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),point.getAddress(), needDismiss);
}
});
builder.create().show();
} else {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), point.getAddress(), needDismiss);
}
saved = true;
}
}
private void doSave(FavouritePoint favorite, String name, String category, String description, boolean needDismiss) {
private void doSave(FavouritePoint favorite, String name, String category, String description, String address, boolean needDismiss) {
FavouritesDbHelper helper = getHelper();
FavoritePointEditor editor = getFavoritePointEditor();
if (editor != null && helper != null) {
if (editor.isNew()) {
doAddFavorite(name, category, description);
doAddFavorite(name, category, description,address);
} else {
helper.editFavouriteName(favorite, name, category, description);
helper.editFavouriteName(favorite, name, category, description,address);
}
}
MapActivity mapActivity = getMapActivity();
@ -245,7 +246,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
}
}
private void doAddFavorite(String name, String category, String description) {
private void doAddFavorite(String name, String category, String description, String address) {
OsmandApplication app = getMyApplication();
FavouritesDbHelper helper = getHelper();
FavouritePoint favorite = getFavorite();
@ -253,6 +254,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
favorite.setName(name);
favorite.setCategory(category);
favorite.setDescription(description);
favorite.setAddress(address);
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
helper.addFavourite(favorite);
}

View file

@ -244,6 +244,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue());
point.setAddress(getAddressTextValue());
point.setColor(color);
point.setBackgroundType(backgroundType);
point.setIconId(iconId);
@ -259,6 +260,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue());
point.setAddress(getAddressTextValue());
point.setColor(color);
point.setBackgroundType(backgroundType);
point.setIconId(iconId);
@ -276,13 +278,13 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), point.getAddress(),
point.getColor(), point.getBackgroundType(), point.getIconId(), needDismiss);
}
});
builder.create().show();
} else {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), point.getAddress(),
point.getColor(), point.getBackgroundType(), point.getIconId(), needDismiss);
}
saved = true;
@ -295,10 +297,11 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
favorite.getName().equals(point.getName()) &&
favorite.getCategory().equals(point.getCategory()) &&
favorite.getBackgroundType().equals(point.getBackgroundType()) &&
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription());
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription()) &&
Algorithms.stringsEqual(favorite.getAddress(), point.getAddress());
}
private void doSave(FavouritePoint favorite, String name, String category, String description,
private void doSave(FavouritePoint favorite, String name, String category, String description, String address,
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) {
FavouritesDbHelper helper = getHelper();
FavoritePointEditor editor = getFavoritePointEditor();
@ -306,7 +309,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
if (editor.isNew()) {
doAddFavorite(name, category, description, color, backgroundType, iconId);
} else {
doEditFavorite(favorite, name, category, description, color, backgroundType, iconId, helper);
doEditFavorite(favorite, name, category, description, address, color, backgroundType, iconId, helper);
}
}
MapActivity mapActivity = getMapActivity();
@ -325,7 +328,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
}
}
private void doEditFavorite(FavouritePoint favorite, String name, String category, String description,
private void doEditFavorite(FavouritePoint favorite, String name, String category, String description, String address,
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId,
FavouritesDbHelper helper) {
OsmandApplication app = getMyApplication();
@ -334,7 +337,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
favorite.setColor(color);
favorite.setBackgroundType(backgroundType);
favorite.setIconId(iconId);
helper.editFavouriteName(favorite, name, category, description);
helper.editFavouriteName(favorite, name, category, description, address);
}
}
@ -405,6 +408,12 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
return favorite != null ? favorite.getDescription() : "";
}
@Override
public String getAddressInitValue() {
FavouritePoint favourite = getFavorite();
return favourite != null ? favourite.getAddress() : "";
}
@Override
public Drawable getNameIcon() {
FavouritePoint favorite = getFavorite();

View file

@ -373,6 +373,12 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
return Algorithms.isEmpty(res) ? null : res;
}
public String getAddressTextValue() {
EditText addressEdit = (EditText) view.findViewById(R.id.address_edit);
String res = addressEdit.getText().toString().trim();
return Algorithms.isEmpty(res) ? null : res;
}
protected Drawable getPaintedIcon(int iconId, int color) {
return getPaintedContentIcon(iconId, color);
}

View file

@ -75,6 +75,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
private View view;
private EditText nameEdit;
private TextView addDelDescription;
private TextView addAddressBtn;
private TextView addToHiddenGroupInfo;
private boolean cancelled;
private boolean nightMode;
@ -91,7 +92,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
private LinkedHashMap<String, JSONArray> iconCategories;
private OsmandApplication app;
private View descriptionCaption;
private View addressCaption;
private EditText descriptionEdit;
private EditText addressEdit;
private int layoutHeightPrevious = 0;
@SuppressLint("ClickableViewAccessibility")
@ -142,11 +145,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
hideKeyboard();
descriptionEdit.clearFocus();
nameEdit.clearFocus();
addressEdit.clearFocus();
}
}
});
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
final int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action);
view.findViewById(R.id.background_layout).setBackgroundResource(nightMode
? R.color.app_bar_color_dark : R.color.list_background_color_light);
@ -218,38 +222,73 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
descriptionEdit = (EditText) view.findViewById(R.id.description_edit);
addressEdit = (EditText) view.findViewById(R.id.address_edit);
AndroidUtils.setTextPrimaryColor(view.getContext(), descriptionEdit, nightMode);
AndroidUtils.setTextPrimaryColor(view.getContext(), addressEdit, nightMode);
AndroidUtils.setHintTextSecondaryColor(view.getContext(), descriptionEdit, nightMode);
AndroidUtils.setHintTextSecondaryColor(view.getContext(), addressEdit, nightMode);
if (getDescriptionInitValue() != null) {
descriptionEdit.setText(getDescriptionInitValue());
}
if (getAddressInitValue() != null){
addressEdit.setText(getAddressInitValue());
}
descriptionCaption = view.findViewById(R.id.description);
addressCaption = view.findViewById(R.id.address);
addDelDescription = (TextView) view.findViewById(R.id.description_button);
addAddressBtn = view.findViewById(R.id.address_button);
addDelDescription.setTextColor(getResources().getColor(activeColorResId));
addAddressBtn.setTextColor(getResources().getColor(activeColorResId));
addAddressBtn.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_location_16, activeColorResId),null,null,null);
addDelDescription.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_description_16, activeColorResId),null,null,null);
addDelDescription.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (descriptionCaption.getVisibility() != View.VISIBLE) {
descriptionCaption.setVisibility(View.VISIBLE);
addDelDescription.setText(view.getResources().getString(R.string.delete_description));
addDelDescription.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16,
activeColorResId),null,null,null);
View descriptionEdit = view.findViewById(R.id.description_edit);
descriptionEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(getActivity(), descriptionEdit);
} else {
descriptionCaption.setVisibility(View.GONE);
addDelDescription.setText(view.getResources().getString(R.string.add_description));
addDelDescription.setCompoundDrawablesWithIntrinsicBounds(
app.getUIUtilities().getIcon(R.drawable.ic_action_description_16,
activeColorResId),null,null,null);
AndroidUtils.hideSoftKeyboard(requireActivity(), descriptionEdit);
descriptionEdit.clearFocus();
}
}
});
addAddressBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (addressCaption.getVisibility() != View.VISIBLE) {
addressCaption.setVisibility(View.VISIBLE);
addAddressBtn.setText(view.getResources().getString(R.string.delete_address));
View addressEdit = view.findViewById(R.id.address_edit);
addressEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(requireActivity(),addressEdit);
} else {
addressCaption.setVisibility(View.GONE);
addAddressBtn.setText(view.getResources().getString(R.string.add_address));
AndroidUtils.hideSoftKeyboard(requireActivity(), addressEdit);
addressEdit.clearFocus();
}
}
});
nameIcon.setImageDrawable(getNameIcon());
if (app.accessibilityEnabled()) {
nameCaption.setFocusable(true);
nameEdit.setHint(R.string.access_hint_enter_name);
descriptionEdit.setHint(R.string.access_hint_enter_description);
}
View deleteButton = view.findViewById(R.id.button_delete_container);
@ -348,6 +387,13 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
descriptionCaption.setVisibility(View.GONE);
addDelDescription.setText(app.getString(R.string.add_description));
}
if (!addressEdit.getText().toString().isEmpty() || addressEdit.hasFocus()) {
addressCaption.setVisibility(View.VISIBLE);
addAddressBtn.setText(app.getString(R.string.delete_address));
} else {
addressCaption.setVisibility(View.GONE);
addAddressBtn.setText(app.getString(R.string.add_address));
}
}
private void createGroupSelector() {
@ -754,6 +800,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public abstract String getDescriptionInitValue();
public abstract String getAddressInitValue();
public abstract Drawable getNameIcon();
public abstract Drawable getCategoryIcon();
@ -800,6 +848,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return Algorithms.isEmpty(res) ? null : res;
}
String getAddressTextValue() {
EditText addressEdit = view.findViewById(R.id.address_edit);
String res = addressEdit.getText().toString().trim();
return Algorithms.isEmpty(res) ? null : res;
}
protected Drawable getPaintedIcon(int iconId, int color) {
return getPaintedContentIcon(iconId, color);
}

View file

@ -402,6 +402,9 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
return wpt != null ? wpt.desc : "";
}
@Override
public String getAddressInitValue() { return ""; }
@Override
public Drawable getNameIcon() {
WptPt wptPt = getWpt();

View file

@ -14,6 +14,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.util.Algorithms;
import java.util.List;
@ -82,11 +83,18 @@ public class MultiSelectionArrayAdapter extends ArrayAdapter<MapMultiSelectionMe
// Text line 2
TextView line2 = (TextView) convertView.findViewById(R.id.context_menu_line2);
((TextView) line2).setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_subtitle_color));
line2.setText(item.getTypeStr());
StringBuilder line2Str = new StringBuilder(item.getTypeStr());
String streetStr = item.getStreetStr();
if (!Algorithms.isEmpty(streetStr) && !item.displayStreetNameInTitle()) {
if (line2Str.length() > 0) {
line2Str.append(", ");
}
line2Str.append(streetStr);
}
line2.setText(line2Str);
Drawable slIcon = item.getTypeIcon();
line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
// Divider
View divider = convertView.findViewById(R.id.divider);
divider.setBackgroundColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_divider_light : R.color.multi_selection_menu_divider_dark));

View file

@ -0,0 +1,81 @@
package net.osmand.view;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
public class GravityDrawable extends Drawable {
// inner Drawable
private final Drawable original;
public GravityDrawable(@NonNull Drawable drawable) {
this.original = drawable;
}
@Override
public int getMinimumHeight() {
return original.getMinimumHeight();
}
@Override
public int getMinimumWidth() {
return original.getMinimumWidth();
}
@Override
public int getIntrinsicHeight() {
return original.getIntrinsicHeight();
}
@Override
public int getIntrinsicWidth() {
return original.getIntrinsicWidth();
}
@Override
public void setChangingConfigurations(int configs) {
super.setChangingConfigurations(configs);
original.setChangingConfigurations(configs);
}
@Override
public void setBounds(int left, int top, int right, int bottom) {
super.setBounds(left, top, right, bottom);
original.setBounds(left, top, right, bottom);
}
@Override
public void setAlpha(int alpha) {
original.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
original.setColorFilter(cf);
}
@Override
public int getOpacity() {
return original.getOpacity();
}
@Override
public void draw(Canvas canvas) {
int halfCanvas = canvas.getHeight() / 2;
int halfDrawable = original.getIntrinsicHeight() / 2;
// align to top
canvas.save();
canvas.translate(0, -halfCanvas + halfDrawable);
original.draw(canvas);
canvas.restore();
}
public void setBoundsFrom(Drawable line2Icon) {
line2Icon.setBounds(0, 0, line2Icon.getIntrinsicWidth(), line2Icon.getIntrinsicHeight());
this.setBounds(0, 0, line2Icon.getIntrinsicWidth(), line2Icon.getIntrinsicHeight());
}
}