Patch Messaging Character Counter

From WebOS Internals

Jump to: navigation, search


Character Counter

Contents

Introduction

One of the features I liked about my old Treo was the character counter built-in to the messaging application. I thought it would be useful on the Pre, so I modified the messaging application to show the current character count. I made this a separate page from the other modifications because it requires many code changes. Maybe the other messaging modifications could be rolled into this page as well.

Procedure

Note: Works in webOS 1.2, HOWEVER, line numbers are entirely incorrect, so currently the only way of doing it is manually patching based on the context of the surrounding lines. Take note not to use the main CharacterCounter.js mods in the main patch, but the subsection underneath.

Run the following commands:

In this example, I have the patch file located in my home directory under patches

cd /
sudo patch -p0 --backup-if-mismatch < ~/patches/charcounter.patch

This is what you should see if it ran properly:

patching file /usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
patching file /usr/palm/applications/com.palm.app.messaging/app/controllers/compose-assistant.js
patching file /usr/palm/applications/com.palm.app.messaging/app/utilities/CharacterCounter.js
patching file /usr/palm/applications/com.palm.app.messaging/app/views/chatview/chatview-scene.html
patching file /usr/palm/applications/com.palm.app.messaging/app/views/compose/compose-scene.html
patching file /usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css

These modifications will require LunaSysMgr to be restarted. A rescan will not work. After you've run the commands above, run one more command:

pkill LunaSysMgr

charcounter.patch

diff -ur /usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js /usr/palm/app-modified/com.palm.app.messaging/app/controllers/chatview-assistant.js
--- /usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js	2009-07-18 00:22:14.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/app/controllers/chatview-assistant.js	2009-07-23 23:13:19.000000000 -0500
@@ -160,6 +160,11 @@
 				segmentCountContainer: this.controller.get('segmentCounterContainer'),
 				segmentCountElement: this.controller.get('segmentCounter'),
 				setTextFieldValueFn: this.setTextFieldValue.bind(this)
+			},
+			charCounter: {
+				charCountContainer: this.controller.get('charCounterContainer'),
+				charCountElement: this.controller.get('charCounter'),
+				setTextFieldValueFn: this.setTextFieldValue.bind(this)
 			}
 		};
 
diff -ur /usr/palm/applications/com.palm.app.messaging/app/controllers/compose-assistant.js /usr/palm/app-modified/com.palm.app.messaging/app/controllers/compose-assistant.js
--- /usr/palm/applications/com.palm.app.messaging/app/controllers/compose-assistant.js	2009-07-18 00:22:14.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/app/controllers/compose-assistant.js	2009-07-23 23:14:11.000000000 -0500
@@ -140,6 +140,11 @@
 			segmentCountContainer: this.controller.get('segmentCounterContainer'),
 			segmentCountElement: this.controller.get('segmentCounter'),
 			setTextFieldValueFn: this.setTextFieldValue.bind(this)
+		},
+		charCounter: {
+			charCountContainer: this.controller.get('charCounterContainer'),
+			charCountElement: this.controller.get('charCounter'),
+			setTextFieldValueFn: this.setTextFieldValue.bind(this)
 		}
 	};
 
diff -ur /usr/palm/applications/com.palm.app.messaging/app/utilities/CharacterCounter.js /usr/palm/app-modified/com.palm.app.messaging/app/utilities/CharacterCounter.js
--- /usr/palm/applications/com.palm.app.messaging/app/utilities/CharacterCounter.js	2009-07-18 00:22:14.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/app/utilities/CharacterCounter.js	2009-07-23 23:47:32.000000000 -0500
@@ -39,6 +39,10 @@
 				containerElement: null,
 				valueElement: null
 			};
+			var charCounterUI = {
+				containerElement: null,
+				valueElement: null
+			};
 
 
 			// TODO: eventually we might want to implement some cleverness that counts
@@ -185,6 +189,20 @@
 				}
 			};
 
+			var setCurrentCharCount = function(newCharCount) {
+				if(charCounterUI.valueElement)
+					charCounterUI.valueElement.update(newCharCount);
+				if(charCounterUI.containerElement) {
+					if (newCharCount == 0) {
+						if (charCounterUI.containerElement.visible())
+							charCounterUI.containerElement.hide();
+					} else {
+						if (!charCounterUI.containerElement.visible())
+							charCounterUI.containerElement.show();
+					}
+				}
+			};
+			
 			return {
 
 				init: function(controller,platform,textElement,params) {
@@ -265,7 +283,13 @@
 								setTextFieldValueFn = params.segmentCounter.setTextFieldValueFn;
 							}						
 						}
-
+						if(params.charCounter) {
+							charCounterUI.containerElement = params.charCounter.charCountContainer;
+							charCounterUI.valueElement = params.charCounter.charCountElement;
+							if(params.charCounter.setTextFieldValueFn) {
+								setTextFieldValueFn = params.charCounter.setTextFieldValueFn;
+							}						
+						}
 					}					
 				},
 
@@ -304,6 +328,7 @@
 					var rawCharacterData = getRawCharacterData();
 					var messageData = parseMessage(rawCharacterData.message,rawCharacterData.count,_maxLength,true);
 					adjustedCharacterCount = messageData.adjustedCharacterCount;
+					setCurrentCharCount(rawCharacterData.count);
 					if (_maxLength > 0)
 						setOverLimit(messageData.isOverLimit);
 					setCurrentSegmentCount(messageData.segmentCount);				
diff -ur /usr/palm/applications/com.palm.app.messaging/app/views/chatview/chatview-scene.html /usr/palm/app-modified/com.palm.app.messaging/app/views/chatview/chatview-scene.html
--- /usr/palm/applications/com.palm.app.messaging/app/views/chatview/chatview-scene.html	2009-07-18 00:22:14.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/app/views/chatview/chatview-scene.html	2009-07-23 23:16:55.000000000 -0500
@@ -22,6 +22,10 @@
 			<div id="messageContainer" class='palm-row'>
 				<div class="palm-row-wrapper textfield-group focused">
 					<div class="title">
+						<div id="charCounterContainer">
+							<div id="charCounter">
+							</div>
+						</div>
 						<div id="attachmentContainer" style="display: none;">
 							<div id="cancelAttachment">
 							</div>
diff -ur /usr/palm/applications/com.palm.app.messaging/app/views/compose/compose-scene.html /usr/palm/app-modified/com.palm.app.messaging/app/views/compose/compose-scene.html
--- /usr/palm/applications/com.palm.app.messaging/app/views/compose/compose-scene.html	2009-07-18 00:22:14.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/app/views/compose/compose-scene.html	2009-07-23 23:17:14.000000000 -0500
@@ -6,6 +6,10 @@
 		<div id="messageContainer" class='palm-row'>
 			<div class="palm-row-wrapper textfield-group focused">
 				<div class="title">
+					<div id="charCounterContainer">
+						<div id="charCounter">
+						</div>
+					</div>
 					<div id="attachmentContainer" style="display: none;">
 						<div id="cancelAttachment">
 						</div>
diff -ur /usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css /usr/palm/app-modified/com.palm.app.messaging/stylesheets/messaging.css
--- /usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css	2009-07-18 00:22:22.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/stylesheets/messaging.css	2009-07-23 23:19:25.000000000 -0500
@@ -837,6 +837,23 @@
 #messageContainer.palm-row .icon.right {
 	height: 61px;
 }
+#messageContainer #charCounterContainer {
+	line-height: 20px;
+	display:block;
+	height: 20px;
+	border-width: 0px 10px 0px 9px;
+	-webkit-border-image: url(../images/message-segment-badge.png) 0 10 0 9 stretch stretch;
+	position: absolute;
+	z-index: 3;
+	top: 2px;
+	left: 2px;
+}
+#messageContainer #charCounterContainer #charCounter {
+	font-size: 12px;
+	font-weight: bold;
+	color: #679BC2;
+	margin: 0px -4px 3px -3px;
+}
 #messageContainer #attachmentContainer {
 	position: relative;
 	margin-top:10px;


Post os1.1 update, you will need to swap in the following for the utilities/CharacterCounter.js section: (mod confirmed working by tcurtin, 7/24/09)

diff -ur /usr/palm/applications/com.palm.app.messaging/app/utilities/CharacterCounter.js /usr/palm/app-modified/com.palm.app.messaging/app/utilities/CharacterCounter.js
--- /usr/palm/applications/com.palm.app.messaging/app/utilities/CharacterCounter.js	2009-07-18 00:22:14.000000000 -0500
+++ /usr/palm/app-modified/com.palm.app.messaging/app/utilities/CharacterCounter.js	2009-07-24 12:20:12.000000000 -0500
@@ -39,6 +39,11 @@
                                containerElement: null,
                                valueElement: null
                        };
+                       var charCounterUI = {
+                               containerElement: null,
+                               valueElement: null
+                       };
+
 
 
                        // TODO: eventually we might want to implement some cleverness that counts
@@ -51,6 +56,10 @@
                                var message = textAreaElement.value;
                                return {count:message.length, message:message};
                        };
+                       var charCounterUI = {
+                               containerElement: null,
+                               valueElement: null
+                       };
 
                        var setOverLimit = function(isOver) {
                                if (isOver) {
@@ -185,6 +194,21 @@
                                }
                        };
 
+                       var setCurrentCharCount = function(newCharCount) {
+                               if(charCounterUI.valueElement)
+                                       charCounterUI.valueElement.update(newCharCount);
+                               if(charCounterUI.containerElement) {
+                                       if (newCharCount == 0) {
+                                               if (charCounterUI.containerElement.visible())
+                                                       charCounterUI.containerElement.hide();
+                                       } else {
+                                               if (!charCounterUI.containerElement.visible())
+                                                       charCounterUI.containerElement.show();
+                                       }
+                               }
+                       };
+
+
                        return {
 
                                init: function(controller,platform,textElement,params) {
@@ -265,7 +289,13 @@
                                                                setTextFieldValueFn = params.segmentCounter.setTextFieldValueFn;
                                                        }
                                                }
-
+                                               if(params.charCounter) {
+                                                       charCounterUI.containerElement = params.charCounter.charCountContainer;
+                                                       charCounterUI.valueElement = params.charCounter.charCountElement;
+                                                       if(params.charCounter.setTextFieldValueFn) {
+                                                               setTextFieldValueFn = params.charCounter.setTextFieldValueFn;
+                                                       }
+                                               }
                                        }
                                },
 
@@ -304,6 +334,7 @@
                                        var rawCharacterData = getRawCharacterData();
                                        var messageData = parseMessage(rawCharacterData.message,rawCharacterData.count,_maxLength,true);
                                        adjustedCharacterCount = messageData.adjustedCharacterCount;
+                                       setCurrentCharCount(rawCharacterData.count);
                                        if (_maxLength > 0)
                                                setOverLimit(messageData.isOverLimit);
                                        setCurrentSegmentCount(messageData.segmentCount);

Notes

Patch Messaging Forward Messages will not work when applying this patch. Please take a look into this. -thatdude

If this patch is applied manually it works fine with the Patch Messaging Forward Messages patch. -NetWhiz

This patch keeps giving me an error that it is malformed at line 15, and i cannot seem to fix it. Is there an already made patch file that doesnt involve me cutting and pasting? -paraplegicemu

not sure if this will help.. but I too was getting the malformed stuff.. probably because of the several other patches to the files before this one, so I just manually added all the +++ (green) lines to the files where they should have been and everything is working perfectly. quite helpful when trying to get into one text msg. - Justin

2011/03/03 - Please resubmit for 2.1! This patch was one of my favorites. Thanks - djwhitey

Acknowledgements

HattCzech

Personal tools
Google AdSense