Search in sources :

Example 1 with NavigationIcon

use of net.osmand.plus.profiles.NavigationIcon in project Osmand by osmandapp.

the class ProfileAppearanceFragment method onBindPreferenceViewHolder.

@Override
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
    super.onBindPreferenceViewHolder(preference, holder);
    if (PROFILE_NAME.equals(preference.getKey())) {
        profileName = (EditText) holder.findViewById(R.id.profile_name_et);
        profileName.setImeOptions(EditorInfo.IME_ACTION_DONE);
        profileName.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        profileName.setText(changedProfile.name);
        profileName.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                changedProfile.name = s.toString();
                if (nameIsEmpty()) {
                    disableSaveButtonWithErrorMessage(app.getString(R.string.please_provide_profile_name_message));
                } else if (hasNameDuplicate()) {
                    disableSaveButtonWithErrorMessage(app.getString(R.string.profile_alert_duplicate_name_msg));
                } else {
                    saveButton.setEnabled(true);
                }
            }
        });
        profileName.setOnFocusChangeListener(new View.OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    profileName.setSelection(profileName.getText().length());
                    AndroidUtils.showSoftKeyboard(getMyActivity(), profileName);
                }
            }
        });
        if (getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile) {
            profileName.setFocusableInTouchMode(false);
            profileName.setFocusable(false);
        }
        profileNameOtfb = (OsmandTextFieldBoxes) holder.findViewById(R.id.profile_name_otfb);
        updateProfileNameAppearance();
    } else if (MASTER_PROFILE.equals(preference.getKey())) {
        baseProfileName = (EditText) holder.findViewById(R.id.master_profile_et);
        baseProfileName.setFocusable(false);
        baseProfileName.setText(changedProfile.parent != null ? changedProfile.parent.toHumanString() : getSelectedAppMode().toHumanString());
        OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.master_profile_otfb);
        baseProfileNameHint.setLabelText(getString(R.string.profile_type_osmand_string));
        FrameLayout selectNavTypeBtn = (FrameLayout) holder.findViewById(R.id.select_nav_type_btn);
        selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isNewProfile) {
                    hideKeyboard();
                    if (getActivity() != null) {
                        String selected = changedProfile.parent != null ? changedProfile.parent.getStringKey() : null;
                        SelectBaseProfileBottomSheet.showInstance(getActivity(), ProfileAppearanceFragment.this, getSelectedAppMode(), selected, false);
                    }
                }
            }
        });
    } else if (SELECT_COLOR.equals(preference.getKey())) {
        colorName = holder.itemView.findViewById(R.id.summary);
        colorName.setTextColor(ContextCompat.getColor(app, R.color.preference_category_title));
    } else if (COLOR_ITEMS.equals(preference.getKey())) {
        createColorsCard(holder);
    } else if (ICON_ITEMS.equals(preference.getKey())) {
        iconItems = (FlowLayout) holder.findViewById(R.id.color_items);
        iconItems.removeAllViews();
        ArrayList<Integer> icons = ProfileIcons.getIcons();
        for (int iconRes : icons) {
            View iconItem = createIconItemView(iconRes, iconItems);
            int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding);
            iconItems.addView(iconItem, new FlowLayout.LayoutParams(minimalPaddingBetweenIcon, 0));
            iconItems.setHorizontalAutoSpacing(true);
        }
        setIconColor(changedProfile.iconRes);
    } else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) {
        locationIconItems = (FlowLayout) holder.findViewById(R.id.color_items);
        locationIconItems.removeAllViews();
        for (LocationIcon locationIcon : LocationIcon.values()) {
            View iconItemView = createLocationIconView(locationIcon, locationIconItems);
            locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
        }
        updateLocationIconSelector(changedProfile.locationIcon);
    } else if (NAV_ICON_ITEMS.equals(preference.getKey())) {
        navIconItems = (FlowLayout) holder.findViewById(R.id.color_items);
        navIconItems.removeAllViews();
        for (NavigationIcon navigationIcon : NavigationIcon.values()) {
            View iconItemView = createNavigationIconView(navigationIcon, navIconItems);
            navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
        }
        updateNavigationIconSelector(changedProfile.navigationIcon);
    }
}
Also used : EditText(android.widget.EditText) LocationIcon(net.osmand.plus.profiles.LocationIcon) FlowLayout(net.osmand.plus.widgets.FlowLayout) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) OsmandTextFieldBoxes(net.osmand.plus.widgets.OsmandTextFieldBoxes) FrameLayout(android.widget.FrameLayout) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) NavigationIcon(net.osmand.plus.profiles.NavigationIcon)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 LocationIcon (net.osmand.plus.profiles.LocationIcon)1 NavigationIcon (net.osmand.plus.profiles.NavigationIcon)1 FlowLayout (net.osmand.plus.widgets.FlowLayout)1 OsmandTextFieldBoxes (net.osmand.plus.widgets.OsmandTextFieldBoxes)1