@quicktvui/ai 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/package.json +1 -1
  2. package/rules/.clinerules +27 -4
  3. package/rules/.cursorrules +27 -4
  4. package/rules/.github/copilot-instructions.md +27 -4
  5. package/rules/.source/hippy/extend_views/CoverFlowHorizontalView.java +203 -0
  6. package/rules/.source/hippy/extend_views/CoverFlowVerticalView.java +203 -0
  7. package/rules/.source/hippy/extend_views/CoverFlowViewController.java +195 -0
  8. package/rules/.source/hippy/extend_views/EngineRootView.java +125 -0
  9. package/rules/.source/hippy/extend_views/ExtendTag.java +83 -0
  10. package/rules/.source/hippy/extend_views/FocusSearchHelper.java +124 -0
  11. package/rules/.source/hippy/extend_views/IRecyclerItemView.java +12 -0
  12. package/rules/.source/hippy/extend_views/JSEventHandleView.java +5 -0
  13. package/rules/.source/hippy/extend_views/MarqueeRelayManager.java +133 -0
  14. package/rules/.source/hippy/extend_views/MarqueeRelayTextView.java +211 -0
  15. package/rules/.source/hippy/extend_views/ProgressBarView.java +83 -0
  16. package/rules/.source/hippy/extend_views/ProgressBarViewController.java +145 -0
  17. package/rules/.source/hippy/extend_views/SeekBarView.java +104 -0
  18. package/rules/.source/hippy/extend_views/SeekBarViewController.java +218 -0
  19. package/rules/.source/hippy/extend_views/StateImageView.java +149 -0
  20. package/rules/.source/hippy/extend_views/StateImageViewController.java +34 -0
  21. package/rules/.source/hippy/extend_views/TVButtonView.java +314 -0
  22. package/rules/.source/hippy/extend_views/TVButtonViewController.java +89 -0
  23. package/rules/.source/hippy/extend_views/TVTextView.java +684 -0
  24. package/rules/.source/hippy/extend_views/TVViewActor.java +811 -0
  25. package/rules/.source/hippy/extend_views/TVViewActorHost.java +6 -0
  26. package/rules/.source/hippy/extend_views/TVViewActor/346/216/245/345/205/245.md +66 -0
  27. package/rules/.source/hippy/extend_views/TemplateUtil.java +336 -0
  28. package/rules/.source/hippy/extend_views/TextButtonNode.java +47 -0
  29. package/rules/.source/hippy/extend_views/TextViewController.java +377 -0
  30. package/rules/.source/hippy/extend_views/fastlist/CenterFlyInAnimator.java +96 -0
  31. package/rules/.source/hippy/extend_views/fastlist/ChildOnScreenScroller.java +548 -0
  32. package/rules/.source/hippy/extend_views/fastlist/ClonedViewTag.java +17 -0
  33. package/rules/.source/hippy/extend_views/fastlist/EventDeliverer.java +55 -0
  34. package/rules/.source/hippy/extend_views/fastlist/FastAdapter.java +4683 -0
  35. package/rules/.source/hippy/extend_views/fastlist/FastAdapterUtil.java +982 -0
  36. package/rules/.source/hippy/extend_views/fastlist/FastFlexNode.java +48 -0
  37. package/rules/.source/hippy/extend_views/fastlist/FastFlexView.java +873 -0
  38. package/rules/.source/hippy/extend_views/fastlist/FastFlexViewController.java +130 -0
  39. package/rules/.source/hippy/extend_views/fastlist/FastItemNode.java +67 -0
  40. package/rules/.source/hippy/extend_views/fastlist/FastItemView.java +306 -0
  41. package/rules/.source/hippy/extend_views/fastlist/FastItemViewController.java +106 -0
  42. package/rules/.source/hippy/extend_views/fastlist/FastListModule.java +95 -0
  43. package/rules/.source/hippy/extend_views/fastlist/FastListNode.java +90 -0
  44. package/rules/.source/hippy/extend_views/fastlist/FastListView.java +2466 -0
  45. package/rules/.source/hippy/extend_views/fastlist/FastListViewController.java +1038 -0
  46. package/rules/.source/hippy/extend_views/fastlist/FastListView/346/270/262/346/237/223/346/265/201/347/250/213/345/233/276.graffle +0 -0
  47. package/rules/.source/hippy/extend_views/fastlist/FastPendingView.java +47 -0
  48. package/rules/.source/hippy/extend_views/fastlist/ItemDecorations.java +71 -0
  49. package/rules/.source/hippy/extend_views/fastlist/ItemStoreNode.java +64 -0
  50. package/rules/.source/hippy/extend_views/fastlist/ItemStoreView.java +13 -0
  51. package/rules/.source/hippy/extend_views/fastlist/ItemStoreViewController.java +45 -0
  52. package/rules/.source/hippy/extend_views/fastlist/ListItemHolder.java +7 -0
  53. package/rules/.source/hippy/extend_views/fastlist/ListViewControlProp.java +41 -0
  54. package/rules/.source/hippy/extend_views/fastlist/MouseRecycleView.java +509 -0
  55. package/rules/.source/hippy/extend_views/fastlist/OnFastItemClickListener.java +12 -0
  56. package/rules/.source/hippy/extend_views/fastlist/OnFastItemFocusChangeListener.java +9 -0
  57. package/rules/.source/hippy/extend_views/fastlist/OnFastScrollStateChangedListener.java +7 -0
  58. package/rules/.source/hippy/extend_views/fastlist/PendingListNode.java +18 -0
  59. package/rules/.source/hippy/extend_views/fastlist/PendingViewController.java +13 -0
  60. package/rules/.source/hippy/extend_views/fastlist/PostHandlerView.java +6 -0
  61. package/rules/.source/hippy/extend_views/fastlist/PostTaskHolder.java +20 -0
  62. package/rules/.source/hippy/extend_views/fastlist/ReplaceChildController.java +105 -0
  63. package/rules/.source/hippy/extend_views/fastlist/ReplaceChildView.java +312 -0
  64. package/rules/.source/hippy/extend_views/fastlist/TVListView.java +3692 -0
  65. package/rules/.source/hippy/extend_views/fastlist/TemplateCodeParser.java +247 -0
  66. package/rules/.source/hippy/extend_views/fastlist/Utils.java +572 -0
  67. package/rules/.source/hippy/extend_views/fastlist/ViewTag.java +317 -0
  68. package/rules/.source/hippy/extend_views/fastlist/VirtualListView.java +8 -0
  69. package/rules/.source/hippy/extend_views/fastlist/diff/FastListDataBindingHelper.java +320 -0
  70. package/rules/.source/hippy/extend_views/fastlist/diff/KeyDiffHelper.java +289 -0
  71. package/rules/.source/hippy/extend_views/fastlist/diff/NoKeyDiffHelper.java +278 -0
  72. package/rules/.source/hippy/extend_views/tag/FontTag.java +53 -0
  73. package/rules/.source/hippy/extend_views/tag/HtmlTag.java +191 -0
  74. package/rules/.source/hippy/extend_views/tag/HtmlTagHandler.java +185 -0
  75. package/rules/.source/hippy/extend_views/tag/SpanTag.java +160 -0
  76. package/rules/.source/hippy/extend_views/tag/TextFontSpan.java +102 -0
  77. package/rules/.source/hippy/extend_views/waterfall/Chunk.java +10 -0
  78. package/rules/.source/hippy/extend_views/waterfall/ChunkGroup.java +5 -0
  79. package/rules/.source/hippy/extend_views/waterfall/Section.java +4 -0
  80. package/rules/.source/hippy/extend_views/waterfall/Tabs.java +5 -0
  81. package/rules/.source/hippy/extend_views/waterfall/WaterfallUtils.java +26 -0
  82. package/rules/.source/hippy/hippy_uimanager/ControllerHolder.java +30 -0
  83. package/rules/.source/hippy/hippy_uimanager/ControllerManager.java +651 -0
  84. package/rules/.source/hippy/hippy_uimanager/ControllerRegistry.java +102 -0
  85. package/rules/.source/hippy/hippy_uimanager/ControllerUpdateManger.java +252 -0
  86. package/rules/.source/hippy/hippy_uimanager/CustomControllerHelper.java +425 -0
  87. package/rules/.source/hippy/hippy_uimanager/DiffUtils.java +526 -0
  88. package/rules/.source/hippy/hippy_uimanager/ExtendViewGroup.java +36 -0
  89. package/rules/.source/hippy/hippy_uimanager/HippyCustomViewCreator.java +29 -0
  90. package/rules/.source/hippy/hippy_uimanager/HippyGroupController.java +83 -0
  91. package/rules/.source/hippy/hippy_uimanager/HippyViewBase.java +27 -0
  92. package/rules/.source/hippy/hippy_uimanager/HippyViewController.java +2189 -0
  93. package/rules/.source/hippy/hippy_uimanager/HippyViewEvent.java +52 -0
  94. package/rules/.source/hippy/hippy_uimanager/IHippyZIndexViewGroup.java +24 -0
  95. package/rules/.source/hippy/hippy_uimanager/InternalExtendViewUtil.java +395 -0
  96. package/rules/.source/hippy/hippy_uimanager/ListItemRenderNode.java +143 -0
  97. package/rules/.source/hippy/hippy_uimanager/ListViewRenderNode.java +44 -0
  98. package/rules/.source/hippy/hippy_uimanager/MatrixUtil.java +470 -0
  99. package/rules/.source/hippy/hippy_uimanager/NativeGestureDispatcher.java +349 -0
  100. package/rules/.source/hippy/hippy_uimanager/NativeGestureProcessor.java +188 -0
  101. package/rules/.source/hippy/hippy_uimanager/PullFooterRenderNode.java +43 -0
  102. package/rules/.source/hippy/hippy_uimanager/PullHeaderRenderNode.java +43 -0
  103. package/rules/.source/hippy/hippy_uimanager/RenderManager.java +304 -0
  104. package/rules/.source/hippy/hippy_uimanager/RenderNode.java +533 -0
  105. package/rules/.source/hippy/hippy_uimanager/StateView.java +17 -0
  106. package/rules/.source/hippy/hippy_uimanager/TransformUtil.java +125 -0
  107. package/rules/.source/hippy/hippy_uimanager/ViewGroupDrawingOrderHelper.java +108 -0
  108. package/rules/.source/hippy/hippy_uimanager/ViewStateProvider.java +10 -0
  109. package/rules/.source/hippy/hippy_views/audioview/AudioPlayManager.java +457 -0
  110. package/rules/.source/hippy/hippy_views/audioview/AudioView.java +225 -0
  111. package/rules/.source/hippy/hippy_views/audioview/AudioViewController.java +135 -0
  112. package/rules/.source/hippy/hippy_views/common/CommonBackgroundDrawable.java +58 -0
  113. package/rules/.source/hippy/hippy_views/common/CommonBorder.java +37 -0
  114. package/rules/.source/hippy/hippy_views/custom/HippyCustomPropsController.java +61 -0
  115. package/rules/.source/hippy/hippy_views/hippylist/HippyRecyclerListAdapter.java +399 -0
  116. package/rules/.source/hippy/hippy_views/hippylist/HippyRecyclerView.java +378 -0
  117. package/rules/.source/hippy/hippy_views/hippylist/HippyRecyclerViewController.java +187 -0
  118. package/rules/.source/hippy/hippy_views/hippylist/HippyRecyclerViewHolder.java +39 -0
  119. package/rules/.source/hippy/hippy_views/hippylist/HippyRecyclerViewWrapper.java +134 -0
  120. package/rules/.source/hippy/hippy_views/hippylist/NodePositionHelper.java +55 -0
  121. package/rules/.source/hippy/hippy_views/hippylist/PreloadHelper.java +54 -0
  122. package/rules/.source/hippy/hippy_views/hippylist/PullFooterEventHelper.java +61 -0
  123. package/rules/.source/hippy/hippy_views/hippylist/PullHeaderEventHelper.java +127 -0
  124. package/rules/.source/hippy/hippy_views/hippylist/RecyclerViewEventHelper.java +394 -0
  125. package/rules/.source/hippy/hippy_views/image/HippyContentDrawable.java +113 -0
  126. package/rules/.source/hippy/hippy_views/image/HippyImageView.java +1608 -0
  127. package/rules/.source/hippy/hippy_views/image/HippyImageViewController.java +382 -0
  128. package/rules/.source/hippy/hippy_views/image/IImageStateListener.java +7 -0
  129. package/rules/.source/hippy/hippy_views/list/ChildOnScreenScroller.java +255 -0
  130. package/rules/.source/hippy/hippy_views/list/HippyListAdapter.java +647 -0
  131. package/rules/.source/hippy/hippy_views/list/HippyListItemView.java +162 -0
  132. package/rules/.source/hippy/hippy_views/list/HippyListItemViewController.java +45 -0
  133. package/rules/.source/hippy/hippy_views/list/HippyListView.java +915 -0
  134. package/rules/.source/hippy/hippy_views/list/HippyListViewController.java +622 -0
  135. package/rules/.source/hippy/hippy_views/list/HippyRecycler.java +31 -0
  136. package/rules/.source/hippy/hippy_views/list/IRecycleItemTypeChange.java +23 -0
  137. package/rules/.source/hippy/hippy_views/list/ItemDecorations.java +70 -0
  138. package/rules/.source/hippy/hippy_views/list/NegativeLongKeyFlinger.java +156 -0
  139. package/rules/.source/hippy/hippy_views/list/NodeHolder.java +34 -0
  140. package/rules/.source/hippy/hippy_views/list/RecycleViewFlinger.java +126 -0
  141. package/rules/.source/hippy/hippy_views/list/TVRecyclerView.java +2070 -0
  142. package/rules/.source/hippy/hippy_views/list/TVSingleLineListView.java +15 -0
  143. package/rules/.source/hippy/hippy_views/modal/HippyModalHostManager.java +102 -0
  144. package/rules/.source/hippy/hippy_views/modal/HippyModalHostView.java +597 -0
  145. package/rules/.source/hippy/hippy_views/modal/ModalHostHelper.java +46 -0
  146. package/rules/.source/hippy/hippy_views/modal/ModalStyleNode.java +34 -0
  147. package/rules/.source/hippy/hippy_views/modal/RequestCloseEvent.java +32 -0
  148. package/rules/.source/hippy/hippy_views/modal/ShowEvent.java +31 -0
  149. package/rules/.source/hippy/hippy_views/navigator/Navigator.java +126 -0
  150. package/rules/.source/hippy/hippy_views/navigator/NavigatorController.java +120 -0
  151. package/rules/.source/hippy/hippy_views/refresh/HippyPullFooterView.java +47 -0
  152. package/rules/.source/hippy/hippy_views/refresh/HippyPullFooterViewController.java +65 -0
  153. package/rules/.source/hippy/hippy_views/refresh/HippyPullHeaderView.java +39 -0
  154. package/rules/.source/hippy/hippy_views/refresh/HippyPullHeaderViewController.java +104 -0
  155. package/rules/.source/hippy/hippy_views/refresh/RefreshWrapper.java +237 -0
  156. package/rules/.source/hippy/hippy_views/refresh/RefreshWrapperController.java +62 -0
  157. package/rules/.source/hippy/hippy_views/refresh/RefreshWrapperItemController.java +39 -0
  158. package/rules/.source/hippy/hippy_views/refresh/RefreshWrapperItemView.java +26 -0
  159. package/rules/.source/hippy/hippy_views/scroll/HippyHorizontalScrollView.java +500 -0
  160. package/rules/.source/hippy/hippy_views/scroll/HippyOnScrollHelper.java +39 -0
  161. package/rules/.source/hippy/hippy_views/scroll/HippyScrollView.java +46 -0
  162. package/rules/.source/hippy/hippy_views/scroll/HippyScrollViewController.java +178 -0
  163. package/rules/.source/hippy/hippy_views/scroll/HippyScrollViewEventHelper.java +92 -0
  164. package/rules/.source/hippy/hippy_views/scroll/HippyVerticalScrollView.java +522 -0
  165. package/rules/.source/hippy/hippy_views/text/HippyTextView.java +512 -0
  166. package/rules/.source/hippy/hippy_views/text/HippyTextViewController.java +77 -0
  167. package/rules/.source/hippy/hippy_views/textinput/HippyTextInput.java +668 -0
  168. package/rules/.source/hippy/hippy_views/textinput/HippyTextInputController.java +528 -0
  169. package/rules/.source/hippy/hippy_views/textinput/TextInputNode.java +115 -0
  170. package/rules/.source/hippy/hippy_views/videoview/APEZProvider.java +287 -0
  171. package/rules/.source/hippy/hippy_views/videoview/APKExpansionSupport.java +82 -0
  172. package/rules/.source/hippy/hippy_views/videoview/PivotPoint.java +13 -0
  173. package/rules/.source/hippy/hippy_views/videoview/ScalableType.java +34 -0
  174. package/rules/.source/hippy/hippy_views/videoview/ScalableVideoView.java +265 -0
  175. package/rules/.source/hippy/hippy_views/videoview/ScaleManager.java +191 -0
  176. package/rules/.source/hippy/hippy_views/videoview/Size.java +19 -0
  177. package/rules/.source/hippy/hippy_views/videoview/VideoHippyView.java +917 -0
  178. package/rules/.source/hippy/hippy_views/videoview/VideoHippyViewController.java +236 -0
  179. package/rules/.source/hippy/hippy_views/videoview/ZipResourceFile.java +427 -0
  180. package/rules/.source/hippy/hippy_views/view/CardRootView.java +28 -0
  181. package/rules/.source/hippy/hippy_views/view/CustomLayoutView.java +10 -0
  182. package/rules/.source/hippy/hippy_views/view/CustomNodeView.java +5 -0
  183. package/rules/.source/hippy/hippy_views/view/DialogViewGroup.java +113 -0
  184. package/rules/.source/hippy/hippy_views/view/HippyViewGroup.java +2042 -0
  185. package/rules/.source/hippy/hippy_views/view/HippyViewGroupController.java +583 -0
  186. package/rules/.source/hippy/hippy_views/view/WindowRoot.java +5 -0
  187. package/rules/.source/hippy/hippy_views/viewpager/HippyViewPager.java +308 -0
  188. package/rules/.source/hippy/hippy_views/viewpager/HippyViewPagerAdapter.java +148 -0
  189. package/rules/.source/hippy/hippy_views/viewpager/HippyViewPagerController.java +246 -0
  190. package/rules/.source/hippy/hippy_views/viewpager/HippyViewPagerItem.java +27 -0
  191. package/rules/.source/hippy/hippy_views/viewpager/HippyViewPagerItemController.java +42 -0
  192. package/rules/.source/hippy/hippy_views/viewpager/ViewPagerPageChangeListener.java +114 -0
  193. package/rules/.source/hippy/hippy_views/viewpager/event/HippyPageItemExposureEvent.java +40 -0
  194. package/rules/.source/hippy/hippy_views/viewpager/event/HippyPageScrollEvent.java +43 -0
  195. package/rules/.source/hippy/hippy_views/viewpager/event/HippyPageScrollStateChangedEvent.java +42 -0
  196. package/rules/.source/hippy/hippy_views/viewpager/event/HippyPageSelectedEvent.java +42 -0
  197. package/rules/.source/hippy/hippy_views/webview/HippyWebView.java +160 -0
  198. package/rules/.source/hippy/hippy_views/webview/HippyWebViewBridge.java +20 -0
  199. package/rules/.source/hippy/hippy_views/webview/HippyWebViewController.java +103 -0
  200. package/rules/.source/hippy/hippy_views/webview/HippyWebViewInner.java +77 -0
  201. package/rules/.windsurfrules +27 -4
  202. package/rules/AGENTS.md +27 -4
  203. package/rules/CLAUDE.md +27 -3
  204. package/rules/GEMINI.md +25 -3
@@ -0,0 +1,108 @@
1
+ /* Tencent is pleased to support the open source community by making Hippy available.
2
+ * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
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.tencent.mtt.hippy.uimanager;
17
+
18
+ import android.view.View;
19
+ import android.view.ViewGroup;
20
+
21
+ import com.tencent.mtt.hippy.utils.LogUtils;
22
+ import com.tencent.mtt.hippy.views.view.HippyViewGroupController;
23
+
24
+ import java.util.ArrayList;
25
+ import java.util.Collections;
26
+ import java.util.Comparator;
27
+
28
+ public class ViewGroupDrawingOrderHelper {
29
+
30
+ private final ViewGroup mViewGroup;
31
+ private int mNumberOfChildrenWithZIndex = 0;
32
+ private int[] mDrawingOrderIndices;
33
+
34
+ public ViewGroupDrawingOrderHelper(ViewGroup viewGroup) {
35
+ mViewGroup = viewGroup;
36
+ }
37
+
38
+
39
+ public void handleAddView(View view) {
40
+ if (HippyViewGroupController.getViewZIndex(view) != null) {
41
+ mNumberOfChildrenWithZIndex++;
42
+ }
43
+
44
+ mDrawingOrderIndices = null;
45
+ }
46
+
47
+
48
+ public void handleRemoveView(View view) {
49
+ if (HippyViewGroupController.getViewZIndex(view) != null) {
50
+ mNumberOfChildrenWithZIndex--;
51
+ }
52
+
53
+ mDrawingOrderIndices = null;
54
+ }
55
+
56
+
57
+ public boolean shouldEnableCustomDrawingOrder() {
58
+ return mNumberOfChildrenWithZIndex > 0;
59
+ }
60
+
61
+
62
+ public int getChildDrawingOrder(int childCount, int index) {
63
+ if (mDrawingOrderIndices == null) {
64
+ ArrayList<View> viewsToSort = new ArrayList<>();
65
+ for (int i = 0; i < childCount; i++) {
66
+ viewsToSort.add(mViewGroup.getChildAt(i));
67
+ }
68
+ // Sort the views by zIndex
69
+ Collections.sort(viewsToSort, new Comparator<View>() {
70
+ @Override
71
+ public int compare(View view1, View view2) {
72
+ Integer view1ZIndex = HippyViewGroupController.getViewZIndex(view1);
73
+ if (view1ZIndex == null) {
74
+ view1ZIndex = 0;
75
+ }
76
+
77
+ Integer view2ZIndex = HippyViewGroupController.getViewZIndex(view2);
78
+ if (view2ZIndex == null) {
79
+ view2ZIndex = 0;
80
+ }
81
+
82
+ return view1ZIndex - view2ZIndex;
83
+ }
84
+ });
85
+
86
+ mDrawingOrderIndices = new int[childCount];
87
+ for (int i = 0; i < childCount; i++) {
88
+ View child = viewsToSort.get(i);
89
+ mDrawingOrderIndices[i] = mViewGroup.indexOfChild(child);
90
+ }
91
+ }
92
+ if (index >= mDrawingOrderIndices.length) {
93
+ LogUtils.d("VGDrawingOrderHelper", "WRONG, index out of mDrawingOrderIndices length");
94
+ return 0;
95
+ }
96
+ return mDrawingOrderIndices[index];
97
+ }
98
+
99
+ public void update() {
100
+ mNumberOfChildrenWithZIndex = 0;
101
+ for (int i = 0; i < mViewGroup.getChildCount(); i++) {
102
+ if (HippyViewGroupController.getViewZIndex(mViewGroup.getChildAt(i)) != null) {
103
+ mNumberOfChildrenWithZIndex++;
104
+ }
105
+ }
106
+ mDrawingOrderIndices = null;
107
+ }
108
+ }
@@ -0,0 +1,10 @@
1
+ package com.tencent.mtt.hippy.uimanager;
2
+
3
+ import android.support.annotation.NonNull;
4
+
5
+ import com.tencent.mtt.hippy.common.HippyMap;
6
+
7
+ public interface ViewStateProvider {
8
+
9
+ void getState(@NonNull HippyMap map);
10
+ }
@@ -0,0 +1,457 @@
1
+ package com.tencent.mtt.hippy.views.audioview;
2
+
3
+ /* Tencent is pleased to support the open source community by making Hippy available.
4
+ * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import android.content.Context;
20
+ import android.media.AudioManager;
21
+ import android.media.MediaPlayer;
22
+ import android.os.Handler;
23
+ import android.os.HandlerThread;
24
+ import android.text.TextUtils;
25
+ import android.util.SparseArray;
26
+
27
+ import com.tencent.mtt.hippy.utils.ContextHolder;
28
+ import com.tencent.mtt.hippy.utils.LogUtils;
29
+
30
+ import java.lang.ref.WeakReference;
31
+
32
+ /**
33
+ * @Description: TODO
34
+ * @author: robinsli
35
+ * @date: 2019/6/11 11:18
36
+ * @version: V1.0
37
+ */
38
+ public class AudioPlayManager
39
+ {
40
+ private static final String TAG = "AudioPlayManager";
41
+ private MediaPlayer mSysMediaPlayer; //系统播放器
42
+ private String mCurrentPlayUrl; //当前播放音频的url
43
+ private int mCurrentPlayID; //当前播放的ID
44
+ private final SparseArray<AudioManagerListener> mPlayCallbackListener = new SparseArray(); //支持多个audio播放,但是如何释放
45
+ private final SparseArray<String> mAudioPlayUrlList = new SparseArray();
46
+ private final SparseArray<Integer> mAudioPlayPositionList = new SparseArray();
47
+ private final HandlerThread mHandlerThread = new HandlerThread("HippyAudioPlayThread");
48
+ private final Handler mHandler;
49
+ private final Runnable mRunnable;
50
+ public static final long PROGRESS_UPDATE_TIME = 1000L; //更新播放进度的时间间隔
51
+ public static final int AUDIO_STREAM_TYPE = 3;
52
+ public static final int PALY_START_POS = 0;
53
+ public static int gUniqPlayId = 0;
54
+
55
+ public static int globalUiqPlayId()
56
+ {
57
+ return ++gUniqPlayId;
58
+ }
59
+
60
+ private static AudioPlayManager sInstance = null;
61
+
62
+ public static AudioPlayManager getInstance()
63
+ {
64
+ if (sInstance == null)
65
+ sInstance = new AudioPlayManager();
66
+ return sInstance;
67
+ }
68
+
69
+ public interface AudioManagerListener
70
+ {
71
+ void onPlayStart(String playAudioUrl); //视频开始播放的回调
72
+
73
+ void onPlayPause(String playAudioUrl); // 暂停
74
+
75
+ void onPlayResume(String playAudioUrl);//继续播放
76
+
77
+ void onPlayError(String playAudioUrl, int what, int extra); //播放失败
78
+
79
+ void onPlayComplete(String playAudioUrl); //播放完成
80
+
81
+ void onPlayBuffering(String playAudioUrl); //音频在缓冲中
82
+
83
+ void onPlayProgress(String playAudioUrl, int currentPlayTimeMs, int audioPlayTotalTimeMs);
84
+ }
85
+
86
+
87
+ public AudioPlayManager()
88
+ {
89
+ /**
90
+ * 初始化音頻播放器
91
+ */
92
+ mSysMediaPlayer = new MediaPlayer();
93
+ mSysMediaPlayer.setAudioStreamType(AUDIO_STREAM_TYPE);
94
+ mSysMediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener()
95
+ {
96
+ public void onBufferingUpdate(MediaPlayer mediaPlayer, int percent)
97
+ {
98
+ if (percent == 100)
99
+ return;
100
+ AudioManagerListener currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
101
+ if (currentPlayCallback != null)
102
+ {
103
+ currentPlayCallback.onPlayBuffering(mCurrentPlayUrl);
104
+ }
105
+ }
106
+ });
107
+ mSysMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
108
+ {
109
+ public void onPrepared(MediaPlayer mediaPlayer)
110
+ {
111
+ int currentPlayPostioin = mAudioPlayPositionList.get(mCurrentPlayID, PALY_START_POS);
112
+ AudioManagerListener currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
113
+ mSysMediaPlayer.seekTo(currentPlayPostioin);
114
+ mSysMediaPlayer.start();
115
+ if (currentPlayCallback != null)
116
+ {
117
+ if (currentPlayPostioin == PALY_START_POS)
118
+ {
119
+ currentPlayCallback.onPlayStart(mCurrentPlayUrl);
120
+ }
121
+ else
122
+ {
123
+ currentPlayCallback.onPlayResume(mCurrentPlayUrl);
124
+ }
125
+ }
126
+ fireProgressChange();
127
+ }
128
+ });
129
+ //系統播放器,播放失敗的回調
130
+ mSysMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener()
131
+ {
132
+ public boolean onError(MediaPlayer mediaPlayer, int what, int extra)
133
+ {
134
+ AudioManagerListener currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
135
+ if (currentPlayCallback != null)
136
+ {
137
+ currentPlayCallback.onPlayError(mCurrentPlayUrl, what, extra);
138
+ }
139
+ return false;
140
+ }
141
+ });
142
+ //系統播放器,播放完成的回調。
143
+ mSysMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
144
+ {
145
+ public void onCompletion(MediaPlayer mp)
146
+ {
147
+ mAudioPlayPositionList.put(mCurrentPlayID, PALY_START_POS); //播放完成,下一次播放的位置位0
148
+ AudioManagerListener currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
149
+ if (currentPlayCallback != null)
150
+ {
151
+ currentPlayCallback.onPlayComplete(mCurrentPlayUrl);
152
+ }
153
+ }
154
+ });
155
+ mHandlerThread.start();
156
+ mHandler = new Handler(mHandlerThread.getLooper());
157
+ mRunnable = new Runnable()
158
+ {
159
+ public void run()
160
+ {
161
+ AudioManagerListener listener = mPlayCallbackListener.get(mCurrentPlayID);
162
+ if (listener != null && mSysMediaPlayer.isPlaying())
163
+ {
164
+ listener.onPlayProgress(mCurrentPlayUrl, mSysMediaPlayer.getCurrentPosition(), mSysMediaPlayer.getDuration());
165
+ mHandler.postDelayed(this, PROGRESS_UPDATE_TIME);
166
+ }
167
+
168
+ }
169
+ };
170
+ }
171
+
172
+ /**
173
+ * nUiqId ---AudioView的标识ID
174
+ * sAudioUrl ---要播放的url
175
+ * playCallback --- 要金监听的播放回调。
176
+ *
177
+ * 返回 true成功
178
+ */
179
+ public boolean setAudioPlayUrl(int nUiqId, String sAudioUrl, AudioManagerListener playCallback)
180
+ {
181
+ if (TextUtils.isEmpty(sAudioUrl)) //参数检查
182
+ {
183
+ return false;
184
+ }
185
+
186
+
187
+ mAudioPlayUrlList.put(nUiqId, sAudioUrl);//记录播放的url
188
+
189
+
190
+ if (playCallback != null) //记录播放的回调
191
+ {
192
+ mPlayCallbackListener.put(nUiqId, playCallback);
193
+ }
194
+ return true;
195
+
196
+ }
197
+
198
+ public boolean seekTo(int nUniqId, int seekToPos)
199
+ {
200
+ //获取播放地址
201
+ String sAudioUrl = mAudioPlayUrlList.get(nUniqId);
202
+ if (TextUtils.isEmpty(sAudioUrl))
203
+ return false;
204
+
205
+ if (mCurrentPlayID == nUniqId && sAudioUrl.equals(mCurrentPlayUrl)) //如果请求播放的音频和当前播放的音频是一样的
206
+ {
207
+ mSysMediaPlayer.seekTo(seekToPos);
208
+ }
209
+ return true;
210
+ }
211
+
212
+ /**
213
+ * 播放音频
214
+ */
215
+ public boolean playAudio(int nUniqId)
216
+ {
217
+ try
218
+ {
219
+ //获取播放地址
220
+ String sAudioUrl = mAudioPlayUrlList.get(nUniqId);
221
+ if (TextUtils.isEmpty(sAudioUrl))
222
+ return false;
223
+ AudioManagerListener currentPlayCallback = null;
224
+
225
+ if (mCurrentPlayID == nUniqId && sAudioUrl.equals(mCurrentPlayUrl)) //如果请求播放的音频和当前播放的音频是一样的
226
+ {
227
+ if (!mSysMediaPlayer.isPlaying())
228
+ {
229
+ mSysMediaPlayer.start(); //开始播放
230
+ currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID); //准备回调
231
+ if (currentPlayCallback != null)
232
+ {
233
+ if (mAudioPlayPositionList.get(mCurrentPlayID, PALY_START_POS) == PALY_START_POS)
234
+ {
235
+ currentPlayCallback.onPlayStart(mCurrentPlayUrl); //从头开始播放
236
+ }
237
+ else
238
+ {
239
+ currentPlayCallback.onPlayResume(mCurrentPlayUrl);//继续播放
240
+ }
241
+ }
242
+
243
+ fireProgressChange();
244
+ }
245
+
246
+ }
247
+ else//如果请求播放的音频和当前播放的音频是不一样的
248
+ {
249
+ if (mSysMediaPlayer.isPlaying()) //播放器正在播放,暂停
250
+ {
251
+ mSysMediaPlayer.pause();
252
+ mAudioPlayPositionList.put(mCurrentPlayID, mSysMediaPlayer.getCurrentPosition());
253
+ currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
254
+ if (currentPlayCallback != null)
255
+ {
256
+ currentPlayCallback.onPlayPause(mCurrentPlayUrl);
257
+ }
258
+ }
259
+
260
+ //准备播放
261
+ mCurrentPlayID = nUniqId;
262
+ mCurrentPlayUrl = sAudioUrl;
263
+ mSysMediaPlayer.reset();
264
+ mSysMediaPlayer.setDataSource(mCurrentPlayUrl);
265
+ mSysMediaPlayer.prepareAsync();
266
+ mSysMediaPlayer.setDisplay(null);
267
+ }
268
+ }
269
+ catch (Exception exception)
270
+ {
271
+ mSysMediaPlayer.reset();
272
+ mCurrentPlayUrl = null;
273
+ mCurrentPlayID = -1;
274
+ LogUtils.d(TAG, "play audio exception" + exception.getMessage());
275
+ return false;
276
+ }
277
+ return true;
278
+ }
279
+
280
+ /**
281
+ * 释放音频播放
282
+ */
283
+ public boolean releaseAudio(int nUniqId)
284
+ {
285
+ String sAudioUrl = mAudioPlayUrlList.get(nUniqId);
286
+
287
+ if (!TextUtils.isEmpty(mCurrentPlayUrl) && mCurrentPlayUrl.equals(sAudioUrl) && nUniqId == mCurrentPlayID )
288
+ {
289
+ mSysMediaPlayer.stop();
290
+ mSysMediaPlayer.reset();
291
+ mCurrentPlayID = -1;
292
+ mCurrentPlayUrl ="";
293
+ }
294
+ mAudioPlayUrlList.delete(nUniqId);
295
+ mPlayCallbackListener.delete(nUniqId);
296
+ mAudioPlayPositionList.delete(nUniqId);
297
+
298
+ return true;
299
+ }
300
+
301
+ /**
302
+ * 暂停音频播放
303
+ */
304
+ public boolean pauseAudio(int nUniqId)
305
+ {
306
+ String sAudioUrl = mAudioPlayUrlList.get(nUniqId);
307
+ if (TextUtils.isEmpty(mCurrentPlayUrl) || !mCurrentPlayUrl.equals(sAudioUrl) || nUniqId != mCurrentPlayID || !mSysMediaPlayer.isPlaying())
308
+ return false;
309
+ mSysMediaPlayer.pause();
310
+ mAudioPlayPositionList.put(mCurrentPlayID, mSysMediaPlayer.getCurrentPosition());
311
+ AudioManagerListener currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
312
+ if (currentPlayCallback != null)
313
+ {
314
+ currentPlayCallback.onPlayPause(mCurrentPlayUrl);
315
+ }
316
+ return true;
317
+ }
318
+
319
+ /**
320
+ * 暂停音频播放
321
+ */
322
+ public boolean stopAudio(int nUniqId)
323
+ {
324
+ String sAudioUrl = mAudioPlayUrlList.get(nUniqId);
325
+ if (TextUtils.isEmpty(mCurrentPlayUrl) || !mCurrentPlayUrl.equals(sAudioUrl) || nUniqId != mCurrentPlayID || !mSysMediaPlayer.isPlaying())
326
+ return false;
327
+ mSysMediaPlayer.stop();
328
+ mAudioPlayPositionList.put(mCurrentPlayID, mSysMediaPlayer.getCurrentPosition());
329
+ AudioManagerListener currentPlayCallback = mPlayCallbackListener.get(mCurrentPlayID);
330
+ if (currentPlayCallback != null)
331
+ {
332
+ currentPlayCallback.onPlayPause(mCurrentPlayUrl);
333
+ }
334
+ return true;
335
+ }
336
+
337
+ public int currentPlayAudioPosition()
338
+ {
339
+ return mSysMediaPlayer.getCurrentPosition();
340
+ }
341
+
342
+ public int currentPlayAudioDuration()
343
+ {
344
+ return mSysMediaPlayer.getDuration();
345
+ }
346
+
347
+
348
+ public void release()
349
+ {
350
+ if (mSysMediaPlayer != null)
351
+ {
352
+ mSysMediaPlayer.stop();
353
+ mSysMediaPlayer.reset();
354
+ mSysMediaPlayer.release();
355
+ mSysMediaPlayer = null;
356
+ mPlayCallbackListener.clear();
357
+ mAudioPlayUrlList.clear();
358
+ mAudioPlayPositionList.clear();
359
+ mCurrentPlayUrl = null;
360
+ mCurrentPlayID = -1;
361
+ mHandler.removeCallbacks(mRunnable);
362
+ }
363
+
364
+ }
365
+
366
+ private void fireProgressChange()
367
+ {
368
+ mHandler.post(mRunnable);
369
+ }
370
+
371
+ /**
372
+ * 获取声音播放焦点
373
+ */
374
+ public static int requestAudioFocus()
375
+ {
376
+ return requestAudioFocus(null);
377
+ }
378
+
379
+ public interface OnAudioStateChange
380
+ {
381
+ void onChange(int state);
382
+ }
383
+
384
+ private static Object afChangeListener;
385
+ private static final AudioManager audioManager = (AudioManager) ContextHolder.getAppContext().getSystemService(Context.AUDIO_SERVICE);
386
+ private static final int AUDIOFOCUS_LOSS_TRANSIENT = -2;
387
+
388
+ public static int requestAudioFocus(OnAudioStateChange onAudioStateChange)
389
+ {
390
+ int result = 0;
391
+ final WeakReference<OnAudioStateChange> reference = new WeakReference<OnAudioStateChange>(onAudioStateChange);
392
+ try
393
+ {
394
+ // 创建监听器
395
+ afChangeListener = new AudioManager.OnAudioFocusChangeListener()
396
+ {
397
+ public void onAudioFocusChange(int focusChange)
398
+ {
399
+ if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT)
400
+ {
401
+ audioManager.abandonAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener);
402
+ // 停止播放
403
+ }
404
+ else if (focusChange == AudioManager.AUDIOFOCUS_GAIN)
405
+ {
406
+ // 恢复播放
407
+ }
408
+ else if (focusChange == AudioManager.AUDIOFOCUS_LOSS)
409
+ {
410
+ audioManager.abandonAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener);
411
+ // 停止播放
412
+ }
413
+ if (reference != null)
414
+ {
415
+ OnAudioStateChange callback = reference.get();
416
+ if (callback != null)
417
+ {
418
+ callback.onChange(focusChange);
419
+ }
420
+
421
+ }
422
+ }
423
+ };
424
+ // 请求播放的音频焦点
425
+ result = audioManager.requestAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener,
426
+ // 指定所使用的音频流
427
+ AudioManager.STREAM_MUSIC,
428
+ // 请求长时间的音频焦点
429
+ AudioManager.AUDIOFOCUS_GAIN);
430
+ }
431
+ catch (Throwable e)
432
+ {
433
+ // QZLog.e(QZLog.TO_DEVICE_TAG, "AudioHelper requestAudioFocus: " + e.getMessage(), e);
434
+ }
435
+
436
+ return result;
437
+ }
438
+
439
+ /**
440
+ * 释放声音播放焦点
441
+ *
442
+ */
443
+ public static void abandonAudioFocus()
444
+ {
445
+ try
446
+ {
447
+ if (audioManager != null)
448
+ {
449
+ audioManager.abandonAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener);
450
+ }
451
+ }
452
+ catch (Throwable e)
453
+ {
454
+ }
455
+ }
456
+
457
+ }