use of net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitmeListDividerItem in project Osmand by osmandapp.
the class SendAnalyticsBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = getMyApplication();
Context context = getContext();
if (context == null || app == null) {
return;
}
final View titleView = View.inflate(new ContextThemeWrapper(context, themeRes), R.layout.make_better_title, null);
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder().setCustomView(titleView).create();
items.add(titleItem);
items.add(new SubtitleDividerItem(context));
if (app.getSettings().SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.isSet()) {
sendAnonymousMapDownloadsData = app.getSettings().SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.get();
} else {
sendAnonymousMapDownloadsData = true;
}
if (app.getSettings().SEND_ANONYMOUS_APP_USAGE_DATA.isSet()) {
sendAnonymousAppUsageData = app.getSettings().SEND_ANONYMOUS_APP_USAGE_DATA.get();
} else {
sendAnonymousAppUsageData = true;
}
final BottomSheetItemWithCompoundButton[] downloadedMapsItem = new BottomSheetItemWithCompoundButton[1];
downloadedMapsItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(sendAnonymousMapDownloadsData).setTitle(getString(R.string.downloaded_maps)).setLayoutId(R.layout.bottom_sheet_item_with_switch_no_icon).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = !downloadedMapsItem[0].isChecked();
downloadedMapsItem[0].setChecked(checked);
sendAnonymousMapDownloadsData = checked;
updateBottomButtons();
}
}).setTag("downloaded_maps").create();
items.add(downloadedMapsItem[0]);
items.add(new LongDescriptionItem(getString(R.string.downloaded_maps_collect_descr)));
items.add(new SubtitmeListDividerItem(context));
final BottomSheetItemWithCompoundButton[] visitedScreensItem = new BottomSheetItemWithCompoundButton[1];
visitedScreensItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(sendAnonymousAppUsageData).setTitle(getString(R.string.visited_screens)).setLayoutId(R.layout.bottom_sheet_item_with_switch_no_icon).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = !visitedScreensItem[0].isChecked();
visitedScreensItem[0].setChecked(checked);
sendAnonymousAppUsageData = checked;
updateBottomButtons();
}
}).setTag("visited_screens").create();
items.add(visitedScreensItem[0]);
items.add(new LongDescriptionItem(getString(R.string.visited_screens_collect_descr)));
items.add(new DividerItem(context));
String privacyPolicyText = getString(R.string.shared_string_privacy_policy);
String text = getString(R.string.privacy_and_security_change_descr, privacyPolicyText);
SpannableString spannable = new SpannableString(text);
int start = text.indexOf(privacyPolicyText);
int end = start + privacyPolicyText.length();
spannable.setSpan(new URLSpan(OsmandApplication.OSMAND_PRIVACY_POLICY_URL) {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int linkTextColor = ContextCompat.getColor(context, !nightMode ? R.color.ctx_menu_bottom_view_url_color_light : R.color.ctx_menu_bottom_view_url_color_dark);
spannable.setSpan(new ForegroundColorSpan(linkTextColor), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
LongDescriptionItem descriptionItem = new LongDescriptionItem(spannable);
descriptionItem.setDescriptionLinksClickable(true);
items.add(descriptionItem);
}
use of net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitmeListDividerItem in project Osmand by osmandapp.
the class RecalculateRouteInDeviationBottomSheet method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
settings = app.getSettings();
appMode = getAppMode();
preference = settings.ROUTE_RECALCULATION_DISTANCE;
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
getPreferenceStateAndValue();
final SwitchPreferenceEx switchPref = (SwitchPreferenceEx) getPreference();
if (switchPref == null) {
return;
}
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_VALUE)) {
currentValue = savedInstanceState.getFloat(CURRENT_VALUE);
}
int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
MetricsConstants mc = settings.METRIC_SYSTEM.get();
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
entryValues = new Float[] { 10.f, 20.0f, 30.0f, 50.0f, 100.0f, 200.0f, 500.0f, 1000.0f, 1500.0f };
} else {
entryValues = new Float[] { 9.1f, 18.3f, 30.5f, 45.7f, 91.5f, 183.0f, 482.0f, 965.0f, 1609.0f };
}
final int appModeColor = appMode.getProfileColor(nightMode);
final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
String title = getString(R.string.recalculate_route_in_deviation);
items.add(new TitleItem(title));
final View sliderView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_slider_with_two_text, null);
slider = sliderView.findViewById(R.id.slider);
tvSliderTitle = sliderView.findViewById(android.R.id.title);
tvSliderTitle.setText(getString(R.string.distance));
tvSliderSummary = sliderView.findViewById(android.R.id.summary);
slider.setValueFrom(0);
slider.setValueTo(entryValues.length - 1);
slider.setStepSize(1);
updateSliderView();
final String on = getString(R.string.shared_string_enabled);
final String off = getString(R.string.shared_string_disabled);
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(enabled).setCompoundButtonColor(appModeColor).setTitle(enabled ? on : off).setTitleColorId(enabled ? activeColor : disabledColor).setCustomView(getCustomButtonView(app, getAppMode(), enabled, nightMode)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
enabled = !enabled;
sliderPositionChanged = false;
switchPref.setChecked(enabled);
preferenceBtn[0].setTitle(enabled ? on : off);
preferenceBtn[0].setTitleColorId(enabled ? activeColor : disabledColor);
preferenceBtn[0].setChecked(enabled);
getDefaultValue();
updateSliderView();
updateCustomButtonView(app, getAppMode(), v, enabled, nightMode);
Fragment target = getTargetFragment();
float newValue = enabled ? DEFAULT_MODE : DISABLE_MODE;
if (target instanceof OnConfirmPreferenceChange) {
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(switchPref.getKey(), newValue, ApplyQueryType.NONE);
}
}
}).create();
items.add(preferenceBtn[0]);
items.add(new DividerSpaceItem(app, contentPaddingSmall));
items.add(new LongDescriptionItem(getString(R.string.select_distance_route_will_recalc)));
items.add(new DividerSpaceItem(app, contentPadding));
slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
sliderPositionChanged = true;
if (fromUser) {
currentValue = entryValues[(int) slider.getValue()];
tvSliderSummary.setText(getFormattedDistance(app, currentValue));
}
}
});
UiUtilities.setupSlider(slider, nightMode, appModeColor, true);
items.add(new BaseBottomSheetItem.Builder().setCustomView(sliderView).create());
items.add(new SubtitmeListDividerItem(getContext()));
items.add(new DividerSpaceItem(app, contentPaddingSmall));
items.add(new LongDescriptionItem(getString(R.string.recalculate_route_distance_promo)));
}
Aggregations