List of usage examples for android.webkit WebView getSettings
public WebSettings getSettings()
From source file:com.aniruddhc.acemusic.player.Utils.Common.java
@Override public void onCreate() { super.onCreate(); //Application context. mContext = getApplicationContext();//from www . j a va2 s . c om //SharedPreferences. mSharedPreferences = this.getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE); //Init the database. mDBAccessHelper = new DBAccessHelper(mContext); //Playback kickstarter. mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext()); //Picasso. mPicasso = new Picasso.Builder(mContext).build(); //ImageLoader. mImageLoader = ImageLoader.getInstance(); mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext()) .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13) .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build(); mImageLoader.init(mImageLoaderConfiguration); //Init DisplayImageOptions. initDisplayImageOptions(); //Log the user into Google Play Music only if the account is currently set up and active. if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) { //Create a temp WebView to retrieve the user agent string. String userAgentString = ""; if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) { WebView webView = new WebView(getApplicationContext()); webView.setVisibility(View.GONE); webView.loadUrl("http://www.google.com"); userAgentString = webView.getSettings().getUserAgentString(); mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit(); mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit(); webView = null; } setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext())); GMusicClientCalls.setWebClientUserAgent(userAgentString); String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", ""); //Authenticate with Google. AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false, accountName); task.execute(); } }
From source file:com.jelly.music.player.Utils.Common.java
@Override public void onCreate() { super.onCreate(); //Application context. mContext = getApplicationContext();/*from w w w. j a v a 2 s . c om*/ //SharedPreferences. mSharedPreferences = this.getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE); //Init the database. mDBAccessHelper = new DBAccessHelper(mContext); //Playback kickstarter. mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext()); //Picasso. mPicasso = new Picasso.Builder(mContext).build(); //ImageLoader. mImageLoader = ImageLoader.getInstance(); mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext()) .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13) .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build(); mImageLoader.init(mImageLoaderConfiguration); //Init DisplayImageOptions. initDisplayImageOptions(); //Log the user into Google Play Music only if the account is currently set up and active. if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) { //Create a temp WebView to retrieve the user agent string. String userAgentString = ""; if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) { WebView webView = new WebView(getApplicationContext()); webView.setVisibility(View.GONE); webView.loadUrl("http://www.google.com"); userAgentString = webView.getSettings().getUserAgentString(); mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit(); mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit(); webView = null; } setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext())); GMusicClientCalls.setWebClientUserAgent(userAgentString); String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", ""); //Authenticate with Google. AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false, accountName); task.execute(); } }
From source file:com.Duo.music.player.Utils.Common.java
@Override public void onCreate() { super.onCreate(); //Application context. mContext = getApplicationContext();//from w ww . j ava2 s .c om //SharedPreferences. mSharedPreferences = this.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE); //Init the database. mDBAccessHelper = new DBAccessHelper(mContext); //Playback kickstarter. mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext()); //Picasso. mPicasso = new Picasso.Builder(mContext).build(); //ImageLoader. mImageLoader = ImageLoader.getInstance(); mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext()) .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13) .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build(); mImageLoader.init(mImageLoaderConfiguration); //Init DisplayImageOptions. initDisplayImageOptions(); //Log the user into Google Play Music only if the account is currently set up and active. if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) { //Create a temp WebView to retrieve the user agent string. String userAgentString = ""; if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) { WebView webView = new WebView(getApplicationContext()); webView.setVisibility(View.GONE); webView.loadUrl("http://www.google.com"); userAgentString = webView.getSettings().getUserAgentString(); mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit(); mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit(); webView = null; } setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext())); GMusicClientCalls.setWebClientUserAgent(userAgentString); String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", ""); //Authenticate with Google. AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false, accountName); task.execute(); } }
From source file:im.vector.adapters.VectorMediasViewerAdapter.java
@Override public Object instantiateItem(ViewGroup container, final int position) { View view = mLayoutInflater.inflate(R.layout.adapter_vector_medias_viewer, null, false); // hide the pie chart final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart); pieFractionView.setVisibility(View.GONE); final WebView imageWebView = (WebView) view.findViewById(R.id.media_slider_image_webview); final View videoLayout = view.findViewById(R.id.media_slider_videolayout); final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail); imageWebView.getSettings().setDisplayZoomControls(false); imageWebView.setOnLongClickListener(new View.OnLongClickListener() { @Override//ww w. j av a 2 s. com public boolean onLongClick(View v) { VectorMediasViewerAdapter.this.onLongClick(); return true; } }); thumbView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { VectorMediasViewerAdapter.this.onLongClick(); return true; } }); // black background view.setBackgroundColor(0xFF000000); imageWebView.setBackgroundColor(0xFF000000); videoLayout.setBackgroundColor(0xFF000000); final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position); String mediaUrl = mediaInfo.mMediaUrl; if (mediaInfo.mMessageType.equals(Message.MSGTYPE_IMAGE)) { imageWebView.setVisibility(View.VISIBLE); imageWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); imageWebView.getSettings().setJavaScriptEnabled(true); imageWebView.getSettings().setLoadWithOverviewMode(true); imageWebView.getSettings().setUseWideViewPort(true); imageWebView.getSettings().setBuiltInZoomControls(true); videoLayout.setVisibility(View.GONE); final int rotationAngle = mediaInfo.mRotationAngle; final String mimeType = mediaInfo.mMimeType; File mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mimeType); // is the high picture already downloaded ? if (null != mediaFile) { if (mHighResMediaIndex.indexOf(position) < 0) { mHighResMediaIndex.add(position); } } else { // try to retrieve the thumbnail mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null); } // the thumbnail is not yet downloaded if (null == mediaFile) { // display nothing container.addView(view, 0); return view; } String mediaUri = "file://" + mediaFile.getPath(); String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle); final String viewportContent = "width=640"; loadImage(imageWebView, Uri.parse(mediaUri), viewportContent, css); container.addView(view, 0); } else { loadVideo(position, view, mediaInfo.mThumbnailUrl, mediaUrl, mediaInfo.mMimeType); container.addView(view, 0); } // check if the media is downloading String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), mediaUrl, mediaInfo.mMimeType); if (null != downloadId) { pieFractionView.setVisibility(View.VISIBLE); pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId)); pieFractionView.setTag(downloadId); mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() { @Override public void onDownloadError(String downloadId, JsonElement jsonElement) { pieFractionView.setVisibility(View.GONE); MatrixError error = JsonUtils.toMatrixError(jsonElement); if ((null != error) && error.isSupportedErrorCode()) { Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } } @Override public void onDownloadProgress(String aDownloadId, DownloadStats stats) { if (aDownloadId.equals(pieFractionView.getTag())) { pieFractionView.setFraction(stats.mProgress); } } @Override public void onDownloadComplete(String aDownloadId) { if (aDownloadId.equals(pieFractionView.getTag())) { pieFractionView.setVisibility(View.GONE); } } }); } return view; }
From source file:com.elpstudio.player.externals.Common.java
@Override public void onCreate() { super.onCreate(); //Application context. mContext = getApplicationContext();/* w ww . j a v a 2 s .c o m*/ sInstance = this; light = Typeface.createFromAsset(getApplicationContext().getAssets(), "segoeuil.ttf"); reg = Typeface.createFromAsset(getApplicationContext().getAssets(), "segoeui.ttf"); //SharedPreferences. mSharedPreferences = this.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE); //Init the database. mDBAccessHelper = new DBAccessHelper(mContext); //Playback kickstarter. //mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext()); //Picasso. // mPicasso = new Picasso.Builder(mContext).build(); //ImageLoader. mImageLoader = ImageLoader.getInstance(); mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext()) .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13) .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build(); mImageLoader.init(mImageLoaderConfiguration); //Init DisplayImageOptions. initDisplayImageOptions(); //Log the user into Google Play Music only if the account is currently set up and active. if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) { //Create a temp WebView to retrieve the user agent string. String userAgentString = ""; if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) { WebView webView = new WebView(getApplicationContext()); webView.setVisibility(View.GONE); webView.loadUrl("http://www.google.com"); userAgentString = webView.getSettings().getUserAgentString(); mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit(); mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit(); webView = null; } /*setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext())); GMusicClientCalls.setWebClientUserAgent(userAgentString); String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", ""); //Authenticate with Google. AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false, accountName); task.execute(); */ } }
From source file:im.neon.adapters.VectorMediasViewerAdapter.java
@Override public Object instantiateItem(ViewGroup container, final int position) { View view = mLayoutInflater.inflate(R.layout.adapter_vector_medias_viewer, null, false); // hide the pie chart final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart); pieFractionView.setVisibility(View.GONE); final WebView imageWebView = (WebView) view.findViewById(R.id.media_slider_image_webview); final View videoLayout = view.findViewById(R.id.media_slider_videolayout); final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail); imageWebView.getSettings().setDisplayZoomControls(false); imageWebView.setOnLongClickListener(new View.OnLongClickListener() { @Override//from w ww . ja v a2 s .co m public boolean onLongClick(View v) { VectorMediasViewerAdapter.this.onLongClick(); return true; } }); thumbView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { VectorMediasViewerAdapter.this.onLongClick(); return true; } }); // black background view.setBackgroundColor(0xFF000000); imageWebView.setBackgroundColor(0xFF000000); videoLayout.setBackgroundColor(0xFF000000); final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position); String mediaUrl = mediaInfo.mMediaUrl; if (mediaInfo.mMessageType.equals(Message.MSGTYPE_IMAGE)) { imageWebView.setVisibility(View.VISIBLE); imageWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); imageWebView.getSettings().setJavaScriptEnabled(true); imageWebView.getSettings().setLoadWithOverviewMode(true); imageWebView.getSettings().setUseWideViewPort(true); imageWebView.getSettings().setBuiltInZoomControls(true); videoLayout.setVisibility(View.GONE); final int rotationAngle = mediaInfo.mRotationAngle; if (TextUtils.isEmpty(mediaInfo.mMimeType)) { mediaInfo.mMimeType = "image/jpeg"; } final String mimeType = mediaInfo.mMimeType; File mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mimeType); // is the high picture already downloaded ? if (null != mediaFile) { if (mHighResMediaIndex.indexOf(position) < 0) { mHighResMediaIndex.add(position); } } else { // try to retrieve the thumbnail mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null); } // the thumbnail is not yet downloaded if (null == mediaFile) { // display nothing container.addView(view, 0); return view; } String mediaUri = "file://" + mediaFile.getPath(); String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle); final String viewportContent = "width=640"; loadImage(imageWebView, Uri.parse(mediaUri), viewportContent, css); container.addView(view, 0); } else { loadVideo(position, view, mediaInfo.mThumbnailUrl, mediaUrl, mediaInfo.mMimeType); container.addView(view, 0); } // check if the media is downloading String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), mediaUrl, mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo); if (null != downloadId) { pieFractionView.setVisibility(View.VISIBLE); pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId)); pieFractionView.setTag(downloadId); mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() { @Override public void onDownloadError(String downloadId, JsonElement jsonElement) { pieFractionView.setVisibility(View.GONE); MatrixError error = JsonUtils.toMatrixError(jsonElement); if ((null != error) && error.isSupportedErrorCode()) { Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } } @Override public void onDownloadProgress(String aDownloadId, DownloadStats stats) { if (aDownloadId.equals(pieFractionView.getTag())) { pieFractionView.setFraction(stats.mProgress); } } @Override public void onDownloadComplete(String aDownloadId) { if (aDownloadId.equals(pieFractionView.getTag())) { pieFractionView.setVisibility(View.GONE); } } }); } return view; }
From source file:info.alni.comete.android.Comete.java
private AlertDialog createHelpDialog() { final WebView wv = new WebView(this); wv.setTag("help"); wv.getSettings().setJavaScriptEnabled(true); wv.setWebViewClient(internalWebViewClient); wv.loadUrl(URL_HELP_MAIN);/*from w w w . ja v a 2s. com*/ return new AlertDialog.Builder(this).setTitle("Help").setView(wv) .setPositiveButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); }
From source file:justforcommunity.radiocom.fragments.HomePageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_home, container, false); mActivity = (Home) getActivity();/*from ww w. j ava 2 s . com*/ mContext = getContext(); try { station.getHistory().replace("<body", "<body style=\'text-align:justify;color:gray;background-color:black;\'"); station.getHistory().replaceAll("style=\".+?\"", ""); } catch (Exception e) { } WebView wb = (WebView) v.findViewById(R.id.history_frame); wb.setBackgroundColor(Color.WHITE); // String fontscript = "<style>@font-face {font-family : 'HelveticaNeue-Light';src:url('file:///android_asset/fonts/"+VariablesGlobalesActivity.GENERICFONT+"');}</style>"; String fontscript = ""; String script = "<style type='text/css' >p{width:100%;}img{width:100%;height:auto;-webkit-transform: translate3d(0px,0px,0px);}a,h1,h2,h3,h4,h5,h6{color:" + GlobalValues.colorHTML + ";}div,p,span,a {max-width: 100%;}iframe{width:100%;height:auto;}</style>"; wb.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } }); wb.loadDataWithBaseURL("", "<html><head>" + fontscript + script + "</head><body style=\"font-family:HelveticaNeue-Light; \">" + station.getHistory() + "</body></html>", "text/html", "utf-8", ""); wb.getSettings().setDomStorageEnabled(true); wb.getSettings().setJavaScriptEnabled(true); App application = (App) getActivity().getApplication(); Tracker mTracker = application.getDefaultTracker(); mTracker.setScreenName(getString(R.string.home_view)); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); return v; }
From source file:com.juick.android.Utils.java
public static void setupWebView(final WebView wv, String content) { try {//from w ww .j a v a 2s . co m if (skipWeb) return; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(wv.getContext()); File file = new File(wv.getContext().getCacheDir(), "temp.html"); String PREFIX = "#prefs.checked."; while (true) { int ix = content.indexOf(PREFIX); if (ix == -1) break; int ix2 = content.indexOf("#", ix + 1); if (ix2 == -1) break; String key = content.substring(ix + PREFIX.length(), ix2); boolean def = false; if (key.endsWith("!")) { def = true; key = key.substring(0, key.length() - 1); } boolean checked = sp.getBoolean(key, def); content = content.substring(0, ix) + (checked ? "checked" : "") + content.substring(ix2 + 1); } FileWriter fileWriter = new FileWriter(file); fileWriter.write(content); fileWriter.close(); wv.getSettings().setJavaScriptEnabled(true); // wv.getSettings().setBlockNetworkImage(false); // wv.getSettings().setBlockNetworkLoads(false); wv.getSettings().setLoadsImagesAutomatically(true); Uri uri = Uri.fromFile(file); wv.addJavascriptInterface(new Object() { public void onFormData(String str) { wv.setTag(str); } }, "EXT"); wv.loadUrl(uri.toString()); } catch (IOException e) { // } }
From source file:com.robandjen.comicsapp.FullscreenActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override//from w ww.j a va 2 s . c om protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_fullscreen); final WebView v = (WebView) findViewById(R.id.fullscreen_content); v.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { updateShare(url); return false; } @Override public void onPageFinished(WebView view, String url) { setProgressBarIndeterminateVisibility(false); super.onPageFinished(view, url); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setProgressBarIndeterminateVisibility(true); super.onPageStarted(view, url, favicon); } }); final WebSettings settings = v.getSettings(); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.open_drawer, R.string.close_drawer); mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true); if (mComicList == null) { try { InputStream is = openFileInput(COMICFILE); if (!loadXml(is)) { Log.w(TAG, "Downloaded list not parseable, defaulting to built-in"); } } catch (FileNotFoundException e) { Log.i(TAG, "Downloaded list not found, defaulting to built-in"); } } if (mComicList == null) { loadDefaultXML(); } if (savedInstanceState != null) { mCurComic = savedInstanceState.getInt(CURCOMICKEY, 0); final String url = savedInstanceState.getString(CURURLKEY); showCurrentComic(url); } else { do { if (!bSkipOther || !mComicList.get(mCurComic).getOther()) { break; } ++mCurComic; mCurComic %= mComicList.size(); } while (mCurComic != 0); showCurrentComic(); } }