Text to speech
// Text to Seech ******************************************
// MainActivity.java
package com.myco.ythuyhhhhfhf;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.net.*;
import android.net.wifi.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.util.*;
import android.speech.tts.*;
import java.util.*;
import android.view.animation.*;
import android.bluetooth.BluetoothManager;
import java.io.IOException;
import android.graphics.fonts.SystemFonts;
public class MainActivity extends Activity
{
Button speek , clear;
EditText edt;
TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt = findViewById(R.id.edt);
speek = findViewById(R.id.speek);
clear = findViewById(R.id.clear);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toas,
(ViewGroup) findViewById(R.id.tText));
Toast tt = new Toast(this);
tt.setDuration(150000000);
tt.setGravity(Gravity.CENTER,0 ,0);
tt.setView(layout);
tt.show();
edt.setText("Gopal Yadav");
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener(){
@Override
public void onInit(int i)
{
if(i==TextToSpeech.SUCCESS){
int lang = textToSpeech.setLanguage(Locale.ENGLISH);
}
}
});
speek.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1)
{
String t= edt.getText().toString();
int spk = textToSpeech.speak(t,textToSpeech.QUEUE_FLUSH,null);
}
});
clear.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1)
{
edt.setText("");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,0,0,"Setting");
menu.add(0,0,0,"Share");
menu.add(0,0,0,"Information");
menu.add(0,0,0,"Exit");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getTitle().toString()){
case "Exit":
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
/*
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
*/
/*
Toast t= Toast.makeText(MainActivity.this,"Long press",Toast.LENGTH_LONG);
// t.setMargin(500,00);
t.setGravity(Gravity.CENTER,0,0);
t.show();
*/
//toas.java***********************************************
package com.myco.ythuyhhhhfhf;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.animation.*;
public class toas extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.toas);
ImageView img = findViewById(R.id.tText);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate);
img.startAnimation(animation);
}
}
// main.xml *********************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingTop="100dp"
android:background="#FFC686FF">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter any text"
android:textSize="30sp"
android:gravity="center"
android:id="@+id/edt"/>
<LinearLayout
android:layout_marginTop="100px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Speek"
android:id="@+id/speek"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="@+id/clear"/>
</LinearLayout>
</LinearLayout>
// toas.xml
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/tText"
android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gopal Yadav Andro"
android:textSize="20dp"
android:background="#FAC3B8"
android:textColor="#6A0BDA"
/>
</LinearLayout>