Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d();
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mBrowser = this;

    mVizWebViewClient = new VizWebViewClient(this);
    mWebChromeClient = new VizWebChromeClient(this);

    mVizWebView = new WebView(getActivity()); // get attributes?
    mVizWebView.setWebViewClient(mVizWebViewClient);
    mVizWebView.setWebChromeClient(mWebChromeClient);
    if (savedInstanceState != null) {
      Log.d("restoring web view state");
      mVizWebView.restoreState(savedInstanceState);
    }
    WebSettings s = mVizWebView.getSettings();
    s.setJavaScriptEnabled(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setBuiltInZoomControls(true);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    s.setSaveFormData(true);

    mVizWebView.setId(61377); // PhoneWindow complained about no id (focus couldn't be saved)

    // Loading homepage here results in an exception on ICS, not sure why.
    // Update: post-poning until onCreatingView doesn't entirely fix the
    // issue either.
    // mVizWebView.loadUrl(defaultURL);
  }
Пример #2
0
 public static void initializeSettings(WebSettings settings, Context context) {
   settings.setJavaScriptEnabled(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   settings.setUserAgentString(settings.getUserAgentString() + DB.USER_AGENT);
   settings.setSupportMultipleWindows(true);
   settings.setSaveFormData(false);
   settings.setSavePassword(false); // 设置为true,系统会弹出AlertDialog确认框
   if (API < 18) {
     settings.setAppCacheMaxSize(Long.MAX_VALUE);
   }
   if (API < 17) {
     settings.setEnableSmoothTransition(true);
   }
   if (API < 19) {
     settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + "/databases");
   }
   settings.setDomStorageEnabled(true);
   settings.setAppCachePath(context.getCacheDir().toString());
   settings.setAppCacheEnabled(true);
   settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
   settings.setGeolocationDatabasePath(context.getCacheDir().getAbsolutePath());
   settings.setAllowFileAccess(true);
   settings.setDatabaseEnabled(true);
   settings.setSupportZoom(true);
   settings.setBuiltInZoomControls(true);
   settings.setDisplayZoomControls(false);
   settings.setAllowContentAccess(true);
   settings.setDefaultTextEncodingName("utf-8");
   /*if (API > 16) {
   	settings.setAllowFileAccessFromFileURLs(false);
   	settings.setAllowUniversalAccessFromFileURLs(false);
   }*/
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // WebView
    mwebView = (WebView) findViewById(R.id.myWebView);
    WebSettings webSettings = mwebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // improve webView performance
    mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mwebView.getSettings().setAppCacheEnabled(true);
    mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setSavePassword(true);
    webSettings.setSaveFormData(true);
    webSettings.setEnableSmoothTransition(true);

    mwebView.loadUrl("http://www.newsweek.com");
    // force links open in webview only
    mwebView.setWebViewClient(new MyWebviewClient());
  }
Пример #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    // -------------------------------TabView
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    // --------------------------------------

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // WebView
    mwebView = (WebView) findViewById(R.id.myWebView);
    WebSettings webSettings = mwebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // improve webView performance
    mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mwebView.getSettings().setAppCacheEnabled(true);
    mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setSavePassword(true);
    webSettings.setSaveFormData(true);
    webSettings.setEnableSmoothTransition(true);

    mwebView.loadUrl("http://www.newsweek.com");
    // force links open in webview only
    mwebView.setWebViewClient(new MyWebviewClient());
  }
Пример #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_innerweb);
    ButterKnife.bind(this);

    StatusBarHelper.setStatusBar(this);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    WebSettings webSettings = wbInnerweb.getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSaveFormData(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    wbInnerweb.requestFocus();
    wbInnerweb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

    wbInnerweb.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.indexOf("tel:") < 0) {
              view.loadUrl(url);
            }
            return true;
          }

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            pbLoading.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            pbLoading.setVisibility(View.GONE);
            wbInnerweb.setVisibility(View.VISIBLE);
            super.onPageFinished(view, url);
          }
        });

    mUrl = getIntent().getStringExtra(PARAM_WEB_URL);
    wbInnerweb.loadUrl(mUrl);
  }
Пример #6
0
  public AdWebView(
      AdViewContainer parent,
      MASTAdLog log,
      DisplayMetrics metrics,
      boolean mraid,
      boolean handleClicks) {
    super(parent.getContext());
    this.setId(getIdForView());

    adViewContainer = parent;
    adLog = log;
    // this.metrics = metrics;
    supportMraid = mraid;
    // launchBrowserOnClicks = handleClicks;

    // dataToInject = null;
    defferedJavascript = new StringBuffer();

    // Clients for javascript and other integration
    setWebChromeClient(new AdWebChromeClient());
    setWebViewClient(new AdWebViewClient(parent.getContext()));

    // Customize settings for web view
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setSupportZoom(false);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // apply standard properties
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

    if (supportMraid) {
      javascriptInterface = new JavascriptInterface(parent, this);
      mraidInterface = new MraidInterface(parent, this);

      /*mraidScript = FileUtils.readTextFromJar(parent.getContext(),
      "/js/mraid.js");*/
    }

    // System.out.println("mraid script read: " + mraidScript);

    if (handleClicks) {
      adClickHandler = new AdClickHandler(adViewContainer);
    }
  }
Пример #7
0
  public synchronized void initPreferences() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    WebSettings webSettings = getSettings();

    webSettings.setLoadWithOverviewMode(true);
    webSettings.setTextZoom(100);
    webSettings.setUseWideViewPort(true);

    webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true));
    webSettings.setJavaScriptEnabled(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setJavaScriptCanOpenWindowsAutomatically(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true));
    webSettings.setSupportMultipleWindows(
        sp.getBoolean(context.getString(R.string.sp_multiple_windows), false));
    webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true));

    boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true);
    if (textReflow) {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
          webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        } catch (Exception e) {
        }
      }
    } else {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    }

    int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0"));
    if (userAgent == 1) {
      webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP);
    } else if (userAgent == 2) {
      webSettings.setUserAgentString(
          sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal));
    } else {
      webSettings.setUserAgentString(userAgentOriginal);
    }

    int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0"));
    initRendering(mode);

    webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true));
  }
Пример #8
0
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.sousuoactivity1);

      editText = (EditText) findViewById(R.id.editText);
      tips = (TextView) findViewById(R.id.tips);
      submit1 = (Button) findViewById(R.id.submit);
      webView = (WebView) findViewById(R.id.toutput);

      webSettings = webView.getSettings();
      webSettings.setSaveFormData(false);
      webSettings.setSavePassword(false);
      webSettings.setSupportZoom(false);

      webView.setWebViewClient(
          new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              view.loadUrl(url);
              return true;
            }
          });

      submit1.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Toast.makeText(Search.this, "aaaaaaaaaaaa", Toast.LENGTH_SHORT).show();
              if (editText.getText().toString().length() == 0) {
                Toast.makeText(Search.this, "请输入查询的词", Toast.LENGTH_SHORT).show();
                return;
              } else {
                tips.setVisibility(TextView.VISIBLE);
                webView.setVisibility(WebView.VISIBLE);
                handler.post(
                    new Runnable() {
                      @Override
                      public void run() {
                        webView.loadUrl(
                            "http://www.baike.com/wiki/" + editText.getText().toString());
                      }
                    });
              }
            }
          });
    }
Пример #9
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView");

    // Inflate layout of the dialog
    View rootView =
        inflater.inflate(
            R.layout.sso_dialog,
            container,
            false); // null parent view because it will go in the dialog layout
    mSsoWebView = (WebView) rootView.findViewById(R.id.sso_webview);

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    if (savedInstanceState == null) {
      Log_OC.d(TAG, "   initWebView start");
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.setAcceptCookie(true);
      cookieManager.removeAllCookie();
      mSsoWebView.loadUrl(mInitialUrl);

    } else {
      Log_OC.d(TAG, "   restoreWebView start");
      WebBackForwardList history =
          mSsoWebView.restoreState(savedInstanceState.getBundle(KEY_WEBVIEW_STATE));
      if (history == null) {
        Log_OC.e(TAG, "Error restoring WebView state ; back to starting URL");
        mSsoWebView.loadUrl(mInitialUrl);
      }
    }

    WebSettings webSettings = mSsoWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setSavePassword(false);
    webSettings.setUserAgentString(WebdavClient.USER_AGENT);
    webSettings.setSaveFormData(false);

    return rootView;
  }
Пример #10
0
  private void initView() {
    // To change body of created methods use File | Settings | File Templates.

    webView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    webView.setOnTouchListener(this);

    if (mNavLeftButton == null) {
      mNavLeftButton = (ImageView) findViewById(R.id.nav_left_image);
    }
    mNavLeftButton.setVisibility(View.VISIBLE);
    mNavLeftButton.setOnClickListener(this);

    loadData();
  }
Пример #11
0
  void init() {
    setWebViewClient(new LoveClient());
    setWebChromeClient(new Chrome());
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSaveFormData(false);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setUseWideViewPort(true);

    /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (BuildConfig.DEBUG) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }*/
  }
Пример #12
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    mWebView = (WebView) findViewById(R.id.webview);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);

    mWebView.setWebChromeClient(new MyWebChromeClient());

    mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");

    setCustomUserAgent();

    mWebView.loadUrl("file:///android_asset/demo.html");
  }
Пример #13
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauthactivity_layout);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setTitle(getString(R.string.login));
    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WeiboWebViewClient());

    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
  }
Пример #14
0
  /** Initialize the WebView options to the ones define by user. */
  public void initializeOptions() {
    WebSettings settings = getSettings();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true));
    settings.setSaveFormData(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true));
    settings.setSavePassword(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true));
    settings.setDefaultZoom(
        ZoomDensity.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString())));
    settings.setUserAgentString(
        prefs.getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT));

    settings.setPluginState(
        PluginState.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_ENABLE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance()
        .setAcceptCookie(prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_COOKIES, true));

    // Technical settings
    // settings.setUseWideViewPort(true);
    settings.setSupportMultipleWindows(true);
    setLongClickable(true);
    setScrollbarFadingEnabled(true);
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setDrawingCacheEnabled(true);

    settings.setAppCacheEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
  }
Пример #15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWebView = (WebView) findViewById(R.id.webview);

    url = getIntent().getStringExtra("url");
    title = getIntent().getStringExtra("title");
    page = 0;

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);

    mWebView.setWebChromeClient(new MyWebChromeClient());

    mWebView.addJavascriptInterface(new AiGouJavaScriptInterface(), "aigou");

    mWebView.loadUrl("file:///android_asset/www/category-show.html");
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Config.LOGD) Log.i(LOGTAG, "onCreate");
    if (context == null) context = getApplicationContext();

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // prepare connection to TwitterService for post processing: call to twitterLogin(pin) (OAuth
    // pin handover)
    Intent serviceIntent = new Intent(this, TwitterService.class);
    bindService(serviceIntent, serviceConnection, BIND_AUTO_CREATE);

    if (myWebView == null) {
      myWebView = new WebView(this);
      if (myWebView != null) {
        WebSettings webSettings = myWebView.getSettings();
        if (webSettings != null) {
          webSettings.setJavaScriptEnabled(true);
          webSettings.setSavePassword(false);
          webSettings.setSaveFormData(false);
        }

        myWebView.setWebViewClient(new MyWebViewClient()); // onPageFinished(), etc.
        myWebView.setWebChromeClient(new MyWebChromeClient()); // onJsAlert(), etc.
        setContentView(myWebView);

        // fetch the OAuth web document..
        String webpath = getIntent().getStringExtra("argAuthorizationURL");
        if (Config.LOGD) Log.i(LOGTAG, "loadUrl(" + webpath + ") ...");
        myWebView.loadUrl(webpath);
        if (Config.LOGD) Log.i(LOGTAG, "done initializing myWebView, mService=" + mService);
        // --> OAuth-pin post-processing -> MyWebViewClient.onPageFinished() and
        // MyWebChromeClient.onJsAlert()
      }
    }

    if (Config.LOGD) Log.i(LOGTAG, "done onCreate()");
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {

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

    QuestionHeaderBox = (WebView) findViewById(R.id.MQuestionHeaderBox);
    Table = (TableLayout) findViewById(R.id.MQtable);
    BtnContinue = (Button) findViewById(R.id.MContinue);
    BtnReason = (Button) findViewById(R.id.MultipleChoiceMultipleShowReason);

    BtnContinue.setOnClickListener(this);
    BtnContinue.setTag(2); // I am using this to identify the continue button
    BtnContinue.setVisibility(View.INVISIBLE);

    BtnReason.setOnClickListener(this);
    BtnReason.setTag(3); // I am using this to identify the Reason Button
    BtnReason.setVisibility(View.INVISIBLE);

    View LLView = findViewById(R.id.LLMultipleMultiple);
    View root = LLView.getRootView();
    root.setBackgroundColor(Color.BLACK);

    cache = ((LocalCache) getApplicationContext());

    WebSettings websettings = QuestionHeaderBox.getSettings();
    websettings.setJavaScriptEnabled(true);
    websettings.setSavePassword(false);
    websettings.setSaveFormData(false);
    websettings.setSupportZoom(true);
    websettings.setBuiltInZoomControls(true);

    Bundle getBasket = getIntent().getExtras();
    Integer _id = getBasket.getInt("_id");

    GetQuestion(_id);
    GetAnswers(_id);
  }
Пример #18
0
  public LGameWeb(
      final LGameAndroid2DActivity activity, final WebProcess webProcess, final String url) {

    super(activity);
    this.url = url;
    this.activity = activity;
    // 允许显示滚动条
    this.setHorizontalScrollBarEnabled(true);
    // 清空原有的缓存数据
    this.clearCache(true);
    // 隐藏当前View
    this.setVisible(false);
    // 不要背景图
    this.setBackgroundDrawable(null);
    // 进行细节设置
    webSettings = getSettings();
    // 数据库访问权限开启
    webSettings.setAllowFileAccess(true);
    // 密码保存与Form信息不保存
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    // 响应JavaScript事件
    webSettings.setJavaScriptEnabled(true);
    // 允许JavaScript脚本打开新的窗口
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    // 允许自动加载图像资源
    webSettings.setLoadsImagesAutomatically(true);
    // 不支持网页缩放
    webSettings.setSupportZoom(false);

    // 当流程监听存在时
    if (webProcess != null) {
      setWebViewClient(
          new WebViewClient() {

            public void onPageStarted(WebView view, String url, Bitmap favicon) {
              webProcess.onPageStarted(url, favicon);
              super.onPageStarted(view, url, favicon);
            }

            public void onPageFinished(WebView view, String url) {
              webProcess.onPageFinished(url);
              super.onPageFinished(view, url);
            }

            public void onLoadResource(WebView view, String url) {
              webProcess.onLoadResource(url);
              super.onLoadResource(view, url);
            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              webProcess.shouldOverrideUrlLoading(url);
              return super.shouldOverrideUrlLoading(view, url);
            }

            public void onReceivedHttpAuthRequest(
                WebView view, HttpAuthHandler handler, String host, String realm) {
              webProcess.onReceivedHttpAuthRequest(handler, host, realm);
              super.onReceivedHttpAuthRequest(view, handler, host, realm);
            }
          });
    }

    // 加载进度条
    final ProgressBar progress = new ProgressBar(activity);
    activity.addView(progress, Location.CENTER);
    setWebChromeClient(
        new WebChromeClient() {
          public void onProgressChanged(final WebView view, final int newProgress) {
            LSystem.post(
                new Runnable() {
                  public void run() {
                    progress.setProgress(newProgress);
                    progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                    if (newProgress == 100) {
                      activity.removeView(progress);
                    }
                    setVisible(newProgress == 100 ? true : false);
                  }
                });
          }
        });

    if (url != null) {
      loadUrl(url);
    }
  }
Пример #19
0
    public Web(final Loon activity, final WebProcess webProcess, final String url) {

      super(activity);
      this.url = url;
      this.activity = activity;
      // 允许显示滚动条
      this.setHorizontalScrollBarEnabled(true);
      // 清空原有的缓存数据
      this.clearCache(true);
      // 隐藏当前View
      this.setVisible(false);
      // 不要背景图
      java.lang.reflect.Method drawable = null;
      try {
        drawable =
            this.getClass()
                .getMethod("setBackgroundDrawable", android.graphics.drawable.Drawable.class);
        drawable.invoke(this, (android.graphics.drawable.Drawable) null);
      } catch (Exception ex) {
        try {
          drawable =
              this.getClass().getMethod("setBackground", android.graphics.drawable.Drawable.class);
          drawable.invoke(this, (android.graphics.drawable.Drawable) null);
        } catch (Exception e) {

        }
      }
      // 进行细节设置
      webSettings = getSettings();
      // 数据库访问权限开启
      webSettings.setAllowFileAccess(true);
      // 密码保存与Form信息不保存
      // webSettings.setSavePassword(false);
      webSettings.setSaveFormData(false);
      if (!webSettings.getJavaScriptEnabled()) {
        // 响应JavaScript事件
        webSettings.setJavaScriptEnabled(true);
      }
      // 允许JavaScript脚本打开新的窗口
      webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      // 允许自动加载图像资源
      webSettings.setLoadsImagesAutomatically(true);
      // 不支持网页缩放
      webSettings.setSupportZoom(false);

      // 当流程监听存在时
      if (webProcess != null) {
        setWebViewClient(
            new android.webkit.WebViewClient() {

              @Override
              public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
                webProcess.onPageStarted(url, favicon);
                super.onPageStarted(view, url, favicon);
              }

              @Override
              public void onPageFinished(android.webkit.WebView view, String url) {
                webProcess.onPageFinished(url);
                super.onPageFinished(view, url);
              }

              @Override
              public void onLoadResource(android.webkit.WebView view, String url) {
                webProcess.onLoadResource(url);
                super.onLoadResource(view, url);
              }

              @Override
              public boolean shouldOverrideUrlLoading(android.webkit.WebView view, String url) {
                webProcess.shouldOverrideUrlLoading(url);
                return super.shouldOverrideUrlLoading(view, url);
              }

              @Override
              public void onReceivedHttpAuthRequest(
                  android.webkit.WebView view,
                  android.webkit.HttpAuthHandler handler,
                  String host,
                  String realm) {
                webProcess.onReceivedHttpAuthRequest(handler, host, realm);
                super.onReceivedHttpAuthRequest(view, handler, host, realm);
              }
            });
      }

      // 加载进度条
      final android.widget.ProgressBar progress = new android.widget.ProgressBar(activity);
      activity.addView(progress, AndroidLocation.CENTER);
      setWebChromeClient(
          new android.webkit.WebChromeClient() {
            @Override
            public void onProgressChanged(
                final android.webkit.WebView view, final int newProgress) {
              Loon.self.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      progress.setProgress(newProgress);
                      progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                      if (newProgress == 100) {
                        activity.removeView(progress);
                      }
                      setVisible(newProgress == 100 ? true : false);
                    }
                  });
            }
          });
      if (url != null) {
        loadUrl(url);
      }
    }
Пример #20
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
    linearLayout.setBackgroundColor(Color.BLACK);

    // Navbar setup

    navbar = (LinearLayout) findViewById(R.id.navbar);
    goButton = (Button) findViewById(R.id.go_button);
    urlField = (EditText) findViewById(R.id.url);

    goButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doNav();
          }
        });

    urlField.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_GO) {

              doNav();

              handled = true;
            }
            return handled;
          }
        });

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    String lastUrl = settings.getString("lastUrl", "");

    urlField.setText(lastUrl);

    // Navbar animation settings

    AnimationListener slideListener =
        new AnimationListener() {
          @Override
          public void onAnimationEnd(Animation animation) {
            if (animation.equals(slideUp)) {
              navbar.setVisibility(View.GONE);
            }
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}

          @Override
          public void onAnimationStart(Animation animation) {
            if (animation.equals(slideDown)) {
              navbar.setVisibility(View.VISIBLE);
            }
          }
        };

    slideUp =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f);
    slideUp.setDuration(500);
    slideUp.setAnimationListener(slideListener);

    slideDown =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f);
    slideDown.setDuration(500);
    slideDown.setAnimationListener(slideListener);

    // WebView setup

    webView = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = webView.getSettings();

    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(
        new WebViewClient() {

          @Override
          public void onPageFinished(WebView view, String url) {

            Log.d("scale", view.getScale() + "");

            Log.d("pageFinished", url);

            view.setInitialScale(70);

            if (url.equalsIgnoreCase(HOME_PAGE)) {
              // navbar.setVisibility(View.VISIBLE);
              navbar.startAnimation(slideDown);
            }
          }

          @Override
          public void onScaleChanged(WebView view, float oldScale, float newScale) {

            Log.d("scale changed", oldScale + " - " + newScale);

            if (newScale > 0.7) {

              Log.d("scale", "reset");
              // view.setInitialScale(70);

            }
          }
        });

    webView.setInitialScale(70);

    webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    webView.setVerticalScrollBarEnabled(false);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);

    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setSupportZoom(true);

    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(
        "/data/data/" + webView.getContext().getPackageName() + "/databases/");
    webSettings.setSaveFormData(false);
    webSettings.setLightTouchEnabled(false);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webSettings.setRenderPriority(RenderPriority.HIGH);
    webSettings.setUserAgentString(
        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV");

    final Intent intent = getIntent();
    if ((intent.getAction() == Intent.ACTION_VIEW) && (intent.getData() != null)) {
      final String url = intent.getDataString();
      urlField.setText(url);
      webView.loadUrl(url);
      navbar.setVisibility(View.GONE);
    } else {
      webView.loadUrl(HOME_PAGE);
    }

    webView.requestFocus();
  }
  @Override
  protected void onStart() {
    super.onStart();

    try {
      jsonSrc = FileUtils.readFromAssetsFile(that, "json2.js");
      androidJsSrc = FileUtils.readFromAssetsFile(that, "android.js");
    } catch (IOException e1) {
      throw new RuntimeException(e1);
    }

    mObserver = new HtmlEventObserver();

    // TODO
    // RpcReceiverManager mFacadeManager = getRpcReceiverManager();
    // mFacadeManager.getReceiver(EventFacade.class).addGlobalEventObserver(mObserver);
    // mAPIWrapperSource = generateAPIWrapper();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, config.getLOG_TAG());
    mWebView.setKeepScreenOn(true);

    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    mWebView.setScrollbarFadingEnabled(false);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setScrollContainer(false);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);

    webSettings.setSupportZoom(false);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    mWebView.addJavascriptInterface(mWrapper, "_rpc_wrapper");
    mWebView.addJavascriptInterface(
        new Object() {

          @SuppressWarnings("unused")
          public void register(String event, int id) {
            mObserver.register(event, id);
          }
        },
        "_callback_wrapper");

    if (Build.VERSION.SDK_INT >= 5) {
      try {
        Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[] {Boolean.TYPE});
        m1.invoke(webSettings, Boolean.TRUE);

        Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[] {Boolean.TYPE});
        m2.invoke(webSettings, Boolean.TRUE);

        Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[] {String.class});
        m3.invoke(webSettings, this.getFilesDir().getParent() + "/databases/");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    mWebView.setWebChromeClient(new WebChromeClient() {});

    mWebView.setWebViewClient(
        new WebViewClient() {
          //        	public void onReceivedError(WebView view, int errorCode, String description,
          // String failingUrl) {
          //        		Toast.makeText(that, "Error: " + description, Toast.LENGTH_SHORT).show();
          //        	}
        });

    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);

    if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 14) {
      mWebView.setSystemUiVisibility(WebView.STATUS_BAR_HIDDEN);
    } else if (Build.VERSION.SDK_INT >= 14) {
      mWebView.setSystemUiVisibility(WebView.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }

    mWebView.loadUrl("javascript:" + jsonSrc);
    mWebView.loadUrl("javascript:" + androidJsSrc);
    mWebView.loadUrl("javascript:" + mAPIWrapperSource);
    Log.d(
        config.getLOG_TAG(),
        "Launch Webview: "
            + "file://"
            + this.getFilesDir().getAbsolutePath()
            + "/"
            + config.getMAIN_SCRIPT_NAME());
    mWebView.loadUrl(
        "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME());
  }
Пример #22
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.resultpage);

    webView = (WebView) findViewById(R.id.webViewResults);
    Refresh = (Button) findViewById(R.id.ResultRefresh);
    Progress = (ProgressBar) findViewById(R.id.ResultsprogressBar);
    Refresh.setEnabled(false);
    Progress.setVisibility(View.VISIBLE);
    Refresh.setOnClickListener(this);
    WebSettings websettings = webView.getSettings();
    websettings.setJavaScriptEnabled(true);
    websettings.setSavePassword(false);
    websettings.setSaveFormData(false);
    websettings.setSupportZoom(true);
    websettings.setDefaultZoom(ZoomDensity.MEDIUM);
    websettings.setAppCacheEnabled(false);

    webView.setWebViewClient(
        new WebViewClient() {

          public void onPageFinished(WebView view, String url) {
            if (Progress.getVisibility() == View.VISIBLE) {
              Progress.setVisibility(View.INVISIBLE);
            }
          }

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

          	view.loadUrl(url);

          	return true;
          }*/

        });

    /*webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
        	activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if(progress == 100)
                activity.setTitle(R.string.app_name);
        }

        public void onPageFinished(WebView view, String url) {

            if (Progress.getVisibility() == View.VISIBLE) {
            	Progress.setVisibility(View.INVISIBLE);

            }
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
        }

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

            view.loadUrl(url);

            Progress.setVisibility( View.INVISIBLE);
            return true;
        }
    });*/

    LoadWebView();
  }
Пример #23
0
  // 封装WebView
  public static void wrapWebView(Context context, WebView webView, WebViewClient webclient) {
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSupportZoom(false);

    // 设置定位可用
    if (context != null) {
      webSettings.setDatabaseEnabled(true);
      String dir =
          context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();

      // 启用地理定位
      webSettings.setGeolocationEnabled(true);
      // 设置定位的数据库路径
      webSettings.setGeolocationDatabasePath(dir);

      // 最重要的方法,一定要设置,这就是出不来的主要原因

      webSettings.setDomStorageEnabled(true);
    }
    //
    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
            callback.invoke(origin, true, false);
            super.onGeolocationPermissionsShowPrompt(origin, callback);
          }
        });
    webView.setWebViewClient(webclient);
    // webView.setWebViewClient(new WebViewClient() {
    //
    // // 加载链接
    // @Override
    // public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // view.loadUrl(url);
    // return true;
    // }
    //
    // // 链接开始加载时
    // @Override
    // public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // super.onPageStarted(view, url, favicon);
    // if (progress != null) {
    // progress.setVisibility(View.VISIBLE);
    // }
    // }
    //
    // // 链接加载完成
    // @Override
    // public void onPageFinished(WebView view, String url) {
    // super.onPageFinished(view, url);
    // if (progress != null) {
    // progress.setVisibility(View.GONE);
    // }
    // }
    //
    // @Override
    // public void onReceivedSslError(WebView view, SslErrorHandler handler,
    // SslError error) {
    // super.onReceivedSslError(view, handler, error);
    // }
    //
    // // webview无网络情况下的人性化处理
    // @Override
    // public void onReceivedError(WebView view, int errorCode, String
    // description, String failingUrl) {
    // super.onReceivedError(view, errorCode, description, failingUrl);
    // view.loadData("", "text/html", "utf-8");
    // Toast.makeText(view.getContext(), "网络不给力",
    // android.widget.Toast.LENGTH_LONG).show();
    // }
    // });
  }
Пример #24
0
  private void setWebView() {
    webSet = web.getSettings();
    webSet.setSavePassword(false);
    webSet.setAllowFileAccess(false);
    webSet.setJavaScriptEnabled(true);
    webSet.setSaveFormData(false);
    webSet.setSupportZoom(true);
    webSet.setBuiltInZoomControls(true);
    webSet.setCacheMode(WebSettings.LOAD_NO_CACHE);
    layout.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);

    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    web.setWebChromeClient(
        new WebChromeClient() { // 设置网页加载的进度条
          public void onProgressChanged(WebView view, int newProgress) {
            if (dialog_flag == true) {
              _showLoading();
              dialog_flag = false;
            }
            if (newProgress == 100) {
              dismissLoading();
              dialog_flag = true;
            }
          }

          // 设置应用程序的标题
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
          }
        });
    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    /*
     *
     * URL = ztspeechandroid://OAuthActivity?oauth_token=
     * f11203c98d813b227204254e3c148884&oauth_verifier=871525
     */
    web.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            LogInfo.LogOut(TAG, "WebView onPageStarted...");
            LogInfo.LogOut(TAG, "URL = " + url);
            if (url != null) {
              if (url.indexOf("checkType=verifycode") != -1) {
                int start = url.indexOf("checkType=verifycode&v=") + 23;
                String verifyCode = url.substring(start, start + 6);
                oAuth.setOauthVerifier(verifyCode);
                view.destroyDrawingCache();
                handler.sendMessage(
                    Message.obtain(
                        handler, ZtspeechWeiboManager.CONSTENT_TENCENT_WEIBO_REGIST, oAuth));
              } else if (url.contains("ztspeechandroid")) {
                // handler.sendMessage(Message.obtain(handler,
                // ZtspeechWeiboManager.CONSTENT_SINA_WEIBO_REGIST,
                // url));
              }
            }
            super.onPageStarted(view, url, favicon);
          }
        });
  }
Пример #25
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_help);

    webview = V.get(this, R.id.webView);
    bOk = V.get(this, R.id.bOk);
    bCancel = V.get(this, R.id.bCancel);
    View panelFaqOnly = V.get(this, R.id.panelFaqOnly);
    TextView tMessage = V.get(this, R.id.tMessage);

    WebSettings webSettings = webview.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(false);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);

    bOk.setOnClickListener(bOk_click);
    bCancel.setOnClickListener(bCancel_click);

    final String page = getIntent().getStringExtra(EXTRA_page);
    okIntent = getIntent().getParcelableExtra(EXTRA_okIntent);

    String message = getIntent().getStringExtra(EXTRA_message);
    tMessage.setText(message);

    final boolean showMessagePanel = getIntent().getBooleanExtra(EXTRA_showMessagePanel, false);
    if (!showMessagePanel) {
      panelFaqOnly.setVisibility(View.GONE);
    }

    if (page != null) {
      webview.loadUrl("file:///android_asset/" + page);
    }

    webview.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            final Uri uri = Uri.parse(url);
            final String scheme = uri.getScheme();

            if ("http".equals(scheme) || "https".equals(scheme)) {
              // open in external browser
              final Intent intent = new Intent(Intent.ACTION_VIEW);
              intent.setData(uri);
              startActivity(intent);
              return true;
            }

            if ("bible".equals(scheme)) {
              // try to decode using OSIS format
              final String ssp = uri.getSchemeSpecificPart();
              final IntArrayList ariRanges = TargetDecoder.decode("o:" + ssp);
              if (ariRanges == null || ariRanges.size() == 0) {
                new AlertDialog.Builder(HelpActivity.this)
                    .setMessage(getString(R.string.alamat_tidak_sah_alamat, url))
                    .setPositiveButton(R.string.ok, null)
                    .show();
              } else {
                final VersesDialog dialog = VersesDialog.newInstance(ariRanges);
                dialog.show(getSupportFragmentManager(), VersesDialog.class.getSimpleName());
                dialog.setListener(
                    new VersesDialog.VersesDialogListener() {
                      @Override
                      public void onVerseSelected(final VersesDialog dialog, final int ari) {
                        Log.d(TAG, "Verse link clicked from page");
                        final Intent intent = Launcher.openAppAtBibleLocation(ari);
                        startActivity(intent);
                      }
                    });
              }
              return true;
            }
            return false;
          }

          @Override
          public void onPageFinished(final WebView view, final String url) {
            super.onPageFinished(view, url);

            setTitle(view.getTitle());
          }
        });
  }
Пример #26
0
  @SuppressLint("SetJavaScriptEnabled")
  @SuppressWarnings("deprecation")
  private void initWebViewSettings() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    // TODO: The Activity is the one that should call requestFocus().
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    // Enable JavaScript
    final WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean
    // 4.2)
    try {
      Method gingerbread_getMethod =
          WebSettings.class.getMethod("setNavDump", new Class[] {boolean.class});

      String manufacturer = android.os.Build.MANUFACTURER;
      Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
      if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB
          && android.os.Build.MANUFACTURER.contains("HTC")) {
        gingerbread_getMethod.invoke(settings, true);
      }
    } catch (NoSuchMethodException e) {
      Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
      Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
      Log.d(
          TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
      Log.d(
          TAG,
          "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }

    // We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
      Level16Apis.enableUniversalAccess(settings);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
      Level17Apis.setMediaPlaybackRequiresUserGesture(settings, false);
    }
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath =
        getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);

    // Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
        && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
      enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    settings.getUserAgentString();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
      this.receiver =
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              settings.getUserAgentString();
            }
          };
      getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
  }
Пример #27
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mProgressBar = (ProgressBar) findViewById(R.id.pb_loading);

    mWebView = (WebView) findViewById(R.id.webView);
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    //        mWebView.addJavascriptInterface(new JSInterface(), "JSInterface");
    settings.setSaveFormData(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    mWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress < 100) {
              mProgressBar.setVisibility(View.VISIBLE);
              mProgressBar.setProgress(newProgress);
            } else {
              mProgressBar.setVisibility(View.GONE);
            }
          }

          @Override
          public boolean onJsAlert(
              WebView view, String url, String message, final JsResult result) {
            // 构架一个builder来显示网页中的对话框
            AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this);
            builder.setTitle("提示");
            builder.setMessage(message);
            builder.setPositiveButton(
                android.R.string.ok,
                new AlertDialog.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // 点击确定按钮之后,继续执行网页中的操作
                    result.confirm();
                  }
                });
            builder.setCancelable(false);
            builder.create();
            builder.show();
            return true;
          }
        });
    mWebView.setWebViewClient(
        new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // do your handling codes here, which url is the requested url
            // probably you need to open that url rather than redirect:
            Uri uri = Uri.parse(url);
            if (uri.getScheme().equals("octmobile")) {
              return false;
            } else {
              view.loadUrl(url);
              mClose.setVisibility(View.VISIBLE);
              return false;
            }
          }

          @Override
          public void onPageFinished(WebView view, String mLoadUrl) {
            mTitle.setText(view.getTitle());
            url = mLoadUrl;
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            CLog.d("WebView", errorCode + " " + description);
            try {
              view.loadUrl(
                  "file:///android_asset/error.html?url=" + URLEncoder.encode(url, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
            }
          }
        });

    if (savedInstanceState != null) {
      url = savedInstanceState.getString(DATA_URL);
    } else {
      decodeUrl(getIntent().getStringExtra(DATA_URL));
    }
    mWebView.loadUrl(url);
  }
Пример #28
0
  public WebFrame(Activity context, boolean allowNavigation, boolean scroll, boolean showExit) {
    super(context);
    initCompatibility();
    mActivity = context;
    mWebView = new WebView(context);
    mWebView.setVerticalScrollBarEnabled(scroll);
    mWebView.setHorizontalScrollBarEnabled(scroll);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    setLayer(mWebView);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);
    webSettings.setSupportZoom(enableZoom);
    webSettings.setBuiltInZoomControls(enableZoom);
    mWebViewClient = new WebViewClient(mActivity, allowNavigation);
    mWebView.setWebViewClient(mWebViewClient);

    final Activity localContext = context;
    if (showExit) {
      ImageView bg = new ImageView(context);
      bg.setBackgroundColor(Color.TRANSPARENT);
      addView(
          bg,
          new FrameLayout.LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              Gravity.CENTER));
      addView(
          mWebView,
          new FrameLayout.LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              Gravity.CENTER));
      mExitButton = new ImageView(context);
      mExitButton.setAdjustViewBounds(false);
      mExitButton.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              localContext.finish();
            }
          });
      int buttonSize =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics());
      mExitButton.setImageDrawable(
          ResourceManager.getStaticResource(
              context, ResourceManager.DEFAULT_SKIP_IMAGE_RESOURCE_ID));
      FrameLayout.LayoutParams params =
          new FrameLayout.LayoutParams(buttonSize, buttonSize, Gravity.TOP | Gravity.RIGHT);
      int margin =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 6, getResources().getDisplayMetrics());
      params.topMargin = margin;
      params.rightMargin = margin;
      addView(mExitButton, params);
    } else {
      addView(
          mWebView,
          new FrameLayout.LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              Gravity.CENTER));
    }
  }