Search in sources :

Example 6 with TextViewEx

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

the class AmenityMenuBuilder method buildRow.

protected void buildRow(final View view, Drawable icon, final String text, final String textPrefix, boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, boolean isPhoneNumber, boolean isUrl, boolean matchWidthDivider, int textLinesLimit) {
    if (!isFirstRow()) {
        buildRowDivider(view);
    }
    final String txt = text;
    LinearLayout baseView = new LinearLayout(view.getContext());
    baseView.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    baseView.setLayoutParams(llBaseViewParams);
    LinearLayout ll = new LinearLayout(view.getContext());
    ll.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    ll.setLayoutParams(llParams);
    ll.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
    ll.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            String textToCopy = !Algorithms.isEmpty(textPrefix) ? textPrefix + ": " + txt : txt;
            copyToClipboard(textToCopy, view.getContext());
            return true;
        }
    });
    baseView.addView(ll);
    // Icon
    if (icon != null) {
        LinearLayout llIcon = new LinearLayout(view.getContext());
        llIcon.setOrientation(LinearLayout.HORIZONTAL);
        llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(64f), dpToPx(48f)));
        llIcon.setGravity(Gravity.CENTER_VERTICAL);
        ll.addView(llIcon);
        ImageView iconView = new ImageView(view.getContext());
        LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
        llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f));
        llIconParams.gravity = Gravity.CENTER_VERTICAL;
        iconView.setLayoutParams(llIconParams);
        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        iconView.setImageDrawable(icon);
        llIcon.addView(iconView);
    }
    // Text
    LinearLayout llText = new LinearLayout(view.getContext());
    llText.setOrientation(LinearLayout.VERTICAL);
    ll.addView(llText);
    TextView textPrefixView = null;
    if (!Algorithms.isEmpty(textPrefix)) {
        textPrefixView = new TextView(view.getContext());
        LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0);
        textPrefixView.setLayoutParams(llTextParams);
        textPrefixView.setTextSize(12);
        textPrefixView.setTextColor(app.getResources().getColor(R.color.ctx_menu_buttons_text_color));
        textPrefixView.setEllipsize(TextUtils.TruncateAt.END);
        textPrefixView.setMinLines(1);
        textPrefixView.setMaxLines(1);
        textPrefixView.setText(textPrefix);
    }
    TextView textView = new TextView(view.getContext());
    LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, textPrefixView == null ? (collapsable ? dpToPx(13f) : dpToPx(8f)) : dpToPx(2f), 0, collapsable && textPrefixView == null ? dpToPx(13f) : dpToPx(8f));
    textView.setLayoutParams(llTextParams);
    textView.setTextSize(16);
    textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
    int linkTextColor = ContextCompat.getColor(view.getContext(), light ? R.color.ctx_menu_bottom_view_url_color_light : R.color.ctx_menu_bottom_view_url_color_dark);
    if (isPhoneNumber || isUrl) {
        textView.setTextColor(linkTextColor);
        needLinks = false;
    }
    textView.setText(txt);
    if (needLinks) {
        Linkify.addLinks(textView, Linkify.ALL);
        textView.setLinksClickable(true);
        textView.setLinkTextColor(linkTextColor);
        AndroidUtils.removeLinkUnderline(textView);
    }
    textView.setEllipsize(TextUtils.TruncateAt.END);
    if (textLinesLimit > 0) {
        textView.setMinLines(1);
        textView.setMaxLines(textLinesLimit);
    } else if (isWiki) {
        textView.setMinLines(1);
        textView.setMaxLines(15);
    } else if (isText) {
        textView.setMinLines(1);
        textView.setMaxLines(10);
    }
    if (textColor > 0) {
        textView.setTextColor(view.getResources().getColor(textColor));
    }
    LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextViewParams.weight = 1f;
    llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
    llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
    llText.setLayoutParams(llTextViewParams);
    if (textPrefixView != null) {
        llText.addView(textPrefixView);
    }
    llText.addView(textView);
    final ImageView iconViewCollapse = new ImageView(view.getContext());
    if (collapsable && collapsableView != null) {
        // Icon
        LinearLayout llIconCollapse = new LinearLayout(view.getContext());
        llIconCollapse.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(40f), ViewGroup.LayoutParams.MATCH_PARENT));
        llIconCollapse.setOrientation(LinearLayout.HORIZONTAL);
        llIconCollapse.setGravity(Gravity.CENTER_VERTICAL);
        ll.addView(llIconCollapse);
        LinearLayout.LayoutParams llIconCollapseParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
        llIconCollapseParams.setMargins(0, dpToPx(12f), dpToPx(24f), dpToPx(12f));
        llIconCollapseParams.gravity = Gravity.CENTER_VERTICAL;
        iconViewCollapse.setLayoutParams(llIconCollapseParams);
        iconViewCollapse.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        iconViewCollapse.setImageDrawable(getCollapseIcon(collapsableView.getContenView().getVisibility() == View.GONE));
        llIconCollapse.addView(iconViewCollapse);
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (collapsableView.getContenView().getVisibility() == View.VISIBLE) {
                    collapsableView.getContenView().setVisibility(View.GONE);
                    iconViewCollapse.setImageDrawable(getCollapseIcon(true));
                    collapsableView.setCollapsed(true);
                } else {
                    collapsableView.getContenView().setVisibility(View.VISIBLE);
                    iconViewCollapse.setImageDrawable(getCollapseIcon(false));
                    collapsableView.setCollapsed(false);
                }
            }
        });
        if (collapsableView.isCollapsed()) {
            collapsableView.getContenView().setVisibility(View.GONE);
            iconViewCollapse.setImageDrawable(getCollapseIcon(true));
        }
        baseView.addView(collapsableView.getContenView());
    }
    if (isWiki) {
        TextViewEx button = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme));
        LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPx(36f));
        llWikiButtonParams.setMargins(dpToPx(16f), 0, 0, dpToPx(16f));
        button.setLayoutParams(llWikiButtonParams);
        button.setTypeface(FontCache.getRobotoMedium(app));
        button.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark);
        button.setTextSize(14);
        int paddingSides = dpToPx(10f);
        button.setPadding(paddingSides, 0, paddingSides, 0);
        ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(view.getContext(), !light, R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
        button.setTextColor(buttonColorStateList);
        button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        button.setSingleLine(true);
        button.setEllipsize(TextUtils.TruncateAt.END);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                WikipediaDialogFragment.showInstance(mapActivity, amenity);
            }
        });
        button.setAllCaps(true);
        button.setText(R.string.context_menu_read_full_article);
        Drawable normal = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n);
        Drawable pressed = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p);
        button.setCompoundDrawablesWithIntrinsicBounds(Build.VERSION.SDK_INT >= 21 ? AndroidUtils.createStateListDrawable(normal, pressed) : normal, null, null, null);
        button.setCompoundDrawablePadding(dpToPx(8f));
        llText.addView(button);
    }
    ((LinearLayout) view).addView(baseView);
    if (isPhoneNumber) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View v) {
                final String[] phones = text.split(",|;");
                if (phones.length > 1) {
                    AlertDialog.Builder dlg = new AlertDialog.Builder(v.getContext());
                    dlg.setNegativeButton(R.string.shared_string_cancel, null);
                    dlg.setItems(phones, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_DIAL);
                            intent.setData(Uri.parse("tel:" + phones[which]));
                            v.getContext().startActivity(intent);
                        }
                    });
                    dlg.show();
                } else {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse("tel:" + text));
                    v.getContext().startActivity(intent);
                }
            }
        });
    } else if (isUrl) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (text.contains(".wikipedia.org/w")) {
                    WikipediaDialogFragment.showFullArticle(v.getContext(), Uri.parse(text), !light);
                } else {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(text));
                    v.getContext().startActivity(intent);
                }
            }
        });
    } else if (isWiki) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                WikipediaDialogFragment.showInstance(mapActivity, amenity);
            }
        });
    } else if (isText && text.length() > 200) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                POIMapLayer.showDescriptionDialog(view.getContext(), app, text, textPrefix);
            }
        });
    }
    rowBuilt();
    setDividerWidth(matchWidthDivider);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MenuBuilder(net.osmand.plus.mapcontextmenu.MenuBuilder) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) TextViewEx(net.osmand.plus.widgets.TextViewEx) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 7 with TextViewEx

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

the class WptPtMenuBuilder method getCollapsableWaypointsView.

private CollapsableView getCollapsableWaypointsView(final Context context, boolean collapsed, @NonNull final GPXUtilities.GPXFile gpxFile, WptPt selectedPoint) {
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    List<WptPt> points = gpxFile.getPoints();
    for (int i = 0; i < points.size() && i < 10; i++) {
        final WptPt point = points.get(i);
        boolean selected = selectedPoint != null && selectedPoint.equals(point);
        TextViewEx button = buildButtonInCollapsableView(context, selected, false);
        button.setText(point.name);
        if (!selected) {
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    LatLon latLon = new LatLon(point.getLatitude(), point.getLongitude());
                    PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, point.name);
                    mapActivity.getContextMenu().show(latLon, pointDescription, point);
                }
            });
        }
        view.addView(button);
    }
    if (points.size() > 10) {
        TextViewEx button = buildButtonInCollapsableView(context, false, true);
        button.setText(context.getString(R.string.shared_string_show_all));
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                OsmAndAppCustomization appCustomization = app.getAppCustomization();
                final Intent intent = new Intent(context, appCustomization.getTrackActivity());
                intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxFile.path);
                intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                context.startActivity(intent);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) Intent(android.content.Intent) View(android.view.View) LatLon(net.osmand.data.LatLon) TextViewEx(net.osmand.plus.widgets.TextViewEx) OsmAndAppCustomization(net.osmand.plus.OsmAndAppCustomization) PointDescription(net.osmand.data.PointDescription) LinearLayout(android.widget.LinearLayout)

Example 8 with TextViewEx

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

the class MenuBuilder method buildButtonInCollapsableView.

protected TextViewEx buildButtonInCollapsableView(Context context, boolean selected, boolean showAll, boolean singleLine) {
    TextViewEx button = new TextViewEx(new ContextThemeWrapper(context, light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme));
    LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llWikiButtonParams.setMargins(0, 0, 0, dpToPx(8f));
    // button.setMinimumHeight(dpToPx(36f));
    button.setLayoutParams(llWikiButtonParams);
    button.setTypeface(FontCache.getRobotoRegular(context));
    int bg;
    if (selected) {
        bg = light ? R.drawable.context_menu_controller_bg_light_selected : R.drawable.context_menu_controller_bg_dark_selected;
    } else if (showAll) {
        bg = light ? R.drawable.context_menu_controller_bg_light_show_all : R.drawable.context_menu_controller_bg_dark_show_all;
    } else {
        bg = light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark;
    }
    button.setBackgroundResource(bg);
    button.setTextSize(14);
    int paddingSides = dpToPx(10f);
    button.setPadding(paddingSides, paddingSides, paddingSides, paddingSides);
    if (!selected) {
        ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(context, !light, R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
        button.setTextColor(buttonColorStateList);
    } else {
        button.setTextColor(ContextCompat.getColor(context, light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
    }
    button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    button.setSingleLine(singleLine);
    button.setEllipsize(TextUtils.TruncateAt.END);
    return button;
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) TextViewEx(net.osmand.plus.widgets.TextViewEx) ColorStateList(android.content.res.ColorStateList) LinearLayout(android.widget.LinearLayout)

Example 9 with TextViewEx

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

the class AmenityMenuBuilder method getPoiAdditionalCollapsableView.

private CollapsableView getPoiAdditionalCollapsableView(final Context context, boolean collapsed, @NonNull final List<PoiType> categoryTypes, AmenityInfoRow textCuisineRow) {
    final List<TextViewEx> buttons = new ArrayList<>();
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    for (final PoiType pt : categoryTypes) {
        TextViewEx button = buildButtonInCollapsableView(context, false, false);
        String name = pt.getTranslation();
        button.setText(name);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (amenity.getType() != null) {
                    PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + amenity.getType().getKeyName());
                    if (filter != null) {
                        filter.clearFilter();
                        filter.setTypeToAccept(amenity.getType(), true);
                        filter.updateTypesToAccept(pt);
                        filter.setFilterByName(pt.getKeyName().replace('_', ':').toLowerCase());
                        getMapActivity().showQuickSearch(filter);
                    }
                }
            }
        });
        buttons.add(button);
        if (buttons.size() > 3 && categoryTypes.size() > 4) {
            button.setVisibility(View.GONE);
        }
        view.addView(button);
    }
    if (textCuisineRow != null) {
        TextViewEx button = buildButtonInCollapsableView(context, true, false, false);
        String name = textCuisineRow.textPrefix + ": " + textCuisineRow.text.toLowerCase();
        button.setText(name);
        view.addView(button);
    }
    if (categoryTypes.size() > 4) {
        final TextViewEx button = buildButtonInCollapsableView(context, false, true);
        button.setText(context.getString(R.string.shared_string_show_all));
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                for (TextViewEx b : buttons) {
                    if (b.getVisibility() != View.VISIBLE) {
                        b.setVisibility(View.VISIBLE);
                    }
                }
                button.setVisibility(View.GONE);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : TextViewEx(net.osmand.plus.widgets.TextViewEx) ArrayList(java.util.ArrayList) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 10 with TextViewEx

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

the class FavouritePointMenuBuilder method getCollapsableFavouritesView.

private CollapsableView getCollapsableFavouritesView(final Context context, boolean collapsed, @NonNull final FavoriteGroup group, FavouritePoint selectedPoint) {
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    List<FavouritePoint> points = group.points;
    for (int i = 0; i < points.size() && i < 10; i++) {
        final FavouritePoint point = points.get(i);
        boolean selected = selectedPoint != null && selectedPoint.equals(point);
        TextViewEx button = buildButtonInCollapsableView(context, selected, false);
        String name = point.getName();
        button.setText(name);
        if (!selected) {
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    LatLon latLon = new LatLon(point.getLatitude(), point.getLongitude());
                    PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName());
                    mapActivity.getContextMenu().show(latLon, pointDescription, point);
                }
            });
        }
        view.addView(button);
    }
    if (points.size() > 10) {
        TextViewEx button = buildButtonInCollapsableView(context, false, true);
        button.setText(context.getString(R.string.shared_string_show_all));
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                OsmAndAppCustomization appCustomization = app.getAppCustomization();
                final Intent intent = new Intent(context, appCustomization.getFavoritesActivity());
                intent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
                intent.putExtra(FavoritesActivity.GROUP_NAME_TO_SHOW, group.name);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                context.startActivity(intent);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) TextViewEx(net.osmand.plus.widgets.TextViewEx) OsmAndAppCustomization(net.osmand.plus.OsmAndAppCustomization) PointDescription(net.osmand.data.PointDescription) LinearLayout(android.widget.LinearLayout)

Aggregations

TextViewEx (net.osmand.plus.widgets.TextViewEx)10 LinearLayout (android.widget.LinearLayout)9 View (android.view.View)7 TextView (android.widget.TextView)7 ImageView (android.widget.ImageView)6 Intent (android.content.Intent)4 LatLon (net.osmand.data.LatLon)3 PointDescription (net.osmand.data.PointDescription)3 ColorStateList (android.content.res.ColorStateList)2 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)2 OnClickListener (android.view.View.OnClickListener)2 ArrayList (java.util.ArrayList)2 OsmAndAppCustomization (net.osmand.plus.OsmAndAppCustomization)2 DialogInterface (android.content.DialogInterface)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 AlertDialog (android.support.v7.app.AlertDialog)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1