示例#1
0
        public void FloatingShow(FloatingObject userData)
        {
            try
            {
                if (!UserDetails.SChatHead)
                {
                    return;
                }

                FloatingObject = userData;

                if (CanDrawOverlays(Application.Context))
                {
                    StartFloatingViewService(Application.Context, userData);
                    return;
                }

                //Intent intent = new Intent(Settings.ActionManageOverlayPermission, Uri.Parse("package:" + ActivityContext.PackageName));
                //ActivityContext.StartActivityForResult(intent, ChatHeadDataRequestCode);
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
示例#2
0
        private void StartFloatingViewService(Context context, FloatingObject userData)
        {
            try
            {
                // *** You must follow these rules when obtain the cutout(FloatingViewManager.findCutoutSafeArea) ***
                try
                {
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
                    {
                        // 1. 'windowLayoutInDisplayCutoutMode' do not be set to 'never'
                        if (ActivityContext?.Window.Attributes.LayoutInDisplayCutoutMode == LayoutInDisplayCutoutMode.Never)
                        {
                            //Toast.MakeText(Application.Context, "windowLayoutInDisplayCutoutMode' do not be set to 'never" ,ToastLength.Short)?.Show();
                            //throw new Exception("'windowLayoutInDisplayCutoutMode' do not be set to 'never'");
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    Methods.DisplayReportResultTrack(e);
                }

                if (ChatHeadService.RunService)
                {
                    return;
                }

                // launch service
                Intent intent = new Intent(context, typeof(ChatHeadService));

                if (ActivityContext != null)
                {
                    intent.PutExtra(ChatHeadService.ExtraCutoutSafeArea, FloatingViewManager.FindCutoutSafeArea(ActivityContext));
                }

                intent.PutExtra("UserData", JsonConvert.SerializeObject(userData));
                ContextCompat.StartForegroundService(context, intent);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
示例#3
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            try
            {
                if (MFloatingViewManager == null)
                {
                    RunService = true;

                    DisplayMetrics metrics = new DisplayMetrics();
                    //DisplayMetrics metrics = Resources.DisplayMetrics;
                    var windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();
                    windowManager?.DefaultDisplay?.GetRealMetrics(metrics);

                    Inflater ??= LayoutInflater.From(Application.Context);

                    var iconView = Inflater?.Inflate(Resource.Layout.WidgetChatHeadLayout, null, false);

                    Image = iconView?.FindViewById <ImageView>(Resource.Id.imageFloating);
                    Image?.SetOnClickListener(this);
                    try
                    {
                        DataUser = JsonConvert.DeserializeObject <FloatingObject>(intent.GetStringExtra("UserData"));
                        if (DataUser != null)
                        {
                            Glide.With(Application.Context).Load(DataUser.Avatar).Apply(new RequestOptions().CircleCrop().Placeholder(Resource.Drawable.no_profile_image_circle)).Into(Image);

                            if (!string.IsNullOrEmpty(DataUser.MessageCount) || DataUser.MessageCount != "0")
                            {
                                ShowOrHideBadgeView(Convert.ToInt32(DataUser.MessageCount), true);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Methods.DisplayReportResultTrack(e);
                    }

                    MFloatingViewManager = new FloatingViewManager(Application.Context, this);
                    MFloatingViewManager.SetFixedTrashIconImage(Application.Context.GetDrawable(Resource.Drawable.ic_trash_fixed));
                    MFloatingViewManager.SetActionTrashIconImage(Application.Context.GetDrawable(Resource.Drawable.ic_trash_action));
                    MFloatingViewManager.SetSafeInsetRect((Rect)intent.GetParcelableExtra(ExtraCutoutSafeArea));

                    // Setting Options(you can change options at any time)
                    FloatingViewManager.Options options = LoadDynamicOptions(metrics);

                    switch (AppSettings.DisplayModeSettings)
                    {
                    case "Always":
                        MFloatingViewManager.SetDisplayMode(FloatingViewManager.DisplayModeShowAlways);
                        break;

                    case "FullScreen":
                        MFloatingViewManager.SetDisplayMode(FloatingViewManager.DisplayModeHideFullscreen);
                        break;

                    case "Hide":
                        MFloatingViewManager.SetDisplayMode(FloatingViewManager.DisplayModeHideAlways);
                        break;
                    }

                    MFloatingViewManager.AddViewToWindow(iconView, options);
                    return(StartCommandResult.Sticky);
                }
                else
                {
                    if (Image != null && (!string.IsNullOrEmpty(DataUser.MessageCount) || DataUser.MessageCount != "0"))
                    {
                        var x = Convert.ToInt32(DataUser.MessageCount);

                        if (x >= 1 && AppSettings.LastChatSystem == SystemApiGetLastChat.Old)
                        {
                            x++;
                        }

                        ShowOrHideBadgeView(x, true);
                    }
                }

                return(StartCommandResult.NotSticky);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(StartCommandResult.NotSticky);
            }
        }