morristech
5/14/2019 - 11:09 PM

PracticalInfoFragment.java

public class PracticalInfoFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_practical_info, container, false);
        TextView practicalInfo = (TextView)view.findViewById(R.id.practical_info);
        practicalInfo.setMovementMethod(LinkMovementMethod.getInstance());
        String infoString = _readStringFromAssets(); // Not detailed here, content can be seen in the other file below
        _setTextViewLinks(practicalInfo, infoString);
        return view;
    }
    
     /**
     * Fixes the links in the textView. In-app links are built up here.
     *
     * @param textView TextView the text will be inserted into.
     * @param text     Text containing the HTML.
     */
    private void _setTextViewLinks(TextView textView, String text) {
        CharSequence sequence = Html.fromHtml(text);
        SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
        URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
        for (URLSpan span : urls) {
            makeLinksClickable(strBuilder, span);
        }
        textView.setText(strBuilder);
    }



    /**
     * Checks for every link if it is a hyperlink to a screen in the app. If yes, it sets the correct listener.
     *
     * @param strBuilder Spannable string builder. Convert your string to a char sequence, then use the string builder constructor on it
     * @param span       An URL span in the string. Sets the listener on this.
     */
    protected void makeLinksClickable(SpannableStringBuilder strBuilder, final URLSpan span) {
        int start = strBuilder.getSpanStart(span);
        int end = strBuilder.getSpanEnd(span);
        int flags = strBuilder.getSpanFlags(span);
        ClickableSpan clickable = new ClickableSpan() {
            @Override
            public void onClick(View view) {
                if (span.getURL().equalsIgnoreCase("app://schedule")) {
                    // Open the schedule
                    ((MainActivity)getActivity()).openFragment(new ScheduleFragment());
                } else {
                    // These are links which should open in the default browser
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(span.getURL()));
                    getActivity().startActivity(intent);
                }
            }
        };
        strBuilder.setSpan(clickable, start, end, flags);
        strBuilder.removeSpan(span);
    }
}
<b>About mdevcon</b> <br/>
<br/>
The conference is by mobile developers, for mobile developers. 
We have two days with multiple tracks, designed in such a way that 
whether you’re an android, iOS or other mobile platform developer, 
there’s always at least one session that should be of interest. 
The schedule contains many industry experts and can be found <a href="app://schedule">here</a>. 
The venue is epic, it’s the 1920′s classic Tuschinski Theater in Amsterdam. 
We expect around 275 attendees. <br/>
<br/>
<b>Target audience</b> <br/>
<br/>
Mdevcon is targeted at developers working with mobile technology. 
There will be talks targeted at a specific platform and talks of a 
more platform independent nature. We welcome independent developers, 
freelancers and developers working for a company – It doesn’t matter 
who you are or where you work, if you work with mobile technology 
you’ll enjoy this conference. <br/>
<br/>
There’s one place where a mobile developer conference makes perfect sense: <b>Appsterdam.</b> 
Founded by Mike Lee, appsterdam is a growing European community of app developers located 
in or near Amsterdam. Visit the <a href="http://appsterdam.rs/">Appsterdam website</a> for more information about this vibrant 
community of developers or to become a member. The conference is open to a world wide 
audience and we hope it will be an opportunity for many developers to get a sense of 
the great atmosphere in Appsterdam! <br/>
<br/>
As for the venue, we looked hard to find a location that is easy to reach but also inspiring. 
The conference will be held in the Tuschinski Theater. According to wikipedia it is 
‘considered one of the most beautiful cinemas in the world’. This means that we’ll not 
only have presentations literally on the big screen, it means we’ll have comfy chairs 
to enjoy the conference. We were also very interested in this venue because of its 
excellent ‘hallway track’. This unofficial track in between or during sessions where you 
meet other developers and speakers is just as valuable as the main content tracks, 
and Tuschinski is a great place to talk to people or to just hang out.