Skip to content

Commit

Permalink
[VisionGlass] Add voice search button to Phone UI
Browse files Browse the repository at this point in the history
Added a new Voice Search button to the phone UI. It's only enabled
when the keyboard is shown, i.e., when input is required. Once
clicked the handling of the input is directly managed by the
KeyboardWidget which properly handles the different types of input
(like entering text in a Web page vs entering text in a UI widget).
  • Loading branch information
svillar authored and felipeerias committed Feb 28, 2024
1 parent 97e4bb3 commit 2377bad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,9 @@ public AppServicesProvider getServicesProvider() {
return (AppServicesProvider)getApplication();
}

@Override
public KeyboardWidget getKeyboard() { return mKeyboard; }

private native void addWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateVisibleWidgetsNative();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1496,4 +1496,9 @@ public void onSessionChanged(@NonNull Session aOldSession, @NonNull Session aSes
aOldSession.removeTextInputListener(this);
aSession.addTextInputListener(this);
}

public void simulateVoiceButtonClick() {
mKeyboardVoiceButton.performClick();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ interface WebXRListener {
void updateLocale(@NonNull Context context);
@NonNull
AppServicesProvider getServicesProvider();
KeyboardWidget getKeyboard();
}
5 changes: 2 additions & 3 deletions app/src/main/res/layout/visionglass_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
android:textOn="" />

<ImageButton
android:id="@+id/voice_button"
android:id="@+id/phoneUIVoiceButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/voice_search_tooltip"
android:scaleType="fitCenter"
android:src="@drawable/ic_icon_microphone"
android:visibility="invisible"/>
android:src="@drawable/ic_icon_microphone" />
</LinearLayout>

<View
Expand Down
10 changes: 10 additions & 0 deletions app/src/visionglass/java/com/igalia/wolvic/PlatformActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class PlatformActivity extends ComponentActivity implements SensorEventLi
private DisplayManager mDisplayManager;
private Display mPresentationDisplay;
private VisionGlassPresentation mActivePresentation;
private View mVoiceSearchButton;

@SuppressWarnings("unused")
public static boolean filterPermission(final String aPermission) {
Expand Down Expand Up @@ -165,6 +166,9 @@ public void onConnectionChange(boolean b) {
private void initVisionGlassPhoneUI() {
setContentView(R.layout.visionglass_layout);

mVoiceSearchButton = findViewById(R.id.phoneUIVoiceButton);
mVoiceSearchButton.setEnabled(false);

View touchpad = findViewById(R.id.touchpad);
touchpad.setOnClickListener(v -> {
// We don't really need the coordinates of the click because we use the position
Expand Down Expand Up @@ -423,6 +427,7 @@ private class PlatformActivityPluginVisionGlass implements PlatformActivityPlugi

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

// Setup the phone UI callbacks that require access to the WindowManagerDelegate.
Expand All @@ -436,6 +441,11 @@ private void setupPhoneUI() {
mDelegate.setHeadLockEnabled(headlockButton.isChecked());
});

findViewById(R.id.phoneUIVoiceButton).setOnClickListener(v -> {
// Delegate all the voice input handling in the KeyboardWidget which already handles
// all the potential voice input cases.
mDelegate.getKeyboard().simulateVoiceButtonClick();
});
}
}

Expand Down

0 comments on commit 2377bad

Please sign in to comment.