Android Open Source - openPDS-HelloWorld Web View Fragment Javascript Interface






From Project

Back to project page openPDS-HelloWorld.

License

The source code is released under:

MIT License

If you think the Android project openPDS-HelloWorld listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.mit.media.hellopds;
//from   w w  w . ja  v  a  2 s .com
import android.app.Activity;
import android.support.v4.view.ViewPager;
import android.webkit.JavascriptInterface;

public class WebViewFragmentJavascriptInterface {
  
  protected ViewPager mViewPager;
  protected Activity mActivity;
  
  public WebViewFragmentJavascriptInterface(ViewPager viewPager, Activity activity) {
    mViewPager = viewPager;
    mActivity = activity;
  }
  
  @JavascriptInterface
  public boolean hideWebNavBar() {
    return true;
  }
  
  @JavascriptInterface
  public boolean handleTabChange(final String dimension, final int tabNumber) {
    if (mActivity != null && mViewPager != null) {
      mActivity.runOnUiThread(new Runnable() { 
        @Override
        public void run() {
          mViewPager.setCurrentItem(tabNumber + 1);
        }
      });
    }
    return true;
  }
}




Java Source Code List

edu.mit.media.hellopds.MainActivity.java
edu.mit.media.hellopds.WebViewFragmentClient.java
edu.mit.media.hellopds.WebViewFragmentJavascriptInterface.java
edu.mit.media.hellopds.WebViewFragment.java