private void handleCropResult(Android.Net.Uri uri, Bitmap bitmap, Java.Lang.Exception error) { if (error == null) { Intent intent = new Intent(Activity, typeof(CropResultActivity)); if (uri != null) { intent.PutExtra("URI", uri); } else { CropResultActivity.mImage = mCropImageView.GetCropShape() == CropImageView.CropShape.Oval ? CropImage.ToOvalBitmap(bitmap) : bitmap; } StartActivity(intent); } else { Log.Error("AIC", "Failed to crop image", error); Toast.MakeText(Activity, "Image crop failed: " + error.Message, ToastLength.Long).Show(); } }
public void ShowFromFile(ImageCropper imageCropper, string imageFile, OutputImageFormatType outputImageFormat) { try { CropImage.ActivityBuilder activityBuilder = CropImage.Activity(Android.Net.Uri.FromFile(new Java.IO.File(imageFile))); if (imageCropper.CropShape == ImageCropper.CropShapeType.Oval) { activityBuilder.SetCropShape(CropImageView.CropShape.Oval); } else { activityBuilder.SetCropShape(CropImageView.CropShape.Rectangle); } if (imageCropper.AspectRatioX > 0 && imageCropper.AspectRatioY > 0) { activityBuilder.SetFixAspectRatio(true); activityBuilder.SetAspectRatio(imageCropper.AspectRatioX, imageCropper.AspectRatioY); } else { activityBuilder.SetFixAspectRatio(false); } if (!string.IsNullOrWhiteSpace(imageCropper.PageTitle)) { activityBuilder.SetActivityTitle(imageCropper.PageTitle); } activityBuilder.Start(CrossCurrentActivity.Current.Activity); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent) { base.OnActivityResult(requestCode, resultCode, intent); if (requestCode == PickImageId) { if ((resultCode == Result.Ok) && (intent != null)) { Android.Net.Uri uri = intent.Data; Stream stream = ContentResolver.OpenInputStream(uri); // Set the Stream as the completion of the Task PickImageTaskCompletionSource.SetResult(stream); } else { PickImageTaskCompletionSource.SetResult(null); } } if (requestCode == CropImage.CropImageActivityRequestCode) { CropImage.ActivityResult result = CropImage.GetActivityResult(intent); if (resultCode == Result.Ok) { ImageCropper.Current.Success?.Invoke(result.Uri.Path); } else if ((int)resultCode == (int)CropImage.CropImageActivityResultErrorCode) { ImageCropper.Current.Faiure?.Invoke(); } } else { base.OnActivityResult(requestCode, resultCode, intent); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 108 || requestCode == CropImage.CropImageActivityRequestCode) { if (Methods.CheckConnectivity()) { var result = CropImage.GetActivityResult(data); if (result.IsSuccessful) { var resultPathImage = result.Uri.Path; if (!string.IsNullOrEmpty(resultPathImage)) { PathImage = resultPathImage; var file = Uri.FromFile(new File(result.Uri.Path)); GlideImageLoader.LoadImage(this, file.Path, Image, ImageStyle.CenterCrop, ImagePlaceholders.Drawable); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } } catch (Exception e) { Console.WriteLine(e); } }
private void LoadImage(string path) { if (path == null) { return; } if (postData.imageNames == null) { postData.imageNames = new List <string>(); } postData.imageNames.Add(path); GameObject cropImage_obj = Instantiate(cropImage_prefab, imgBoard, false); cropImage_obj.GetComponent <RectTransform>().sizeDelta = new Vector2(imgBoard.gameObject.GetComponent <RectTransform>().sizeDelta.y, imgBoard.gameObject.GetComponent <RectTransform>().sizeDelta.y); CropImage cropImage = cropImage_obj.GetComponent <CropImage>(); cropImage.image.sprite = IMG2Sprite.LoadNewSprite(path); cropImage.GetComponent <CropImage>().FitCanvas(); }
public void onDrawerOptionClicked(View view) { switch (view.Id) { case Resource.Id.drawer_option_load: if (CropImage.IsExplicitCameraPermissionRequired(this)) { RequestPermissions(new string[] { Manifest.Permission.Camera }, CropImage.CameraCapturePermissionsRequestCode); } else { CropImage.StartPickImageActivity(this); } mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_oval: setMainFragmentByPreset(CropDemoPreset.CIRCULAR); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_rect: setMainFragmentByPreset(CropDemoPreset.RECT); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_customized_overlay: setMainFragmentByPreset(CropDemoPreset.CUSTOMIZED_OVERLAY); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_min_max_override: setMainFragmentByPreset(CropDemoPreset.MIN_MAX_OVERRIDE); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_scale_center: setMainFragmentByPreset(CropDemoPreset.SCALE_CENTER_INSIDE); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_toggle_scale: mCropImageViewOptions.scaleType = mCropImageViewOptions.scaleType == CropImageView.ScaleType.FitCenter ? CropImageView.ScaleType.CenterInside : mCropImageViewOptions.scaleType == CropImageView.ScaleType.CenterInside ? CropImageView.ScaleType.Center : mCropImageViewOptions.scaleType == CropImageView.ScaleType.Center ? CropImageView.ScaleType.CenterCrop : CropImageView.ScaleType.FitCenter; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_toggle_shape: mCropImageViewOptions.cropShape = mCropImageViewOptions.cropShape == CropImageView.CropShape.Rectangle ? CropImageView.CropShape.Oval : CropImageView.CropShape.Rectangle; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_toggle_guidelines: mCropImageViewOptions.guidelines = mCropImageViewOptions.guidelines == CropImageView.Guidelines.Off ? CropImageView.Guidelines.On : mCropImageViewOptions.guidelines == CropImageView.Guidelines.On ? CropImageView.Guidelines.OnTouch : CropImageView.Guidelines.Off; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_toggle_aspect_ratio: if (!mCropImageViewOptions.fixAspectRatio) { mCropImageViewOptions.fixAspectRatio = true; mCropImageViewOptions.aspectRatio = new Android.Util.Pair(1, 1); } else { if ((int)mCropImageViewOptions.aspectRatio.First == 1 && (int)mCropImageViewOptions.aspectRatio.Second == 1) { mCropImageViewOptions.aspectRatio = new Android.Util.Pair(4, 3); } else if ((int)mCropImageViewOptions.aspectRatio.First == 4 && (int)mCropImageViewOptions.aspectRatio.Second == 3) { mCropImageViewOptions.aspectRatio = new Android.Util.Pair(16, 9); } else if ((int)mCropImageViewOptions.aspectRatio.First == 16 && (int)mCropImageViewOptions.aspectRatio.Second == 9) { mCropImageViewOptions.aspectRatio = new Android.Util.Pair(9, 16); } else { mCropImageViewOptions.fixAspectRatio = false; } } mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_toggle_auto_zoom: mCropImageViewOptions.autoZoomEnabled = !mCropImageViewOptions.autoZoomEnabled; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_toggle_max_zoom: mCropImageViewOptions.maxZoomLevel = mCropImageViewOptions.maxZoomLevel == 4 ? 8 : mCropImageViewOptions.maxZoomLevel == 8 ? 2 : 4; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_set_initial_crop_rect: mCurrentFragment.setInitialCropRect(); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_reset_crop_rect: mCurrentFragment.resetCropRect(); mDrawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_toggle_show_overlay: mCropImageViewOptions.showCropOverlay = !mCropImageViewOptions.showCropOverlay; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; case Resource.Id.drawer_option_toggle_show_progress_bar: mCropImageViewOptions.showProgressBar = !mCropImageViewOptions.showProgressBar; mCurrentFragment.setCropImageViewOptions(mCropImageViewOptions); updateDrawerTogglesByOptions(mCropImageViewOptions); break; default: Toast.MakeText(this, "Unknown drawer option clicked", ToastLength.Long).Show(); break; } }
//Permissions public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { try { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 101) { if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { SaveImage(); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_Permission_is_denailed), ToastLength.Long) .Show(); } } else if (requestCode == 10) { Methods.Path.Chack_MyFolder(); } else if (requestCode == CropImage.PickImagePermissionsRequestCode) { if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { //Open Image var myUri = Uri.FromFile(new File(Methods.Path.FolderDcimNiceArt, Methods.GetTimestamp(DateTime.Now) + ".jpeg")); CropImage.Builder() .SetInitialCropWindowPaddingRatio(0) .SetAutoZoomEnabled(true) .SetMaxZoom(4) .SetGuidelines(CropImageView.Guidelines.On) .SetCropMenuCropButtonTitle(GetText(Resource.String.Lbl_Done)) .SetOutputUri(myUri).Start(this); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_Permission_is_denailed), ToastLength.Long) .Show(); } } else if (requestCode == CropImage.CameraCapturePermissionsRequestCode) { if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { CropImage.StartPickImageActivity(this); } else { Toast.MakeText(this, GetString(Resource.String.Lbl_Permission_is_denailed), ToastLength.Long) .Show(); } } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); //If its from Camera or Gallery if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { var imageUri = CropImage.GetPickImageResultUri(this, data); if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { var intent = new Intent(this, typeof(AddStory_Activity)); intent.PutExtra("Uri", resultUri.Path); intent.PutExtra("Type", "image"); StartActivity(intent); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } } } else if (requestCode == CropImage.CropImageActivityResultErrorCode) { var result = CropImage.GetActivityResult(data); Exception error = result.Error; } else if (requestCode == 100 && resultCode == Result.Ok) { var FullPath = IMethods.MultiMedia.GetRealVideoPathFromURI(data.Data); if (!string.IsNullOrEmpty(FullPath)) { var intent = new Intent(this, typeof(AddStory_Activity)); intent.PutExtra("Uri", FullPath); intent.PutExtra("Type", "video"); StartActivity(intent); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long) .Show(); } } else if (requestCode == 2 && resultCode == Result.Ok) { SearchViewBar.Focusable = false; SearchViewBar.FocusableInTouchMode = false; SearchViewBar.ClearFocus(); } else if (requestCode == 2500) { News_Feed_Tab.HybridController.EvaluateJavascript("Wo_GetNewPosts();"); } else if (requestCode == 3500) { string ID = data.GetStringExtra("PostId"); string Text = data.GetStringExtra("PostText"); string JavaCode = "$('#post-' + " + ID + ").find('#edit-post').attr('onclick', '{*type*:*edit_post*,*post_id*:*" + ID + "*,*edit_text*:*" + Text + "*}');"; string Decode = JavaCode.Replace("*", """); News_Feed_Tab.HybridController.EvaluateJavascript(Decode); News_Feed_Tab.HybridController.EvaluateJavascript("$('#post-' + " + ID + ").find('.post-description p').html('" + Text + "');"); } } catch (Exception e) { Crashes.TrackError(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 500 && resultCode == Result.Ok) // Add image { if (data.ClipData != null) { var mClipData = data.ClipData; for (var i = 0; i < mClipData.ItemCount; i++) { //var item = mClipData.GetItemAt(i); Uri uri = data.Data; var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, uri); PickiTonCompleteListener(filepath); } } else { Uri uri = data.Data; var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, uri); PickiTonCompleteListener(filepath); } } else if (requestCode == CropImage.CropImageActivityRequestCode) // Add image { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { var attach = new Attachments { Id = MAdapter.AttachmentList.Count + 1, TypeAttachment = "postPhotos[]", FileSimple = resultUri.Path, FileUrl = resultUri.Path }; MAdapter.Add(attach); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); //If its from Camera or Gallery if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { GroupPathImage = resultUri.Path; File file2 = new File(resultUri.Path); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this).Load(photoUri).Apply(new RequestOptions()).Into(ImageGroup); //GlideImageLoader.LoadImage(this, resultUri.Path, ImageGroup, ImageStyle.RoundedCrop, ImagePlaceholders.Drawable); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_Something_went_wrong), ToastLength.Long).Show(); } } } } else if (requestCode == 3) { NewUserList = MentionActivity.MAdapter.MentionList.Where(a => a.Selected).ToList(); UsersIds = ""; foreach (var user in NewUserList) { UsersIds += user.UserId + ","; var dataUser = MAdapter.UserList.FirstOrDefault(attachments => attachments.UserId == user.UserId); if (dataUser == null) { MAdapter.UserList.Add(user); } } UsersIds = UsersIds.Remove(UsersIds.Length - 1, 1); MAdapter.NotifyDataSetChanged(); var(apiStatus, respond) = await RequestsAsync.GroupChat .AddOrRemoveUserToGroup(GroupData.GroupId, UsersIds, "add_user").ConfigureAwait(false); if (apiStatus == 200) { } else { Methods.DisplayReportResult(this, respond); } } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); switch (requestCode) { // Add image case CropImage.CropImageActivityRequestCode when resultCode == Result.Ok: { var result = CropImage.GetActivityResult(data); switch (result.IsSuccessful) { case true: { var resultUri = result.Uri; switch (string.IsNullOrEmpty(resultUri.Path)) { case false: { // Chick if it was successful var check = WoWonderTools.CheckMimeTypesWithServer(resultUri.Path); switch (check) { case false: //this file not supported on the server , please select another file Toast.MakeText(this, GetString(Resource.String.Lbl_ErrorFileNotSupported), ToastLength.Short)?.Show(); return; } var attach = new Attachments { Id = MAdapter.AttachmentList.Count + 1, TypeAttachment = "postPhotos[]", FileSimple = resultUri.Path, FileUrl = resultUri.Path }; MAdapter.Add(attach); break; } default: Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show(); break; } break; } default: Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show(); break; } break; } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
//Result protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (AppSettings.ShowInAppBilling) { BillingPayment?.Handler?.HandleActivityResult(requestCode, resultCode, data); } if (requestCode == 108 || requestCode == CropImage.CropImageActivityRequestCode) { if (Methods.CheckConnectivity()) { var result = CropImage.GetActivityResult(data); if (result.IsSuccessful) { var resultPathImage = result.Uri.Path; if (!string.IsNullOrEmpty(resultPathImage)) { if (TypeAvatar == OpenGalleryDialogFor.Avatar) { GlideImageLoader.LoadImage(this, resultPathImage, ProfileFragment?.ProfileImage, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => ApiRequest.UpdateAvatarApi(this, resultPathImage) }); } else { //sent api PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => RequestsAsync.Users.UploadMediaFileUserAsync(resultPathImage) }); } var reviewMediaFiles = ListUtils.SettingsSiteList.FirstOrDefault()?.ReviewMediaFiles; if (reviewMediaFiles == "1") //Uploaded successfully, file will be reviewed { Toast.MakeText(this, GetText(Resource.String.Lbl_UploadedSuccessfullyWithReviewed), ToastLength.Long).Show(); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_UploadedSuccessfully), ToastLength.Long).Show(); } } } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } else if (requestCode == 1050) //1050 { //Get Location And Get Data Api TrendingFragment?.CheckAndGetLocation(); } else if (requestCode == InitPayPalPayment?.PayPalDataRequestCode) { switch (resultCode) { case Result.Ok: var confirmObj = data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation); PaymentConfirmation configuration = Android.Runtime.Extensions.JavaCast <PaymentConfirmation>(confirmObj); if (configuration != null) { //string createTime = configuration.ProofOfPayment.CreateTime; //string intent = configuration.ProofOfPayment.Intent; //string paymentId = configuration.ProofOfPayment.PaymentId; //string state = configuration.ProofOfPayment.State; //string transactionId = configuration.ProofOfPayment.TransactionId; if (InitPayPalPayment?.PayType != "membership") { if (Methods.CheckConnectivity()) { (int apiStatus, var respond) = await RequestsAsync.Auth.SetCreditAsync(InitPayPalPayment?.Credits, InitPayPalPayment?.Price, "PayPal").ConfigureAwait(false); if (apiStatus == 200) { if (respond is SetCreditObject result) { RunOnUiThread(() => { try { var dataUser = ListUtils.MyUserInfo.FirstOrDefault(a => a.Id == UserDetails.UserId); if (dataUser != null) { dataUser.Balance = result.Balance; var sqlEntity = new SqLiteDatabase(); sqlEntity.InsertOrUpdate_DataMyInfo(dataUser); sqlEntity.Dispose(); } if (ProfileFragment.WalletNumber != null) { ProfileFragment.WalletNumber.Text = result.Balance; } Toast.MakeText(this, GetText(Resource.String.Lbl_Done), ToastLength.Long).Show(); } catch (Exception e) { Console.WriteLine(e); } }); } } else { Methods.DisplayReportResult(this, respond); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } else { if (Methods.CheckConnectivity()) { (int apiStatus, var respond) = await RequestsAsync.Auth.SetProAsync(InitPayPalPayment?.Id, InitPayPalPayment?.Price, "PayPal").ConfigureAwait(false); if (apiStatus == 200) { RunOnUiThread(() => { try { var dataUser = ListUtils.MyUserInfo.FirstOrDefault(); if (dataUser != null) { dataUser.VerifiedFinal = true; dataUser.IsPro = "1"; var sqlEntity = new SqLiteDatabase(); sqlEntity.InsertOrUpdate_DataMyInfo(dataUser); sqlEntity.Dispose(); } Toast.MakeText(this, GetText(Resource.String.Lbl_Done), ToastLength.Long).Show(); } catch (Exception e) { Console.WriteLine(e); } }); } else { Methods.DisplayReportResult(this, respond); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } } break; case Result.Canceled: Toast.MakeText(this, GetText(Resource.String.Lbl_Canceled), ToastLength.Long).Show(); break; } } else if (requestCode == PaymentActivity.ResultExtrasInvalid) { Toast.MakeText(this, GetText(Resource.String.Lbl_Invalid), ToastLength.Long).Show(); } else if (requestCode == 1001 && resultCode == Result.Ok && AppSettings.ShowInAppBilling) { if (BillingPayment?.PayType != "membership") { if (Methods.CheckConnectivity()) { (int apiStatus, var respond) = await RequestsAsync.Auth.SetCreditAsync(BillingPayment?.Credits, BillingPayment?.Price, "Google InApp").ConfigureAwait(false); if (apiStatus == 200) { if (respond is SetCreditObject result) { RunOnUiThread(() => { try { var dataUser = ListUtils.MyUserInfo.FirstOrDefault(); if (dataUser != null) { dataUser.Balance = result.Balance; var sqlEntity = new SqLiteDatabase(); sqlEntity.InsertOrUpdate_DataMyInfo(dataUser); sqlEntity.Dispose(); } if (ProfileFragment.WalletNumber != null) { ProfileFragment.WalletNumber.Text = result.Balance.Replace(".00", ""); } Toast.MakeText(this, GetText(Resource.String.Lbl_Done), ToastLength.Long).Show(); } catch (Exception e) { Console.WriteLine(e); } }); } } else { Methods.DisplayReportResult(this, respond); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } else { if (Methods.CheckConnectivity()) { (int apiStatus, var respond) = await RequestsAsync.Auth.SetProAsync(BillingPayment?.Id, BillingPayment?.Price, "Google InApp").ConfigureAwait(false); if (apiStatus == 200) { RunOnUiThread(() => { try { var dataUser = ListUtils.MyUserInfo.FirstOrDefault(); if (dataUser != null) { dataUser.VerifiedFinal = true; dataUser.IsPro = "1"; var sqlEntity = new SqLiteDatabase(); sqlEntity.InsertOrUpdate_DataMyInfo(dataUser); sqlEntity.Dispose(); } Toast.MakeText(this, GetText(Resource.String.Lbl_Done), ToastLength.Long).Show(); } catch (Exception e) { Console.WriteLine(e); } }); } else { Methods.DisplayReportResult(this, respond); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 108 || requestCode == CropImage.CropImageActivityRequestCode) { if (Methods.CheckConnectivity()) { var result = CropImage.GetActivityResult(data); if (result.IsSuccessful) { var resultPathImage = result.Uri.Path; if (!string.IsNullOrEmpty(resultPathImage)) { var unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); string time2 = unixTimestamp.ToString(CultureInfo.InvariantCulture); //Sent image ChatMessagesDataObject message = new ChatMessagesDataObject { Id = Convert.ToInt32(unixTimestamp), FromId = UserDetails.UserId, ToId = Userid, Text = "", Seen = 0, Time = unixTimestamp, FromDeleted = 0, ToDeleted = 0, SentPush = 0, NotificationId = "", TypeTwo = "", Image = resultPathImage, FullImage = "", ApiPosition = ApiPosition.Right, ApiType = ApiType.Image, Hash = time2 }; MAdapter.MessageList.Add(message); int index = MAdapter.MessageList.IndexOf(MAdapter.MessageList.Last()); if (index > -1) { MAdapter.NotifyItemInserted(index); //Scroll Down >> ChatBoxRecyclerView.ScrollToPosition(index); } PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => MessageController.SendMessageTask(Userid, "", resultPathImage, time2, UserInfoData) }); EmojisIconEditTextView.Text = ""; } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); switch (requestCode) { case 502 when resultCode == Result.Ok: GetPlaceFromPicker(data); break; case CropImage.CropImageActivityRequestCode: { var result = CropImage.GetActivityResult(data); switch (resultCode) { case Result.Ok: { switch (result.IsSuccessful) { case true: { var resultUri = result.Uri; switch (string.IsNullOrEmpty(resultUri.Path)) { case false: { var productPathImage = resultUri.Path; var attach = new Attachments { Id = MAdapter.AttachmentList.Count + 1, TypeAttachment = "images[]", FileSimple = productPathImage, FileUrl = productPathImage }; MAdapter.Add(attach); break; } default: Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show(); break; } break; } } break; } } break; } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); switch (requestCode) { //If its from Camera or Gallery case CropImage.CropImageActivityRequestCode when resultCode == Result.Ok: { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { GroupPathImage = resultUri.Path; File file2 = new File(resultUri.Path); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this).Load(photoUri).Apply(new RequestOptions()).Into(ImageGroup); } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show(); } } } break; } case 3: { UserList = MentionActivity.MAdapter.MentionList.Where(a => a.Selected).ToList(); UsersIds = ""; foreach (var user in UserList) { UsersIds += user.UserId + ","; var dataUser = MAdapter.UserList.FirstOrDefault(attachments => attachments.UserId == user.UserId); if (dataUser == null) { MAdapter.UserList.Insert(1, user); } } UsersIds = UsersIds.Remove(UsersIds.Length - 1, 1); MAdapter.NotifyDataSetChanged(); break; } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void OpenGallery(string type) { try { TypeImage = type; if (!Methods.CheckConnectivity()) { Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); } else { switch ((int)Build.VERSION.SdkInt) { // Check if we're running on Android 5.0 or higher case < 23: { Methods.Path.Chack_MyFolder(); //Open Image var myUri = Uri.FromFile(new File(Methods.Path.FolderDiskImage, Methods.GetTimestamp(DateTime.Now) + ".jpeg")); CropImage.Activity() .SetInitialCropWindowPaddingRatio(0) .SetAutoZoomEnabled(true) .SetMaxZoom(4) .SetGuidelines(CropImageView.Guidelines.On) .SetCropMenuCropButtonTitle(GetText(Resource.String.Lbl_Crop)) .SetOutputUri(myUri).Start(this); break; } default: { if (!CropImage.IsExplicitCameraPermissionRequired(this) && CheckSelfPermission(Manifest.Permission.ReadExternalStorage) == Permission.Granted && CheckSelfPermission(Manifest.Permission.WriteExternalStorage) == Permission.Granted && CheckSelfPermission(Manifest.Permission.Camera) == Permission.Granted) { Methods.Path.Chack_MyFolder(); //Open Image var myUri = Uri.FromFile(new File(Methods.Path.FolderDiskImage, Methods.GetTimestamp(DateTime.Now) + ".jpeg")); CropImage.Activity() .SetInitialCropWindowPaddingRatio(0) .SetAutoZoomEnabled(true) .SetMaxZoom(4) .SetGuidelines(CropImageView.Guidelines.On) .SetCropMenuCropButtonTitle(GetText(Resource.String.Lbl_Crop)) .SetOutputUri(myUri).Start(this); } else { new PermissionsController(this).RequestPermission(108); } break; } } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); switch (requestCode) { //If its from Camera or Gallery case CropImage.CropImageActivityRequestCode: { CropImage.ActivityResult result = CropImage.GetActivityResult(data); switch (resultCode) { case Result.Ok when result.IsSuccessful: { Uri resultUri = result.Uri; switch (string.IsNullOrEmpty(resultUri.Path)) { case false: switch (TypeImage) { case "YourImage": { PathYourImage = resultUri.Path; File file2 = new File(resultUri.Path); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this).Load(photoUri).Apply(new RequestOptions()).Into(YourImage); break; } case "Passport": { PathPassportImage = resultUri.Path; File file2 = new File(resultUri.Path); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this).Load(photoUri).Apply(new RequestOptions()).Into(PassportImage); break; } } break; default: Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Short)?.Show(); break; } break; } } break; } } } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } }
public async Task <UploadImageResult> CropAndUpload(CropImage model, HttpPostedFileBase sourceImage, string sourcePath = null, int w = 0) { try { float scale = float.Parse(model.Scale, CultureInfo.InvariantCulture); // Якщо шлях не задано збережемо в тимчасову папку if (sourcePath == null) { sourcePath = userId + "/temporary_thumbnail/"; } else { sourcePath = userId + sourcePath; } // Ім'я зображення string fileName = model.PathPhoto.Substring(model.PathPhoto.LastIndexOf("/") + 1); // Повний шлях зображення uploadImageResult.PathFile = "/" + containerName + "/" + sourcePath + fileName; // Шлях для завантаження на Azure BLOB sourcePath = sourcePath + fileName; // Вхідний шлях для файла, обріжимо "/images/" if (scale > 0) { model.Width = (int)(model.Width / scale); model.Height = (int)(model.Height / scale); model.x = (int)(model.x / scale); model.y = (int)(model.y / scale); // not use //logger.Info("test: " + "Width " + model.Width + "Height " + model.Height + "x " + model.x + "y " + model.y + "scale " + model.Scale); } // Отримаєм потік і обріжимо за заданими кординатами Image image = Bitmap.FromStream(sourceImage.InputStream); SetImageOrientation(ref image); var bmp = new Bitmap(model.Width, model.Height, image.PixelFormat); var gra = Graphics.FromImage(bmp); gra.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; gra.DrawImage(image, new Rectangle(0, 0, model.Width, model.Height), new Rectangle(model.x, model.y, model.Width, model.Height), GraphicsUnit.Pixel); // Створимо новий потік var bmpStream = new MemoryStream(); // Якщо ширина обрізаного зображення більше за змінну "w" то зменшимо розміри зображення до ширини "w" // якщо менше то збережемо зображення в потік if (model.Width > w && w != 0) { bmpStream = ResizeImage(bmp, uploadImageResult.PathFile, fileName, w); } else { bmp.Save(bmpStream, image.RawFormat); } // Обнулимо позицію потоку bmpStream.Position = 0; // Отримаємо тип зображення що б потім використати при завантаженні на Azure BLOB string mimeType = SupportMimeTypeOfStream(image.RawFormat.Guid); // Завантаження потоку на Azure BLOB await UploadFileToAzureAsync(bmpStream, sourcePath, mimeType); image.Dispose(); bmp.Dispose(); gra.Dispose(); return(uploadImageResult); } catch (Exception e) { uploadImageResult.Error = e.Message; return(uploadImageResult); } }
protected override async void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); //If its from Camera or Gallery if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok && result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { var ch = ListUtils.MyChannelList.FirstOrDefault(); switch (ImageType) { case "Cover": { ImageCover = resultUri.Path; if (ch != null) { ch.Cover = ImageCover; } UserDetails.Cover = resultUri.Path; break; } case "Avatar": { ImageAvatar = resultUri.Path; if (ch != null) { ch.Avatar = ImageAvatar; } UserDetails.Avatar = resultUri.Path; break; } } if (ch != null) { var sqlEntity = new SqLiteDatabase(); sqlEntity.InsertOrUpdate_DataMyChannel(ch); sqlEntity.Dispose(); } //Send image function if (Methods.CheckConnectivity()) { if (ImageType == "Avatar" || ImageType == "Cover") { var(code, uploadAvatar) = await RequestsAsync.Global.Update_UserData_Image_Http(resultUri.Path, ImageType.ToLower()).ConfigureAwait(false); if (code == 200) { Console.WriteLine(uploadAvatar); } else { Methods.DisplayReportResult(this, uploadAvatar); } RunOnUiThread(() => { try { Toast.MakeText(this, GetText(Resource.String.Lbl_Image_changed_successfully), ToastLength.Short).Show(); Intent intent = new Intent(); SetResult(Result.Ok, intent); Finish(); } catch (Exception e) { Console.WriteLine(e); } }); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Short).Show(); } } } } catch (Exception exception) { Console.WriteLine(exception); } }
private void ImageUserCoverOnClick(object sender, EventArgs eventArgs) { try { try { TypeIMG = "Cover"; if ((int)Build.VERSION.SdkInt < 23) { //Open Image Android.Net.Uri myUri = Android.Net.Uri.FromFile(new File(IMethods.IPath.FolderDcimMyApp, IMethods.GetTimestamp(DateTime.Now) + ".jpeg")); CropImage.Builder().SetInitialCropWindowPaddingRatio(0).SetAutoZoomEnabled(true).SetMaxZoom(4) .SetGuidelines(CropImageView.Guidelines.On).SetCropMenuCropButtonTitle(this.GetText(Resource.String.Lbl_Done)) .SetActivityTitle(this.GetText(Resource.String.Lbl_Crop)).SetOutputUri(myUri).Start(this); return; } else { if (CropImage.IsExplicitCameraPermissionRequired(this)) { RequestPermissions(new[] { Manifest.Permission.Camera, Manifest.Permission.ReadExternalStorage }, CropImage.PickImagePermissionsRequestCode); } else { //Open Image Android.Net.Uri myUri = Android.Net.Uri.FromFile(new File(IMethods.IPath.FolderDcimMyApp, IMethods.GetTimestamp(DateTime.Now) + ".jpeg")); CropImage.Builder().SetInitialCropWindowPaddingRatio(0).SetAutoZoomEnabled(true) .SetMaxZoom(4).SetGuidelines(CropImageView.Guidelines.On) .SetCropMenuCropButtonTitle(this.GetText(Resource.String.Lbl_Done)).SetActivityTitle(this.GetText(Resource.String.Lbl_Crop)) .SetOutputUri(myUri).Start(this); return; } if (!ShouldShowRequestPermissionRationale(Manifest.Permission.ReadExternalStorage)) { //Open Image Android.Net.Uri myUri = Android.Net.Uri.FromFile(new File(IMethods.IPath.FolderDcimMyApp, IMethods.GetTimestamp(DateTime.Now) + ".jpeg")); CropImage.Builder().SetInitialCropWindowPaddingRatio(0).SetAutoZoomEnabled(true) .SetMaxZoom(4).SetGuidelines(CropImageView.Guidelines.On) .SetCropMenuCropButtonTitle(this.GetText(Resource.String.Lbl_Done)).SetActivityTitle(this.GetText(Resource.String.Lbl_Crop)) .SetOutputUri(myUri).Start(this); return; } else { Toast.MakeText(this, this.GetText(Resource.String.Lbl_Permission_is_denailed), ToastLength.Long).Show(); } } } catch (Exception exception) { Console.WriteLine(exception); } } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// Selects the image button click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void SelectImageButtonClick(object sender, System.EventArgs e) { CropImage.Activity() .SetGuidelines(CropImageView.Guidelines.On) .Start(this); }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); //If its from Camera or Gallary if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { var imageUri = CropImage.GetPickImageResultUri(this, data); if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { var pathimg = ""; if (TypeIMG == "Cover") { pathimg = resultUri.Path; Update_Image_Api(TypeIMG, pathimg); } else if (TypeIMG == "Avatar") { pathimg = resultUri.Path; Update_Image_Api(TypeIMG, pathimg); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_Something_went_wrong), ToastLength.Long).Show(); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_Something_went_wrong), ToastLength.Long) .Show(); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_Something_went_wrong), ToastLength.Long) .Show(); } } else if (requestCode == CropImage.CropImageActivityResultErrorCode) { var result = CropImage.GetActivityResult(data); Exception error = result.Error; } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); switch (requestCode) { // Add image case 500 when resultCode == Result.Ok: { if (data.ClipData != null) { var mClipData = data.ClipData; for (var i = 0; i < mClipData.ItemCount; i++) { var item = mClipData.GetItemAt(i); Uri uri = item.Uri; var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, uri); PickiTonCompleteListener(filepath); } } else { Uri uri = data.Data; var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, uri); PickiTonCompleteListener(filepath); } break; } case CropImage.CropImageActivityRequestCode when resultCode == Result.Ok: { var result = CropImage.GetActivityResult(data); switch (result.IsSuccessful) { case true: { var resultUri = result.Uri; switch (string.IsNullOrEmpty(resultUri.Path)) { case false: { var check = WoWonderTools.CheckMimeTypesWithServer(resultUri.Path); switch (check) { case false: //this file not supported on the server , please select another file Toast.MakeText(this, GetString(Resource.String.Lbl_ErrorFileNotSupported), ToastLength.Short)?.Show(); return; } MAdapter.PhotosList.Add(new PhotoAlbumObject { Image = resultUri.Path }); MAdapter.NotifyDataSetChanged(); PathImage.Add(new Attachments { Id = MAdapter.PhotosList.Count + 1, TypeAttachment = "postPhotos[]", FileSimple = resultUri.Path, FileUrl = resultUri.Path }); break; } } break; } } break; } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
//Result protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 503 && resultCode == Result.Ok) // Add image using camera { if (string.IsNullOrEmpty(IntentController.CurrentPhotoPath)) { var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, data.Data); if (filepath != null) { var type = Methods.AttachmentFiles.Check_FileExtension(filepath); if (type == "Image") { SendFile(filepath, filepath, "Image"); } } } else { if (Methods.MultiMedia.CheckFileIfExits(IntentController.CurrentPhotoPath) != "File Dont Exists") { SendFile(IntentController.CurrentPhotoPath, IntentController.CurrentPhotoPath, "Image"); } } } else if (requestCode == 501 && resultCode == Result.Ok) // Add video { var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, data.Data); if (filepath != null) { var type = Methods.AttachmentFiles.Check_FileExtension(filepath); if (type == "Video") { var fileName = filepath.Split('/').Last(); var fileNameWithoutExtension = fileName.Split('.').First(); var path = Methods.Path.FolderDcimVideo + "/" + fileNameWithoutExtension + ".png"; var videoPlaceHolderImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimVideo, fileNameWithoutExtension + ".png"); if (videoPlaceHolderImage == "File Dont Exists") { var bitmapImage = Methods.MultiMedia.Retrieve_VideoFrame_AsBitmap(this, data.Data.ToString()); if (bitmapImage != null) { Methods.MultiMedia.Export_Bitmap_As_Image(bitmapImage, fileNameWithoutExtension, Methods.Path.FolderDcimVideo); } else { File file2 = new File(filepath); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this) .AsBitmap() .Load(photoUri) // or URI/path .Into(new MySimpleTarget(filepath)); //image view to set thumbnail to await Task.Delay(500); } } SendFile(filepath, path, "Video"); } } } else if (requestCode == 513 && resultCode == Result.Ok) // Add video Camera { var filepath = Methods.AttachmentFiles.GetActualPathFromFile(this, data.Data); if (filepath != null) { var type = Methods.AttachmentFiles.Check_FileExtension(filepath); if (type == "Video") { var fileName = filepath.Split('/').Last(); var fileNameWithoutExtension = fileName.Split('.').First(); var path = Methods.Path.FolderDcimVideo + "/" + fileNameWithoutExtension + ".png"; var videoPlaceHolderImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimVideo, fileNameWithoutExtension + ".png"); if (videoPlaceHolderImage == "File Dont Exists") { var bitmapImage = Methods.MultiMedia.Retrieve_VideoFrame_AsBitmap(this, data.Data.ToString()); if (bitmapImage != null) { Methods.MultiMedia.Export_Bitmap_As_Image(bitmapImage, fileNameWithoutExtension, Methods.Path.FolderDcimVideo); } else { File file2 = new File(filepath); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this) .AsBitmap() .Load(photoUri) // or URI/path .Into(new MySimpleTarget(filepath)); //image view to set thumbnail to await Task.Delay(500); } } SendFile(filepath, path, "Video"); } } } else if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (result.IsSuccessful) { var resultPathImage = result.Uri.Path; if (!string.IsNullOrEmpty(resultPathImage)) { SendFile(resultPathImage, resultPathImage, "Image"); } } } } catch (Exception e) { Console.WriteLine(e); } }
private void StartCropImageActivity() { CropImage.Builder().SetCropShape(CropShape.Oval).SetFixAspectRatio(true).SetAspectRatio(1, 1).SetAllowFlipping(false).SetGuidelines(Guidelines.On).Start(this); }
public List <FileResultModel> CropSaveBanner([FromUri] Guid organizationId, [FromBody] CropImage body) { try { var filename = body.Filename; var yCropPosition = body.yCrop; var organization = new OrganizationComponent(organizationId); var portal = PortalController.GetCurrentPortalSettings(); var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo(); var tempId = Helper.HelperMethods.GenerateHash(currentUser.UserID).ToString(); if (currentUser.IsInRole("Registered Users")) { if (currentUser.IsInRole("Administrators") || organization.Organization.CreatedBy == DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().UserID) { var fileResultModelList = new List <FileResultModel>(); yCropPosition = yCropPosition * -1; string extension = ".png";//Path.GetExtension(filename); string fileRootName = organizationId.ToString(); MemoryStream outStream = new MemoryStream(); long tmpSize = 0; string ImageProcessingFolfer = Path.Combine(portal.HomeDirectoryMapPath + "OrgImages\\TempImages", filename); Helper.HelperMethods.DeleteFiles(portal.HomeDirectoryMapPath + "OrgImages\\HeaderImages", "*" + organizationId.ToString() + "*"); ImageFactory imageFactory = new ImageFactory(preserveExifData: true); imageFactory.Load(ImageProcessingFolfer); imageFactory.Save(outStream);// (); tmpSize = outStream.Length; Helper.HelperMethods.SaveImage(ref outStream, Path.Combine(portal.HomeDirectoryMapPath + "OrgImages\\HeaderImages", fileRootName + extension)); fileResultModelList.Add(new FileResultModel() { Extension = extension, Filename = fileRootName, Link = portal.HomeDirectory + "OrgImages/HeaderImages/" + fileRootName + extension, Description = "Original Image", Size = tmpSize }); var image = imageFactory.Image; var originalHeight = image.Size.Height; var originalWidth = image.Size.Width; float referenceHeight = 575; float referenceWidth = 1148; float WidthFactor = 1; WidthFactor = referenceWidth / originalWidth; float HeightFactor = 1; HeightFactor = referenceHeight / originalHeight; float standardHeight = 0; standardHeight = originalHeight * WidthFactor; float cutTop = Convert.ToSingle(yCropPosition) / WidthFactor; float cutBotom = (standardHeight - referenceHeight - cutTop) / WidthFactor; Size sizeCrop = new Size(Convert.ToInt32(referenceWidth / WidthFactor), Convert.ToInt32(referenceHeight / WidthFactor)); Point pointCrop = new Point(0, Convert.ToInt32(cutTop)); Rectangle rectangleCrop = new Rectangle(pointCrop, sizeCrop); imageFactory.Crop(rectangleCrop); System.Drawing.Size sizeBig = new System.Drawing.Size(Convert.ToInt32(referenceWidth), Convert.ToInt32(referenceHeight)); var img = imageFactory.Resize(sizeBig); outStream = new MemoryStream(); imageFactory.Save(outStream); tmpSize = outStream.Length; Helper.HelperMethods.SaveImage(ref outStream, Path.Combine(portal.HomeDirectoryMapPath + "OrgImages\\HeaderImages", "cropBig" + fileRootName + extension)); fileResultModelList.Add(new FileResultModel() { Extension = extension, Filename = "cropBig" + fileRootName, Link = portal.HomeDirectory + "OrgImages/HeaderImages/" + "cropBig" + fileRootName + extension, Description = "Crop Big", Size = tmpSize }); System.Drawing.Size sizeSmall = new System.Drawing.Size(Convert.ToInt32(600), Convert.ToInt32(300)); imageFactory.Resize(sizeSmall); outStream = new MemoryStream(); imageFactory.Save(outStream); tmpSize = outStream.Length; Helper.HelperMethods.SaveImage(ref outStream, Path.Combine(portal.HomeDirectoryMapPath + "OrgImages\\HeaderImages", "cropThumb" + fileRootName + extension)); fileResultModelList.Add(new FileResultModel() { Extension = extension, Filename = "cropThumb" + fileRootName, Link = portal.HomeDirectory + "OrgImages/HeaderImages/" + "cropThumb" + fileRootName + extension, Description = "Crop Thumbnail", Size = tmpSize }); Helper.HelperMethods.DeleteFiles(portal.HomeDirectoryMapPath + "OrgImages\\TempUserImages", filename + "*"); return(fileResultModelList); } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } catch (HttpResponseException e) { throw e; } catch (Exception ee) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ee); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
public void onDrawerOptionClicked(View view) { switch (view.Id) { case Resource.Id.drawer_option_load: if (CropImage.IsExplicitCameraPermissionRequired(this)) { RequestPermissions(new[] { Manifest.Permission.Camera }, CropImage.CameraCapturePermissionsRequestCode); } else { CropImage.StartPickImageActivity(this); } _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_oval: SetMainFragmentByPreset(CropDemoPreset.Circular); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_rect: SetMainFragmentByPreset(CropDemoPreset.Rect); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_customized_overlay: SetMainFragmentByPreset(CropDemoPreset.CustomizedOverlay); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_min_max_override: SetMainFragmentByPreset(CropDemoPreset.MinMaxOverride); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_scale_center: SetMainFragmentByPreset(CropDemoPreset.ScaleCenterInside); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_toggle_scale: _cropImageViewOptions.ScaleType = _cropImageViewOptions.ScaleType == CropImageView.ScaleType.FitCenter ? CropImageView.ScaleType.CenterInside : _cropImageViewOptions.ScaleType == CropImageView.ScaleType.CenterInside ? CropImageView.ScaleType.Center : _cropImageViewOptions.ScaleType == CropImageView.ScaleType.Center ? CropImageView.ScaleType.CenterCrop : CropImageView.ScaleType.FitCenter; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_shape: _cropImageViewOptions.CropShape = _cropImageViewOptions.CropShape == CropImageView.CropShape.Rectangle ? CropImageView.CropShape.Oval : CropImageView.CropShape.Rectangle; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_guidelines: _cropImageViewOptions.Guidelines = _cropImageViewOptions.Guidelines == CropImageView.Guidelines.Off ? CropImageView.Guidelines.On : _cropImageViewOptions.Guidelines == CropImageView.Guidelines.On ? CropImageView.Guidelines.OnTouch : CropImageView.Guidelines.Off; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_aspect_ratio: if (!_cropImageViewOptions.FixAspectRatio) { _cropImageViewOptions.FixAspectRatio = true; _cropImageViewOptions.AspectRatio = (1, 1); } else { if (_cropImageViewOptions.AspectRatio.AspectRatioX == 1 && _cropImageViewOptions.AspectRatio.AspectRatioY == 1) { _cropImageViewOptions.AspectRatio = (4, 3); } else if (_cropImageViewOptions.AspectRatio.AspectRatioX == 4 && _cropImageViewOptions.AspectRatio.AspectRatioY == 3) { _cropImageViewOptions.AspectRatio = (16, 9); } else if (_cropImageViewOptions.AspectRatio.AspectRatioX == 16 && _cropImageViewOptions.AspectRatio.AspectRatioY == 9) { _cropImageViewOptions.AspectRatio = (9, 16); } else { _cropImageViewOptions.FixAspectRatio = false; } } _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_auto_zoom: _cropImageViewOptions.AutoZoomEnabled = !_cropImageViewOptions.AutoZoomEnabled; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_max_zoom: _cropImageViewOptions.MaxZoomLevel = _cropImageViewOptions.MaxZoomLevel == 4 ? 8 : _cropImageViewOptions.MaxZoomLevel == 8 ? 2 : 4; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_set_initial_crop_rect: _currentFragment.SetInitialCropRect(); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_reset_crop_rect: _currentFragment.ResetCropRect(); _drawerLayout.CloseDrawers(); break; case Resource.Id.drawer_option_toggle_multitouch: _cropImageViewOptions.Multitouch = !_cropImageViewOptions.Multitouch; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_show_overlay: _cropImageViewOptions.ShowCropOverlay = !_cropImageViewOptions.ShowCropOverlay; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; case Resource.Id.drawer_option_toggle_show_progress_bar: _cropImageViewOptions.ShowProgressBar = !_cropImageViewOptions.ShowProgressBar; _currentFragment.SetCropImageViewOptions(_cropImageViewOptions); UpdateDrawerTogglesByOptions(_cropImageViewOptions); break; default: Toast.MakeText(this, "Unknown drawer option clicked", ToastLength.Long).Show(); break; } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); //If its from Camera or Gallery if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { string pathImg; if (ImageType == "Cover") { pathImg = resultUri.Path; UpdateImageGroup_Api(ImageType, pathImg); } else if (ImageType == "Avatar") { pathImg = resultUri.Path; UpdateImageGroup_Api(ImageType, pathImg); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } } } else if (requestCode == 2500 && resultCode == Result.Ok)//add post { if (!string.IsNullOrEmpty(data.GetStringExtra("itemObject"))) { var postData = JsonConvert.DeserializeObject <PostDataObject>(data.GetStringExtra("itemObject")); if (postData != null) { var countList = PostFeedAdapter.ItemCount; var combine = new FeedCombiner(postData, PostFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections("Top"); int countIndex = 1; var model1 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model2 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model3 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model4 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model4 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model4) + 1; } else if (model3 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model3) + 1; } else if (model2 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model2) + 1; } else if (model1 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model1) + 1; } else { countIndex = 0; } PostFeedAdapter.NotifyItemRangeInserted(countIndex, PostFeedAdapter.ListDiffer.Count - countList); } } else { PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => MainRecyclerView.FetchNewsFeedApiPosts() }); } } else if (requestCode == 3950 && resultCode == Result.Ok) //Edit post { var postId = data.GetStringExtra("PostId") ?? ""; var postText = data.GetStringExtra("PostText") ?? ""; var diff = PostFeedAdapter.ListDiffer; List <AdapterModelsClass> dataGlobal = diff.Where(a => a.PostData?.Id == postId).ToList(); if (dataGlobal.Count > 0) { foreach (var postData in dataGlobal) { postData.PostData.Orginaltext = postText; var index = diff.IndexOf(postData); if (index > -1) { PostFeedAdapter.NotifyItemChanged(index); } } var checkTextSection = dataGlobal.FirstOrDefault(w => w.TypeView == PostModelType.TextSectionPostPart); if (checkTextSection == null) { var collection = dataGlobal.FirstOrDefault()?.PostData; var item = new AdapterModelsClass { TypeView = PostModelType.TextSectionPostPart, Id = int.Parse((int)PostModelType.TextSectionPostPart + collection?.Id), PostData = collection, IsDefaultFeedPost = true }; var headerPostIndex = diff.IndexOf(dataGlobal.FirstOrDefault(w => w.TypeView == PostModelType.HeaderPost)); if (headerPostIndex > -1) { diff.Insert(headerPostIndex + 1, item); PostFeedAdapter.NotifyItemInserted(headerPostIndex + 1); } } } } else if (requestCode == 3500 && resultCode == Result.Ok) //Edit post product { if (string.IsNullOrEmpty(data.GetStringExtra("itemData"))) { return; } var item = JsonConvert.DeserializeObject <ProductDataObject>(data.GetStringExtra("itemData")); if (item != null) { var diff = PostFeedAdapter.ListDiffer; var dataGlobal = diff.Where(a => a.PostData?.Id == item.PostId).ToList(); if (dataGlobal.Count > 0) { foreach (var postData in dataGlobal) { var index = diff.IndexOf(postData); if (index > -1) { var productUnion = postData.PostData.Product?.ProductClass; if (productUnion != null) { productUnion.Id = item.Id; } productUnion = item; Console.WriteLine(productUnion); PostFeedAdapter.NotifyItemChanged(PostFeedAdapter.ListDiffer.IndexOf(postData)); } } } } } else if (requestCode == 2005 && resultCode == Result.Ok) { string result = data.GetStringExtra("groupItem"); var item = JsonConvert.DeserializeObject <GroupClass>(result); if (item != null) { LoadPassedData(item); } } else if (requestCode == 2019 && resultCode == Result.Ok) { var manged = GroupsActivity.GetInstance().MAdapter.SocialList.FirstOrDefault(a => a.TypeView == SocialModelType.MangedGroups); var dataListGroup = manged?.MangedGroupsModel.GroupsList?.FirstOrDefault(a => a.GroupId == GroupId); if (dataListGroup != null) { manged.MangedGroupsModel.GroupsList.Remove(dataListGroup); GroupsActivity.GetInstance().MAdapter.NotifyDataSetChanged(); ListUtils.MyGroupList.Remove(dataListGroup); } Finish(); } } catch (Exception e) { Console.WriteLine(e); } }
//Result public override async void OnActivityResult(int requestCode, int resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 108 || requestCode == CropImage.CropImageActivityRequestCode) { if (Methods.CheckConnectivity()) { var result = CropImage.GetActivityResult(data); if (result.IsSuccessful) { var resultPathImage = result.Uri.Path; if (!string.IsNullOrEmpty(resultPathImage)) { Java.IO.File file2 = new Java.IO.File(resultPathImage); var photoUri = FileProvider.GetUriForFile(Activity, Activity.PackageName + ".fileprovider", file2); GlideImageLoader.LoadImage(Activity, photoUri.Path, UserProfileImage, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); var dataUser = ListUtils.MyProfileList.FirstOrDefault(); if (dataUser != null) { dataUser.Avatar = resultPathImage; UserDetails.Avatar = resultPathImage; SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.InsertOrUpdateToMyProfileTable(dataUser); dbDatabase.Dispose(); } var dataStory = GlobalContext.NewsFeedFragment.StoryAdapter?.StoryList?.FirstOrDefault(a => a.Type == "Your"); if (dataStory != null) { dataStory.Avatar = resultPathImage; GlobalContext.NewsFeedFragment.StoryAdapter.NotifyItemChanged(0); } await Task.Run(async() => { (int apiStatus, var respond) = await RequestsAsync.User.SaveImageUser(resultPathImage).ConfigureAwait(false); }); } else { Toast.MakeText(Activity, Activity.GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } else { Toast.MakeText(Activity, Activity.GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } else { Toast.MakeText(Activity, Activity.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Long).Show(); } } else if (requestCode == 3000) { LoadProfile(); } } catch (Exception e) { Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); switch (requestCode) { //If its from Camera or Gallery case CropImage.CropImageActivityRequestCode: { var result = CropImage.GetActivityResult(data); switch (resultCode) { case Result.Ok when result.IsSuccessful: { var resultUri = result.Uri; switch (string.IsNullOrEmpty(resultUri.Path)) { case false: { EventPathImage = resultUri.Path; File file2 = new File(resultUri.Path); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Glide.With(this).Load(photoUri).Apply(new RequestOptions()).Into(ImageEvent); break; } default: Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show(); break; } break; } case Result.Ok: Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show(); break; } break; } // Location case 502 when resultCode == Result.Ok: { var placeAddress = data.GetStringExtra("Address") ?? ""; TxtLocation.Text = string.IsNullOrEmpty(placeAddress) switch { //var placeLatLng = data.GetStringExtra("latLng") ?? ""; false => placeAddress, _ => TxtLocation.Text }; break; } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }