예제 #1
0
 /// <summary>
 /// Gets the context of the function
 /// </summary>
 /// <param name="context">Context.</param>
 public AppletFunctionBridge(Context context, AppletWebView view)
 {
     ApplicationContext.ProgressChanged += (o, e) => this.m_applicationStatus = new KeyValuePair <string, float>(e.ProgressText, e.Progress);
     this.m_context = context;
     this.m_view    = view;
 }
예제 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            (AndroidApplicationContext.Current as AndroidApplicationContext).CurrentActivity = this;

            this.SetContentView(Resource.Layout.Applet);
            this.m_webView = FindViewById <AppletWebView> (Resource.Id.applet_view);
            //this.m_webView.Asset = asset;
            var assetLink = this.Intent.Extras.Get("assetLink").ToString();

            this.m_tracer.TraceInfo("Navigating to {0}", assetLink);
            if (!String.IsNullOrEmpty(assetLink))
            {
                this.m_webView.LoadUrl(assetLink);
            }

            // Progress bar
            this.m_progressBar = new ProgressBar(this, null, Android.Resource.Attribute.ProgressBarStyleHorizontal);
            this.m_textView    = new TextView(this, null);
            this.m_textView.SetText(Resource.String.loading);
            this.m_progressBar.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, 24);
            this.m_textView.LayoutParameters    = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
            var decorView = this.Window.DecorView as FrameLayout;

            decorView.AddView(this.m_progressBar);
            decorView.AddView(this.m_textView);

            // Find the applet
            //AppletAsset asset = AndroidApplicationContext.Current.LoadedApplets.ResolveAsset(
            //             assetLink, language: this.Resources.Configuration.Locale.Language);
            //if (asset == null) {
            //             UserInterfaceUtils.ShowMessage(this, (o, e) => { this.Finish(); }, String.Format("FATAL: {0} not found (installed: {1})", assetLink, AndroidApplicationContext.Current.LoadedApplets.Count));

            //}



            // Progress has changed
            AndroidApplicationContext.ProgressChanged += (o, e) =>
            {
                RunOnUiThread(() =>
                {
                    try
                    {
                        if (!String.IsNullOrEmpty(e.ProgressText) && e.Progress > 0 && e.Progress < 1.0f)
                        {
                            this.m_textView.Visibility  = ViewStates.Visible;
                            this.m_progressBar.Progress = (int)(this.m_progressBar.Max * e.Progress);
                            this.m_textView.Text        = String.Format("{0} {1}", e.ProgressText, e.Progress > 0 ? String.Format("({0:0%})", e.Progress) : null);
                        }
                        else
                        {
                            this.m_textView.Visibility = ViewStates.Invisible;
                        }
                    }
                    catch { }
                });
            };

            // Set view
            EventHandler observer = null;

            observer = (o, e) =>
            {
                try
                {
                    View contentView = decorView.FindViewById(Android.Resource.Id.Content);
                    this.m_progressBar.SetY(contentView.GetY() + contentView.Height - 15);
                    this.m_textView.SetY(contentView.GetY() + contentView.Height - this.m_textView.MeasuredHeight - 15);

                    this.m_progressBar.ViewTreeObserver.GlobalLayout -= observer;
                }
                catch { }
            };
            this.m_progressBar.ViewTreeObserver.GlobalLayout += observer;


            //this.m_webView.LoadDataWithBaseURL ("applet:index", "<html><body>Hi!</body></html>", "text/html", "UTF-8", null);
        }