List of usage examples for android.webkit WebView addJavascriptInterface
public void addJavascriptInterface(Object object, String name)
From source file:com.yang.bruce.mumuxi.util.WebDialog.java
private void setWebView(WebView webView, Context context) { WebSettings settings = webView.getSettings(); settings.setDefaultTextEncodingName(KEY_UTF_8); settings.setJavaScriptEnabled(true); webView.addJavascriptInterface(new WebAppInterface(context), "Android"); }
From source file:it.clipart.swipehtmlpageapp.IntroFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.intro_screen, container, false); View controlView = rootView.findViewById(R.id.introFinishControls); /*/* ww w .j av a 2 s .c om*/ If we are on the last page of the intro, we show a special controlView that lets the user select if they ever want to see this again, and continue on to the main part of the app. Se si nell'ultima pagina dell'intro, verr mostrato uno speciale controlView che lascia l'utente se vuole vederlo da capo o proseguire nella parte principale. */ if (item == MyWebActivity.NUM_INTRO_PAGES) { /* Se l'ultima pagina rende visibile il layout contenente il controllo che lancia la guida vera e propria - Il fatto che sia l'ultima pagina non viene creato un successivo Fragment e quindi lo swipe non pi attivo. */ controlView.setVisibility(View.VISIBLE); // Controlla la checkBox "Non mostrare pi" rootView.findViewById(R.id.checkBox).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dontShowAgainTapped(); } }); } // Se si torna indietro ( ad esempio ) rende invisibile il controllo di cui sopra else { controlView.setVisibility(View.INVISIBLE); } WebView webview = (WebView) rootView.findViewById(R.id.webView); android.webkit.WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webview.getSettings().setLoadsImagesAutomatically(true); webview.addJavascriptInterface(new WebAppInterface(this.activity), "Android"); webview.loadUrl("file:///android_asset/intro" + item + ".html"); Log.d(TAG, "Caricata la pagina intro url: " + webview.getUrl()); return rootView; }
From source file:se.eliga.aves.AboutFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webView = (WebView) getView().findViewById(R.id.about_text); webView.loadUrl("file:///android_asset/about.html"); webView.setBackgroundColor(0x00FFFFFF); webView.setVisibility(View.VISIBLE); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.addJavascriptInterface( new AboutJSObject(getVersion(), BuildConfig.BUILDTIME, BuildConfig.BUILDTYPE), "AboutData"); }
From source file:com.dwdesign.tweetings.fragment.WebMapFragment.java
/** Sets up the WebView object and loads the URL of the page **/ private void setupWebView() { final WebView webview = getWebView(); webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); setWebViewClient(new MapWebViewClient(getActivity())); loadUrl(mUri.toString());/*from ww w. java 2 s . c o m*/ final WebSettings settings = webview.getSettings(); settings.setBuiltInZoomControls(false); /** Allows JavaScript calls to access application resources **/ webview.addJavascriptInterface(new JavaScriptInterface(), "android"); }
From source file:com.linkbubble.util.PageInspector.java
public PageInspector(Context context, WebView webView, OnItemFoundListener listener) { mContext = context;// w w w . ja va 2 s . c o m mWebView = webView; mHandler = new Handler(); mJSEmbedHandler = new JSEmbedHandler(); mOnItemFoundListener = listener; webView.addJavascriptInterface(mJSEmbedHandler, JS_VARIABLE); }
From source file:jp.mixi.android.sdk.MixiDialog.java
private WebView setUpWebView(WebView webView) { Log.v(TAG, "setwebview"); webView.getSettings().setUserAgentString(Constants.USER_AGENT); webView.setVerticalScrollBarEnabled(false); webView.setHorizontalScrollBarEnabled(false); webView.setWebViewClient(new MixiWebviewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(new JsHandler(), "mixi"); String token = mParams.get("oauth_token"); int sdkInt = Integer.valueOf(Build.VERSION.SDK); // android2.1 if (sdkInt < Constants.SUPPORTED_SDK_VERSION) { Uri uri = Uri.parse(mUrl);/*from w w w. ja v a 2 s.c o m*/ if (token != null) { Builder builder = uri.buildUpon(); builder.appendQueryParameter("oauth_token", token); uri = builder.build(); } webView.loadUrl(uri.toString()); } else { HashMap<String, String> extraHeaders = new HashMap<String, String>(); if (token != null) { extraHeaders.put("Authorization", "OAuth " + token); } webView.loadUrl(mUrl, extraHeaders); } return webView; }
From source file:org.quizreader.android.PageReadActivity.java
/** Called when the activity is first created. */ @SuppressLint("SetJavaScriptEnabled") @Override/* w ww .j av a 2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.page_read); // immediately pop up loading dialog dialog = new ProgressDialog(this); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setMessage("loading page"); dialog.show(); // set up webview WebView webview = (WebView) findViewById(R.id.webView); webview.setWebViewClient(new QRWebViewClient()); webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("QuizReader", cm.message() + ", line " + cm.lineNumber() + " " + cm.sourceId()); return true; } }); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webview.addJavascriptInterface(new QuizReaderInterface(), "qr"); try { random = new Random(); wordDao = new WordDao(this); qzzFile = new QzzFile(title.getFilepath(), this); URL htmlURL = qzzFile.getHTML(title.getId(), title.getSection()); if (htmlURL == null) { // beyond the last section setResult(RESULT_END_TITLE); finish(); } String externalForm = htmlURL.toExternalForm(); webview.loadUrl(externalForm + "?paragraph=" + title.getParagraph()); } catch (Exception ex) { webview.loadData(ex.toString(), "text/plain", null); } }
From source file:com.github.jobs.ui.fragment.EditTemplateFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // init argument fields Bundle arguments = getArguments();/*from w ww. j ava2 s .c om*/ mTemplateId = arguments.getLong(ARG_TEMPLATE_ID, -1); mShowEditor = mShowEditor || mTemplateId == -1; // prepare ui View root = getView(); mViewSwitcher = (ViewSwitcher) root.findViewById(R.id.switcher_edit_mode); if (!mShowEditor) { showEditor(mShowEditor); } WebView templatePreview = (WebView) root.findViewById(R.id.lbl_cover_letter_preview); AppUtils.setupWebView(templatePreview); mJavascriptInterface = new GithubJobsJavascriptInterface(getActivity(), templatePreview, null); templatePreview.addJavascriptInterface(mJavascriptInterface, JS_INTERFACE); templatePreview.loadUrl(PREVIEW_TEMPLATE_URL); mTemplateName = (EditText) root.findViewById(R.id.edit_cover_letter_name); mTemplateContent = (EditText) root.findViewById(R.id.edit_cover_letter_content); mTemplateContent.addTextChangedListener(mTextWatcher); if (mTemplateId != -1) { // retrieve template from database Template template = new Template(); template.setId(mTemplateId); template = adapter.findFirst(template); ArrayList<TemplateService> templateServices = new ArrayList<TemplateService>( template.getTemplateServices()); for (TemplateService savedService : mTemplateServices) { if (!templateServices.contains(savedService)) { templateServices.add(savedService); } } mTemplateServices = templateServices; // set name and raw content mTemplateName.setText(template.getName()); getActivity().setTitle(template.getName()); String content = template.getContent(); mTemplateContent.setText(content); updatePreview(); } }
From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext()); //To keep session for desfire async requests CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); LocalStorage.getInstance(getApplicationContext()); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(getApplicationContext())); setContentView(R.layout.activity_main); mAdapter = NfcAdapter.getDefaultAdapter(this); checkHardware(mAdapter);/*from ww w . j a v a 2 s . co m*/ localStorageDBHelper = LocalStorage.getInstance(this.getApplicationContext()); String numeroId = localStorageDBHelper.getValue("numeroId"); TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); url = ESUP_NFC_TAG_SERVER_URL + "/nfc-index?numeroId=" + numeroId + "&imei=" + imei + "&macAddress=" + getMacAddr() + "&apkVersion=" + getApkVersion(); view = (WebView) this.findViewById(R.id.webView); view.clearCache(true); view.addJavascriptInterface(new LocalStorageJavaScriptInterface(this.getApplicationContext()), "AndroidLocalStorage"); view.addJavascriptInterface(new AndroidJavaScriptInterface(this.getApplicationContext()), "Android"); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { if (progress == 100) { AUTH_TYPE = localStorageDBHelper.getValue("authType"); } } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { log.info("Webview console message : " + consoleMessage.message()); return false; } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { view.reload(); return true; } }); view.getSettings().setAllowContentAccess(true); WebSettings webSettings = view.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDatabasePath(this.getFilesDir().getParentFile().getPath() + "/databases/"); view.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); view.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { } }); view.loadUrl(url); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); }
From source file:ca.bitwit.postcard.PostcardAdaptor.java
/** * Cordova Plugin Overrides//from w ww . j av a 2 s. com */ public PostcardAdaptor(Activity activity, WebView webView) { Log.d("PostcardApplication", "Initialized"); NetworksManager.INSTANCE.adaptor = this; this.activity = activity; this.webView = webView; Context context = activity.getApplicationContext(); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.addJavascriptInterface(this, "PostcardApplication"); webView.loadUrl("file:///android_asset/www/index.html"); this.properties = new Properties(); String propFileName = "postcard.properties"; try { InputStream inputStream = context.getAssets().open(propFileName); if (inputStream != null) { this.properties.load(inputStream); } else { throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); } } catch (IOException e) { e.printStackTrace(); } this.networkAccountDataSource = new NetworkAccountDataSource(context); this.networkAccountDataSource.open(); this.personDataSource = new PersonDataSource(context); this.personDataSource.open(); this.tagDataSource = new TagDataSource(context); this.tagDataSource.open(); }