PIE: Disable orientation sensor when we don't need it

Orientation sensor always enabled causing some device keep awake and
battery drain. This commit fix this issue.

  * Disable/Enable orientation listener when screen turn off/on if PIE
is enabled.
  * If PIE is disabled, recycle it.

Change-Id: I6bda168b3fd62d9f7047ffc3a3c6bfd08e655543

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
[TEMP] PIE: fix a freezing bug

How to reproduce:
- Enable PIE;
- Toggle between on/of;
- Without close expanded status bar click any tile that use one of this methods -> private void startSettingsActivity(String action) or private void startSettingsActivity(Intent intent);
- System will freez for some seconds and soft reboot;

Solution:
- When deteced PIE mode enabled use a runnable with a less time possible to give time to system colapse panels and perform needed actions

Change-Id: Idc5f112873aa7a31993e7a3c82a1760bb45f8b9b
PIE: Unlock screen on triggering recents

* Bring up unlock panel. Clear all is still hidden when lockscreen is showing.
  Thanks to community for pointing this out.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
Show IME back button in Pie.

Updated Pie to show the alternate back button when an IME is present like the stock navigation bar does.

Change-Id: I97b385904c183a42c6d76a9f238c4b9624668576
Picture: http://i.imgur.com/T0n9bVc.png

EDIT: Fixed whitespace and tabbing
Revert "[TEMP] PIE: fix a freezing bug"

This reverts commit 004b6dc18a6399cb592859188502ed6f0d265f19.
PIE: Use case upgrade and bugfixes:

1.Play with navigation bar height instead of view state. Just set navbar height to 0, even because
  swipe gesture is disabled aswell so it will never be called. This way we handle just one var
  that is height. PhoneWindowManager will take care to calculate decors since it uses height (width
  in landscape) as a param in the calculation.
2.Remove dependency from last systemui flags. Right now before this patch, pie showed no matter if you
  were in forced or native immersive mode. That made us bring a couple of hacks to keep this marriage,
  but there is no need in the end cause PIE is an alternative way you have to enable. That means apps will (should)
  use their own immersive mode at first unless you have already PIE mode on. Not all apps hide navigation bar,
  that means they can not cover the entire screen height (portrait). That's why there is forced mode, to supply this
  cause force the app to go immersive. Last but more important, immersive API works again now :)
3.Cleanup some vars not used anymore, just need observing main immersive mode now.

Change-Id: Ia17bb7ede36d5a14c8508841e32910e6e9595310
Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
SystemUI: Add EdgeGesture service.

Based on code of PieService.

Change-Id: I5c66e2858c8ddbe9faa0e0640c50714c8d1d5e29

Conflicts:
	core/res/res/values/pa_symbols.xml
SystemUI: Use EdgeGesture service to trigger Pie

EdgeGesture service triggers Pie when detecting gestures on
the WHOLE edge, not just the center.

Patch Set 2: Better trigger values

Change-Id: Id7d9d7f6f5a37ca3696cdddf0da78c88c067970e
SystemUI: Position Pie at gesture's triggered position

As the EdgeGesture service is triggered at the whole screen
edge, place Pie at the gesture's triggered position, instead
of always positioning it at the center of the edge.

This might be controversial and a matter of taste, but in
particular on tablets it's sometimes hard to hit the exact
center of the edge and therefore gestures often fail. Could
also imagine enabling this feature on tablets only. Needs
some discussion...

Change-Id: Ife28ac434667148583b34bcccd11262c111b5a67
PhoneWindowManager: add ability to use EdgeGestureService for system gestures.

Update: Default to enabled

Change-Id: Id4e2c0d82f771cd1c20e9196fb6db347494cca69

Conflicts:
	core/java/android/provider/Settings.java
	policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
SystemUI: Stick Pie to edge on phones

Apply the same UX of AOSP's navbar on phones to Pie
controls. When rotating the phone, Pie now sticks to the
same physical screen edge, to which it was pinned before. As
most people start holding their phone with two hands in
landscape mode, keeping Pie at the right or left edge might
be more comfortable to reach by thumbs. The behavior on
tablets should not be affected in any way by this change.

Changes:

PieControlPanel stores only the absolute gravity (the
rotation independent position in portrait mode) of Pie.
PieMenu and PieController query the gravity from Panel.
Query methods (getOrientation(), getDegree(),
isGravityPossible()) only return the relative gravity (the
position depending on current rotation). Therfore, only the
PieControlPanel is aware of, whether and how gravity is
converted.

The amount of snap points is reduced in landscape mode,
because Pie cannot be pinned to the top edge of the screen.

Change-Id: I263f16e1c59e134f374b9a3a007ecdce2d54dc46
SystemUI: Fixed stick Pie to edge
SystemUI: Force Pie centered on small display devices
PhoneWindowManager: EdgeGestureService: Bring compatibility with PIE service:

Remove all edges flags but TOP (for statusbar) regards to system edge gestures.
Pie covers the other edges with its service.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
ActivityInfo: Restore default behavior for screen size changes or layout changes

This was a change introduced with PIE intended to fix an aosp bug,
test to see if we still face one or more of current immersive issue(s).

Edit: revert for now along with the other PIE work.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
PIE: EdgeGestureService: Add flags LONG_LIVING | UNRESTRICTED

Following PhoneWindowManager enforcing.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
PhoneWindowManager: Fix a couple of issues and cleanup recent PIE rewamp

SystemGestures is unregistered due to default new EdgeGestureService,
still for safety keep a boolean check on requestTransientBars().
Refresh height live.

Change-Id: Iae9c6079c21e65d01eea330fa17f3861a4c2e100
Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
PhoneWindowManager: Don't handle navigation bar visibility when switching to PIE

Right now when restoring full height after disabling immersive if pie mode is
on, navbar isn't showed until panel collapsing cause it should have been showed
(the view even with height zero) called by top swipe gesture that calls requestTransientBars().
Don't touch the API, cleanup old code traces and changes cause in any case navbar has height = 0
and its bottom/right gesture is disabled.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
Change-Id: Id05175a553aad2a5a2b36c3fe4e32a2d071dcc88

Conflicts:
	policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
PIE: On-The-Spot: Fix abnormal behavior when chosing ASK_LATER

Right now when chosing ask later it does not activate default immersive for that immersion.
We should call switchImmersiveGlobal() no matter what we chose on on-the-spot dialog,
also if immersive mode is disabled and is going to be activated.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
On-The-Spot: Add clear all recents button to user preferences.

PS3: Add proper drawable thanks to / by Dani Rosenkamp @DaNi--
     Fix wrong change id (from abandoned commit)
PS4: More logic drawable

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
Change-Id: I632730bee6b409072689e07fb1084ceaca5b1d49

Conflicts:
	core/java/android/provider/Settings.java
	packages/SystemUI/res/values-ca/pa_strings.xml
	packages/SystemUI/res/values-es/pa_strings.xml
	packages/SystemUI/res/values/ras_strings.xml
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java