private void websocket_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
        {
            GF.devLog("[WS][err]");

            //TODO 取得 error code, 處理重新連線
            //TODO 通知
        }
        private void websocket_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            var msg = e.Message;

            GF.devLog("[WS][msg] " + msg);

            //TODO 用以下方式轉換資料
            //JObject restoredObject = JsonConvert.DeserializeObject<JObject> (msg);

            //GF.devLog ("[method] " + restoredObject ["method"]);
            //switch (restoredObject ["method"].ToString ()) {
            //	case "yo":
            //		GF.devLog ("[data] N/A");
            //		break;

            //	case "yo2":
            //		GF.devLog ("[data] " + restoredObject ["data"]);
            //		GF.devLog ("[data.name] " + restoredObject ["data"] ["name"]);
            //		GF.devLog ("[data.phone] " + restoredObject ["data"] ["phone"]);
            //		break;


            //}


            //TODO 取得資料後用發通知
            //  是否把 extra 用於 json ?!
            //NotificationToolbox.updateNotification (this, title, content, extra);
        }
Exemplo n.º 3
0
        protected override void OnStop()
        {
            base.OnStop();
            GF.devLog("[OnStop]");

            webview.ClearCache(true);
        }
        public override void OnDestroy()
        {
            base.OnDestroy();

            GF.devLog("[SERVICE] OnDestroy");

            webSocket.Close();
        }
Exemplo n.º 5
0
        //iframe的url在這裡才收的到. (不會觸發OnPageStarted, OnPageFinished, OnReceivedError)
        public override void OnLoadResource(WebView view, string url)
        {
            base.OnLoadResource(view, url);
            GF.devLog("OnLoadResource: " + url);

            #region = timeout =
            this.cd_500ms = CD;
            #endregion
        }
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            GF.devLog("[SERVICE] OnStartCommand");

            //updateNotification(result[2].ToDoListCount, result[2].ToDoListTitle, GF.NOTIFICATION_ID_2);
            //BadgeControl.setBadge (ApplicationContext, KUserDefault.getNotiCnt_0 () + KUserDefault.getNotiCnt_1 () + KUserDefault.getNotiCnt_2 ());

            return(StartCommandResult.Sticky);           //base.OnStartCommand (intent, flags, startId);
        }
Exemplo n.º 7
0
        //public bool enableBackBtn = true;
        //public string backBtnFunc = string.Empty;


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            #region splash
            if (Ini.ShowLaunchScreen)
            {
                StartActivity(typeof(SplashActitvity));
            }

            #endregion

            GF.devLog("========= " + Application.Context.PackageName);             //

            //
            vibrator = (Vibrator)GetSystemService(VibratorService);

            //
            var lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            panel = new RelativeLayout(this);
            SetContentView(panel, lp);

            webview = new O08WebView(this);
            webview.SetWebViewClient(new O08WebViewClient(this));
            webview.SetWebChromeClient(new O08WebChromeClient(webview));              //for debug
            webview.Settings.JavaScriptEnabled = true;
            //if ((int)Android.OS.Build.VERSION.SdkInt >= 19) {  //UNDONE test for performance
            //	webview.SetLayerType (LayerType.Hardware, null);
            //} else {
            //	webview.SetLayerType (LayerType.Software, null);
            //}
            //if (useMeta) {
            //	webview.Settings.UseWideViewPort = true;
            //	webview.Settings.LoadWithOverviewMode = true;
            //}
            //if (scalable) {
            //	webview.Settings.BuiltInZoomControls = true;
            //	webview.Settings.DisplayZoomControls = false;
            //}

            var rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            panel.AddView(webview, rlp);
            webview.LoadUrl(Ini.URL_MAIN);

            //
            cookieManager = CookieManager.Instance;
            cookieManager.SetAcceptCookie(true);
            if (!string.IsNullOrWhiteSpace(KUserDefault.Cookie))
            {
                string [] cookieArr = KUserDefault.Cookie.Split(';');
                for (int i = 0; i < cookieArr.Length; i++)
                {
                    cookieManager.SetCookie(Ini.URL_MAIN, cookieArr [i]);
                }
            }
        }
Exemplo n.º 8
0
        public override void OnReceivedError(WebView view, IWebResourceRequest request, WebResourceError error)
        {
            GF.devLog("[WebView][OnReceivedError]: " + error);

            stopTimeoutChecking();

            this.webview.LoadUrl(Ini.URL_ERR);

            //
            base.OnReceivedError(view, request, error);
        }
Exemplo n.º 9
0
        protected override void OnDestroy()
        {
            base.OnDestroy();
            GF.devLog("[OnDestroy]");

            if (cookieManager != null)
            {
                GF.devLog("[OnDestroy][Cookie] " + cookieManager.GetCookie(Ini.URL_MAIN));
                KUserDefault.Cookie = cookieManager.GetCookie(Ini.URL_MAIN);
            }
        }
Exemplo n.º 10
0
        /*
         * void createNotification(string title, string desc)
         * {
         *      //Create notification
         *      var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
         *
         *      //Create an intent to show ui
         *      var uiIntent = new Intent(this, typeof(MainActivity));
         *
         *      //Create the notification
         *      var notification = new Notification(Android.Resource.Drawable.SymActionEmail, title);
         *
         *      //Auto cancel will remove the notification once the user touches it
         *      notification.Flags = NotificationFlags.AutoCancel;
         *
         *      //Set the notification info
         *      //we use the pending intent, passing our ui intent over which will get called
         *      //when the notification is tapped.
         *      notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));
         *
         *      //Show the notification
         *      notificationManager.Notify(1, notification);
         * }
         */

        private void updateNotification(int num, string msg, int notificationID, string url)
        {
            // These are the values that we want to pass to the next activity
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt(GF.CALL_FROM_NOTI_TYPE, notificationID);
            valuesForActivity.PutString(GF.URL_FROM_NOTI, url);

            // Create the PendingIntent with the back stack
            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(this, typeof(MainActivity));

            resultIntent.PutExtras(valuesForActivity);             // Pass some values to SecondActivity.

            Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(this);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            //Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            Android.Net.Uri alarmSound;             //= Android.Net.Uri.Parse ("android.resource://" + PackageName + "/" + Resource.Raw.noti_sound_coin);
            string          msgText;

            if (Ini.checkNotiId(notificationID))
            {
                alarmSound = Ini.DefaultNotiAudio;                //Ini.NotiAudioList [notificationID];
                msgText    = Ini.NotiTitleList [notificationID];
            }
            else
            {
                alarmSound = Ini.DefaultNotiAudio;
                msgText    = Ini.DefaultNotiTitle;
            }

            GF.devLog("[GcmService] notificationID: " + notificationID + "  msgText: " + msgText);

            // Build the notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetAutoCancel(true)                        // dismiss the notification from the notification area when the user clicks on it
                                                 .SetContentIntent(resultPendingIntent)      // start up this activity when the user clicks the intent.
                                                 .SetContentTitle(num.ToString() + msgText)  // Set the title
                                                 .SetSmallIcon(Resource.Drawable.Icon)       // This is the icon to display
                                                 .SetSound(alarmSound, 5)
                                                 .SetContentText(msg.Replace("</br>", " ")); // the message to display.
            //.SetContentInfo ("info")
            //.SetNumber (num); // Display the count in the Content Info

            // Finally publish the notification
            NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.Notify(notificationID, builder.Build());
        }
Exemplo n.º 11
0
        public override void OnReceive(Context context, Intent intent)
        {
            //Toast.MakeText (context, "Received intent!", ToastLength.Short).Show ();

            GF.devLog("[BootUpReceiver][OnReceive]");

            if ((intent.Action != null) &&
                (intent.Action == Android.Content.Intent.ActionBootCompleted))
            {
                context.ApplicationContext.StartService(new Intent(context, typeof(NotificationService)));
            }
        }
Exemplo n.º 12
0
        public override bool ShouldOverrideUrlLoading(WebView view, string url)
        {
            GF.devLog("[ShouldOverrideUrlLoading] " + url);

            string _url = System.Web.HttpUtility.UrlDecode(url).Replace(" ", string.Empty);

            if (_url.StartsWith(Ini.CMD_PRFIX, StringComparison.CurrentCulture))
            {
                processCMD(_url);
                return(true);
            }

            return(base.ShouldOverrideUrlLoading(view, url));
        }
Exemplo n.º 13
0
        public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
        {
            this.webview = view;

            #region = timeout =
            startTimeoutChecking();
            #endregion

            GF.devLog("OnPageStarted: " + url);

            view.ClearCache(true);

            base.OnPageStarted(view, url, favicon);
        }
Exemplo n.º 14
0
 private void stopTimeoutChecking()
 {
     if (timeoutChecking != null)
     {
         keepTimeoutChecking = false;
         if (timeoutChecking.IsAlive)
         {
             timeoutChecking.Abort();
         }
         timeoutChecking = null;
     }
     this.retryCnt = 0;
     this.cd_500ms = CD;
     GF.devLog("== TimeoutChecking Stoped ==");
 }
Exemplo n.º 15
0
        private void websocket_Opened(object sender, EventArgs e)
        {
            GF.devLog("[WS][opened]");


            //TODO 把以下測試刪掉. 並在此處加上設備的註冊機制.
            //註冊機制:APP第一次啟動時存住一組GUID, 同時傳給 server. 未來連線時就直接傳這組GUID.
            var t = new Thread(() => {
                for (int i = 0; i < 10; i++)
                {
                    webSocket.Send("Hello World! [" + i + "]");
                    Thread.Sleep(10000);
                }
                StopSelf();
            });

            t.Start();
        }
Exemplo n.º 16
0
        private void startTimeoutChecking()
        {
            stopTimeoutChecking();
            if (timeoutChecking == null)
            {
                timeoutChecking = new Thread(new ThreadStart(delegate {
                    try {
                        while (keepTimeoutChecking)
                        {
                            if (--cd_500ms < 0)
                            {
                                GF.devLog("[WebView][Timeout] " + this.retryCnt);

                                KToast.showCenterToast(mainActivity, "伺服器無法服務 [" + this.retryCnt + "]", ToastLength.Long);

                                if (this.retryCnt >= Ini.WebViewTimeoutRetry)
                                {
                                    mainActivity.RunOnUiThread(delegate {
                                        this.webview.LoadUrl(Ini.URL_ERR);
                                    });
                                }
                                else
                                {
                                    this.retryCnt++;
                                    mainActivity.RunOnUiThread(delegate {
                                        this.webview.Reload();
                                    });
                                }
                                break;
                            }
                            else
                            {
                                GF.devLog("[cd_500ms] " + cd_500ms);
                                Thread.Sleep(500);
                            }
                        }
                    } catch {
                        timeoutChecking = null;
                    }
                }));
                timeoutChecking.Start();
                GF.devLog("== TimeoutChecking Started ==");
            }
        }
Exemplo n.º 17
0
        private void processCMD(string url)
        {
            string jsonStr = url.Remove(0, Ini.CMD_PRFIX.Length);

            GF.devLog("[jsonStr] " + jsonStr);

            JObject restoredObject = JsonConvert.DeserializeObject <JObject> (jsonStr);

            GF.devLog("[method] " + restoredObject ["method"]);
            switch (restoredObject ["method"].ToString())
            {
            case "yo":
                GF.devLog("[data] N/A");
                break;

            case "yo2":
                GF.devLog("[data] " + restoredObject ["data"]);
                GF.devLog("[data.name] " + restoredObject ["data"] ["name"]);
                GF.devLog("[data.phone] " + restoredObject ["data"] ["phone"]);
                break;

            case "startService":
                mainActivity.StartService(new Intent(mainActivity, typeof(NotificationService)));
                break;

            case "stopService":
                mainActivity.StopService(new Intent(mainActivity, typeof(NotificationService)));
                break;

            case "notification":
                var title   = restoredObject ["data"] ["title"].ToString();
                var content = restoredObject ["data"] ["content"].ToString();
                NotificationToolbox.updateNotification(mainActivity, title, content, "this is extra");
                break;

            case "vibrate":
                var     jArr    = restoredObject ["data"] as JArray;
                long [] pattern = jArr.Select(jv => jv.Value <long> ()).ToArray();
                mainActivity.doVibrate(pattern);
                break;
            }
        }
Exemplo n.º 18
0
        protected override void OnResume()
        {
            base.OnResume();
            GF.devLog("[OnResume]");

            // NOTE 這不會啟動多重的同個 service
            StartService(new Intent(this, typeof(NotificationService)));

            //
            if (Intent.Extras != null)
            {
                var msg = Intent.Extras.GetString("msg_from_noti", string.Empty);
                GF.devLog("[OnResume] extra: " + msg);
            }
            else
            {
                GF.devLog("[OnResume] no extras");
            }

            // TODO 解析 extra 並做對應動作
        }
Exemplo n.º 19
0
        protected override void OnMessage(Context context, Intent intent)
        {
            Log.Info(TAG, "GCM Message Received!");

            //var msg = new StringBuilder();
            string msg  = string.Empty;
            int    type = 0;
            //long notiID = 0;
            string url = string.Empty;            //"www.google.com";

            if (intent != null && intent.Extras != null)
            {
                foreach (var key in intent.Extras.KeySet())
                {
                    //msg.AppendLine (key + "=" + intent.Extras.Get (key).ToString ());

                    if (key == "msg")
                    {
                        msg = intent.Extras.Get(key).ToString();
                    }
                    else if (key == "type")
                    {
                        int.TryParse(intent.Extras.Get(key).ToString(), out type);
                    }
                    else if (key == "url")
                    {
                        url = intent.Extras.Get(key).ToString();
                    }
                }
            }

            GF.devLog("[type] ============== " + type.ToString() + " =========");
            GF.devLog("[url] ============== " + url + " =========");

            //WS_TD888.device_setReceived (notiID);


            KUserDefault.addNotiCnt(type, 1);
            if (type < Ini.NotiIdList.Length)
            {
                updateNotification(KUserDefault.getNotiCnt(type), msg, Ini.NotiIdList [type], url);
                BadgeControl.setBadge(context, KUserDefault.getSumNotiCnt());
            }

            /*
             * switch (type) {
             *      case 0:
             *              KUserDefault.addNotiCnt_0 (1);
             *              updateNotification (KUserDefault.getNotiCnt_0 (), msg, Ini.NotiIdList[0]);
             *              break;
             *
             *      case 1:
             *              KUserDefault.addNotiCnt_1 (1);
             *              updateNotification (KUserDefault.getNotiCnt_1 (), msg, Ini.NotiIdList[1]);
             *              break;
             *
             *      case 2:
             *              KUserDefault.addNotiCnt_2 (1);
             *              updateNotification (KUserDefault.getNotiCnt_2 (), msg, Ini.NotiIdList[2]);
             *              break;
             *
             * }
             *
             * if (type <= 2) {
             *      GF.devLog ("[NotiCnt] " + KUserDefault.getNotiCnt_0 () + ", " + KUserDefault.getNotiCnt_1 () + ", " + KUserDefault.getNotiCnt_2 ());
             *      BadgeControl.setBadge (context, KUserDefault.getNotiCnt_0 () + KUserDefault.getNotiCnt_1 () + KUserDefault.getNotiCnt_2 ());
             * }
             */

            /*
             * //Store the message
             * var prefs = GetSharedPreferences(context.PackageName, FileCreationMode.Private);
             * var edit = prefs.Edit();
             * edit.PutString("last_msg", msg.ToString());
             * edit.Commit();
             *
             * createNotification("GCM Sample", "Message Received for GCM Sample... Tap to View!");
             *
             *
             * Log.Info(TAG, "GCM Message Received!");
             */

            //GF.devLog ("[== Noti Msg ==] " + msg.ToString ());
        }
Exemplo n.º 20
0
 public override IBinder OnBind(Intent intent)
 {
     GF.devLog("[SERVICE] OnBind");
     return(null);
 }
Exemplo n.º 21
0
 public override void OnWindowFocusChanged(bool hasFocus)
 {
     base.OnWindowFocusChanged(hasFocus);
     GF.devLog("[OnWindowFocusChanged]");
 }
Exemplo n.º 22
0
 private void websocket_Closed(object sender, EventArgs e)
 {
     GF.devLog("[WS][closed]");
 }