/packages/SystemUI/src/com/android/systemui/statusbar/phone/SettingsPanelView.java

https://github.com/aizuzi/platform_frameworks_base · Java · 161 lines · 122 code · 23 blank · 16 comment · 20 complexity · 934a49ba65f871caa53688e62594e6ae MD5 · raw file

  1. /*
  2. * Copyright (C) 2012 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. package com.android.systemui.statusbar.phone;
  17. import android.content.Context;
  18. import android.content.res.Resources;
  19. import android.graphics.Canvas;
  20. import android.graphics.drawable.Drawable;
  21. import android.util.AttributeSet;
  22. import android.util.EventLog;
  23. import android.view.MotionEvent;
  24. import android.view.View;
  25. import android.view.accessibility.AccessibilityEvent;
  26. import com.android.systemui.EventLogTags;
  27. import com.android.systemui.R;
  28. import com.android.systemui.statusbar.GestureRecorder;
  29. import com.android.systemui.statusbar.policy.BatteryController;
  30. import com.android.systemui.statusbar.policy.BluetoothController;
  31. import com.android.systemui.statusbar.policy.LocationController;
  32. import com.android.systemui.statusbar.policy.NetworkController;
  33. import com.android.systemui.statusbar.policy.RotationLockController;
  34. public class SettingsPanelView extends PanelView {
  35. public static final boolean DEBUG_GESTURES = true;
  36. private QuickSettings mQS;
  37. private QuickSettingsContainerView mQSContainer;
  38. Drawable mHandleBar;
  39. int mHandleBarHeight;
  40. View mHandleView;
  41. public SettingsPanelView(Context context, AttributeSet attrs) {
  42. super(context, attrs);
  43. }
  44. @Override
  45. protected void onFinishInflate() {
  46. super.onFinishInflate();
  47. mQSContainer = (QuickSettingsContainerView) findViewById(R.id.quick_settings_container);
  48. Resources resources = getContext().getResources();
  49. mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
  50. mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
  51. mHandleView = findViewById(R.id.handle);
  52. }
  53. public void setQuickSettings(QuickSettings qs) {
  54. mQS = qs;
  55. }
  56. @Override
  57. public void setBar(PanelBar panelBar) {
  58. super.setBar(panelBar);
  59. if (mQS != null) {
  60. mQS.setBar(panelBar);
  61. }
  62. }
  63. public void setImeWindowStatus(boolean visible) {
  64. if (mQS != null) {
  65. mQS.setImeWindowStatus(visible);
  66. }
  67. }
  68. public void setup(NetworkController networkController, BluetoothController bluetoothController,
  69. BatteryController batteryController, LocationController locationController,
  70. RotationLockController rotationLockController) {
  71. if (mQS != null) {
  72. mQS.setup(networkController, bluetoothController, batteryController,
  73. locationController, rotationLockController);
  74. }
  75. }
  76. void updateResources() {
  77. if (mQS != null) {
  78. mQS.updateResources();
  79. }
  80. if (mQSContainer != null) {
  81. mQSContainer.updateResources();
  82. }
  83. requestLayout();
  84. }
  85. @Override
  86. public void fling(float vel, boolean always) {
  87. GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
  88. if (gr != null) {
  89. gr.tag(
  90. "fling " + ((vel > 0) ? "open" : "closed"),
  91. "settings,v=" + vel);
  92. }
  93. super.fling(vel, always);
  94. }
  95. public void setService(PhoneStatusBar phoneStatusBar) {
  96. if (mQS != null) {
  97. mQS.setService(phoneStatusBar);
  98. }
  99. }
  100. @Override
  101. public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
  102. if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
  103. event.getText()
  104. .add(getContext().getString(R.string.accessibility_desc_quick_settings));
  105. return true;
  106. }
  107. return super.dispatchPopulateAccessibilityEvent(event);
  108. }
  109. // We draw the handle ourselves so that it's always glued to the bottom of the window.
  110. @Override
  111. protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  112. super.onLayout(changed, left, top, right, bottom);
  113. if (changed) {
  114. final int pl = getPaddingLeft();
  115. final int pr = getPaddingRight();
  116. mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
  117. }
  118. }
  119. @Override
  120. public void draw(Canvas canvas) {
  121. super.draw(canvas);
  122. final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
  123. canvas.translate(0, off);
  124. mHandleBar.setState(mHandleView.getDrawableState());
  125. mHandleBar.draw(canvas);
  126. canvas.translate(0, -off);
  127. }
  128. @Override
  129. public boolean onTouchEvent(MotionEvent event) {
  130. if (DEBUG_GESTURES) {
  131. if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
  132. EventLog.writeEvent(EventLogTags.SYSUI_QUICKPANEL_TOUCH,
  133. event.getActionMasked(), (int) event.getX(), (int) event.getY());
  134. }
  135. }
  136. return super.onTouchEvent(event);
  137. }
  138. }