Skip to content

Adds Voicer support to Slideshow #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.deitel.slideshow"
minSdkVersion 8
minSdkVersion 21
targetSdkVersion 8
}

Expand All @@ -16,4 +16,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

dependencies {
compile (project(':voicer')) {
transitive = false
}
}
}
48 changes: 44 additions & 4 deletions app/src/main/java/com/deitel/slideshow/Slideshow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SlideshowInfo> 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
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include ':app'
include ':app', ':voicer'

project (':voicer').projectDir = new File('../voicerframework/voicer')