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: siiMobilityAppKit   File: InAppBrowser.java   View source code 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 2
Project: WebViewInputSample   File: MainActivity.java   View source code 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 3
Project: SmartRefresh   File: RefreshContentWrapper.java   View source code 6 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 4
Project: DailyZhiHu   File: DownloadDetaiContentActivity.java   View source code 6 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 5
Project: LoRaWAN-Smart-Parking   File: CordovaUriHelper.java   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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);
    }
}