Ejemplo n.º 1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Android.Resource.Id.editButton:
                if (selectedGifUrl != string.Empty)
                {
                    string fileName = "myFile.gif";
                    Task   taskA    = Task.Factory.StartNew(() => {
                        GifarooTools.DownloadFileFromURL(this, selectedGifUrl, fileName);
                    });
                    taskA.Wait();

                    var           editGifActivity = new Intent(this, typeof(EditGifActivity));
                    List <string> myStringList    = new List <string> ();
                    myStringList.Add(fileName);
                    editGifActivity.PutStringArrayListExtra("gifUrl", myStringList);
                    StartActivity(editGifActivity);
                }
                else
                {
                    Toast.MakeText(this, "Select a gif First.", ToastLength.Short).Show();
                }
                return(true);

            case 16908332:
                Intent intent = new Intent();
                intent.SetClass(BaseContext, typeof(MainActivity));
                intent.SetFlags(ActivityFlags.ReorderToFront);
                StartActivity(intent);
                return(true);
            }
            return(base.OnOptionsItemSelected(item));
        }
Ejemplo 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();
                }
            };
        }
Ejemplo n.º 3
0
        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater inflater = this.MenuInflater;

            inflater.Inflate(Resource.Menu.menu, menu);

            var URLBarUncasted = (SearchView)menu.FindItem(Resource.Id.URLBar).ActionView;

            URLBar = URLBarUncasted.JavaCast <SearchView> ();
            //URLBar.LayoutParameters = new LinearLayout.LayoutParams (SearchView.LayoutParams.MatchParent, SearchView.LayoutParams.WrapContent);
            URLBar.SetQueryHint("Search Google or enter a URL");
            //downloadButton = (IMenuItem)menu.FindItem (Resource.Id.downloadButton).ActionView;

            homeButton = (IMenuItem)menu.FindItem(Resource.Id.homePageButton).ActionView;

            URLBar.QueryTextFocusChange += delegate {
                if (!URLBar.IsFocused)
                {
                    manager.HideSoftInputFromWindow(URLBar.WindowToken, 0);
                    if (URLBar.Query == "" && webView.Url != homePage)
                    {
                        URLBar.SetQuery(webView.Url, false);
                    }
                }
                else if (URLBar.IsFocused &&
                         webView.Url != null &&
                         webView.Url == homePage)
                {
                    URLBar.SetQuery("", false);
                }
            };

            URLBar.QueryTextSubmit += delegate {
                manager.HideSoftInputFromWindow(URLBar.WindowToken, 0);
                string urlModed = GifarooTools.getURL(URLBar.Query);
                webView.StopLoading();

                URLBar.SetQuery(urlModed, false);
                webView.LoadUrl(urlModed);
                //webView.RequestFocus();
            };

            if (mState == false)
            {
                URLBar.Visibility = ViewStates.Gone;
            }
            else
            {
                URLBar.Visibility = ViewStates.Visible;
            }
            for (int i = 0; i < menu.Size(); i++)
            {
                menu.GetItem(i).SetVisible(mState);
            }

            //Get rid of the unecessary views
            menu.FindItem(Resource.Id.editButton).SetVisible(false);
            menu.FindItem(Resource.Id.saveButton).SetVisible(false);
            menu.FindItem(Resource.Id.downloadButton).SetVisible(false);
            menu.FindItem(Resource.Id.storeButton).SetVisible(false);

            return(base.OnCreateOptionsMenu(menu));
        }