Exemple #1
0
        public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            var            me         = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);
            var            widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
            InternetStatus status     = new InternetStatus();
            NetCredential  credential = new NetCredential();

            credential.State = await status.SuggestAsync();

            var helper = credential.GetHelper();

            if (helper != null)
            {
                FluxUser user = await helper.GetFluxAsync();

                widgetView.SetTextViewText(Resource.Id.widgetTitle, user.Username);
                widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}");
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance));
            }
            var intent = new Intent(context, typeof(AppWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds);
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
            appWidgetManager.UpdateAppWidget(me, widgetView);
        }
Exemple #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            try
            {
                NetCredential  credential = new NetCredential();
                InternetStatus status     = new InternetStatus();
                credential.State = await status.SuggestAsync();

                var helper = credential.GetHelper();
                if (helper != null)
                {
                    FluxUser user = await helper.GetFluxAsync();

                    NotificationHelper.UpdateTile(user);
                    NetXFSettings settings = new NetXFSettings();
                    settings.LoadSettings();
                    if (settings.EnableFluxLimit)
                    {
                        NotificationHelper.SendWarningToast(user, settings.FluxLimit);
                    }
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
 private void Start()
 {
     if (Application.internetReachability == NetworkReachability.NotReachable)
     {
         internetConnectionStatus = InternetStatus.NotConnected;
         CheckInternetStaus();
     }
     StartCoroutine(Ping());
 }
        private void ListeningInternet()
        {
            while (true)
            {
                if (connectProfile != null && connectProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess && _currentStatus== InternetStatus.NotConnect)
                {
                    _currentStatus = InternetStatus.Connected;
                    InternetStatusChanged(true, new EventArgs());
                }

            }
        }
Exemple #5
0
        public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            var            me         = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);
            var            widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
            InternetStatus status     = new InternetStatus();
            NetCredential  credential = new NetCredential();

            (credential.Username, credential.Password) = await CredentialStore.LoadCredentialAsync();

            credential.State = await status.SuggestAsync();

            NetXFSettings settings = new NetXFSettings();

            settings.LoadSettings();
            var helper = credential.GetHelper(settings);

            if (helper != null)
            {
                if (settings.BackgroundAutoLogin && !string.IsNullOrEmpty(credential.Username))
                {
                    if (settings.EnableRelogin)
                    {
                        await helper.LogoutAsync();
                    }
                    await helper.LoginAsync();
                }
                FluxUser user = await helper.GetFluxAsync();

                var remainFlux = FluxHelper.GetMaxFlux(user.Flux, user.Balance) - user.Flux;
                widgetView.SetTextViewText(Resource.Id.widgetTitle, $"用户:{user.Username}");
                widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}");
                widgetView.SetTextViewText(Resource.Id.widgetRemain, $"剩余:{remainFlux}");
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance));
            }
            else
            {
                widgetView.SetTextViewText(Resource.Id.widgetTitle, "暂无流量信息");
                widgetView.SetTextViewText(Resource.Id.widgetFlux, string.Empty);
                widgetView.SetTextViewText(Resource.Id.widgetRemain, string.Empty);
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Empty);
            }
            var intent = new Intent(context, typeof(AppWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
            appWidgetManager.UpdateAppWidget(me, widgetView);
        }
Exemple #6
0
        private void IcOnStatusChanging(object sender, InternetStatus internetStatus)
        {
            switch (internetStatus)
            {
            case InternetStatus.YesInternet:
                BeginInvoke(new MethodInvoker(delegate
                {
                    statusLabel.Text   = "Готово";
                    IsEnternetExist    = true;
                    btnConnect.Enabled = true;
                    updateBTN.Enabled  = true;
                }));
                break;

            case InternetStatus.Searching:
                BeginInvoke(new MethodInvoker(delegate
                {
                    statusLabel.Text   = "Поиск интернета";
                    IsEnternetExist    = false;
                    btnConnect.Enabled = false;
                    updateBTN.Enabled  = false;
                }));
                break;

            case InternetStatus.SearchingAgain:
                BeginInvoke(new MethodInvoker(delegate
                {
                    statusLabel.Text   = "Переподключение";
                    IsEnternetExist    = false;
                    btnConnect.Enabled = false;
                    updateBTN.Enabled  = false;
                }));
                break;

            case InternetStatus.NoInternet:
                BeginInvoke(new MethodInvoker(delegate
                {
                    statusLabel.Text   = "Нет интернета";
                    IsEnternetExist    = false;
                    btnConnect.Enabled = false;
                    updateBTN.Enabled  = false;
                }));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(internetStatus), internetStatus, null);
            }
        }
        private void CheckForInternetConnectionStatus()
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                internetConnectionStatus = InternetStatus.NotConnected;
            }
            else if (pingSamples.Count == maxPingSampleCount)
            {
                averagePingTime = 0;
                foreach (var val in pingSamples)
                {
                    averagePingTime += val;
                }
                averagePingTime /= maxPingSampleCount;

                if (averagePingTime == 1000)
                {
                    internetConnectionStatus = InternetStatus.NotConnected;
                }
                else if (averagePingTime <= 100)
                {
                    internetConnectionStatus = InternetStatus.Excellent;
                }
                else if (averagePingTime <= 200)
                {
                    internetConnectionStatus = InternetStatus.Good;
                }
                else if (averagePingTime <= 400)
                {
                    internetConnectionStatus = InternetStatus.average;
                }
                else
                {
                    internetConnectionStatus = InternetStatus.Bad;
                }
            }
            CheckInternetStaus();
        }
        public bool CheckInternetConnected()
        {

            try
            {
                if (connectProfile != null && connectProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
                {
                    _currentStatus = InternetStatus.Connected;
                    return true;
                }
                else
                {
                    Thread thread = new Thread(new ThreadStart(ListeningInternet));
                    thread.Start();
                    _currentStatus = InternetStatus.NotConnect;
                    ListeningInternet();
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemple #9
0
 protected override async void OnNavigatedTo(NavigationEventArgs e)
 {
     InternetStaus.Text = InternetStatus.GetConnectionGeneration();
     base.OnNavigatedTo(e);
     await FirstStep();
 }