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:com.zhongsou.souyue.ui.indicator.CheckTabPageIndicator.java

private void doSetTextStyle(TextView tv, int background) {
    tv.setGravity(Gravity.CENTER);//from  www.  j  a  v  a 2  s  .  co  m
    tv.setBackgroundResource(background);
    tv.setPadding(10, 12, 10, 12);
    tv.setTextSize(16);
    tv.setMaxLines(1);
    tv.setWidth(dip2px(this.getContext(), 110));
    tv.setTextColor(0xff696969);
}

From source file:nu.yona.app.ui.settings.SettingsFragment.java

private void doUnsubscribe() {
    YonaActivity.getActivity().showLoadingView(true, null);
    APIManager.getInstance().getAuthenticateManager().deleteUser(new DataLoadListener() {
        @Override//ww  w . ja  v  a2 s  .  c o  m
        public void onDataLoad(Object result) {
            YonaApplication.getEventChangeManager().notifyChange(EventChangeManager.EVENT_CLEAR_ACTIVITY_LIST,
                    null);
            YonaApplication.getEventChangeManager().notifyChange(EventChangeManager.EVENT_USER_NOT_EXIST, null);
            YonaActivity.getActivity().showLoadingView(false, null);
            startActivity(new Intent(YonaActivity.getActivity(), LaunchActivity.class));
            YonaApplication.getEventChangeManager()
                    .notifyChange(EventChangeManager.EVENT_CLOSE_ALL_ACTIVITY_EXCEPT_LAUNCH, null);

        }

        @Override
        public void onError(Object errorMessage) {
            YonaActivity.getActivity().showLoadingView(false, null);
            Snackbar snackbar = Snackbar.make(YonaActivity.getActivity().findViewById(android.R.id.content),
                    ((ErrorMessage) errorMessage).getMessage(), Snackbar.LENGTH_SHORT);
            TextView textView = ((TextView) snackbar.getView()
                    .findViewById(android.support.design.R.id.snackbar_text));
            textView.setMaxLines(5);
            snackbar.show();
        }
    });
}

From source file:com.desno365.mods.DesnoUtils.java

public static void collapseTextView(ViewGroup container, final TextView tv, int collapsedHeight) {

    if (Build.VERSION.SDK_INT >= 19) {
        int lines = tv.getLineCount();

        // animation
        TransitionManager.beginDelayedTransition(container, new AutoTransition()
                .setDuration(SharedConstants.CHANGELOG_TEXT_ANIMATION_DURATION_PER_LINE * lines));

        // collapse the view by setting the collapsed height
        DesnoUtils.setViewHeight(tv, collapsedHeight);

        // restore initial state of the TextView when the animation finishes
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override/*ww w  .  jav  a2  s.c  o m*/
            public void run() {
                DesnoUtils.setViewHeight(tv, ViewGroup.LayoutParams.WRAP_CONTENT);
                tv.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);
            }
        }, SharedConstants.CHANGELOG_TEXT_ANIMATION_DURATION_PER_LINE * lines + 100);
    } else {
        // no animation without the new APIs :/
        tv.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);
    }

}

From source file:com.desno365.mods.Tabs.FragmentTab3.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab3, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_laser_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.laser.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.laser_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.laser.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.laser_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.laser.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab3); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//w ww .  java  2  s.  c  o  m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab2.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab2, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_portal_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.portal.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.portal_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.portal.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.portal_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.portal.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab2); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/*  ww  w .  j av  a 2 s  .c om*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab7.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab7, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_unreal_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.unreal.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.unreal_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.unreal.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.unreal_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.unreal.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab7); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w w.  j  a va2 s. co  m*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab6.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab6, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_guns_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.desnoGuns.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.guns_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.desnoGuns.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.guns_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.desnoGuns.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab6); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from  www  .  ja  v a  2  s. c  o  m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab4.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab4, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_turrets_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.turrets.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.turrets_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.turrets.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.turrets_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.turrets.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab4); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override//from www  .  j  ava2 s  .  c  o m
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.desno365.mods.Tabs.FragmentTab5.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragmenttab5, container, false); // xml tab

    TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_jukebox_is); // id TextView version
    textVersion.setText(MainActivity.modsContainer.jukebox.getVersion()); // MainActivity variable that holds the latest version

    TextView textCompatibility = (TextView) rootView.findViewById(R.id.jukebox_compatibility); // id TextView compatibility
    textCompatibility.setText(MainActivity.modsContainer.jukebox.getCompatibility()); // MainActivity variable that holds the versions compatibility

    final TextView textChangelog = (TextView) rootView.findViewById(R.id.jukebox_changelog); // id TextView changelog
    textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.jukebox.getChangelog())); // MainActivity variable that holds the latest changelog
    textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
    textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES);

    final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab5); // id TextView show/hide changelog
    textShowHide.setText(getResources().getString(R.string.show_changelog));
    textShowHide.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w.  ja  va 2 s . com*/
        public void onClick(View v) {

            if (!displayingAllChangelog) {

                // get the TextView height that will be used when hiding the changelog
                changelogHiddenHeight = textChangelog.getHeight();

                DesnoUtils.expandTextView(container, textChangelog);

                displayingAllChangelog = true;
                textShowHide.setText(getResources().getString(R.string.hide_changelog));

            } else {

                DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight);

                displayingAllChangelog = false;
                textShowHide.setText(getResources().getString(R.string.show_changelog));
            }
        }
    });

    // make the show/hide button invisible if it is not necessary
    ViewTreeObserver vto = textShowHide.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) {
                textShowHide.setVisibility(View.GONE);
            } else {
                textShowHide.setVisibility(View.VISIBLE);
            }
        }
    });

    return rootView;
}

From source file:com.app.the.bunker.views.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 ava2  s  .c o m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    textView.setTypeface(Typeface.DEFAULT);
    textView.setMaxLines(1);
    textView.setSingleLine(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);
    textView.setBackgroundResource(outValue.resourceId);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}