• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 com.android.sampleplugin;
18 
19 import android.content.Context;
20 import android.graphics.PixelFormat;
21 import android.opengl.GLSurfaceView;
22 import android.view.SurfaceHolder;
23 import android.view.SurfaceView;
24 import android.view.View;
25 import android.view.WindowManager;
26 import android.view.SurfaceHolder.Callback;
27 import android.view.ViewGroup.LayoutParams;
28 import android.webkit.PluginStub;
29 import android.widget.FrameLayout;
30 import android.widget.MediaController;
31 import android.widget.VideoView;
32 import com.android.sampleplugin.graphics.CubeRenderer;
33 
34 public class SamplePluginStub implements PluginStub {
35 
36     static {
37         //needed for jni calls
38         System.loadLibrary("sampleplugin");
39     }
40 
getEmbeddedView(final int npp, Context context)41     public View getEmbeddedView(final int npp, Context context) {
42 
43         final SurfaceView view = new SurfaceView(context);
44 
45         /* You can do all sorts of interesting operations on the surface view
46          * here. We illustrate a few of the important operations below.
47          */
48 
49         //TODO get pixel format from the subplugin (via jni)
50         view.getHolder().setFormat(PixelFormat.RGBA_8888);
51         view.getHolder().addCallback(new Callback() {
52 
53             public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
54                 nativeSurfaceChanged(npp, format, width, height);
55             }
56 
57             public void surfaceCreated(SurfaceHolder holder) {
58                 nativeSurfaceCreated(npp, view);
59             }
60 
61             public void surfaceDestroyed(SurfaceHolder holder) {
62                 nativeSurfaceDestroyed(npp);
63             }
64 
65         });
66 
67         if (nativeIsFixedSurface(npp)) {
68             //TODO get the fixed dimensions from the plugin
69             //view.getHolder().setFixedSize(width, height);
70         }
71 
72         return view;
73     }
74 
getFullScreenView(int npp, Context context)75     public View getFullScreenView(int npp, Context context) {
76 
77         /* TODO make this aware of the plugin instance and get the video file
78          * from the plugin.
79          */
80 
81         FrameLayout layout = new FrameLayout(context);
82         LayoutParams fp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
83         layout.setLayoutParams(fp);
84 
85         VideoView video = new VideoView(context);
86         LayoutParams vp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
87         layout.setLayoutParams(vp);
88 
89         GLSurfaceView gl = new GLSurfaceView(context);
90         LayoutParams gp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
91         layout.setLayoutParams(gp);
92 
93         layout.addView(video);
94         layout.addView(gl);
95 
96         // We want an 8888 pixel format because that's required for a translucent
97         // window. And we want a depth buffer.
98         gl.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
99         // Tell the cube renderer that we want to render a translucent version
100         // of the cube:
101         gl.setRenderer(new CubeRenderer(true));
102         // Use a surface format with an Alpha channel:
103         gl.getHolder().setFormat(PixelFormat.TRANSLUCENT);
104         gl.setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY);
105 
106 
107         video.setVideoPath("/sdcard/test_video.3gp");
108         video.setMediaController(new MediaController(context));
109         video.requestFocus();
110 
111         return layout;
112     }
113 
nativeSurfaceCreated(int npp, View surfaceView)114     private native void nativeSurfaceCreated(int npp, View surfaceView);
nativeSurfaceChanged(int npp, int format, int width, int height)115     private native void nativeSurfaceChanged(int npp, int format, int width, int height);
nativeSurfaceDestroyed(int npp)116     private native void nativeSurfaceDestroyed(int npp);
nativeIsFixedSurface(int npp)117     private native boolean nativeIsFixedSurface(int npp);
118 }
119