Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15998] Android: Support AttributedString

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-01-15T18:37:34.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0
ComponentsAndroid
Labelsandroid, exalture, module_android, notable, qe-manualtest, qe-testadded
ReporterMostafizur Rahman
AssigneeSunila
Created2013-12-16T10:18:20.000+0000
Updated2015-04-10T16:01:51.000+0000

Description

I saw in Ti SDK 3.2.x we have added new features [AttributedString| http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.iOS.AttributedString] for iOS only. But in native android this features is already available from API level 1 but in titanium this is missing. For more information please visit http://developer.android.com/reference/java/text/AttributedString.html I would like to request for android also.

Comments

  1. Sunila 2014-11-17

    https://github.com/appcelerator/titanium_mobile/pull/6358 Implemented support for attributed string with following properties
  2. Sunila 2014-11-17

    Sample to test
                       var win = Titanium.UI.createWindow({
       	    backgroundColor: '#ddd',
       	});
       
       	win.open();
       
       	var text =  'Bacon ipsum dolor Appcelerator Titanium rocks! sit amet fatback leberkas salami sausage tongue strip steak.';
       
       	var attr = Titanium.UI.createAttributedString({
       	    text: text,
       	    attributes: [
       			//font
       			{
       			    type: Ti.UI.ATTRIBUTE_FONT,
       			    value: {font:{fontSize:50,fontFamily:'Helvetica Neue'}},
       			    range: [0, text.length]
       			},
       	        // Underlines text
       	        {
       	            type: Ti.UI.ATTRIBUTE_UNDERLINES_STYLE,
       	            range: [0, text.length]
       	        },
       	        // Sets a background color
       	        {
       	            type: Ti.UI.ATTRIBUTE_BACKGROUND_COLOR,
       	            value: "red",
       	            range: [text.indexOf('Appcelerator'), ('Appcelerator').length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_BACKGROUND_COLOR,
       	            value: "blue",
       	            range: [text.indexOf('Titanium'), ('Titanium').length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_BACKGROUND_COLOR,
       	            value: "yellow",
       	            range: [text.indexOf('rocks!'), ('rocks!').length]
       	        },
       	        // Sets a foreground color
       	        {
       	            type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
       	            value: "orange",
       	            range: [0,  text.length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
       	            value: "black",
       	            range: [text.indexOf('rocks!'), ('rocks!').length]
       	        },
       	        // Sets strike through
       	        {
       	            type: Ti.UI.ATTRIBUTE_STRIKETHROUGH_STYLE,
       	            range: [text.indexOf('tongue'), ('tongue').length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_LINK,
       	            value: "http://www.appcelerator.com",
       	            range: [text.indexOf('Appcelerator'), ('Appcelerator').length]
       	        }
       	    ]
       	});
       
       	var label = Titanium.UI.createLabel({
       	    left: 20,
       	    right: 20,
       	    height: Titanium.UI.SIZE,
       	    attributedString: attr
       	});
       	
       	var changeStyle = Titanium.UI.createButton({
       		bottom:200,
       	    title: "ChangeStyle"
       	});
       
       	win.add(label);
       	win.add(changeStyle);
       	
       	var attr2 = Titanium.UI.createAttributedString({
       	    text: text,
       	    attributes: [
       			//font
       			{
       			    type: Ti.UI.ATTRIBUTE_FONT,
       			    value: {font:{fontSize:30,fontFamily:'Helvetica Neue'}},
       			    range: [0, text.length]
       			},
       	        // Underlines text
       	        {
       	            type: Ti.UI.ATTRIBUTE_UNDERLINES_STYLE,
       	            range: [0, text.length]
       	        },
       	        // Sets a background color
       	        {
       	            type: Ti.UI.ATTRIBUTE_BACKGROUND_COLOR,
       	            value: "green",
       	            range: [text.indexOf('Appcelerator'), ('Appcelerator').length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_BACKGROUND_COLOR,
       	            value: "red",
       	            range: [text.indexOf('Titanium'), ('Titanium').length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_BACKGROUND_COLOR,
       	            value: "blue",
       	            range: [text.indexOf('rocks!'), ('rocks!').length]
       	        },
       	        // Sets a foreground color
       	        {
       	            type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
       	            value: "black",
       	            range: [0,  text.length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
       	            value: "red",
       	            range: [text.indexOf('rocks!'), ('rocks!').length]
       	        },
       	        // Sets strike through
       	        {
       	            type: Ti.UI.ATTRIBUTE_STRIKETHROUGH_STYLE,
       	            range: [text.indexOf('tongue'), ('tongue').length]
       	        },
       	        {
       	            type: Ti.UI.ATTRIBUTE_LINK,
       	            value: "http://www.appcelerator.com",
       	            range: [text.indexOf('Appcelerator'), ('Appcelerator').length]
       	        }
       	    ]
       	});
       	
       	changeStyle.addEventListener('click', function(){
       		label.attributedString=attr2});
       
  3. Shannon Hicks 2014-11-17

    Is it possible that Ti.UI.ATTRIBUTE_LINK could respond to click events in addition to longpress? It is difficult to explain to users that they see something that looks clickable, but no, they need to longpress it.
  4. Ashraf Abu 2014-11-20

    For parity with iOS, a ticket might need to be created to change the iOS from using the "Ti.UI.iOS" prefix for all methods and variables related to AttributedString.
  5. Chee Kiat Ng 2014-12-05

    Closing this PR https://github.com/appcelerator/titanium_mobile/pull/6358 in favor of https://github.com/appcelerator/titanium_mobile/pull/6409 that adds iOS modifications and documentation fixes.
  6. Vishal Duggal 2015-01-15

    PR https://github.com/appcelerator/titanium_mobile/pull/6463 merged
  7. Eric Wieber 2015-03-11

    Verified fixed using: Titanium SDK 4.0.0.v20150311105810 Studio 4.0.0.201503062102 CLI 3.4.2 Xcode 6.2 Node 0.10.36 On: Galaxy Note 2, Android 4.3
  8. Alex Bernier 2015-04-10

    Custom fonts aren't working: AC-70

JSON Source