Skip to content

Commit faaaef0

Browse files
committed
Merge branch 'master' into codex/create-building.md-for-codename-one-o1r15v
2 parents 462ebb3 + 6227382 commit faaaef0

File tree

7 files changed

+174
-18
lines changed

7 files changed

+174
-18
lines changed

CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.codename1.io.tar.TarEntry;
4343
import com.codename1.io.tar.TarInputStream;
4444
import com.codename1.l10n.L10NManager;
45+
import com.codename1.ui.Component;
4546
import com.codename1.location.LocationManager;
4647
import com.codename1.media.Media;
4748
import com.codename1.media.MediaManager;
@@ -8549,4 +8550,18 @@ public void postMessage(MessageEvent message) {
85498550
public Boolean isDarkMode() {
85508551
return null;
85518552
}
8553+
8554+
/**
8555+
* Manually announces text to native accessibility services, associating the announcement with
8556+
* a specific component when possible. Components are typically announced automatically when
8557+
* focused; this hook allows platforms to expose announcements triggered outside the normal
8558+
* focus lifecycle. The default implementation is a no-op.
8559+
*
8560+
* @param cmp the component related to this announcement or {@code null} for the root context
8561+
* @param text the message to announce
8562+
*/
8563+
public void announceForAccessibility(Component cmp, String text) {
8564+
// No-op by default. Platforms that support accessibility announcements
8565+
// should override this method.
8566+
}
85528567
}

CodenameOne/src/com/codename1/ui/CN.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,27 @@ public static void vibrate(int duration) {
327327
Display.impl.vibrate(duration);
328328
}
329329

330+
/**
331+
* Manually announces text to native accessibility services, optionally associating the
332+
* announcement with a specific component. Normally, components are announced automatically
333+
* when they receive focus; this method is for cases where an announcement is needed outside
334+
* the normal focus lifecycle.
335+
*
336+
* @param cmp the component related to this announcement or {@code null} for the root view
337+
* @param text the message to announce
338+
*/
339+
public static void announceForAccessibility(Component cmp, String text) {
340+
Display.impl.announceForAccessibility(cmp, text);
341+
}
342+
343+
/**
344+
* Convenience overload to announce text without specifying a component.
345+
*
346+
* @param text the message to announce
347+
*/
348+
public static void announceForAccessibility(String text) {
349+
Display.impl.announceForAccessibility(null, text);
350+
}
330351

331352
/**
332353
* Returns true if we are currently in the event dispatch thread.

CodenameOne/src/com/codename1/ui/Component.java

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,9 @@ public class Component implements Animation, StyleListener, Editable {
481481
EventDispatcher longPressListeners;
482482
private EventDispatcher stateChangeListeners;
483483
boolean isUnselectedStyle;
484-
484+
485485
private String tooltip;
486+
private String accessibilityText;
486487

487488
boolean isDragAndDropInitialized() {
488489
return dragAndDropInitialized;
@@ -2138,6 +2139,10 @@ public Label getLabelForComponent() {
21382139
*/
21392140
void focusGainedInternal() {
21402141
startComponentLableTicker();
2142+
String text = getAccessibilityText();
2143+
if (text != null && text.length() > 0) {
2144+
announceForAccessibility(text);
2145+
}
21412146
}
21422147

21432148

@@ -2156,7 +2161,7 @@ void stopComponentLableTicker() {
21562161
}
21572162

21582163
/**
2159-
* Callback allowing a developer to track wheh the component gains focus
2164+
* Callback allowing a developer to track when the component gains focus
21602165
*/
21612166
protected void focusGained() {
21622167
}
@@ -8158,6 +8163,55 @@ public void paint(Graphics g) {
81588163
}
81598164
}
81608165

8166+
/**
8167+
* Manually announces text to native accessibility services, associating the announcement
8168+
* with this component when possible. Screen readers normally announce a component
8169+
* automatically when it gains focus; this helper is for additional announcements that
8170+
* should occur outside of focus changes.
8171+
*
8172+
* @param text the message to announce
8173+
*/
8174+
public void announceForAccessibility(String text) {
8175+
Display.getInstance().announceForAccessibility(this, text);
8176+
}
8177+
8178+
/**
8179+
* Sets the text that describes this component to assistive technologies.
8180+
* When the component gains focus, this text will be announced
8181+
* automatically.
8182+
*
8183+
* @param text accessibility description
8184+
*/
8185+
public void setAccessibilityText(String text) {
8186+
this.accessibilityText = text;
8187+
}
8188+
8189+
/**
8190+
* Returns the text that describes this component to assistive technologies.
8191+
* If no text was set explicitly, this method attempts to derive a
8192+
* description from the component's label or content.
8193+
*
8194+
* @return accessibility description or {@code null} if none
8195+
*/
8196+
public String getAccessibilityText() {
8197+
if (accessibilityText != null) {
8198+
return accessibilityText;
8199+
}
8200+
if (componentLabel != null) {
8201+
String t = componentLabel.getText();
8202+
if (t != null && t.length() > 0) {
8203+
return t;
8204+
}
8205+
}
8206+
if (this instanceof TextHolder) {
8207+
String t = ((TextHolder) this).getText();
8208+
if (t != null && t.length() > 0) {
8209+
return t;
8210+
}
8211+
}
8212+
return null;
8213+
}
8214+
81618215
/**
81628216
* @return the tooltip
81638217
*/

CodenameOne/src/com/codename1/ui/Display.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,28 @@ public void flashBacklight(int duration) {
682682
impl.flashBacklight(duration);
683683
}
684684

685+
/**
686+
* Manually announces text to native accessibility services, optionally associating the
687+
* announcement with a specific component. Most assistive technologies will announce a
688+
* component automatically when it gains focus; this method is intended for situations
689+
* where an announcement should occur independently of focus changes.
690+
*
691+
* @param cmp the component related to this announcement or {@code null} for the root view
692+
* @param text the message to announce
693+
*/
694+
public void announceForAccessibility(Component cmp, String text) {
695+
impl.announceForAccessibility(cmp, text);
696+
}
697+
698+
/**
699+
* Convenience overload to announce text without specifying a component.
700+
*
701+
* @param text the message to announce
702+
*/
703+
public void announceForAccessibility(String text) {
704+
announceForAccessibility(null, text);
705+
}
706+
685707
/**
686708
* Invoking the show() method of a form/dialog while the user is editing
687709
* text in the native text box can have several behaviors: SHOW_DURING_EDIT_IGNORE,

Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
import android.util.Log;
5858
import android.util.TypedValue;
5959
import android.view.KeyEvent;
60-
import android.view.View;
61-
import android.view.ViewGroup;
62-
import android.view.Window;
60+
import android.view.View;
61+
import android.view.ViewGroup;
62+
import android.view.Window;
6363
import android.webkit.WebSettings;
6464
import android.webkit.WebView;
6565
import android.webkit.WebViewClient;
@@ -114,8 +114,10 @@
114114
import android.telephony.SmsManager;
115115
import android.telephony.gsm.GsmCellLocation;
116116
import android.text.Html;
117-
import android.view.*;
118-
import android.view.View.MeasureSpec;
117+
import android.view.*;
118+
import android.view.View.MeasureSpec;
119+
import android.view.accessibility.AccessibilityEvent;
120+
import android.view.accessibility.AccessibilityManager;
119121
import android.webkit.*;
120122
import android.widget.*;
121123
import com.codename1.background.BackgroundFetch;
@@ -10794,13 +10796,50 @@ public void run() {
1079410796
return true;
1079510797
}
1079610798

10797-
public boolean isJailbrokenDevice() {
10798-
try {
10799-
Runtime.getRuntime().exec("su");
10800-
return true;
10801-
} catch(Throwable t) {
10802-
com.codename1.io.Log.e(t);
10803-
}
10804-
return false;
10805-
}
10806-
}
10799+
public boolean isJailbrokenDevice() {
10800+
try {
10801+
Runtime.getRuntime().exec("su");
10802+
return true;
10803+
} catch(Throwable t) {
10804+
com.codename1.io.Log.e(t);
10805+
}
10806+
return false;
10807+
}
10808+
10809+
@Override
10810+
public void announceForAccessibility(final Component cmp, final String text) {
10811+
final Activity act = getActivity();
10812+
if (act == null) {
10813+
return;
10814+
}
10815+
act.runOnUiThread(new Runnable() {
10816+
@Override
10817+
public void run() {
10818+
View view = null;
10819+
if (cmp instanceof PeerComponent) {
10820+
Object peer = ((PeerComponent) cmp).getNativePeer();
10821+
if (peer instanceof View) {
10822+
view = (View) peer;
10823+
}
10824+
}
10825+
if (view == null) {
10826+
view = act.getWindow().getDecorView();
10827+
}
10828+
if (view == null) {
10829+
return;
10830+
}
10831+
if (Build.VERSION.SDK_INT >= 16) {
10832+
view.announceForAccessibility(text);
10833+
} else {
10834+
AccessibilityManager manager = (AccessibilityManager) act.getSystemService(Context.ACCESSIBILITY_SERVICE);
10835+
if (manager != null && manager.isEnabled()) {
10836+
AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
10837+
event.getText().add(text);
10838+
event.setSource(view);
10839+
manager.sendAccessibilityEvent(event);
10840+
}
10841+
}
10842+
}
10843+
});
10844+
}
10845+
}

maven/CodeNameOneBuildClient.jar

1.51 MB
Binary file not shown.

maven/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
<source>1.8</source>
333333
<show>protected</show>
334334
<failOnError>false</failOnError>
335+
<doclint>none</doclint>
335336
</configuration>
336337
</plugin>
337338
<plugin>
@@ -398,7 +399,11 @@
398399
<artifactId>maven-javadoc-plugin</artifactId>
399400
<version>3.2.0</version>
400401
<configuration>
401-
<additionalOptions>--allow-script-in-comments</additionalOptions>
402+
<doclint>none</doclint>
403+
<failOnError>false</failOnError>
404+
<additionalOptions>
405+
<additionalOption>--allow-script-in-comments</additionalOption>
406+
</additionalOptions>
402407
</configuration>
403408
</plugin>
404409
<plugin>

0 commit comments

Comments
 (0)