增加 等待弹窗

master
wanghao 3 months ago
parent 9d82b28d85
commit 453d398f81

@ -5,11 +5,13 @@ import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableBoolean;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import com.example.readtext.adapter.MainAdapter;
@ -45,6 +47,12 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressDialog dialog = new ProgressDialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("引擎加载中...");
dialog.show();
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
intent = new Intent(this, ConfigActivity.class);
initAdapter();
@ -57,6 +65,7 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
dialog.dismiss();
// 设置语言为中文
int result = textToSpeech.setLanguage(Locale.CHINA);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
@ -78,7 +87,7 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
adapter1 = new MainAdapter(this, new MyClickInterface() {
@Override
public void onClickCall(int index) {
textToSpeech.speak(list1.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
speech(list1.get(index));
}
@SuppressLint("NotifyDataSetChanged")
@ -93,7 +102,7 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
adapter2 = new MainAdapter(this, new MyClickInterface() {
@Override
public void onClickCall(int index) {
textToSpeech.speak(list2.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
speech(list2.get(index));
}
@SuppressLint("NotifyDataSetChanged")
@ -108,7 +117,7 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
adapter3 = new MainAdapter(this, new MyClickInterface() {
@Override
public void onClickCall(int index) {
textToSpeech.speak(list3.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
speech(list3.get(index));
}
@SuppressLint("NotifyDataSetChanged")
@ -123,7 +132,7 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
adapter4 = new MainAdapter(this, new MyClickInterface() {
@Override
public void onClickCall(int index) {
textToSpeech.speak(list4.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
speech(list4.get(index));
}
@SuppressLint("NotifyDataSetChanged")
@ -141,6 +150,14 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
binding.setAdapter4(adapter4);
}
private void speech(ReadTextBeen readTextBeen) {
int clickNum = readTextBeen.getClickNum();
Log.e("TAG", "onClickCall:" + clickNum);
readTextBeen.setClickNum(clickNum + 1);
readTextBeen.update(readTextBeen.getId());
textToSpeech.speak(readTextBeen.getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
}
// 查询和加载列表
@SuppressLint("NotifyDataSetChanged")
@Override

@ -58,7 +58,7 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.MyViewHolder>
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Log.e("TAG", "onBindViewHolder:运行"+position );
// Log.e("TAG", "onBindViewHolder:运行"+position );
ReadTextBeen readTextBeen = list.get(position);
ItemMainBinding binding = holder.binding;
binding.setItem(readTextBeen);

Loading…
Cancel
Save