Java Code Examples for android.webkit.WebView

The following are top voted examples for showing how to use android.webkit.WebView. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: SmartRefresh   File: RefreshContentWrapper.java   Source Code and License 7 votes vote down vote up
private View findScrollableViewInternal(View content, boolean selfable) {
    View scrollableView = null;
    Queue<View> views = new LinkedBlockingQueue<>(Collections.singletonList(content));
    while (!views.isEmpty() && scrollableView == null) {
        View view = views.poll();
        if (view != null) {
            if ((selfable || view != content) && (view instanceof AbsListView
                    || view instanceof ScrollView
                    || view instanceof ScrollingView
                    || view instanceof NestedScrollingChild
                    || view instanceof NestedScrollingParent
                    || view instanceof WebView
                    || view instanceof ViewPager)) {
                scrollableView = view;
            } else if (view instanceof ViewGroup) {
                ViewGroup group = (ViewGroup) view;
                for (int j = 0; j < group.getChildCount(); j++) {
                    views.add(group.getChildAt(j));
                }
            }
        }
    }
    return scrollableView;
}
 
Example 2
Project: DailyZhiHu   File: DownloadDetaiContentActivity.java   Source Code and License 7 votes vote down vote up
private void init(){
    LinearLayout layout = (LinearLayout) findViewById(R.id.Download_layout);
    layout.setVisibility(View.GONE);

    Intent intent = getIntent();
    body = intent.getStringExtra("body");
    title = intent.getStringExtra("title");
    contentView = (WebView) findViewById(R.id.content_webview);
    contentView.setHorizontalScrollBarEnabled(false);//水平不显示
    contentView.setVerticalScrollBarEnabled(false); //垂直不显示

    contentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return (event.getAction() == MotionEvent.ACTION_MOVE);
        }
    });
    contentView.setWebViewClient(new WebViewClient());

    topImage = (ImageView) findViewById(R.id.top_image);
    topTitle = (TextView) findViewById(R.id.top_titlt);
    topSource = (TextView) findViewById(R.id.top_source);
}
 
Example 3
Project: siiMobilityAppKit   File: InAppBrowser.java   Source Code and License 7 votes vote down vote up
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }

    // https://issues.apache.org/jira/browse/CB-11248
    view.clearFocus();
    view.requestFocus();

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);

        sendUpdate(obj, true);
    } catch (JSONException ex) {
        LOG.d(LOG_TAG, "Should never happen");
    }
}
 
Example 4
Project: WebViewInputSample   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    webView = (WebView) findViewById(R.id.webview);
    String url = "file:///android_asset/sample.html";

    webView.getSettings().setJavaScriptEnabled(true);

    webChromeClient = new FileChooserWebChromeClient();
    webView.setWebChromeClient(webChromeClient);
    webView.loadUrl(url);

    WebView.setWebContentsDebuggingEnabled(true);

}
 
Example 5
Project: LoRaWAN-Smart-Parking   File: CordovaUriHelper.java   Source Code and License 6 votes vote down vote up
/**
 * Give the host application a chance to take over the control when a new url
 * is about to be loaded in the current WebView.
 *
 * @param view          The WebView that is initiating the callback.
 * @param url           The url to be loaded.
 * @return              true to override, false for default behavior
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
boolean shouldOverrideUrlLoading(WebView view, String url) {
    // Give plugins the chance to handle the url
    if (this.appView.pluginManager.onOverrideUrlLoading(url)) {
        // Do nothing other than what the plugins wanted.
        // If any returned true, then the request was handled.
        return true;
    }
    else if(url.startsWith("file://") | url.startsWith("data:"))
    {
        //This directory on WebKit/Blink based webviews contains SQLite databases!
        //DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
        return url.contains("app_webview");
    }
    else if (appView.getWhitelist().isUrlWhiteListed(url)) {
        // Allow internal navigation
        return false;
    }
    else if (appView.getExternalWhitelist().isUrlWhiteListed(url))
    {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setComponent(null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                intent.setSelector(null);
            }
            this.cordova.getActivity().startActivity(intent);
            return true;
        } catch (android.content.ActivityNotFoundException e) {
            LOG.e(TAG, "Error loading url " + url, e);
        }
    }
    // Intercept the request and do nothing with it -- block it
    return true;
}
 
Example 6
Project: lurkerhn   File: StoryWebViewActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story_webview);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final Item item = (Item) getIntent().getSerializableExtra("item");

    WebView webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    setContentView(webView);
    webView.loadUrl(item.getUrl());
}
 
Example 7
Project: LoRaWAN-Smart-Parking   File: CordovaUriHelper.java   Source Code and License 6 votes vote down vote up
/**
 * Give the host application a chance to take over the control when a new url
 * is about to be loaded in the current WebView.
 *
 * @param view          The WebView that is initiating the callback.
 * @param url           The url to be loaded.
 * @return              true to override, false for default behavior
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
boolean shouldOverrideUrlLoading(WebView view, String url) {
    // Give plugins the chance to handle the url
    if (this.appView.pluginManager.onOverrideUrlLoading(url)) {
        // Do nothing other than what the plugins wanted.
        // If any returned true, then the request was handled.
        return true;
    }
    else if(url.startsWith("file://") | url.startsWith("data:"))
    {
        //This directory on WebKit/Blink based webviews contains SQLite databases!
        //DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
        return url.contains("app_webview");
    }
    else if (appView.getWhitelist().isUrlWhiteListed(url)) {
        // Allow internal navigation
        return false;
    }
    else if (appView.getExternalWhitelist().isUrlWhiteListed(url))
    {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setComponent(null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                intent.setSelector(null);
            }
            this.cordova.getActivity().startActivity(intent);
            return true;
        } catch (android.content.ActivityNotFoundException e) {
            LOG.e(TAG, "Error loading url " + url, e);
        }
    }
    // Intercept the request and do nothing with it -- block it
    return true;
}
 
Example 8
Project: hybrid-jsbridge-simple   File: JSBridge.java   Source Code and License 6 votes vote down vote up
/**
 * 获取框架api类中所有符合要求的api
 *
 * @param injectedCls
 * @return
 * @throws Exception
 */
private static HashMap<String, Method> getAllMethod(Class injectedCls) throws Exception {
    HashMap<String, Method> mMethodsMap = new HashMap<>();
    Method[] methods = injectedCls.getDeclaredMethods();
    for (Method method : methods) {
        String name;
        if (method.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC) || (name = method.getName()) == null) {
            continue;
        }
        Class[] parameters = method.getParameterTypes();
        if (null != parameters && parameters.length == 4) {
            if (parameters[1] == WebView.class && parameters[2] == JSONObject.class && parameters[3] == Callback.class) {
                mMethodsMap.put(name, method);
            }
        }
    }
    return mMethodsMap;
}
 
Example 9
Project: LoRaWAN-Smart-Parking   File: CordovaWebViewClient.java   Source Code and License 6 votes vote down vote up
/**
 * Notify the host application that a page has started loading.
 * This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted
 * one time for the main frame. This also means that onPageStarted will not be called when the contents of an
 * embedded frame changes, i.e. clicking a link whose target is an iframe.
 *
 * @param view          The webview initiating the callback.
 * @param url           The url of the page.
 */
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    isCurrentlyLoading = true;
    LOG.d(TAG, "onPageStarted(" + url + ")");
    // Flush stale messages.
    this.appView.bridge.reset(url);

    // Broadcast message that page has loaded
    this.appView.postMessage("onPageStarted", url);

    // Notify all plugins of the navigation, so they can clean up if necessary.
    if (this.appView.pluginManager != null) {
        this.appView.pluginManager.onReset();
    }
}
 
Example 10
Project: SmoothRefreshLayout   File: ScrollCompat.java   Source Code and License 6 votes vote down vote up
public static void flingCompat(View view, int velocityY) {
    if (view instanceof ScrollView) {
        ((ScrollView) view).fling(velocityY);
    } else if (view instanceof WebView) {
        ((WebView) view).flingScroll(0, velocityY);
    } else if (view instanceof RecyclerView) {
        ((RecyclerView) view).fling(0, velocityY);
    } else if (view instanceof NestedScrollView) {
        ((NestedScrollView) view).fling(velocityY);
    } else if (view instanceof AbsListView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ((AbsListView) view).fling(velocityY);
        } else {
            SRReflectUtil.compatOlderAbsListViewFling((AbsListView) view, velocityY);
        }
    }
}
 
Example 11
Project: sa-android   File: AnnouncementsArticleActivity.java   Source Code and License 6 votes vote down vote up
private void fetchArticleBody() {
    setBusy(true);
    AnnouncementModels.fetchArticleBody(articleID, new ModelListener<String>() {
        @Override
        public void onData(String result, String message) {
            setBusy(false);
            if (result == null) {
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            } else {
                WebView wb = (WebView) findViewById(R.id.webViewforArticle);
                wb.loadData(result, "text/html;charset=utf-8", null);
                wb.getSettings().setLoadWithOverviewMode(true);
                wb.getSettings().setUseWideViewPort(true);
            }
        }
    });
}
 
Example 12
Project: guanggoo-android   File: TopicDetailFragment.java   Source Code and License 6 votes vote down vote up
private void initWebView() {
    mContentWebView.getSettings().setUseWideViewPort(false);
    mContentWebView.getSettings().setLoadWithOverviewMode(true);
    mContentWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
    mContentWebView.setWebChromeClient(new WebChromeClient());
    mContentWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            FragmentFactory.PageType pageType = FragmentFactory.getPageTypeByUrl(url);
            if (mListener != null && pageType == FragmentFactory.PageType.VIEW_IMAGE) {
                mListener.openPage(url, getString(R.string.view_image));
                return true;
            }

            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        }
    });
    mContentWebView.getSettings().setJavaScriptEnabled(true);
}
 
Example 13
Project: keemob   File: SystemWebViewClient.java   Source Code and License 6 votes vote down vote up
/**
 * On received client cert request.
 * The method forwards the request to any running plugins before using the default implementation.
 *
 * @param view
 * @param request
 */
@Override
@TargetApi(21)
public void onReceivedClientCertRequest (WebView view, ClientCertRequest request)
{

    // Check if there is some plugin which can resolve this certificate request
    PluginManager pluginManager = this.parentEngine.pluginManager;
    if (pluginManager != null && pluginManager.onReceivedClientCertRequest(null, new CordovaClientCertRequest(request))) {
        parentEngine.client.clearLoadTimeoutTimer();
        return;
    }

    // By default pass to WebViewClient
    super.onReceivedClientCertRequest(view, request);
}
 
Example 14
Project: iosched-reader   File: AboutUtils.java   Source Code and License 6 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.loadUrl("file:///android_asset/licenses.html");

    return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.about_licenses)
            .setView(webView)
            .setPositiveButton(R.string.ok,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }
            )
            .create();
}
 
Example 15
Project: AgentWeb   File: AgentWebView.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
    Log.i(TAG,"onJsPrompt:"+url+"  message:"+message+"  d:"+defaultValue+"  ");
    if (mJsCallJavas != null && JsCallJava.isSafeWebViewCallMsg(message)) {
        JSONObject jsonObject = JsCallJava.getMsgJSONObject(message);
        String interfacedName = JsCallJava.getInterfacedName(jsonObject);
        if (interfacedName != null) {
            JsCallJava jsCallJava = mJsCallJavas.get(interfacedName);
            if (jsCallJava != null) {
                result.confirm(jsCallJava.call(view, jsonObject));
            }
        }
        return true;
    } else {
        return false;
    }

}
 
Example 16
Project: buildAPKsApps   File: AboutActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Called when the activity is first created. Set the web view layout and
 * get the title and file to be displayed.
 * 
 * @param savedInstanceState
 *            Is used to save the state of the created Activity.
 * 
 * @author Yuriy Stanchev
 * 
 * @email [email protected]
 * 
 * @date 11 Mar 2012
 */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	Intent intent = getIntent();
	Bundle extras = intent.getExtras();

	String title = (String) extras.get("title");
	String file = (String) extras.get("file");

	setContentView(R.layout.about);

	setTitle(title);

	WebView view = (WebView) findViewById(R.id.web);

	view.setFocusable(true);
	view.setFocusableInTouchMode(true);
	view.requestFocus();
	view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
	view.loadUrl(file);

}
 
Example 17
Project: siiMobilityAppKit   File: SystemWebViewClient.java   Source Code and License 6 votes vote down vote up
/**
 * On received client cert request.
 * The method forwards the request to any running plugins before using the default implementation.
 *
 * @param view
 * @param request
 */
@Override
@TargetApi(21)
public void onReceivedClientCertRequest (WebView view, ClientCertRequest request)
{

    // Check if there is some plugin which can resolve this certificate request
    PluginManager pluginManager = this.parentEngine.pluginManager;
    if (pluginManager != null && pluginManager.onReceivedClientCertRequest(null, new CordovaClientCertRequest(request))) {
        parentEngine.client.clearLoadTimeoutTimer();
        return;
    }

    // By default pass to WebViewClient
    super.onReceivedClientCertRequest(view, request);
}
 
Example 18
Project: LuaViewPlayground   File: UDWebView.java   Source Code and License 5 votes vote down vote up
/**
 * Get the tile of web page
 * @return
 */
public String title() {
    WebView view = null;
    if (this.getView() != null && (view = this.getView().getWebView()) != null) {
        return view.getTitle();
    }

    return "";
}
 
Example 19
Project: cordova-plugin-themeablebrowser-diy   File: ThemeableBrowser.java   Source Code and License 5 votes vote down vote up
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);

        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
    }
}
 
Example 20
Project: YFHR_Android_App   File: contactUs.java   Source Code and License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view= inflater.inflate(R.layout.fragment_contact_us, container, false);
    web=(WebView)view.findViewById(R.id.web_View);
    WebSettings webs =web.getSettings();
    webs.setJavaScriptEnabled(true);
    web.loadUrl(myUrl);

    web.setWebViewClient(new myWebViewClient());

    return view;
}
 
Example 21
Project: COB   File: SystemWebViewClient.java   Source Code and License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
Example 22
Project: LuaViewPlayground   File: UDWebView.java   Source Code and License 5 votes vote down vote up
/**
 * Loads the given URL.
 * @param url
 * @return
 */
public UDWebView loadUrl(String url) {
    if (!TextUtils.isEmpty(url)) {
        WebView view = null;
        if (this.getView() != null && (view = this.getView().getWebView()) != null) {
            view.loadUrl(url);
        }
    }

    return this;
}
 
Example 23
Project: studydemo   File: WebViewActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void onProgressChanged(WebView view, int newProgress) {
    if(newProgress == 100){
        mProgressBar.setVisibility(View.GONE);
    }
    super.onProgressChanged(view, newProgress);
}
 
Example 24
Project: MakiLite   File: MessagesTouchActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
	WebView.HitTestResult result = webView.getHitTestResult();
	if (result != null) {
		int type = result.getType();

		if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
			showLongPressedImageMenu(menu, result.getExtra());
		}
	}
}
 
Example 25
Project: AgentWeb   File: SmartRefreshWebLayout.java   Source Code and License 5 votes vote down vote up
public SmartRefreshWebLayout(Activity activity){

        View mView=activity.getLayoutInflater().inflate(R.layout.fragment_srl_web,null);
        View smarkView = mView.findViewById(R.id.smarkLayout);
        mSmartRefreshLayout = (SmartRefreshLayout) smarkView;
        mWebView = (WebView) mSmartRefreshLayout.findViewById(R.id.webView);

    }
 
Example 26
Project: NullAway   File: NullAwayNativeModels.java   Source Code and License 5 votes vote down vote up
static void androidStuff() {
  android.webkit.WebView webView = new WebView();
  // BUG: Diagnostic contains: dereferenced expression
  webView.getUrl().toString();
  String s = null;
  if (!android.text.TextUtils.isEmpty(s)) {
    // no warning due to isEmpty check
    s.hashCode();
  }
}
 
Example 27
Project: diycode   File: GcsMarkdownViewClient.java   Source Code and License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
    String url = request.getUrl().toString();
    WebResourceResponse response = getWebResourceResponse(url);
    if (response != null) return response;
    return super.shouldInterceptRequest(view, request);
}
 
Example 28
Project: localcloud_fe   File: SystemCookieManager.java   Source Code and License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SystemCookieManager(WebView webview) {
    webView = webview;
    cookieManager = CookieManager.getInstance();

    //REALLY? Nobody has seen this UNTIL NOW?
    cookieManager.setAcceptFileSchemeCookies(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.setAcceptThirdPartyCookies(webView, true);
    }
}
 
Example 29
Project: BackTube   File: PlayerService.java   Source Code and License 5 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled"})
@Override
public void onCreate() {
    super.onCreate();

    mWebView = new WebView(this);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    mWebView.getSettings().setJavaScriptEnabled(true);
    {
        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

        mHideParams = newLayoutParams(1);

        final DisplayMetrics metrics = getResources().getDisplayMetrics();
        final int min = Math.min(metrics.heightPixels, metrics.widthPixels);

        mPlayerSize = (int) (min / metrics.density);

        mParams = newLayoutParams(min);
        mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
        mParams.y = getTopY(metrics);
    }
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ServiceAction.STOP);
    filter.addAction(ServiceAction.SHOW);
    filter.addAction(ServiceAction.HIDE);

    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver = newBroadcastReceiver(), filter);
}
 
Example 30
Project: siiMobilityAppKit   File: InAppBrowser.java   Source Code and License 5 votes vote down vote up
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    String newloc = "";
    if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
        newloc = url;
    }
    else
    {
        // Assume that everything is HTTP at this point, because if we don't specify,
        // it really should be.  Complain loudly about this!!!
        LOG.e(LOG_TAG, "Possible Uncaught/Unknown URI");
        newloc = "http://" + url;
    }

    // Update the UI if we haven't already
    if (!newloc.equals(edittext.getText().toString())) {
        edittext.setText(newloc);
     }

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_START_EVENT);
        obj.put("url", newloc);
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        LOG.e(LOG_TAG, "URI passed in has caused a JSON error.");
    }
}
 
Example 31
Project: PicShow-zhaipin   File: H5PayDemoActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
	if (!(url.startsWith("http") || url.startsWith("https"))) {
		return true;
	}

	final PayTask task = new PayTask(H5PayDemoActivity.this);
	final String ex = task.fetchOrderInfoFromH5PayUrl(url);
	if (!TextUtils.isEmpty(ex)) {
		System.out.println("paytask:::::" + url);
		new Thread(new Runnable() {
			public void run() {
				System.out.println("payTask:::" + ex);
				final H5PayResultModel result = task.h5Pay(ex, true);
				if (!TextUtils.isEmpty(result.getReturnUrl())) {
					H5PayDemoActivity.this.runOnUiThread(new Runnable() {
						
						@Override
						public void run() {
							view.loadUrl(result.getReturnUrl());
						}
					});
				}
			}
		}).start();
	} else {
		view.loadUrl(url);
	}
	return true;
}
 
Example 32
Project: popup-bridge-android   File: PopupBridgeTest.java   Source Code and License 5 votes vote down vote up
@Test
@SuppressLint("JavascriptInterface")
public void newInstance_addsJavascriptInterfaceToWebView() {
    WebView webView = mock(WebView.class);
    when(webView.getSettings()).thenReturn(mock(WebSettings.class));
    PopupBridge popupBridge = PopupBridge.newInstance(mActivity, webView);

    verify(webView).addJavascriptInterface(eq(popupBridge), eq("popupBridge"));
}
 
Example 33
Project: siiMobilityAppKit   File: InAppBrowser.java   Source Code and License 5 votes vote down vote up
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);

        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        LOG.d(LOG_TAG, "Should never happen");
    }
}
 
Example 34
Project: alerta-fraude   File: SystemWebViewEngine.java   Source Code and License 5 votes vote down vote up
private static void exposeJsInterface(WebView webView, CordovaBridge bridge) {
    if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)) {
        LOG.i(TAG, "Disabled addJavascriptInterface() bridge since Android version is old.");
        // Bug being that Java Strings do not get converted to JS strings automatically.
        // This isn't hard to work-around on the JS side, but it's easier to just
        // use the prompt bridge instead.
        return;
    }
    SystemExposedJsApi exposedJsApi = new SystemExposedJsApi(bridge);
    webView.addJavascriptInterface(exposedJsApi, "_cordovaNative");
}
 
Example 35
Project: boohee_v5.6   File: AuthActivity.java   Source Code and License 5 votes vote down vote up
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        try {
            this.d = extras.getString(b);
            String string = extras.getString("params");
            if (i.b(string)) {
                Method method;
                super.requestWindowFeature(1);
                this.f = new Handler(getMainLooper());
                View linearLayout = new LinearLayout(getApplicationContext());
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
                linearLayout.setOrientation(1);
                setContentView(linearLayout, layoutParams);
                this.c = new WebView(getApplicationContext());
                layoutParams.weight = 1.0f;
                this.c.setVisibility(0);
                linearLayout.addView(this.c, layoutParams);
                WebSettings settings = this.c.getSettings();
                settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
                settings.setRenderPriority(RenderPriority.HIGH);
                settings.setSupportMultipleWindows(true);
                settings.setJavaScriptEnabled(true);
                settings.setSavePassword(false);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
                settings.setAllowFileAccess(false);
                settings.setTextSize(TextSize.NORMAL);
                this.c.setVerticalScrollbarOverlay(true);
                this.c.setWebViewClient(new b());
                this.c.setWebChromeClient(new a());
                this.c.setDownloadListener(new a(this));
                this.c.loadUrl(string);
                if (VERSION.SDK_INT >= 7) {
                    try {
                        method = this.c.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                        if (method != null) {
                            method.invoke(this.c.getSettings(), new Object[]{Boolean.valueOf(true)});
                        }
                    } catch (Exception e) {
                    }
                }
                try {
                    method = this.c.getClass().getMethod("removeJavascriptInterface", new Class[0]);
                    if (method != null) {
                        method.invoke(this.c, new Object[]{"searchBoxJavaBridge_"});
                        method.invoke(this.c, new Object[]{"accessibility"});
                        method.invoke(this.c, new Object[]{"accessibilityTraversal"});
                        return;
                    }
                    return;
                } catch (Exception e2) {
                    return;
                }
            }
            finish();
        } catch (Exception e3) {
            finish();
        }
    } catch (Exception e4) {
        finish();
    }
}
 
Example 36
Project: letv   File: HongKongLoginWebview.java   Source Code and License 5 votes vote down vote up
public void onProgressChanged(WebView view, int newProgress) {
    super.onProgressChanged(view, newProgress);
    if (HongKongLoginWebview.this.progressBar.getVisibility() != 0) {
        HongKongLoginWebview.this.progressBar.setVisibility(0);
    }
    HongKongLoginWebview.this.progressBar.setProgress(newProgress);
    if (newProgress == 100) {
        HongKongLoginWebview.this.progressBar.setVisibility(8);
    }
}
 
Example 37
Project: mupdf-android-viewer-old   File: PrintDialogActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
	if (url.startsWith(ZXING_URL)) {
		Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
		intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
		try {
			startActivityForResult(intentScan, ZXING_SCAN_REQUEST);
		} catch (ActivityNotFoundException error) {
			view.loadUrl(url);
		}
	} else {
		view.loadUrl(url);
	}
	return false;
}
 
Example 38
Project: AgentWeb   File: WebChromeClientWrapper.java   Source Code and License 5 votes vote down vote up
public void onReceivedTouchIconUrl(WebView view, String url,
                                   boolean precomposed) {
    if (this.mRealWebChromeClient != null){
        this.mRealWebChromeClient.onReceivedTouchIconUrl(view, url, precomposed);
        return ;
    }
    super.onReceivedTouchIconUrl(view,url,precomposed);
}
 
Example 39
Project: CSipSimple   File: Faq.java   Source Code and License 5 votes vote down vote up
@Override
public void onPageFinished(final WebView view, String url) {
	super.onPageFinished(view, url);
	LinearLayout indicator = (LinearLayout) parentView.findViewById(R.id.loading_indicator);
	indicator.setVisibility(View.GONE);
	// Googlecode collapse side bar
	//view.loadUrl("javascript:$('wikisidebar').setAttribute('class', 'vt collapse');");
}
 
Example 40
Project: GracefulMovies   File: WebActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void onProgressChanged(WebView view, int newProgress) {
    super.onProgressChanged(view, newProgress);
    if (newProgress == 100) {
        mProgressBar.setVisibility(View.GONE);
    } else {
        if (mProgressBar.getVisibility() != View.VISIBLE)
            mProgressBar.setVisibility(View.VISIBLE);
        mProgressBar.setProgress(newProgress);
    }
}
 
Example 41
Project: Auto.js   File: EWebView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file://")) {
        view.loadUrl(url);
    } else {
        try {
            getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example 42
Project: boohee_v5.6   File: j.java   Source Code and License 5 votes vote down vote up
public void onReceivedError(WebView webView, int i, String str, String str2) {
    Log.e(j.a, "onReceivedError: " + str2 + "\nerrCode: " + i + " description:" + str);
    if (this.b.e.getVisibility() == 0) {
        this.b.e.setVisibility(8);
    }
    super.onReceivedError(webView, i, str, str2);
    SocializeUtils.safeCloseDialog(this.b);
}
 
Example 43
Project: TaipeiTechRefined   File: DonateActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_donate);
    mToolbar = (Toolbar) findViewById(R.id.main_toolbar);
    setSupportActionBar(mToolbar);
    setActionBar();
    WebView webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(new WebViewClient());
    webview.loadUrl("file:///android_asset/donate.html");
    CookieManager.getInstance().setAcceptCookie(true);
    Toast.makeText(this, R.string.web_back_hint, Toast.LENGTH_LONG).show();
}
 
Example 44
Project: Auto.js   File: CodeMirrorEditor.java   Source Code and License 5 votes vote down vote up
private void setupWebView() {
    mWebView = new WebView(getContext()) {
        @Override
        public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
            InputConnection connection = super.onCreateInputConnection(outAttrs);
            return connection == null ? null : new MyInputConnection(connection);
        }
    };
    setupWebSettings();
    mWebView.addJavascriptInterface(mJavaScriptBridge, "__bridge__");
    addView(mWebView);
}
 
Example 45
Project: letv   File: LetvOpenIDOAuthLoginActivity.java   Source Code and License 5 votes vote down vote up
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    if (LetvOpenIDOAuthLoginActivity.this.baseUrl.contains(LetvUtils.WEB_INNER_FLAG) || !LetvConfig.getPcode().equals("010110016")) {
        handler.proceed();
    } else {
        handler.cancel();
    }
}
 
Example 46
Project: QRScanner   File: BaseWebActivity.java   Source Code and License 5 votes vote down vote up
public void onWebViewReceivedError(WebView view, int errorCode, CharSequence description, String failingUrl) {
    Log.i("0000", "errorCode:   " + errorCode);
    switch (errorCode) {
        case WebViewClient.ERROR_CONNECT:
        case WebViewClient.ERROR_TIMEOUT:
        case WebViewClient.ERROR_HOST_LOOKUP:
        case WebViewClient.ERROR_BAD_URL:
            showErrorHint(failingUrl);
            break;
    }
}
 
Example 47
Project: markor   File: ShareUtilBase.java   Source Code and License 5 votes vote down vote up
@Nullable
public static Bitmap getBitmapFromWebView(WebView webView) {
    try {
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

        //Measure WebView's content
        webView.measure(widthMeasureSpec, heightMeasureSpec);
        webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());

        //Build drawing cache and store its size
        webView.buildDrawingCache();

        int measuredWidth = webView.getMeasuredWidth();
        int measuredHeight = webView.getMeasuredHeight();

        //Creates the bitmap and draw WebView's content on in
        Bitmap bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);

        Paint paint = new Paint();

        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(bitmap, 0, bitmap.getHeight(), paint);

        webView.draw(canvas);
        webView.destroyDrawingCache();

        return bitmap;
    } catch (Exception | OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 48
Project: android-perftracking   File: WebViewClientBase.java   Source Code and License 5 votes vote down vote up
public void onPageFinished(WebView view, String url) {
  Tracker.prolongMetric();
  if (com_rakuten_tech_mobile_perf_page_trackingId != 0) {
    Tracker.endUrl(com_rakuten_tech_mobile_perf_page_trackingId);
    com_rakuten_tech_mobile_perf_page_trackingId = 0;
  }
  super.onPageFinished(view, url);
}
 
Example 49
Project: add_to_evernote_note   File: EvernoteOAuthActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Uri uri = Uri.parse(url);
    if (EvernoteOAuthHelper.CALLBACK_SCHEME.equals(uri.getScheme())) {
        ((EvernoteOAuthActivity) getActivity()).setResultUri(url);
        getActivity().finish();
        return true;
    }

    return super.shouldOverrideUrlLoading(view, url);
}
 
Example 50
Project: wirtualnaApteczka   File: WebViewActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);

    String urlLink = getIntent().getStringExtra(AppConstants.URL_LINK);

    webView = (WebView) findViewById(R.id.web_view);
    webView.getSettings().setJavaScriptEnabled(true);

    if (!TextUtils.isEmpty(urlLink))
        webView.loadUrl(urlLink);
}
 
Example 51
Project: IdealMedia   File: TwitterShare.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.dialog_twitter_share);

    close = findViewById(R.id.close_button);

    WebView mWebView = (WebView) findViewById(R.id.webWiew);
    mWebView.getSettings().setJavaScriptEnabled(true);

    mWebView.loadUrl(shareURL);
    mWebView.setWebViewClient(new ThisWebViewClient());

    mWebView.setPictureListener(new WebView.PictureListener() {
        @Override
        public void onNewPicture(WebView view, Picture picture) {
            if (progress != null && progress.isShowing()) {
                progress.dismiss();
            }
        }
    });

    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            TwitterShare.this.cancel();
        }
    });
}
 
Example 52
Project: GitHub   File: SwipeBackLayout.java   Source Code and License 5 votes vote down vote up
/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup
 */
private void findScrollView(ViewGroup viewGroup) {
    scrollChild = viewGroup;
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        View child;
        for (int i = 0; i < count; i++) {
            child = viewGroup.getChildAt(i);
            if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager || child instanceof WebView) {
                scrollChild = child;
                return;
            }
        }
    }
}
 
Example 53
Project: TubiPlayer   File: DoubleViewTubiPlayerActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void initLayout() {
    setContentView(R.layout.activity_double_tubi_player);

    mTubiPlayerView = (TubiExoPlayerView) findViewById(R.id.tubitv_player);
    vpaidWebView = (WebView) findViewById(R.id.vpaid_webview);
    vpaidWebView.setBackgroundColor(Color.BLACK);

    mTubiPlayerView.requestFocus();
    mTubiPlayerView.setActivity(this);
}
 
Example 54
Project: letv   File: AuthDialog.java   Source Code and License 5 votes vote down vote up
public void onReceivedError(WebView webView, int i, String str, String str2) {
    super.onReceivedError(webView, i, str, str2);
    f.c(AuthDialog.a, "-->onReceivedError, errorCode: " + i + " | description: " + str);
    if (!Util.checkNetWork(this.a.l)) {
        this.a.c.onError(new UiError(9001, "当前网络不可用,请稍后重试!", str2));
        this.a.dismiss();
    } else if (this.a.p.startsWith(ServerSetting.DOWNLOAD_QQ_URL)) {
        this.a.c.onError(new UiError(i, str, str2));
        this.a.dismiss();
    } else {
        long elapsedRealtime = SystemClock.elapsedRealtime() - this.a.r;
        if (this.a.o >= 1 || elapsedRealtime >= this.a.s) {
            this.a.k.loadUrl(this.a.b());
            return;
        }
        this.a.o = this.a.o + 1;
        this.a.e.postDelayed(new Runnable(this) {
            final /* synthetic */ LoginWebViewClient a;

            {
                this.a = r1;
            }

            public void run() {
                this.a.a.k.loadUrl(this.a.a.p);
            }
        }, 500);
    }
}
 
Example 55
Project: GitHub   File: MDRootLayout.java   Source Code and License 5 votes vote down vote up
private void invalidateDividersForWebView(WebView view, final boolean setForTop, boolean setForBottom, boolean hasButtons) {
    if (setForTop) {
        drawTopDivider = titleBar != null &&
                titleBar.getVisibility() != View.GONE &&
                //Not scrolled to the top.
                view.getScrollY() + view.getPaddingTop() > 0;
    }
    if (setForBottom) {
        //noinspection deprecation
        drawBottomDivider = hasButtons &&
                view.getScrollY() + view.getMeasuredHeight() - view.getPaddingBottom() < view.getContentHeight() * view.getScale();
    }
}
 
Example 56
Project: letv   File: MobclickAgentJSInterface.java   Source Code and License 4 votes vote down vote up
public void onReceivedIcon(WebView webView, Bitmap bitmap) {
    this.a.onReceivedIcon(webView, bitmap);
}
 
Example 57
Project: cordova-plugin-themeablebrowser-diy   File: ThemeableBrowser.java   Source Code and License 4 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // The JS protects against multiple calls, so this should happen only when
            // closeDialog() is called by other native code.
            if (inAppWebView == null) {
                emitWarning(WRN_UNEXPECTED, "Close called but already closed.");
                return;
            }

            inAppWebView.setWebViewClient(new WebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(WebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }

                    // Clean up.
                    dialog = null;
                    inAppWebView = null;
                    edittext = null;
                    callbackContext = null;
                }
            });

            // NB: From SDK 19: "If you call methods on WebView from any
            // thread other than your app's UI thread, it can cause
            // unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            inAppWebView.loadUrl("about:blank");

            try {
                JSONObject obj = new JSONObject();
                obj.put("type", EXIT_EVENT);
                sendUpdate(obj, false);
            } catch (JSONException ex) {
            }
        }
    });
}
 
Example 58
Project: Android-SmartWebView   File: MainActivity.java   Source Code and License 4 votes vote down vote up
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    get_location();
}
 
Example 59
Project: Android-Development   File: OAuthCallbackWebViewClient.java   Source Code and License 4 votes vote down vote up
@TargetApi(23)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
{
	onError(null);
}
 
Example 60
Project: letv   File: b.java   Source Code and License 4 votes vote down vote up
public static void showTitleBar(WebView webView) {
    if (mWebViewHelper != null) {
        mWebViewHelper.b();
    }
}