gpt4 book ai didi

android-progressbar - 如何让 TalkBack 读取 Android progressBar 进度?

转载 作者:行者123 更新时间:2023-12-02 02:03:39 26 4
gpt4 key购买 nike

我试图让 TalkBack 阅读进度条上的进度,但运气不佳。关于如何获取该信息以便 TalkBack 可以说出来的任何想法。

谢谢

公共(public)类 MainActivity 扩展 Activity {

Button btnStartProgress;
ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarHandler = new Handler();

private long fileSize = 0;

private String msgProgress ="";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

addListenerOnButton();

}

public void addListenerOnButton() {

btnStartProgress = (Button) findViewById(R.id.btnStartProgress);
btnStartProgress.setOnClickListener(
new OnClickListener() {

@Override
public void onClick(View v) {

// prepare for a progress bar dialog
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();

//reset progress bar status
progressBarStatus = 0;

//reset filesize
fileSize = 0;

new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {

// process some tasks
progressBarStatus = doSomeTasks();


// your computer is too fast, sleep 1 second
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
//progressBar.setMessage(msgProgress);

}
});
}

// ok, file is downloaded,
if (progressBarStatus >= 100) {

// sleep 2 seconds, so that you can see the 100%
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

// close the progress bar dialog
progressBar.dismiss();
}
}
}).start();

}

});

}

// file download simulator... a really simple
public int doSomeTasks() {

while (fileSize <= 1000000) {

fileSize++;

if (fileSize == 250000) {
//msgProgress = "25 Percent";
return 25;
} else if (fileSize == 500000) {
//msgProgress = "50 Percent";
return 50;
} else if (fileSize == 750000) {
//msgProgress = "75 Percent";
return 75;
} else if (fileSize == 900000) {
//msgProgress = "90 Percent";
return 90;
}
// ...add your own

}

return 100;

}

最佳答案

如前所述here可以创建一个 TTS 单例并添加一个方法来检查是否启用了辅助功能。每次显示进度条时调用方法 say(message)。

我是这样实现的

public class AccessibilityUtil implements OnInitListener {

private static final String TAG = AccessibilityUtil.class.getSimpleName();

private static final AccessibilityUtil instance = new AccessibilityUtil();
private String message;
private static TextToSpeech tts=null;

private static boolean isAccesibilityEnabled() {

return ((AccessibilityManager) TmcPlusApplication.getInstance()
.getSystemService(
TmcPlusApplication.getInstance().ACCESSIBILITY_SERVICE))
.isEnabled();


}

public static AccessibilityUtil getInstance() {

return instance;
}

public void say(String message) {

if (isAccesibilityEnabled()) {
if (tts == null) {
this.message = message;
tts = new TextToSpeech(<Your Application object>.getInstance(), (AccessibilityUtil) instance);
} else {
speakOut();
}
}
}

@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
Log.v(TAG, "Text to speech enabled");
speakOut();
}

}

/*
* utters the message String
*/
private void speakOut() {
Log.v(TAG, "Text to speech the word "+message);
tts.speak(message, TextToSpeech.QUEUE_FLUSH, null);
}

public void stopTTS() {
if (tts != null) {
tts.shutdown();
tts.stop();
tts = null;
}
}

当你调用 say() 方法时,它看起来像这样

AccessibilityUtil.getInstance().say("Loading. Please wait");

希望对你有帮助

关于android-progressbar - 如何让 TalkBack 读取 Android progressBar 进度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16021624/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com