Skip to content

Commit

Permalink
Up update Mozilla Speech v2 (#3340)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jun 10, 2020
1 parent c93ffcd commit c7dd36c
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 117 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ dependencies {
annotationProcessor deps.room.compiler

// Android Components
implementation deps.mozilla_speech
implementation deps.mozilla_speech.library
implementation deps.mozilla_speech.utils
implementation deps.android_components.telemetry
implementation deps.android_components.browser_errorpages
implementation deps.android_components.browser_search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.content.Context;
import android.content.res.Configuration;

import com.mozilla.speechlibrary.SpeechService;

import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.browser.Services;
Expand All @@ -30,6 +32,7 @@ public class VRBrowserApplication extends Application implements AppServicesProv
private Places mPlaces;
private Accounts mAccounts;
private DownloadsManager mDownloadsManager;
private SpeechService mSpeechService;

@Override
public void onCreate() {
Expand All @@ -46,6 +49,7 @@ protected void onActivityCreate() {
mServices = new Services(this, mPlaces);
mAccounts = new Accounts(this);
mDownloadsManager = new DownloadsManager(this);
mSpeechService = new SpeechService(this);
}

@Override
Expand Down Expand Up @@ -94,4 +98,9 @@ public Accounts getAccounts() {
public DownloadsManager getDownloadsManager() {
return mDownloadsManager;
}

@Override
public SpeechService getSpeechService() {
return mSpeechService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ public class DownloadJob {
private String mFilename;
private String mTitle;
private String mDescription;
private String mOutputPath;

public static DownloadJob create(@NonNull String uri, @Nullable String contentType,
long contentLength, @Nullable String filename) {
return create(uri, contentType, contentLength, filename, null);
}

public static DownloadJob create(@NonNull String uri, @Nullable String contentType,
long contentLength, @Nullable String filename,
@Nullable String outputPath) {
DownloadJob job = new DownloadJob();
job.mUri = uri;
job.mContentType = contentType;
Expand All @@ -37,6 +44,7 @@ public static DownloadJob create(@NonNull String uri, @Nullable String contentTy
}
job.mTitle = filename;
job.mDescription = filename;
job.mOutputPath = outputPath;
return job;
}

Expand Down Expand Up @@ -156,4 +164,9 @@ public String getDescription() {
public void setDescription(String mDescription) {
this.mDescription = mDescription;
}

@Nullable
public String getOutputPath() {
return mOutputPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mozilla.speechlibrary.utils.StorageUtils;

import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.utils.UrlUtils;

Expand Down Expand Up @@ -98,6 +100,10 @@ private void stopUpdates() {
}

public void startDownload(@NonNull DownloadJob job) {
startDownload(job, SettingsStore.getInstance(mContext).getDownloadsStorage());
}

public void startDownload(@NonNull DownloadJob job, @SettingsStore.Storage int storageType) {
if (!URLUtil.isHttpUrl(job.getUri()) && !URLUtil.isHttpsUrl(job.getUri())) {
notifyDownloadError("Cannot download non http/https files", job.getFilename());
return;
Expand All @@ -110,16 +116,21 @@ public void startDownload(@NonNull DownloadJob job) {
request.setMimeType(job.getContentType());
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setVisibleInDownloadsUi(false);
if (SettingsStore.getInstance(mContext).getDownloadsStorage() == SettingsStore.EXTERNAL) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, job.getFilename());
if (job.getOutputPath() == null) {
if (storageType == SettingsStore.EXTERNAL) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, job.getFilename());

} else {
String outputPath = getOutputPathForJob(job);
if (outputPath == null) {
notifyDownloadError("Cannot create output file", job.getFilename());
return;
} else {
String outputPath = getOutputPathForJob(job);
if (outputPath == null) {
notifyDownloadError("Cannot create output file", job.getFilename());
return;
}
request.setDestinationUri(Uri.parse(outputPath));
}
request.setDestinationUri(Uri.parse(outputPath));

} else {
request.setDestinationUri(Uri.parse("file://" + job.getOutputPath()));
}

if (mDownloadManager != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mozilla.vrbrowser.ui.widgets;

import com.mozilla.speechlibrary.SpeechService;

import org.mozilla.vrbrowser.AppExecutors;
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.Places;
Expand All @@ -19,5 +21,5 @@ public interface AppServicesProvider {
BitmapCache getBitmapCache();
Accounts getAccounts();
DownloadsManager getDownloadsManager();

SpeechService getSpeechService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1257,18 +1257,13 @@ public void onGlobalFocusChanged(View oldFocus, View newFocus) {

// VoiceSearch Delegate
@Override
public void OnVoiceSearchResult(String aTranscription, float confidance) {
public void OnVoiceSearchResult(String aTranscription, float confidence) {
if (aTranscription != null && !aTranscription.isEmpty()) {
handleText(aTranscription);
}
exitVoiceInputMode();
}

@Override
public void OnVoiceSearchCanceled() {
exitVoiceInputMode();
}

@Override
public void OnVoiceSearchError() {
exitVoiceInputMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public void onDrmButtonClicked() {
// VoiceSearch Delegate

@Override
public void OnVoiceSearchResult(String transcription, float confidance) {
public void OnVoiceSearchResult(String transcription, float confidence) {
mBinding.navigationBarNavigation.urlBar.handleURLEdit(transcription);
}

Expand Down

0 comments on commit c7dd36c

Please sign in to comment.