Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: athena/system/orientation_controller.cc

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/system/orientation_controller.h ('k') | athena/system/public/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "athena/screen/public/screen_manager.h"
6 #include "athena/system/orientation_controller.h"
7 #include "base/bind.h"
8 #include "base/files/file_path_watcher.h"
9 #include "base/files/file_util.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/task_runner.h"
12 #include "chromeos/accelerometer/accelerometer_reader.h"
13
14 namespace athena {
15
16 namespace {
17
18 // Threshold after which to rotate in a given direction.
19 const int kGravityThreshold = 6.0f;
20
21 } // namespace
22
23 OrientationController::OrientationController() {
24 }
25
26 void OrientationController::InitWith(
27 scoped_refptr<base::TaskRunner> blocking_task_runner) {
28 chromeos::AccelerometerReader::GetInstance()->Initialize(
29 blocking_task_runner);
30 chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
31 }
32
33 OrientationController::~OrientationController() {
34 }
35
36 void OrientationController::Shutdown() {
37 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
38 }
39
40 void OrientationController::OnAccelerometerUpdated(
41 const ui::AccelerometerUpdate& update) {
42 if (!update.has(ui::ACCELEROMETER_SOURCE_SCREEN))
43 return;
44
45 float gravity_x = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).x();
46 float gravity_y = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).y();
47 gfx::Display::Rotation rotation;
48 if (gravity_x < -kGravityThreshold) {
49 rotation = gfx::Display::ROTATE_270;
50 } else if (gravity_x > kGravityThreshold) {
51 rotation = gfx::Display::ROTATE_90;
52 } else if (gravity_y < -kGravityThreshold) {
53 rotation = gfx::Display::ROTATE_180;
54 } else if (gravity_y > kGravityThreshold) {
55 rotation = gfx::Display::ROTATE_0;
56 } else {
57 // No rotation as gravity threshold was not hit.
58 return;
59 }
60
61 if (rotation == current_rotation_)
62 return;
63
64 current_rotation_ = rotation;
65 ScreenManager::Get()->SetRotation(rotation);
66 }
67
68 } // namespace athena
OLDNEW
« no previous file with comments | « athena/system/orientation_controller.h ('k') | athena/system/public/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698