Search in sources :

Example 1 with DocumentView

use of com.bluejamesbond.text.DocumentView in project TextJustify-Android by bluejamesbond.

the class CustomHyphenatorTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DocumentView documentView = addDocumentView(new StringBuilder().append(getResources().getString(R.string.plain_text)).toString(), DocumentView.PLAIN_TEXT);
    documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
    documentView.getDocumentLayoutParams().setHyphenator(SqueezeHyphenator.getInstance());
    documentView.getDocumentLayoutParams().setHyphenated(true);
}
Also used : DocumentView(com.bluejamesbond.text.DocumentView)

Example 2 with DocumentView

use of com.bluejamesbond.text.DocumentView in project TextJustify-Android by bluejamesbond.

the class TextUpdateTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final DocumentView documentView = addDocumentView("Click here!", DocumentView.PLAIN_TEXT);
    documentView.getDocumentLayoutParams().setHyphenator(SqueezeHyphenator.getInstance());
    documentView.getDocumentLayoutParams().setHyphenated(true);
    documentView.getViewportView().setClickable(true);
    documentView.getViewportView().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Console.log("Clicked");
            documentView.setText("Click[" + System.currentTimeMillis() + "], " + documentView.getText());
        }
    });
}
Also used : DocumentView(com.bluejamesbond.text.DocumentView) DocumentView(com.bluejamesbond.text.DocumentView) View(android.view.View)

Example 3 with DocumentView

use of com.bluejamesbond.text.DocumentView in project TextJustify-Android by bluejamesbond.

the class WordSpacingTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DocumentView documentView = addDocumentView("Document view now supports both String and Spannables. To support this, there are two (2) types of layouts: (a) " + "DocumentLayout and (b) SpannedDocumentLayout. " + "DocumentLayout supports just plain Strings just like the text you are reading. However, Spannables require the " + "constructor to have SpannedDocumentLayout.class as a parameter. For now, DocumentLayout will offer significant speed improvements " + "compared to SpannedDocumentLayout, so use each class accordingly. DocumentLayout also supports hyphenation. To learn more about" + "these layouts and what they have to offer visit the link in the titlebar above. And please report all the issues on GitHub!", DocumentView.PLAIN_TEXT);
    documentView.getDocumentLayoutParams().setWordSpacingMultiplier(5f);
}
Also used : DocumentView(com.bluejamesbond.text.DocumentView)

Example 4 with DocumentView

use of com.bluejamesbond.text.DocumentView in project TextJustify-Android by bluejamesbond.

the class TestActivity method addDocumentView.

public DocumentView addDocumentView(CharSequence article, int type, boolean rtl) {
    final DocumentView documentView = new DocumentView(this, type);
    documentView.getDocumentLayoutParams().setTextColor(0xffffffff);
    documentView.getDocumentLayoutParams().setTextTypeface(Typeface.DEFAULT);
    documentView.getDocumentLayoutParams().setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
    documentView.getDocumentLayoutParams().setInsetPaddingLeft(30f);
    documentView.getDocumentLayoutParams().setInsetPaddingRight(30f);
    documentView.getDocumentLayoutParams().setInsetPaddingTop(30f);
    documentView.getDocumentLayoutParams().setInsetPaddingBottom(30f);
    documentView.getDocumentLayoutParams().setLineHeightMultiplier(1f);
    documentView.getDocumentLayoutParams().setReverse(rtl);
    documentView.getDocumentLayoutParams().setDebugging(debugging);
    documentView.setText(article);
    documentView.setProgressBar((ProgressBar) findViewById(R.id.progressBar));
    documentView.setFadeInDuration(800);
    documentView.setFadeInAnimationStepDelay(30);
    documentView.setFadeInTween(new DocumentView.ITween() {

        @Override
        public float get(float t, float b, float c, float d) {
            return c * (t /= d) * t * t + b;
        }
    });
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    linearLayout.addView(documentView);
    LinearLayout articleList = (LinearLayout) findViewById(R.id.articleList);
    articleList.addView(linearLayout);
    debugging = documentView.getDocumentLayoutParams().isDebugging();
    cacheConfig = documentView.getCacheConfig().getId();
    final TextView debugButton = (TextView) findViewById(R.id.debugButton);
    if (debugButton != null) {
        debugButton.setText((debugging ? "DISABLE" : "ENABLE") + " DEBUG");
        debugButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                debugging = !debugging;
                debugButton.setText((debugging ? "DISABLE" : "ENABLE") + " DEBUG");
                documentView.getDocumentLayoutParams().setDebugging(debugging);
            }
        });
    }
    final TextView cacheButton = (TextView) findViewById(R.id.cacheButton);
    final Toast cacheConfigToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
    if (cacheButton != null) {
        cacheConfigToast.setText("Activated " + documentView.getCacheConfig().name());
        cacheConfigToast.show();
        cacheButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                cacheConfig = (cacheConfig + 1) % 5;
                DocumentView.CacheConfig newCacheConfig = DocumentView.CacheConfig.getById(cacheConfig);
                cacheConfigToast.setText("Activated " + newCacheConfig.name());
                cacheConfigToast.show();
                documentView.setCacheConfig(newCacheConfig);
                documentView.destroyCache();
                documentView.invalidate();
            }
        });
    }
    return documentView;
}
Also used : Toast(android.widget.Toast) TextView(android.widget.TextView) DocumentView(com.bluejamesbond.text.DocumentView) TextView(android.widget.TextView) DocumentView(com.bluejamesbond.text.DocumentView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 5 with DocumentView

use of com.bluejamesbond.text.DocumentView in project TextJustify-Android by bluejamesbond.

the class ClickableSpanTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final DocumentView documentView = addDocumentView(new ArticleBuilder().append("Healthcare workers returning to New York or New Jersey after treating Ebola patients in West Africa will be placed under a mandatory quarantine, officials announced Friday, one day after a Doctors Without Borders doctor was diagnosed with the virus in New York City. Illinois announced a similar policy Saturday, meaning it will be enforced in states with three of the five airports through which passengers traveling from the Ebola-stricken West African countries must enter the United States.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("N.J. Gov. Chris Christie and N.Y. Gov. Andrew Cuomo made the announcement as part of a broader procedural plan to help protect the densely packed, highly populated area from any further spread of the disease. ", true, new RelativeSizeSpan(0.8f), new JustifiedSpan(), new MyQuoteSpan(0xFFFFC801)).append("“Since taking office, I have erred on the side of caution when it comes to the safety and protection of New Yorkers, and the current situation regarding Ebola will be no different,” Gov. Cuomo said. “The steps New York and New Jersey are taking today will strengthen our safeguards to protect our residents against this disease and help ensure those that may be infected by Ebola are treated with the highest precautions.”", true, new RelativeSizeSpan(1f), new JustifiedSpan(), new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            Toast.makeText(ClickableSpanTest.this, "Clicked", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(Color.parseColor("#ff05c5cf"));
            ds.setUnderlineText(true);
        }
    }).append("New York and New Jersey state health department staff will be present on the ground at John F. Kennedy International Airport in New York and Newark Liberty Airport in New Jersey. In addition to implementing the mandatory quarantine of health care workers and others who had direct contact with Ebola patients, health department officials in each state will determine whether others should travelers should be hospitalized or quarantined.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("“The announcements mark a dramatic escalation in measures designed to prevent the spread of Ebola in the United States. Previously, only individuals with symptoms of Ebola would be quarantined upon entry to the U.S. under a federal rule from the Centers for Diseases Control and the Department of Homeland Security.”", true, new RelativeSizeSpan(1f), new JustifiedSpan()), DocumentView.FORMATTED_TEXT);
    documentView.getDocumentLayoutParams().setHyphenator(SqueezeHyphenator.getInstance());
    documentView.getDocumentLayoutParams().setHyphenated(true);
}
Also used : JustifiedSpan(com.bluejamesbond.text.style.JustifiedSpan) MyQuoteSpan(com.bluejamesbond.text.sample.helper.MyQuoteSpan) ArticleBuilder(com.bluejamesbond.text.util.ArticleBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) DocumentView(com.bluejamesbond.text.DocumentView) ClickableSpan(android.text.style.ClickableSpan) DocumentView(com.bluejamesbond.text.DocumentView) View(android.view.View) TextPaint(android.text.TextPaint)

Aggregations

DocumentView (com.bluejamesbond.text.DocumentView)6 View (android.view.View)3 TextPaint (android.text.TextPaint)1 ClickableSpan (android.text.style.ClickableSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 MyQuoteSpan (com.bluejamesbond.text.sample.helper.MyQuoteSpan)1 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)1 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)1