Esempio n. 1
0
 /// <summary>
 /// Toggles the loading controlls and sleep locks.
 /// </summary>
 /// <param name="enable">If set to <c>true</c> enable.</param>
 public void toggleLoadingControlls(bool enable)
 {
     if (enable == false)
     {
         if (playingWarning.Parent == null)
         {
             relativeLayout.AddView(playingWarning);
         }
         relativeLayout.AddView(cancelDownloadButton);
         relativeLayout.AddView(progressBar);
         mState = false;
         try { wl.Acquire(); } catch (Exception e) {
             trackingInterface.TrackException(e.Message, false);
         }
     }
     else if (enable == true)
     {
         if (playingWarning.Parent != null)
         {
             relativeLayout.RemoveView(playingWarning);
         }
         relativeLayout.RemoveView(cancelDownloadButton);
         relativeLayout.RemoveView(progressBar);
         mState = true;
         try { wl.Release(); } catch (Exception ex) {
             trackingInterface.TrackException(ex.Message, false);
         }
     }
     InvalidateOptionsMenu();
 }
Esempio n. 2
0
        //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();
                }
            };
        }