使用带闪光灯的WebView时,屏幕闪烁 [英] Screen blinking when using a webview with flash

查看:506
本文介绍了使用带闪光灯的WebView时,屏幕闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我做了一个演示APK,这样你就可以明白我的意思: http://cl.ly/3g0s1p030j243y0p3m2F

I made a demo apk, so you can understand what I mean: http://cl.ly/3g0s1p030j243y0p3m2F

有关我的应用程序,我想一种超级电源点,或基调采用所有的Andr​​oid善良,手势等..上(商业团队将present产品给他们的客户) Android平板电脑。由于蜂窝还没有准备好,因为我们的行军之前需要它,我们选择了一些随机的升级Froyo平板电脑(爱可视101),但我的问题是每一个平板电脑/手机,我试过了。

For my application, I want a kind of "Super Power Point", or a keynote (the commercial team will present the product to their customers) using all the Android goodness, gestures, etc... on an Android tablet. As Honeycomb is not yet ready and because we need it before march, we choose some random Froyo Tablet (Archos 101), but my issue is for every tablet/phone I tried.

我做了一个真正伟大的应用程序,但在presentation一些动画,客户想用Flash动画。因为我无法code动画(有点小电影/动画图形),可以轻松地在Android和时间不够,这似乎是一个不错的主意。

I made a really great application, but for some animations during the presentation, the customer wanted to use flash animations. Because I couldn't code animations (sort of little movies/ animated graphics) that easily in Android and the lack of time, that seemed to be a good idea.

所以,在网络上一些搜索后,我用的WebView这code:

So, after some search on the Web, I used webview and this code:

    WebView mWebView1 = (WebView) findViewById(R.id.webview1);
    mWebView1.getSettings().setJavaScriptEnabled(true);
    mWebView1.getSettings().setPluginsEnabled(true);
    mWebView1.loadUrl("file:///android_asset/graph_01.swf");

这工作pretty的很好,但是每个设备上我想(爱可视101,Nexus One的,的Nexus S,Galaxy S的,的Xperia,欲望,HTC英雄,真多)用的WebView眨眼每一次活动,几黑屏毫秒,那么动画终于出现。

This work pretty well, but on every device I tried (Archos 101, Nexus One, Nexus S, Galaxy S, Xperia, Desire, HTC Hero, and really more) every activity with a webview blink, a few milliseconds of black screen, then the animation finally appear.

PS:我的布局相当简单过:

PS: My layout is quite simple too:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView android:id="@+id/webview1" android:layout_height="fill_parent"
            android:layout_width="fill_parent"></WebView>
</LinearLayout>

请帮帮我,我无法想象我是唯一一个要面对这个问题。

Please help me, I cannot imagine I am the only one to face this issue.

感谢很多的任何帮助。你有我所有的code和演示APK。

Thank a lot for any help. You have all my code and the demo apk.

推荐答案

后加入这样的回答:

所以,问题是,Adobe的Flash Player将创建一个 SurfaceView 的WebView 和之间存在的延迟 SurfaceView 出现和Flash引擎费心去画什么。在小的差距SurfaceView出现全黑。

So the problem is that Adobe's Flash Player creates a SurfaceView inside the WebView and there is a delay between the SurfaceView appearing and the Flash engine bothering to draw anything. In that small gap the SurfaceView appears totally black.

我已经找到了解决办法是子类的WebView,并添加自定义的SurfaceView的视图树。其次是同样重要的坐席preSS的第一拉伸()调用到Adobe视图。在code我的子类的WebView如下:

The solution I've found is to subclass WebView and add a customized SurfaceView to the view tree. Secondly it is also important to suppress the first draw() call to the Adobe view. The code for my subclassed WebView is as follows:

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.webkit.WebView;
import android.widget.AbsoluteLayout;

public class FixAdobeWebView extends WebView {

    View whiteView;
    private boolean eatenFirstFlashDraw;

    public FixAdobeWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        whiteView = new WhiteSurfaceView(context);
        whiteView.setLayoutParams(new AbsoluteLayout.LayoutParams(800, 480, 0, 0));
        addView(whiteView);
    }


    private class WhiteSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
        public WhiteSurfaceView(Context context) {
            super(context);
            getHolder().addCallback(this);
        }
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            Canvas canvas = holder.lockCanvas();
            if (canvas != null) {
                canvas.drawColor(Color.WHITE);
                holder.unlockCanvasAndPost(canvas);
            }
        }
        @Override
        public void surfaceCreated(SurfaceHolder holder) { }
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) { }
    }


    //
    // Override drawChild to eat the first draw of the FlashPaintSurface
    //
    @Override 
    protected boolean drawChild (Canvas canvas, View child, long drawingTime) {
             if (!eatenFirstFlashDraw && child.getClass().getName().equals("com.adobe.flashplayer.FlashPaintSurface")) {
                 eatenFirstFlashDraw = true;
                 return true;
             }
        return super.drawChild(canvas, child, drawingTime);
    }
}

布局XML应该声明这个类的一个实例,即:

The layout XML should declare an instance of this class, i.e. :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    >
<org.test.FixAdobeWebView android:id="@+id/webview1" 
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    />
</LinearLayout>

在我的Nexus One运行CM6.1这工作完全在直到闪存SurfaceView开始绘制的WebView显示为纯白色。你可能需要去适应它一下,例如,摆脱硬codeD尺寸800×480,同时还破坏白SurfaceView一旦不再需要。

On my Nexus One running CM6.1 this works perfectly in that the WebView appears as solid white until the Flash SurfaceView starts drawing. You will probably need to adapt it a bit, e.g. get rid of the hardcoded 800x480 dimensions, and also destroy the white SurfaceView once it's no longer needed.

<打击> ORIGINAL(错)答:

ORIGINAL (WRONG) ANSWER:

看起来像Adobe被指责为这一个。

Looks like Adobe are to blame for this one.

最不糟糕的解决办法我发现到目前为止是:

The least awful workaround I've found so far is to :

  1. 请web视图的父的背景兼容的颜色(即白色)。
  2. 隐藏的WebView开始。
  3. 等到你的页面加载事件,然后排队一个可运行,显示一秒钟的延迟后的WebView。

这意味着你得到保证一秒钟后才能看到任何东西,但它比那个可怕的黑色闪AFAIK少不和谐。

It means you get a guaranteed one second delay before you can see anything, but it's less jarring than that horrible black flash afaik.

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    >
<WebView android:id="@+id/webview1" 
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:visibility="invisible"    
    />
</LinearLayout>

code:

Code:

    final Handler handler = new Handler();
    ...
    final WebView mWebView1 = (WebView) findViewById(R.id.webview1);
    mWebView1.getSettings().setJavaScriptEnabled(true);
    mWebView1.getSettings().setPluginsEnabled(true);
    mWebView1.setWebViewClient(new WebViewClient() {
        @Override 
        public void onPageFinished(WebView view, String url) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mWebView1.setVisibility(View.VISIBLE);                      
                }
            }, 1000);
        }
    });
    mWebView1.loadUrl("file:///android_asset/graph_01.swf");        

有可能是一个更好的办法,虽然这将不再需要一个固定的延迟...

There might be a better way though that would remove the need for a fixed delay...

这已经有一段时间,因为我做了与Flash什么,但我似乎记得有一种方法为Flash控件使用浏览器的Javascript引擎(快速谷歌变成了的Flex Ajax Bridge的这似乎是有可能的)。

It's been a while since I did anything with Flash but I seem to recall there is a way for the Flash control to use the browser's Javascript engine (a quick Google turns up the Flex Ajax Bridge which seems likely).

你可以做的是,与上述桥,使用ActionScript调用JavaScript函数确实警报()。在你的Java code你会勾你mWebView1到一个 WebChromeClient 它实现<一个href="http://developer.android.com/reference/android/webkit/WebChromeClient.html#onJsAlert%28android.webkit.WebView,%20java.lang.String,%20java.lang.String,%20android.webkit.JsResult%29"><$c$c>onJsAlert().在该功能你会做的WebView可见。

What you could do is, with the aforementioned bridge, use ActionScript to call a Javascript function which does an alert(). In your Java code you'd hook your mWebView1 up to a WebChromeClient which implements onJsAlert(). In that function you'd make the WebView visible.

这篇关于使用带闪光灯的WebView时,屏幕闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆