/** @brief ページ読み込み進行ハンドラ 100% に達したらページ修正、オートログインなどを実施する */
  @Override
  public void onProgressChanged(WebView wv, int progress) {
    Log.d(TAG, "onProgressChanged = " + progress + " " + wv.getUrl());
    if (progress < 100) {
      if (dlg == null) {
        dlg = new Dialog(view.getContext());
        dlg.setTitle("Loading...");
        dlg.show();
      }
    } else {
      if (dlg != null) {
        dlg.dismiss();
        dlg = null;
      }

      if (autoLogin(wv)) {
        return;
      }

      String url = wv.getUrl();
      if (url != null && url.startsWith(INNER_URL_PREFIX)) {
        fixPage(wv);
      }
    }
  }
Exemple #2
0
 /**
  * Returns the URL currently being viewed
  *
  * @return URL of the page being viewed
  */
 @SimpleProperty(
     description =
         "URL of the page currently viewed.   This could be different from the "
             + "Home URL if new pages were visited by following links.",
     category = PropertyCategory.BEHAVIOR)
 public String CurrentUrl() {
   return (webview.getUrl() == null) ? "" : webview.getUrl();
 }
 @Override
 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
   // Ignore SSL certificate errors for PNA, can't use my client cert :(
   if (view.getUrl() == null
       || view.getUrl().equals("https://management.pna.utexas.edu/server/graph.cgi")) {
     handler.proceed();
   } else {
     super.onReceivedSslError(view, handler, error);
   }
 }
Exemple #4
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   EditText tv = (EditText) findViewById(R.id.editText1);
   if (tv.getVisibility() == View.VISIBLE) {
     if (tv.getText().toString().equals("1234")) {
       tv.setVisibility(View.INVISIBLE);
       wv.setVisibility(View.VISIBLE);
     }
     return super.onOptionsItemSelected(item);
   }
   switch (item.getItemId()) {
     case R.id.item1:
       tv.setVisibility(View.VISIBLE);
       tv.setText("");
       wv.setVisibility(View.INVISIBLE);
       this.getWindow()
           .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
       break;
     case R.id.item2:
       wv.loadUrl(GOOGLE);
       break;
     case R.id.item3:
       wv.goBack();
       break;
     case R.id.item4:
       Intent intent = new Intent(App.this, Bookmark.class);
       intent.putExtra("url", wv.getUrl());
       intent.putExtra("title", wv.getTitle());
       startActivityForResult(intent, REQUEST_CODE);
       break;
   }
   return super.onOptionsItemSelected(item);
 }
  /**
   * Click handlers for buttons
   *
   * @param target Button that is clicked
   */
  public void onButtonClickHandler(View target) {
    try {

      if (target.getId() == R.id.buttonWebBack) {
        if (mWebView.canGoBack()) {
          mWebView.goBack();
        }
      } else if (target.getId() == R.id.buttonWebReload) {
        mWebView.reload();
      }
      //			else if (target.getId() == R.id.buttonWebStop)
      //			{
      //				mWebView.stopLoading();
      //			}
      else if (target.getId() == R.id.buttonWebForward) {
        if (mWebView.canGoForward()) {
          mWebView.goForward();
        }
      } else if (target.getId() == R.id.buttonClose) {
        finish();
      } else if (target.getId() == R.id.buttonShare) {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(mWebView.getUrl()));
        startActivity(Intent.createChooser(i, getString(R.string.BTN_SHARING)));
      }
    } catch (Exception e) {

    }
  }
  // 框架回调函数 onConfigurationChanged 出自 android.content.res.Configuration 包。
  // 参数 newConfig - 新设备的配备。
  // 当设备配置信息有改动(比如屏幕方向的改变,实体键盘的推开或合上等)时,
  // 并且如果此时有 Activity 正在运行,系统会调用这个函数。
  // 注意:onConfigurationChanged 只会响应应用程序在 AnroidMainifest.xml 中
  //    通过 android:configChanges="配置类型" 指定的配置类型的改动;
  //    而对于其他配置的更改,则系统会先销毁当前屏幕的 Activity ,
  //    然后重新开启一个新的适应屏幕改变的 Activity 实例。
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    String url = mWebView.getUrl();

    System.out.println("========================" + url);

    // 一定要先调用父类的同名函数,让框架默认函数先处理
    // 下面这句一定不能省去,否则将引发:android.app.SuperNotCalledException 异常。
    super.onConfigurationChanged(newConfig);
    // 检测屏幕的方向:纵向或横向
    //        if ( this.getResources().getConfiguration().orientation ==
    // Configuration.ORIENTATION_LANDSCAPE )
    //        {
    //            mWebView.loadUrl(url);
    //        }
    //        else if ( this.getResources().getConfiguration().orientation ==
    // Configuration.ORIENTATION_PORTRAIT )
    //        {
    //            //当前为竖屏, 在此处添加额外的处理代码
    //            mWebView.loadUrl(url);
    //        }
    //        //检测实体键盘的状态:推出或者合上
    //        if ( newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO )
    //        {
    //            // 实体键盘处于推出状态,在此处添加额外的处理代码
    //        }
    //        else if ( newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES )
    //        {
    //            // 实体键盘处于合上状态,在此处添加额外的处理代码
    //        }
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   switch (id) {
     case R.id.action_refresh:
       refresh();
       return true;
     case R.id.action_copy_url:
       String copyDone = getString(R.string.tip_copy_done);
       AndroidUtils.copyToClipBoard(this, mWebView.getUrl(), copyDone);
       return true;
     case R.id.action_open_url:
       Intent intent = new Intent();
       intent.setAction(Intent.ACTION_VIEW);
       Uri uri = Uri.parse(mUrl);
       intent.setData(uri);
       if (intent.resolveActivity(getPackageManager()) != null) {
         startActivity(intent);
       } else {
         ToastUtils.showLong(R.string.tip_open_fail);
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
  /** @brief オートログイン */
  public boolean autoLogin(WebView wv) {
    String js, fmt;

    // ログインページに居るかどうか確認
    String url = wv.getUrl();
    if (url == null || !url.startsWith(LOGIN_URL)) {
      return false;
    }

    // User ID / Pass を取得
    SharedPreferences prefs =
        context.getSharedPreferences(PrefActivity.PREF_NAME, Context.MODE_PRIVATE);
    String uid = prefs.getString(PrefActivity.PREF_KEY_USERID, "");
    String pass = prefs.getString(PrefActivity.PREF_KEY_PASSWORD, "");

    // auto login
    for (int i = 1; i <= 2; i++) {
      fmt = "javascript:document.getElementById(\"user_id%d\").value=\"%s\"";
      js = String.format(fmt, i, uid);
      runJs(wv, js);

      fmt = "javascript:document.getElementById(\"password%d\").value=\"%s\"";
      js = String.format(fmt, i, pass);
      runJs(wv, js);
    }

    return true;
  }
 @Override
 protected void onSaveInstanceState(Bundle state) {
   String url = webView.getUrl();
   if (url != null && url.length() > 0) {
     webView.saveState(state);
     state.putBoolean(WEBVIEW_STATE_PRESENT, true);
   }
 }
Exemple #10
0
 /**
  * Tried to maintain a stack of urls first, but b/c shouldOverride is not called each time, it
  * proved to be a poor solution. Instead, we just query the webview for the loaded page after it's
  * been loaded. This can make the urlbar slow to update, but at least it's accurate.
  */
 public void loadFinished() {
   String url = mVizWebView.getUrl();
   if (!TextUtils.isEmpty(url)) {
     if (urlBar != null) {
       urlBar.setText(url);
     }
   }
   setCanGoBack();
 }
 public void saveConfigInfo(String url, String userName, String password) {
   sharedEditor.putString(F_URL, url);
   sharedEditor.putString(F_USERNAME, userName);
   sharedEditor.putString(F_PASSWORD, password);
   sharedEditor.commit();
   if (isEmpty(contentWebView.getUrl())) {
     contentWebView.loadUrl(url);
   }
 }
Exemple #12
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.action_external:
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl())));
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
Exemple #13
0
  private void refreshUI() {
    Log.d();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String url = prefs.getString(Preferences.LASTPAGE_LOADED, "http://vimeo.com");
    Log.d("Got url from preferences: " + url);
    String currentURL = mVizWebView.getUrl();
    if (TextUtils.isEmpty(currentURL) || !url.equals(currentURL)) {
      urlBar.setText(url);
      loadUrlFromUrlBar();
    }
  }
  public void refreshData() {
    if (NetworkManager.isOnline(getActivity()) || mLocal) {
      // show progress in action bar
      showActionBarProgress(true);

      // load web url
      WebView webView = (WebView) mRootView.findViewById(R.id.fragment_main_webview);
      webView.loadUrl(webView.getUrl());
    } else {
      showActionBarProgress(false);
      Toast.makeText(getActivity(), R.string.global_offline_toast, Toast.LENGTH_LONG).show();
    }
  }
Exemple #15
0
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
      if (mKey.isBound()) {
        // We fire an event here!
        appView.loadUrl("javascript:document.keyEvent.backTrigger()");
      } else {
        String testUrl = appView.getUrl();
        appView.goBack();
        if (appView.getUrl().equals(testUrl)) {
          return super.onKeyDown(keyCode, event);
        }
      }
    }

    if (keyCode == KeyEvent.KEYCODE_MENU) {
      // This is where we launch the menu
      appView.loadUrl("javascript:keyEvent.menuTrigger()");
    }

    return false;
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
      Toast.makeText(this, webView.getUrl(), Toast.LENGTH_SHORT).show();
      if (webView.canGoBack()) {
        webView.goBack(); // 返回上一个页面
        return true;
      } else {
        System.exit(0); // 退出程序
      }
    }
    return super.onKeyDown(keyCode, event);
  }
 @Override
 public void onPageFinished(WebView view, String url) {
   String javascript = new String();
   if (url.startsWith("https://apps1.u-bordeaux.fr/groupesetuBx/"))
     javascript = "javascript:" + getScriptContent("td.js");
   //			else if (url.startsWith("https://apogee.u-bordeaux.fr"))
   //				javascript = "javascript:" + getScriptContent("apogee.js");
   //			else
   javascript = "javascript:function(){};";
   view.loadUrl(javascript);
   pDialog.dismiss();
   pDialog.cancel();
   current_url = view.getUrl();
   state = 0;
   CookieSyncManager.getInstance().sync();
 }
Exemple #18
0
 @Override
 public void onPause() {
   Log.d();
   String url = null;
   if (mVizWebView != null) {
     url = mVizWebView.getUrl();
   }
   if (url != null) {
     Log.d("Storing url for later: " + url);
     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
     SharedPreferences.Editor ed = prefs.edit();
     ed.putString(Preferences.LASTPAGE_LOADED, url);
     ed.commit();
   }
   super.onPause();
 }
Exemple #19
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   Log.d();
   int id = item.getItemId();
   if (id == android.R.id.home) {
     Log.d("Home pressed, go back in web history");
     goBack();
     return true;
   } else if (id == R.id.add_favorite) {
     Log.d("Add favorite");
     Favorite favorite =
         Favorite.newInstance(
             mVizWebView.getTitle(), mVizWebView.getUrl(), mVizWebView.getFavicon());
     ContentValues map = favorite.toContentValues();
     getActivity().getContentResolver().insert(VizContract.Favorites.CONTENT_URI, map);
     getActivity().getContentResolver().notifyChange(VizContract.Favorites.CONTENT_URI, null);
     CharSequence text = favorite.getTitle() + " " + VizApp.getResString(R.string.favorites_added);
     Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
     return true;
   } else {
     return super.onOptionsItemSelected(item);
   }
 }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.bGo:
        String theWebSite = url.getText().toString();
        ourBrow.loadUrl(theWebSite);
        // hiding the Keyboard after using an EditText
        InputMethodManager imm =
            (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(url.getWindowToken(), 0);
        break;

      case R.id.bBack:
        if (ourBrow.canGoBack()) {
          ourBrow.goBack();
          url.setText(ourBrow.getOriginalUrl());
        }
        break;

      case R.id.bRefresh:
        ourBrow.reload();
        break;

      case R.id.bForward:
        if (ourBrow.canGoForward()) {
          ourBrow.goForward();
          url.setText(ourBrow.getUrl());
        }
        break;

      case R.id.bHistory:
        ourBrow.clearHistory();
        url.setText("");
        break;
    }
  }
 private void shareURL() {
   shareIntent.setType("text/plain");
   shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
   startActivity(Intent.createChooser(shareIntent, "分享..."));
 }
Exemple #22
0
 public String currentLocation(int index) {
   return webView.getUrl();
 }
  @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));
    }
  }