├── MultiActionTextViewLib
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ └── values
│ │ ├── dimens.xml
│ │ └── strings.xml
├── AndroidManifest.xml
├── project.properties
├── proguard-project.txt
├── .project
└── src
│ └── com
│ └── ajra
│ └── multiactiontextview
│ ├── MultiActionTextviewClickListener.java
│ ├── MultiActionTextViewClickableSpan.java
│ ├── InputObject.java
│ └── MultiActionTextView.java
├── MultiActionTextViewDemo
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── values
│ │ ├── dimens.xml
│ │ └── strings.xml
│ ├── values-w820dp
│ │ └── dimens.xml
│ └── layout
│ │ └── activity_main.xml
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── project.properties
├── proguard-project.txt
├── AndroidManifest.xml
├── .project
└── src
│ └── com
│ └── ajra
│ └── multiactiontextview
│ └── MainActivity.java
├── .gitignore
└── README.md
/MultiActionTextViewLib/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajaysahani/MultiActionTextView/HEAD/MultiActionTextViewLib/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MultiActionTextViewLib/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajaysahani/MultiActionTextView/HEAD/MultiActionTextViewLib/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajaysahani/MultiActionTextView/HEAD/MultiActionTextViewDemo/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajaysahani/MultiActionTextView/HEAD/MultiActionTextViewDemo/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajaysahani/MultiActionTextView/HEAD/MultiActionTextViewDemo/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajaysahani/MultiActionTextView/HEAD/MultiActionTextViewDemo/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MultiActionTextView
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MultiActionTextViewLib
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Eclipse project files
23 | .classpath
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-20
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-20
15 | android.library.reference.1=../MultiActionTextViewLib
16 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MultiActionTextView
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MultiActionTextViewDemo
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MultiActionTextView
2 | ===================
3 | [](https://android-arsenal.com/details/1/1099)
4 |
5 | It is use to create spannable textview with and without under line.
6 | You can provide custom color to text on which you want click functionality.
7 |
8 |
9 |
10 |
11 | Compatibility
12 | =========
13 | * **Library** : API 1
14 | * **LibrarySample** : API 1
15 | *
16 | License
17 | =======
18 | Copyright 2014-present Ajay Sahani
19 |
20 | Licensed under the Apache License, Version 2.0 (the "License");
21 | you may not use this file except in compliance with the License.
22 | You may obtain a copy of the License at
23 |
24 | http://www.apache.org/licenses/LICENSE-2.0
25 |
26 | Unless required by applicable law or agreed to in writing, software
27 | distributed under the License is distributed on an "AS IS" BASIS,
28 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | See the License for the specific language governing permissions and
30 | limitations under the License.
31 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/src/com/ajra/multiactiontextview/MultiActionTextviewClickListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014-present Ajay Sahani
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 | * not use this file except in compliance with the License. You may obtain a
6 | * copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 | package com.ajra.multiactiontextview;
17 |
18 | /**
19 | *
20 | * @author Ajay Sahani
21 | * @seeA :Interface to handle click on sub string of TextView.
22 | *
23 | */
24 | public interface MultiActionTextviewClickListener {
25 |
26 | /**
27 | *
28 | * @param inputObject
29 | * : Object which we had sent in request getting back when click
30 | * operation occur basically use to identify which part of Text
31 | * clicked. User operation type variable to identify for which
32 | * section of text clicked.
33 | */
34 | public void onTextClick(InputObject inputObject);
35 | }
36 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
16 |
17 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/src/com/ajra/multiactiontextview/MultiActionTextViewClickableSpan.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014-present Ajay Sahani
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 | * not use this file except in compliance with the License. You may obtain a
6 | * copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 | package com.ajra.multiactiontextview;
17 |
18 | import android.text.TextPaint;
19 | import android.text.style.ClickableSpan;
20 |
21 | /**
22 | *
23 | * @author Ajay Sahani:
24 | * @seeA :Class responsible for hiding and showing and Setting Link to
25 | * substring.
26 | *
27 | */
28 | public abstract class MultiActionTextViewClickableSpan extends ClickableSpan {
29 |
30 | private boolean isUnderLineRequired;
31 |
32 | public MultiActionTextViewClickableSpan(boolean isUnderLineRequired) {
33 | this.isUnderLineRequired = isUnderLineRequired;
34 | }
35 |
36 | @Override
37 | public void updateDrawState(TextPaint ds) {
38 | ds.setColor(ds.linkColor);
39 | ds.setUnderlineText(isUnderLineRequired);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/src/com/ajra/multiactiontextview/InputObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014-present Ajay Sahani
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 | * not use this file except in compliance with the License. You may obtain a
6 | * copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 | package com.ajra.multiactiontextview;
17 |
18 | import android.text.SpannableStringBuilder;
19 |
20 | public class InputObject {
21 |
22 | /**
23 | * start index
24 | */
25 | private int startSpan;
26 | /**
27 | * end index
28 | */
29 | private int endSpan;
30 | /**
31 | * append entire sub text into SpannableStringBuilder
32 | */
33 | private SpannableStringBuilder stringBuilder;
34 | /**
35 | * Call back to handle click event
36 | */
37 | private MultiActionTextviewClickListener multiActionTextviewClickListener;
38 | /**
39 | * input object which we want when click event occur.
40 | */
41 | private Object inputObject;
42 | /**
43 | * uniquely identify on which part of text view click.
44 | */
45 | private int OperationType;
46 |
47 | public Object getInputObject() {
48 | return inputObject;
49 | }
50 |
51 | public void setInputObject(Object inputObject) {
52 | this.inputObject = inputObject;
53 | }
54 |
55 | public int getOperationType() {
56 | return OperationType;
57 | }
58 |
59 | public void setOperationType(int operationType) {
60 | OperationType = operationType;
61 | }
62 |
63 | public int getStartSpan() {
64 | return startSpan;
65 | }
66 |
67 | public void setStartSpan(int startSpan) {
68 | this.startSpan = startSpan;
69 | }
70 |
71 | public int getEndSpan() {
72 | return endSpan;
73 | }
74 |
75 | public void setEndSpan(int endSpan) {
76 | this.endSpan = endSpan;
77 | }
78 |
79 | public SpannableStringBuilder getStringBuilder() {
80 | return stringBuilder;
81 | }
82 |
83 | public void setStringBuilder(SpannableStringBuilder stringBuilder) {
84 | this.stringBuilder = stringBuilder;
85 | }
86 |
87 | public MultiActionTextviewClickListener getMultiActionTextviewClickListener() {
88 | return multiActionTextviewClickListener;
89 | }
90 |
91 | public void setMultiActionTextviewClickListener(
92 | MultiActionTextviewClickListener multiActionTextviewClickListener) {
93 | this.multiActionTextviewClickListener = multiActionTextviewClickListener;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/MultiActionTextViewLib/src/com/ajra/multiactiontextview/MultiActionTextView.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014-present Ajay Sahani
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 | * not use this file except in compliance with the License. You may obtain a
6 | * copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 | package com.ajra.multiactiontextview;
17 |
18 | import android.text.Spannable;
19 | import android.text.SpannableStringBuilder;
20 | import android.text.method.LinkMovementMethod;
21 | import android.view.View;
22 | import android.widget.TextView;
23 | import android.widget.TextView.BufferType;
24 |
25 | /**
26 | *
27 | * @author Ajay Sahani:
28 | * @seeA class which is responsible for handling multiple type of click on
29 | * single TextView and use different color for text section on which we
30 | * want click action.
31 | *
32 | */
33 | public class MultiActionTextView {
34 |
35 | public static void setSpannableText(TextView textView,
36 | SpannableStringBuilder stringBuilder, int highLightTextColor) {
37 | textView.setMovementMethod(LinkMovementMethod.getInstance());
38 | textView.setText(stringBuilder, BufferType.SPANNABLE);
39 | textView.setLinkTextColor(highLightTextColor);
40 | }
41 |
42 | /**
43 | *
44 | * @param inputObject
45 | * :should not null Method responsible for creating click able
46 | * part in TextView without hyper link.
47 | */
48 | public static void addActionOnTextViewWithLink(final InputObject inputObject) {
49 | inputObject.getStringBuilder().setSpan(
50 | new MultiActionTextViewClickableSpan(true) {
51 | @Override
52 | public void onClick(View widget) {
53 | inputObject.getMultiActionTextviewClickListener()
54 | .onTextClick(inputObject);
55 | }
56 | }, inputObject.getStartSpan(), inputObject.getEndSpan(),
57 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
58 | }
59 |
60 | /**
61 | *
62 | * @param inputObject
63 | * :should not null Method responsible for creating click able
64 | * part in TextView with hyper link.
65 | */
66 | public static void addActionOnTextViewWithoutLink(
67 | final InputObject inputObject) {
68 | inputObject.getStringBuilder().setSpan(
69 | new MultiActionTextViewClickableSpan(false) {
70 | @Override
71 | public void onClick(View widget) {
72 | inputObject.getMultiActionTextviewClickListener()
73 | .onTextClick(inputObject);
74 | }
75 | }, inputObject.getStartSpan(), inputObject.getEndSpan(),
76 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/MultiActionTextViewDemo/src/com/ajra/multiactiontextview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ajra.multiactiontextview;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.text.SpannableStringBuilder;
7 | import android.util.Log;
8 | import android.widget.TextView;
9 | import android.widget.Toast;
10 |
11 |
12 | public class MainActivity extends Activity {
13 |
14 | private TextView textViewWithoutLink;
15 | private TextView textViewWithoutLinkFewClickable;
16 | private TextView textViewWithLink;
17 | private MyMultiActionClickListener myMultiActionClickListener;
18 | private final int NAME_CLICKED = 1;
19 | private final int ACTION_CLICKED = 2;
20 | private final int CONTENT_CLICKED = 3;
21 | private final String TAG = MainActivity.class.getSimpleName();
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | textViewWithoutLink = (TextView) findViewById(R.id.multi_action_textview);
28 | textViewWithoutLinkFewClickable = (TextView) findViewById(R.id.multi_action_textview_link_few);
29 | textViewWithLink = (TextView) findViewById(R.id.multi_action_textview_link);
30 |
31 | myMultiActionClickListener = new MyMultiActionClickListener();
32 | multiActionTextViewWithoutLinkALLClickable();
33 | multiActionTextViewWithoutLinkFewClickable();
34 | multiActionTextViewWithLink();
35 | }
36 |
37 | private void multiActionTextViewWithoutLinkALLClickable() {
38 | String name = "User Name";
39 | String action = "Action";
40 | String contentName = "Content Name";
41 | SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
42 | stringBuilder.append(name);
43 | stringBuilder.append(" ");
44 | stringBuilder.append(action);
45 | stringBuilder.append(" ");
46 | stringBuilder.append(contentName);
47 | int startSpan = 0;
48 | int endSpan = name.length();
49 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
50 | // name click
51 | InputObject nameClick = new InputObject();
52 | nameClick.setStartSpan(startSpan);
53 | nameClick.setEndSpan(endSpan);
54 | nameClick.setStringBuilder(stringBuilder);
55 | nameClick
56 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
57 | nameClick.setOperationType(NAME_CLICKED);
58 | MultiActionTextView.addActionOnTextViewWithoutLink(nameClick);
59 |
60 | // action click
61 | endSpan = endSpan + 1;
62 | startSpan = endSpan;
63 | endSpan = endSpan + action.length();
64 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
65 | InputObject actionClick = new InputObject();
66 | actionClick.setStartSpan(startSpan);
67 | actionClick.setEndSpan(endSpan);
68 | actionClick.setStringBuilder(stringBuilder);
69 | actionClick
70 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
71 | actionClick.setOperationType(ACTION_CLICKED);
72 | MultiActionTextView.addActionOnTextViewWithoutLink(actionClick);
73 |
74 | // content name click
75 | endSpan = endSpan + 1;
76 | startSpan = endSpan;
77 | endSpan = endSpan + contentName.length();
78 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
79 | InputObject contentClick = new InputObject();
80 | contentClick.setStartSpan(startSpan);
81 | contentClick.setEndSpan(endSpan);
82 | contentClick.setStringBuilder(stringBuilder);
83 | contentClick
84 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
85 | contentClick.setOperationType(CONTENT_CLICKED);
86 | MultiActionTextView.addActionOnTextViewWithoutLink(contentClick);
87 |
88 | // final step
89 | MultiActionTextView.setSpannableText(textViewWithoutLink,
90 | stringBuilder, Color.RED);
91 | }
92 |
93 | private void multiActionTextViewWithoutLinkFewClickable() {
94 | String name = "User Name";
95 | String action = "Action";
96 | String contentName = "Content Name";
97 | SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
98 | stringBuilder.append(name);
99 | stringBuilder.append(" ");
100 | stringBuilder.append(action);
101 | stringBuilder.append(" ");
102 | stringBuilder.append(contentName);
103 | int startSpan = 0;
104 | int endSpan = name.length();
105 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
106 | // name click
107 | InputObject nameClick = new InputObject();
108 | nameClick.setStartSpan(startSpan);
109 | nameClick.setEndSpan(endSpan);
110 | nameClick.setStringBuilder(stringBuilder);
111 | nameClick
112 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
113 | nameClick.setOperationType(NAME_CLICKED);
114 | MultiActionTextView.addActionOnTextViewWithoutLink(nameClick);
115 |
116 | // content name click
117 | endSpan = endSpan + 2+ action.length();
118 | startSpan = endSpan;
119 | endSpan = endSpan + contentName.length();
120 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
121 | InputObject contentClick = new InputObject();
122 | contentClick.setStartSpan(startSpan);
123 | contentClick.setEndSpan(endSpan);
124 | contentClick.setStringBuilder(stringBuilder);
125 | contentClick
126 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
127 | contentClick.setOperationType(CONTENT_CLICKED);
128 | MultiActionTextView.addActionOnTextViewWithoutLink(contentClick);
129 |
130 | // final step
131 | MultiActionTextView.setSpannableText(textViewWithoutLinkFewClickable,
132 | stringBuilder, Color.RED);
133 | }
134 |
135 | private void multiActionTextViewWithLink() {
136 | String name = "User Name";
137 | String action = "Action";
138 | String contentName = "Content Name";
139 | SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
140 | stringBuilder.append(name);
141 | stringBuilder.append(" ");
142 | stringBuilder.append(action);
143 | stringBuilder.append(" ");
144 | stringBuilder.append(contentName);
145 | int startSpan = 0;
146 | int endSpan = name.length();
147 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
148 | // name click
149 | InputObject nameClick = new InputObject();
150 | nameClick.setStartSpan(startSpan);
151 | nameClick.setEndSpan(endSpan);
152 | nameClick.setStringBuilder(stringBuilder);
153 | nameClick
154 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
155 | nameClick.setOperationType(NAME_CLICKED);
156 | MultiActionTextView.addActionOnTextViewWithLink(nameClick);
157 |
158 | // content name click
159 | endSpan = endSpan + 2+ action.length();
160 | startSpan = endSpan;
161 | endSpan = endSpan + contentName.length();
162 | Log.d(TAG, " start : endspan::" + startSpan + " : " + endSpan);
163 | InputObject contentClick = new InputObject();
164 | contentClick.setStartSpan(startSpan);
165 | contentClick.setEndSpan(endSpan);
166 | contentClick.setStringBuilder(stringBuilder);
167 | contentClick
168 | .setMultiActionTextviewClickListener(myMultiActionClickListener);
169 | contentClick.setOperationType(CONTENT_CLICKED);
170 | MultiActionTextView.addActionOnTextViewWithLink(contentClick);
171 |
172 | // final step
173 | MultiActionTextView.setSpannableText(textViewWithLink,
174 | stringBuilder, Color.RED);
175 | }
176 |
177 | class MyMultiActionClickListener implements
178 | MultiActionTextviewClickListener {
179 |
180 | @Override
181 | public void onTextClick(InputObject inputObject) {
182 | int operation = inputObject.getOperationType();
183 | String operationType = "";
184 | switch (operation) {
185 | case NAME_CLICKED:
186 | operationType = "Name Clicked";
187 | break;
188 |
189 | case ACTION_CLICKED:
190 | operationType = "Action Clicked";
191 | break;
192 |
193 | case CONTENT_CLICKED:
194 | operationType = "Content Clicked";
195 | break;
196 |
197 | }
198 | Toast.makeText(getApplicationContext(), operationType,
199 | Toast.LENGTH_LONG).show();
200 | }
201 | }
202 | }
203 |
--------------------------------------------------------------------------------