mathew-kurian / TextJustify-Android

:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0
https://github.com/bluejamesbond/TextJustify-Android/wiki
Apache License 2.0
1.86k stars 369 forks source link

Library not clear #53

Closed samsoft00 closed 9 years ago

samsoft00 commented 9 years ago

To be honest, i've spent hours trying to find a way to make use of this library and to attached it to view.. it was so difficult, can you help on how?

I want to make use of ArticleBuilder(), so how do i make reference to view where i have this --> <com.bluejamesbond.text.DocumentView xmlns:document="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="+id/instruction" />

here is my java code

    a = new ArticleBuilder();
    a.append("WHO: Ebola Cases",
            false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD))
            .append("<font color=0xFFC801>Sam Frizell</font><font color=0x888888> @Sam_Frizell  Oct. 25, 2014</font>",
                    false, new RelativeSizeSpan(0.8f), new StyleSpan(Typeface.BOLD))
            .append("In New York and New Jersey, governors Andrew Cuomo and Chris Christie have implemented controversial quarantines on all healthcare workers returning from West Africa after a doctor returning from Guinea contracted the disease and was diagnosed in New York.",
                    true, new RelativeSizeSpan(1f), new JustifiedSpan());

    DocumentView documentView = new DocumentView(getActivity(), R.id.instruction);  // Support spanned text
    documentView.setText(a); // Set to `true` to enable justification

Doing it this way generate error

Process: com.samsoft.cbc.studio, PID: 2834
java.lang.NullPointerException
        at com.bluejamesbond.text.DocumentView$MeasureTask.onPostExecute(DocumentView.java:729)
        at com.bluejamesbond.text.DocumentView$MeasureTask.onPostExecute(DocumentView.java:685)
        at android.os.AsyncTask.finish(AsyncTask.java:632)
        at android.os.AsyncTask.access$600(AsyncTask.java:177)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

Any Solution on how to relate the view and the java code together, if i'm not doing it right.. please let me know. Thanks

mathew-kurian commented 9 years ago

@samsoft00 Your code seems correct. The latest version of the build has not been pushed to maven yet. You are still using a rather beta edition. There is in fact a bug with the library. It has been fixed. I will push it in momentarily. Thank you for spotting it and I apologize for the problem

mathew-kurian commented 9 years ago

Use version 2.0.3. Please look at the samples before you use it. There are some modifications done in order to address previous bugs. Let me know if issues persist.

mathew-kurian commented 9 years ago

Use version 2.0.4. Let me know if you still have any issues.

samsoft00 commented 9 years ago

No Crashing again but no text display -> DocumentView documentView = new DocumentView(getActivity(), R.id.instruction); Please help, I'm using fragment layout..

mathew-kurian commented 9 years ago

Provide some code

— Sent from Mailbox

On Thu, Jan 15, 2015 at 2:53 AM, Oyewole S. Abayomi notifications@github.com wrote:

No Crashing again but no text display -> DocumentView documentView = new DocumentView(getActivity(), R.id.instruction);

Please help, I'm using fragment layout..

Reply to this email directly or view it on GitHub: https://github.com/bluejamesbond/TextJustify-Android/issues/53#issuecomment-70056144

samsoft00 commented 9 years ago

Here is my code

public class StartRegistrationFragment extends Fragment { private static final String ARG_KEY = "key";

private PageFragmentCallbacks mCallbacks;
private String mKey;
private StartRegistrationActivity mPage;
DocumentView mDocumentView;
ArticleBuilder a;

public static StartRegistrationFragment create(String key) {
    Bundle args = new Bundle();
    args.putString(ARG_KEY, key);

    StartRegistrationFragment fragment = new StartRegistrationFragment();
    fragment.setArguments(args);
    return fragment;
}

public StartRegistrationFragment(){}

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

    Bundle args = getArguments();
    mKey = args.getString(ARG_KEY);
    mPage = (StartRegistrationActivity) mCallbacks.onGetPage(mKey);

    a = new ArticleBuilder();
    a.append("WHO: Ebola Cases",
            false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD))
            .append("<font color=0xFFC801>Sam Frizell</font><font color=0x888888> @Sam_Frizell  Oct. 25, 2014</font>",
                    false, new RelativeSizeSpan(0.8f), new StyleSpan(Typeface.BOLD))
            .append("In New York and New Jersey, governors Andrew Cuomo and Chris Christie have implemented controversial quarantines on all healthcare workers returning from West Africa after a doctor returning from Guinea contracted the disease and was diagnosed in New York.",
                    true, new RelativeSizeSpan(1f), new JustifiedSpan());

    DocumentView documentView = new DocumentView(getActivity(), R.id.instruction);  // Support spanned text
    documentView.setText(a); // Set to `true` to enable justification

}

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

    View rootView = inflater.inflate(R.layout.activity_start_registration, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

   //mDocumentView = (DocumentView) rootView.findViewById(R.id.instruction);

    return rootView;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    if (!(activity instanceof PageFragmentCallbacks)) {
        throw new ClassCastException("Activity must implement PageFragmentCallbacks");
    }

    mCallbacks = (PageFragmentCallbacks) activity;
}

@Override
public void onDetach() {
    super.onDetach();
    mCallbacks = null;
}

}

samsoft00 commented 9 years ago

This is my view

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:document="http://schemas.android.com/apk/res-auto"
    style="@style/WizardPageContainer"
    android:orientation="vertical">
    <TextView style="@style/WizardPageTitle" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/review_icon"
                android:layout_gravity="center"
                android:padding="10dp"/>
            <LinearLayout
                android:id="@+id/discription_wrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:padding="10dp">
                <com.bluejamesbond.text.DocumentView
                    android:id="@+id/instruction"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </LinearLayout>
</LinearLayout>
mathew-kurian commented 9 years ago

Your did not add DocumentView to a parent layout

samsoft00 commented 9 years ago

@bluejamesbond DocumentView to a parent layout? where and how?

mathew-kurian commented 9 years ago

findViewById(R.id.desriptionWrapper).addView(documentView)

samsoft00 commented 9 years ago

@bluejamesbond i'm sorry, this is getting confused...

This is reference to my layout==> DocumentView mDocumentView = (DocumentView) rootView.findViewById(R.id.instruction);

Where i'm going to reference it here ==> DocumentView documentView = new DocumentView(getActivity(), R.id.instruction); documentView.setText(articleBuilder);

can you help me with sample code! Thanks!

mathew-kurian commented 9 years ago

https://gist.github.com/bluejamesbond/32d73923b9f67dc07639

samsoft00 commented 9 years ago

Thanks, it work now but i move the code to onResume()

@Override
public void onResume() {
    super.onResume();

    a = new ArticleBuilder();
    a.append("WHO: Ebola Cases",
            false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD))
            .append("<font color=0xFFC801>Sam Frizell</font><font color=0x888888> @Sam_Frizell  Oct. 25, 2014</font>",
                    false, new RelativeSizeSpan(0.8f), new StyleSpan(Typeface.BOLD))
            .append("In New York and New Jersey, governors Andrew Cuomo and Chris Christie have implemented controversial quarantines on all healthcare workers returning from West Africa after a doctor returning from Guinea contracted the disease and was diagnosed in New York.",
                    true, new RelativeSizeSpan(1f), new JustifiedSpan());

    DocumentView documentView = new DocumentView(getActivity(), DocumentView.FORMATTED_TEXT);  // Support spanned text
    documentView.setText(a); // Set to `true` to enable justification
    (mLayout).addView(documentView);
}

Thanks

mathew-kurian commented 9 years ago

@samsoft00 I don't believe you are supposed to put it in onResume as per Android contract.

samsoft00 commented 9 years ago

@bluejamesbond it crashed when i put it onCreate, remember this is fragment. Also, question. how do i reset the textSize!

samsoft00 commented 9 years ago

I think dere's alot to amend, i later discovered that the article is not fully loaded, only first append contents.. Check code

    a = new ArticleBuilder();
    a.append("BluSlate Study Studio",
            false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD))
            .append("The Blue Slate Study Studio is our flagship education solution where the art of teaching, the joy of learning and the proactive anticipation of exams – all co-exist in harmony to produce a positive and gratifying learning experience. The Study Studio application is made of multiple Study Booths. A Study Booth caters exclusively for a course as follows: Course No., Course Name, Course Material, Slide Presentations, Practice Exams, Course Notes and Course Information.",
                    true, new RelativeSizeSpan(1f), new JustifiedSpan())
            .append("<font color=0xFFC801>Course No. Tab:</font> (the first tab) lists the course identifier – e.g. CSC 101.",
                    true, new RelativeSizeSpan(1f), new JustifiedSpan())
            .append("<font color=0xFFC801>Course Name Tab:</font> (the second tab)  lists the full name of the course.",
                    true, new RelativeSizeSpan(1f), new LeftSpan())
            .append("<font color=0xFFC801>Course Material Tab: </font> opens up an e-book containing lecture materials content.",
                    true, new RelativeSizeSpan(1f), new LeftSpan())
            .append("<font color=0xFFC801>Slide Presentation Tab: </font> opens into a Power point Slide presentation prepared by lecturer.",
                    true, new RelativeSizeSpan(1f), new LeftSpan())
            .append("<font color=0xFFC801>Practice Exam Tab: </font> opens up to CBC’s Practezer App with content made up of previous sessions exams, answers and correct model solutions. The students can practice in an ad-hoc manner (random questions, untimed) or actually sit for a previous exam (timed). For each question, the student can click a button to see the correct answer, and click another button to get a detailed model solution.",
                    true, new RelativeSizeSpan(1f), new LeftSpan())
            .append("<font color=0xFFC801>Course Notes Tab: </font> opens up a Word document where the student can keep personal notes on the course..",
                    true, new RelativeSizeSpan(1f), new LeftSpan())
            .append("<font color=0xFFC801>Course Info Tab: </font> opens up to general information on the course such as course content, prerequisites, lecturers, as well as the schedule of lectures and labs for the course.",
                    true, new RelativeSizeSpan(1f), new LeftSpan())
            .append("PLEASE NOTE THAT YOU WILL NEED INTERNET ACCESS FOR <font color=0xFFC801>REGISTRATION</font> FOR YOUR FIRST LOGIN",
                    true, new RelativeSizeSpan(1f), new LeftSpan());

    DocumentView documentView = new DocumentView(getActivity(), DocumentView.FORMATTED_TEXT);  // Support spanned text
    documentView.setText(a);
    (mLayout).addView(documentView);