From e23e2c07780ca729c14a147dc2dd49898c78f97d Mon Sep 17 00:00:00 2001 From: fidojones Date: Thu, 6 Feb 2014 11:07:25 +0100 Subject: [PATCH] Accessibility changes in contact list to read username and last message, and some content descripiton in layout images Signed-off-by: fidojones --- .../java/org/telegram/ui/Cells/BaseCell.java | 58 +++++++++++++++++++ .../org/telegram/ui/Cells/DialogCell.java | 3 + .../main/res/layout/chat_header_layout.xml | 1 + .../src/main/res/layout/chat_layout.xml | 2 + .../main/res/layout/settings_name_layout.xml | 2 + .../src/main/res/values-es/strings.xml | 9 +++ TMessagesProj/src/main/res/values/strings.xml | 9 +++ 7 files changed, 84 insertions(+) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/BaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/BaseCell.java index 4c17a2699..7dd1d2b51 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/BaseCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/BaseCell.java @@ -10,20 +10,31 @@ package org.telegram.ui.Cells; import android.content.Context; import android.graphics.drawable.Drawable; +import android.os.Build; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; +import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityNodeInfo; + +import org.telegram.messenger.R; public class BaseCell extends View { + private CharSequence currentNameMessage; + public BaseCell(Context context) { super(context); + tryInstallAccessibilityDelegate(); } public BaseCell(Context context, AttributeSet attrs) { super(context, attrs); + tryInstallAccessibilityDelegate(); } public BaseCell(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + tryInstallAccessibilityDelegate(); } protected void setDrawableBounds(Drawable drawable, int x, int y) { @@ -33,4 +44,51 @@ public class BaseCell extends View { protected void setDrawableBounds(Drawable drawable, int x, int y, int w, int h) { drawable.setBounds(x, y, x + w, y + h); } + + public void tryInstallAccessibilityDelegate() { + if (Build.VERSION.SDK_INT < 14) { + return; + } + + setAccessibilityDelegate(new AccessibilityDelegate() { + @Override + public void onInitializeAccessibilityNodeInfo(View host,AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host,info); + // We called the super implementation to let super classes set + // appropriate info properties. Then we add our properties + // (checkable and checked) which are not supported by a super class. + // Very often you will need to add only the text on the custom view. + CharSequence text = getTextAccessibility(); + if (!TextUtils.isEmpty(text)) { + info.setText(text); + } + } + + @Override + public void onPopulateAccessibilityEvent(View host,AccessibilityEvent event) { + super.onPopulateAccessibilityEvent(host,event); + // We called the super implementation to populate its text to the + // event. Then we add our text not present in a super class. + // Very often you will need to add only the text on the custom view. + CharSequence text = getTextAccessibility(); + if (!TextUtils.isEmpty(text)) { + event.getText().add(text); + } + } + }); + } + + public CharSequence getTextAccessibility() { + if (!TextUtils.isEmpty(currentNameMessage)) { + return currentNameMessage; + }else{ + return getResources().getString(R.string.ContactUnAllocated); + } + } + + public void setTextAccessibility(CharSequence text){ + + currentNameMessage = text; + } + } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java index 6adea8808..5b0720e1e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java @@ -638,6 +638,9 @@ public class DialogCell extends BaseCell { CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - Utilities.dp(12), TextUtils.TruncateAt.END); messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + //Set string for Accessibility events to speak contact list + setTextAccessibility(nameStringFinal+" "+getResources().getString(R.string.LastMessage)+": "+messageString); + double widthpx = 0; float left = 0; if (Utilities.isRTL) { diff --git a/TMessagesProj/src/main/res/layout/chat_header_layout.xml b/TMessagesProj/src/main/res/layout/chat_header_layout.xml index 8fb0b2f79..72e313630 100644 --- a/TMessagesProj/src/main/res/layout/chat_header_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_header_layout.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/chat_layout.xml b/TMessagesProj/src/main/res/layout/chat_layout.xml index 3098d1a7d..d518b9400 100644 --- a/TMessagesProj/src/main/res/layout/chat_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_layout.xml @@ -129,6 +129,7 @@ android:scaleType="centerInside" android:paddingLeft="4dp" android:id="@+id/chat_smile_button" + android:contentDescription="@string/Emoticons" android:layout_alignBottom="@+id/chat_text_edit"/> @@ -68,6 +69,7 @@ android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/ic_edit" + android:contentDescription="@string/EditName" android:layout_marginTop="4dp"/> \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index 32dbcbfde..3ce933b22 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -348,6 +348,15 @@ Los mensajes de Telegram]]> están fuertemente]]>cifrados y se pueden autodestruir. Empieza a conversar + + Contacto no asignado + último mensaje + emoticonos + enviar mensaje + avatar + cambiar avatar + editar nombre + CACHE_TAG \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 3b850b794..dcd991a20 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -348,6 +348,15 @@ Telegram]]> messages are heavily encrypted]]>and can self-destruct Start Messaging + + Contact unallocated + last message + emoticons + send message + avatar + change avatar + edit name + CACHE_TAG \ No newline at end of file