コード例 #1
0
ファイル: WebFragment.java プロジェクト: vishnu038/android
 public static WebFragment newInstance(String url, SESSIONTYPE sessionType) {
   WebFragment fragment = new WebFragment();
   Bundle args = new Bundle();
   args.putString(URL, url);
   args.putInt(SESSION_TYPE, sessionType.getCode());
   fragment.setArguments(args);
   return fragment;
 }
コード例 #2
0
ファイル: WebFragment.java プロジェクト: vishnu038/android
  public void init() {
    keyboardService = new KeyboardService(getActivity());
    mainWebView = (DDGWebView) fragmentView.findViewById(R.id.fragmentMainWebView);
    mainWebView.setParentActivity(getActivity());
    mainWebView.getSettings().setJavaScriptEnabled(PreferencesManager.getEnableJavascript());
    Log.e("javascript_enabled", PreferencesManager.getEnableJavascript() + "");
    DDGWebView.recordCookies(PreferencesManager.getRecordCookies());
    DDGNetworkConstants.setWebView(mainWebView);

    // get default User-Agent string for reuse later
    mWebViewDefaultUA = mainWebView.getSettings().getUserAgentString();

    mainWebView.setWebViewClient(new DDGWebViewClient(getActivity(), this));
    View container = getActivity().findViewById(R.id.activityContainer);
    mainWebView.setWebChromeClient(new DDGWebChromeClient(this, container));

    contentDownloader = new ContentDownloader(getActivity());

    mainWebView.setDownloadListener(
        new DownloadListener() {
          public void onDownloadStart(
              String url,
              String userAgent,
              String contentDisposition,
              String mimetype,
              long contentLength) {

            contentDownloader.downloadContent(url, mimetype);
          }
        });

    // temporary fix until next appcompat release
    // https://code.google.com/p/android/issues/detail?id=80434
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
        && Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2) {
      mainWebView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              return true;
            }
          });
      mainWebView.setLongClickable(false);
    }

    webMenu = new MenuBuilder(getActivity());
    getActivity().getMenuInflater().inflate(R.menu.feed, webMenu);
    headerMenu = new MenuBuilder(getActivity());
    getActivity().getMenuInflater().inflate(R.menu.web_navigation, headerMenu);
    mainMenu = new MenuBuilder(getActivity());
    getActivity().getMenuInflater().inflate(R.menu.main, mainMenu);

    Bundle args = getArguments();

    if (args != null) {
      String url = null;
      if (args.containsKey(URL)) url = args.getString(URL);
      SESSIONTYPE sessionType = SESSIONTYPE.SESSION_BROWSE;
      if (args.containsKey(SESSION_TYPE))
        sessionType = SESSIONTYPE.getByCode(args.getInt(SESSION_TYPE));

      if (url != null) {
        searchOrGoToUrl(url, sessionType);
      }
    }
  }