Example usage for android.widget TextView setMaxLines

List of usage examples for android.widget TextView setMaxLines

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setMaxLines(int maxLines) 

Source Link

Document

Sets the height of the TextView to be at most maxLines tall.

Usage

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

private static void setMaxLines(TextView view, int maxLines) {
    // setSingleLine must be called before setMaxLines because it resets maximum to
    // Integer.MAX_VALUE.
    if (maxLines == 1) {
        view.setSingleLine(true);/*from   w w  w . j av  a  2  s  . c  o m*/
    } else {
        view.setSingleLine(false);
        view.setMaxLines(maxLines);
    }
}

From source file:me.albinmathew.celluloid.ui.fragments.MovieDetailFragment.java

@Override
public void onClick(@NonNull View view) {
    {/*w w  w .j  ava  2  s. co  m*/
        switch (view.getId()) {
        case R.id.video_thumb:
            String videoUrl = (String) view.getTag();
            Intent playVideoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(videoUrl));
            startActivity(playVideoIntent);
            break;

        case R.id.review_content:
            TextView review = (TextView) view;
            if (review.getMaxLines() == 5) {
                review.setMaxLines(500);
            } else {
                review.setMaxLines(5);
            }
            break;
        case R.id.fab:
            setFavourites();
        default:
            break;
        }
    }
}

From source file:key.secretkey.SettingsActivity.java

/**
 * Opens a file explorer to import the private key
 *//*from  w  w w  . ja v a 2 s. c o m*/
//    public void getSshKey() {
//        // This always works
//        Intent i = new Intent(getApplicationContext(), FilePickerActivity.class);
//        // This works if you defined the intent filter
//        // Intent i = new Intent(Intent.ACTION_GET_CONTENT);
//
//        // Set these depending on your use case. These are the defaults.
//        i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
//        i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
//        i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
//
//        i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
//
//        startActivityForResult(i, IMPORT_SSH_KEY);
//    }

public void exportPasswordsWithPermissions() {
    final Activity activity = this;
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            Snackbar snack = Snackbar
                    .make(prefsFragment.getView(), "We need access to the sd-card to export the passwords",
                            Snackbar.LENGTH_INDEFINITE)
                    .setAction(R.string.dialog_ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ActivityCompat.requestPermissions(activity,
                                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                    REQUEST_EXTERNAL_STORAGE);
                        }
                    });
            snack.show();
            View view = snack.getView();
            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(Color.WHITE);
            tv.setMaxLines(10);
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(activity,
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_EXTERNAL_STORAGE);
        }
    } else {
        Intent i = new Intent(getApplicationContext(), FilePickerActivity.class);

        // Set these depending on your use case. These are the defaults.
        i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
        i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
        i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);

        i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());

        startActivityForResult(i, EXPORT_PASSWORDS);
    }
}

From source file:fm.krui.kruifm.ScheduleFragment.java

/**
 * Adds a show to the schedule./*from   w ww  .  j a  va  2  s  .co m*/
 * @param title Title of show to display
 * @param description Description of show to display
 * @param startTime Start time of show in minutes from midnight
 * @param endTime End time of show in minutes from midnight
 * @param category Format of this show, required to correctly color the event.
 *
 * Valid settings for category include:
 *                 1 - Regular Rotation
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Specials
 */
private void addShow(String title, String description, int startTime, int endTime, int category) {

    /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent
    the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference
    between the start and end times. */

    // Fix for corner case of shows ending at midnight.
    if (endTime == 0) {
        endTime = 1440;
    }
    int difference = endTime - startTime;

    /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width.
    Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the
    difference (in minutes) between midnight and the start of the show. */

    Log.v(TAG, "Configuring " + title);
    //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime);
    //Log.v(TAG, "Setting parameters for " + title);
    RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference));
    rrLayoutParams.leftMargin = dpToPixels(55);
    //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin);
    rrLayoutParams.topMargin = dpToPixels(startTime);
    //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin);
    rrLayoutParams.rightMargin = dpToPixels(5);
    //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin);

    /* Build LinearLayout and apply parameters */
    LinearLayout eventLL = new LinearLayout(getActivity());
    eventLL.setOrientation(LinearLayout.VERTICAL);
    eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5));

    // Get background for this event
    eventLL.setBackgroundResource(getEventBackground(category));

    /* Add title of event to LinearLayout */
    TextView titleTV = new TextView(getActivity());

    // Title of a show should be bolded
    titleTV.setText(title);
    titleTV.setTypeface(null, Typeface.BOLD);
    titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0);
    eventLL.addView(titleTV);

    /* Determine length of event to see if we have room to attach a description (if one was passed) */
    int length = endTime - startTime;

    /* Attach a description with a size that depends on the event length (longer events can hold more description text). */
    if (description != null) {
        TextView descriptionTV = new TextView(getActivity());
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        descriptionTV.setText(description);

        // ~hour long shows can display 1 line of description
        if (difference >= 30 && difference <= 60) {
            descriptionTV.setMaxLines(1);
        }

        // 1:30 long shows can display 2 lines of description
        else if (difference >= 60 && difference <= 90) {
            descriptionTV.setMaxLines(2);
        }

        // 2:00 long shows can display 4 lines of description
        else if (difference >= 120) {
            descriptionTV.setMaxLines(4);
        }

        descriptionTV.setEllipsize(TextUtils.TruncateAt.END);
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        eventLL.addView(descriptionTV);
    }

    /* Add this view to the schedule UI */
    RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout);
    rl.addView(eventLL, rrLayoutParams);
}

From source file:com.mycompany.popularmovies.DetailActivity.DetailFragment.java

@Override
public void onClick(View v) {
    if (v.getId() == R.id.favorite) {
        Uri uri = MovieContract.MovieTable.CONTENT_URI;
        ContentResolver resolver = mActivity.getContentResolver();
        Cursor favoriteStatusCursor = resolver.query(uri,
                new String[] { MovieContract.MovieTable.COLUMN_FAVORITED },
                MovieContract.MovieTable._ID + "== ?", new String[] { Integer.toString(mMovieId) }, null);
        if (favoriteStatusCursor != null && favoriteStatusCursor.moveToFirst()) {
            Integer favoriteStatus = favoriteStatusCursor
                    .getInt(favoriteStatusCursor.getColumnIndex(MovieContract.MovieTable.COLUMN_FAVORITED));
            Integer flippedFavoriteStatus = favoriteStatus == 0 ? 1 : 0;
            ContentValues updateFavoriteStatusValues = new ContentValues();
            updateFavoriteStatusValues.put(MovieContract.MovieTable.COLUMN_FAVORITED, flippedFavoriteStatus);
            resolver.update(uri, updateFavoriteStatusValues, MovieContract.MovieTable._ID + " == ?",
                    new String[] { Integer.toString(mMovieId) });
            favoriteStatusCursor.close();
        }//from  w  ww . ja  va  2s.c om
    } else if (v.getId() == R.id.trailer_thumbnail) {
        String link = (String) v.getTag();
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
    } else if (v.getId() == R.id.review) {
        final RelativeLayout reviewItem = (RelativeLayout) v;
        final TextView author = (TextView) v.findViewById(R.id.author_full_name);
        final TextView review = (TextView) v.findViewById(R.id.review_text);

        if (reviewItem.getTag() == DetailFragment.TAG_REVIEW_COLLAPSED) {
            author.setVisibility(View.VISIBLE);
            review.setMaxLines(Integer.MAX_VALUE);
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    int excess = mReviewList.getTop() + reviewItem.getBottom()
                            - (mScrollView.getScrollY() + mScrollView.getHeight());
                    if (excess > 0) {
                        if (reviewItem.getHeight() <= mScrollView.getHeight()) {
                            mScrollView.smoothScrollBy(0, excess);
                        } else {
                            mScrollView.smoothScrollTo(0, mReviewList.getTop() + reviewItem.getTop());
                        }
                    }
                }
            });
            reviewItem.setTag(DetailFragment.TAG_REVIEW_EXPANDED);
        } else {
            author.setVisibility(View.GONE);
            review.setMaxLines(REVIEW_MAXLINES);
            reviewItem.setTag(DetailFragment.TAG_REVIEW_COLLAPSED);
        }
    }
}

From source file:org.comixwall.pffw.InfoRules.java

@Override
public void onItemClick(View view) {

    TextView tvRule = view.findViewById(R.id.rule);
    TextView tvEvalsStates = view.findViewById(R.id.evalsStates);

    int lines = 10;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (tvRule.getMaxLines() != 1) {
            lines = 1;/*  ww w  .  jav  a  2 s.  co  m*/
        }
    }

    tvRule.setMaxLines(lines);
    tvEvalsStates.setMaxLines(lines);
}

From source file:org.comixwall.pffw.Notifications.java

@Override
public void onItemClick(View view) {

    TextView tvTitle = view.findViewById(R.id.title);
    TextView tvBody = view.findViewById(R.id.body);

    int lines = 10;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (tvTitle.getMaxLines() != 1) {
            lines = 1;/*from   www  . ja  va 2  s  .c o m*/
        }
    }

    tvTitle.setMaxLines(lines);
    tvBody.setMaxLines(lines);

    List<NotificationDetail> details = new ArrayList<>();

    // Position == view id
    Notification notification = mNotificationsList.get(view.getId());
    try {
        JSONObject jsonArray = new JSONObject(notification.data);

        for (String p : priorities) {
            Iterator<String> modules = jsonArray.keys();
            while (modules.hasNext()) {
                String module = modules.next();
                Iterator<String> prios = jsonArray.getJSONObject(module).keys();
                while (prios.hasNext()) {
                    String prio = prios.next();
                    if (prio.contains(p)) {
                        JSONArray logs = jsonArray.getJSONObject(module).getJSONArray(prio);
                        // There is only one sample log record, at index 0
                        details.add(NotificationDetail.newInstance(module, logs.getJSONObject(0)));
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.warning("onItemClick exception= " + e.toString());
    }

    NotificationDetails.setNotificationDetails(details);

    // TODO: Code reuse, unite with MainActivity onNavigationItemSelected()
    fragment = new NotificationDetails();

    Bundle args = new Bundle();
    args.putString("title", notification.title);
    args.putString("body", notification.body);
    args.putString("datetime", notification.datetime);

    fragment.setArguments(args);

    FragmentManager fm = getActivity().getSupportFragmentManager();
    android.support.v4.app.FragmentTransaction transaction = fm.beginTransaction();
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    String fragmentName = fragment.getClass().getSimpleName();
    transaction.addToBackStack(fragmentName);

    transaction.replace(R.id.fragmentContainer, fragment);
    transaction.commit();

    ((MainActivity) getActivity()).createOptionsMenu();
}

From source file:com.chenl.widgets.flippablestackview.indicator.OrientedPagerSlidingTabLayout.java

private void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);/*  w  w w .j a  v  a  2s.  c o  m*/
    tab.setGravity(Gravity.CENTER);
    tab.setMaxLines(2);
    addTab(position, tab);
}

From source file:org.comixwall.pffw.InfoQueues.java

@Override
public void onItemClick(View view) {

    TextView tvPacketsBytes = view.findViewById(R.id.packetsBytes);
    TextView tvDropped = view.findViewById(R.id.dropped);

    int lines = 10;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (tvPacketsBytes.getMaxLines() != 1) {
            lines = 1;// w w  w .j  a  va 2s .  c  o  m
        }
    }

    tvPacketsBytes.setMaxLines(lines);
    tvDropped.setMaxLines(lines);
}

From source file:org.comixwall.pffw.InfoIfs.java

@Override
public void onItemClick(View view) {

    TextView tvName = view.findViewById(R.id.name);
    TextView tvCleared = view.findViewById(R.id.cleared);

    int lines = 10;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (tvName.getMaxLines() != 1) {
            lines = 1;//from w  w w . ja  va  2s.co  m
        }
    }

    tvName.setMaxLines(lines);
    tvCleared.setMaxLines(lines);
}