Skip to content

Commit

Permalink
add function to set voice interaction status.
Browse files Browse the repository at this point in the history
BUG=b:62705237
TEST=manually start stop voice interaciton.

Review-Url: https://codereview.chromium.org/2946193002
Cr-Commit-Position: refs/heads/master@{#482376}
  • Loading branch information
muyuanli authored and Commit Bot committed Jun 26, 2017
1 parent 7dc10a6 commit d766f2e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ash/app_list/app_list_delegate_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void AppListDelegateImpl::OnAppListVisibilityChanged(bool visible,
if (app_list::features::IsFullscreenAppListEnabled()) {
aura::Window* root_window =
Shell::Get()->GetRootWindowForDisplayId(display_id);
Shell::Get()->OnAppListVisibilityChanged(visible, root_window);
Shell::Get()->NotifyAppListVisibilityChanged(visible, root_window);
}
}

Expand Down
4 changes: 2 additions & 2 deletions ash/app_list/app_list_presenter_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void AppListPresenterDelegate::Init(app_list::AppListView* view,
void AppListPresenterDelegate::OnShown(int64_t display_id) {
is_visible_ = true;
aura::Window* root_window = Shell::GetRootWindowForDisplayId(display_id);
Shell::Get()->OnAppListVisibilityChanged(is_visible_, root_window);
Shell::Get()->NotifyAppListVisibilityChanged(is_visible_, root_window);
}

void AppListPresenterDelegate::OnDismissed() {
Expand All @@ -146,7 +146,7 @@ void AppListPresenterDelegate::OnDismissed() {
is_visible_ = false;
aura::Window* root_window =
RootWindowController::ForTargetRootWindow()->GetRootWindow();
Shell::Get()->OnAppListVisibilityChanged(is_visible_, root_window);
Shell::Get()->NotifyAppListVisibilityChanged(is_visible_, root_window);
}

void AppListPresenterDelegate::UpdateBounds() {
Expand Down
16 changes: 16 additions & 0 deletions ash/shelf/app_list_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

namespace ash {

constexpr uint8_t kVoiceInteractionRunningAlpha = 255; // 100% alpha
constexpr uint8_t kVoiceInteractionNotRunningAlpha = 138; // 54% alpha

AppListButton::AppListButton(InkDropButtonListener* listener,
ShelfView* shelf_view,
Shelf* shelf)
Expand Down Expand Up @@ -245,13 +248,21 @@ void AppListButton::PaintButtonContents(gfx::Canvas* canvas) {
fg_flags.setAntiAlias(true);
fg_flags.setStyle(cc::PaintFlags::kStroke_Style);
fg_flags.setColor(kShelfIconColor);

if (chromeos::switches::IsVoiceInteractionEnabled())
// active: 100% alpha, inactive: 54% alpha
fg_flags.setAlpha(voice_interaction_running_
? kVoiceInteractionRunningAlpha
: kVoiceInteractionNotRunningAlpha);

const float thickness = std::ceil(ring_thickness_dp * dsf);
const float radius = std::ceil(ring_outer_radius_dp * dsf) - thickness / 2;
fg_flags.setStrokeWidth(thickness);
// Make sure the center of the circle lands on pixel centers.
canvas->DrawCircle(circle_center, radius, fg_flags);

if (chromeos::switches::IsVoiceInteractionEnabled()) {
fg_flags.setAlpha(255);
const float kCircleRadiusDp = 5.f;
fg_flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawCircle(circle_center, std::ceil(kCircleRadiusDp * dsf),
Expand Down Expand Up @@ -291,4 +302,9 @@ void AppListButton::OnAppListVisibilityChanged(bool shown,
OnAppListDismissed();
}

void AppListButton::OnVoiceInteractionStatusChanged(bool running) {
voice_interaction_running_ = running;
SchedulePaint();
}

} // namespace ash
3 changes: 3 additions & 0 deletions ash/shelf/app_list_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ASH_EXPORT AppListButton : public views::ImageButton,
// ShellObserver overrides:
void OnAppListVisibilityChanged(bool shown,
aura::Window* root_window) override;
void OnVoiceInteractionStatusChanged(bool running) override;

// True if the app list is currently showing for this display.
// This is useful because other IsApplistVisible functions aren't per-display.
Expand All @@ -75,6 +76,8 @@ class ASH_EXPORT AppListButton : public views::ImageButton,

VoiceInteractionOverlay* voice_interaction_overlay_;

bool voice_interaction_running_ = false;

DISALLOW_COPY_AND_ASSIGN(AppListButton);
};

Expand Down
9 changes: 7 additions & 2 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,17 @@ void Shell::SetIsBrowserProcessWithMash() {
g_is_browser_process_with_mash = true;
}

void Shell::OnAppListVisibilityChanged(bool visible,
aura::Window* root_window) {
void Shell::NotifyAppListVisibilityChanged(bool visible,
aura::Window* root_window) {
for (auto& observer : shell_observers_)
observer.OnAppListVisibilityChanged(visible, root_window);
}

void Shell::NotifyVoiceInteractionStatusChanged(bool running) {
for (auto& observer : shell_observers_)
observer.OnVoiceInteractionStatusChanged(running);
}

////////////////////////////////////////////////////////////////////////////////
// Shell, private:

Expand Down
4 changes: 3 additions & 1 deletion ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ class ASH_EXPORT Shell : public SessionObserver,
// Used to provide better error messages for Shell::Get() under mash.
static void SetIsBrowserProcessWithMash();

void OnAppListVisibilityChanged(bool visible, aura::Window* root_window);
void NotifyAppListVisibilityChanged(bool visible, aura::Window* root_window);

void NotifyVoiceInteractionStatusChanged(bool running);

private:
FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
Expand Down
3 changes: 3 additions & 0 deletions ash/shell_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class ASH_EXPORT ShellObserver {
// Called when a new KeyboardController is created.
virtual void OnKeyboardControllerCreated() {}

// Called when voice interaction session starts / finishes.
virtual void OnVoiceInteractionStatusChanged(bool running) {}

// Called at the end of Shell::Init.
virtual void OnShellInitialized() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ void ArcVoiceInteractionFrameworkService::CaptureFullscreen(
base::Passed(std::move(old_layer_owner))));
}

void ArcVoiceInteractionFrameworkService::SetVoiceInteractionRunning(
bool running) {
ash::Shell::Get()->NotifyVoiceInteractionStatusChanged(running);
}

void ArcVoiceInteractionFrameworkService::OnMetalayerClosed() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
CallAndResetMetalayerCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ArcVoiceInteractionFrameworkService
void CaptureFullscreen(const CaptureFullscreenCallback& callback) override;
void OnMetalayerClosed() override;
void SetMetalayerEnabled(bool enabled) override;
void SetVoiceInteractionRunning(bool running) override;

bool IsMetalayerSupported();
void ShowMetalayer(const base::Closure& closed);
Expand Down
7 changes: 5 additions & 2 deletions components/arc/common/voice_interaction_framework.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Next MinVersion: 6
// Next MinVersion: 7

module arc.mojom;

import "screen_rect.mojom";

// Handles voice interaction queries from Android.
// Next method ID: 4
// Next method ID: 5
interface VoiceInteractionFrameworkHost {
// Returns a screenshot of currently focused window or empty array if
// no window is focused. |data| represents the image encoded in JPEG
Expand All @@ -25,6 +25,9 @@ interface VoiceInteractionFrameworkHost {

// Enables/disables screenshot taking.
[MinVersion=3]SetMetalayerEnabled@3(bool enabled);

// Notifies Chrome whether voice interaction session is running.
[MinVersion=6]SetVoiceInteractionRunning@4(bool running);
};

// Connects with Android system server.
Expand Down

0 comments on commit d766f2e

Please sign in to comment.