Skip to content
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

[Vision Glass] Voice button can be used for search and text input #1449

Merged
merged 3 commits into from
Jun 27, 2024
Merged
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
23 changes: 15 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ apply from: "$project.rootDir/tools/gradle/versionCode.gradle"
apply plugin: 'kotlin-android'
apply plugin: "org.mozilla.telemetry.glean-gradle-plugin"

// Apply AGConnect plugin only for Hvr builds
if (getGradle().getStartParameter().getTaskRequests().toString() =~ /(h|H)vr/) {
// Apply AGConnect plugin only for Huawei builds
if (getGradle().getStartParameter().getTaskRequests().toString() =~ /[Hh]vr/
|| getGradle().getStartParameter().getTaskRequests().toString() =~ /[Vv]isionglass/) {
apply plugin: 'com.huawei.agconnect'
}

Expand Down Expand Up @@ -327,6 +328,7 @@ android {
arguments "-DVISIONGLASS=ON"
}
}
buildConfigField "String", "HVR_API_KEY", "\"${getHVRApiKey()}\""
buildConfigField "Float", "DEFAULT_DENSITY", "1.5f"
buildConfigField "Float", "DEFAULT_WINDOW_DISTANCE", "1.0f"
}
Expand Down Expand Up @@ -550,7 +552,8 @@ android {

visionglass {
java.srcDirs = [
'src/visionglass/java'
'src/visionglass/java',
'src/hvr/java/com/igalia/wolvic/speech'
]
}

Expand Down Expand Up @@ -722,6 +725,10 @@ dependencies {

// Vission Glass
visionglassImplementation fileTree(dir: "${project.rootDir}/third_party/aliceimu/", include: ['*.aar'])
visionglassImplementation fileTree(dir: "${project.rootDir}/third_party/hvr", include: ['*.jar'])
visionglassImplementation 'com.huawei.agconnect:agconnect-core-harmony:1.1.0.300'
visionglassImplementation 'com.huawei.agconnect:agconnect-core:1.9.1.301'
visionglassImplementation 'com.huawei.hms:ml-computer-voice-asr:3.1.0.300'

// HTC Vive
if (!gradle.startParameter.taskNames.isEmpty() &&
Expand Down Expand Up @@ -806,21 +813,21 @@ android.applicationVariants.configureEach { variant ->
buildConfigField 'String', 'MLS_TOKEN', '""'
}

// HVR packages for mainland china must only use HVR speech recognition system.
def platform = variant.productFlavors.get(0).name
def store = variant.productFlavors.get(3).name
if (platform.toLowerCase().startsWith('hvr') && store == "mainlandChina") {
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.HUAWEI_ASR }"
}

// Default homepages for China releases.
// Default homepages and voice recognition services for China releases.
// HVR packages for mainland china must only use HVR speech recognition system.
if (store == "mainlandChina") {
if (platform.toLowerCase().startsWith('hvr')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/index.html"'
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.HUAWEI_ASR }"
} else if (platform.toLowerCase().startsWith('visionglass')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/hvg.html"'
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.HUAWEI_ASR }"
} else if (platform.toLowerCase().startsWith('picoxr')) {
variant.resValue 'string', 'HOMEPAGE_URL', '"https://wolvic.com/zh/start/pico.html"'
variant.buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.MEETKAI }"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public abstract class PlatformActivityPlugin {
public interface PlatformActivityPluginListener {
void onPlatformScrollEvent(float distanceX, float distanceY);
}
abstract void onKeyboardVisibilityChange(boolean isVisible);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that we can remove this, I've never really liked it.

abstract void onVideoAvailabilityChange();
void registerListener(PlatformActivityPluginListener listener) {
if (mListeners == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,6 @@ public void updateWidget(final Widget aWidget) {
view.setVisibility(visible ? View.VISIBLE : View.GONE);
}

if (aWidget == mKeyboard && mPlatformPlugin != null) {
mPlatformPlugin.onKeyboardVisibilityChange(visible);
}

for (UpdateListener listener: mWidgetUpdateListeners) {
listener.onWidgetUpdate(aWidget);
}
Expand Down Expand Up @@ -1934,8 +1930,6 @@ public void setControllersVisible(final boolean aVisible) {
@Override
public void keyboardDismissed() {
mNavigationBar.showVoiceSearch();
if (mPlatformPlugin != null)
mPlatformPlugin.onKeyboardVisibilityChange(false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class SpeechServices {
// These classes must implement the SpeechRecognizer interface and provide a constructor
// that takes a Context as its only parameter.
public static final String MEETKAI = "com.igalia.wolvic.speech.MKSpeechRecognizer";
public static final String HUAWEI_ASR = "com.igalia.wolvic.HVRSpeechRecognizer";
public static final String HUAWEI_ASR = "com.igalia.wolvic.speech.HVRSpeechRecognizer";

@StringDef(value = {MEETKAI, HUAWEI_ASR})
@interface Service {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public void stopVoiceSearch() {

@Override
public void show(@ShowFlags int aShowFlags) {
if (mApplication.getSpeechRecognizer() == null) {
Log.e(LOGTAG, "Speech recognizer not available");
return;
}

if (!mApplication.getSpeechRecognizer().shouldDisplayStoreDataPrompt() ||
SettingsStore.getInstance(getContext()).isSpeechDataCollectionEnabled() ||
SettingsStore.getInstance(getContext()).isSpeechDataCollectionReviewed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.igalia.wolvic.utils.LocaleUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class VoiceSearchLanguageOptionsView extends SettingsView {
Expand All @@ -44,7 +45,7 @@ protected void updateUI() {
LayoutInflater inflater = LayoutInflater.from(getContext());
SpeechRecognizer speechRecognizer = mWidgetManager.getServicesProvider().getSpeechRecognizer();

mSupportedLanguages = speechRecognizer.getSupportedLanguages();
mSupportedLanguages = (speechRecognizer != null) ? speechRecognizer.getSupportedLanguages() : Collections.emptyList();

// Inflate this data binding layout
mBinding = DataBindingUtil.inflate(inflater, R.layout.options_language_voice, this, true);
Expand Down
3 changes: 3 additions & 0 deletions app/src/hvr/java/com/igalia/wolvic/PlatformActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
import com.huawei.hvr.LibUpdateClient;
import com.igalia.wolvic.browser.PermissionDelegate;
import com.igalia.wolvic.browser.SettingsStore;
import com.igalia.wolvic.geolocation.HVRLocationManager;
import com.igalia.wolvic.messaging.WolvicHmsMessageService;
import com.igalia.wolvic.speech.SpeechRecognizer;
import com.igalia.wolvic.speech.SpeechServices;
import com.igalia.wolvic.telemetry.HVRTelemetry;
import com.igalia.wolvic.telemetry.TelemetryService;
import com.igalia.wolvic.ui.adapters.SystemNotification;
import com.igalia.wolvic.ui.widgets.SystemNotificationsManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.igalia.wolvic;
package com.igalia.wolvic.geolocation;

import android.content.Context;
import android.location.Location;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.igalia.wolvic;
package com.igalia.wolvic.messaging;

import android.content.Intent;
import android.os.Bundle;
Expand All @@ -15,6 +15,7 @@
import com.huawei.hms.push.HmsMessageService;
import com.huawei.hms.push.HmsMessaging;
import com.huawei.hms.push.RemoteMessage;
import com.igalia.wolvic.BuildConfig;
import com.igalia.wolvic.utils.SystemUtils;

public class WolvicHmsMessageService extends HmsMessageService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.igalia.wolvic;
package com.igalia.wolvic.speech;

import android.app.Activity;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.igalia.wolvic;
package com.igalia.wolvic.telemetry;

import android.content.Context;
import android.os.Bundle;
Expand Down
42 changes: 32 additions & 10 deletions app/src/visionglass/java/com/igalia/wolvic/PlatformActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.SeekBar;
Expand All @@ -39,6 +40,7 @@
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;

import com.huawei.hms.mlsdk.common.MLApplication;
import com.huawei.usblib.DisplayMode;
import com.huawei.usblib.DisplayModeCallback;
import com.huawei.usblib.OnConnectionListener;
Expand All @@ -48,8 +50,11 @@
import com.igalia.wolvic.browser.api.WMediaSession;
import com.igalia.wolvic.browser.api.WSession;
import com.igalia.wolvic.databinding.VisionglassLayoutBinding;
import com.igalia.wolvic.speech.SpeechRecognizer;
import com.igalia.wolvic.speech.SpeechServices;
import com.igalia.wolvic.ui.widgets.UIWidget;
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;
import com.igalia.wolvic.utils.StringUtils;
import com.igalia.wolvic.utils.SystemUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -156,6 +161,8 @@ protected void onCreate(Bundle savedInstanceState) {
usbPermissionFilter.addAction(HUAWEI_USB_PERMISSION);
registerReceiver(mUsbPermissionReceiver, usbPermissionFilter);

initializeAGConnect();

initVisionGlassPhoneUI();

mDisplayManager.registerDisplayListener(mDisplayListener, null);
Expand Down Expand Up @@ -245,8 +252,6 @@ private void initVisionGlassPhoneUI() {

mBinding.realignButton.setOnClickListener(v -> reorientController());

mBinding.voiceSearchButton.setEnabled(false);

Button backButton = findViewById(R.id.back_button);
backButton.setOnClickListener(v -> onBackPressed());

Expand Down Expand Up @@ -503,6 +508,26 @@ private void updateDisplays() {
mViewModel.updateConnectionState(PhoneUIViewModel.ConnectionState.DISPLAY_UNAVAILABLE);
}

private void initializeAGConnect() {
try {
String speechService = SettingsStore.getInstance(this).getVoiceSearchService();
if (SpeechServices.HUAWEI_ASR.equals(speechService) && StringUtils.isEmpty(BuildConfig.HVR_API_KEY)) {
Log.e(LOGTAG, "HVR API key is not available");
return;
}
MLApplication.getInstance().setApiKey(BuildConfig.HVR_API_KEY);
try {
SpeechRecognizer speechRecognizer = SpeechServices.getInstance(this, speechService);
((VRBrowserApplication) getApplicationContext()).setSpeechRecognizer(speechRecognizer);
} catch (Exception e) {
Log.e(LOGTAG, "Exception creating the speech recognizer: " + e);
((VRBrowserApplication) getApplicationContext()).setSpeechRecognizer(null);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public final PlatformActivityPlugin createPlatformPlugin(WidgetManagerDelegate delegate) {
return new PlatformActivityPluginVisionGlass(delegate);
}
Expand All @@ -517,11 +542,6 @@ private class PlatformActivityPluginVisionGlass extends PlatformActivityPlugin {
setupPhoneUI();
}

@Override
public void onKeyboardVisibilityChange(boolean isVisible) {
mBinding.voiceSearchButton.setEnabled(isVisible);
}

@Override
public void onVideoAvailabilityChange() {
boolean isAvailable = mDelegate.getWindows().isVideoAvailable();
Expand Down Expand Up @@ -601,9 +621,11 @@ private void setupPhoneUI() {
});

mBinding.voiceSearchButton.setOnClickListener(v -> {
// Delegate all the voice input handling in the KeyboardWidget which already handles
// all the potential voice input cases.
mDelegate.getKeyboard().simulateVoiceButtonClick();
if (mDelegate.getKeyboard().getVisibility() == View.VISIBLE) {
mDelegate.getKeyboard().simulateVoiceButtonClick();
} else {
mDelegate.getNavigationBar().onVoiceSearchClicked();
}
});

mBinding.muteButton.setOnClickListener(v -> {
Expand Down
Loading