Java Code Examples for android.webkit.WebView#requestFocus()

The following examples show how to use android.webkit.WebView#requestFocus() . 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: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 6 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
Source File: WebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 3
Source File: JSWebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);

    mInjectJS = new InjectJS(mWebView);

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 4
Source File: GSIDWebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);

    mInjectJS = new InjectJS(mWebView);

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 5
Source File: WebViewActivity.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_web_view);
  mWebView = (WebView) findViewById(R.id.web_view);
  mWebView.getSettings().setJavaScriptEnabled(true);
  mWebView.loadUrl(urlFromIntent(getIntent()));
  mWebView.requestFocus();
  mWebView.setWebViewClient(
      new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
          return false;
        }
      });
}
 
Example 6
Source File: WebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 7
Source File: JSWebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);

    mInjectJS = new InjectJS(mWebView);

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 8
Source File: GSIDWebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);

    mInjectJS = new InjectJS(mWebView);

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 9
Source File: WeiboDialog.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void initWebView()
{
    mWebViewContainer = new RelativeLayout(getContext());
    mWebView = new WebView(getContext());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setSavePassword(false);
    mWebView.setWebViewClient(new WeiboWebViewClient(null));
    mWebView.requestFocus();
    mWebView.setScrollBarStyle(0);
    mWebView.setVisibility(4);
    NetworkHelper.clearCookies(mContext, mAuthUrl);
    mWebView.loadUrl(mAuthUrl);
    android.widget.RelativeLayout.LayoutParams layoutparams = new android.widget.RelativeLayout.LayoutParams(-1, -1);
    android.widget.RelativeLayout.LayoutParams layoutparams1 = new android.widget.RelativeLayout.LayoutParams(-1, -1);
    DisplayMetrics displaymetrics = getContext().getResources().getDisplayMetrics();
    int i = (int)(10F * displaymetrics.density);
    layoutparams1.setMargins(i, i, i, i);
    Drawable drawable = ResourceManager.getNinePatchDrawable(mContext, 1);
    mWebViewContainer.setBackgroundDrawable(drawable);
    mWebViewContainer.addView(mWebView, layoutparams1);
    mWebViewContainer.setGravity(17);
    int j = 1 + ResourceManager.getDrawable(mContext, 2).getIntrinsicWidth() / 2;
    layoutparams.setMargins(j, (int)(25F * displaymetrics.density), j, j);
    mRootContainer.addView(mWebViewContainer, layoutparams);
}
 
Example 10
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 6 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 11
Source File: MainActivity.java    From AddressToGPS with MIT License 5 votes vote down vote up
void startWebView(){
    webView = (WebView) findViewById(R.id.webView);
    JavaScriptInterface jsInterface = new JavaScriptInterface(this);
    webView.getSettings().setJavaScriptEnabled(true); // enable javascript
    webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36");
    webView.addJavascriptInterface(jsInterface, "JSInterface");
    webView.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
        }
    });
    webView.loadUrl("file:///android_asset/AddressToGPS/index.html");
    webView.requestFocus();
}
 
Example 12
Source File: WebViewActivity.java    From testing-cin with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    mWebView = (WebView) findViewById(R.id.web_view);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(urlFromIntent(getIntent()));
    mWebView.requestFocus();
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
}
 
Example 13
Source File: ArticleViewAdapter.java    From GankMeizhi with Apache License 2.0 5 votes vote down vote up
private void initWebview(WebView webView) {
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webView.getSettings().setAppCacheEnabled(true);

    webView.requestFocus();
    webView.getSettings().getAllowFileAccess();
}
 
Example 14
Source File: WebViewActivity.java    From testing-samples 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_view);
    mWebView = (WebView) findViewById(R.id.web_view);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(urlFromIntent(getIntent()));
    mWebView.requestFocus();
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
}
 
Example 15
Source File: PrefetchService.java    From GankMeizhi with Apache License 2.0 5 votes vote down vote up
@UiThread
private void load(String url) {
    WebView webView = new WebView(this);
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress == 100) {
                Log.d(TAG, "onProgressChanged: " + view.getUrl());
            }
        }
    });
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    String cacheDirPath = getFilesDir().getAbsolutePath() + "/webviewcache";
    webView.getSettings().setDatabasePath(cacheDirPath);
    webView.getSettings().setAppCachePath(cacheDirPath);
    webView.getSettings().setAppCacheEnabled(true);

    webView.requestFocus();
    webView.getSettings().getAllowFileAccess();

    webView.loadUrl(url);
}
 
Example 16
Source File: InAppBrowser.java    From cordova-plugin-inappbrowser with Apache License 2.0 5 votes vote down vote up
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    // Set the namespace for postMessage()
    if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        injectDeferredObject("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}", null);
    }

    // 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 17
Source File: UrgenceActivity.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.urgence);
    id = getIntent().getExtras().getInt("id");
    webView = (WebView) findViewById(R.id.web_view);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    urgence = getResources().getStringArray(R.array.secu_urgence);

    id--;
    getSupportActionBar().setTitle(urgence[id]);
    String url = "";

    switch (id) {
        case 0:
            url = "file:///android_asset/urgence_resum_bombe.html";
            break;
        case 1:
            url = "file:///android_asset/urgence_resum_colis.html";
            break;
        case 2:
            url = "file:///android_asset/urgence_resum_feu.html";
            break;
        case 3:
            url = "file:///android_asset/urgence_resum_odeur.html";
            break;
        case 4:
            url = "file:///android_asset/urgence_resum_pane_asc.html";
            break;
        case 5:
            url = "file:///android_asset/urgence_resum_panne_elec.html";
            break;
        case 6:
            url = "file:///android_asset/urgence_resum_pers_arm.html";
            break;
        case 7:
            url = "file:///android_asset/urgence_resum_medic.html";
            break;
        default:
            break;
    }

    webView.loadUrl(url);

    webView.requestFocus();

    findViewById(R.id.urgence_appel_urgence).setOnClickListener(
            new OnClickListener() {

                @Override
                public void onClick(final View v) {

                    final String uri = "tel:"
                            + getString(R.string.secu_phone_lbl);
                    final Intent intent = new Intent(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse(uri));
                    startActivity(intent);
                }
            });
}
 
Example 18
Source File: ChatWindowView.java    From chat-window-android with MIT License 4 votes vote down vote up
private void initView(Context context) {
    setFitsSystemWindows(true);
    setVisibility(GONE);
    LayoutInflater.from(context).inflate(R.layout.view_chat_window_internal, this, true);
    webView = (WebView) findViewById(R.id.chat_window_web_view);
    statusText = (TextView) findViewById(R.id.chat_window_status_text);
    progressBar = (ProgressBar) findViewById(R.id.chat_window_progress);
    reloadButton = (Button) findViewById(R.id.chat_window_button);
    reloadButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            reload();
        }
    });

    if (Build.VERSION.RELEASE.matches("4\\.4(\\.[12])?")) {
        String userAgentString = webView.getSettings().getUserAgentString();
        webView.getSettings().setUserAgentString(userAgentString + " AndroidNoFilesharing");
    }

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);

    webView.setFocusable(true);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setSupportMultipleWindows(true);
    webSettings.setDomStorageEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    }

    webView.setWebViewClient(new LCWebViewClient());
    webView.setWebChromeClient(new LCWebChromeClient());

    webView.requestFocus(View.FOCUS_DOWN);
    webView.setVisibility(GONE);

    webView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
            }
            return false;
        }
    });
    webView.addJavascriptInterface(new ChatWindowJsInterface(this), ChatWindowJsInterface.BRIDGE_OBJECT_NAME);
}