LorDClockaN

navbartr

Oct 8th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2013 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. package com.android.systemui.statusbar.phone;
  18.  
  19. import android.animation.Animator;
  20. import android.animation.AnimatorListenerAdapter;
  21. import android.content.Context;
  22. import android.graphics.Color;
  23. import android.graphics.PorterDuff;
  24. import android.os.ServiceManager;
  25. import android.view.MotionEvent;
  26. import android.view.View;
  27. import android.view.animation.AccelerateInterpolator;
  28.  
  29. import com.android.internal.statusbar.IStatusBarService;
  30. import com.android.internal.util.aokp.AwesomeConstants.AwesomeConstant;
  31. import com.android.systemui.R;
  32. import com.android.systemui.statusbar.policy.KeyButtonView;
  33. import com.android.internal.util.omni.ColorUtils;
  34.  
  35. public final class NavigationBarTransitions extends BarTransitions {
  36.  
  37. private static final float KEYGUARD_QUIESCENT_ALPHA = 0.5f;
  38. private static final int CONTENT_FADE_DURATION = 200;
  39.  
  40. private final NavigationBarView mView;
  41. private final IStatusBarService mBarService;
  42.  
  43. private boolean mLightsOut;
  44. private boolean mVertical;
  45. private boolean mLeftIfVertical;
  46. private int mRequestedMode;
  47. private boolean mStickyTransparent;
  48. private int mCurrentColor;
  49. private int mCurrentBg;
  50.  
  51. public NavigationBarTransitions(NavigationBarView view) {
  52. super(view, R.drawable.nav_background, R.color.navigation_bar_background_opaque,
  53. R.color.navigation_bar_background_semi_transparent);
  54. mView = view;
  55. mBarService = IStatusBarService.Stub.asInterface(
  56. ServiceManager.getService(Context.STATUS_BAR_SERVICE));
  57. }
  58.  
  59. public void init(boolean isVertical) {
  60. setVertical(isVertical);
  61. applyModeBackground(-1, getMode(), false /*animate*/);
  62. applyMode(getMode(), false /*animate*/, true /*force*/);
  63. }
  64.  
  65. public void setVertical(boolean isVertical) {
  66. setIsVertical(isVertical);
  67. if (mVertical != isVertical) {
  68. mVertical = isVertical;
  69. updateBackgroundResource();
  70. }
  71. }
  72.  
  73. public void setLeftIfVertical(boolean leftIfVertical) {
  74. if (mLeftIfVertical != leftIfVertical) {
  75. mLeftIfVertical = leftIfVertical;
  76. updateBackgroundResource();
  77. }
  78. }
  79.  
  80. private void updateBackgroundResource() {
  81. if (mVertical && mLeftIfVertical) {
  82. setGradientResourceId(R.drawable.nav_background_land_left);
  83. } else if (mVertical) {
  84. setGradientResourceId(R.drawable.nav_background_land);
  85. } else {
  86. setGradientResourceId(R.drawable.nav_background);
  87. }
  88. transitionTo(mRequestedMode, false /*animate*/);
  89. }
  90.  
  91. @Override
  92. public void transitionTo(int mode, boolean animate) {
  93. mRequestedMode = mode;
  94. if (mStickyTransparent) {
  95. mode = MODE_TRANSPARENT;
  96. }
  97. super.transitionTo(mode, animate);
  98. }
  99.  
  100. @Override
  101. protected void onTransition(int oldMode, int newMode, boolean animate) {
  102. super.onTransition(oldMode, newMode, animate);
  103. applyMode(newMode, animate, false /*force*/);
  104. }
  105.  
  106. private void applyMode(int mode, boolean animate, boolean force) {
  107. // apply to key buttons
  108. final float alpha = alphaForMode(mode);
  109. View[] views = mView.getAllButtons();
  110.  
  111. for(View v : views) {
  112. if (AwesomeConstant.ACTION_BACK.value().equals(v.getTag())) {
  113. // back button was skipped in original calculations
  114. continue;
  115. }
  116. setKeyButtonViewQuiescentAlpha(v, alpha, animate);
  117. }
  118.  
  119. setKeyButtonViewQuiescentAlpha(mView.getSearchLight(), KEYGUARD_QUIESCENT_ALPHA, animate);
  120. setKeyButtonViewQuiescentAlpha(mView.getCameraButton(), KEYGUARD_QUIESCENT_ALPHA, animate);
  121. setKeyButtonViewQuiescentAlpha(mView.getNotifsButton(), KEYGUARD_QUIESCENT_ALPHA, animate);
  122. applyBackButtonQuiescentAlpha(mode, animate);
  123.  
  124. // apply to lights out
  125. applyLightsOut(mode == MODE_LIGHTS_OUT, animate, force);
  126. }
  127.  
  128. private float alphaForMode(int mode) {
  129. final boolean isOpaque = mode == MODE_OPAQUE || mode == MODE_LIGHTS_OUT;
  130. return isOpaque ? KeyButtonView.DEFAULT_QUIESCENT_ALPHA : 1f;
  131. }
  132.  
  133. public void applyBackButtonQuiescentAlpha(int mode, boolean animate) {
  134. float backAlpha = 0;
  135. View[] views = mView.getAllButtons();
  136. for(View v : views) {
  137. if (AwesomeConstant.ACTION_BACK.value().equals(v.getTag())) {
  138. // back button was skipped in original calculations
  139. continue;
  140. }
  141. backAlpha = maxVisibleQuiescentAlpha(backAlpha, v);
  142. }
  143.  
  144. backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getNotifsButton());
  145.  
  146. if (backAlpha > 0) {
  147. setKeyButtonViewQuiescentAlpha(mView.getBackButton(), backAlpha, animate);
  148. }
  149. }
  150.  
  151. public void applyTransparent(boolean sticky) {
  152. if (sticky != mStickyTransparent) {
  153. mStickyTransparent = sticky;
  154. if (!mStickyTransparent) {
  155. transitionTo(mRequestedMode, false);
  156. } else {
  157. transitionTo(MODE_TRANSPARENT, false);
  158. }
  159. }
  160. }
  161.  
  162. private static float maxVisibleQuiescentAlpha(float max, View v) {
  163. if ((v instanceof KeyButtonView) && v.isShown()) {
  164. return Math.max(max, ((KeyButtonView)v).getQuiescentAlpha());
  165. }
  166. return max;
  167. }
  168.  
  169. @Override
  170. public void setContentVisible(boolean visible) {
  171. final float alpha = visible ? 1 : 0;
  172. fadeContent(mView.getCameraButton(), alpha);
  173. fadeContent(mView.getNotifsButton(), alpha);
  174. fadeContent(mView.getSearchLight(), alpha);
  175. }
  176.  
  177. private void fadeContent(View v, float alpha) {
  178. if (v != null) {
  179. v.animate().alpha(alpha).setDuration(CONTENT_FADE_DURATION);
  180. }
  181. }
  182.  
  183. private void setKeyButtonViewQuiescentAlpha(View button, float alpha, boolean animate) {
  184. if (button instanceof KeyButtonView) {
  185. ((KeyButtonView) button).setQuiescentAlpha(alpha, animate);
  186. }
  187. }
  188.  
  189. @Override
  190. public void finishAnimations() {
  191. setColorButtonNavigationBar(-3);
  192. super.finishAnimations();
  193. }
  194.  
  195. @Override
  196. public void changeColorIconBackground(int bg_color, int ic_color) {
  197. if (mCurrentBg == bg_color) {
  198. return;
  199. }
  200. mCurrentBg = bg_color;
  201. if (ColorUtils.isBrightColor(bg_color)) {
  202. ic_color = Color.BLACK;
  203. }
  204. mCurrentColor = ic_color;
  205. setColorButtonNavigationBar(ic_color);
  206. super.changeColorIconBackground(bg_color, ic_color);
  207. }
  208.  
  209. public int getCurrentIconColor() {
  210. return mCurrentColor;
  211. }
  212.  
  213. private void setColorButtonNavigationBar(int ic_color) {
  214. setKeyButtonViewColor(AwesomeConstant.ACTION_HOME, ic_color);
  215. setKeyButtonViewColor(AwesomeConstant.ACTION_RECENTS, ic_color);
  216. setKeyButtonViewColor(AwesomeConstant.ACTION_MENU, ic_color);
  217. setKeyButtonViewColor(AwesomeConstant.ACTION_SEARCH, ic_color);
  218. setKeyButtonViewColor(AwesomeConstant.ACTION_BACK, ic_color);
  219. setKeyButtonViewButtonColor(mView.getSearchLight(), ic_color);
  220. setKeyButtonViewButtonColor(mView.getCameraButton(), ic_color);
  221. }
  222.  
  223. private void setKeyButtonViewColor(ButtonInfo info, int ic_color) {
  224. View button = mView.findViewWithTag(info);
  225. if (button != null) {
  226. setKeyButtonViewButtonColor(button, ic_color);
  227. }
  228. }
  229.  
  230. private void setKeyButtonViewButtonColor(View button, int ic_color) {
  231. if (button instanceof KeyButtonView) {
  232. if (ic_color == -3) {
  233. ((KeyButtonView) button).clearColorFilterBg();
  234. } else {
  235. ((KeyButtonView) button).setColorFilterBg(ic_color, PorterDuff.Mode.SRC_ATOP);
  236. }
  237. }
  238. }
  239.  
  240. private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) {
  241. if (!force && lightsOut == mLightsOut) return;
  242.  
  243. mLightsOut = lightsOut;
  244.  
  245. final View navButtons = mView.getCurrentView().findViewById(R.id.nav_buttons);
  246. final View lowLights = mView.getCurrentView().findViewById(R.id.lights_out);
  247.  
  248. // ok, everyone, stop it right there
  249. navButtons.animate().cancel();
  250. lowLights.animate().cancel();
  251.  
  252. final float navButtonsAlpha = lightsOut ? 0f : 1f;
  253. final float lowLightsAlpha = lightsOut ? 1f : 0f;
  254.  
  255. if (!animate) {
  256. navButtons.setAlpha(navButtonsAlpha);
  257. lowLights.setAlpha(lowLightsAlpha);
  258. lowLights.setVisibility(lightsOut ? View.VISIBLE : View.GONE);
  259. } else {
  260. final int duration = lightsOut ? LIGHTS_OUT_DURATION : LIGHTS_IN_DURATION;
  261. navButtons.animate()
  262. .alpha(navButtonsAlpha)
  263. .setDuration(duration)
  264. .start();
  265.  
  266. lowLights.setOnTouchListener(mLightsOutListener);
  267. if (lowLights.getVisibility() == View.GONE) {
  268. lowLights.setAlpha(0f);
  269. lowLights.setVisibility(View.VISIBLE);
  270. }
  271. lowLights.animate()
  272. .alpha(lowLightsAlpha)
  273. .setDuration(duration)
  274. .setInterpolator(new AccelerateInterpolator(2.0f))
  275. .setListener(lightsOut ? null : new AnimatorListenerAdapter() {
  276. @Override
  277. public void onAnimationEnd(Animator _a) {
  278. lowLights.setVisibility(View.GONE);
  279. }
  280. })
  281. .start();
  282. }
  283. }
  284.  
  285. private final View.OnTouchListener mLightsOutListener = new View.OnTouchListener() {
  286. @Override
  287. public boolean onTouch(View v, MotionEvent ev) {
  288. if (ev.getAction() == MotionEvent.ACTION_DOWN) {
  289. // even though setting the systemUI visibility below will turn these views
  290. // on, we need them to come up faster so that they can catch this motion
  291. // event
  292. applyLightsOut(false, false, false);
  293.  
  294. try {
  295. mBarService.setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE);
  296. } catch (android.os.RemoteException ex) {
  297. }
  298. }
  299. return false;
  300. }
  301. };
  302. }
Advertisement
Add Comment
Please, Sign In to add comment