应用阅读电子邮件

时间:2017-04-05 13:32:59

标签: android android-actionbar android-xml text-to-speech

我正在尝试开发可以大声阅读电子邮件的应用程序,问题是如何创建一个TEXT TO SPEECH工具或可以让我接触到电子邮件正文的东西?我的意思是如何将文本与语音代码连接到电子邮件正文中的文本以便大声朗读?

我已经尝试了第一步并通过网络视图打开电子邮件并在其中创建浮动操作按钮但问题是该按钮刚刚出现,我登录后它没有显示,我该如何修复这个?这段代码:

WebView webView;
ProgressBar progressBar;


FloatingActionButton fab_plus,fab_voice,fab_pause;
Animation FabOpen,FabClose,FabRClookwise,FabRanticlookwise;
boolean isOpen=false;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test1_main);


    webView=(WebView)findViewById(R.id.webView);
    progressBar=(ProgressBar)findViewById(R.id.progressBar);


    fab_plus=(FloatingActionButton)findViewById(R.id.fab_plus);
    fab_voice=(FloatingActionButton)findViewById(R.id.fab_voice);
    fab_pause=(FloatingActionButton)findViewById(R.id.fab_pause);
    FabOpen= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_open);
    FabClose= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_close);
    FabRClookwise= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_clockwise);
    FabRanticlookwise= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_anticlockwise);


    fab_plus.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if(isOpen){

                fab_pause.startAnimation(FabClose);
                fab_voice.startAnimation(FabClose);
                fab_plus.startAnimation(FabRanticlookwise);
                fab_voice.setClickable(false);
                fab_pause.setClickable(false);
                isOpen=false;

            }

            else {
                fab_pause.startAnimation(FabOpen);
                fab_voice.startAnimation(FabOpen);
                fab_plus.startAnimation(FabRanticlookwise);
                fab_voice.setClickable(true);
                fab_pause.setClickable(true);
                isOpen=true;

            }
        }
    });

    if(savedInstanceState != null){

        webView.restoreState(savedInstanceState);
    }
    else{
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(false);
        webView.getSettings().setBuiltInZoomControls(false);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.setBackgroundColor(Color.WHITE);

        webView.setWebViewClient(new ourViewClient());
        webView.setWebChromeClient(new WebChromeClient(){

            public void onProgressChanged(WebView view ,int progress){

                progressBar.setProgress(progress);
                if(progress<100 && progressBar.getVisibility()== ProgressBar.GONE){


                    progressBar.setVisibility(ProgressBar.VISIBLE);
                }
                if(progress==100){

                    progressBar.setVisibility(ProgressBar.GONE);
                }
            }



        });

        String data=getIntent().getDataString();
        if(Intent.ACTION_VIEW.equals(getIntent().getAction())){


            webView.loadUrl(data);
        }

        else{

            webView.loadUrl("https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1#identifier");
        }

    }
}

public class ourViewClient extends WebViewClient {


    @Override
    public boolean shouldOverrideUrlLoading(WebView v, String url) {
        if(url.contains("accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1#identifier")){




            v.loadUrl(url);
            CookieManager.getInstance().setAcceptCookie(true);

        }
        else{

            Uri uri = Uri.parse(url);
            startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW,uri),"choose broweser"));

        }

        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }
}


@Override
public void onBackPressed() {

    if(webView.canGoBack()){

        webView.goBack();
    }else {
        super.onBackPressed();
    }
}


@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    webView.saveState(outState);
}

}

对于XML:

<?xml version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="64dp"
android:paddingRight="64dp"
android:paddingTop="16dp"

tools:context="com.example.test1.Test1MainActivity">


<ProgressBar

    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="8dp" />

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<android.support.design.widget.FloatingActionButton
    android:layout_width="308dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="@dimen/fab_margin_right"
    android:layout_marginBottom="160dp"
    android:src="@drawable/ic_action_puse"
    android:elevation="6dp"
    android:id="@+id/fab_pause"
    app:pressedTranslationZ="12dp"
    app:backgroundTint="@color/fab2_color"
    android:visibility="invisible"
    />

<android.support.design.widget.FloatingActionButton
    android:layout_width="308dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="@dimen/fab_margin_right"
    android:layout_marginBottom="110dp"
    android:src="@drawable/ic_action_voice"
    android:elevation="6dp"
    android:id="@+id/fab_voice"
    app:pressedTranslationZ="12dp"
    app:backgroundTint="@color/fab1_color"
    android:visibility="invisible"
    />


<android.support.design.widget.FloatingActionButton
    android:layout_width="308dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="@dimen/fab_margin_right"
    android:layout_marginBottom="50dp"
    android:src="@drawable/ic_action_plus"
    android:elevation="6dp"
    android:id="@+id/fab_plus"
    app:pressedTranslationZ="12dp"
    />

第二个我想通过TTS算法在这些按钮中执行操作,如上所述,但我不知道我如何达到电子邮件正文中的文本...这样可以做这样的应用程序吗?

1 个答案:

答案 0 :(得分:0)

使用google Speech api 转到下面的TTS链接 https://developer.android.com/reference/android/speech/tts/TextToSpeech.html