Exemplo n.º 1
0
        public TurnOnOffScreen(Window window)
        {
            m_Window = window;
            WindowManagerFlags screenFlags = WindowManagerFlags.ShowWhenLocked | WindowManagerFlags.TurnScreenOn | WindowManagerFlags.KeepScreenOn | WindowManagerFlags.DismissKeyguard;

            m_TurnOff = new ExecuteAction(() =>
            {
                try
                {
                    m_Window.AddFlags(screenFlags);
                    var attributes = new WindowManagerLayoutParams();
                    attributes.CopyFrom(m_Window.Attributes);
                    attributes.ScreenBrightness = 0f;
                    m_Window.Attributes         = attributes;
                }
                catch
                {
                }
            });
            m_TurnOn = new ExecuteAction(() =>
            {
                try
                {
                    m_Window.ClearFlags(screenFlags);
                    var attributes = new WindowManagerLayoutParams();
                    attributes.CopyFrom(m_Window.Attributes);
                    attributes.ScreenBrightness = -1f;
                    m_Window.Attributes         = attributes;
                }
                catch
                {
                }
            });
        }
Exemplo n.º 2
0
        public object ShowProgress()
        {
            var  top  = Mvx.Resolve <IMvxAndroidCurrentTopActivity>();
            var  act  = top.Activity;
            View view = act.LayoutInflater.Inflate(Resource.Layout.ProgressView, null);

            AlertDialog.Builder builder = new AlertDialog.Builder(act);
            builder.SetCancelable(false);
            builder.SetView(view);

            AlertDialog dialog = builder.Create();

            dialog.Show();
            Window window = dialog.Window;

            if (window != null)
            {
                WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams();
                layoutParams.CopyFrom(dialog.Window.Attributes);
                layoutParams.Width       = ViewGroup.LayoutParams.WrapContent;
                layoutParams.Height      = ViewGroup.LayoutParams.WrapContent;
                dialog.Window.Attributes = layoutParams;
                Drawable drawable = new ColorDrawable(Android.Graphics.Color.Transparent);
                dialog.Window.SetBackgroundDrawable(drawable);
            }

            return(dialog);
        }
Exemplo n.º 3
0
        // Overridden from IAlertDialog.Builder
        public override AlertDialog Create()
        {
            View v = LayoutInflater.From(Context).Inflate(Resource.Layout.dialog_title, null, false);

            TextView titleView = v.FindViewById <TextView>(Resource.Id.title);
            View     closeView = v.FindViewById(Resource.Id.close);

            if (truncate)
            {
                titleView.SetSingleLine(true);
                titleView.Ellipsize = TextUtils.TruncateAt.End;
            }

            SetCustomTitle(v);
            titleView.Text = title;

            AlertDialog ret = base.Create();

            closeView.SetOnClickListener(new CloseDialogAction(ret));
            closeView.Visibility = (isCancelable) ? ViewStates.Visible : ViewStates.Gone;

            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();

            lp.CopyFrom(ret.Window.Attributes);
            lp.Width = ViewGroup.LayoutParams.MatchParent;

            return(ret);
        }
Exemplo n.º 4
0
        public CustomAlertDialog(Context context) : base(context)
        {
            // Вместо "?android:attr/dialogPreferredPadding" в customDialogLayout.axml для уровней API ниже 22.
            _preferredPadding = Build.VERSION.SdkInt < BuildVersionCodes.LollipopMr1
                ? Context.Resources.GetDimensionPixelSize(Resource.Dimension.dialogPreferredPaddingApiLess22)
                : UiUtilities.GetAttributeValuePixelSize(Context, Resource.Attribute.dialogPreferredPadding);

            ShowEvent += (s, e) =>
            {
                WindowManagerLayoutParams layoutParameters = new WindowManagerLayoutParams();
                layoutParameters.CopyFrom(Window.Attributes);

                IWindowManager windowManager = (context as AppCompatActivity).WindowManager;
                (Int32 width, Int32 height) = UiUtilities.GetScreenPixelSize(windowManager);

                Int32 maxDialogHeight = (Int32)(height * 0.9);
                if (Window.DecorView.Height > maxDialogHeight)
                {
                    layoutParameters.Height = maxDialogHeight;
                }

                Window.Attributes = layoutParameters;
            };

            _layout = View.Inflate(Context, Resource.Layout.customDialogLayout, null) as ViewGroup;
            _layout.SetPadding(_preferredPadding, _preferredPadding, _preferredPadding, _preferredPadding);

            SetView(_layout);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.Extra_BeSmart_AdvancedSearch_DialogFragment, null, false);

            Dialog.Window.RequestFeature(WindowFeatures.NoTitle);

            RelativeLayout Container = v.FindViewById <RelativeLayout>(Resource.Id.relativeLayout2);
            TextView       CategoriePrimara_TView   = v.FindViewById <TextView>(Resource.Id.textView1);
            TextView       CategorieSecundara_TView = v.FindViewById <TextView>(Resource.Id.textView2);
            TextView       Firma_TView      = v.FindViewById <TextView>(Resource.Id.textView3);
            TextView       NumeProdus_TView = v.FindViewById <TextView>(Resource.Id.textView4);
            TextView       Cauta_TView      = v.FindViewById <TextView>(Resource.Id.textView5);

            SetTypeface.Normal.SetTypeFace(Activity, CategoriePrimara_TView);
            SetTypeface.Normal.SetTypeFace(Activity, CategorieSecundara_TView);
            SetTypeface.Normal.SetTypeFace(Activity, Firma_TView);
            SetTypeface.Normal.SetTypeFace(Activity, NumeProdus_TView);
            SetTypeface.Normal.SetTypeFace(Activity, Cauta_TView);

            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();

            lp.CopyFrom(Dialog.Window.Attributes);
            lp.Height = Container.LayoutParameters.Height;
            lp.Width  = Container.LayoutParameters.Width;

            Dialog.Show();

            Dialog.Window.Attributes = lp;

            return(v);
        }
        private void Add_more_device_Click(object sender, EventArgs e)
        {
            // create a WebView
            WebView webView = new WebView(Context);

            // populate the WebView with an HTML string
            webView.LoadUrl("file:///android_asset/" + Context.GetString(Resource.String.add_more_device_html));

            webView.SetWebViewClient(new MyWebViewClient(Context));

            FrameLayout container = new FrameLayout(Context);
            var         @params   = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            webView.LayoutParameters = @params;
            container.AddView(webView);

            // create an AlertDialog.Builder
            AlertDialog.Builder builder = new AlertDialog.Builder(Context);

            // set the WebView as the AlertDialog.Builder’s view
            builder.SetView(container);

            var dialog = builder.Show();

            WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams();

            layoutParams.CopyFrom(dialog.Window.Attributes);
            layoutParams.Width       = WindowManagerLayoutParams.MatchParent;
            layoutParams.Height      = WindowManagerLayoutParams.MatchParent;
            dialog.Window.Attributes = layoutParams;

            dialog.Show();
        }
Exemplo n.º 7
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.Organizator_Trip_ViewQuestionPool_DialogAdapter, null, false);

            Dialog.Window.RequestFeature(WindowFeatures.NoTitle);

            RelativeLayout Frame          = v.FindViewById <RelativeLayout>(Resource.Id.relativeLayout2);
            ListView       ListaIntrebari = v.FindViewById <ListView>(Resource.Id.listView1);
            ListView       ListaVariante  = v.FindViewById <ListView>(Resource.Id.listView2);

            ListaIntrebari.Adapter = new Organizator_Trip_ViewQuestionPool_Adapters.Organizator_Trip_ViewQuestionPool_ListaIntrebari_Adapter(Activity, ListaVariante, Votes);

            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();

            lp.CopyFrom(Dialog.Window.Attributes);
            lp.Height = Frame.LayoutParameters.Height;
            lp.Width  = Frame.LayoutParameters.Width;
            lp.Alpha  = 0.8f;

            Dialog.SetCanceledOnTouchOutside(true);
            Dialog.Show();

            Dialog.Window.Attributes = lp;
            return(v);
        }
Exemplo n.º 8
0
        public float GetBrightness()
        {
            Window?window = CrossCurrentActivity.Current.Activity.Window;
            WindowManagerLayoutParams attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(window.Attributes);
            return(attributesWindow.ScreenBrightness);
        }
        public void SetScreenBrightness(float brightness)
        {
            var window           = CrossCurrentActivity.Current.Activity.Window;
            var attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(window.Attributes);
            attributesWindow.ScreenBrightness = brightness;
            window.Attributes = attributesWindow;
        }
Exemplo n.º 10
0
        protected override void NativeSet(float brightness)
        {
            var window           = Mvx.Resolve <IMvxAndroidCurrentTopActivity>().Activity.Window;
            var attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(window.Attributes);
            attributesWindow.ScreenBrightness = brightness;
            window.Attributes = attributesWindow;
        }
Exemplo n.º 11
0
 private void ChangeBrightness(ChangeBrightnessMessage msg)
 {
     RunOnUiThread(() => {
         var attributesWindow = new WindowManagerLayoutParams();
         attributesWindow.CopyFrom(Window.Attributes);
         attributesWindow.ScreenBrightness = (float)ChangeBrightnessMessage.Validate(msg.Brightness);
         Window.Attributes = attributesWindow;
     });
 }
Exemplo n.º 12
0
        public void SetBrightness(float brightness)
        {
            var window       = MainActivity.Instance.Window;
            var windowParams = new WindowManagerLayoutParams();

            windowParams.CopyFrom(window.Attributes);
            windowParams.ScreenBrightness = brightness;

            window.Attributes = windowParams;
        }
        public float GetBrightness()
        {
            //throw new NotImplementedException();
            var window = ((Activity)Forms.Context).Window;
            //var window = CrossCurrentActivity.Current.Activity.Window;
            var attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(window.Attributes);

            return(attributesWindow.ScreenBrightness);
        }
Exemplo n.º 14
0
 public void parlaklik(int value)
 {
     try
     {
         var attributesWindow = new WindowManagerLayoutParams();
         attributesWindow.CopyFrom(Window.Attributes);
         attributesWindow.ScreenBrightness = Convert.ToSingle(value);
         Window.Attributes = attributesWindow;
     }
     catch (Exception ex) { Toast.MakeText(this, ex.Message + "AYAR", ToastLength.Long).Show(); }
 }
Exemplo n.º 15
0
 public void parlaklikKac()
 {
     try
     {
         var attributesWindow = new WindowManagerLayoutParams();
         attributesWindow.CopyFrom(Window.Attributes);
         byte[] ayar = Encoding.UTF8.GetBytes("PARLAKLIK|" + attributesWindow.ScreenBrightness.ToString());
         PictureCallback.Send(Soketimiz, ayar, 0, ayar.Length, 59999);
         Toast.MakeText(this, attributesWindow.ScreenBrightness.ToString() + "GET", ToastLength.Long).Show();
     }
     catch (Exception ex) { Toast.MakeText(this, ex.Message + "GET", ToastLength.Long).Show(); }
 }
Exemplo n.º 16
0
        private void ChangeBrightness(ChangesBrightnessMessage msg)
        {
            RunOnUiThread(() => {
                var brightness = Math.Min(msg.Brightness, 1);
                brightness     = Math.Max(brightness, 0);

                var attributesWindow = new WindowManagerLayoutParams();
                attributesWindow.CopyFrom(Window.Attributes);
                attributesWindow.ScreenBrightness = brightness;
                Window.Attributes = attributesWindow;
            });
        }
Exemplo n.º 17
0
        public void SetBrightness(float brightnessValue)
        {
            System.Random random           = new System.Random();
            int           a                = random.Next(1, 100);
            var           attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(Window.Attributes);

            attributesWindow.ScreenBrightness = (a / 100);
            brightness.Text = a + " %";

            Window.Attributes = attributesWindow;
        }
Exemplo n.º 18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Disable screen dim/sleep
            Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);

            // Set screen brightness to 100%
            var attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(Window.Attributes);
            attributesWindow.ScreenBrightness = 1f;
            Window.Attributes = attributesWindow;


            var view = FindViewById <SurfaceView>(Resource.Id.surfaceView1);

            // Set initial background color to green
            view.SetBackgroundColor(Color.LimeGreen);
            var isGreen = true;

            // Change color when screen is clicked
            view.Click += delegate {
                if (isGreen)
                {
                    view.SetBackgroundColor(Color.Red);
                }
                else
                {
                    view.SetBackgroundColor(Color.LimeGreen);
                }
                isGreen = !isGreen;
            };

            // Display About message when screen is long pressed
            view.LongClick += delegate
            {
                var context = this.ApplicationContext;
                var version = context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName;
                using (var builder = new AlertDialog.Builder(this))
                {
                    builder.SetMessage("RedCard v" + version + "\nErik C. McLaughlin\nhttps://erikcmclaughlin.com");
                    builder.SetTitle("About");
                    builder.Create();
                    builder.Show();
                }
            };
        }
Exemplo n.º 19
0
        private CustomDialogProfileSharingData OpenMiniProfileDialog()
        {
            var cdd = new CustomDialogProfileSharingData(Activity);

            var lp = new WindowManagerLayoutParams();

            lp.CopyFrom(cdd.Window.Attributes);
            lp.Width  = ViewGroup.LayoutParams.MatchParent;
            lp.Height = ViewGroup.LayoutParams.MatchParent;

            cdd.Show();
            cdd.Window.Attributes = lp;
            return(cdd);
        }
Exemplo n.º 20
0
        public void Show()
        {
            var viewGroup = FormsViewHelper.ConvertFormsToNative(_popup, DisplayHelper.GetSize());
            _dialog.SetContentView(viewGroup);

            // to show dialog container 'fullscreen'
            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();
            lp.CopyFrom(_dialog.Window.Attributes);
            lp.Width = ViewGroup.LayoutParams.MatchParent;
            lp.Height = ViewGroup.LayoutParams.MatchParent;
            _dialog.Window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
            _dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
            _dialog.Show();
            _dialog.Window.Attributes = lp;
        }
Exemplo n.º 21
0
        private CustomDialogProfileSharingData OpenMiniProfileDialog()
        {
            var cdd = new CustomDialogProfileSharingData(Activity);

            var windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            var lp = new WindowManagerLayoutParams();

            lp.CopyFrom(cdd.Window.Attributes);
            lp.Width  = ViewGroup.LayoutParams.MatchParent;
            lp.Height = ViewGroup.LayoutParams.MatchParent;

            cdd.Show();
            cdd.Window.Attributes = lp;
            return(cdd);
        }
Exemplo n.º 22
0
        public MaterialDialog(Builder builder)
            : base(builder.Context, DialogInit.GetTheme(builder))
        {
            mHandler = new Handler();
            MBuilder = builder;
            LayoutInflater inflater = LayoutInflater.From(builder.Context);
            view = (MDRootLayout)inflater.Inflate(DialogInit.GetInflateLayout(builder), null);
            DialogInit.Init(this);

            if (builder.Context.Resources.GetBoolean(Resource.Boolean.sino_droid_md_is_tablet))
            {
                WindowManagerLayoutParams lp = new WindowManagerLayoutParams();
                lp.CopyFrom(Window.Attributes);
                lp.Width = builder.Context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_default_dialog_width);
                Window.Attributes = lp;
            }
        }
Exemplo n.º 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="brightness">From 0 to 1</param>
        public void SetBrightness(float brightness)
        {
            if (brightness > 1f || brightness == 0f)
            {
                return;
            }
            if (!originalBrightness.HasValue)
            {
                originalBrightness = GetBrightness();
            }
            var window           = CrossCurrentActivity.Current.Activity.Window;
            var attributesWindow = new WindowManagerLayoutParams();

            attributesWindow.CopyFrom(window.Attributes);
            attributesWindow.ScreenBrightness = brightness;
            window.Attributes = attributesWindow;
        }
Exemplo n.º 24
0
        public void Show()
        {
            var viewGroup = FormsViewHelper.ConvertFormsToNative(_popup, DisplayHelper.GetSize());

            _dialog.SetContentView(viewGroup);

            // to show dialog container 'fullscreen'
            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();

            lp.CopyFrom(_dialog.Window.Attributes);
            lp.Width  = ViewGroup.LayoutParams.MatchParent;
            lp.Height = ViewGroup.LayoutParams.MatchParent;
            _dialog.Window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
            _dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
            _dialog.Show();
            _dialog.Window.Attributes = lp;
        }
Exemplo n.º 25
0
        //////////////////////////////////////////////////////////////////////////
        // DIALOG Section
        //////////////////////////////////////////////////////////////////////////
        public void ShowPresentationDialog(Context context, string title, string content, bool external = false)
        {
            LayoutInflater inflater            = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
            View           view                = inflater.Inflate(Resource.Layout.DialogWebView, null);
            WebView        presentationWebView = view.FindViewById <WebView>(Resource.Id.dialogWebView);

            StorehouseWebViewClient client = new StorehouseWebViewClient(external);

            presentationWebView.SetWebViewClient(client);
            presentationWebView.Settings.JavaScriptEnabled   = true;
            presentationWebView.Settings.BuiltInZoomControls = true;
            presentationWebView.VerticalScrollBarEnabled     = false;
            presentationWebView.Settings.DefaultFontSize     = GetWebViewTextSize(App.STATE.SeekBarTextSize);

            if (content.StartsWith("http"))
            {
                presentationWebView.LoadUrl(content);
            }
            else
            {
                presentationWebView.LoadDataWithBaseURL("file:///android_asset/", content, "text/html", "utf-8", null);
            }

            MaterialDialog dialog = null;

            MaterialDialog.Builder popup = new MaterialDialog.Builder(context);
            popup.SetCustomView(view, false);
            popup.SetNegativeText("X", (o, args) =>
            {
                // Close dialog
            });

            App.STATE.Activity.RunOnUiThread(() =>
            {
                dialog = popup.Show();

                // Set dialog width to width of screen
                WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams();
                layoutParams.CopyFrom(dialog.Window.Attributes);
                layoutParams.Width       = WindowManagerLayoutParams.MatchParent;
                dialog.Window.Attributes = layoutParams;
            });
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.Extra_BeSmart_SetareDistanta_DialogFragment, null, false);

            Dialog.Window.RequestFeature(WindowFeatures.NoTitle);

            RelativeLayout Container = v.FindViewById <RelativeLayout>(Resource.Id.relativeLayout2);
            ListView       Distante  = v.FindViewById <ListView>(Resource.Id.listView1);
            SearchView     SearchBar = v.FindViewById <SearchView>(Resource.Id.searchView1);

            Distante.Adapter = new BeSmart_SetareDistanta_Adapter(Activity, new string[] {
                "50",
                "100",
                "200",
                "300",
                "500",
                "1000",
                "1500",
                "2000",
                "3000",
                "4000",
                "5000",
                "10000",
                "20000",
                "30000"
            }, this);

            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();

            lp.CopyFrom(Dialog.Window.Attributes);
            lp.Height = Container.LayoutParameters.Height;
            lp.Width  = Container.LayoutParameters.Width;

            Dialog.Show();

            Dialog.Window.Attributes = lp;

            return(v);
        }
Exemplo n.º 27
0
        private void InitializeIoC()
        {
            if (SimpleIoc.Default.IsRegistered <bleissem.babyphone.Settings>())
            {
                return;
            }

            SimpleIoc.Default.Register <ICreateTimer>(() => new MyTimerCreator(), true);

            var      dbPath   = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Babyphone.Settings.db3");
            Settings settings = new Settings(dbPath);

            SimpleIoc.Default.Register <bleissem.babyphone.Settings>(() => settings, true);

            AudioManager audioManager = (AudioManager)this.GetSystemService(Context.AudioService);

            Speaker speaker = new Speaker(audioManager);

            SimpleIoc.Default.Register <ISpeaker>(() => speaker, true);

            MuteUnmutePhone mum = new MuteUnmutePhone(audioManager);

            SimpleIoc.Default.Register <IUnMutePhone>(() => mum, true);
            SimpleIoc.Default.Register <IMutePhone>(() => mum, true);

            WindowManagerFlags screenFlags = WindowManagerFlags.ShowWhenLocked | WindowManagerFlags.TurnScreenOn | WindowManagerFlags.KeepScreenOn | WindowManagerFlags.DismissKeyguard;

            TurnOnOffScreenViewModel turnOnOffScreen = new TurnOnOffScreenViewModel(
                new ExecuteAction(() =>
            {
                try
                {
                    this.Window.AddFlags(screenFlags);
                    var attributes = new WindowManagerLayoutParams();
                    attributes.CopyFrom(this.Window.Attributes);
                    attributes.ScreenBrightness = 0f;
                    this.Window.Attributes      = attributes;
                }
                catch
                {
                }
            }),
                new ExecuteAction(() =>
            {
                try
                {
                    this.Window.ClearFlags(screenFlags);
                    var attributes = new WindowManagerLayoutParams();
                    attributes.CopyFrom(this.Window.Attributes);
                    attributes.ScreenBrightness = -1f;
                    this.Window.Attributes      = attributes;
                }
                catch
                {
                }
            }));


            SimpleIoc.Default.Register <ITurnOnOffScreen>(() => turnOnOffScreen, true);

            PhoneCallTimer pct = new PhoneCallTimer(this.ApplicationContext);

            SimpleIoc.Default.Register <IReactOnCall>(() => pct, true);
            SimpleIoc.Default.Register <INotifiedOnCalling>(() => pct, true);

            ForceHangup fh = new ForceHangup();

            fh.Register(this.ForceHangup);
            SimpleIoc.Default.Register <IForceHangup>(() => fh, true);

            ReadContacts rc = new ReadContacts();

            rc.OnFinished += ReadContactsFinished;
            rc.Execute(this);
            SimpleIoc.Default.Register <ReadContacts>(() => rc, true);

            CallNumber callNumber = new CallNumber();

            callNumber.Register(this.Dial, this.CanDial);
            SimpleIoc.Default.Register <ICallNumber>(() => callNumber, true);

            SimpleIoc.Default.Register <IAudioRecorder>(() => new AudioRecorderViewModel(), true);

            SimpleIoc.Default.Register <MainViewModel>(true);
            pct.Register(OnHangUp);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.Login_SignUpUsingFacebook_DialogAdapter, null, false);

            Dialog.Window.RequestFeature(WindowFeatures.NoTitle);

            FrameLayout    Container      = v.FindViewById <FrameLayout>(Resource.Id.frameLayout1);
            RelativeLayout Frame          = v.FindViewById <RelativeLayout>(Resource.Id.relativeLayout2);
            TextView       NumeUtilizator = v.FindViewById <TextView>(Resource.Id.textView1);
            ImageView      PozaUtilizator = v.FindViewById <ImageView>(Resource.Id.imageView1);
            ImageView      LeftArrow      = v.FindViewById <ImageView>(Resource.Id.imageView2);
            ImageView      RightArrow     = v.FindViewById <ImageView>(Resource.Id.imageView3);

            ActualFragment = v.FindViewById <TextView>(Resource.Id.textView2);

            SetTypeface.Normal.SetTypeFace(Activity, ActualFragment);
            SetTypeface.Normal.SetTypeFace(Activity, NumeUtilizator);

            HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(DateUtilizatorNou[5]);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            ProfilePic          = BitmapFactory.DecodeStream(response.GetResponseStream());
            NumeUtilizator.Text = DateUtilizatorNou[0] + " " + DateUtilizatorNou[1];
            PozaUtilizator.SetImageDrawable(new BitmapDrawable(Activity.Resources, RoundedBitmap.MakeRound(ProfilePic, ProfilePic.Height / 2)));

            Login_SignUpUsingFacebook_NumarTelefon NumarTelefon_Fragment = new Login_SignUpUsingFacebook_NumarTelefon();
            Login_SignUpUsingFacebook_TipCont      TipCont_Fragment      = new Login_SignUpUsingFacebook_TipCont();
            Login_SignUpUsingFacebook_Parola       Parola_Fragment       = new Login_SignUpUsingFacebook_Parola();

            Frags = new Fragment[] {
                NumarTelefon_Fragment,
                TipCont_Fragment,
                Parola_Fragment
            };

            var trans = ChildFragmentManager.BeginTransaction();

            trans.Add(Container.Id, Parola_Fragment, "Parola");
            trans.Add(Container.Id, TipCont_Fragment, "TipCont");
            trans.Add(Container.Id, NumarTelefon_Fragment, "NumarTelefon");
            trans.Hide(Parola_Fragment);
            trans.Hide(TipCont_Fragment);
            trans.Commit();

            WindowManagerLayoutParams lp = new WindowManagerLayoutParams();

            lp.CopyFrom(Dialog.Window.Attributes);
            lp.Height = Frame.LayoutParameters.Height;
            lp.Width  = Frame.LayoutParameters.Width;
            lp.Alpha  = 0.8f;

            Dialog.SetCanceledOnTouchOutside(true);
            Dialog.Show();

            Dialog.Window.Attributes = lp;

            RightArrow.Click += RightArrow_Click;
            LeftArrow.Click  += LeftArrow_Click;

            return(v);
        }
        public override bool ShouldOverrideUrlLoading(WebView view, string url)
        {
            if (!external)
            {
                if (App.FUNCTIONS.ConnectedToNetwork(App.STATE.Context))
                {
                    Console.WriteLine(url);
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Timeout = 80000;

                    try
                    {
                        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        {
                            Dialog dialog = new Dialog(App.STATE.Activity);

                            // If image
                            if (url.Contains("/mp/"))
                            {
                                dialog = App.FUNCTIONS.PresentationUrlDialog(App.STATE.Activity, url);
                            }
                            // If html
                            else
                            {
                                string html    = string.Empty;
                                string html2   = string.Empty;
                                string title   = string.Empty;
                                string pattern = "(<div id=\"main\">)(.*?)(<div id=\"contentFooter\">)";

                                Stream       stream = response.GetResponseStream();
                                StreamReader reader = new StreamReader(stream);
                                html = reader.ReadToEnd();

                                //////////////////////////////////////////////////////////////////////////
                                // ARTICLE TITLE
                                //////////////////////////////////////////////////////////////////////////
                                foreach (Match match in Regex.Matches(html, "(<title>)(.*?)(</title>)", RegexOptions.Singleline))
                                {
                                    title = match.Groups[2].Value.Replace("&mdash;", "—");
                                }

                                //////////////////////////////////////////////////////////////////////////
                                // ARTICLE CONTENT
                                //////////////////////////////////////////////////////////////////////////
                                foreach (Match match in Regex.Matches(html, pattern, RegexOptions.Singleline))
                                {
                                    html = match.Groups[2].Value;
                                    html = html.Replace("/en", "http://m.wol.jw.org/en");

                                    html2 = html;

                                    html = @"<html>
                                                <head>
                                                    <meta name='viewport' content='width=320' />
                                                    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                                                    <link href='css/wol.css' type='text/css' rel='stylesheet' />
                                                </head>
                                                <body class='calibre'>
                                                    <div class='body' id='content'>" + html + @"</div>
                                                    <script src='http://wol.jw.org/js/jquery.min.js'></script>
                                                    <script src='http://wol.jw.org/js/underscore-min.js'></script>
                                                    <script src='http://wol.jw.org/js/wol.modernizr.min.js'></script>
                                                    <script src='http://wol.jw.org/js/startup.js'></script>
                                                    <script src='http://wol.jw.org/js/mediaelement-and-player.min.js'></script>
                                                    <script src='http://wol.jw.org/js/spin.min.js'></script>
                                                    <script src='http://wol.jw.org/js/wol.mobile.min.js'></script>
                                                    <script src='http://wol.jw.org/js/home.js'></script>
                                                </body>
                                            </html>";
                                }

                                //////////////////////////////////////////////////////////////////////////
                                // GET ANNOTATION IF ACTIVATED IN PREFERENCES
                                //////////////////////////////////////////////////////////////////////////
                                if (App.STATE.Preferences.GetBoolean("pinyinReferences", false) && url.Contains("chs"))
                                {
                                    HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("http://mandarinspot.com/annotate?text=" + App.FUNCTIONS.RemoveHTMLTags(html2));
                                    request2.Timeout = 80000;
                                    try
                                    {
                                        using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse())
                                        {
                                            Stream       stream2 = response2.GetResponseStream();
                                            StreamReader reader2 = new StreamReader(stream2);
                                            html2 = reader2.ReadToEnd();

                                            string js = string.Empty;
                                            foreach (Match m in Regex.Matches(html2, @"(<script type=""text/javascript"">)(.*?)(</script>)", RegexOptions.Singleline))
                                            {
                                                js += m.Value.Replace("#da0", "#dd0033");
                                            }

                                            html2 = html2.Replace("<br />            <br />	    <br />		        <br />				        ", "");
                                            html2 = html2.Replace("<br />    <br />        <br />            <br />	    <br />				        ", "");
                                            html2 = html2.Replace("<br />				    <br />    <br />						", "<br />");
                                            html2 = html2.Replace("<br />				    <br /><br />    <br /><br />	    <br />				        ", "<p>");
                                            //html2 = html2.Replace("<br />", "");

                                            string pattern2 = @"(<div id=""annotated"">)(.*?)(<div class=""mid"">)";
                                            foreach (Match match in Regex.Matches(html2, pattern2, RegexOptions.Singleline))
                                            {
                                                html2 = @"<html>
                                                            <head>
                                                                <meta name='viewport' content='width=320' />
                                                                <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                                                                <style type='text/css'>
                                                                    #tip{border:1px solid #332f2f;background-color:#ccc8c8;padding:4px;font:normal 80% sans-serif,arial;z-index:10001;visibility:hidden;position:absolute;_width:15ex;}
                                                                    .ann{cursor:default;z-index:99;}
                                                                    .iann{color:#535353;text-align:center;white-space:nowrap;display:-moz-inline-box;display:inline-table;display:inline-block;vertical-align:bottom;}
                                                                    .sann{margin:0 0.3ex;}
                                                                    .nann{vertical-align:bottom;}
                                                                    .py{font-size:80%;color:#4477a1;display:table-row;}
                                                                    .zy{font-size:70%;color:#4477a1;display:table-row;}
                                                                    .zh{display:table-row;}
                                                                </style>" + js +
                                                        @"</head>
                                                            <body>
                                                                <div id='content'>
                                                                <div id='tip' style='text-align: center'></div>
                                                                <div id='annotated'>" + match.Groups[2].Value + @"</div>
                                                            </body>
                                                        </html>";
                                            }

                                            html = html2;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Toast.MakeText(App.STATE.Context, "Sorry, there was an error loading the content. " + ex.Message, ToastLength.Long).Show();
                                    }
                                }

                                // References
                                if (!App.STATE.Preferences.GetBoolean("references", true))
                                {
                                    html = html.Replace("class='fn'", "class='fn' style='display: none;'").Replace("class='mr'", "class='mr' style='display: none;'");
                                }

                                // Load in webview
                                //view.LoadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);

                                // Load in dialog
                                dialog = App.FUNCTIONS.PresentationDialog(App.STATE.Activity, title, html);
                            }

                            dialog.Show();

                            // Set dialog width to width of screen
                            WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams();
                            layoutParams.CopyFrom(dialog.Window.Attributes);
                            layoutParams.Width       = WindowManagerLayoutParams.MatchParent;
                            dialog.Window.Attributes = layoutParams;
                        }
                    }
                    catch (Exception ex)
                    {
                        Toast.MakeText(App.STATE.Context, "Sorry, there was an error loading the content. " + ex.Message, ToastLength.Long).Show();
                    }
                }
                else
                {
                    Toast.MakeText(App.STATE.Context, "Cannot connect to Watchtower ONLINE Library. Consider device connection.", ToastLength.Long).Show();
                }

                return(true);
            }
            else
            {
                Intent browserIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(url));
                App.STATE.Activity.StartActivity(browserIntent);

                return(base.ShouldOverrideUrlLoading(view, url));
            }
        }
Exemplo n.º 30
0
        public override Task <int?> ShowDialogAsync(
            object body,
            IEnumerable <object> buttons,
            string caption = null,
            int defaultAcceptButtonIndex      = -1,
            DialogController dialogController = null)
        {
            Context context = ResolveContext();

            AlertDialog.Builder builder = CreateAlertDialogBuilder(context, DialogStyle);

            if (dialogController != null && !dialogController.Cancellable)
            {
                builder.SetCancelable(false);
            }

            if (!string.IsNullOrWhiteSpace(caption))
            {
                var stringParserService = Dependency.Resolve <IStringParserService>();
                var parsedText          = stringParserService.Parse(caption);
                builder.SetTitle(parsedText);
            }

            var bodyView = body as View;

            if (bodyView != null)
            {
                builder.SetView(bodyView);
            }
            else
            {
                var sequence = body as ICharSequence;
                if (sequence != null)
                {
                    builder.SetMessage(sequence);
                }
                else
                {
                    string bodyText = body?.ToString();

                    if (!string.IsNullOrWhiteSpace(bodyText))
                    {
                        var stringParserService = Dependency.Resolve <IStringParserService>();
                        var parsedText          = stringParserService.Parse(bodyText);
                        ;                                               builder.SetMessage(parsedText);
                    }
                }
            }

            List <string> labels     = null;
            int           labelCount = 0;

            if (buttons != null)
            {
                labels = new List <string>();
                foreach (var button in buttons)
                {
                    string buttonText = button.ToString();
                    labels.Add(buttonText);
                }

                labelCount = labels.Count;
            }

            var resultSource = new TaskCompletionSource <int?>();

            if (labelCount >= 2)
            {
                builder.SetNegativeButton(labels[0],
                                          (dialog, whichButton) =>
                {
                    resultSource.TrySetResult(0);
                });

                for (int i = 1; i < labelCount - 1; i++)
                {
                    int iClosureCopy = i;
                    builder.SetNeutralButton(labels[i],
                                             (dialog, whichButton) =>
                    {
                        resultSource.TrySetResult(iClosureCopy);
                    });
                }

                builder.SetPositiveButton(labels[labelCount - 1],
                                          (dialog, whichButton) =>
                {
                    int selectedIndex = labelCount - 1;
                    resultSource.TrySetResult(selectedIndex);
                });
            }
            else
            {
                if (labelCount == 1)
                {
                    string buttonLabel = labels[0];

                    builder.SetPositiveButton(buttonLabel,
                                              (dialog, whichButton) =>
                    {
                        resultSource.TrySetResult(0);
                    });
                }
            }

            builder.NothingSelected += (sender, e) => resultSource.TrySetResult(-1);

            Android.App.Application.SynchronizationContext.Post((object state) =>
            {
                try
                {
                    Interlocked.Increment(ref openDialogCount);

                    AlertDialog alertDialog = builder.Show();

                    var dialogStyles = dialogController?.DialogStyles;

                    if (dialogStyles.HasValue)
                    {
                        var styles    = dialogStyles.Value;
                        var lp        = new WindowManagerLayoutParams();
                        Window window = alertDialog.Window;
                        lp.CopyFrom(window.Attributes);

                        var stretchHorizontal = (styles & DialogStyles.StretchHorizontal) == DialogStyles.StretchHorizontal;
                        var stretchVertical   = (styles & DialogStyles.StretchVertical) == DialogStyles.StretchVertical;
                        lp.Width          = stretchHorizontal ? ViewGroup.LayoutParams.MatchParent : lp.Width;
                        lp.Height         = stretchVertical ? ViewGroup.LayoutParams.MatchParent : lp.Height;                //ViewGroup.LayoutParams.WrapContent;
                        window.Attributes = lp;
                    }

                    //var backgroundImage = dialogController?.BackgroundImage;
                    //
                    //if (backgroundImage != null)
                    //{
                    //	//Window window = alertDialog.Window;
                    //	//window.SetBackgroundDrawable(backgroundImage);;
                    //}

                    alertDialog.CancelEvent += delegate
                    {
                        resultSource.TrySetResult(-1);
                    };

                    if (dialogController != null)
                    {
                        dialogController.CloseRequested += delegate
                        {
                            if (alertDialog.IsShowing)
                            {
                                alertDialog.Cancel();
                            }
                        };
                    }

                    /* Subscribing to the DismissEvent to set the result source
                     * is unnecessary as other events are always raised.
                     * The DismissEvent is, however, always raised and thus
                     * we place the bodyView removal code here. */
                    alertDialog.DismissEvent += (sender, args) =>
                    {
                        Interlocked.Decrement(ref openDialogCount);
                        builder.SetView(null);

                        try
                        {
                            (bodyView?.Parent as ViewGroup)?.RemoveView(bodyView);
                        }
                        catch (ObjectDisposedException)
                        {
                            /* View was already disposed in user code. */
                        }
                        catch (Exception ex)
                        {
                            var log = Dependency.Resolve <ILog>();
                            log.Debug("Exception raised when removing view from alert.", ex);
                        }
                    };

                    if (AlertDialogDividerColor.HasValue)
                    {
                        var resources     = context.Resources;
                        int id            = resources.GetIdentifier("titleDivider", "id", "android");
                        View titleDivider = alertDialog.FindViewById(id);
                        if (titleDivider != null)
                        {
                            var color = AlertDialogDividerColor.Value;
                            if (color == Color.Transparent)
                            {
                                titleDivider.Visibility = ViewStates.Gone;
                            }

                            titleDivider.SetBackgroundColor(color);
                        }
                    }

                    if (AlertDialogTitleColor.HasValue)
                    {
                        var resources = context.Resources;
                        int id        = resources.GetIdentifier("alertTitle", "id", "android");
                        var textView  = alertDialog.FindViewById <TextView>(id);
                        if (textView != null)
                        {
                            var color = AlertDialogTitleColor.Value;
                            textView.SetTextColor(color);
                        }
                    }

                    if (AlertDialogBackgroundColor.HasValue)
                    {
                        var v = bodyView ?? alertDialog.ListView;
                        v.SetBackgroundColor(AlertDialogBackgroundColor.Value);
                    }
                }
                catch (WindowManagerBadTokenException ex)
                {
                    /* See http://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window*/
                    resultSource.SetException(new Exception(
                                                  "Unable to use the Application.Context object to create a dialog. Please either set the Context property of this DialogService or register the current activity using Dependency.Register<Activity>(myActivity)", ex));
                }
            }, null);

            return(resultSource.Task);
        }