Bonjour à tous.
je veux utiliser la classe CommandeVocal pour lire un texte écrit sur un AlertDialog.
voilà les classes
**************HelloItemizedOverlay*************
*******************CommandeVocal********************
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 import java.util.ArrayList; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.drawable.Drawable; import android.location.LocationListener; import android.net.Uri; import android.view.MotionEvent; import android.widget.TextView; import android.widget.Toast; import com.google.android.maps.GeoPoint; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.MapView; import com.google.android.maps.OverlayItem; public class HelloItemizedOverlay extends ItemizedOverlay { private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); private Context mContext; /*public HelloItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); // TODO Auto-generated constructor stub }*/ public HelloItemizedOverlay(Drawable defaultMarker, Context context) { // super(defaultMarker); super(boundCenterBottom(defaultMarker)); mContext = context; // HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(defaultMarker, mContext); } @Override protected OverlayItem createItem(int i) { // TODO Auto-generated method stub return mOverlays.get(i); } @Override public int size() { // TODO Auto-generated method stub return mOverlays.size(); } public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); } @Override protected boolean onTap(int index) { OverlayItem item = mOverlays.get(index); AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); dialog.setTitle(item.getTitle()); dialog.setMessage(item.getSnippet()); dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onCancel(DialogInterface dialog) {} @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.setPositiveButton("photo", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(mContext,HelloGallery.class); mContext.startActivity(intent); } //public void onCancel(DialogInterface dialog) {} }); dialog.setNeutralButton("Ecouter", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub //probleme ///inviter la classe CommandeVocal pour lire le texte " item.getSnippet() " au lieu de "hello" decrite dans la classe CommadeVocal Intent intent = new Intent(mContext,CommandeVocal.class); mContext.startActivity(intent); } }); dialog.show(); return true; } }
sachant que j'ai déclaré les activités dans le Manifest.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 import java.util.Locale; import java.util.Random; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.util.Log; import android.view.View; import android.widget.Button; public class CommandeVocal extends Activity implements TextToSpeech.OnInitListener { private static final String TAG = "TextToSpeechDemo"; private TextToSpeech mTts; private Button mAgainButton; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.text_to_speech); //instanciation de l'objet *mTts mTts = new TextToSpeech(this, this // TextToSpeech.OnInitListener ); mAgainButton = (Button) findViewById(R.id.again_button); mAgainButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ParleandroidPhone(); } }); } @Override public void onDestroy() { // Don't forget to shutdown! if (mTts != null) { mTts.stop(); mTts.shutdown(); } super.onDestroy(); } // Implements TextToSpeech.OnInitListener. public void onInit(int status) { // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (status == TextToSpeech.SUCCESS) { //le choix de la langue ici français int result = mTts.setLanguage(Locale.FRANCE); // vérification ici si cette langue est supporté par le terminal et si elle existe if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { //renvoi une erreur sur la console logcat. Log.e(TAG, "Language is not available."); } else { mAgainButton.setEnabled(true); // Greet the user. ParleandroidPhone(); } } else { // Initialization failed. Log.e(TAG, "Could not initialize TextToSpeech."); } } private static final Random RANDOM = new Random(); private static final String[] HELLOS = { "Bonjour", "Comment tu vas", "abidjan", "Je t'aime Guy" }; private void ParleandroidPhone() { // choix aléatoire de la phrase. int helloLength = HELLOS.length; String hello = HELLOS[RANDOM.nextInt(helloLength)]; mTts.speak(hello,TextToSpeech.QUEUE_FLUSH,null); } }
merci
Partager