Search in sources :

Example 6 with TextToggleButton

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.

the class GPXAction method setupWaypointAppearanceToggle.

private void setupWaypointAppearanceToggle(@NonNull View container, @NonNull MapActivity mapActivity) {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean night = isNightMode(mapActivity);
    boolean usePredefinedAppearance = predefinedWaypoint != null || Boolean.parseBoolean(getParams().get(KEY_USE_PREDEFINED_WPT_APPEARANCE));
    LinearLayout appearanceToggle = container.findViewById(R.id.appearance_toggle);
    appearanceToggleButton = new TextToggleButton(app, appearanceToggle, night);
    TextRadioItem alwaysAskButton = new TextRadioItem(app.getString(R.string.confirm_every_run));
    TextRadioItem predefinedAppearanceButton = new TextRadioItem(app.getString(R.string.shared_string_predefined));
    alwaysAskButton.setOnClickListener(getOnAppearanceToggleButtonClicked(container, true, mapActivity));
    predefinedAppearanceButton.setOnClickListener(getOnAppearanceToggleButtonClicked(container, false, mapActivity));
    appearanceToggleButton.setItems(alwaysAskButton, predefinedAppearanceButton);
    TextRadioItem selectedItem = usePredefinedAppearance ? predefinedAppearanceButton : alwaysAskButton;
    appearanceToggleButton.setSelectedItem(selectedItem);
    updateAppearanceBottomInfo(container, !usePredefinedAppearance, mapActivity);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) TextToggleButton(net.osmand.plus.widgets.multistatetoggle.TextToggleButton) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) LinearLayout(android.widget.LinearLayout)

Example 7 with TextToggleButton

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.

the class SelectProfileBottomSheet method addToggleButton.

protected void addToggleButton(TextRadioItem selectedItem, TextRadioItem... radioItems) {
    int padding = getDimen(R.dimen.content_padding_small);
    Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
    LayoutInflater inflater = UiUtilities.getInflater(themedCtx, nightMode);
    LinearLayout container = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
    LinearLayout.MarginLayoutParams params = new LinearLayout.MarginLayoutParams(LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
    AndroidUtils.setMargins(params, padding, padding, padding, 0);
    container.setLayoutParams(params);
    TextToggleButton radioGroup = new TextToggleButton(app, container, nightMode);
    radioGroup.setItems(radioItems);
    radioGroup.setSelectedItem(selectedItem);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(container).create());
}
Also used : Context(android.content.Context) BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) TextToggleButton(net.osmand.plus.widgets.multistatetoggle.TextToggleButton) LayoutInflater(android.view.LayoutInflater) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LinearLayout(android.widget.LinearLayout)

Example 8 with TextToggleButton

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.

the class VoiceLanguageBottomSheetFragment method setupTypeRadioGroup.

private void setupTypeRadioGroup(LinearLayout buttonsContainer) {
    TextRadioItem tts = createRadioButton(InfoType.TTS);
    TextRadioItem recorded = createRadioButton(InfoType.RECORDED);
    TextToggleButton radioGroup = new TextToggleButton(app, buttonsContainer, nightMode);
    radioGroup.setItems(tts, recorded);
    if (selectedVoiceType == InfoType.TTS) {
        radioGroup.setSelectedItem(tts);
    } else {
        radioGroup.setSelectedItem(recorded);
    }
}
Also used : TextToggleButton(net.osmand.plus.widgets.multistatetoggle.TextToggleButton) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem)

Example 9 with TextToggleButton

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.

the class LiveUpdatesSettingsBottomSheet method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    app = requiredMyApplication();
    settings = app.getSettings();
    LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
    if (getTargetFragment() instanceof OnLiveUpdatesForLocalChange) {
        onLiveUpdatesForLocalChange = (OnLiveUpdatesForLocalChange) getTargetFragment();
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(LOCAL_INDEX_FILE_NAME)) {
        fileName = savedInstanceState.getString(LOCAL_INDEX_FILE_NAME);
    }
    CommonPreference<Boolean> localUpdatePreference = preferenceForLocalIndex(fileName, settings);
    CommonPreference<Boolean> downloadViaWiFiPreference = preferenceDownloadViaWiFi(fileName, settings);
    CommonPreference<Integer> frequencyPreference = preferenceUpdateFrequency(fileName, settings);
    CommonPreference<Integer> timeOfDayPreference = preferenceTimeOfDayToUpdate(fileName, settings);
    int dp6 = getDimen(R.dimen.content_padding_small_half);
    int dp8 = getDimen(R.dimen.content_padding_half);
    int dp12 = getDimen(R.dimen.content_padding_small);
    int dp16 = getDimen(R.dimen.content_padding);
    int dp24 = getDimen(R.dimen.dialog_content_margin);
    int dp36 = getDimen(R.dimen.dialog_button_height);
    itemTitle = new SimpleBottomSheetItem.Builder().setTitle(getNameToDisplay(fileName, app)).setTitleColorId(ColorUtilities.getPrimaryTextColorId(nightMode)).setLayoutId(R.layout.bottom_sheet_item_title_big).create();
    items.add(itemTitle);
    itemLastCheck = new ShortDescriptionItem.Builder().setDescription(getLastCheckString()).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setDescriptionMaxLines(2).setLayoutId(R.layout.bottom_sheet_item_description).create();
    items.add(itemLastCheck);
    View itemLiveUpdate = getCustomButtonView(app, null, localUpdatePreference.get(), nightMode);
    View itemLiveUpdateButton = itemLiveUpdate.findViewById(R.id.button_container);
    CompoundButton button = (CompoundButton) itemLiveUpdateButton.findViewById(R.id.compound_button);
    UiUtilities.setupCompoundButton(button, nightMode, TOOLBAR);
    itemLiveUpdateButton.setMinimumHeight(getDimen(R.dimen.bottom_sheet_selected_item_title_height));
    itemSwitchLiveUpdate = new BottomSheetItemWithCompoundButton.Builder().setChecked(localUpdatePreference.get()).setTitle(getStateText(localUpdatePreference.get())).setTitleColorId(ColorUtilities.getActiveTabTextColorId(nightMode)).setCustomView(itemLiveUpdate).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) itemSwitchLiveUpdate;
            boolean checked = item.isChecked();
            item.setChecked(!checked);
            if (onLiveUpdatesForLocalChange != null && onLiveUpdatesForLocalChange.onUpdateLocalIndex(fileName, !checked, new Runnable() {

                @Override
                public void run() {
                    updateLastCheck();
                    updateFrequencyHelpMessage();
                    updateFileSize();
                    Fragment target = getTargetFragment();
                    if (target instanceof LiveUpdatesFragment) {
                        ((LiveUpdatesFragment) target).runSort();
                    }
                }
            })) {
                item.setTitle(getStateText(!checked));
                updateCustomButtonView(app, null, item.getView(), !checked, nightMode);
                CommonPreference<Boolean> localUpdatePreference = preferenceForLocalIndex(fileName, settings);
                frequencyToggleButton.setItemsEnabled(localUpdatePreference.get());
                timeOfDayToggleButton.setItemsEnabled(localUpdatePreference.get());
                setStateViaWiFiButton(localUpdatePreference);
            }
        }
    }).create();
    items.add(itemSwitchLiveUpdate);
    Typeface typefaceRegular = FontCache.getRobotoRegular(app);
    TextViewEx frequencyTitle = (TextViewEx) inflater.inflate(R.layout.bottom_sheet_item_title, null);
    frequencyTitle.setMinHeight(dp24);
    frequencyTitle.setMinimumHeight(dp24);
    frequencyTitle.setText(R.string.update_frequency);
    frequencyTitle.setTypeface(typefaceRegular);
    AndroidUtils.setPadding(frequencyTitle, dp16, dp12, dp16, dp12);
    AndroidUtils.setTextPrimaryColor(app, frequencyTitle, nightMode);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(frequencyTitle).create());
    LinearLayout itemFrequencyButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
    LinearLayout.MarginLayoutParams itemFrequencyParams = new LinearLayout.MarginLayoutParams(LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
    AndroidUtils.setMargins(itemFrequencyParams, dp16, 0, dp16, 0);
    itemFrequencyButtons.setLayoutParams(itemFrequencyParams);
    String hourly = getString(R.string.hourly);
    String daily = getString(R.string.daily);
    String weekly = getString(R.string.weekly);
    TextRadioItem hourlyButton = new TextRadioItem(hourly);
    TextRadioItem dailyButton = new TextRadioItem(daily);
    TextRadioItem weeklyButton = new TextRadioItem(weekly);
    frequencyToggleButton = new TextToggleButton(app, itemFrequencyButtons, nightMode);
    frequencyToggleButton.setItems(hourlyButton, dailyButton, weeklyButton);
    setSelectedRadioItem(frequencyToggleButton, frequencyPreference.get(), hourlyButton, dailyButton, weeklyButton);
    frequencyToggleButton.setItemsEnabled(localUpdatePreference.get());
    items.add(new BaseBottomSheetItem.Builder().setCustomView(itemFrequencyButtons).create());
    TextViewEx timeOfDayTitle = (TextViewEx) inflater.inflate(R.layout.bottom_sheet_item_title, null);
    timeOfDayTitle.setMinHeight(dp24);
    timeOfDayTitle.setMinimumHeight(dp24);
    timeOfDayTitle.setText(R.string.update_time);
    timeOfDayTitle.setTypeface(typefaceRegular);
    AndroidUtils.setPadding(timeOfDayTitle, dp16, dp16, dp16, dp6);
    AndroidUtils.setTextPrimaryColor(app, timeOfDayTitle, nightMode);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(timeOfDayTitle).create());
    LinearLayout itemTimeOfDayButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
    LinearLayout.MarginLayoutParams itemTimeOfDayParams = new LinearLayout.MarginLayoutParams(LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
    AndroidUtils.setMargins(itemTimeOfDayParams, dp16, 0, dp16, 0);
    itemTimeOfDayButtons.setLayoutParams(itemTimeOfDayParams);
    String morning = getString(R.string.morning);
    String night = getString(R.string.night);
    TextRadioItem morningButton = new TextRadioItem(morning);
    TextRadioItem nightButton = new TextRadioItem(night);
    timeOfDayToggleButton = new TextToggleButton(app, itemTimeOfDayButtons, nightMode);
    timeOfDayToggleButton.setItems(morningButton, nightButton);
    setSelectedRadioItem(timeOfDayToggleButton, timeOfDayPreference.get(), morningButton, nightButton);
    timeOfDayToggleButton.setItemsEnabled(localUpdatePreference.get());
    refreshTimeOfDayLayout(frequencyPreference.get(), itemTimeOfDayButtons, timeOfDayTitle);
    morningButton.setOnClickListener(getTimeOfDayButtonListener(TimeOfDay.MORNING));
    nightButton.setOnClickListener(getTimeOfDayButtonListener(TimeOfDay.NIGHT));
    items.add(new BaseBottomSheetItem.Builder().setCustomView(itemTimeOfDayButtons).create());
    hourlyButton.setOnClickListener(getFrequencyButtonListener(UpdateFrequency.HOURLY, itemTimeOfDayButtons, timeOfDayTitle));
    dailyButton.setOnClickListener(getFrequencyButtonListener(UpdateFrequency.DAILY, itemTimeOfDayButtons, timeOfDayTitle));
    weeklyButton.setOnClickListener(getFrequencyButtonListener(UpdateFrequency.WEEKLY, itemTimeOfDayButtons, timeOfDayTitle));
    itemFrequencyHelpMessage = new ShortDescriptionItem.Builder().setDescription(getFrequencyHelpMessage()).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setLayoutId(R.layout.bottom_sheet_item_description).create();
    items.add(itemFrequencyHelpMessage);
    LinearLayout itemUpdateNowButton = (LinearLayout) inflater.inflate(R.layout.bottom_sheet_button_with_icon_center, null);
    LinearLayout.MarginLayoutParams itemUpdateNowParams = new LinearLayout.MarginLayoutParams(LinearLayout.MarginLayoutParams.MATCH_PARENT, dp36);
    AndroidUtils.setMargins(itemUpdateNowParams, dp12, dp16, dp16, dp12);
    itemUpdateNowButton.setLayoutParams(itemUpdateNowParams);
    ((AppCompatImageView) itemUpdateNowButton.findViewById(R.id.button_icon)).setImageDrawable(AppCompatResources.getDrawable(app, R.drawable.ic_action_update));
    UiUtilities.setupDialogButton(nightMode, itemUpdateNowButton, UiUtilities.DialogButtonType.SECONDARY, getString(R.string.update_now));
    itemUpdateNowButton.setMinimumHeight(AndroidUtils.dpToPx(app, dp36));
    items.add(new BaseBottomSheetItem.Builder().setCustomView(itemUpdateNowButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!settings.isInternetConnectionAvailable()) {
                app.showShortToastMessage(R.string.no_internet_connection);
            } else {
                if (onLiveUpdatesForLocalChange != null) {
                    Runnable runnable = () -> {
                        if (isAdded()) {
                            updateLastCheck();
                            updateFrequencyHelpMessage();
                            updateFileSize();
                            Fragment target = getTargetFragment();
                            if (target instanceof LiveUpdatesFragment) {
                                ((LiveUpdatesFragment) target).updateList();
                            }
                        }
                    };
                    onLiveUpdatesForLocalChange.forceUpdateLocal(fileName, true, runnable);
                }
            }
        }
    }).create());
    items.add(createDividerItem());
    int iconDeleteColor = ContextCompat.getColor(app, R.color.color_osm_edit_delete);
    Drawable iconDelete = AppCompatResources.getDrawable(app, R.drawable.ic_action_delete_dark);
    itemClear = new BottomSheetItemWithDescription.Builder().setDescription(getUpdatesSizeStr()).setIcon(UiUtilities.tintDrawable(iconDelete, iconDeleteColor)).setTitle(getString(R.string.updates_size)).setLayoutId(R.layout.bottom_sheet_item_with_descr_icon_right).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getUpdatesSize() > 0) {
                if (getFragmentManager() != null) {
                    LiveUpdatesClearBottomSheet.showInstance(getFragmentManager(), LiveUpdatesSettingsBottomSheet.this, fileName);
                }
            }
        }
    }).create();
    items.add(itemClear);
    items.add(createDividerItem());
    itemViaWiFi = new BottomSheetItemWithCompoundButton.Builder().setChecked(downloadViaWiFiPreference.get()).setDescription(getStateText(downloadViaWiFiPreference.get())).setIconHidden(true).setTitle(getString(R.string.only_download_over_wifi)).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (preferenceForLocalIndex(fileName, settings).get()) {
                BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) itemViaWiFi;
                boolean checked = item.isChecked();
                item.setChecked(!checked);
                item.setDescription(getStateText(!checked));
                preferenceDownloadViaWiFi(fileName, settings).set(!checked);
            }
        }
    }).create();
    items.add(itemViaWiFi);
    items.add(new DividerSpaceItem(app, getDimen(R.dimen.context_menu_padding_margin_large)));
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) SpannableString(android.text.SpannableString) ShortDescriptionItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem) Fragment(androidx.fragment.app.Fragment) MenuBottomSheetDialogFragment(net.osmand.plus.base.MenuBottomSheetDialogFragment) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription) TextViewEx(net.osmand.plus.widgets.TextViewEx) DividerSpaceItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) CommonPreference(net.osmand.plus.settings.backend.preferences.CommonPreference) Typeface(android.graphics.Typeface) Drawable(android.graphics.drawable.Drawable) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) View(android.view.View) BooleanPreferenceBottomSheet.updateCustomButtonView(net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.updateCustomButtonView) TextView(android.widget.TextView) BooleanPreferenceBottomSheet.getCustomButtonView(net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.getCustomButtonView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) TextToggleButton(net.osmand.plus.widgets.multistatetoggle.TextToggleButton) LayoutInflater(android.view.LayoutInflater) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Example 10 with TextToggleButton

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton in project Osmand by osmandapp.

the class RouteLineColorCard method setupRadioGroup.

private void setupRadioGroup(LinearLayout buttonsContainer) {
    TextRadioItem day = createMapThemeButton(false);
    TextRadioItem night = createMapThemeButton(true);
    TextToggleButton radioGroup = new TextToggleButton(app, buttonsContainer, nightMode);
    radioGroup.setItems(day, night);
    radioGroup.setSelectedItem(!isNightMap() ? day : night);
}
Also used : TextToggleButton(net.osmand.plus.widgets.multistatetoggle.TextToggleButton) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem)

Aggregations

TextToggleButton (net.osmand.plus.widgets.multistatetoggle.TextToggleButton)12 TextRadioItem (net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem)10 LinearLayout (android.widget.LinearLayout)7 View (android.view.View)5 TextView (android.widget.TextView)5 ImageView (android.widget.ImageView)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 Drawable (android.graphics.drawable.Drawable)2 LayoutInflater (android.view.LayoutInflater)2 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)2 Context (android.content.Context)1 Typeface (android.graphics.Typeface)1 SpannableString (android.text.SpannableString)1 OnClickListener (android.view.View.OnClickListener)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 CompoundButton (android.widget.CompoundButton)1 ImageButton (android.widget.ImageButton)1 Nullable (androidx.annotation.Nullable)1 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)1 Fragment (androidx.fragment.app.Fragment)1