Example usage for android.widget TextView setLines

List of usage examples for android.widget TextView setLines

Introduction

In this page you can find the example usage for android.widget TextView setLines.

Prototype

@android.view.RemotableViewMethod
public void setLines(int lines) 

Source Link

Document

Sets the height of the TextView to be exactly lines tall.

Usage

From source file:Main.java

public static int fitLineCount(TextView view, String szText, int nWidth) {
    int nCharCount = view.getPaint().breakText(szText, 0, szText.length(), true, nWidth, null);
    int nLineCount = szText.length() / nCharCount;
    if (szText.length() > nCharCount * nLineCount)
        nLineCount++;//  w w  w .  ja v a 2s  .c o m
    view.setLines(nLineCount);
    return nLineCount;
}

From source file:com.shipfindpeople.app.widget.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from   w w w  . j  a  va  2s. c  o m*/
 */

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setLines(1);
    //textView.setAllCaps(true);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        textView.setTextColor(
                getResources().getColorStateList(R.color.sliding_tab_title_selector, context.getTheme()));
    } else {

        textView.setTextColor(getResources().getColorStateList(R.color.sliding_tab_title_selector));
    }
    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:fr.cph.chicago.core.activity.StationActivity.java

/**
 * Draw line/*from  ww  w .  ja va2 s.  c o m*/
 *
 * @param eta the eta
 */
public void drawAllArrivalsTrain(@NonNull final Eta eta) {
    final TrainLine line = eta.getRouteName();
    final Stop stop = eta.getStop();
    final String key = line.toString() + "_" + stop.getDirection().toString();
    // viewId might be not there if CTA API provide wrong data
    if (ids.containsKey(key)) {
        final int viewId = ids.get(key);
        final LinearLayout line3View = (LinearLayout) findViewById(viewId);
        final Integer id = ids
                .get(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName());
        if (id == null) {
            final LinearLayout insideLayout = new LinearLayout(this);
            insideLayout.setOrientation(LinearLayout.HORIZONTAL);
            insideLayout.setLayoutParams(paramsStop);
            final int newId = Util.generateViewId();
            insideLayout.setId(newId);
            ids.put(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(), newId);

            final TextView stopName = new TextView(this);
            final String stopNameData = eta.getDestName() + ": ";
            stopName.setText(stopNameData);
            stopName.setTextColor(grey);
            stopName.setPadding(line3PaddingLeft, line3PaddingTop, 0, 0);
            insideLayout.addView(stopName);

            final TextView timing = new TextView(this);
            final String timingData = eta.getTimeLeftDueDelay() + " ";
            timing.setText(timingData);
            timing.setTextColor(grey);
            timing.setLines(1);
            timing.setEllipsize(TruncateAt.END);
            insideLayout.addView(timing);

            line3View.addView(insideLayout);
        } else {
            final LinearLayout insideLayout = (LinearLayout) findViewById(id);
            final TextView timing = (TextView) insideLayout.getChildAt(1);
            final String timingData = timing.getText() + eta.getTimeLeftDueDelay() + " ";
            timing.setText(timingData);
        }
        line3View.setVisibility(View.VISIBLE);
    }
}

From source file:com.landenlabs.all_devtool.ConsoleFragment.java

private TextView addTextView(RelativeLayout relLayout, int belowId, int rightId, int widthDp, int heightDp,
        int padLeft) {
    float scale = Resources.getSystem().getDisplayMetrics().density;

    int widthParam = (widthDp != 0) ? dpToPx(widthDp) : RelativeLayout.LayoutParams.WRAP_CONTENT;
    int heightParam = (heightDp != 0) ? dpToPx(heightDp) : RelativeLayout.LayoutParams.WRAP_CONTENT;
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(widthParam, heightParam);

    // params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    if (belowId != 0)
        params.addRule(RelativeLayout.BELOW, belowId);
    if (rightId != 0) {
        if (rightId > 0)
            params.addRule(RelativeLayout.ALIGN_RIGHT, rightId);
        else/*from   w ww .j a va 2s  .co  m*/
            params.addRule(RelativeLayout.RIGHT_OF, -rightId);
    }

    // relLayout.setPadding(padLeft,  0,  0,  0);
    params.setMargins(padLeft, 0, 0, 0);

    TextView textView = new TextView(relLayout.getContext());
    textView.setLines(1);
    if (widthDp > 0)
        textView.setMaxWidth(dpToPx(widthDp));

    if (Build.VERSION.SDK_INT >= 17) {
        textView.setId(View.generateViewId());
    } else {
        textView.setId(sNextId++);
    }

    relLayout.addView(textView, params);
    return textView;
}

From source file:eu.pellerito.popularmoviesproject2.fragment.DetailFragment.java

private void viewTrailer(@NonNull List<MovieTrailer> trailer) {

    if ((mContext != null) && (trailerArrayList != null)) {

        LayoutInflater layoutInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        final String[] strKey = new String[1];

        for (int i = 0; i < trailer.size(); i++) {

            strKey[0] = trailer.get(i).getKey();

            View view = layoutInflater.inflate(R.layout.layout_trailer, layoutWrapper, false);

            LinearLayout linearLayoutWrapper = ButterKnife.findById(view, R.id.trailer_wrapper);

            LinearLayout.LayoutParams layoutParamsImage = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

            layoutParamsImage.setMargins(8, 8, 8, 8);

            if (trailerTitle != null) {
                separatorTrailer.setVisibility(View.VISIBLE);
                trailerTitle.setVisibility(View.VISIBLE);
            }//w w  w .j a v a2s .c o  m

            final ImageView image = new ImageView(mContext);
            image.setTag(trailer.get(i).getName());
            image.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.youtube));

            image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    playTrailer(strKey[0]);
                }
            });

            LinearLayout.LayoutParams layoutParamsTextView = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

            layoutParamsTextView.setMargins(8, 8, 8, 8);

            TextView textView = new TextView(mContext);
            textView.setText(trailer.get(i).getName());
            textView.setGravity(Gravity.CENTER_VERTICAL);
            textView.setLines(2);

            linearLayoutWrapper.addView(image, layoutParamsImage);
            linearLayoutWrapper.addView(textView, layoutParamsTextView);

            if (layoutBaseTrailer != null) {
                layoutBaseTrailer.addView(linearLayoutWrapper);
            }

        }
    }
}

From source file:fr.cph.chicago.activity.StationActivity.java

/**
 * Draw line/*from   w w  w .j ava  2 s  .c o  m*/
 * 
 * @param eta
 *            the eta
 */
private final void drawLine3(final Eta eta) {
    TrainLine line = eta.getRouteName();
    Stop stop = eta.getStop();
    int line3Padding = (int) getResources().getDimension(R.dimen.activity_station_stops_line3);
    Integer viewId = mIds.get(line.toString() + "_" + stop.getDirection().toString());
    // viewId might be not there if CTA API provide wrong data
    if (viewId != null) {
        LinearLayout line3View = (LinearLayout) findViewById(viewId);
        Integer id = mIds.get(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName());
        if (id == null) {
            LinearLayout insideLayout = new LinearLayout(this);
            insideLayout.setOrientation(LinearLayout.HORIZONTAL);
            insideLayout.setLayoutParams(mParamsStop);
            int newId = Util.generateViewId();
            insideLayout.setId(newId);
            mIds.put(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(), newId);

            TextView stopName = new TextView(this);
            stopName.setText(eta.getDestName() + ": ");
            stopName.setTextColor(getResources().getColor(R.color.grey));
            stopName.setPadding(line3Padding, 0, 0, 0);
            insideLayout.addView(stopName);

            TextView timing = new TextView(this);
            timing.setText(eta.getTimeLeftDueDelay() + " ");
            timing.setTextColor(getResources().getColor(R.color.grey));
            timing.setLines(1);
            timing.setEllipsize(TruncateAt.END);
            insideLayout.addView(timing);

            line3View.addView(insideLayout);
        } else {
            LinearLayout insideLayout = (LinearLayout) findViewById(id);
            TextView timing = (TextView) insideLayout.getChildAt(1);
            timing.setText(timing.getText() + eta.getTimeLeftDueDelay() + " ");
        }
        line3View.setVisibility(View.VISIBLE);
    }
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBuses(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    // Bus/*w w w. j a  va  2 s  . c  om*/
    final int index = position - stations.size();
    final BusStop busStop = busStops.get(index);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bus_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(busStop.getName());

    final LinearLayout resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final Map<String, List<BusArrival>> arrivalsForStop = busArrivals.get(busStop.getId(), new HashMap<>());

    Stream.of(arrivalsForStop.entrySet()).forEach(entry -> {
        final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        final RelativeLayout insideLayout = new RelativeLayout(context);
        insideLayout.setLayoutParams(leftParam);
        insideLayout.setPadding(line1PaddingColor * 2, stopsPaddingTop, 0, 0);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            insideLayout.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.any_selector));
        }

        final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
        int lineId = Util.generateViewId();
        lineIndication.setId(lineId);

        final RelativeLayout.LayoutParams stopParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        stopParam.addRule(RelativeLayout.RIGHT_OF, lineId);
        stopParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

        final LinearLayout stopLayout = new LinearLayout(context);
        stopLayout.setOrientation(LinearLayout.VERTICAL);
        stopLayout.setLayoutParams(stopParam);
        int stopId = Util.generateViewId();
        stopLayout.setId(stopId);

        final RelativeLayout.LayoutParams boundParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        boundParam.addRule(RelativeLayout.RIGHT_OF, stopId);

        final LinearLayout boundLayout = new LinearLayout(context);
        boundLayout.setOrientation(LinearLayout.HORIZONTAL);

        final String direction = entry.getKey();
        final List<BusArrival> busArrivals = entry.getValue();
        final String routeId = busArrivals.get(0).getRouteId();

        final TextView bound = new TextView(context);
        final String routeIdText = routeId + " (" + direction + "): ";
        bound.setText(routeIdText);
        bound.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
        boundLayout.addView(bound);

        Stream.of(busArrivals).forEach(busArrival -> {
            final TextView timeView = new TextView(context);
            final String timeLeftDueDelay = busArrival.getTimeLeftDueDelay() + " ";
            timeView.setText(timeLeftDueDelay);
            timeView.setTextColor(ContextCompat.getColor(context, R.color.grey));
            timeView.setLines(1);
            timeView.setEllipsize(TruncateAt.END);
            boundLayout.addView(timeView);
        });

        stopLayout.addView(boundLayout);

        insideLayout.addView(lineIndication);
        insideLayout.addView(stopLayout);
        resultLayout.addView(insideLayout);
    });

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, busStop.getId(),
            busStop.getPosition().getLatitude(), busStop.getPosition().getLongitude()));
    return convertView;
}

From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java

private void handleStation(@NonNull final FavoritesViewHolder holder, @NonNull final Station station) {
    final int stationId = station.getId();
    final Set<TrainLine> trainLines = station.getLines();

    holder.favoriteImage.setImageResource(R.drawable.ic_train_white_24dp);
    holder.stationNameTextView.setText(station.getName());
    holder.detailsButton.setOnClickListener(v -> {
        if (!Util.isNetworkAvailable(context)) {
            Util.showNetworkErrorMessage(activity);
        } else {/*from   ww w  .j  a v  a 2s.com*/
            // Start station activity
            final Bundle extras = new Bundle();
            final Intent intent = new Intent(context, StationActivity.class);
            extras.putInt(activity.getString(R.string.bundle_train_stationId), stationId);
            intent.putExtras(extras);
            activity.startActivity(intent);
        }
    });

    holder.mapButton.setText(activity.getString(R.string.favorites_view_trains));
    holder.mapButton.setOnClickListener(v -> {
        if (!Util.isNetworkAvailable(context)) {
            Util.showNetworkErrorMessage(activity);
        } else {
            if (trainLines.size() == 1) {
                startActivity(trainLines.iterator().next());
            } else {
                final List<Integer> colors = new ArrayList<>();
                final List<String> values = Stream.of(trainLines).flatMap(line -> {
                    final int color = line != TrainLine.YELLOW ? line.getColor()
                            : ContextCompat.getColor(context, R.color.yellowLine);
                    colors.add(color);
                    return Stream.of(line.toStringWithLine());
                }).collect(Collectors.toList());

                final PopupFavoritesTrainAdapter ada = new PopupFavoritesTrainAdapter(activity, values, colors);

                final List<TrainLine> lines = new ArrayList<>();
                lines.addAll(trainLines);

                final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setAdapter(ada, (dialog, position) -> startActivity(lines.get(position)));

                final int[] screenSize = Util.getScreenSize(context);
                final AlertDialog dialog = builder.create();
                dialog.show();
                if (dialog.getWindow() != null) {
                    dialog.getWindow().setLayout((int) (screenSize[0] * 0.7), LayoutParams.WRAP_CONTENT);
                }
            }
        }
    });

    Stream.of(trainLines).forEach(trainLine -> {
        boolean newLine = true;
        int i = 0;
        final Map<String, StringBuilder> etas = favoritesData.getTrainArrivalByLine(stationId, trainLine);
        for (final Entry<String, StringBuilder> entry : etas.entrySet()) {
            final LinearLayout.LayoutParams containParam = getInsideParams(newLine, i == etas.size() - 1);
            final LinearLayout container = new LinearLayout(context);
            container.setOrientation(LinearLayout.HORIZONTAL);
            container.setLayoutParams(containParam);

            // Left
            final RelativeLayout.LayoutParams leftParam = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            final RelativeLayout left = new RelativeLayout(context);
            left.setLayoutParams(leftParam);

            final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine);
            int lineId = Util.generateViewId();
            lineIndication.setId(lineId);

            final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId);
            destinationParams.setMargins(pixelsHalf, 0, 0, 0);

            final String destination = entry.getKey();
            final TextView destinationTextView = new TextView(context);
            destinationTextView.setTextColor(grey5);
            destinationTextView.setText(destination);
            destinationTextView.setLines(1);
            destinationTextView.setLayoutParams(destinationParams);

            left.addView(lineIndication);
            left.addView(destinationTextView);

            // Right
            final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            rightParams.setMargins(marginLeftPixel, 0, 0, 0);
            final LinearLayout right = new LinearLayout(context);
            right.setOrientation(LinearLayout.VERTICAL);
            right.setLayoutParams(rightParams);

            final StringBuilder currentEtas = entry.getValue();
            final TextView arrivalText = new TextView(context);
            arrivalText.setText(currentEtas);
            arrivalText.setGravity(Gravity.END);
            arrivalText.setSingleLine(true);
            arrivalText.setTextColor(grey5);
            arrivalText.setEllipsize(TextUtils.TruncateAt.END);

            right.addView(arrivalText);

            container.addView(left);
            container.addView(right);

            holder.mainLayout.addView(container);

            newLine = false;
            i++;
        }
    });
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Window window = getWindow();/*from  w  w w  .j  a  v  a  2  s.c  om*/
    window.setWindowAnimations(R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        containerView.setBackgroundDrawable(shadowDrawable);
        containerView.setPadding(backgroundPaddingLeft,
                (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop, backgroundPaddingLeft,
                (applyBottomPadding ? AndroidUtilities.dp(8) : 0));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }
    containerView.setVisibility(View.INVISIBLE);
    container.addView(containerView, 0,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }
        containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
    } else {
        int topOffset = 0;
        if (title != null) {
            TextView titleView = new TextView(getContext());
            titleView.setLines(1);
            titleView.setSingleLine(true);
            titleView.setText(title);
            titleView.setTextColor(0xff757575);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
            titleView.setGravity(Gravity.CENTER_VERTICAL);
            containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48));
            titleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 48;
        }
        if (items != null) {
            FrameLayout rowLayout = null;
            int lastRowLayoutNum = 0;
            for (int a = 0; a < items.length; a++) {
                BottomSheetCell cell = new BottomSheetCell(getContext(), 0);
                cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
                containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48,
                        Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
                topOffset += 48;
                cell.setTag(a);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismissWithButtonClick((Integer) v.getTag());
                    }
                });
                itemViews.add(cell);
            }
        }
    }

    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.dimAmount = 0;
    params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params);
}

From source file:kr.wdream.ui.ActionBar.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Window window = getWindow();//from  www.java 2s . c  o m
    window.setWindowAnimations(kr.wdream.storyshop.R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        containerView.setBackgroundDrawable(shadowDrawable);
        containerView.setPadding(backgroundPaddingLeft,
                (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop, backgroundPaddingLeft,
                (applyBottomPadding ? AndroidUtilities.dp(8) : 0));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }
    containerView.setVisibility(View.INVISIBLE);
    container.addView(containerView, 0,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }
        containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
    } else {
        int topOffset = 0;
        if (title != null) {
            TextView titleView = new TextView(getContext());
            titleView.setLines(1);
            titleView.setSingleLine(true);
            titleView.setText(title);
            titleView.setTextColor(0xff757575);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
            titleView.setGravity(Gravity.CENTER_VERTICAL);
            containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48));
            titleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 48;
        }
        if (items != null) {
            FrameLayout rowLayout = null;
            int lastRowLayoutNum = 0;
            for (int a = 0; a < items.length; a++) {
                BottomSheetCell cell = new BottomSheetCell(getContext(), 0);
                cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
                containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48,
                        Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
                topOffset += 48;
                cell.setTag(a);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismissWithButtonClick((Integer) v.getTag());
                    }
                });
                itemViews.add(cell);
            }
        }
    }

    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.dimAmount = 0;
    params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params);
}