android.webkit.WebView Java Examples

The following examples show how to use android.webkit.WebView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebChromeClientConfig.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void onProgressChanged(WebView view, int newProgress) {
    //加载的进度
    progressBar.setProgress(newProgress);
    if (newProgress == 100) {

        Message msg = new Message();
        msg.what = 5;
        handler.sendMessageDelayed(msg, 300);

    } else {

        if (View.GONE == progressBar.getVisibility())
            progressBar.setVisibility(View.VISIBLE);
    }

    super.onProgressChanged(view, newProgress);
}
 
Example #2
Source File: StartActivity.java    From jpHolo with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	super.init();
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		if ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) ) {
			WebView.setWebContentsDebuggingEnabled(true);
		}
	}
	if (checkScreenSize().equals("large") || checkScreenSize().equals("xlarge")) {
		initiateApp("tablet");
	} else {
		initiateApp("smartphone");
	}
}
 
Example #3
Source File: IssuePreviewActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public void resetView() {
       setContentView(R.layout.activity_issue_preview);

	((TextView) findViewById(R.id.title)).setText(Utils.stripTags(title));

       final WebView web = (WebView) findViewById(R.id.detailsLabel);
       web.loadDataWithBaseURL(null, details, "text/html", "utf-8", null);
       web.setWebViewClient(new WebViewClient() {
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
           	try {
           		view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
           	} catch (Exception failed) {
           		return false;
           	}
               return true;
           }
       });
}
 
Example #4
Source File: FunctionIntroducedActivity.java    From sealtalk-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_function_introduced);

    getSupportActionBar().setTitle(R.string.function_introduce);

    mWebView = (WebView) findViewById(R.id.function_introdiced_webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setUseWideViewPort(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setSupportZoom(true);


    MyWebViewClient mMyWebViewClient = new MyWebViewClient();
    mMyWebViewClient.onPageFinished(mWebView, "http://rongcloud.cn/features");
    mMyWebViewClient.shouldOverrideUrlLoading(mWebView, "http://rongcloud.cn/features");
    mMyWebViewClient.onPageFinished(mWebView, "http://rongcloud.cn/features");
    mWebView.setWebViewClient(mMyWebViewClient);
}
 
Example #5
Source File: OfflineAds.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
static void displayBanner() {
	if (BuildConfig.DEBUG) {
		Game.instance().runOnUiThread(new Runnable() {
			@Override
			public void run() {
				LinearLayout layout = Game.instance().getLayout();
				if (layout.getChildCount() == 1) {

					WebView adView = new WebView(Game.instance());

					int adViewHeight = Math.max(50, layout.getHeight() / 10);

					ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, adViewHeight);
					adView.setLayoutParams(params);

					adView.loadDataWithBaseURL(null, Utils.format(adTemplate, "Рекламко"), "text/html", "utf-8", null);
					Game.instance().getLayout().addView(adView, 0);
					Game.setNeedSceneRestart(true);
				}
			}
		});
	}
}
 
Example #6
Source File: GoJsActivity.java    From DragonGoApp with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onPageFinished(final WebView view, String url) {
	System.out.println("page finished loading");
	if (curstate!=guistate.review)
		GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].last()");
	else if (!Reviews.isNotReviewStage) {
		Reviews.advance();
	}
	if (curstate==guistate.markDeadStones)
		GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].detmarkx()");
	final EventManager em = EventManager.getEventManager();
	em.sendEvent(eventType.gobanReady);

	// ask for comments to display them in big
	System.out.println("page finished call detComments");
	GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].detComments()");
	// also get the HTML of the page
	GoJsActivity.viewUrl("javascript:console.log('MAGIC'+document.getElementsByTagName('html')[0].innerHTML);");
}
 
Example #7
Source File: WebViewHelper.java    From AndroidReview with GNU General Public License v3.0 6 votes vote down vote up
public static void initWebViewSettings(WebView webView) {
    WebSettings settings = webView.getSettings();
    //这个单位是SP
    settings.setDefaultFontSize(15);

    settings.setJavaScriptEnabled(true);  //支持js

    settings.setUseWideViewPort(false);  //将图片调整到适合webview的大小

    settings.setSupportZoom(true);  //支持缩放

    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//无论是否有网络,只要本地有缓存,都使用缓存。本地没有缓存时才从网络上获取。 这里的WebView主要是用来加载图片和解析Html文本

    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局

    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //使超链接失效
            return true;
        }
    });

}
 
Example #8
Source File: TaskAddHtml.java    From pe-protector-moe with GNU General Public License v3.0 6 votes vote down vote up
public TaskAddHtml(WebView webview, HttpFinishCallBack callBack) {
    this.callBack = callBack;
    List<MapConfigBean> list = LitePal.findAll(MapConfigBean.class);
    List<String> name = new ArrayList<>();
    for (MapConfigBean m : list) {
        name.add(m.name);
    }
    webview.loadUrl("file:///android_asset/html/task.html");
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            view.loadUrl(String.format("javascript:onLoad(\'%s\')", JSON.toJSONString(name)));
        }
    });
}
 
Example #9
Source File: Register.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_register, container, false);

    SharedPreferences sharedPref
            = getActivity().getApplicationContext().getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE);

    WebView webview = (WebView)view.findViewById(R.id.web);
    pbar = (ProgressBar)view.findViewById(R.id.loading);
    pbar.setVisibility(View.GONE);
    webview.setWebViewClient(new WebViewClient());
    webview.getSettings().setJavaScriptEnabled(true);

    String registerURL = sharedPref.getString(REGLINK_TAG, null);
    webview.loadUrl(registerURL);

    return view;
}
 
Example #10
Source File: WebDialog.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(BACKGROUND_GRAY);
    contentFrameLayout.addView(webViewContainer);
}
 
Example #11
Source File: HorizontalScrollCompat.java    From SmoothRefreshLayout with MIT License 6 votes vote down vote up
public static boolean isScrollingView(View view) {
    if (ViewCatcherUtil.isViewPager(view)
            || view instanceof HorizontalScrollView
            || view instanceof WebView) {
        return true;
    } else if (ViewCatcherUtil.isRecyclerView(view)) {
        RecyclerView recyclerView = (RecyclerView) view;
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager != null) {
            if (manager instanceof LinearLayoutManager) {
                LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
                return linearManager.getOrientation() == RecyclerView.HORIZONTAL;
            } else if (manager instanceof StaggeredGridLayoutManager) {
                StaggeredGridLayoutManager gridLayoutManager =
                        (StaggeredGridLayoutManager) manager;
                return gridLayoutManager.getOrientation() == RecyclerView.HORIZONTAL;
            }
        }
    }
    return false;
}
 
Example #12
Source File: PointsWeb.java    From letv with Apache License 2.0 6 votes vote down vote up
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    try {
        if (url.indexOf("?") > 0) {
            String u = url.substring(0, url.indexOf("?"));
            if (TextUtils.isEmpty(u)) {
                return super.shouldOverrideUrlLoading(view, url);
            }
            if (PointsWeb.this.jumpType == 0) {
                if (!".mp4".equals(u.substring(u.lastIndexOf("."), u.length())) || !url.contains("vtype=mp4")) {
                    return super.shouldOverrideUrlLoading(view, url);
                }
                view.stopLoading();
                if (!PointsWeb.this.isFinish) {
                    Intent intent = new Intent("android.intent.action.VIEW");
                    intent.setDataAndType(Uri.parse(url), "video/mp4");
                    intent.putExtra("android.intent.extra.screenOrientation", 0);
                    PointsWeb.this.startActivity(intent);
                }
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.shouldOverrideUrlLoading(view, url);
}
 
Example #13
Source File: AlertDialogWidget.java    From rexxar-android with MIT License 6 votes vote down vote up
@Override
public boolean handle(WebView view, String url) {
    if (TextUtils.isEmpty(url)) {
        return false;
    }
    Uri uri = Uri.parse(url);
    String path = uri.getPath();
    if (TextUtils.equals(path, getPath())) {
        String data = uri.getQueryParameter(KEY);
        Data alertDialogData = null;
        if (!TextUtils.isEmpty(data)) {
            alertDialogData = GsonHelper.getInstance().fromJson(data, Data.class);
        }
        if (null == alertDialogData || !alertDialogData.valid()) {
            return false;
        }

        return renderDialog((Activity) view.getContext(), view, alertDialogData);
    }
    return false;
}
 
Example #14
Source File: ActivityAbout.java    From wakao-app with MIT License 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initView(){
	detail = (WebView) findViewById(R.id.wv_article_detail);
	commentbar = (LinearLayout)findViewById(R.id.comment_bar);
	title = (TextView)findViewById(R.id.top_bar_title);
	toggle_btn = (ImageButton)findViewById(R.id.m_toggle);
	back_btn = (ImageButton)findViewById(R.id.go_back);
	
	
	detail.getSettings().setJavaScriptEnabled(true);
	detail.loadUrl("file:///android_asset/about.html");
	title.setText("关于我们");
	back_btn.setVisibility(View.VISIBLE);
	toggle_btn.setVisibility(View.GONE);
	commentbar.setVisibility(View.GONE);
	
	back_btn.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			onBackPressed();
		}
	});
}
 
Example #15
Source File: CordovaWebView.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
Example #16
Source File: BridgeWebViewClient.java    From JsBridge with MIT License 5 votes vote down vote up
@Override
public void onFormResubmission(WebView view, android.os.Message dontResend, android.os.Message resend) {
    boolean interrupt = false;
    if (bridgeWebViewClientListener != null) {
        interrupt = bridgeWebViewClientListener.onFormResubmission(view, dontResend, resend);
    }
    if (!interrupt) {
        super.onFormResubmission(view, dontResend, resend);
    }
}
 
Example #17
Source File: BlogActivity.java    From ImmersionBar with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView() {
    if ("github".equals(blog)) {
        mWebView.loadUrl("https://github.com/gyf-dev/ImmersionBar");
    } else {
        mWebView.loadUrl("https://www.jianshu.com/p/2a884e211a62");
    }
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.toString());
            return true;
        }
    });
}
 
Example #18
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void onPageStarted(WebView webView, String url, Bitmap favicon) {
  super.onPageStarted(webView, url, favicon);
  mLastLoadFailed = false;

  dispatchEvent(
    webView,
    new TopLoadingStartEvent(
      webView.getId(),
      createWebViewEvent(webView, url)));
}
 
Example #19
Source File: WebViewClientDelegate.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) {
    if (mDelegate != null) {
        mDelegate.onReceivedClientCertRequest(view, request);
        return;
    }
    super.onReceivedClientCertRequest(view, request);
}
 
Example #20
Source File: Web3TokenView.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@Override
public void onUnhandledKeyEvent(WebView view, KeyEvent event)
{
    if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
    {
        if (keyPressCallback != null)
            keyPressCallback.enterKeyPressed();
    }
    super.onUnhandledKeyEvent(view, event);
}
 
Example #21
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onProgressChanged(WebView view, int newProgress) {
	if (shouldCallSuper("onProgressChanged")) {
		super.onProgressChanged(view, newProgress);
	}
	if (shouldSendEvent("onProgressChanged")) {
		WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.WEBPLAYER, WebPlayerEvent.PROGRESS_CHANGED, newProgress, viewId);
	}
}
 
Example #22
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 5 votes vote down vote up
@Override
public void doUpdateVisitedHistory(WebView webView, String url, boolean isReload) {
    super.doUpdateVisitedHistory(webView, url, isReload);
    dispatchEvent(
            webView,
            new TopLoadingStartEvent(
                    webView.getId(),
                    createWebViewEvent(webView, url)));
}
 
Example #23
Source File: ByWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    //6.0以下执行
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return;
    }
    String mErrorUrl = "file:///android_asset/404_error.html";
    view.loadUrl(mErrorUrl);
}
 
Example #24
Source File: SystemWebChromeClient.java    From keemob with MIT License 5 votes vote down vote up
/**
 * Tell the client to display a confirm dialog to the user.
 */
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    dialogsHelper.showConfirm(message, new CordovaDialogsHelper.Result() {
        @Override
        public void gotResult(boolean success, String value) {
            if (success) {
                result.confirm();
            } else {
                result.cancel();
            }
        }
    });
    return true;
}
 
Example #25
Source File: WebViewActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public boolean onShowFileChooser(final WebView webView, final ValueCallback<Uri[]> filePathCallback,
                                 final FileChooserParams fileChooserParams) {
    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = filePathCallback;

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(TYPE_IMAGE);
    startActivityForResult(intent, INPUT_FILE_REQUEST_CODE);

    return true;
}
 
Example #26
Source File: OpenSourceLicensesActivity.java    From Tehreer-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_open_source_licenses);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    WebView licensesView = findViewById(R.id.web_view_licenses);
    licensesView.loadUrl("file:///android_asset/OpenSourceLicenses.html");
}
 
Example #27
Source File: CordovaWebViewClient.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * On received http auth request.
 * The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination
 *
 * @param view
 * @param handler
 * @param host
 * @param realm
 */
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {

    // Get the authentication token
    AuthenticationToken token = this.getAuthenticationToken(host, realm);
    if (token != null) {
        handler.proceed(token.getUserName(), token.getPassword());
    }
    else {
        // Handle 401 like we'd normally do!
        super.onReceivedHttpAuthRequest(view, handler, host, realm);
    }
}
 
Example #28
Source File: WebActivity.java    From Router with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);

    webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("file:///android_asset/schame-test.html");
}
 
Example #29
Source File: KakaoWebViewDialog.java    From kakao-android-sdk-standalone with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    Logger.getInstance().d(LOG_TAG, "Webview loading URL: " + url);
    super.onPageStarted(view, url, favicon);
    if (!isDetached) {
        spinner.show();
    }
}
 
Example #30
Source File: CreateReplyActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_create_reply);
       
       if (MainActivity.instance instanceof ForumConfig) {
       	HttpGetImageAction.fetchImage(this, MainActivity.instance.avatar, findViewById(R.id.icon));
       } else {
       	((ImageView)findViewById(R.id.icon)).setImageResource(R.drawable.icon,80,80);
       }
       
       TextView text = (TextView) findViewById(R.id.topicText);
       text.setText(MainActivity.post.topic);
       
       CheckBox checkbox = (CheckBox) findViewById(R.id.replyToParentCheckBox);
       if (MainActivity.post.parent != null && MainActivity.post.parent.length() != 0) {
       	checkbox.setChecked(true);
       } else {
       	checkbox.setVisibility(View.GONE);
       }
       
       final WebView web = (WebView) findViewById(R.id.detailsLabel);
       web.loadDataWithBaseURL(null, MainActivity.post.detailsText, "text/html", "utf-8", null);
       
       web.setWebViewClient(new WebViewClient() {
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
           	try {
           		view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
           	} catch (Exception failed) {
           		return false;
           	}
               return true;
           }
       });
}