Added powered by OsmAnd drawer item

This commit is contained in:
crimean 2018-11-10 19:12:29 +03:00
parent dd074b5c2f
commit 996e3ca65f
4 changed files with 109 additions and 15 deletions

View file

@ -93,13 +93,32 @@
</FrameLayout>
<ListView
android:id="@+id/menuItems"
<RelativeLayout
android:id="@+id/drawer_relative_layout"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="?attr/bg_color"
android:clipToPadding="false"
android:drawSelectorOnTop="true"/>
android:layout_gravity="start">
<ListView
android:id="@+id/menuItems"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="?attr/bg_color"
android:clipToPadding="false"
android:drawSelectorOnTop="true" />
<RelativeLayout
android:id="@+id/drawer_footer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_alignParentBottom="true"
android:visibility="gone">
<include layout="@layout/powered_by_osmand_item"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="bottom"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:contentDescription="@string/app_name_osmand"
android:scaleType="centerInside"
android:tint="@color/osmand_orange"
android:src="@drawable/ic_action_osmand_logo" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:drawablePadding="24dp"
android:gravity="center_vertical"
android:minHeight="@dimen/list_item_height"
android:paddingStart="4dp"
android:paddingLeft="4dp"
android:text="@string/powered_by_osmand"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textStyle="normal" />
</LinearLayout>

View file

@ -10,6 +10,7 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
-->
<string name="powered_by_osmand">Powered by OsmAnd</string>
<string name="osm_live_plan_pricing">Plan &amp; Pricing</string>
<string name="osm_live_payment_monthly_title">Pay monthly</string>
<string name="osm_live_payment_3_months_title">Pay once in 3 months</string>

View file

@ -49,7 +49,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.activities.actions.OsmAndDialogs;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
@ -130,14 +129,16 @@ public class MapActivityActions implements DialogProvider {
private RoutingHelper routingHelper;
@NonNull
private ImageView navDrawerLogoHeader;
private ImageView drawerLogoHeader;
private View drawerOsmAndFooter;
public MapActivityActions(MapActivity mapActivity) {
this.mapActivity = mapActivity;
settings = mapActivity.getMyApplication().getSettings();
routingHelper = mapActivity.getMyApplication().getRoutingHelper();
navDrawerLogoHeader = new ImageView(mapActivity);
navDrawerLogoHeader.setPadding(-AndroidUtils.dpToPx(mapActivity, 8f), AndroidUtils.dpToPx(mapActivity, 16f), 0,0);
drawerLogoHeader = new ImageView(mapActivity);
drawerLogoHeader.setPadding(-AndroidUtils.dpToPx(mapActivity, 8f), AndroidUtils.dpToPx(mapActivity, 16f), 0,0);
drawerOsmAndFooter = mapActivity.getLayoutInflater().inflate(R.layout.powered_by_osmand_item, null);
}
public void addAsTarget(double latitude, double longitude, PointDescription pd) {
@ -997,11 +998,14 @@ public class MapActivityActions implements DialogProvider {
} else {
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light));
}
menuItemsListView.removeHeaderView(navDrawerLogoHeader);
final Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
menuItemsListView.removeHeaderView(drawerLogoHeader);
menuItemsListView.removeFooterView(drawerOsmAndFooter);
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
boolean customHeader = false;
if (navDrawerLogo != null) {
navDrawerLogoHeader.setImageBitmap(navDrawerLogo);
menuItemsListView.addHeaderView(navDrawerLogoHeader);
customHeader = true;
drawerLogoHeader.setImageBitmap(navDrawerLogo);
menuItemsListView.addHeaderView(drawerLogoHeader);
}
menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
@ -1013,7 +1017,9 @@ public class MapActivityActions implements DialogProvider {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mapActivity.dismissCardDialog();
if (position == 0 && navDrawerLogo != null) {
boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0;
boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0;
if ((hasHeader && position == 0) || (hasFooter && position == menuItemsListView.getCount() - 1)) {
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
} else {
@ -1027,6 +1033,40 @@ public class MapActivityActions implements DialogProvider {
}
}
});
if (customHeader) {
menuItemsListView.post(new Runnable() {
public void run() {
View footerLayout = mapActivity.findViewById(R.id.drawer_footer_layout);
boolean showFooterLayout = false;
if (menuItemsListView.getChildCount() > 0) {
int numItemsVisible = menuItemsListView.getLastVisiblePosition() -
menuItemsListView.getFirstVisiblePosition();
View lastView = menuItemsListView.getChildAt(menuItemsListView.getLastVisiblePosition());
boolean overlapped = lastView != null && lastView.getY() + lastView.getHeight() * 2 > menuItemsListView.getHeight();
if (simpleListAdapter.getCount() - 1 > numItemsVisible || overlapped) {
menuItemsListView.addFooterView(drawerOsmAndFooter);
} else {
showFooterLayout = true;
}
} else {
showFooterLayout = true;
}
if (showFooterLayout) {
footerLayout.setVisibility(View.VISIBLE);
footerLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
}
});
} else {
footerLayout.setVisibility(View.GONE);
}
}
});
}
}
public void setFirstMapMarkerAsTarget() {