Search in sources :

Example 1 with TextViewEx

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

the class MenuBuilder method buildRow.

public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText, boolean collapsable, final CollapsableView collapsableView, boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
    if (!isFirstRow()) {
        buildRowDivider(view);
    }
    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) {
            copyToClipboard(text, 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);
    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);
    ll.addView(llText);
    // Primary text
    TextViewEx textView = new TextViewEx(view.getContext());
    LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(secondaryText != null ? 10f : 8f), 0, dpToPx(secondaryText != null ? 6f : 8f));
    textView.setLayoutParams(llTextParams);
    textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
    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 (isUrl) {
        textView.setTextColor(linkTextColor);
    } else if (needLinks) {
        Linkify.addLinks(textView, Linkify.ALL);
        textView.setLinksClickable(true);
        textView.setLinkTextColor(linkTextColor);
        AndroidUtils.removeLinkUnderline(textView);
    }
    if (textLinesLimit > 0) {
        textView.setMinLines(1);
        textView.setMaxLines(textLinesLimit);
    }
    textView.setText(text);
    if (textColor > 0) {
        textView.setTextColor(view.getResources().getColor(textColor));
    }
    llText.addView(textView);
    // Secondary text
    if (!TextUtils.isEmpty(secondaryText)) {
        TextViewEx textViewSecondary = new TextViewEx(view.getContext());
        LinearLayout.LayoutParams llTextSecondaryParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        llTextSecondaryParams.setMargins(icon != null ? 0 : dpToPx(16f), 0, 0, dpToPx(6f));
        textViewSecondary.setLayoutParams(llTextSecondaryParams);
        textViewSecondary.setTypeface(FontCache.getRobotoRegular(view.getContext()));
        textViewSecondary.setTextSize(14);
        textViewSecondary.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_secondary_text_color_light : R.color.ctx_menu_bottom_view_secondary_text_color_dark));
        textViewSecondary.setText(secondaryText);
        llText.addView(textViewSecondary);
    }
    // Button
    if (!TextUtils.isEmpty(buttonText)) {
        TextViewEx buttonTextView = new TextViewEx(view.getContext());
        LinearLayout.LayoutParams buttonTextViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        buttonTextViewParams.gravity = Gravity.CENTER_VERTICAL;
        buttonTextViewParams.setMargins(dpToPx(8), 0, dpToPx(8), 0);
        buttonTextView.setLayoutParams(buttonTextViewParams);
        buttonTextView.setTypeface(FontCache.getRobotoMedium(view.getContext()));
        buttonTextView.setAllCaps(true);
        buttonTextView.setTextColor(ContextCompat.getColor(view.getContext(), !light ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n));
        buttonTextView.setText(buttonText);
        ll.addView(buttonTextView);
    }
    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), dpToPx(48f)));
        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 (onClickListener != null) {
        ll.setOnClickListener(onClickListener);
    } else if (isUrl) {
        ll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(text));
                v.getContext().startActivity(intent);
            }
        });
    }
    ((LinearLayout) view).addView(baseView);
    rowBuilt();
    setDividerWidth(matchWidthDivider);
    return ll;
}
Also used : TextViewEx(net.osmand.plus.widgets.TextViewEx) OnClickListener(android.view.View.OnClickListener) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 2 with TextViewEx

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

the class MenuBuilder method getCollapsableTextView.

protected CollapsableView getCollapsableTextView(Context context, boolean collapsed, String text) {
    final TextViewEx textView = new TextViewEx(context);
    textView.setVisibility(collapsed ? View.GONE : View.VISIBLE);
    LinearLayout.LayoutParams llTextDescParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextDescParams.setMargins(dpToPx(64f), 0, dpToPx(40f), dpToPx(13f));
    textView.setLayoutParams(llTextDescParams);
    textView.setTypeface(FontCache.getRobotoRegular(context));
    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));
    textView.setText(text);
    return new CollapsableView(textView, this, collapsed);
}
Also used : TextViewEx(net.osmand.plus.widgets.TextViewEx) LinearLayout(android.widget.LinearLayout)

Example 3 with TextViewEx

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

the class MenuBuilder method buildTransportRowItem.

private View buildTransportRowItem(View view, TransportStopRoute route, OnClickListener listener) {
    LinearLayout baseView = new LinearLayout(view.getContext());
    baseView.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    baseView.setLayoutParams(llBaseViewParams);
    baseView.setPadding(dpToPx(16), 0, dpToPx(16), dpToPx(12));
    baseView.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
    TextViewEx transportRect = new TextViewEx(view.getContext());
    LinearLayout.LayoutParams trParams = new LinearLayout.LayoutParams(dpToPx(32), dpToPx(18));
    trParams.setMargins(0, dpToPx(16), 0, 0);
    transportRect.setLayoutParams(trParams);
    transportRect.setGravity(Gravity.CENTER);
    transportRect.setAllCaps(true);
    transportRect.setTypeface(FontCache.getRobotoMedium(view.getContext()));
    transportRect.setTextColor(Color.WHITE);
    transportRect.setTextSize(10);
    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    shape.setCornerRadius(dpToPx(3));
    shape.setColor(route.getColor(mapActivity.getMyApplication(), !light));
    transportRect.setBackgroundDrawable(shape);
    transportRect.setText(route.route.getRef());
    baseView.addView(transportRect);
    LinearLayout infoView = new LinearLayout(view.getContext());
    infoView.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams infoViewLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    infoViewLayoutParams.setMargins(dpToPx(16), dpToPx(12), dpToPx(16), 0);
    infoView.setLayoutParams(infoViewLayoutParams);
    baseView.addView(infoView);
    TextView titleView = new TextView(view.getContext());
    LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    titleView.setLayoutParams(titleParams);
    titleView.setTextSize(16);
    titleView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
    titleView.setText(route.getDescription(getMapActivity().getMyApplication(), true));
    infoView.addView(titleView);
    LinearLayout typeView = new LinearLayout(view.getContext());
    typeView.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams typeViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    typeViewParams.setMargins(0, dpToPx(8), 0, 0);
    typeView.setGravity(Gravity.CENTER);
    typeView.setLayoutParams(typeViewParams);
    infoView.addView(typeView);
    ImageView typeImageView = new ImageView(view.getContext());
    LinearLayout.LayoutParams typeImageParams = new LinearLayout.LayoutParams(dpToPx(16), dpToPx(16));
    typeImageParams.setMargins(dpToPx(4), 0, dpToPx(4), 0);
    typeImageView.setLayoutParams(typeImageParams);
    int drawableResId = route.type == null ? R.drawable.ic_action_polygom_dark : route.type.getResourceId();
    typeImageView.setImageDrawable(getRowIcon(drawableResId));
    typeView.addView(typeImageView);
    TextView typeTextView = new TextView(view.getContext());
    LinearLayout.LayoutParams typeTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    typeTextView.setLayoutParams(typeTextParams);
    typeTextView.setText(route.getTypeStrRes());
    AndroidUtils.setTextSecondaryColor(getMapActivity(), typeTextView, getApplication().getDaynightHelper().isNightModeForMapControls());
    typeView.addView(typeTextView);
    baseView.setOnClickListener(listener);
    ((ViewGroup) view).addView(baseView);
    return baseView;
}
Also used : TextViewEx(net.osmand.plus.widgets.TextViewEx) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 4 with TextViewEx

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

the class MenuBuilder method getCollapsableWikiView.

protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    for (final Amenity wiki : nearestWiki) {
        TextViewEx button = buildButtonInCollapsableView(context, false, false);
        String name = wiki.getName(preferredMapAppLang, transliterateNames);
        button.setText(name);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                LatLon latLon = new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude());
                PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(wiki);
                mapActivity.getContextMenu().show(latLon, pointDescription, wiki);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) TextViewEx(net.osmand.plus.widgets.TextViewEx) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 5 with TextViewEx

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

the class WaypointDialogHelper method createItemForCategory.

protected View createItemForCategory(final FragmentActivity ctx, final int type, final int[] running, final int position, final ArrayAdapter<Object> thisAdapter, boolean nightMode, final WaypointDialogHelper helper) {
    View v;
    v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
    final CompoundButton btn = (CompoundButton) v.findViewById(R.id.toggle_item);
    btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE);
    btn.setOnCheckedChangeListener(null);
    final boolean checked = waypointHelper.isTypeEnabled(type);
    btn.setChecked(checked);
    btn.setEnabled(running[0] == -1);
    v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
    btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            running[0] = position;
            thisAdapter.notifyDataSetInvalidated();
            if (type == WaypointHelper.POI && isChecked) {
                selectPoi(running, thisAdapter, type, isChecked, ctx);
            } else {
                enableType(running, thisAdapter, type, isChecked);
            }
        }
    });
    final TextViewEx optionsButton = (TextViewEx) v.findViewById(R.id.text_button);
    if (type == WaypointHelper.TARGETS) {
        optionsButton.setVisibility(View.VISIBLE);
        optionsButton.setTextColor(ContextCompat.getColor(ctx, nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light));
        optionsButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean hasActivePoints = false;
                if (thisAdapter instanceof StableArrayAdapter) {
                    List<Object> items = ((StableArrayAdapter) thisAdapter).getActiveObjects();
                    if (items.size() > 0) {
                        if (items.size() > 1) {
                            hasActivePoints = true;
                        } else {
                            Object item = items.get(0);
                            if (item instanceof LocationPointWrapper) {
                                LocationPointWrapper w = (LocationPointWrapper) item;
                                if (w.getPoint() instanceof TargetPoint) {
                                    hasActivePoints = !((TargetPoint) w.point).start;
                                }
                            } else {
                                hasActivePoints = true;
                            }
                        }
                    }
                }
                if (hasActivePoints) {
                    TargetOptionsBottomSheetDialogFragment fragment = new TargetOptionsBottomSheetDialogFragment();
                    fragment.setUsedOnMap(true);
                    fragment.show(ctx.getSupportFragmentManager(), TargetOptionsBottomSheetDialogFragment.TAG);
                }
            }
        });
    } else {
        optionsButton.setVisibility(View.GONE);
    }
    TextView tv = (TextView) v.findViewById(R.id.header_text);
    AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
    tv.setText(getHeader(type, checked, ctx));
    return v;
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TextViewEx(net.osmand.plus.widgets.TextViewEx) List(java.util.List) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

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