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); }
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); }
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); }