@Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
   super.onRestoreInstanceState(savedInstanceState);
   if (webView != null) {
     webView.restoreState(savedInstanceState);
   }
 }
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.help);

    webView = (WebView) findViewById(R.id.help_contents);
    webView.setWebViewClient(new HelpClient(this));

    Intent intent = getIntent();
    String page = intent.getStringExtra(REQUESTED_PAGE_KEY);

    // Show an OK button.
    View doneButton = findViewById(R.id.done_button);
    doneButton.setOnClickListener(doneListener);

    if (page.equals(DEFAULT_PAGE)) {
      doneButton.setVisibility(View.VISIBLE);
    } else {
      doneButton.setVisibility(View.GONE);
    }

    // Froyo has a bug with calling onCreate() twice in a row, which causes the What's New page
    // that's auto-loaded on first run to appear blank. As a workaround we only call restoreState()
    // if a valid URL was loaded at the time the previous activity was torn down.
    if (icicle != null && icicle.getBoolean(WEBVIEW_STATE_PRESENT, false)) {
      webView.restoreState(icicle);
    } else if (intent != null && page != null && page.length() > 0) {
      webView.loadUrl(BASE_URL + page);
    } else {
      webView.loadUrl(BASE_URL + DEFAULT_PAGE);
    }
  }
예제 #3
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // restore webview state
    if (savedInstanceState != null) {
      WebView webView = (WebView) mRootView.findViewById(R.id.fragment_main_webview);
      webView.restoreState(savedInstanceState);
    }

    // setup webview
    renderView();

    // pull to refresh
    SwipeRefreshLayout swipeRefreshLayout =
        (SwipeRefreshLayout) mRootView.findViewById(R.id.container_swipe_refresh);
    swipeRefreshLayout.setOnRefreshListener(this);

    // load and show data
    if (mViewState == null || mViewState == ViewState.OFFLINE) {
      loadData();
    } else if (mViewState == ViewState.CONTENT) {
      showContent();
    } else if (mViewState == ViewState.PROGRESS) {
      showProgress();
    } else if (mViewState == ViewState.EMPTY) {
      showEmpty();
    }

    // progress in action bar
    showActionBarProgress(mActionBarProgress);
  }
예제 #4
0
파일: Browser.java 프로젝트: elevenfive/Viz
  @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);
  }
예제 #5
0
  protected void init(int webViewId, int layoutId, String url) {
    setContentView(layoutId);
    jsBridge.setApp(myApp);
    appView = ((WebView) findViewById(webViewId));
    loader = findViewById(R.id.loader);
    if (instanceState != null) appView.restoreState(instanceState);
    appView.addJavascriptInterface(jsBridge, "Native");
    appView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {
            loader.setVisibility(View.INVISIBLE);
          }

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d(TAG, "page started");
            loader.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
          }

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!url.startsWith("http://")) {
              Log.d(TAG, "loading external url: " + url);
              view.loadUrl(url);
              return true;
            }
            return false;
          }
        });
    /* WebChromeClient must be set BEFORE calling loadUrl! */
    appView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public boolean onJsAlert(
              WebView view, String url, String message, final android.webkit.JsResult result) {
            new AlertDialog.Builder(myApp)
                .setTitle("javaScript dialog")
                .setMessage(message)
                .setPositiveButton(
                    android.R.string.ok,
                    new AlertDialog.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                        result.confirm();
                      }
                    })
                .setCancelable(false)
                .create()
                .show();

            return true;
          };
        });
    appView.getSettings().setJavaScriptEnabled(true);
    jsBridge.setApp(this);
    this.url = url;
    Log.d(TAG, "init done");
  }
예제 #6
0
파일: Browser.java 프로젝트: elevenfive/Viz
 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
   Log.d();
   if (savedInstanceState != null) {
     mVizWebView.restoreState(savedInstanceState);
   }
   super.onActivityCreated(savedInstanceState);
 }
예제 #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);

    Bundle b = getIntent().getExtras();
    feedItem = b.getParcelable("feedItem");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_webview);
    setSupportActionBar(toolbar);

    myWebView = (WebView) findViewById(R.id.webview);

    // Load previous state if we have it
    if (savedInstanceState != null) {
      myWebView.restoreState(savedInstanceState);
    } else {
      initWebView(myWebView);
    }

    // If we have a related feed item, we choose the advanced toolbar
    if (feedItem != null) {
      hasFeedItem = true;
      thumbnail = (Bitmap) getIntent().getParcelableExtra("thumbnail");
      getSupportActionBar().setTitle(feedItem.getTitle());
      getSupportActionBar().setSubtitle(feedItem.getShortUrl());

      // If we don't have previous state, reload the URL
      if (savedInstanceState == null) {
        myWebView.loadUrl(feedItem.getLongUrl());
      }
    } else {
      hasFeedItem = false;
      getSupportActionBar().setTitle(b.getString("url"));

      if (savedInstanceState == null) {
        myWebView.loadUrl(b.getString("url"));
      }
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressBar.setMax(100);
  }
예제 #8
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;
  }
예제 #9
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);
    this.webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    if (savedInstanceState != null) {
      webView.restoreState(savedInstanceState);
    } else {
      webView.loadUrl(UrlConstants.WEBVIEW_URL);
    }
  }
예제 #10
0
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
   super.onRestoreInstanceState(savedInstanceState);
   mainWebView.restoreState(savedInstanceState);
 }
예제 #11
0
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
   super.onRestoreInstanceState(savedInstanceState);
   // Restore the state of the WebView
   jincheon.restoreState(savedInstanceState);
 }
 @Override
 public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
   super.onViewStateRestored(savedInstanceState);
   mWebView.restoreState(savedInstanceState);
 }
예제 #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView) this.findViewById(R.id.webview);
    setUpWebViewDefaults(mWebView);
    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
      // Restore the previous URL and history stack
      mWebView.restoreState(savedInstanceState);
    }
    mWebView.loadUrl(getString(R.string.main_url));
    setImmerseLayout(mWebView);

    mWebView.setWebChromeClient(
        new WebChromeClient() {

          // For Android 2.0+
          public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            if (mUploadMessage != null) {
              return;
            }
            mUploadMessage = uploadMsg;
            startActivityForResult(
                Intent.createChooser(createDefaultOpenableIntent(), "File Chooser"),
                FILECHOOSER_RESULTCODE);
          }
          // For Android 3.0+
          public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
          }
          // For Android 4.1+
          public void openFileChooser(
              ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
          }
          // Android 5.0+ 以上文件选择
          public boolean onShowFileChooser(
              WebView webView,
              ValueCallback<Uri[]> filePathCallback,
              WebChromeClient.FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null) {
              mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;
            startActivityForResult(createDefaultOpenableIntent(), INPUT_FILE_REQUEST_CODE);
            return true;
          }
          /**
           * 获取文件选择的Intent
           *
           * @return
           */
          private Intent createDefaultOpenableIntent() {

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            Intent pictureIntent = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
              pictureIntent = createCameraIntentUp();
            } else {
              pictureIntent = createCameraIntentLow();
            }
            if (pictureIntent != null) {
              intentArray = new Intent[] {pictureIntent};
            } else {
              intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "File Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            return chooserIntent;
          }

          /** 低版本相机拍照选取 */
          private Intent createCameraIntentLow() {
            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            try {
              File externalDataDir =
                  Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
              System.out.println("externalDataDir:" + externalDataDir);
              File cameraDataFile = createImageFile();
              mCameraPhotoPath = cameraDataFile.getAbsolutePath();
              cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraDataFile));
            } catch (IOException e) {
              cameraIntent = null;
            }
            return cameraIntent;
          }

          /** 5.0+版本相机拍照选取 */
          private Intent createCameraIntentUp() {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
              // Create the File where the photo should go
              File photoFile = null;
              try {
                photoFile = createImageFile();
                takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
              } catch (IOException ex) {
                // Error occurred while creating the File
                Log.e(TAG, "Unable to create Image File", ex);
              }

              // Continue only if the File was successfully created
              if (photoFile != null) {
                mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
              } else {
                takePictureIntent = null;
              }
            }
            return takePictureIntent;
          }
        });

    if (mWebView.getUrl() == null) {
      mWebView.loadUrl(getString(R.string.main_url));
    }
  }
예제 #14
0
 @Override // metodo override que se ejecuta cuando se crea la actividad
 public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   myWebView.restoreState(
       savedInstanceState); // Se restaura el estado del webView al crearse la actividad
 }
예제 #15
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_whats_trending, container, false);
    // View footerView =
    // ((LayoutInflater)this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
    // this.getListView().addFooterView(footerView);
    progressBarT4 = (ProgressBar) rootView.findViewById(R.id.progressBar1web);
    load = (TextView) rootView.findViewById(R.id.loadin);
    browser = (WebView) rootView.findViewById(R.id.webView1);
    refreshweb = (Button) rootView.findViewById(R.id.buttonrefresh);
    anim = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.animation);
    // load.startAnimation(anim);
    // getActivity().anim.setAnimationListener(this);
    browser.setWebViewClient(new MyBrowser());

    // TODO Auto-generated method stub
    browser.getSettings().setLoadsImagesAutomatically(true);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.getSettings().setSupportZoom(false);
    // browser.getSettings().setBuiltInZoomControls(true);
    browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    browser.setScrollbarFadingEnabled(true);
    browser.getSettings().setLoadsImagesAutomatically(true);

    if (!haveNetworkConnection()) { // load.setTextColor(getResources().getColor(R.color.yellow));
      load.setBackgroundColor(getResources().getColor(R.color.red));
      load.setText("No Internet Connection");

      progressBarT4.setVisibility(View.GONE);
      refreshweb.setVisibility(View.VISIBLE);
      refreshweb.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
              // TODO Auto-generated method stub
              Intent i = new Intent(getActivity(), MainActivity.class);

              getActivity().finish();
              startActivity(i);
            }
          });
      Toast.makeText(getActivity(), "No Internet Cannection", Toast.LENGTH_SHORT).show();

    } else {

      browser.setWebChromeClient(
          new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
              progressBarT4.setVisibility(View.VISIBLE);

              progressBarT4.setProgress(progress);

              if (progress == 100) {
                load.setVisibility(View.GONE);
                //		    	            	/load.clearAnimation();
                progressBarT4.setVisibility(
                    View.GONE); // Make the bar disappear after URL is loaded
              }
            }
          });
      load.setVisibility(View.VISIBLE);
      progressBarT4.setVisibility(View.VISIBLE);

      if (webViewBundle == null) {
        browser.loadUrl("http://192.168.43.207/SEtest-Mobile/about.html");
      } else {
        browser.restoreState(webViewBundle);
      }

      /*dialog = ProgressDialog.show(getActivity(), "",
                 "Please Wait",true);
      dialog.setCancelable(true);
      dialog.setCanceledOnTouchOutside(true);*/

    }

    return rootView;
  }
예제 #16
0
  @SuppressLint("SetJavaScriptEnabled")
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
      // get url and navigatio preference (default true)
      final String url = getIntent().getStringExtra(getPackageName() + ".URL");
      final boolean navigation =
          getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true);

      setContentView(R.layout.webviewnav);

      // if we want navigation bar and not hide it, make it visible. Make it invisible if not.
      if (navigation && !hideNavigationBar) {
        findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE);
      } else {
        findViewById(R.id.webBottomBar).setVisibility(View.GONE);
      }

      mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack);
      mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward);
      mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop);

      mProgressView = (ProgressBar) findViewById(R.id.progressBar);
      mProgressView.setIndeterminate(true);

      // init webview
      mWebView = (WebView) findViewById(R.id.webView);

      // disable hw accel as it creates flickering pages, html5 video won't work with this
      if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16)
        mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

      // This hides white bar on the right
      mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

      WebSettings settings = mWebView.getSettings();
      // enable plugins before java script
      settings.setPluginState(PluginState.ON);

      // TODO test these two settings with a big webpage (cafe lotty?)
      settings.setLoadWithOverviewMode(true);
      settings.setUseWideViewPort(true);
      // enable javascript and zoom controls
      settings.setJavaScriptEnabled(true);
      settings.setBuiltInZoomControls(true);
      settings.setGeolocationEnabled(true);
      settings.setDatabaseEnabled(true);
      String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath();
      settings.setDatabasePath(databasePath);
      settings.setGeolocationDatabasePath(databasePath);
      settings.setDomStorageEnabled(true);
      settings.setAppCacheEnabled(true);

      // allow XMLHttpRequests
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        settings.setAllowUniversalAccessFromFileURLs(true);

      MetaioWebViewClient client = new MetaioWebViewClient();
      mWebView.setWebViewClient(client);
      mWebView.setWebChromeClient(new MetaioWebChromeClient());

      registerForContextMenu(mWebView);

      if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
      } else {

        // if we don't have to override the url, load it in the webview
        if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url);
      }
    } catch (Exception e) {
      MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e);
    }
  }