public override void OnCreate()
        {
            base.OnCreate();

            floatingView                 = LayoutInflater.From(this).Inflate(Resource.Layout.floatingWidget, null);
            closeFloatingView            = LayoutInflater.From(this).Inflate(Resource.Layout.closeWidget, null);
            closeFloatingView.Visibility = ViewStates.Invisible;

            SetTouchListener();

            closeLayoutParams = new WindowManagerLayoutParams(ViewGroup.LayoutParams.WrapContent,
                                                              ViewGroup.LayoutParams.WrapContent,
                                                              WindowManagerTypes.ApplicationOverlay,
                                                              WindowManagerFlags.NotFocusable,
                                                              Format.Translucent)
            {
                Gravity = GravityFlags.Center
            };

            windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            windowManager.AddView(closeFloatingView, closeLayoutParams);

            layoutParams = new WindowManagerLayoutParams(ViewGroup.LayoutParams.WrapContent,
                                                         ViewGroup.LayoutParams.WrapContent,
                                                         WindowManagerTypes.ApplicationOverlay,
                                                         WindowManagerFlags.NotFocusable,
                                                         Format.Translucent)
            {
                Gravity = GravityFlags.Left | GravityFlags.Top
            };

            windowManager.AddView(floatingView, layoutParams);

            SetCenter();
        }
Exemplo n.º 2
0
        //Metodo principal en el cual se creara el servicio y pintaremos nuestro imageview sobre la ventana
        public override void OnCreate()
        {
            base.OnCreate();



            windowManager = GetSystemService("window").JavaCast <IWindowManager>();

            chatHead = new ImageView(this);

            chatHead.SetImageResource(Resource.Drawable.IcNotificationClearAll);

            chatHead.SetOnTouchListener(this);

            param = new WindowManagerLayoutParams(
                WindowManagerLayoutParams.WrapContent,
                WindowManagerLayoutParams.WrapContent,
                WindowManagerTypes.Phone,
                WindowManagerFlags.NotFocusable
                | WindowManagerFlags.NotTouchModal
                | WindowManagerFlags.WatchOutsideTouch
                | WindowManagerFlags.LayoutNoLimits,
                Format.Translucent);

            param.Gravity = GravityFlags.Top | GravityFlags.Left;

            param.X = 0;

            param.Y = 100;

            windowManager.AddView(chatHead, param);
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            base.OnCreate(bundle);
            this.Window.AddFlags(WindowManagerFlags.Fullscreen);
            this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
            this.Window.AddFlags(WindowManagerFlags.DismissKeyguard);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            var sp   = PreferenceManager.GetDefaultSharedPreferences(this);
            var edit = sp.Edit();

            edit.PutBoolean(PrefKioskMode, true);
            edit.Commit();

            WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();

            localLayoutParams.Type    = WindowManagerTypes.SystemError;
            localLayoutParams.Gravity = GravityFlags.Top;
            localLayoutParams.Flags   = WindowManagerFlags.NotFocusable |
                                        WindowManagerFlags.NotTouchModal | WindowManagerFlags.LayoutInScreen;
            localLayoutParams.Width  = WindowManagerLayoutParams.MatchParent;
            localLayoutParams.Height = (int)(50 * Resources.DisplayMetrics.ScaledDensity);
            localLayoutParams.Format = Format.Transparent;

            IWindowManager  manager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            CustomViewGroup view    = new CustomViewGroup(this);

            manager.AddView(view, localLayoutParams);
        }
Exemplo n.º 4
0
        private void Start()
        {
            _floatingView = LayoutInflater.From(this).Inflate(Resource.Layout.layout_floating_widget, null);
            SetTouchListener();

            WindowManagerTypes managerType;

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                managerType = WindowManagerTypes.ApplicationOverlay;
            }
            else
            {
                managerType = WindowManagerTypes.Phone;
            }

            _layoutParams = new WindowManagerLayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent,
                managerType,
                WindowManagerFlags.NotFocusable,
                Format.Translucent)
            {
                Gravity = GravityFlags.Left | GravityFlags.Center
            };

            _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            _windowManager.AddView(_floatingView, _layoutParams);
            //_expandedContainer = _floatingView.FindViewById(Resource.Id.flyout);
            txtSpeed = _floatingView.FindViewById(Resource.Id.txtSpeed) as TextView;
            txtKmh   = _floatingView.FindViewById(Resource.Id.txtKmh) as TextView;
        }
Exemplo n.º 5
0
        public override void OnCreate()
        {
            base.OnCreate();
            WindowManagerTypes layoutType = WindowManagerTypes.Phone;

            if (Build.VERSION.SdkInt > BuildVersionCodes.NMr1)      //Nougat 7.1
            {
                layoutType = WindowManagerTypes.ApplicationOverlay; //Android Oreo does not allow to add windows of WindowManagerTypes.Phone
            }

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

            var layoutInflater = LayoutInflater.From(this);

            View view = null;

            //view =  (LinearLayout)layoutInflater.Inflate(Resource.Layout.Floating, null); //Replace with your custom axml view in resources.
            floatingView = view as LinearLayout;

            int width = 200;
            var floatingNotificationWidth = TypedValue.ApplyDimension(ComplexUnitType.Dip, width, Resources.DisplayMetrics); //To fit all screen sizes.

            WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams
            {
                Width   = (int)floatingNotificationWidth,
                Height  = ViewGroup.LayoutParams.WrapContent,
                Type    = layoutType,
                Flags   = WindowManagerFlags.NotFocusable,                            //If you are using it on immersive apps, this will avoid that app from losing the Immersive mode.
                Format  = Format.Translucent,
                Gravity = GravityFlags.CenterHorizontal | GravityFlags.CenterVertical //Location of the view.
            };

            windowManager.AddView(floatingView, layoutParams);
        }
Exemplo n.º 6
0
        /// <summary>
        /// OverrayするViewの描写範囲設定とフォントサイズを設定し描写
        /// </summary>
        public void OverrayViewReSet()
        {
            // カスタムViewにアダプターをセット(フォントの大きさ変更のため)
            customMemoAdapter = new CustomMemoAdapter(this, customViewItem, getFontSize());
            listView.Adapter  = customMemoAdapter;

            // 描写位置決定のため画面サイズを取得
            var psize = new Android.Graphics.Point();

            WindowManager.DefaultDisplay.GetSize(psize);

            // 重ね合わせる画面を指定
            param = new WindowManagerLayoutParams(
                (int)(psize.X * 0.8),
                (int)(psize.Y * 0.9),
                WindowManagerTypes.ApplicationOverlay, // タッチ操作ありのため
                WindowManagerFlags.Fullscreen,         //フルスクリーン表示
                Android.Graphics.Format.Translucent    //半透明
                )
            {
                Gravity = GravityFlags.Top
            };

            // Viewを画面上に重ね合わせする
            WindowManager.AddView(view, param);
            // オーバーレイViewの存在フラグを立てる
            _isViewPresenceCheck = true;
        }
        public bool Start(Intent MediaProjectionToken = null)
        {
            if (ServiceStarted)
            {
                return(false);
            }

            if (MediaProjectionToken != null)
            {
                _mediaProjection = MediaProjectionManager.GetMediaProjection((int)Result.Ok, MediaProjectionToken);
            }

            _imageReader = ImageReader.NewInstance(_screenWidth, _screenHeight, (ImageFormatType)1, 2);
            _imgListener = new ImgListener(_imageReader);
            _imageReader.SetOnImageAvailableListener(_imgListener, null);

            SetupVirtualDisplay();

            _windowManager.AddView(_layout, _layoutParams);
            ServiceStarted = true;

            ShowForegroundNotification();

            return(true);
        }
        private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e)
        {
            if (!AccessibilityHelpers.OverlayPermitted())
            {
                System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted");
                Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show();
                return;
            }

            if (_overlayView != null || _anchorNode != null || _overlayAnchorObserverRunning)
            {
                CancelOverlayPrompt();
            }

            if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000)
            {
                return;
            }

            var uri = AccessibilityHelpers.GetUri(root);

            if (string.IsNullOrWhiteSpace(uri))
            {
                return;
            }

            var layoutParams   = AccessibilityHelpers.GetOverlayLayoutParams();
            var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(root, e.Source);

            layoutParams.X = anchorPosition.X;
            layoutParams.Y = anchorPosition.Y;

            if (_windowManager == null)
            {
                _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            }

            var intent = new Intent(this, typeof(AccessibilityActivity));

            intent.PutExtra("uri", uri);
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop);

            _overlayView        = AccessibilityHelpers.GetOverlayView(this);
            _overlayView.Click += (sender, eventArgs) =>
            {
                CancelOverlayPrompt();
                StartActivity(intent);
            };

            _anchorNode  = e.Source;
            _lastAnchorX = anchorPosition.X;
            _lastAnchorY = anchorPosition.Y;

            _windowManager.AddView(_overlayView, layoutParams);

            System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Added at X:{0} Y:{1}",
                                               layoutParams.X, layoutParams.Y);

            StartOverlayAnchorObserver();
        }
Exemplo n.º 9
0
		//Metodo principal en el cual se creara el servicio y pintaremos nuestro imageview sobre la ventana
		public override void OnCreate ()
		{
			base.OnCreate ();
			//incializaremos en windowmanager obteniendo el servicio directo de la ventan del sistema y haremos
			//un casting de tipo JavaCast<IWindowManager>
			windowManager = GetSystemService ("window").JavaCast<IWindowManager> ();
			//inicializaremos nuestro imageview dandole los atributos de nuestra clase para que obtenga los metodos
			//de touch
			chatHead = new ImageView(this);
			//definimos la imagen del imageview
			chatHead.SetImageResource (Resource.Drawable.ic_launcher);
			//Asignamos el listener del touch nuestra clase del tipo View.IOnTouchListener
			chatHead.SetOnTouchListener (this);
			//instanciamos los parametros que necesitamos para poder tomar la pantalla y asi poder mostrar nuestro imageview
			param = new WindowManagerLayoutParams(
				WindowManagerLayoutParams.WrapContent,
				WindowManagerLayoutParams.WrapContent,
				WindowManagerTypes.Phone,
				WindowManagerFlags.NotFocusable,
				Format.Translucent);
			//Agregamos la propiedad de gravedad en la parte de arriba hacia la izquieda
			param.Gravity = GravityFlags.Top | GravityFlags.Left;
			//Asignamos la posicion X del imageview
			param.X = 0;
			//Asignamos la posicion Y del imageview
			param.Y = 100;
			//Agregamos una vista a la ventana del sistema con nuestro imageview y los parametros generados
			windowManager.AddView (chatHead, param);
		}
        public override void OnCreate()
        {
            base.OnCreate();

            mFloatingView = LayoutInflater.From(this).Inflate(Resource.Layout.floating_widget, null, false);

            var layoutParams = new WindowManagerLayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent,
                WindowManagerTypes.Phone,
                WindowManagerFlags.NotFocusable,
                Format.Translucent
                );


            mWindowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            mWindowManager.AddView(mFloatingView, layoutParams);

            collapsedView = mFloatingView.FindViewById(Resource.Id.floating_widget_layout_collapsed);
            expandedView  = mFloatingView.FindViewById(Resource.Id.floating_widget_layout_expanded);

            var collapseButton = expandedView.FindViewById <RelativeLayout>(Resource.Id.widget_collapse_button);

            collapseButton.SetOnClickListener(this);

            var touchListener = new FloatingWidgetTouchListener(mWindowManager, mFloatingView, collapsedView, expandedView);

            mFloatingView.FindViewById(Resource.Id.floating_widget_layout).SetOnTouchListener(touchListener);
        }
Exemplo n.º 11
0
 //Metodo principal en el cual se creara el servicio y pintaremos nuestro imageview sobre la ventana
 public override void OnCreate()
 {
     base.OnCreate();
     //incializaremos en windowmanager obteniendo el servicio directo de la ventan del sistema y haremos
     //un casting de tipo JavaCast<IWindowManager>
     windowManager = GetSystemService("window").JavaCast <IWindowManager> ();
     //inicializaremos nuestro imageview dandole los atributos de nuestra clase para que obtenga los metodos
     //de touch
     chatHead = new ImageView(this);
     //definimos la imagen del imageview
     chatHead.SetImageResource(Resource.Drawable.ic_launcher);
     //Asignamos el listener del touch nuestra clase del tipo View.IOnTouchListener
     chatHead.SetOnTouchListener(this);
     //instanciamos los parametros que necesitamos para poder tomar la pantalla y asi poder mostrar nuestro imageview
     param = new WindowManagerLayoutParams(
         WindowManagerLayoutParams.WrapContent,
         WindowManagerLayoutParams.WrapContent,
         WindowManagerTypes.Phone,
         WindowManagerFlags.NotFocusable,
         Format.Translucent);
     //Agregamos la propiedad de gravedad en la parte de arriba hacia la izquieda
     param.Gravity = GravityFlags.Top | GravityFlags.Left;
     //Asignamos la posicion X del imageview
     param.X = 0;
     //Asignamos la posicion Y del imageview
     param.Y = 100;
     //Agregamos una vista a la ventana del sistema con nuestro imageview y los parametros generados
     windowManager.AddView(chatHead, param);
 }
Exemplo n.º 12
0
        //

        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            Intent _intent = new Intent(Settings.ActionUsageAccessSettings);

            StartActivity(_intent);

            // ViewがすでにあるならRemoveする
            if (_isOverlayViewPresenceCheck)
            {
                _windowManager.RemoveView(_overlayView);
                _isOverlayViewPresenceCheck = false;
            }

            //
            UsageStatsManager usageStatsManager1 = (UsageStatsManager)_context.GetSystemService(USAGE_STATS_SERVICE);

            currentYear1     = DateTime.Now.Year; // Calendar.GetInstance().Get(Calendar.Year);
            queryUsageStats1 = usageStatsManager1.QueryUsageStats(UsageStatsInterval.Yearly, currentYear1 - 1, currentYear1);
            queryUsageStats2 = usageStatsManager1.QueryEvents(currentYear1 - 1, currentYear1);
            //

            _windowManager = _context.GetSystemService(WindowService).JavaCast <IWindowManager>();
            var layoutInflater = LayoutInflater.From(_context);

            _overlayView = layoutInflater.Inflate(Resource.Layout.overlay_test_layout, null);

            // 画面サイズを取得
            var psize = new Android.Graphics.Point();

            _windowManager.DefaultDisplay.GetSize(psize);

            // オーバーレイ範囲指定 & オーバーレイ設定
            var param = new WindowManagerLayoutParams(
                (int)(psize.X * 0.9),
                (int)(psize.Y * 0.4),               // なんかいい感じに範囲を指定
                WindowManagerTypes.SystemAlert,
                WindowManagerFlags.Fullscreen,      // なんかいい感じに属性を追加
                Android.Graphics.Format.Translucent // 半透明とか
                )
            {
                Gravity = GravityFlags.Top
            };

            // OverlayViewのクリックイベントを登録
            var closeButton = _overlayView.FindViewById <Button>(Resource.Id.closeButton);

            closeButton.Click += CloseButton_Click;
            var testButton = _overlayView.FindViewById <Button>(Resource.Id.testButton);

            testButton.Click += (sender, args) => TestMethod();

            // Viewを画面上に重ね合わせする
            _windowManager.AddView(_overlayView, param);
            _isOverlayViewPresenceCheck = true;

            return(StartCommandResult.NotSticky);
        }
Exemplo n.º 13
0
        public bool Start(Intent MediaProjectionToken = null)
        {
            if (ServiceStarted)
            {
                return false;
            }

            if (!RegisterScreenshot(MediaProjectionToken))
                return false;

            if (!RegisterGestures())
                return false;

            _windowManager.AddView(_highlightView, _highlightLayoutParams);
            _windowManager.AddView(_layout, _layoutParams);

            ServiceStarted = true;

            ShowForegroundNotification();

            return true;
        }
Exemplo n.º 14
0
        public override void OnCreate()
        {
            base.OnCreate();
            mChatHeadView = LayoutInflater.From(CrossCurrentActivity.Current.Activity).Inflate(Resource.Layout.bubble_layout, null);


            // create a windowManager object - relatively easy
            mWindowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();


            WindowManagerTypes LAYOUT_FLAG;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                LAYOUT_FLAG = WindowManagerTypes.ApplicationOverlay;//mWindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
            }
            else
            {
                LAYOUT_FLAG = WindowManagerTypes.Phone;
            }

            paramss = new WindowManagerLayoutParams(
                WindowManagerLayoutParams.WrapContent,
                WindowManagerLayoutParams.WrapContent,
                LAYOUT_FLAG,
                WindowManagerFlags.NotFocusable,
                Android.Graphics.Format.Translucent);
            paramss.Gravity = GravityFlags.Top | GravityFlags.Left;
            paramss.X       = 0;
            paramss.Y       = 100;



            mWindowManager.AddView(mChatHeadView, paramss);


            var chatHeadImage = mChatHeadView.FindViewById <CircleImageView>(Resource.Id.chat_head_profile_iv);
            var fileDesc      = Assets.OpenFd("messenger_tone.mp3");

            var bitmap = GetDrawable(Image);

            chatHeadImage.SetImageDrawable(bitmap);
            chatHeadImage.SetOnTouchListener(this);
            chatHeadImage.Click += ChatHeadImage_Click;
            MediaPlayer mp = new MediaPlayer();

            mp.Reset();
            mp.SetDataSource(fileDesc);
            mp.Prepare();
            mp.Start();
        }
Exemplo n.º 15
0
        public void DisplayAdvertising() //funcion que muestra la publicidad, es un layout inflado
        {
            try
            {
                var layout = VideoViewInstance(); //devuelve la vista con el video incorporado

                _displayParam = new WindowManagerLayoutParams(
                    WindowManagerLayoutParams.MatchParent,
                    WindowManagerLayoutParams.MatchParent,
                    WindowManagerTypes.Phone,
                    WindowManagerFlags.Fullscreen, Format.Transparent);
                _displayParam.Gravity = GravityFlags.Center;

                if (transparentLayout != null)
                {
                    _windowManager.RemoveViewImmediate(transparentLayout);
                }

                _windowManager.AddView(layout, _displayParam);

                mVideoView.Start(); //esto es asincrono

                mVideoView.Prepared += delegate
                {
                    mButton.Visibility = ViewStates.Visible;
                };

                mVideoView.Completion += delegate
                {
                    mVideoView.StopPlayback();
                    mVideoView.SetVideoURI(Android.Net.Uri.Parse(GetVideoUrl.GetUrlBySection(_configuration.GetConfigurationSection())));
                    mVideoView.Start();
                };
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 16
0
        public override void OnCreate()
        {
            base.OnCreate();
            InitB2World();
            hc.BaseAddress  = new Uri("http://192.168.1.69");
            wm              = this.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            overlayedButton = new ImageButton(this);
            overlayedButton.SetImageResource(Resource.Drawable.Snow);
            overlayedButton.SetBackgroundColor(Color.Transparent);
            overlayedButton.SetColorFilter(Color.White);

            overlayedButton.ScaleX = 0.7f;
            overlayedButton.ScaleY = 0.7f;
            overlayedButton.SetOnTouchListener(this);
            overlayedButton.SetOnClickListener(this);
            overlayedButton.SetOnLongClickListener(this);
            var param = new WindowManagerLayoutParams(
                WindowManagerLayoutParams.WrapContent,
                WindowManagerLayoutParams.WrapContent,
                //WindowManagerTypes.SystemOverlay,
                WindowManagerTypes.SystemAlert,
                WindowManagerFlags.Fullscreen |
                WindowManagerFlags.WatchOutsideTouch |
                WindowManagerFlags.AllowLockWhileScreenOn |
                WindowManagerFlags.NotTouchModal |
                WindowManagerFlags.LayoutInScreen |
                WindowManagerFlags.NotFocusable |
                WindowManagerFlags.AltFocusableIm,
                Android.Graphics.Format.Transparent);

            param.Gravity = GravityFlags.Left | GravityFlags.Top;
            param.X       = 100;
            param.Y       = 150;
            wm.AddView(overlayedButton, param);
            System.Timers.Timer timer = new System.Timers.Timer(5);

            timer.Elapsed += (o, e) =>
            {
                Rotate();
            };
            timer.Start();
            //Task.Run(() =>
            //{
            //    while (true)
            //        Update();
            //});
        }
        /// <summary>
        /// Create a window containing this view and show it.
        /// </summary>
        /// <param name="windowToken"> obtained from v.getWindowToken() from one of your views </param>
        /// <param name="touchX"> the x coordinate the user touched in screen coordinates </param>
        /// <param name="touchY"> the y coordinate the user touched in screen coordinates </param>
        public void Show(IBinder windowToken, int touchX, int touchY)
        {
            WindowManagerLayoutParams lp;
            Format pixelFormat;

            pixelFormat = Format.Translucent;

            lp = new WindowManagerLayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, touchX - mRegistrationX, touchY - mRegistrationY, WindowManagerTypes.ApplicationSubPanel, WindowManagerFlags.LayoutInScreen | WindowManagerFlags.LayoutNoLimits, pixelFormat);
            /*| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM*/
            //        lp.token = mStatusBarView.getWindowToken();
            lp.Gravity    = GravityFlags.Left | GravityFlags.Top;
            lp.Token      = windowToken;
            lp.Title      = "DragView";
            mLayoutParams = lp;

            mWindowManager.AddView(this, lp);
        }
Exemplo n.º 18
0
        public override void OnCreate()
        {
            base.OnCreate();
            WindowManagerTypes layoutType = WindowManagerTypes.Phone;

            if (Build.VERSION.SdkInt > BuildVersionCodes.NMr1)      //Nougat 7.1
            {
                layoutType = WindowManagerTypes.ApplicationOverlay; //Android Oreo does not allow to add windows of WindowManagerTypes.Phone
            }

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

            var lol = LayoutInflater.From(this);

            floatingNotificationView = (LinearLayout)lol.Inflate(Resource.Layout.FloatingNotification, null);

            int width = 200;
            var floatingNotificationWidth = TypedValue.ApplyDimension(ComplexUnitType.Dip, width, Resources.DisplayMetrics);

            WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams
            {
                Width   = (int)floatingNotificationWidth,
                Height  = ViewGroup.LayoutParams.WrapContent,
                Type    = layoutType,
                Flags   = WindowManagerFlags.NotFocusable | WindowManagerFlags.WatchOutsideTouch,
                Format  = Format.Translucent,
                Gravity = GravityFlags.CenterHorizontal | GravityFlags.CenterVertical
            };

            floatingNotificationView.Visibility = ViewStates.Gone;

            windowManager.AddView(floatingNotificationView, layoutParams);

            floatingNotificationAppName          = floatingNotificationView.FindViewById <TextView>(Resource.Id.floatingappname);
            floatingNotificationWhen             = floatingNotificationView.FindViewById <TextView>(Resource.Id.floatingwhen);
            floatingNotificationTitle            = floatingNotificationView.FindViewById <TextView>(Resource.Id.floatingtitle);
            floatingNotificationText             = floatingNotificationView.FindViewById <TextView>(Resource.Id.floatingtext);
            floatingNotificationActionsContainer = floatingNotificationView.FindViewById <LinearLayout>(Resource.Id.floatingNotificationActions);

            CatcherHelper.NotificationRemoved             += CatcherHelper_NotificationRemoved;
            CatcherHelper.NotificationPosted              += CatcherHelper_NotificationPosted;
            NotificationAdapterViewHolder.ItemClicked     += NotificationAdapterViewHolder_ItemClicked;
            NotificationAdapterViewHolder.ItemLongClicked += NotificationAdapterViewHolder_ItemLongClicked;
            LockScreenActivity.OnActivityStateChanged     += LockScreenActivity_OnActivityStateChanged;
            floatingNotificationView.SetOnTouchListener(this);
        }
Exemplo n.º 19
0
        private void StatusBar()
        {
            WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();

            localLayoutParams.Type    = WindowManagerTypes.SystemError;
            localLayoutParams.Gravity = GravityFlags.Top;
            localLayoutParams.Flags   = WindowManagerFlags.NotFocusable |
                                        WindowManagerFlags.NotTouchModal | WindowManagerFlags.LayoutInScreen;
            localLayoutParams.Width  = WindowManagerLayoutParams.MatchParent;
            localLayoutParams.Height = (int)(50 * Resources.DisplayMetrics.ScaledDensity);
            localLayoutParams.Format = Format.Transparent;

            IWindowManager  manager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            customViewGroup view    = new customViewGroup(this);

            manager.AddView(view, localLayoutParams);
        }
Exemplo n.º 20
0
        public void criarWidget()
        {
            Context context = Android.App.Application.Context;

            mWindowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            mRootLayout    = LayoutInflater.From(context).Inflate(Resource.Layout.service_player, null);
            var mContentContainerLayout = mRootLayout.FindViewById(Resource.Id.root_layout);

            //mContentContainerLayout.SetBackgroundColor(Android.Graphics.Color.Argb(200, 255, 255, 255));
            // Erro de Invalid Cast - Depois a gente vé essa merda!
            //mContentContainerLayout.SetOnTouchListener(new TrayTouchListener(this));
            mContentContainerLayout.Touch += (sender, e) =>
            {
                var me = ((Android.Views.View.TouchEventArgs)e).Event;
                MotionEventActions action = me.ActionMasked;
                switch (action)
                {
                case MotionEventActions.Down:
                case MotionEventActions.Move:
                case MotionEventActions.Up:
                case MotionEventActions.Cancel:
                    this.dragTray(action, (int)me.RawX, (int)me.RawY);
                    break;
                    //default:
                    //    return false;
                }
                //return true;
            };
            mRootLayoutParams = new WindowManagerLayoutParams(
                dpToPixels(TRAY_DIM_X_DP, context.Resources),
                dpToPixels(TRAY_DIM_Y_DP, context.Resources),
                WindowManagerTypes.Phone,
                WindowManagerFlags.NotFocusable | WindowManagerFlags.LayoutNoLimits,
                Android.Graphics.Format.Translucent
                );
            mRootLayoutParams.Gravity = GravityFlags.Top | GravityFlags.Left;
            //mRootLayout.SetBackgroundColor(Android.Graphics.Color.White);
            mWindowManager.AddView(mRootLayout, mRootLayoutParams);
            //var velocidadeRadar = mRootLayout.FindViewById<TextView>(Resource.Id.velocidadeRadar);
            var distanciaRadar = mRootLayout.FindViewById <TextView>(Resource.Id.distanciaRadar);

            //velocidadeRadar.Text = "0 KM/H";
            distanciaRadar.Text = "0 m";
            //mRootLayout.Visibility = ViewStates.Visible;
        }
Exemplo n.º 21
0
        public bool Start(CameraFacing cameraId, GotchaAFrame gotchaAFrameFromCamera)
        {
            bool result = true;

            this.IsStopped            = false;
            this.GotchaAFrameCallback = gotchaAFrameFromCamera;
            try {
                using (Handler handler = new Handler(Looper.MainLooper)) {
                    handler.Post(() => {
                        cameraPreviewCallback = new MyCameraPreviewCallback(PictureDefaultFilename,
                                                                            GotchaAFrameFromCamera);

                        surfaceView = new SurfaceView(Application.Context);

                        windowManager =
                            Application.Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                        WindowManagerLayoutParams parameters = new WindowManagerLayoutParams(
                            1, 1,
                            WindowManagerTypes.SystemOverlay,
                            WindowManagerFlags.WatchOutsideTouch,
                            Android.Graphics.Format.Translucent);

                        surfaceHolder = surfaceView.Holder;

                        surfaceView.SetZOrderOnTop(true);
                        surfaceHolder.SetFormat(Android.Graphics.Format.Translucent);

                        surfaceHolderCallback          = new MySurfaceHolderCallback(surfaceHolder, cameraPreviewCallback);
                        surfaceHolderCallback.cameraId = cameraId;
                        surfaceHolder.AddCallback(surfaceHolderCallback);

                        windowManager.AddView(surfaceView, parameters);
                    });
                }
            }
            catch (Exception e) {
                Log.Error(TAG, "Error: " + e.StackTrace);
                result = false;
            }

            return(result);
        }
Exemplo n.º 22
0
        public void CamInService()
        {
            var layoutParams = new ViewGroup.LayoutParams(100, 100);

            _globalSurface = new SurfaceView(this)
            {
                LayoutParameters = layoutParams
            };
            _globalSurface.Holder.AddCallback(new Prev());
            WindowManagerLayoutParams winparam = new WindowManagerLayoutParams(WindowManagerTypes.SystemAlert);

            winparam.Flags  = WindowManagerFlags.NotTouchModal;
            winparam.Flags |= WindowManagerFlags.NotFocusable;
            winparam.Format = Android.Graphics.Format.Rgba8888;
            winparam.Width  = 1;
            winparam.Height = 1;

            windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            windowManager.AddView(_globalSurface, winparam);
        }
Exemplo n.º 23
0
    private void ShowFloatingWindow()
    {
        WindowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
        LayoutInflater mLayoutInflater = LayoutInflater.From(ApplicationContext);

        floatView = mLayoutInflater.Inflate(Resource.Layout.layout_floating_widget, null);
        floatView.SetBackgroundColor(Color.Argb(15, 0, 0, 0));

        floatView.SetOnTouchListener(this);
        txtResult = floatView.FindViewById <TextView>(Resource.Id.txtDetails);
        ImageView iv1 = floatView.FindViewById <ImageView>(Resource.Id.iv1);
        ImageView iv2 = floatView.FindViewById <ImageView>(Resource.Id.iv2);

        iv1.Click += delegate { Toast.MakeText(ApplicationContext, "Hides Me!", ToastLength.Short).Show(); FloatViewVisibility(false); };
        iv2.Click += delegate { Toast.MakeText(ApplicationContext, "STOPPING SERVICE", ToastLength.Short).Show(); StopFloatingWindowService(); };

        layoutParams = new WindowManagerLayoutParams(
            ViewGroup.LayoutParams.WrapContent,
            ViewGroup.LayoutParams.WrapContent,
            WindowManagerTypes.Phone,
            WindowManagerFlags.NotTouchModal | WindowManagerFlags.NotFocusable | WindowManagerFlags.LayoutInScreen,
            Format.Translucent);

        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            layoutParams.Type = WindowManagerTypes.ApplicationOverlay;
        }
        else
        {
            layoutParams.Type = WindowManagerTypes.Phone;
        }

        layoutParams.Width   = 550;
        layoutParams.X       = 100;
        layoutParams.Y       = 200;
        layoutParams.Gravity = GravityFlags.Center | GravityFlags.Start;

        floatView.Visibility = ViewStates.Invisible;

        WindowManager.AddView(floatView, layoutParams);
    }
Exemplo n.º 24
0
        public override void OnCreate()
        {
            base.OnCreate();

            // inflate the layout
            _floatingView = LayoutInflater.From(this).Inflate(Resource.Layout.floatingWindow_Layout, null);

            // set the params
            _layoutParams = new WindowManagerLayoutParams(
                0,
                0,
                WindowManagerTypes.SystemOverlay,
                WindowManagerFlags.NotFocusable,
                Android.Graphics.Format.Translucent)
            {
                Gravity = GravityFlags.Top | GravityFlags.Left,
                X       = 0,
                Y       = 0
            };

            // add the view
            _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            _windowManager.AddView(_floatingView, _layoutParams);
        }
Exemplo n.º 25
0
        public override void OnCreate()
        {
            base.OnCreate();

            _floatingView = LayoutInflater.From(this).Inflate(Resource.Layout.layout_floating_widget, null);
            SetTouchListener();

            _layoutParams = new WindowManagerLayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent,
                WindowManagerTypes.Phone,
                WindowManagerFlags.NotFocusable,
                Format.Translucent)
            {
                Gravity = GravityFlags.Left | GravityFlags.Top
            };

            _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            _windowManager.AddView(_floatingView, _layoutParams);
            _expandedContainer = _floatingView.FindViewById(Resource.Id.flyout);


            translatedTextView = _floatingView.FindViewById <TextView>(Resource.Id.translatedTextView);
            ocrdLabelTextView  = _floatingView.FindViewById <TextView>(Resource.Id.ocrdLabelTextView);

            translatedTextView.MovementMethod = new ScrollingMovementMethod();

            translatedCopyButton = _floatingView.FindViewById <ImageButton>(Resource.Id.translatedCopyButton);

            translatedCopyButton.Click += TranslatedCopyButtonOnClick;

            spinner = _floatingView.FindViewById <Spinner>(Resource.Id.spinner);



            languagesList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("English", "en"),
                new KeyValuePair <string, string>("Arabic", "ar"),
                new KeyValuePair <string, string>("Greek", "el"),
                new KeyValuePair <string, string>("Hebrew", "he"),
                new KeyValuePair <string, string>("Spanish", "es"),
                new KeyValuePair <string, string>("Chinese", "zh"),
                new KeyValuePair <string, string>("Korean", "ko"),
                new KeyValuePair <string, string>("German", "de"),
                new KeyValuePair <string, string>("Punjabi", "pa"),
                new KeyValuePair <string, string>("Persian", "fa"),
                new KeyValuePair <string, string>("Russian", "ru"),
                new KeyValuePair <string, string>("Turkish", "tr"),
                new KeyValuePair <string, string>("Urdu", "ur"),
                new KeyValuePair <string, string>("French", "fr"),
                new KeyValuePair <string, string>("Hindi", "hi"),
                new KeyValuePair <string, string>("Japanese", "ja")
            };

            List <string> languages = new List <string>();

            foreach (var item in languagesList)
            {
                languages.Add(item.Key);
            }



            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            var adapter = new ArrayAdapter <string>(this,
                                                    Android.Resource.Layout.SimpleSpinnerItem, languages);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleListItemSingleChoice);
            spinner.Adapter = adapter;
        }
        private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e)
        {
            if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000 ||
                AccessibilityHelpers.IsAutofillServicePromptVisible(Windows))
            {
                return;
            }

            if (!AccessibilityHelpers.OverlayPermitted())
            {
                if (!AccessibilityHelpers.IsAutofillTileAdded)
                {
                    // The user has the option of only using the autofill tile and leaving the overlay permission
                    // disabled, so only show this toast if they're using accessibility without overlay permission and
                    // have _not_ added the autofill tile
                    System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted");
                    Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show();
                }
                return;
            }

            if (_overlayView != null || _anchorNode != null || _overlayAnchorObserverRunning)
            {
                CancelOverlayPrompt();
            }

            var uri      = AccessibilityHelpers.GetUri(root);
            var fillable = !string.IsNullOrWhiteSpace(uri);

            if (fillable)
            {
                if (_blacklistedUris != null && _blacklistedUris.Any())
                {
                    if (Uri.TryCreate(uri, UriKind.Absolute, out var parsedUri) && parsedUri.Scheme.StartsWith("http"))
                    {
                        fillable = !_blacklistedUris.Contains(
                            string.Format("{0}://{1}", parsedUri.Scheme, parsedUri.Host));
                    }
                    else
                    {
                        fillable = !_blacklistedUris.Contains(uri);
                    }
                }
            }
            if (!fillable)
            {
                return;
            }

            var intent = new Intent(this, typeof(AccessibilityActivity));

            intent.PutExtra("uri", uri);
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop);

            _overlayView = AccessibilityHelpers.GetOverlayView(this);
            _overlayView.Measure(View.MeasureSpec.MakeMeasureSpec(0, 0),
                                 View.MeasureSpec.MakeMeasureSpec(0, 0));
            _overlayViewHeight  = _overlayView.MeasuredHeight;
            _overlayView.Click += (sender, eventArgs) =>
            {
                CancelOverlayPrompt();
                StartActivity(intent);
            };

            var layoutParams   = AccessibilityHelpers.GetOverlayLayoutParams();
            var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, e.Source,
                                                                               _overlayViewHeight, _isOverlayAboveAnchor);

            layoutParams.X = anchorPosition.X;
            layoutParams.Y = anchorPosition.Y;

            if (_windowManager == null)
            {
                _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            }

            _anchorNode  = e.Source;
            _lastAnchorX = anchorPosition.X;
            _lastAnchorY = anchorPosition.Y;

            _windowManager.AddView(_overlayView, layoutParams);

            System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Added at X:{0} Y:{1}",
                                               layoutParams.X, layoutParams.Y);

            StartOverlayAnchorObserver();
        }
Exemplo n.º 27
0
        private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e)
        {
            if (!AccessibilityHelpers.OverlayPermitted())
            {
                System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted");
                Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show();
                return;
            }

            var uri = AccessibilityHelpers.GetUri(root);

            if (string.IsNullOrWhiteSpace(uri))
            {
                return;
            }

            WindowManagerTypes windowManagerType;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                windowManagerType = WindowManagerTypes.ApplicationOverlay;
            }
            else
            {
                windowManagerType = WindowManagerTypes.Phone;
            }

            var layoutParams = new WindowManagerLayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent,
                windowManagerType,
                WindowManagerFlags.NotFocusable | WindowManagerFlags.NotTouchModal,
                Format.Transparent);

            var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(root, e);

            layoutParams.Gravity = GravityFlags.Bottom | GravityFlags.Left;
            layoutParams.X       = anchorPosition.X;
            layoutParams.Y       = anchorPosition.Y;

            var intent = new Intent(this, typeof(AccessibilityActivity));

            intent.PutExtra("uri", uri);
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop);

            if (_windowManager == null)
            {
                _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
            }

            var updateView = false;

            if (_overlayView != null)
            {
                updateView = true;
            }

            _overlayView        = AccessibilityHelpers.GetOverlayView(this);
            _overlayView.Click += (sender, eventArgs) =>
            {
                CancelOverlayPrompt();
                StartActivity(intent);
            };

            _lastNotificationUri = uri;

            if (updateView)
            {
                _windowManager.UpdateViewLayout(_overlayView, layoutParams);
            }
            else
            {
                _windowManager.AddView(_overlayView, layoutParams);
            }

            System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View {0} X:{1} Y:{2}",
                                               updateView ? "Updated to" : "Added at", layoutParams.X, layoutParams.Y);
        }
        public override void OnCreate()
        {
            base.OnCreate();
            WindowManagerTypes layoutType = WindowManagerTypes.Phone;

            if (Build.VERSION.SdkInt > BuildVersionCodes.NMr1)      //Nougat 7.1
            {
                layoutType = WindowManagerTypes.ApplicationOverlay; //Android Oreo does not allow to add windows of WindowManagerTypes.Phone
            }

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

            var lol = LayoutInflater.From(this);

            floatingNotificationView = (LinearLayout)lol.Inflate(Resource.Layout.FloatingNotification, null);
            //var floatingList = (RecyclerView)lol.Inflate(Resource.Layout.NotificationList, null);

            //using (var layoutManager = new LinearLayoutManager(Application.Context))
            //{
            //    floatingList.SetLayoutManager(layoutManager);
            //    floatingList.SetAdapter(CatcherHelper.notificationAdapter);
            //}
            int width = 200;
            var floatingNotificationWidth = TypedValue.ApplyDimension(ComplexUnitType.Dip, width, Resources.DisplayMetrics);

            //var uiOptions = (int)floatingList.SystemUiVisibility;
            //var newUiOptions = uiOptions;

            //newUiOptions |= (int)SystemUiFlags.Fullscreen;
            //newUiOptions |= (int)SystemUiFlags.HideNavigation;
            //newUiOptions |= (int)SystemUiFlags.Immersive;
            //// This option will make bars disappear by themselves
            //newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;
            //floatingList.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

            WindowManagerLayoutParams layoutParams = new WindowManagerLayoutParams
            {
                Width  = (int)floatingNotificationWidth,
                Height = ViewGroup.LayoutParams.WrapContent,
                Type   = layoutType,
                Flags  =
                    WindowManagerFlags.NotFocusable
                    | WindowManagerFlags.WatchOutsideTouch
                    | WindowManagerFlags.ShowWhenLocked,
                Format  = Format.Translucent,
                Gravity = GravityFlags.CenterHorizontal | GravityFlags.CenterVertical
            };

            floatingNotificationView.Visibility = ViewStates.Gone;

            windowManager.AddView(floatingNotificationView, layoutParams);
            //windowManager.AddView(floatingList, layoutParams);

            floatingNotificationAppName          = floatingNotificationView.FindViewById <TextView>(Resource.Id.tvAppName);
            floatingNotificationWhen             = floatingNotificationView.FindViewById <TextView>(Resource.Id.tvWhen);
            floatingNotificationTitle            = floatingNotificationView.FindViewById <TextView>(Resource.Id.tvTitle);
            floatingNotificationText             = floatingNotificationView.FindViewById <TextView>(Resource.Id.tvText);
            floatingNotificationActionsContainer = floatingNotificationView.FindViewById <LinearLayout>(Resource.Id.notificationActions);

            CatcherHelper.NotificationRemoved             += CatcherHelper_NotificationRemoved;
            CatcherHelper.NotificationPosted              += CatcherHelper_NotificationPosted;
            NotificationAdapterViewHolder.ItemClicked     += NotificationAdapterViewHolder_ItemClicked;
            NotificationAdapterViewHolder.ItemLongClicked += NotificationAdapterViewHolder_ItemLongClicked;
            ActivityLifecycleHelper.GetInstance().ActivityStateChanged += LockScreenActivity_OnActivityStateChanged;
            floatingNotificationView.SetOnTouchListener(this);
        }
Exemplo n.º 29
0
        public async Task Show(TopAlert alert)
        {
            await Stop();

            this._Token = new CancellationTokenSource();

            this._Delay = alert.Duration;

            var            activity      = Xamarin.Forms.Forms.Context as Android.App.Activity;
            IWindowManager windowManager = Xamarin.Forms.Forms.Context.GetSystemService(Android.App.Service.WindowService).JavaCast <IWindowManager>();

            this._Layout = (LinearLayout)activity.LayoutInflater.Inflate(Resource.Layout.AlertBox, null, false);
            this._Layout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            var submain = this._Layout.FindViewById <LinearLayout> (Resource.Id.linearLayout3);

            submain.SetBackgroundColor(alert.BackgroundColor.ToAndroid());

            var main = _Layout.FindViewById <LinearLayout> (Resource.Id.linearLayout1);

            var id = Xamarin.Forms.Forms.Context.Resources.GetIdentifier("alertborder", "drawable", Xamarin.Forms.Forms.Context.PackageName);

            Android.Graphics.Drawables.GradientDrawable drawable =
                Xamarin.Forms.Forms.Context.Resources.GetDrawable(id).JavaCast <Android.Graphics.Drawables.GradientDrawable>();


            var text = submain.FindViewById <TextView> (Resource.Id.textView1);

            text.SetTextColor(alert.TextColor.ToAndroid());
            text.Text = alert.Text;

            if (alert.TextSize > 0)
            {
                text.TextSize = alert.TextSize;
            }

            drawable.SetColor(alert.BorderColor.ToAndroid());
            drawable.SetCornerRadius(alert.BorderWidth);
            main.SetBackground(drawable);

            //activity.ActionBar.Hide ();

            var actionBarHeight = activity.ActionBar.Height;

            var intent = alert.Intent;

            var p = new WindowManagerLayoutParams(
                windowManager.DefaultDisplay.Width - intent * 2,
                (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight),
                WindowManagerTypes.SystemAlert,
                0 | WindowManagerFlags.NotFocusable,
                Android.Graphics.Format.Translucent);

            var yOffset = alert.TopOffset;

            p.Gravity = GravityFlags.Top | GravityFlags.Left;
            p.X       = intent;
            p.Y       = alert.TopOffset + yOffset + (activity.ActionBar.IsShowing ? actionBarHeight : 0);
            p.Height  = (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight);
            windowManager.AddView(_Layout, p);

            this._Layout.Touch += LayoutTouched;

            Task.Run(async() => {
                await Task.Delay(alert.Duration, this._Token.Token);

                if (this._Token != null && this._Token.IsCancellationRequested == false)
                {
                    if (alert.FadeOut)
                    {
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
                            // this works
                            this._fadeOut = ObjectAnimator.OfFloat(_Layout, "alpha", 1f, 0f);
                            this._fadeOut.SetDuration(1000);
                            this._fadeOut.AnimationEnd += _fadeOut_AnimationEnd;
                            this._Set = new AnimatorSet();
                            this._Set.Play(_fadeOut);
                            this._Set.Start();
                        });
                    }
                    else
                    {
                        Stop();
                    }
                }
            });
        }
        public override void OnCreate()
        {
            base.OnCreate();

            floatingView = LayoutInflater.From(this).Inflate(Resource.Layout.floatingWidget, null);

            bloodSugarLevel     = floatingView.FindViewById <TextView>(Resource.Id.bloodSugarLevel);
            unit                = floatingView.FindViewById <TextView>(Resource.Id.unit);
            bloodSugarEvolution = floatingView.FindViewById <TextView>(Resource.Id.bloodSugarEvolution);

            appSettings = (AppSettings)App.Current.Container.Resolve(typeof(AppSettings));

            //Repo init
            userRepository = (IUserRepository)App.Current.Container.Resolve(typeof(IUserRepository));
            IUserSettingsRepository userSettingsRepository = (IUserSettingsRepository)App.Current.Container.Resolve(typeof(IUserSettingsRepository));
            var  userSettings = userSettingsRepository.GetCurrentUserSettings();
            User currentUsr   = userRepository.GetCurrentUser();

            SetTouchListener();

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

            WindowManagerTypes LAYOUT_FLAG;

            if (Build.VERSION.SdkInt >= Build.VERSION_CODES.O)
            {
                LAYOUT_FLAG = WindowManagerTypes.ApplicationOverlay;
            }
            else
            {
                LAYOUT_FLAG = WindowManagerTypes.Phone;
            }

            layoutParams = new WindowManagerLayoutParams(ViewGroup.LayoutParams.WrapContent,
                                                         ViewGroup.LayoutParams.WrapContent,
                                                         LAYOUT_FLAG,
                                                         WindowManagerFlags.NotFocusable,
                                                         Format.Translucent)
            {
                Gravity = GravityFlags.Left | GravityFlags.CenterVertical,
                X       = currentUsr.WidgetPositionX,
                Y       = currentUsr.WidgetPositionY
            };
            if (Settings.CanDrawOverlays(this))
            {
                windowManager.AddView(floatingView, layoutParams);
            }

            SetCenter();

            //Fill the widget with default values
            DefaultState();

            //Startup data refreshed management
            DateTimeOffset empty = new DateTimeOffset();

            if (currentUsr != null && currentUsr.GetMeasureTrend() != MeasureTrend.None)
            {
                NotificationMeasure notif = new NotificationMeasure();
                notif.NewMeasure             = currentUsr.CurrentMeasure;
                notif.MaximumGlucoseTreshold = userSettings.MaximumGlucoseTreshold;
                notif.MinimumGlucoseTreshold = userSettings.MinimumGlucoseTreshold;
                notif.MeasureTrend           = currentUsr.GetMeasureTrend();
                RefreshDatas(notif);
            }

            IEventAggregator eventAggregator = (IEventAggregator)App.Current.Container.Resolve(typeof(IEventAggregator));

            actionRefresh = new Action <NotificationMeasure>((notification) => { this.RefreshDatas(notification); });
            eventAggregator.GetEvent <NotificationMeasureEvent>().Subscribe(actionRefresh);

            eventAggregator.GetEvent <ExitApplicationEvent>().Publish();

            Analytics.TrackEvent(AnalyticsEvent.WidgetViewed);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Create the service.
        /// </summary>
        public override void OnCreate()
        {
            base.OnCreate();

            // get the window manager, and create it with the attributes so its always around
            _wm = this.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            var ps = new WindowManagerLayoutParams(WindowManagerTypes.SystemAlert)
            {
                Flags   = WindowManagerFlags.NotTouchModal | WindowManagerFlags.NotFocusable,
                Format  = Format.Translucent,
                Gravity = GravityFlags.Left | GravityFlags.Top,
                X       = 0,
                Y       = 0,
                Width   = ViewGroup.LayoutParams.MatchParent,
                Height  = ViewGroup.LayoutParams.WrapContent
            };


            // inflate the console view
            var v = this.GetSystemService(Context.LayoutInflaterService).JavaCast <LayoutInflater>();

            _theView = v.Inflate((int)Resource.Layout.overlay, null);

            // find out key buttons and lists
            _restoreButton       = _theView.FindViewById <ImageButton>(Resource.Id.consoleRestoreButton);
            _minimizeButton      = _theView.FindViewById <ImageButton>(Resource.Id.consoleMinimizeButton);
            _minimalLayout       = _theView.FindViewById <LinearLayout>(Resource.Id.consoleMinimizedLayout);
            _restoredLayout      = _theView.FindViewById <FrameLayout>(Resource.Id.consoleExpandedLayout);
            _toolbarLayout       = _theView.FindViewById <RelativeLayout>(Resource.Id.consoleToolbar);
            _logListView         = _theView.FindViewById <ListView>(Resource.Id.consoleLogList);
            _trackActiveButton   = _theView.FindViewById <ImageButton>(Resource.Id.consoleTrackLatestButton);
            _playPauseButton     = _theView.FindViewById <ImageButton>(Resource.Id.consolePlayPauseButton);
            _clearButton         = _theView.FindViewById <ImageButton>(Resource.Id.consoleClearButton);
            _copyClipboardButton = _theView.FindViewById <ImageButton>(Resource.Id.consoleCopyClipboardButton);
            _closeButton         = _theView.FindViewById <ImageButton>(Resource.Id.consoleCloseButton);

            // setup listensers to allow for things to be moved around
            _toolbarLayout.SetOnTouchListener(this);
            _restoreButton.SetOnTouchListener(this);

            // listen to our toolbar buttons.
            _minimizeButton.Click      += MinimizeButtonClick;
            _restoreButton.Click       += RestoreButtonClick;
            _trackActiveButton.Click   += TrackActiveButtonClick;
            _playPauseButton.Click     += PlayPauseButtonClick;
            _clearButton.Click         += ClearButtonClick;
            _copyClipboardButton.Click += CopyClipboardButtonClick;
            _closeButton.Click         += CloseButtonClick;

            // finally add the view.
            _wm.AddView(_theView, ps);


            // host look to observable the logging firehose

            // monitor the fire hose and format to text...
            var diagnosticsSubscriber = Overlay.DiagnosticsSubscriber;

            _adapter             = new RxOverlayLogAdapter(diagnosticsSubscriber.BufferSize);
            _logListView.Adapter = _adapter;

            // and create the subscription which gives us the things to be presented
            _firehoseSub = diagnosticsSubscriber.Entries.Where(_ => _playing).
                           Scan(new OverlayListEntry(0, string.Empty), (e, s) => new OverlayListEntry(e.Index + 1, s)).
                           ObserveOn(RxApp.MainThreadScheduler).
                           Do(s =>
            {
                _adapter.Add(s);
            }).
                           Subscribe(s =>
            {
                if (_trackToActive && _adapter.Count > 0)
                {
                    _logListView.SmoothScrollToPosition(_adapter.Count - 1);
                }
            });
        }