Christofer Ã…kersten | cfa0370 | 2017-12-20 17:58:15 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 android.widget; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.content.Context; |
| 22 | import android.graphics.Canvas; |
| 23 | import android.media.session.MediaController; |
| 24 | import android.media.update.ApiLoader; |
| 25 | import android.media.update.MediaController2Provider; |
| 26 | import android.media.update.ViewProvider; |
| 27 | import android.util.AttributeSet; |
| 28 | import android.view.KeyEvent; |
| 29 | import android.view.MotionEvent; |
| 30 | import android.view.View; |
| 31 | import android.view.View.OnClickListener; |
| 32 | |
| 33 | /** |
| 34 | * TODO PUBLIC API |
| 35 | * @hide |
| 36 | */ |
| 37 | public class MediaController2 extends FrameLayout { |
| 38 | private final MediaController2Provider mProvider; |
| 39 | |
| 40 | public MediaController2(@NonNull Context context) { |
| 41 | this(context, null); |
| 42 | } |
| 43 | |
| 44 | public MediaController2(@NonNull Context context, @Nullable AttributeSet attrs) { |
| 45 | this(context, attrs, 0); |
| 46 | } |
| 47 | |
| 48 | public MediaController2(@NonNull Context context, @Nullable AttributeSet attrs, |
| 49 | int defStyleAttr) { |
| 50 | this(context, attrs, defStyleAttr, 0); |
| 51 | } |
| 52 | |
| 53 | public MediaController2(@NonNull Context context, @Nullable AttributeSet attrs, |
| 54 | int defStyleAttr, int defStyleRes) { |
| 55 | super(context, attrs, defStyleAttr, defStyleRes); |
| 56 | |
| 57 | mProvider = ApiLoader.getProvider(context) |
| 58 | .createMediaController2(this, new SuperProvider()); |
| 59 | } |
| 60 | |
| 61 | public void setController(MediaController controller) { |
| 62 | mProvider.setController_impl(controller); |
| 63 | } |
| 64 | |
| 65 | public void setAnchorView(View view) { |
| 66 | mProvider.setAnchorView_impl(view); |
| 67 | } |
| 68 | |
| 69 | public void show() { |
| 70 | mProvider.show_impl(); |
| 71 | } |
| 72 | |
| 73 | public void show(int timeout) { |
| 74 | mProvider.show_impl(timeout); |
| 75 | } |
| 76 | |
| 77 | public boolean isShowing() { |
| 78 | return mProvider.isShowing_impl(); |
| 79 | } |
| 80 | |
| 81 | public void hide() { |
| 82 | mProvider.hide_impl(); |
| 83 | } |
| 84 | |
| 85 | public void setPrevNextListeners(OnClickListener next, OnClickListener prev) { |
| 86 | mProvider.setPrevNextListeners_impl(next, prev); |
| 87 | } |
| 88 | |
| 89 | public void showCCButton() { |
| 90 | mProvider.showCCButton_impl(); |
| 91 | } |
| 92 | |
| 93 | public boolean isPlaying() { |
| 94 | return mProvider.isPlaying_impl(); |
| 95 | } |
| 96 | |
| 97 | public int getCurrentPosition() { |
| 98 | return mProvider.getCurrentPosition_impl(); |
| 99 | } |
| 100 | |
| 101 | public int getBufferPercentage() { |
| 102 | return mProvider.getBufferPercentage_impl(); |
| 103 | } |
| 104 | |
| 105 | public boolean canPause() { |
| 106 | return mProvider.canPause_impl(); |
| 107 | } |
| 108 | |
| 109 | public boolean canSeekBackward() { |
| 110 | return mProvider.canSeekBackward_impl(); |
| 111 | } |
| 112 | |
| 113 | public boolean canSeekForward() { |
| 114 | return mProvider.canSeekForward_impl(); |
| 115 | } |
| 116 | |
| 117 | public void showSubtitle() { |
| 118 | mProvider.showSubtitle_impl(); |
| 119 | } |
| 120 | |
| 121 | public void hideSubtitle() { |
| 122 | mProvider.hideSubtitle_impl(); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | protected void onAttachedToWindow() { |
| 127 | mProvider.onAttachedToWindow_impl(); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | protected void onDetachedFromWindow() { |
| 132 | mProvider.onDetachedFromWindow_impl(); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 137 | mProvider.onLayout_impl(changed, left, top, right, bottom); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public void draw(Canvas canvas) { |
| 142 | mProvider.draw_impl(canvas); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public CharSequence getAccessibilityClassName() { |
| 147 | return mProvider.getAccessibilityClassName_impl(); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public boolean onTouchEvent(MotionEvent ev) { |
| 152 | return mProvider.onTouchEvent_impl(ev); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean onTrackballEvent(MotionEvent ev) { |
| 157 | return mProvider.onTrackballEvent_impl(ev); |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 162 | return mProvider.onKeyDown_impl(keyCode, event); |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public void onFinishInflate() { |
| 167 | mProvider.onFinishInflate_impl(); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 172 | return mProvider.dispatchKeyEvent_impl(event); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void setEnabled(boolean enabled) { |
| 177 | mProvider.setEnabled_impl(enabled); |
| 178 | } |
| 179 | |
| 180 | private class SuperProvider implements ViewProvider { |
| 181 | @Override |
| 182 | public void onAttachedToWindow_impl() { |
| 183 | MediaController2.super.onAttachedToWindow(); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void onDetachedFromWindow_impl() { |
| 188 | MediaController2.super.onDetachedFromWindow(); |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void onLayout_impl(boolean changed, int left, int top, int right, int bottom) { |
| 193 | MediaController2.super.onLayout(changed, left, top, right, bottom); |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void draw_impl(Canvas canvas) { |
| 198 | MediaController2.super.draw(canvas); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public CharSequence getAccessibilityClassName_impl() { |
| 203 | return MediaController2.super.getAccessibilityClassName(); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public boolean onTouchEvent_impl(MotionEvent ev) { |
| 208 | return MediaController2.super.onTouchEvent(ev); |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public boolean onTrackballEvent_impl(MotionEvent ev) { |
| 213 | return MediaController2.super.onTrackballEvent(ev); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public boolean onKeyDown_impl(int keyCode, KeyEvent event) { |
| 218 | return MediaController2.super.onKeyDown(keyCode, event); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public void onFinishInflate_impl() { |
| 223 | MediaController2.super.onFinishInflate(); |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public boolean dispatchKeyEvent_impl(KeyEvent event) { |
| 228 | return MediaController2.super.dispatchKeyEvent(event); |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public void setEnabled_impl(boolean enabled) { |
| 233 | MediaController2.super.setEnabled(enabled); |
| 234 | } |
| 235 | } |
| 236 | } |