Android Open Source - LinkTextView Main Activity






From Project

Back to project page LinkTextView.

License

The source code is released under:

MIT License

If you think the Android project LinkTextView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.zekunyan.linktextview.sample;
//  w ww . j  a v a  2  s.c  o  m
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.zekunyan.linktextview.LinkTextView;

public class MainActivity extends Activity implements View.OnClickListener {

    //UI controls
    LinkTextView linkTextView;
    TextView infoTextView;
    EditText editText;

    //Index
    int exampleLinkBegin = 0;
    int exampleLinkEnd = 12;

    int manualLinkBegin = 14;
    int manualLinkEnd = 25;

    //Link ID
    int exampleLinkID = -1;
    int manualLinkID = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        linkTextView = (LinkTextView) findViewById(R.id.linkTextView);
        infoTextView = (TextView) findViewById(R.id.textview_info);
        editText = (EditText) findViewById(R.id.edittext_attachment);

        //Bind click
        findViewById(R.id.button_change_normal_color).setOnClickListener(this);
        findViewById(R.id.button_change_pressed_color).setOnClickListener(this);
        findViewById(R.id.button_change_bg_color).setOnClickListener(this);
        findViewById(R.id.button_add).setOnClickListener(this);
        findViewById(R.id.button_remove).setOnClickListener(this);

        //Set text.
        linkTextView.setClickableText("Example link.\nManual link.");

        //Set example link
        exampleLinkID = linkTextView.addClick(
                exampleLinkBegin,                 //Link begin index
                exampleLinkEnd,                   //Link end index
                new LinkTextView.OnClickInLinkText() {
            @Override
            public void onLinkTextClick(String clickText, int linkID, Object attachment) {
                infoTextView.setText("You click example link. It's attachment is: " + attachment);
            }
        },
                "This is example link attachment", //Link attachment
                true,                              //Show link underline
                Color.BLACK,                       //Text normal color
                Color.YELLOW,                      //Text pressed color
                Color.WHITE,                       //Background normal color
                Color.GREEN                        //Background pressed color
        );
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button_change_normal_color:
                linkTextView.setTextNormalColor(exampleLinkID, Color.MAGENTA);
                break;
            case R.id.button_change_pressed_color:
                linkTextView.setTextPressedColor(exampleLinkID, Color.RED);
                break;
            case R.id.button_change_bg_color:
                linkTextView.setBackgroundNormalColor(exampleLinkID, Color.CYAN);
                break;
            case R.id.button_add:
                manualLinkID = linkTextView.addClick(manualLinkBegin, manualLinkEnd,
                        new LinkTextView.OnClickInLinkText() {
                    @Override
                    public void onLinkTextClick(String clickText, int linkID, Object attachment) {
                        infoTextView.setText("You click manual link. It's attachment is: " + attachment);
                    }
                }, editText.getText());
                break;
            case R.id.button_remove:
                linkTextView.removeLink(manualLinkID);
                infoTextView.setText("You have removed the link");
                break;
        }
    }
}




Java Source Code List

com.zekunyan.linktextview.LinkTextView.java
com.zekunyan.linktextview.LinkTextView.java
com.zekunyan.linktextview.sample.ApplicationTest.java
com.zekunyan.linktextview.sample.MainActivity.java