Search in sources :

Example 11 with TextRadioItem

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem 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 12 with TextRadioItem

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

the class CycleRoutesFragment method createRadioButton.

private TextRadioItem createRadioButton(@NonNull CommonPreference<Boolean> pref, boolean enabled, int titleId) {
    TextRadioItem item = new TextRadioItem(getString(titleId));
    item.setOnClickListener(new OnRadioItemClickListener() {

        @Override
        public boolean onRadioItemClick(RadioItem radioItem, View view) {
            pref.set(enabled);
            View mainView = getView();
            if (mainView != null) {
                setupTypesCard(mainView);
            }
            MapActivity mapActivity = (MapActivity) getMyActivity();
            if (mapActivity != null) {
                mapActivity.refreshMapComplete();
                mapActivity.getMapLayers().updateLayers(mapActivity);
            }
            return true;
        }
    });
    return item;
}
Also used : OnRadioItemClickListener(net.osmand.plus.widgets.multistatetoggle.RadioItem.OnRadioItemClickListener) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) RadioItem(net.osmand.plus.widgets.multistatetoggle.RadioItem) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 13 with TextRadioItem

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem 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 14 with TextRadioItem

use of net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem 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)

Example 15 with TextRadioItem

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

the class RouteLineColorCard method createMapThemeButton.

private TextRadioItem createMapThemeButton(final boolean isNight) {
    TextRadioItem item = new TextRadioItem(app.getString(!isNight ? DAY_TITLE_ID : NIGHT_TITLE_ID));
    item.setOnClickListener(new OnRadioItemClickListener() {

        @Override
        public boolean onRadioItemClick(RadioItem radioItem, View view) {
            selectedMapTheme = isNight ? DayNightMode.NIGHT : DayNightMode.DAY;
            changeMapTheme(selectedMapTheme);
            updateDescription();
            return true;
        }
    });
    return item;
}
Also used : OnRadioItemClickListener(net.osmand.plus.widgets.multistatetoggle.RadioItem.OnRadioItemClickListener) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) RadioItem(net.osmand.plus.widgets.multistatetoggle.RadioItem) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

TextRadioItem (net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem)19 View (android.view.View)10 TextToggleButton (net.osmand.plus.widgets.multistatetoggle.TextToggleButton)10 TextView (android.widget.TextView)9 ImageView (android.widget.ImageView)6 LinearLayout (android.widget.LinearLayout)6 RadioItem (net.osmand.plus.widgets.multistatetoggle.RadioItem)5 OnRadioItemClickListener (net.osmand.plus.widgets.multistatetoggle.RadioItem.OnRadioItemClickListener)5 OsmandApplication (net.osmand.plus.OsmandApplication)3 Drawable (android.graphics.drawable.Drawable)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 MapActivity (net.osmand.plus.activities.MapActivity)2 Typeface (android.graphics.Typeface)1 SpannableString (android.text.SpannableString)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1 CompoundButton (android.widget.CompoundButton)1 ImageButton (android.widget.ImageButton)1 Nullable (androidx.annotation.Nullable)1 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)1