Accessibility changes in contact list to read username and last message, and some content description in layout images, and focus order for physical keyboard

This commit is contained in:
fidojones 2014-02-13 21:56:29 +01:00
parent ff85d74b85
commit 76b176de75
7 changed files with 122 additions and 0 deletions

View file

@ -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,76 @@ 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);
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(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(AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(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 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;
}
}

View file

@ -642,6 +642,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) {

View file

@ -8,6 +8,7 @@
<org.telegram.ui.Views.BackupImageView
android:layout_height="48dp"
android:layout_width="48dp"
android:contentDescription="@string/Avatar"
android:id="@+id/chat_avatar_image"/>
</RelativeLayout>

View file

@ -40,6 +40,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/chat_list_view"
android:nextFocusDown="@+id/chat_text_edit"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:clipToPadding="false"
@ -124,22 +125,26 @@
android:src="@drawable/ic_msg_panel_smiles"
android:layout_width="48dp"
android:layout_height="48dp"
android:nextFocusRight="@+id/chat_text_edit"
android:layout_marginTop="2dp"
android:paddingTop="1dp"
android:scaleType="centerInside"
android:paddingLeft="4dp"
android:id="@+id/chat_smile_button"
android:contentDescription="@string/Emoticons"
android:layout_alignBottom="@+id/chat_text_edit"/>
<ImageButton
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="2dp"
android:nextFocusLeft="@+id/chat_text_edit"
android:scaleType="centerInside"
android:id="@+id/chat_send_button"
android:layout_alignParentRight="true"
android:layout_alignBottom="@+id/chat_text_edit"
android:enabled="false"
android:contentDescription="@string/SendMessage"
android:src="@drawable/send_button_states"
android:background="@android:color/transparent"/>
@ -147,6 +152,7 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="2dp"
android:nextFocusLeft="@+id/chat_text_edit"
android:scaleType="centerInside"
android:id="@+id/chat_audio_send_button"
android:layout_alignParentRight="true"
@ -154,6 +160,7 @@
android:enabled="false"
android:src="@drawable/mic_button_states"
android:paddingRight="4dp"
android:contentDescription="@string/SendAudio"
android:background="@android:color/transparent"/>
<EditText
@ -162,6 +169,9 @@
android:id="@+id/chat_text_edit"
android:layout_toRightOf="@id/chat_smile_button"
android:layout_toLeftOf="@id/chat_send_button"
android:nextFocusLeft="@+id/chat_smile_button"
android:nextFocusUp="@+id/chat_list_view"
android:nextFocusRight="@+id/chat_audio_send_button"
android:layout_marginTop="2dp"
android:maxLines="4"
android:minHeight="48dp"

View file

@ -19,6 +19,7 @@
<ImageButton
android:id="@+id/settings_change_avatar_button"
android:background="@drawable/photo_spinner"
android:contentDescription="@string/ChangeAvatar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
@ -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"/>
</LinearLayout>

View file

@ -348,6 +348,17 @@
<string name="Page7Message">Los mensajes de <![CDATA[<b>Telegram</b>]]> están fuertemente<![CDATA[<br/>]]>cifrados y se pueden autodestruir.</string>
<string name="StartMessaging">Empieza a conversar</string>
<!--Accessibility strings-->
<string name="ContactUnAllocated">Contacto no asignado</string>
<string name="LastMessage">último mensaje</string>
<string name="Emoticons">emoticonos</string>
<string name="SendMessage">enviar mensaje</string>
<string name="RecordAudio">grabar audio</string>
<string name="SendAudio">enviar audio</string>
<string name="Avatar">avatar</string>
<string name="ChangeAvatar">cambiar avatar</string>
<string name="EditName">editar nombre</string>
<!--Don't change this! Not for localization!-->
<string name="CacheTag">CACHE_TAG</string>
</resources>

View file

@ -348,6 +348,18 @@
<string name="Page7Message"><![CDATA[<b>Telegram</b>]]> messages are heavily encrypted<![CDATA[<br/>]]>and can self-destruct</string>
<string name="StartMessaging">Start Messaging</string>
<!--Accessibility strings-->
<string name="ContactUnAllocated">Contact unallocated</string>
<string name="LastMessage">last message</string>
<string name="Emoticons">emoticons</string>
<string name="SendMessage">send message</string>
<string name="RecordAudio">record audio</string>
<string name="SendAudio">send audio</string>
<string name="Avatar">avatar</string>
<string name="ChangeAvatar">change avatar</string>
<string name="EditName">edit name</string>
<!--Don't change this! Not for localization!-->
<string name="CacheTag">CACHE_TAG</string>
</resources>