Ejemplo n.º 1
0
 @Override
 public void onBackPressed() {
   // Notify the VideoEnabledWebChromeClient, and handle it ourselves if it doesn't handle it
   if (!v.onBackPressed()) {
     if (webView.canGoBack()) {
       webView.goBack();
     } else {
       // Close app (presumably)
       //      super.onBackPressed();
     }
   }
 }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context c = this;
    setContentView(R.layout.activity_main);
    // mContentView=(RelativeLayout)findViewById(R.id.activity_main);
    // mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

    webView = (VideoEnabledWebView) findViewById(R.id.webView1);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setPluginsEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    View nonVideoLayout = findViewById(R.id.activity_main); // Your own view, read class comments
    ViewGroup videoLayout =
        (ViewGroup)
            findViewById(R.id.fullscreen_custom_content); // Your own view, read class comments
    View loadingView = getLayoutInflater().inflate(R.layout.activity_main, null);
    v =
        new VideoEnabledWebChromeClient(
            nonVideoLayout,
            videoLayout,
            loadingView,
            webView,
            c) // See all available constructors...
        {
          // Subscribe to standard events, such as onProgressChanged()...

          @Override
          public void onProgressChanged(WebView view, int progress) {
            // Your code...
          }
        };
    v.setOnToggledFullscreen(
        new VideoEnabledWebChromeClient.ToggledFullscreenCallback() {
          @Override
          public void toggledFullscreen(boolean fullscreen) {
            /*if(fullscreen)
            onBackPressed();*/
            // Your code to handle the full-screen change, for example showing and hiding the title
            // bar
          }
        });
    webView.setWebChromeClient(v);
    webView.setWebViewClient(
        new WebViewClient() {

          private View mCustomView;

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {

            // if(url.contains("youtube.com"))
            {
              //	Toast.makeText(c, url+"", Toast.LENGTH_LONG).show();
            }
            /*  view.setWebChromeClient(new WebChromeClient() {
             FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                       FrameLayout.LayoutParams.MATCH_PARENT);

             	     @Override
               public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
               {
              	  if (mCustomView != null)
                    {
                        callback.onCustomViewHidden();
                        return;
                    }

               	 mContentView = (RelativeLayout) findViewById(R.id.activity_main);
                    mContentView.setVisibility(View.GONE);
                    mCustomViewContainer = new FrameLayout(MainActivity.this);
                    mCustomViewContainer.setLayoutParams(LayoutParameters);
                    mCustomViewContainer.setBackgroundResource(android.R.color.black);
                    view.setLayoutParams(LayoutParameters);
                    mCustomViewContainer.addView(view);
                    mCustomView = view;
                    mCustomViewCallback = callback;
                    mCustomViewContainer.setVisibility(View.VISIBLE);
                    setContentView(mCustomViewContainer);


                   // if a view already exists then immediately terminate the new one
               	   	  if (mCustomView != null)
                   {
                       callback.onCustomViewHidden();
                       return;
                   }

                   // Add the custom view to its container.
                   mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
                   mCustomView = view;
                   mCustomViewCallback = callback;

                   // hide main browser view
                   mContentView.setVisibility(View.GONE);

                   // Finally show the custom view container.
                   mCustomViewContainer.setVisibility(View.VISIBLE);
                   mCustomViewContainer.bringToFront();
               }

                @Override
                public void onHideCustomView() {
                    if (mCustomView == null) {
                        return;
                    } else {
                        // Hide the custom view.
                        mCustomView.setVisibility(View.GONE);
                        // Remove the custom view from its container.
                        mCustomViewContainer.removeView(mCustomView);
                        mCustomView = null;
                        mCustomViewContainer.setVisibility(View.GONE);
                        mCustomViewCallback.onCustomViewHidden();
                        // Show the content view.
                        mContentView.setVisibility(View.VISIBLE);
                        setContentView(mContentView);
                    }
                }
            } );*/
            if (!GetNetworkStatus.isNetworkAvailable(c)) {
              Toast.makeText(c, "Need working internet to use this app", Toast.LENGTH_LONG);
            }
            if (url.contains("share")) {
              // Toast.makeText(c, webView.getUrl(),Toast.LENGTH_SHORT).show();
              view.goBack();
              Share.share(webView.getUrl(), c);
              url = webView.getUrl();
            }
            if (url.contains("youtube")) {
              view.goBack();
              Share.share(webView.getUrl(), c);
              url = webView.getUrl();
            }
            if (url.contains("exit")) {
              view.goBack();
              finish();
              // Toast.makeText(c, webView.getUrl(),Toast.LENGTH_SHORT).show();
              AlertDialog.Builder builder = new AlertDialog.Builder(c);
              builder
                  .setMessage("Are you sure to exit?")
                  .setPositiveButton("Yes", dialogClickListener)
                  .setNegativeButton("No", dialogClickListener)
                  .show();

            } else {
              view.loadUrl(url);
            }
            return false;
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {

            Toast.makeText(c, webView.getUrl() + description, Toast.LENGTH_SHORT).show();

            webView.loadUrl("http://www.f1gplive.com/");

            // Toast.makeText(c, "Sorry, You need net Connection to get full itemlist",
            // Toast.LENGTH_LONG).show();
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
          }
        });
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setPadding(0, 0, 0, 0);
    webView.setBackgroundColor(Color.WHITE);
    // webView.loadUrl("http://www.youtube.com");
    //  String s ="http://marsapparel.co.jp/app";
    webView.loadUrl("http://www.f1gplive.com");
    // webView.loadUrl("file:///android_asset/Spun   Just another Caroline Moore site.htm");

  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context c = this;
    setContentView(R.layout.activity_main);
    // mContentView=(RelativeLayout)findViewById(R.id.activity_main);
    // mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

    webView = (VideoEnabledWebView) findViewById(R.id.webView1);
    // webView.getSettings().setAppCacheEnabled(true);
    // webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setPluginsEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.getSettings().setDomStorageEnabled(true);
    View nonVideoLayout = findViewById(R.id.activity_main); // Your own view, read class comments
    ViewGroup videoLayout =
        (ViewGroup)
            findViewById(R.id.fullscreen_custom_content); // Your own view, read class comments
    View loadingView = getLayoutInflater().inflate(R.layout.activity_main, null);
    v =
        new VideoEnabledWebChromeClient(
            nonVideoLayout,
            videoLayout,
            loadingView,
            webView,
            c) // See all available constructors...
        {
          // Subscribe to standard events, such as onProgressChanged()...

          @Override
          public void onProgressChanged(WebView view, int progress) {
            // Your code...
          }
        };
    v.setOnToggledFullscreen(
        new VideoEnabledWebChromeClient.ToggledFullscreenCallback() {
          @Override
          public void toggledFullscreen(boolean fullscreen) {
            /*if(fullscreen)
            onBackPressed();*/
            // Your code to handle the full-screen change, for example showing and hiding the title
            // bar
          }
        });
    webView.setWebChromeClient(v);
    webView.setWebViewClient(
        new WebViewClient() {

          private View mCustomView;

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (!GetNetworkStatus.isNetworkAvailable(c)) {
              Toast.makeText(c, "Need working internet to use this app", Toast.LENGTH_LONG);
            }
            if (url.contains("share")) {
              // Toast.makeText(c, webView.getUrl(),Toast.LENGTH_SHORT).show();
              view.goBack();
              Share.share(webView.getUrl(), c);
              url = webView.getUrl();
            }
            if (url.contains("youtube")) {
              view.goBack();
              Share.share(webView.getUrl(), c);
              url = webView.getUrl();
            }
            if (url.contains("exit")) {
              view.goBack();
              finish();
              // Toast.makeText(c, webView.getUrl(),Toast.LENGTH_SHORT).show();
              AlertDialog.Builder builder = new AlertDialog.Builder(c);
              builder
                  .setMessage("Are you sure to exit?")
                  .setPositiveButton("Yes", dialogClickListener)
                  .setNegativeButton("No", dialogClickListener)
                  .show();

            } else {
              view.loadUrl(url);
            }
            return false;
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {

            Toast.makeText(c, webView.getUrl() + description, Toast.LENGTH_SHORT).show();

            webView.loadUrl("http://www.parts-search.com/");

            // Toast.makeText(c, "Sorry, You need net Connection to get full itemlist",
            // Toast.LENGTH_LONG).show();
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
          }
        });
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setPadding(0, 0, 0, 0);
    webView.setBackgroundColor(Color.WHITE);
    // webView.loadUrl("http://www.youtube.com");
    //  String s ="http://marsapparel.co.jp/app";
    webView.loadUrl("http://www.f1gplive.com/");
    // webView.loadUrl("file:///android_asset/Spun   Just another Caroline Moore site.htm");

  }
Ejemplo n.º 4
0
 /**
  * Indicates if the video is being displayed using a custom_icon view (typically full-screen)
  *
  * @return true it the video is being displayed using a custom_icon view (typically full-screen)
  */
 @SuppressWarnings("unused")
 public boolean isVideoFullscreen() {
   return videoEnabledWebChromeClient != null && videoEnabledWebChromeClient.isVideoFullscreen();
 }