scroll menu

This commit is contained in:
madwasp79 2019-07-02 10:09:45 +03:00
parent 1df2a3a2cf
commit 36672ba7db
2 changed files with 72 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package net.osmand.plus.activities.actions;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.LayoutRes;
@ -8,11 +9,14 @@ import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -21,9 +25,12 @@ import net.osmand.plus.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
public class AppModeDialog {
private static final Log LOG = PlatformUtil.getLog(AppModeDialog.class);
public static View prepareAppModeView(Activity a, final Set<ApplicationMode> selected, boolean showDefault,
ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener) {
OsmandApplication app = (OsmandApplication) a.getApplication();
@ -58,7 +65,7 @@ public class AppModeDialog {
public static View prepareAppModeView(Activity a, final List<ApplicationMode> values, final Set<ApplicationMode> selected,
ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener, boolean nightMode) {
View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
final View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
if (useListBg) {
AndroidUtils.setListItemBackground(a, ll, nightMode);
} else {
@ -73,6 +80,37 @@ public class AppModeDialog {
updateButtonState((OsmandApplication) a.getApplication(), values, selected, onClickListener, buttons, i,
singleSelection, useMapTheme, nightMode);
}
final int[] scrollLength = {0};
OsmandApplication app = (OsmandApplication) a.getApplication();
int buttonWidth = AndroidUtils.dpToPx(a, (int) a.getResources().getDimension(R.dimen.route_info_modes_height));
List<ApplicationMode> modes = new ArrayList<>(ApplicationMode.values(app));
final HorizontalScrollView sv = ll.findViewById(R.id.app_modes_scroll_container);
if (app.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
for (int i = 0; i < modes.size(); i++) {
if (modes.get(i).equals(app.getSettings().getApplicationMode())
&& (i - 1) * buttonWidth > AndroidUtils.getScreenWidth(a)) {
scrollLength[0] = i * buttonWidth - AndroidUtils.getScreenWidth(a);
}
}
} else {
for (int i = 0; i < modes.size(); i++) {
if (modes.get(i).equals(app.getSettings().getApplicationMode())) {
scrollLength[0] = i * buttonWidth - (int) app.getResources()
.getDimension(R.dimen.dashboard_land_width);
}
}
}
OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
sv.scrollTo(scrollLength[0], 0);
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
};
ll.getViewTreeObserver().addOnGlobalLayoutListener(listener);
return ll;
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.routepreparationmenu;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.content.res.Configuration;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Build;
@ -21,6 +22,7 @@ import android.support.v7.widget.AppCompatImageView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
@ -804,10 +806,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
updateApplicationMode(am, next);
}
View ll = mapActivity.getLayoutInflater().inflate(R.layout.mode_toggles, vg);
final View ll = mapActivity.getLayoutInflater().inflate(R.layout.mode_toggles, vg);
ll.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.card_and_list_background_dark : R.color.card_and_list_background_light));
HorizontalScrollView scrollView = ll.findViewById(R.id.app_modes_scroll_container);
final HorizontalScrollView scrollView = ll.findViewById(R.id.app_modes_scroll_container);
scrollView.setVerticalScrollBarEnabled(false);
scrollView.setHorizontalScrollBarEnabled(false);
@ -837,6 +839,35 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
for (int i = 0; i < buttons.length; i++) {
AppModeDialog.updateButtonStateForRoute((OsmandApplication) mapActivity.getApplication(), values, selected, listener, buttons, i, true, true, nightMode);
}
final int[] scrollLength = {0};
int buttonWidth = AndroidUtils.dpToPx(mapActivity,
(int) mapActivity.getResources().getDimension(R.dimen.route_info_modes_height));
if (app.getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT) {
for (int i = 0; i < values.size(); i++) {
if (values.get(i).equals(app.getSettings().getApplicationMode())
&& (i - 1) * buttonWidth > AndroidUtils.getScreenWidth(mapActivity)) {
scrollLength[0] = i * buttonWidth - AndroidUtils.getScreenWidth(mapActivity);
}
}
} else {
for (int i = 0; i < values.size(); i++) {
if (values.get(i).equals(app.getSettings().getApplicationMode())) {
scrollLength[0] = i * buttonWidth - (int) app.getResources()
.getDimension(R.dimen.dashboard_land_width);
}
}
}
OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
scrollView.scrollTo(scrollLength[0], 0);
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
};
ll.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
}
private void updateOptionsButtons() {