diff --git a/app/build.gradle b/app/build.gradle index df7f914..64e1b9b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "com.deitel.slideshow" - minSdkVersion 8 + minSdkVersion 21 targetSdkVersion 8 } @@ -16,4 +16,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } + + dependencies { + compile (project(':voicer')) { + transitive = false + } + } } diff --git a/app/src/main/java/com/deitel/slideshow/Slideshow.java b/app/src/main/java/com/deitel/slideshow/Slideshow.java index 1bccd39..7415ed0 100644 --- a/app/src/main/java/com/deitel/slideshow/Slideshow.java +++ b/app/src/main/java/com/deitel/slideshow/Slideshow.java @@ -16,7 +16,9 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Looper; import android.provider.MediaStore; +import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -33,13 +35,23 @@ import android.widget.TextView; import android.widget.Toast; -public class Slideshow extends ListActivity { +import com.miyagilabs.voicer.InitListener; +import com.miyagilabs.voicer.Voicer; +import com.miyagilabs.voicer.VoicerFactory; +import com.miyagilabs.voicer.annotation.Voice; +import com.miyagilabs.voicer.tts.SpeakerException; +import com.miyagilabs.voicer.tts.VirtualAssistant; +import com.miyagilabs.voicer.util.VoicerListener; +import com.miyagilabs.voicer.widget.Toaster; + +public class Slideshow extends ListActivity implements InitListener { // used when adding slideshow name as an extra to an Intent public static final String NAME_EXTRA = "NAME"; static List slideshowList; // List of slideshows private ListView slideshowListView; // this ListActivity's ListView private SlideshowAdapter slideshowAdapter; // adapter for the ListView + private Voicer mVoicer; // called when the activity is first created @Override @@ -60,6 +72,18 @@ public void onCreate(Bundle savedInstanceState) { builder.show(); } // end method onCreate + @Override + protected void onResume() { + VoicerFactory.fakeVoicer(this, this); + super.onResume(); + } + + @Override + protected void onPause() { + mVoicer.shutdown(); + super.onPause(); + } + // create the Activity's menu from a menu resource XML file @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -75,6 +99,12 @@ public boolean onCreateOptionsMenu(Menu menu) { // handle choice from options menu @Override public boolean onOptionsItemSelected(MenuItem item) { + newSlideShow(); + return super.onOptionsItemSelected(item); // call super's method + } // end method onOptionsItemSelected + + @Voice(commands = "new slideshow") + private void newSlideShow() { // get a reference to the LayoutInflater service LayoutInflater inflater = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE); @@ -119,9 +149,7 @@ public void onClick(DialogInterface dialog, int whichButton) { inputDialog.setNegativeButton(R.string.button_cancel, null); inputDialog.show(); - - return super.onOptionsItemSelected(item); // call super's method - } // end method onOptionsItemSelected + } // refresh ListView after slideshow editing is complete @Override @@ -131,6 +159,18 @@ protected void onActivityResult(int requestCode, int resultCode, slideshowAdapter.notifyDataSetChanged(); // refresh the adapter } // end method onActivityResult + @Override + public void onInit(Voicer voicer, int status) { + mVoicer = voicer; + mVoicer.register(this); + mVoicer.addVoicerListener(new Toaster(this)); + try { + mVoicer.addVoicerListener(new VirtualAssistant(Slideshow.this)); + } catch (SpeakerException | InterruptedException ex) { + Log.e(getClass().getName(), null, ex); + } + } + // Class for implementing the "ViewHolder pattern" // for better ListView performance private static class ViewHolder { diff --git a/settings.gradle b/settings.gradle index e7b4def..f3b2588 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,3 @@ -include ':app' +include ':app', ':voicer' + +project (':voicer').projectDir = new File('../voicerframework/voicer') \ No newline at end of file