3030import android .view .ViewGroup ;
3131import android .view .accessibility .AccessibilityEvent ;
3232import android .view .accessibility .AccessibilityNodeInfo ;
33- import android .widget .FrameLayout ;
34- import android .widget .ImageButton ;
33+ import android .widget .LinearLayout ;
3534import android .widget .MediaController .MediaPlayerControl ;
36- import android .widget .ProgressBar ;
3735import android .widget .SeekBar ;
3836import android .widget .SeekBar .OnSeekBarChangeListener ;
39- import android .widget .TextView ;
4037
4138import com .owncloud .android .MainApp ;
4239import com .owncloud .android .R ;
40+ import com .owncloud .android .databinding .MediaControlBinding ;
4341import com .owncloud .android .lib .common .utils .Log_OC ;
4442import com .owncloud .android .utils .theme .ViewThemeUtils ;
4543
5654 * <p>
5755 * It synchronizes itself with the state of the {@link MediaPlayer}.
5856 */
59- public class MediaControlView extends FrameLayout implements OnClickListener , OnSeekBarChangeListener {
57+ public class MediaControlView extends LinearLayout implements OnClickListener , OnSeekBarChangeListener {
6058 private static final String TAG = MediaControlView .class .getSimpleName ();
6159 private static final int SHOW_PROGRESS = 1 ;
6260
6361 private MediaPlayerControl playerControl ;
64- private final View root ;
65- private ProgressBar progressBar ;
66- private TextView endTime ;
67- private TextView currentTime ;
62+ private final MediaControlBinding binding ;
6863 private boolean isDragging ;
69- private ImageButton pauseButton ;
70- private ImageButton forwardButton ;
71- private ImageButton rewindButton ;
7264
7365 @ Inject
7466 ViewThemeUtils viewThemeUtils ;
@@ -80,14 +72,9 @@ public MediaControlView(Context context,
8072
8173 MainApp .getAppComponent ().inject (this );
8274
83- FrameLayout .LayoutParams frameParams = new FrameLayout .LayoutParams (
84- ViewGroup .LayoutParams .MATCH_PARENT ,
85- ViewGroup .LayoutParams .MATCH_PARENT
86- );
8775 LayoutInflater inflate = (LayoutInflater ) context .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
88- root = inflate .inflate (R .layout .media_control , null );
89- initControllerView (root );
90- addView (root , frameParams );
76+ binding = MediaControlBinding .inflate (inflate , this , true );
77+ initControllerView ();
9178
9279 setFocusable (true );
9380 setFocusableInTouchMode (true );
@@ -103,7 +90,7 @@ public void onFinishInflate() {
10390 public void setMediaPlayer (MediaPlayerControl player ) {
10491 playerControl = player ;
10592 handler .sendEmptyMessage (SHOW_PROGRESS );
106- handler .postDelayed (()-> {
93+ handler .postDelayed (() -> {
10794 updatePausePlay ();
10895 setProgress ();
10996 }, 100 );
@@ -113,37 +100,17 @@ public void stopMediaPlayerMessages() {
113100 handler .removeMessages (SHOW_PROGRESS );
114101 }
115102
116- private void initControllerView (View v ) {
117- pauseButton = v .findViewById (R .id .playBtn );
118- if (pauseButton != null ) {
119- pauseButton .requestFocus ();
120- pauseButton .setOnClickListener (this );
121- }
103+ private void initControllerView () {
104+ binding .playBtn .requestFocus ();
105+ binding .playBtn .setOnClickListener (this );
122106
123- forwardButton = v .findViewById (R .id .forwardBtn );
124- if (forwardButton != null ) {
125- forwardButton .setOnClickListener (this );
126- }
107+ binding .forwardBtn .setOnClickListener (this );
127108
128- rewindButton = v .findViewById (R .id .rewindBtn );
129- if (rewindButton != null ) {
130- rewindButton .setOnClickListener (this );
131- }
132-
133- progressBar = v .findViewById (R .id .progressBar );
134- if (progressBar != null ) {
135- if (progressBar instanceof SeekBar ) {
136- SeekBar seeker = (SeekBar ) progressBar ;
137- viewThemeUtils .platform .themeHorizontalSeekBar (seeker );
138- seeker .setOnSeekBarChangeListener (this );
139- } else {
140- viewThemeUtils .platform .themeHorizontalProgressBar (progressBar );
141- }
142- progressBar .setMax (1000 );
143- }
109+ binding .rewindBtn .setOnClickListener (this );
144110
145- endTime = v .findViewById (R .id .totalTimeText );
146- currentTime = v .findViewById (R .id .currentTimeText );
111+ viewThemeUtils .platform .themeHorizontalSeekBar (binding .progressBar );
112+ binding .progressBar .setOnSeekBarChangeListener (this );
113+ binding .progressBar .setMax (1000 );
147114 }
148115
149116 /**
@@ -152,15 +119,18 @@ private void initControllerView(View v) {
152119 */
153120 private void disableUnsupportedButtons () {
154121 try {
155- if (pauseButton != null && !playerControl .canPause ()) {
156- pauseButton .setEnabled (false );
157- }
158- if (rewindButton != null && !playerControl .canSeekBackward ()) {
159- rewindButton .setEnabled (false );
160- }
161- if (forwardButton != null && !playerControl .canSeekForward ()) {
162- forwardButton .setEnabled (false );
122+ if (binding != null ) {
123+ if (!playerControl .canPause ()) {
124+ binding .playBtn .setEnabled (false );
125+ }
126+ if (!playerControl .canSeekBackward ()) {
127+ binding .rewindBtn .setEnabled (false );
128+ }
129+ if (!playerControl .canSeekForward ()) {
130+ binding .forwardBtn .setEnabled (false );
131+ }
163132 }
133+
164134 } catch (IncompatibleClassChangeError ex ) {
165135 // We were given an old version of the interface, that doesn't have
166136 // the canPause/canSeekXYZ methods. This is OK, it just means we
@@ -205,23 +175,20 @@ private int setProgress() {
205175 }
206176 int position = playerControl .getCurrentPosition ();
207177 int duration = playerControl .getDuration ();
208- if (progressBar != null ) {
178+ if (binding != null ) {
209179 if (duration > 0 ) {
210180 // use long to avoid overflow
211181 long pos = 1000L * position / duration ;
212- progressBar .setProgress ((int ) pos );
182+ binding . progressBar .setProgress ((int ) pos );
213183 }
214184 int percent = playerControl .getBufferPercentage ();
215- progressBar .setSecondaryProgress (percent * 10 );
216- }
185+ binding .progressBar .setSecondaryProgress (percent * 10 );
217186
218- if (endTime != null ) {
219187 String endTime = duration > 0 ? formatTime (duration ) : "--:--" ;
220- this .endTime .setText (endTime );
221- }
222- if (currentTime != null ) {
223- currentTime .setText (formatTime (position ));
188+ binding .totalTimeText .setText (endTime );
189+ binding .currentTimeText .setText (formatTime (position ));
224190 }
191+
225192 return position ;
226193 }
227194
@@ -236,8 +203,8 @@ public boolean dispatchKeyEvent(KeyEvent event) {
236203 if (uniqueDown ) {
237204 doPauseResume ();
238205 //show(sDefaultTimeout);
239- if (pauseButton != null ) {
240- pauseButton .requestFocus ();
206+ if (binding != null ) {
207+ binding . playBtn .requestFocus ();
241208 }
242209 }
243210 return true ;
@@ -260,28 +227,28 @@ public boolean dispatchKeyEvent(KeyEvent event) {
260227 }
261228
262229 public void updatePausePlay () {
263- if (root == null || pauseButton == null ) {
230+ if (binding == null ) {
264231 return ;
265232 }
266233
267234 if (playerControl .isPlaying ()) {
268- pauseButton .setImageResource (android .R .drawable .ic_media_pause );
235+ binding . playBtn .setImageResource (android .R .drawable .ic_media_pause );
269236 } else {
270- pauseButton .setImageResource (android .R .drawable .ic_media_play );
237+ binding . playBtn .setImageResource (android .R .drawable .ic_media_play );
271238 }
272239
273240 final boolean canSeekFfd = playerControl .canSeekForward ();
274241 if (canSeekFfd ) {
275- forwardButton .setVisibility (View .VISIBLE );
242+ binding . forwardBtn .setVisibility (View .VISIBLE );
276243 } else {
277- forwardButton .setVisibility (View .INVISIBLE );
244+ binding . forwardBtn .setVisibility (View .INVISIBLE );
278245 }
279246
280247 final boolean canSeekBwd = playerControl .canSeekBackward ();
281248 if (canSeekBwd ) {
282- rewindButton .setVisibility (View .VISIBLE );
249+ binding . rewindBtn .setVisibility (View .VISIBLE );
283250 } else {
284- rewindButton .setVisibility (View .INVISIBLE );
251+ binding . rewindBtn .setVisibility (View .INVISIBLE );
285252 }
286253 }
287254
@@ -296,18 +263,13 @@ private void doPauseResume() {
296263
297264 @ Override
298265 public void setEnabled (boolean enabled ) {
299- if (pauseButton != null ) {
300- pauseButton .setEnabled (enabled );
301- }
302- if (forwardButton != null ) {
303- forwardButton .setEnabled (enabled );
304- }
305- if (rewindButton != null ) {
306- rewindButton .setEnabled (enabled );
307- }
308- if (progressBar != null ) {
309- progressBar .setEnabled (enabled );
266+ if (binding !=null ){
267+ binding .playBtn .setEnabled (enabled );
268+ binding .forwardBtn .setEnabled (enabled );
269+ binding .rewindBtn .setEnabled (enabled );
270+ binding .progressBar .setEnabled (enabled );
310271 }
272+
311273 disableUnsupportedButtons ();
312274 super .setEnabled (enabled );
313275 }
@@ -350,9 +312,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
350312 long duration = playerControl .getDuration ();
351313 long newPosition = (duration * progress ) / 1000L ;
352314 playerControl .seekTo ((int ) newPosition );
353- if (currentTime != null ) {
354- currentTime .setText (formatTime ((int ) newPosition ));
355- }
315+ binding .currentTimeText .setText (formatTime ((int ) newPosition ));
356316 }
357317
358318 /**
0 commit comments