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:org.comixwall.pffw.Dashboard.java

@Override
public void onItemClick(View view) {

    TextView tvModule = view.findViewById(R.id.module);
    TextView tvErrors = view.findViewById(R.id.errors);

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

    tvModule.setMaxLines(lines);
    tvErrors.setMaxLines(lines);
}

From source file:com.he5ed.lib.cloudprovider.picker.ItemFragment.java

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

    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.cp_fragment_item, container, false);
    final Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from w w  w  .j  a  v a 2s  .  c o  m*/
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });

    final TextView title = (TextView) rootView.findViewById(R.id.title_text_view);
    AppBarLayout appbar = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            // detect collapsed mode
            if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                title.setMaxLines(1);
            } else {
                title.setMaxLines(2);
            }
        }
    });

    updateView(rootView);
    return rootView;
}

From source file:com.rubengees.introduction.IntroductionFragment.java

@NonNull
private View initDefaultViews(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.introduction_fragment_default_content, container,
            false);/*  ww  w  . j  av a  2 s.  com*/
    TextView title = (TextView) root.findViewById(R.id.introduction_fragment_default_content_title);
    ImageView image = (ImageView) root.findViewById(R.id.introduction_fragment_default_content_image);
    ViewGroup descriptionContainer = (ViewGroup) root
            .findViewById(R.id.introduction_fragment_default_content_description_container);
    TextView description;

    if (slide.getTitle() != null) {
        title.setText(slide.getTitle());
        title.setMaxLines(getLineCountForTitle());
        title.setTypeface(IntroductionConfiguration.getInstance().getTitleTypeface());

        if (slide.getTitleSize() != null) {
            title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, slide.getTitleSize());
        }
    }

    if (slide.getDescription() == null && slide.getOption() != null) {
        AppCompatCheckBox option = (AppCompatCheckBox) inflater.inflate(R.layout.introduction_fragment_option,
                descriptionContainer, false);

        option.setText(slide.getOption().getTitle());
        option.setChecked(slide.getOption().isActivated());
        option.setMaxLines(getLineCountForDescription());
        option.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                slide.getOption().setActivated(isChecked);
            }
        });

        CompoundButtonCompat.setButtonTintList(option,
                ContextCompat.getColorStateList(getContext(), android.R.color.white));

        descriptionContainer.addView(option);
        description = option;
    } else {
        description = (TextView) inflater.inflate(R.layout.introduction_fragment_description,
                descriptionContainer, false);

        if (slide.getDescription() != null) {
            description.setText(slide.getDescription());
        }

        description.setMaxLines(getLineCountForDescription());
        descriptionContainer.addView(description);
    }

    description.setTypeface(IntroductionConfiguration.getInstance().getDescriptionTypeface());

    if (slide.getDescriptionSize() != null) {
        description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, slide.getDescriptionSize());
    }

    if (slide.getImageResource() != null) {
        image.setImageResource(slide.getImageResource());
    }

    IntroductionConfiguration.getInstance().callOnSlideInit(slide.getPosition(), title, image, description);

    return root;
}

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

@Override
public void onItemClick(View view) {
    TextView tvCommand = view.findViewById(R.id.command);
    TextView tvOthers = view.findViewById(R.id.others);

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

    tvCommand.setMaxLines(lines);
    tvOthers.setMaxLines(lines);
}

From source file:key.secretkey.MainActivity.java

public void onResume() {
    super.onResume();
    // do not attempt to checkLocalRepository() if no storage permission: immediate crash
    if (settings.getBoolean("git_external", false)) {
        if (ContextCompat.checkSelfPermission(activity,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {
                Snackbar snack = Snackbar.make(findViewById(R.id.main_layout),
                        "The store is on the sdcard but the app does not have permission to access it. Please give permission.",
                        Snackbar.LENGTH_INDEFINITE).setAction(R.string.dialog_ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ActivityCompat.requestPermissions(activity,
                                        new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                                        REQUEST_EXTERNAL_STORAGE);
                            }//ww w .  jav a  2s.  c  o m
                        });
                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.READ_EXTERNAL_STORAGE }, REQUEST_EXTERNAL_STORAGE);
            }
        } else {
            checkLocalRepository();
        }

    } else {
        checkLocalRepository();
    }
}

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

@Override
public void onItemClick(View view) {
    TextView tvSrcDst = view.findViewById(R.id.srcDst);
    TextView tvOthers = view.findViewById(R.id.others);

    int lines = 10;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (tvSrcDst.getMaxLines() != 1) {
            lines = 1;/*from   www .  j  a  v  a2  s. c  o m*/
        }
    }

    tvSrcDst.setMaxLines(lines);
    tvOthers.setMaxLines(lines);
}

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

@Override
public void onItemClick(View view) {
    TextView tvLog = view.findViewById(R.id.log);
    TextView tvSrcDst = view.findViewById(R.id.srcDst);

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

    tvLog.setMaxLines(lines);
    tvSrcDst.setMaxLines(lines);
}

From source file:com.prey.activities.CheckPasswordActivity.java

@Override
protected void onResume() {
    super.onResume();
    bindPasswordControls();//from  w w w. j  a  va 2  s.  c o m
    TextView device_ready_h2_text = (TextView) findViewById(R.id.device_ready_h2_text);
    final TextView textForgotPassword = (TextView) findViewById(R.id.link_forgot_password);

    Button password_btn_login = (Button) findViewById(R.id.password_btn_login);
    EditText password_pass_txt = (EditText) findViewById(R.id.password_pass_txt);

    TextView textView1 = (TextView) findViewById(R.id.textView1);
    TextView textView2 = (TextView) findViewById(R.id.textView2);

    Typeface titilliumWebRegular = Typeface.createFromAsset(getAssets(),
            "fonts/Titillium_Web/TitilliumWeb-Regular.ttf");
    Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(),
            "fonts/Titillium_Web/TitilliumWeb-Bold.ttf");
    Typeface magdacleanmonoRegular = Typeface.createFromAsset(getAssets(),
            "fonts/MagdaClean/magdacleanmono-regular.ttf");

    textView1.setTypeface(magdacleanmonoRegular);
    textView2.setTypeface(magdacleanmonoRegular);

    device_ready_h2_text.setTypeface(titilliumWebRegular);
    textForgotPassword.setTypeface(titilliumWebBold);
    password_btn_login.setTypeface(titilliumWebBold);
    password_pass_txt.setTypeface(magdacleanmonoRegular);

    try {

        textForgotPassword.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                try {
                    String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelUrl();
                    Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
                    startActivity(browserIntent);
                } catch (Exception e) {
                }
            }
        });
    } catch (Exception e) {
    }

    TextView textView5_1 = (TextView) findViewById(R.id.textView5_1);
    TextView textView5_2 = (TextView) findViewById(R.id.textView5_2);

    textView5_1.setTypeface(magdacleanmonoRegular);
    textView5_2.setTypeface(titilliumWebBold);

    TextView textViewUninstall = (TextView) findViewById(R.id.textViewUninstall);
    LinearLayout linearLayoutTour = (LinearLayout) findViewById(R.id.linearLayoutTour);
    textViewUninstall.setTypeface(titilliumWebBold);

    if (PreyConfig.getPreyConfig(getApplication()).getProtectTour()) {
        linearLayoutTour.setVisibility(View.GONE);
        textViewUninstall.setVisibility(View.VISIBLE);

        textViewUninstall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = PreyConfig.getPreyConfig(getApplication()).getPreyUninstallUrl();

                Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
                startActivity(browserIntent);

                finish();
            }
        });
    } else {

        linearLayoutTour.setVisibility(View.VISIBLE);
        textViewUninstall.setVisibility(View.GONE);
        try {

            linearLayoutTour.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getApplication(), TourActivity1.class);
                    Bundle b = new Bundle();
                    b.putInt("id", 1);
                    intent.putExtras(b);
                    startActivity(intent);
                    finish();
                }
            });
        } catch (Exception e) {

        }
    }

    boolean showLocation = false;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(this);
        boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(this);
        boolean canAccessCamera = PreyPermission.canAccessCamera(this);
        boolean canAccessReadPhoneState = PreyPermission.canAccessReadPhoneState(this);
        boolean canAccessReadExternalStorage = PreyPermission.canAccessReadExternalStorage(this);

        if (!canAccessFineLocation || !canAccessCoarseLocation || !canAccessCamera || !canAccessReadPhoneState
                || !canAccessReadExternalStorage) {

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            final FrameLayout frameView = new FrameLayout(this);
            builder.setView(frameView);

            final AlertDialog alertDialog = builder.create();
            LayoutInflater inflater = alertDialog.getLayoutInflater();
            View dialoglayout = inflater.inflate(R.layout.warning, frameView);

            TextView warning_title = (TextView) dialoglayout.findViewById(R.id.warning_title);
            TextView warning_body = (TextView) dialoglayout.findViewById(R.id.warning_body);

            warning_title.setTypeface(magdacleanmonoRegular);
            warning_body.setTypeface(titilliumWebBold);

            Button button_ok = (Button) dialoglayout.findViewById(R.id.button_ok);
            Button button_close = (Button) dialoglayout.findViewById(R.id.button_close);
            button_ok.setTypeface(titilliumWebBold);
            button_close.setTypeface(titilliumWebBold);

            final Activity thisActivity = this;
            button_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PreyLogger.d("askForPermission");
                    askForPermission();
                    alertDialog.dismiss();

                }
            });

            button_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PreyLogger.d("close ask");

                    alertDialog.dismiss();
                }
            });

            alertDialog.show();
            showLocation = false;

        } else {
            showLocation = true;
        }

    } else {
        showLocation = true;
    }
    if (showLocation) {
        LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (isGpsEnabled || isNetworkEnabled) {
            PreyLogger.d("isGpsEnabled || isNetworkEnabled");

        } else {
            PreyLogger.d("no gps ni red");
            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            final AlertDialog alertDialog = builder.create();
            TextView textview = new TextView(this);
            textview.setText(getString(R.string.location_settings));
            textview.setMaxLines(10);
            textview.setTextSize(18F);
            textview.setPadding(20, 0, 20, 20);
            textview.setTextColor(Color.BLACK);
            builder.setView(textview);
            builder.setPositiveButton(getString(R.string.go_to_settings),
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialoginterface, int i) {
                            dialoginterface.dismiss();
                            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                            startActivityForResult(intent, 0);
                            return;

                        }

                    });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialoginterface, int i) {
                    dialoginterface.dismiss();
                }

            });
            builder.create().show();
        }
    }

}

From source file:org.nativescript.widgets.TabLayout.java

/**
 * Create a default view to be used for tabs.
 *//*from  www . j a  v  a 2  s .  com*/
protected View createDefaultTabView(Context context, TabItemSpec tabItem) {
    float density = getResources().getDisplayMetrics().density;
    int padding = (int) (TAB_VIEW_PADDING_DIPS * density);

    LinearLayout ll = new LinearLayout(context);
    ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setGravity(Gravity.CENTER);
    ll.setOrientation(LinearLayout.VERTICAL);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    ll.setBackgroundResource(outValue.resourceId);

    ImageView imgView = new ImageView(context);
    imgView.setScaleType(ScaleType.FIT_CENTER);
    LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgLP.gravity = Gravity.CENTER;
    imgView.setLayoutParams(imgLP);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setMaxWidth((int) (TEXT_MAX_WIDTH * density));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setAllCaps(true);
    textView.setMaxLines(2);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setPadding(padding, 0, padding, 0);

    this.setupItem(ll, textView, imgView, tabItem);

    ll.addView(imgView);
    ll.addView(textView);
    return ll;
}

From source file:com.liushengfan.test.customerviewgroup.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, SpannableString title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from  w  w w  . jav a2s  .c  om
    tab.setMovementMethod(LinkMovementMethod.getInstance());
    tab.setGravity(Gravity.CENTER);
    tab.setMaxLines(2);
    tab.setSingleLine(false);
    addTab(position, tab);
}