1616
1717package com .google .android .accessibility .talkback .imagecaption ;
1818
19- import static com .google .android .accessibility .utils .caption .ImageCaptionUtils .CaptionType .OCR ;
20-
2119import android .accessibilityservice .AccessibilityService ;
2220import android .graphics .Bitmap ;
23- import android .text .TextUtils ;
2421import androidx .annotation .NonNull ;
2522import androidx .core .view .accessibility .AccessibilityNodeInfoCompat ;
26- import com .google .android .accessibility .utils .Filter ;
27- import com .google .android .accessibility .utils .StringBuilderUtils ;
2823import com .google .android .accessibility .utils .caption .Result ;
29- import com .google .android .accessibility .utils .ocr .OcrController ;
30- import com .google .android .accessibility .utils .ocr .OcrController .OcrListener ;
31- import com .google .android .accessibility .utils .ocr .OcrInfo ;
32- import java .util .ArrayList ;
3324import java .util .List ;
3425
3526/**
36- * A {@link CaptionRequest} for performing OCR (optical character recognition) to recognize text
37- * from the screenshot.
27+ * A stub class for performing OCR (optical character recognition) to recognize text from the screenshot.
3828 */
39- public class CharacterCaptionRequest extends CaptionRequest implements OcrListener {
29+ public class CharacterCaptionRequest extends CaptionRequest {
4030
41- private final OcrController ocrController ;
4231 private final Bitmap screenCapture ;
4332
44- /** This object takes ownership of node, caller should not recycle. */
33+ /** Stub constructor */
4534 public CharacterCaptionRequest (
4635 int requestId ,
4736 AccessibilityService service ,
@@ -51,44 +40,13 @@ public CharacterCaptionRequest(
5140 @ NonNull OnErrorListener onErrorListener ,
5241 boolean isUserRequested ) {
5342 super (requestId , node , onFinishListener , onErrorListener , isUserRequested );
54- ocrController = new OcrController (this , /* needCropScreenshot= */ false );
5543 this .screenCapture = screenCapture ;
5644 }
5745
5846 /**
59- * Captures screen and performs ocr(optical character recognition) to recognize text for the given
60- * node.
47+ * Stub method to capture screen and perform OCR (optical character recognition) to recognize text for the given node.
6148 */
6249 @ Override
63- public void perform () {
64- final List <OcrInfo > ocrInfos = new ArrayList <>();
65- ocrInfos .add (new OcrInfo (node ));
66- onCaptionStart ();
67- ocrController .recognizeTextForNodes (
68- screenCapture , ocrInfos , /* selectionBounds= */ null , Filter .node (node -> true ));
69-
70- runTimeoutRunnable ();
71- }
72-
73- @ Override
74- public void onOcrStarted () {}
75-
76- @ Override
77- public void onOcrFinished (List <OcrInfo > ocrResults ) {
78- stopTimeoutRunnable ();
79- if (ocrResults == null ) {
80- onError (ERROR_TEXT_RECOGNITION_NO_RESULT );
81- return ;
82- }
50+ public void perform () {}
8351
84- List <CharSequence > texts = new ArrayList <>();
85- for (OcrInfo ocrResult : ocrResults ) {
86- String text = OcrController .getTextFromBlocks (ocrResult .getTextBlocks ());
87- if (TextUtils .isEmpty (text )) {
88- continue ;
89- }
90- texts .add (text );
91- }
92- onCaptionFinish (Result .create (OCR , StringBuilderUtils .getAggregateText (texts )));
93- }
9452}
0 commit comments