AI2 Component  (Version nb184)
CustomMediaController.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2012 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime.util;
8 
9 import android.content.Context;
10 import android.util.Log;
11 import android.view.MotionEvent;
12 import android.view.View;
13 import android.view.ViewGroup;
14 import android.widget.MediaController;
15 
26 public class CustomMediaController extends MediaController implements
27  View.OnTouchListener {
28 
29  // The view whose touch events are listened to.
30  private View mAnchorView;
31 
32  /*
33  * How long the GUI should be shown when the anchorView passed in
34  */
35  private int mShowTime = 3000;
36 
37  public CustomMediaController(Context context) {
38  super(context);
39  }
40 
47  @Override
48  public void show(int timeout) {
49  setVisibility(VISIBLE);
50  super.show(timeout);
51  }
52 
57  @Override
58  public void show() {
59  setVisibility(VISIBLE);
60  super.show();
61  }
62 
75  public boolean addTo(ViewGroup parent, ViewGroup.LayoutParams params) {
76  Object mParent = getParent();
77  if (mParent != null && mParent instanceof ViewGroup) {
78  ((ViewGroup) mParent).removeView(this);
79  parent.addView(this, params);
80  return true;
81  } else {
82  Log.e("CustomMediaController.addTo",
83  "MediaController not available in fullscreen.");
84  return false;
85  }
86  }
87 
92  @Override
93  public void setAnchorView(View anchorView) {
94  mAnchorView = anchorView;
95  mAnchorView.setOnTouchListener(this);
96  super.setAnchorView(anchorView);
97  }
98 
103  @Override
104  public void hide() {
105  super.hide();
106  setVisibility(INVISIBLE);
107  }
108 
114  @Override
115  public boolean onTouch(View v, MotionEvent event) {
116  if (v == mAnchorView) {
117  show(mShowTime);
118  }
119  return false;
120  }
121 
122 }
com.google.appinventor.components.runtime.util.CustomMediaController.show
void show(int timeout)
Definition: CustomMediaController.java:48
com.google.appinventor.components.runtime.util.CustomMediaController.hide
void hide()
Definition: CustomMediaController.java:104
com.google.appinventor.components.runtime.util.CustomMediaController.onTouch
boolean onTouch(View v, MotionEvent event)
Definition: CustomMediaController.java:115
com.google.appinventor.components.runtime.util.CustomMediaController.CustomMediaController
CustomMediaController(Context context)
Definition: CustomMediaController.java:37
com.google.appinventor.components.runtime.util.CustomMediaController.show
void show()
Definition: CustomMediaController.java:58
com.google.appinventor.components.runtime.util.CustomMediaController.addTo
boolean addTo(ViewGroup parent, ViewGroup.LayoutParams params)
Definition: CustomMediaController.java:75
com.google.appinventor.components.runtime.util.CustomMediaController.setAnchorView
void setAnchorView(View anchorView)
Definition: CustomMediaController.java:93
com.google.appinventor.components.runtime.util.CustomMediaController
Definition: CustomMediaController.java:26