void downloadWhatsAppFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     RunOnUiThread(() => {
         progressDialog.Dismiss();
         if (downloadedOK)
         {
             var installApk = new Intent(Intent.ActionView);
             installApk.SetDataAndType(Android.Net.Uri.Parse("file://" + fullLatestWhatsAppFilename), "application/vnd.android.package-archive");
             installApk.SetFlags(ActivityFlags.NewTask);
             try {
                 StartActivity(installApk);
                 AlertDialog deleteWhatsApp = new AlertDialog.Builder(this).Create();
                 deleteWhatsApp.SetTitle(Resources.GetString(Resource.String.delete));
                 deleteWhatsApp.SetMessage(Resources.GetString(Resource.String.delete_description));
                 deleteWhatsApp.SetButton((int)DialogButtonType.Positive, Resources.GetString(Resource.String.delete_button_delete), (object senderDelete, DialogClickEventArgs eDelete) => File.Delete(fullLatestWhatsAppFilename));
                 deleteWhatsApp.SetButton((int)DialogButtonType.Negative, Resources.GetString(Resource.String.delete_button_cancel), (object senderCancel, DialogClickEventArgs eCancel) => deleteWhatsApp.Dismiss());
                 deleteWhatsApp.SetCancelable(false);
                 deleteWhatsApp.Show();
             } catch (ActivityNotFoundException ex) {
                 var errorInstalled = new AlertDialog.Builder(this).Create();
                 errorInstalled.SetTitle(Resources.GetString(Resource.String.download_error));
                 errorInstalled.SetMessage(string.Format(Resources.GetString(Resource.String.download_error_description), "WhatsApp " + latestWhatsAppVersion));
                 errorInstalled.Show();
             }
             downloadedOK = false;
         }
         else
         {
             File.Delete(fullLatestWhatsAppFilename);
         }
     });
 }
        void OnAlertRequested(Page sender, AlertArguments arguments)
        {
            AlertDialog alert = new AlertDialog.Builder(this).Create();

            alert.SetTitle(arguments.Title);
            alert.SetMessage(arguments.Message);
            if (arguments.Accept != null)
            {
                alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true));
            }
            alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false));
            alert.CancelEvent += (o, args) => { arguments.SetResult(false); };
            alert.Show();
        }
示例#3
0
            void OnPromptRequested(Page sender, PromptArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                AlertDialog alertDialog = new AlertDialog.Builder(Activity).Create();

                alertDialog.SetTitle(arguments.Title);
                alertDialog.SetMessage(arguments.Message);

                var frameLayout = new FrameLayout(Activity);
                var editText    = new EditText(Activity)
                {
                    Hint = arguments.Placeholder
                };
                var layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
                {
                    LeftMargin  = (int)(22 * Activity.Resources.DisplayMetrics.Density),
                    RightMargin = (int)(22 * Activity.Resources.DisplayMetrics.Density)
                };

                editText.LayoutParameters = layoutParams;
                editText.InputType        = arguments.Keyboard.ToInputType();
                if (arguments.Keyboard == Keyboard.Numeric)
                {
                    editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType);
                }

                if (arguments.MaxLength > -1)
                {
                    editText.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(arguments.MaxLength) });
                }

                frameLayout.AddView(editText);
                alertDialog.SetView(frameLayout);

                alertDialog.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(editText.Text));
                alertDialog.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(null));
                alertDialog.CancelEvent += (o, args) => { arguments.SetResult(null); };

                alertDialog.Window.SetSoftInputMode(SoftInput.StateVisible);
                alertDialog.Show();
                editText.RequestFocus();
            }
        // Retrieve latest version of Beta Updater
        public async Task GetLatestAppVersion(string pageUrl)
        {
            var    getVersion  = new WebClient();
            string htmlAndroid = getVersion.DownloadString(new Uri(pageUrl));

            // Get WhatsApp latest version
            string[] split = htmlAndroid.Split(new char[] { '>' });
            int      i     = 0;

            while (i < split.Length)
            {
                if (split.GetValue(i).ToString().StartsWith("v"))
                {
                    split            = split.GetValue(i).ToString().Split(new char[] { 'v', '<' });
                    latestAppVersion = split.GetValue(1).ToString().Trim();
                    break;
                }
                i++;
            }

            installedAppVersion = PackageManager.GetPackageInfo("com.javiersantos.whatsappbetaupdater", 0).VersionName.Trim();

            if (CompareVersionReceiver.VersionCompare(installedAppVersion, latestAppVersion) < 0)
            {
                appApk = appApk + "v" + latestAppVersion + "/com.javiersantos.whatsappbetaupdater.apk";

                AlertDialog appUpdateDialog = new AlertDialog.Builder(this).Create();
                appUpdateDialog.SetTitle(string.Format(Resources.GetString(Resource.String.app_update), latestAppVersion));
                appUpdateDialog.SetMessage(string.Format(Resources.GetString(Resource.String.app_update_description), Resources.GetString(Resource.String.app_name)));
                appUpdateDialog.SetButton((int)DialogButtonType.Positive, Resources.GetString(Resource.String.update_button), (object senderUpdateAppOK, DialogClickEventArgs eUpdateAppOK) => {
                    SetDownloadDialog();
                    var webClient = new WebClient();
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged);
                    webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(downloadAppFileCompleted);
                    webClient.DownloadFileAsync(new Uri(appApk), fullLatestAppFilename);
                    progressDialog.SetTitle(string.Format(Resources.GetString(Resource.String.downloading), Resources.GetString(Resource.String.app_name) + " " + latestAppVersion + "..."));
                    progressDialog.SetButton(Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => { webClient.CancelAsync(); progressDialog.Dismiss(); });
                    progressDialog.Show();
                });
                appUpdateDialog.SetButton((int)DialogButtonType.Negative, Resources.GetString(Resource.String.cancel_button), (object senderUpdateAppCancel, DialogClickEventArgs eUpdateAppCancel) => appUpdateDialog.Dismiss());
                appUpdateDialog.SetButton((int)DialogButtonType.Neutral, Resources.GetString(Resource.String.never_button), (object senderUpdateAppNever, DialogClickEventArgs eUpdateAppNever) => { prefs.Edit().PutBoolean("prefShowAppUpdates", false).Commit(); appUpdateDialog.Dismiss(); });
                appUpdateDialog.SetCancelable(false);
                appUpdateDialog.Show();
            }
        }
示例#5
0
            void OnAlertRequested(Page sender, AlertArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                AlertDialog alert = new AlertDialog.Builder(Activity).Create();

                alert.SetTitle(arguments.Title);
                alert.SetMessage(arguments.Message);
                if (arguments.Accept != null)
                {
                    alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true));
                }
                alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false));
                alert.CancelEvent += (o, args) => { arguments.SetResult(false); };
                alert.Show();
            }
		void downloadWhatsAppFileCompleted (object sender, AsyncCompletedEventArgs e) {
			RunOnUiThread (() => {
				progressDialog.Dismiss ();
				if (downloadedOK) {
					var installApk = new Intent(Intent.ActionView);
					installApk.SetDataAndType(Android.Net.Uri.Parse("file://" + fullLatestWhatsAppFilename), "application/vnd.android.package-archive");
					installApk.SetFlags(ActivityFlags.NewTask);
					try {
						StartActivity(installApk);
						AlertDialog deleteWhatsApp = new AlertDialog.Builder (this).Create ();
						deleteWhatsApp.SetTitle (Resources.GetString(Resource.String.delete));
						deleteWhatsApp.SetMessage (Resources.GetString(Resource.String.delete_description));
						deleteWhatsApp.SetButton ((int)DialogButtonType.Positive, Resources.GetString(Resource.String.delete_button_delete), (object senderDelete, DialogClickEventArgs eDelete) => File.Delete(fullLatestWhatsAppFilename));
						deleteWhatsApp.SetButton ((int)DialogButtonType.Negative, Resources.GetString(Resource.String.delete_button_cancel), (object senderCancel, DialogClickEventArgs eCancel) => deleteWhatsApp.Dismiss ());
						deleteWhatsApp.SetCancelable (false);
						deleteWhatsApp.Show ();
					} catch (ActivityNotFoundException ex) {
						var errorInstalled = new AlertDialog.Builder (this).Create ();
						errorInstalled.SetTitle (Resources.GetString(Resource.String.download_error));
						errorInstalled.SetMessage (string.Format(Resources.GetString(Resource.String.download_error_description), "WhatsApp " + latestWhatsAppVersion));
						errorInstalled.Show ();	
					}
					downloadedOK = false;
				} else {
					File.Delete(fullLatestWhatsAppFilename);
				}
			});
		}
		// Retrieve latest version of Beta Updater
		public async Task GetLatestAppVersion (string pageUrl) {
			var getVersion = new WebClient();
			string htmlAndroid = getVersion.DownloadString (new Uri(pageUrl));

			// Get WhatsApp latest version
			string[] split = htmlAndroid.Split (new char[] { '>' });
			int i = 0;
			while (i < split.Length) {
				if (split.GetValue (i).ToString ().StartsWith ("v")) {
					split = split.GetValue (i).ToString ().Split (new char[] { 'v', '<' });
					latestAppVersion = split.GetValue (1).ToString ().Trim ();
					break;
				}
				i++;
			}

			installedAppVersion = PackageManager.GetPackageInfo ("com.javiersantos.whatsappbetaupdater", 0).VersionName.Trim ();

			if (CompareVersionReceiver.VersionCompare (installedAppVersion, latestAppVersion) < 0) {
				appApk = appApk + "v" + latestAppVersion + "/com.javiersantos.whatsappbetaupdater.apk";

				AlertDialog appUpdateDialog = new AlertDialog.Builder (this).Create ();
				appUpdateDialog.SetTitle (string.Format(Resources.GetString(Resource.String.app_update), latestAppVersion));
				appUpdateDialog.SetMessage (string.Format(Resources.GetString(Resource.String.app_update_description), Resources.GetString(Resource.String.app_name)));
				appUpdateDialog.SetButton ((int)DialogButtonType.Positive, Resources.GetString (Resource.String.update_button), (object senderUpdateAppOK, DialogClickEventArgs eUpdateAppOK) => {
					SetDownloadDialog ();
					var webClient = new WebClient ();
					webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler (downloadProgressChanged);
					webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (downloadAppFileCompleted);
					webClient.DownloadFileAsync (new Uri (appApk), fullLatestAppFilename);
					progressDialog.SetTitle (string.Format(Resources.GetString(Resource.String.downloading), Resources.GetString(Resource.String.app_name) + " " + latestAppVersion + "..."));
					progressDialog.SetButton (Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => {webClient.CancelAsync (); progressDialog.Dismiss ();});
					progressDialog.Show ();
				});
				appUpdateDialog.SetButton ((int)DialogButtonType.Negative, Resources.GetString(Resource.String.cancel_button), (object senderUpdateAppCancel, DialogClickEventArgs eUpdateAppCancel) => appUpdateDialog.Dismiss ());
				appUpdateDialog.SetButton ((int)DialogButtonType.Neutral, Resources.GetString(Resource.String.never_button), (object senderUpdateAppNever, DialogClickEventArgs eUpdateAppNever) => {prefs.Edit().PutBoolean("prefShowAppUpdates", false).Commit(); appUpdateDialog.Dismiss (); });
				appUpdateDialog.SetCancelable (false);
				appUpdateDialog.Show ();
			}
		}
		// Retrieve latest version of WhatsApp
		public async Task GetLatestWhatsAppVersion (string pageUrl) {
			var getVersion = new WebClient();
			string htmlAndroid = getVersion.DownloadString (new Uri(pageUrl));

			// Get WhatsApp latest version
			string[] split = htmlAndroid.Split (new char[] { '>' });
			int i = 0;
			while (i < split.Length) {
				if (split.GetValue (i).ToString ().StartsWith ("Version")) {
					split = split.GetValue (i).ToString ().Split (new char[] { ' ', '<' });
					latestWhatsAppVersion = split.GetValue (1).ToString ().Trim ();
					break;
				}
				i++;
			}

			// Display WhatsApp installed and latest version
			TextView whatsapp_installed_version = FindViewById<TextView> (Resource.Id.whatsapp_installed_version);
			TextView whatsapp_latest_version = FindViewById<TextView> (Resource.Id.whatsapp_latest_version);

			installedWhatsAppVersion = PackageManager.GetPackageInfo ("com.whatsapp", 0).VersionName.Trim ();

			whatsapp_installed_version.Text = installedWhatsAppVersion;
			whatsapp_latest_version.Text = latestWhatsAppVersion;

			fullLatestWhatsAppFilename = filename + "WhatsApp_" + latestWhatsAppVersion + ".apk";

			// Load Floating Button
			var fab = FindViewById<FloatingActionButton> (Resource.Id.fab);

			// Compare installed and latest WhatsApp version
			if (CompareVersionReceiver.VersionCompare(installedWhatsAppVersion, latestWhatsAppVersion) < 0) { // There is a new version
				fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_download));
				// Preference: Autodownload
				if (prefAutoDownload) {
					SetDownloadDialog ();
					var webClient = new WebClient ();
					webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler (downloadProgressChanged);
					webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (downloadWhatsAppFileCompleted);
					webClient.DownloadFileAsync (new Uri (whatsAppApk), fullLatestWhatsAppFilename);
					progressDialog.SetTitle (string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "..."));
					progressDialog.SetButton (Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => {webClient.CancelAsync (); progressDialog.Dismiss ();});
					progressDialog.Show ();
				} else {
					fab.Click += delegate {
						SetDownloadDialog ();
						var webClient = new WebClient ();
						webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler (downloadProgressChanged);
						webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (downloadWhatsAppFileCompleted);
						webClient.DownloadFileAsync (new Uri (whatsAppApk), fullLatestWhatsAppFilename);
						progressDialog.SetTitle (string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "..."));
						progressDialog.SetButton (Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => {webClient.CancelAsync (); progressDialog.Dismiss ();});
						progressDialog.Show ();
					};
				}
			// There is not a new version
			} else {
				fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_menu_about));
				fab.Click += delegate {
					AlertDialog errorInstalled = new AlertDialog.Builder (this).Create ();
					errorInstalled.SetTitle (Resources.GetString(Resource.String.latest_installed));
					errorInstalled.SetMessage (string.Format(Resources.GetString(Resource.String.latest_installed_description), "WhatsApp " + installedWhatsAppVersion));
					errorInstalled.SetButton ((int)DialogButtonType.Positive, Resources.GetString(Resource.String.ok), (object senderClose, DialogClickEventArgs eClose) => errorInstalled.Dismiss ());
					errorInstalled.Show ();
				};
			}
		}
        // Retrieve latest version of WhatsApp
        public async Task GetLatestWhatsAppVersion(string pageUrl)
        {
            var    getVersion  = new WebClient();
            string htmlAndroid = getVersion.DownloadString(new Uri(pageUrl));

            // Get WhatsApp latest version
            string[] split = htmlAndroid.Split(new char[] { '>' });
            int      i     = 0;

            while (i < split.Length)
            {
                if (split.GetValue(i).ToString().StartsWith("Version"))
                {
                    split = split.GetValue(i).ToString().Split(new char[] { ' ', '<' });
                    latestWhatsAppVersion = split.GetValue(1).ToString().Trim();
                    break;
                }
                i++;
            }

            // Display WhatsApp installed and latest version
            TextView whatsapp_installed_version = FindViewById <TextView> (Resource.Id.whatsapp_installed_version);
            TextView whatsapp_latest_version    = FindViewById <TextView> (Resource.Id.whatsapp_latest_version);

            installedWhatsAppVersion = PackageManager.GetPackageInfo("com.whatsapp", 0).VersionName.Trim();

            whatsapp_installed_version.Text = installedWhatsAppVersion;
            whatsapp_latest_version.Text    = latestWhatsAppVersion;

            fullLatestWhatsAppFilename = filename + "WhatsApp_" + latestWhatsAppVersion + ".apk";

            // Load Floating Button
            var fab = FindViewById <FloatingActionButton> (Resource.Id.fab);

            // Compare installed and latest WhatsApp version
            if (CompareVersionReceiver.VersionCompare(installedWhatsAppVersion, latestWhatsAppVersion) < 0)               // There is a new version
            {
                fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_download));
                // Preference: Autodownload
                if (prefAutoDownload)
                {
                    SetDownloadDialog();
                    var webClient = new WebClient();
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged);
                    webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(downloadWhatsAppFileCompleted);
                    webClient.DownloadFileAsync(new Uri(whatsAppApk), fullLatestWhatsAppFilename);
                    progressDialog.SetTitle(string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "..."));
                    progressDialog.SetButton(Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => { webClient.CancelAsync(); progressDialog.Dismiss(); });
                    progressDialog.Show();
                }
                else
                {
                    fab.Click += delegate {
                        SetDownloadDialog();
                        var webClient = new WebClient();
                        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged);
                        webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(downloadWhatsAppFileCompleted);
                        webClient.DownloadFileAsync(new Uri(whatsAppApk), fullLatestWhatsAppFilename);
                        progressDialog.SetTitle(string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "..."));
                        progressDialog.SetButton(Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => { webClient.CancelAsync(); progressDialog.Dismiss(); });
                        progressDialog.Show();
                    };
                }
                // There is not a new version
            }
            else
            {
                fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_menu_about));
                fab.Click += delegate {
                    AlertDialog errorInstalled = new AlertDialog.Builder(this).Create();
                    errorInstalled.SetTitle(Resources.GetString(Resource.String.latest_installed));
                    errorInstalled.SetMessage(string.Format(Resources.GetString(Resource.String.latest_installed_description), "WhatsApp " + installedWhatsAppVersion));
                    errorInstalled.SetButton((int)DialogButtonType.Positive, Resources.GetString(Resource.String.ok), (object senderClose, DialogClickEventArgs eClose) => errorInstalled.Dismiss());
                    errorInstalled.Show();
                };
            }
        }