/// <summary> /// Start remote client /// </summary> public void StartRemoteClient() { if (_webServer != null) { throw new InvalidOperationException("Remote client has been started"); } _webServer = new WebBrowserClient(ClientId); }
internal WebServiceSettings GetLatestWebServiceSettings(bool throwException) { WebServiceSettings webServiceSettings = null; WebBrowserClient webClient = new WebBrowserClient(); string webServiceSettingsUrl = GetCurrenWebServiceSettingsUrl(); int retries = 1; TryAgain: try { string webServiceSettingsString = webClient.GetPage(new Uri(webServiceSettingsUrl), "", true); if (!string.IsNullOrEmpty(webServiceSettingsString)) { try { webServiceSettingsString = SerializeDeserializeObject.DeserializeObject <String>(webServiceSettingsString); webServiceSettingsString = Encryption.DecryptString(webServiceSettingsString); webServiceSettings = SerializeDeserializeObject.DeserializeObject <WebServiceSettings>(webServiceSettingsString); } catch (Exception ex) { throw new Exception(Constants.Message.TRY_NEXT_URL); } } else { throw new Exception(Constants.Message.TRY_NEXT_URL); } } catch { if (retries < GetNumberOfWebServiceSettingsUrl()) { retries++; webServiceSettingsUrl = GetNextWebServiceSettingsUrl(); goto TryAgain; } else if (throwException) { throw new Exception(Constants.Message.WEBSERVICE_SETTINGS_NOT_FOUND); } } return(webServiceSettings); }
private void GetValidWebServiceUrl(bool throwException) { lock (_lock) { bool updateWebServiceSettingsWhenAllServicesAreDown = true; WebBrowserClient webClient = new WebBrowserClient(); WebServiceUrl webServiceUrl = GetCurrentWebServiceUrl(); if (_currentWebServiceUrl != null && (DateTime.Now - _lastPingDateTime).TotalSeconds <= 15) { return; } int retries = 1; TryAgain: try { if (webServiceUrl != null && PingWebService(webServiceUrl.Url, false)) { _lastPingDateTime = DateTime.Now; _currentWebServiceUrl = webServiceUrl; } else { throw new Exception(Constants.Message.TRY_NEXT_URL); } } catch (Exception ex) { if (ex.Message.Equals(Constants.Message.TRY_NEXT_URL)) { if (retries < GetNumberOfWebServiceUrl()) { retries++; webServiceUrl = GetNextWebServiceUrl(); goto TryAgain; } else if (updateWebServiceSettingsWhenAllServicesAreDown) { updateWebServiceSettingsWhenAllServicesAreDown = false; WebServiceSettings tempWebServiceSettings = GetLatestWebServiceSettings(false); if (tempWebServiceSettings != null && _webServiceSettings.SettingId != tempWebServiceSettings.SettingId) { _webServiceSettings.SettingId = tempWebServiceSettings.SettingId; _webServiceSettings.WebServiceUrlList = tempWebServiceSettings.WebServiceUrlList; _currentWebServiceUrlIndex = 0; webServiceUrl = GetCurrentWebServiceUrl(); retries = 1; goto TryAgain; } } if (throwException) { throw new Exception(Constants.Message.WEBSERVICES_ARE_DOWN); } } else if (throwException) { throw ex; } } } }
//Ads fields //TODO: clear the ram use from this activity. protected override void OnCreate(Bundle bundle) { //Attempts to load ffmpeg to see if it is supported. //StartActivity(new Intent(this, Java.Lang.Class.ForName("android.loadffmpeg"))); //RequestWindowFeature (WindowFeatures.IndeterminateProgress); RequestWindowFeature(WindowFeatures.Progress); SetContentView(Resource.Layout.Main); base.OnCreate(bundle); //ActionBar.SetLogo (Resource.Drawable.inappicon); this.Title = string.Empty; trackingInterface = new TrackingInterface(this); //trackingInterface.TrackScreen(TrackingInterface.ActivityNames.MainActivity); manager = (InputMethodManager)GetSystemService(InputMethodService); //used to control sleeping pm = (PowerManager)this.GetSystemService(Service.PowerService); wl = pm.NewWakeLock(WakeLockFlags.ScreenDim, "My Tag"); this.appContext = this.ApplicationContext; //this.activityContext = this.activityContext; //assign controllers/widgets webView = FindViewById <WebView> (Resource.Id.webView1); progressBar = FindViewById <ProgressBar> (Resource.Id.progressBar1); playingWarning = FindViewById <TextView> (Resource.Id.playingWarning); tapAndHoldPrompt = FindViewById <TextView> (Resource.Id.tapAndHoldPrompt); relativeLayout = FindViewById <RelativeLayout> (Resource.Id.relativeLayout1); cancelDownloadButton = FindViewById <Button> (Resource.Id.cancelDownloadButton); //Flurry //Flurry.Analytics.FlurryAgent.Init(this, "ZTKSCWYBWHW9D6F28KY5"); //adBanner = new Flurry.Ads.FlurryAdBanner(this, relativeLayout, "Main_activity_banner"); //adBanner.FetchAndDisplayAd(); relativeLayout.RemoveView(tapAndHoldPrompt); relativeLayout.RemoveView(playingWarning); relativeLayout.RemoveView(cancelDownloadButton); relativeLayout.RemoveView(progressBar); //used when the GetGifs button is pressed, contains ValueReceived event //myResult = new JavaScriptResult (); /*WEBVIEW: load default URL, * enable JavaScript, * prevent Android's default browser from opening */ WebBrowserChromeClient myClient = new WebBrowserChromeClient(this); WebBrowserClient viewClient = new WebBrowserClient(); webView.SetWebChromeClient(myClient); webView.SetWebViewClient(viewClient); webView.ClearCache(true); webView.LoadUrl(homePage); webView.Settings.DomStorageEnabled = true; webView.Settings.JavaScriptEnabled = true; webView.Settings.LoadWithOverviewMode = true; webView.Settings.UseWideViewPort = true; webView.Settings.BuiltInZoomControls = true; webView.SetBackgroundColor(Color.White); #region ffmpeg loading //load ffmpeg ffmpeg = FFmpeg.GetInstance(this); FffmpegTools.XLoadBinaryResponseHandler loadBinaryHandler = new FffmpegTools.XLoadBinaryResponseHandler(); FffmpegTools.XExecuteBinaryResponseHandler executeBinaryHandler = new FffmpegTools.XExecuteBinaryResponseHandler(); //new TaskFactory ().StartNew (()=>{ // ffmpeg.LoadBinary(loadBinaryHandler); //}); loadBinaryHandler.OnFfmpegLoadindAttemptFinished += (object sender, EventArgs e) => { if (loadBinaryHandler.failed) { } }; #endregion viewClient.EOnPageStarted += delegate(object sender, EventArgs e){ manager.HideSoftInputFromWindow(webView.WindowToken, 0); if (URLBar != null) { if (webView.Url != homePage) { URLBar.SetQuery(webView.Url, false); } else if (webView.Url == homePage) { URLBar.SetQuery("", false); } } }; //Fired when the download button is pressed and the JavaScript interface got the value if (myResult != null) { myResult.ValueReceived += delegate(object sender, EventArgs e) { List <string> gifUrlList = GifarooTools.GetAllGifUrls( myResult.ResponseString, webView.OriginalUrl); //Navigate to GifGallery with GifUrls as data if (gifUrlList.Count != 0) { var gifGallery = new Intent(this, typeof(GifGalleryActivity)); gifGallery.PutStringArrayListExtra("gifUrlsList", gifUrlList); StartActivity(gifGallery); } else { Toast.MakeText(this, "No animated gifs found... (Not all animated images are gif files...)", ToastLength.Short).Show(); } } } ; //Long click will go directly to the EditGif activity Toast notAGifToast = Toast.MakeText(this, "That's not a supported animated image.", ToastLength.Short); webView.LongClick += (object sender, View.LongClickEventArgs e) => { //URLBar.ClearFocus(); webView.StopLoading(); //TODO: break point this to allow asus to reach the next activity WebView eventWebView = (WebView)sender; var myResultza = eventWebView.GetHitTestResult(); var myResultzaType = myResultza.Type; var extra = myResultza.Extra; bool formatsupported = false; bool isHomepageGif = true; #if !DEBUG isHomepageGif = (webView.Url != homePage); //This only runs on release, prevents the hoemsreen gif from being longclicked. #endif foreach (string extension in GifarooTools.supportedImageExtensions) { if (isHomepageGif && extra != null && extra.Contains(extension)) { downloadTask = null; formatsupported = true; downloadAndSaveGifCancelationToken = new CancellationTokenSource(); try { toggleLoadingControlls(false); string fileName = "my_file" + extension; //string newFileName = "my_file.mp4"; //string dimensionsString = FffmpegTools.GetResizeCommandDimensions(this, fileName); //string ffmpegCommand = "-y -i "+FilesDir.Path+"/"+fileName+" -vf scale="+ dimensionsString +" -preset superfast "+FilesDir.Path+"/"+newFileName; //string ffmpegCommand = "-y -i "+FilesDir.Path+"/"+fileName+" -c:v libx264 -preset superfast -crf 22 -c:a copy " +FilesDir.Path+"/"+newFileName; //string ffmpegCommand = "-y -i "+FilesDir.Path+"/"+fileName+" -c:v libx264 -vprofile baseline -c:a libfaac -ar 44100 -ac 2 -b:a 128k -movflags faststart "+FilesDir.Path+"/"+newFileName; //string ffmpegCommand = "-y -i " + FilesDir.Path + "/" + fileName + " -c:v libx264 -profile:v baseline -c:a libfaac -ar 44100 -ac 2 -b:a 128k -movflags faststart " + FilesDir.Path + "/" + newFileName; //string ffmpegCommand = "-y -i " + FilesDir.Path + "/" + fileName + " -s 480x320 -vcodec mpeg4 -acodec aac -strict -2 -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 " + FilesDir.Path + "/" + newFileName; downloadTask = Task.Factory.StartNew(() => { try{ GifarooTools.DownloadFileFromURL(this, extra, fileName); }catch (Exception se) { trackingInterface.TrackException(se.Message, false); } //ffmpeg.Execute(ffmpegCommand.Split(), executeBinaryHandler); }, downloadAndSaveGifCancelationToken.Token); downloadTask.ContinueWith((antecedent) => { var editGifActivity = new Intent(this, typeof(EditGifActivity)); //var editGifActivity = new Intent (this, typeof(SaveActivity)); //goes to java version of save activity List <string> myStringList = new List <string>(); myStringList.Add(fileName);//TODO: change to newFilename when ffmpeg is implemented editGifActivity.PutStringArrayListExtra("gifUrl", myStringList); trackingInterface.TrackFileSorceDomain(new Java.Net.URL(extra).Host); StartActivity(editGifActivity); //TODO: remove this line when ffmpeg converison is implemented correctly //executeBinaryHandler.OnExecutionFinished += (object exeSender, EventArgs eexe) => //{ // if (executeBinaryHandler.failed == false) // StartActivity(editGifActivity); //}; }, downloadAndSaveGifCancelationToken.Token); } catch (Exception es) { Toast.MakeText(this, "Something went wrong, try again.", ToastLength.Long).Show(); toggleLoadingControlls(true); downloadTask = null; trackingInterface.TrackException(es.Message, false); } cancelDownloadButton.Click += (object cancelSender, EventArgs cancelEA) => { downloadAndSaveGifCancelationToken.Cancel(); toggleLoadingControlls(true); SetProgressBarIndeterminateVisibility(false); downloadTask = null; }; } } if (formatsupported == false) { SetProgressBarIndeterminateVisibility(false); notAGifToast.Show(); } }; }