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

The following examples show how to use android.webkit.WebView#setFocusable() . 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: FunctionUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
public static void handleContentTV(final WebView contentTV, final MessageArticlePageInfo row, int bgColor, int fgColor, Context context) {
    final WebViewClient client = new WebViewClientEx((FragmentActivity) context);
    contentTV.setBackgroundColor(0);
    contentTV.setFocusableInTouchMode(false);
    contentTV.setFocusable(false);
    contentTV.setLongClickable(false);


    WebSettings setting = contentTV.getSettings();
    setting.setUserAgentString(context.getString(R.string.clientua) + BuildConfig.VERSION_CODE);
    setting.setDefaultFontSize(PhoneConfiguration.getInstance()
            .getWebSize());
    setting.setJavaScriptEnabled(false);
    contentTV.setWebViewClient(client);

    contentTV.setTag(row.getLou());
    contentTV.loadDataWithBaseURL(null, row.getFormated_html_data(),
            "text/html", "utf-8", null);
}
 
Example 2
Source File: GraphView.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
public WebView getView(String html) {
    if (BuildConfig.DEBUG) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    WebView webView = new GraphWebView(mContext);

    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);

    webView.setClickable(true);
    webView.setFocusable(false);
    webView.setFocusableInTouchMode(false);

    settings.setBuiltInZoomControls(mIsFullScreen);
    settings.setSupportZoom(mIsFullScreen);
    settings.setDisplayZoomControls(mIsFullScreen);

    // Improve performance
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    this.myHTML = html;
    webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);
    return webView;
}
 
Example 3
Source File: AboutActivity.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.about);

	String url = DEFAULT_PAGE;

	Intent it = getIntent();
	if ( it != null ){
		Bundle extras = it.getExtras();
		if ( extras !=null ){
			String iturl = extras.getString(EXTRA_URL);
			if ( iturl !=null ){
				url = iturl;
			}
			String ittitle = extras.getString(EXTRA_TITLE);
			if ( ittitle !=null ){
				setTitle( ittitle );
			}
		}else{
		    url = getString(R.string.about_url);
               setTitle( R.string.about_title );
		}
	}

	WebView webview = (WebView)findViewById(R.id.WebView01);
	webview.loadUrl( url );

	mjsobj = new JsCallbackObj();
	webview.addJavascriptInterface(mjsobj, "jscallback");

	webview.getSettings().setJavaScriptEnabled(true);
	webview.setFocusable(true);
	webview.setFocusableInTouchMode(true);
}
 
Example 4
Source File: AboutActivity.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.about);

	String url = DEFAULT_PAGE;

	Intent it = getIntent();
	if ( it != null ){
		Bundle extras = it.getExtras();
		if ( extras !=null ){
			String iturl = extras.getString(EXTRA_URL);
			if ( iturl !=null ){
				url = iturl;
			}
			String ittitle = extras.getString(EXTRA_TITLE);
			if ( ittitle !=null ){
				setTitle( ittitle );
			}
		}else{
		    url = getString(R.string.about_url);
               setTitle( R.string.about_title );
		}
	}

	WebView webview = (WebView)findViewById(R.id.WebView01);
	webview.loadUrl( url );

	mjsobj = new JsCallbackObj();
	webview.addJavascriptInterface(mjsobj, "jscallback");

	webview.getSettings().setJavaScriptEnabled(true);
	webview.setFocusable(true);
	webview.setFocusableInTouchMode(true);
}
 
Example 5
Source File: WebInitCompat.java    From Android_Skin_2.0 with Apache License 2.0 5 votes vote down vote up
@Override
public void setDefaultAttr(WebView view) {
	// 去除滚动条白色背景,必须在代码里面添加才有效
	view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
	view.setScrollbarFadingEnabled(true);
	view.setDrawingCacheEnabled(true);
	view.setLongClickable(true);
	view.setBackgroundResource(android.R.color.transparent);
	view.setBackgroundColor(Color.TRANSPARENT);
	view.getBackground().setAlpha(0);
	view.setFocusable(true);
	view.setFocusableInTouchMode(true);
}
 
Example 6
Source File: WebDialog.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext().getApplicationContext()) {
        /* Prevent NPE on Motorola 2.2 devices
         * See https://groups.google.com/forum/?fromgroups=#!topic/android-developers/ktbwY2gtLKQ
         */
        @Override
        public void onWindowFocusChanged(boolean hasWindowFocus) {
            try {
                super.onWindowFocusChanged(hasWindowFocus);
            } catch (NullPointerException e) {
            }
        }
    };
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);
    webView.getSettings().setSaveFormData(false);
    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
    webView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (!v.hasFocus())
            {
                v.requestFocus();
            }
            return false;
        }
    });

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(BACKGROUND_GRAY);
    contentFrameLayout.addView(webViewContainer);
}
 
Example 7
Source File: WebViewer.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new WebViewer component.
 *
 * @param container  container the component will be placed in
 */
public WebViewer(ComponentContainer container) {
  super(container);

  webview = new WebView(container.$context());
  resetWebViewClient();       // Set up the web view client
  webview.getSettings().setJavaScriptEnabled(true);
  webview.setFocusable(true);
  // adds a way to send strings to the javascript
  wvInterface = new WebViewInterface();
  webview.addJavascriptInterface(wvInterface, "AppInventor");
  // enable pinch zooming and zoom controls
  webview.getSettings().setBuiltInZoomControls(true);

  if (SdkLevel.getLevel() >= SdkLevel.LEVEL_ECLAIR)
    EclairUtil.setupWebViewGeoLoc(this, webview, container.$context());

  container.$add(this);

  webview.setOnTouchListener(new View.OnTouchListener() {
    @Override
    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;
    }
  });

  // set the initial default properties.  Height and Width
  // will be fill-parent, which will be the default for the web viewer.

  HomeUrl("");
  Width(LENGTH_FILL_PARENT);
  Height(LENGTH_FILL_PARENT);
}
 
Example 8
Source File: LightningView.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) {
    BrowserApp.getAppComponent().inject(this);
    mActivity = activity;
    mUIController = (UIController) activity;
    mWebView = new WebView(activity);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.setId(View.generateViewId());
    }
    mIsIncognitoTab = isIncognito;
    mTitle = new LightningViewTitle(activity);

    sMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();

    mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
    mWebView.setFocusableInTouchMode(true);
    mWebView.setFocusable(true);
    mWebView.setDrawingCacheEnabled(false);
    mWebView.setWillNotCacheDrawing(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        mWebView.setAnimationCacheEnabled(false);
        //noinspection deprecation
        mWebView.setAlwaysDrawnWithCacheEnabled(false);
    }
    mWebView.setBackgroundColor(Color.WHITE);

    mWebView.setScrollbarFadingEnabled(true);
    mWebView.setSaveEnabled(true);
    mWebView.setNetworkAvailable(true);
    mWebView.setWebChromeClient(new LightningChromeClient(activity, this));
    mWebView.setWebViewClient(new LightningWebClient(activity, this));
    mWebView.setDownloadListener(new LightningDownloadListener(activity));
    mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
    mWebView.setOnTouchListener(new TouchListener());
    sDefaultUserAgent = mWebView.getSettings().getUserAgentString();
    initializeSettings();
    initializePreferences(activity);

    if (url != null) {
        if (!url.trim().isEmpty()) {
            mWebView.loadUrl(url, mRequestHeaders);
        } else {
            // don't load anything, the user is looking for a blank tab
        }
    } else {
        loadHomepage();
    }
}
 
Example 9
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);
}
 
Example 10
Source File: LightningView.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) {
    BrowserApp.getAppComponent().inject(this);
    mActivity = activity;
    mUIController = (UIController) activity;
    mWebView = new WebView(activity);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.setId(View.generateViewId());
    }
    mIsIncognitoTab = isIncognito;
    mTitle = new LightningViewTitle(activity);

    sMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();

    mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
    mWebView.setFocusableInTouchMode(true);
    mWebView.setFocusable(true);
    mWebView.setDrawingCacheEnabled(false);
    mWebView.setWillNotCacheDrawing(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        mWebView.setAnimationCacheEnabled(false);
        //noinspection deprecation
        mWebView.setAlwaysDrawnWithCacheEnabled(false);
    }
    mWebView.setBackgroundColor(Color.WHITE);

    mWebView.setScrollbarFadingEnabled(true);
    mWebView.setSaveEnabled(true);
    mWebView.setNetworkAvailable(true);
    mWebView.setWebChromeClient(new LightningChromeClient(activity, this));
    mLightningWebClient = new LightningWebClient(activity, this);
    mWebView.setWebViewClient(mLightningWebClient);
    mWebView.setDownloadListener(new LightningDownloadListener(activity));
    mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
    mWebView.setOnTouchListener(new TouchListener());
    sDefaultUserAgent = mWebView.getSettings().getUserAgentString();
    initializeSettings();
    initializePreferences(activity);

    if (url != null) {
        if (!url.trim().isEmpty()) {
            mWebView.loadUrl(url, mRequestHeaders);
        } else {
            // don't load anything, the user is looking for a blank tab
        }
    } else {
        loadHomepage();
    }
}