Commit 98fd7ce8 authored by Vance's avatar Vance Committed by Jeffrey I. Schiller

Add Resizable and Full Screen Video Player

Change-Id: Ica112991b56c830fcd42eb436b3921f63ce81723
parent cba736dc
......@@ -77,10 +77,6 @@ public final class MockVideoPlayer extends MockVisibleComponent {
@Override
protected boolean isPropertyVisible(String propertyName) {
if (propertyName.equals(PROPERTY_NAME_WIDTH) ||
propertyName.equals(PROPERTY_NAME_HEIGHT)) {
return false;
}
return super.isPropertyVisible(propertyName);
}
}
......@@ -753,6 +753,13 @@ public final class YoungAndroidFormUpgrader {
// No properties need to be modified to upgrade to version 3.
srcCompVersion = 3;
}
if (srcCompVersion < 4) {
// The VideoPlayer.height and VideoPlayer.width getter and setters were marked as
// visible to the user.
// The FullScreen property was created.
// No properties need to be modified to upgrade to version 4.
srcCompVersion = 4;
}
return srcCompVersion;
}
......
......@@ -951,6 +951,11 @@ public class BlockSaveFile {
}
blkCompVersion = 3;
}
if (blkCompVersion < 4) {
// The VideoPlayer.height and VideoPlayer.width getter and setters were marked as
// visible to the user
blkCompVersion = 4;
}
return blkCompVersion;
}
......
......@@ -176,11 +176,12 @@ public class YaVersion {
// - PLAYER_COMPONENT_VERSION was incremented to 4.
// For YOUNG_ANDROID_VERSION 58:
// - FORM_COMPONENT_VERSION was incremented to 7.
// For YOUNG_ANDROID_VERSION 59:
//The Camcorder component was added.
// For YOUNG_ANDROID_VERION 59:
// The Camcorder component was added.
// For YOUNG_ANDROID_VERION 60:
// - VIDEOPLAYER_COMPONENT_VERSION was incremented to 4.
public static final int YOUNG_ANDROID_VERSION = 59;
public static final int YOUNG_ANDROID_VERSION = 60;
// ............................... Blocks Language Version Number ...............................
......@@ -499,7 +500,10 @@ public class YaVersion {
// - The VideoPlayer.VideoPlayerError event was added.
// For VIDEOPLAYER_COMPONENT_VERSION 3:
// - The VideoPlayer.VideoPlayerError event was marked userVisible false and is no longer used.
public static final int VIDEOPLAYER_COMPONENT_VERSION = 3;
// For VIDEOPLAYER_COMPONENT_VERSION 4:
// - The VideoPlayer.width and VideoPlayer.height variables were marked as user visible.
// - The FullScreen property was added to the VideoPlayer.
public static final int VIDEOPLAYER_COMPONENT_VERSION = 4;
public static final int VOTING_COMPONENT_VERSION = 1;
......
......@@ -6,7 +6,6 @@ import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
......@@ -18,6 +17,7 @@ import com.google.appinventor.components.runtime.collect.Lists;
import com.google.appinventor.components.runtime.collect.Maps;
import com.google.appinventor.components.runtime.collect.Sets;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.FullScreenVideoUtil;
import com.google.appinventor.components.runtime.util.JsonUtil;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.util.SdkLevel;
......@@ -25,6 +25,7 @@ import com.google.appinventor.components.runtime.util.ViewUtil;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -131,6 +132,8 @@ public class Form extends Activity
// event.
private String nextFormName;
private FullScreenVideoUtil fullScreenVideoUtil;
@Override
public void onCreate(Bundle icicle) {
// Called when the activity is first created
......@@ -155,6 +158,8 @@ public class Form extends Activity
startupValue = startIntent.getStringExtra(ARGUMENT_NAME);
}
fullScreenVideoUtil = new FullScreenVideoUtil(this, androidUIHandler);
// Add application components to the form
$define();
......@@ -350,6 +355,25 @@ public class Form extends Activity
onDestroyListeners.add(component);
}
public Dialog onCreateDialog(int id, Bundle args) {
switch(id) {
case FullScreenVideoUtil.FULLSCREEN_VIDEO_DIALOG_FLAG:
return fullScreenVideoUtil.createFullScreenVideoDialog(args);
default:
return super.onCreateDialog(id, args);
}
}
public void onPrepareDialog(int id, Dialog dialog, Bundle args) {
switch(id) {
case FullScreenVideoUtil.FULLSCREEN_VIDEO_DIALOG_FLAG:
fullScreenVideoUtil.prepareFullScreenVideoDialog(dialog, args);
break;
default:
super.onPrepareDialog(id, dialog, args);
}
}
/**
* Compiler-generated method to initialize and add application components to
* the form. We just provide an implementation here to artificially make
......@@ -494,6 +518,7 @@ public class Form extends Activity
if (backgroundDrawable != null) {
ViewUtil.setBackgroundImage(frameLayout, backgroundDrawable);
}
setContentView(frameLayout);
frameLayout.requestLayout();
}
......@@ -1117,4 +1142,41 @@ public class Form extends Activity
throw e.getTargetException();
}
}
/**
* Perform some action related to fullscreen video display.
* @param action
* Can be any of the following:
* <ul>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_DURATION}
* </li>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_FULLSCREEN}
* </li>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_PAUSE}
* </li>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_PLAY}
* </li>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_SEEK}
* </li>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_SOURCE}
* </li>
* <li>
* {@link com.google.appinventor.components.runtime.util.FullScreenVideoUtil#FULLSCREEN_VIDEO_ACTION_STOP}
* </li>
* </ul>
* @param source
* The VideoPlayer to use in some actions.
* @param data
* Used by the method. This object varies depending on the action.
* @return Varies depending on what action was passed in.
*/
public synchronized Bundle fullScreenVideoAction(int action, VideoPlayer source, Object data) {
return fullScreenVideoUtil.performAction(action, source, data);
}
}
// Copyright MIT
package com.google.appinventor.components.runtime.util;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
/**
* A modified MediaController that allows adding to a
* {@link android.view.ViewGroup} instead of the Window that Android adds the
* MediaController to.
*
* This class manages displaying the controller GUI.
*
* @author Vance Turnewitsch
*
*/
public class CustomMediaController extends MediaController implements
View.OnTouchListener {
// The view whose touch events are listened to.
private View mAnchorView;
/*
* How long the GUI should be shown when the anchorView passed in
*/
private int mShowTime = 3000;
public CustomMediaController(Context context) {
super(context);
}
/**
* Sets the visibility of the GUI to {@link android.view.View#VISIBLE}
* and calls {@link android.widget.MediaController#show(int)}.
* @param timeout
* How long the GUI should be shown for.
*/
@Override
public void show(int timeout) {
setVisibility(VISIBLE);
super.show(timeout);
}
/**
* Sets the visibility of the GUI to {@link android.view.View#VISIBLE}
* and calls {@link android.widget.MediaController#show()}.
*/
@Override
public void show() {
setVisibility(VISIBLE);
super.show();
}
/**
* Attempts to remove this CustomMediaController from the Window that Android
* automatically adds it to and add it to another
* {@link android.view.ViewGroup}.
*
* @param parent
* The {@link android.view.ViewGroup} to add the CustomMediaController
* to.
* @param params
* The {@link android.view.ViewGroup.LayoutParams} to use when adding
* the CustomMediaController to the parent.
*/
public boolean addTo(ViewGroup parent, ViewGroup.LayoutParams params) {
Object mParent = getParent();
if (mParent != null && mParent instanceof ViewGroup) {
((ViewGroup) mParent).removeView(this);
parent.addView(this, params);
return true;
} else {
Log.e("CustomMediaController.addTo",
"MediaController not available in fullscreen.");
return false;
}
}
/**
* Calls {@link android.widget.MediaController#setAnchorView(View)} and sets
* up a listener that shows a GUI when the anchorView is touched.
*/
@Override
public void setAnchorView(View anchorView) {
mAnchorView = anchorView;
mAnchorView.setOnTouchListener(this);
super.setAnchorView(anchorView);
}
/**
* Calls {@link android.widget.MediaController#hide()} and sets the visibility
* of this object to {@link android.view.View#INVISIBLE}.
*/
@Override
public void hide() {
super.hide();
setVisibility(INVISIBLE);
}
/**
* Called when the anchorView passed in
* {@link CustomMediaController#setAnchorView(View)} is touched. Shows the
* controller GUI.
*/
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v == mAnchorView) {
show(mShowTime);
}
return false;
}
}
......@@ -115,8 +115,10 @@ public final class ErrorMessages {
public static final int ERROR_PHONE_UNSUPPORTED_SEARCH_IN_CONTACT_PICKING = 1108;
//Camcorder errors
public static final int ERROR_CAMCORDER_NO_CLIP_RETURNED = 1201;
// Please start the next group of error numbers at 1301.
// VideoPlayer errors
public static final int ERROR_VIDEOPLAYER_FULLSCREEN_UNAVAILBLE = 1301;
public static final int ERROR_VIDEOPLAYER_FULLSCREEN_CANT_EXIT = 1302;
//Please start the next group of error numbers at 1401.
// Mapping of error numbers to error message format strings.
private static final Map<Integer, String> errorMessages;
......@@ -315,6 +317,11 @@ public final class ErrorMessages {
// Camcorder errors
errorMessages.put(ERROR_CAMCORDER_NO_CLIP_RETURNED,
"The camcorder did not return a clip.");
// VideoPlayer errors
errorMessages.put(ERROR_VIDEOPLAYER_FULLSCREEN_UNAVAILBLE,
"Cannot start fullscreen mode.");
errorMessages.put(ERROR_VIDEOPLAYER_FULLSCREEN_CANT_EXIT,
"Cannot exit fullscreen mode.");
}
private ErrorMessages() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment