示例#1
0
        public async override void OnViewCreated(View rootView, Bundle savedInstanceState)
        {
            base.OnViewCreated(rootView, savedInstanceState);

            webView = rootView.FindViewById<MyWebView>(Resource.Id.webViewNews);

            Post post = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<Post>(postSerialized));
            Stream input = Context.Assets.Open("template.txt");
            StreamReader reader = new StreamReader(input);
            String template = reader.ReadToEnd();
            var imageFile = imageLoader.DiskCache.Get(post.ImageUrl);
            html = String.Format(template, imageFile.ToURI(), post.Title, post.Content, post.Link);

            webView.LoadDataWithBaseURL("http://smartreporter.altervista.org/", html, null, "UTF-8", null);

            FloatingActionButton fabAddFav = rootView.FindViewById<FloatingActionButton>(Resource.Id.fab_fav);
            fabAddFav.Click += (object sender, EventArgs e) => {
                var prefs = Application.Context.GetSharedPreferences
                    ("AndroidReport", FileCreationMode.Private);
                var prefsEdit = prefs.Edit();

                JArray fav = JArray.Parse(prefs.GetString("favourites", "[]"));
                if (!fav.Values<String>().Contains(postSerialized))
                {
                    fav.Add(postSerialized);
                    Toast.MakeText(Activity, "Articolo aggiunto ai preferiti", ToastLength.Short).Show();
                }
                else
                {
                    Toast.MakeText(Activity, "Hai già questo articolo nei tuoi preferiti!", ToastLength.Short).Show();
                }
                prefsEdit.PutString("favourites", fav.ToString());
                prefsEdit.Commit();
            };

            FloatingActionButton fabShare = rootView.FindViewById<FloatingActionButton>(Resource.Id.fab_share);
            fabShare.Click += (object sender, EventArgs e) =>
            {
                Intent sendIntent = new Intent();
                sendIntent.SetAction(Intent.ActionSend);
                sendIntent.PutExtra(Intent.ExtraText, "Leggi questo articolo su Smart Report: \"" + post.Title + "\", " + post.Link);
                sendIntent.SetType("text/plain");
                StartActivity(Intent.CreateChooser(sendIntent, "Condividi con:"));
            };
        }
示例#2
0
		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			// Use this to return your custom view for this Fragment
			View rootView = inflater.Inflate(Resource.Layout.web_view_fragment, container, false);

            webView = rootView.FindViewById<MyWebView>(Resource.Id.webViewNews);
            webView.Settings.JavaScriptEnabled = true;
            webView.Settings.SetRenderPriority(WebSettings.RenderPriority.High);
            webView.Settings.CacheMode = CacheModes.NoCache;
            webView.SetWebViewClient(new MWebViewClient(Context));
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
            {
                // chromium, enable hardware acceleration
                webView.SetLayerType(LayerType.Hardware, null);
            }
            else
            {
                // older android version, disable hardware acceleration
                webView.SetLayerType(LayerType.Software, null);
            }

            return rootView;
		}
示例#3
0
 public override void OnDestroyView()
 {
     if (webView != null)
     {
         if (webView != null)
         {
             webView.ClearHistory();
             webView.ClearCache(true);
             webView.LoadUrl("about:blank");
             webView.FreeMemory();
             webView.PauseTimers();
             webView = null;
         }
     }
     base.OnDestroyView();
 }