5

我正在制作一个用于在电视机上显示 youtube.com/tv 的应用程序。它具有简单而漂亮的布局,并且还具有一些不错的功能,例如通过智能手机配对和控制它。所以.. 我使用 webview 来获取网址:youtube.com/tv

一切正常,除了我希望它在选择 vid 时自动全屏显示。

通常我已经找到了我所有的答案,(在这里)但是这个很难。

我希望一切都发生在 webview 中。那应该可以吗?还是我需要开始一个新的意图,或者创建一个新类 videoview.java 来调用 eks。视频视图.xml?对此真的不确定.. 我问的原因是,当一个视频开始时,youtube.com/tv 会像播放列表一样自动播放下一个,希望保持这种状态。

我在http://developer.android.com/reference/android/webkit/WebChromeClient.html#onShowCustomView(android.view.View , android.webkit.WebChromeClient.CustomViewCallback)找到了一些关于 HTML5 全屏的文档,但是仍然很困惑。这是要走的路吗?使用:

public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)

和:

public void onHideCustomView ()

这是我的主要 TV.java 直到现在。请温柔一点,因为我对这些东西很陌生。

@SuppressLint("SetJavaScriptEnabled")
public class Tv extends Activity
{
    WebView web;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        //Transparent actionBar Only option menu available...
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        ActionBar actionBar = getActionBar();
        actionBar.setBackgroundDrawable(null);
        setDisplayShowHomeEnabled(false);
        setTitleShowHomeEnabled();
        getActionBar().setDisplayShowHomeEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(false);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        // webview id
        web = (WebView) findViewById(R.id.webview);
        //webchromeclient
        web.setWebChromeClient(new WebChromeClient());
        //hide search bar
        web.setWebViewClient(new myWebClient());
        //Enable javascript
        web.getSettings().setJavaScriptEnabled(true);
        web.getSettings().setPluginState(PluginState.ON);
        //Scale video controls
        web.setInitialScale(150);
        // Test

        //web.getSettings().setLoadWithOverviewMode(true);
        //web.getSettings().setUseWideViewPort(true);
        //web.setVerticalScrollbarOverlay(true);
        //web.getSettings().setAllowFileAccess(true);

        //Load url
        web.loadUrl("http://www.youtube.com/tv");
        //Load file from assets NB: Missing "S" is correct
        // web.loadUrl("file:///android_asset/yt.html");
    }


    //Fullscreen
    public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
    {
    }

    public void onHideCustomView ()
    {
    }
    //End fullscreen


    private void setTitleShowHomeEnabled()
    {
    }

    private void setDisplayShowHomeEnabled(boolean b)
    {
    }

    public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon)
        {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;

        }
    }

    // To handle "Back" key press event for WebView to go back to previous screen.
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack())
        {
            web.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    // Ask if user wants to exit
    @Override
    public void onBackPressed()
    {
        new AlertDialog.Builder(this)
        .setMessage("Are you sure you want to exit?")
        .setCancelable(false)
        .setPositiveButton("Yes", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                //Tv.this.finish();
                android.os.Process.killProcess(android.os.Process.myPid());
            }
        })
        .setNegativeButton("No", null)
        .show();
    }


    //Option menu
    public class SimpleOptionMenu extends Activity
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);

        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
        case R.id.text1:    
            AlertDialog alertDialog = new AlertDialog.Builder(this).create(); //Read Update
            alertDialog.setTitle("Information");
            alertDialog.setMessage("In order to log in to your account and activate the use of your smart phone, please select: -Sign in & settings- -> -Sign in- in the left menu, write down the activation code, and then click on -Activate- in this menu. Have a happy tube :) ");

            alertDialog.setButton("Continue..", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which)
                {
                    // here you can add functions
                }
            });

            alertDialog.show();
            break;

        case R.id.text2:   
            Intent intent = new Intent(this, GetActivation.class);
            this.startActivity(intent);
            break;
            //Exit
        case R.id.text3: 
            android.os.Process.killProcess(android.os.Process.myPid()); // <- Complete kill
            //Tv.this.finish(); <-Dosent kill totally
            return true;
        default:
            return false;
        }
        return true;
    }
}
4

0 回答 0