Where to call an Action when user removes an uploaded image in GWTUpload? - gwt

I am using GWTUpload , the library is in here https://code.google.com/p/gwtupload/
The Example code at client side found on that website has this structure:
// Attach an image to the pictures viewer
private OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() {
public void onLoad(PreloadedImage image) {
//showImageFlowPanel code solution 1
image.setWidth("75px");
showImageFlowPanel.add(image);
}
};
private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
public void onFinish(IUploader uploader) {
if (uploader.getStatus() == Status.SUCCESS) {
new PreloadedImage(uploader.fileUrl(), showImage);
UploadedInfo info = uploader.getServerInfo();
String headShotImageUrl="http://"+Window.Location.getHost()+"/" +"images/uploaded/"+info.message;
//headShotImage code solution 2
if(!"".equals(headShotImageUrl) && UriUtils.isSafeUri(headShotImageUrl)){
headShotImage.setUrl(UriUtils.fromString(headShotImageUrl));
}
}
}
};
The example uses showImageFlowPanel (solution 1) to store the image but I want to store the image inside headShotImage which take the url after user uploaded image successfully, see the headShotImage (solution 2) code above.
Ok, the headShotImage code work fine but I dont know how to remove it when users remove the image. If I use showImageFlowPanel as in the solution 1 then the program remove the image automatically for me and I do not need to do anything.
So my question is "Where to call an Action when user removes an uploaded image in GWTUpload?"

You have to use setOnCancelUploaderHandler. Take a look to this code took from the demo.
// When the user clicks a cancel button we get an event
uploader.addOnCancelUploadHandler (
new IUploader.OnCancelUploaderHandler() {
public void onCancel(IUploader uploader) {
for (String iname : uploader.getServerMessage().getUploadedFieldNames()) {
// loadedImages is an temporary table where we are adding all uploaded files
// indexed by field name
Widget w = loadedImages.get(iname);
if (w != null) {
w.removeFromParent();
loadedImages.remove(uploader.getInputName());
}
}
}
});

Related

Binding Image URIs via Image.SetBinding() not working properly

I'm using the following code snippet to bind a image url to a image object (used as one element in a ViewCell object).
...
Image Picture = new Image()
{
Aspect = Aspect.AspectFit,
HorizontalOptions = LayoutOptions.StartAndExpand
}; // ImageSource.FromUri(new Uri("sImageUrl")))
Picture.SetBinding(Image.SourceProperty, "sImageUrl");
...
The images in the list, for which I'm using that cell view, are not loading always. I was not able to identify the exact reason for the problem, but I think the problem is the load-process (for loading the images from the url/internet)..
Maybe the problem could be solved by setting the url via new Uri(...) as described in the documentation
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"));
Now my question: is there a workaround for binding a uri object? e.g.
...
Image Picture = new Image()
{
Aspect = Aspect.AspectFit,
HorizontalOptions = LayoutOptions.StartAndExpand
}; // ImageSource.FromUri(new Uri("sImageUrl")))
Picture.SetBinding(Image.SourceProperty, ImageSource.FromUri(new Uri("sImageUrl")));
...
I'm working with xamarin studio (version 6.1.2, build 44, update channel "beta", os x).
Would be great if someone got a tipp.
Thanks a lot,
Alex
after some more trying I found a solution.. I'm not sure if it's a secure / professional way.. But for now, it seems to work.
What I did: I implemented my own class "AsyncSrcImage", derived it from Image and added another bindable property:
public class AsyncSrcImage : Image
{
private static String sDefaultURL = "";
public static readonly BindableProperty AsyncImgUrlProperty = BindableProperty.Create(nameof(AsyncImgUrl), typeof(String), typeof(AsyncSrcImage), sDefaultURL);
public String AsyncImgUrl
{
get { return (String)GetValue(AsyncImgUrlProperty); }
set { SetValue(AsyncImgUrlProperty, value); }
}
}
Additionally I adjusted the rendering process with a custom renderer. There I'm loading the image source via new Uri(...) as described in the documentation:
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using System;
[assembly: ExportRenderer(typeof(AsyncSrcImage), typeof(AsyncSrcImageRenderer))]
public class AsyncSrcImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
AsyncSrcImage oImage = (AsyncSrcImage)Element;
if (oImage != null && oImage.AsyncImgUrl != "")
{
oImage.Source = ImageSource.FromUri(new Uri(oImage.AsyncImgUrl));
}
}
}
Maybe that helps other folks ;)

Xamarin Android: Facebook share content is empty

I have a Xamarin Forms App. Which I created a FBShareButton : Button to handle the sharing via custom renderers. This is the code in my renderer:
public class FacebookShareRenderer : ButtonRenderer
{
ShareButton sb;
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged (e);
sb = new ShareButton(Context);
this.Control.Click += (sender, eargs) => sb.PerformClick();
sb.Click += (sender, eargs) => {
ShareLinkContent.Builder shareLinkContentBuilder = new ShareLinkContent.Builder().
SetContentDescription("Hello").
SetContentTitle("Desc");
shareLinkContentBuilder.SetImageUrl("url");
ShareLinkContent shareLinkContent = shareLinkContentBuilder.Build();
sb.ShareContent = shareLinkContent;
}
};
}
}
The share dialog opens and asks me to right something as I supposed to. However, the content does not appear and when I share they do not show. Any ideas?
I fugired this out; first the SetImageUrl should be a valid url with an Image and second I needed to SetContentUrl also, otherwise it would empty the content.

how prevent duplicate code in wicket

Sorry my english is bad
I have two class profile and EditProfile
in both class i have
protected void addContent(PageParameters pageParameters) {
final String email = pageParameters.get(ListUser.USER_EMAIL).toString();
final User loggedUser = getLoggedUser();
if (email == null) {
redirectToInterceptPage(new ErrorPage404(null));
return;
}
User userByEmail = userService.findByEmail(email);
if (userByEmail == null) {
redirectToInterceptPage(new ForbiddenPage403(null));
return;
}
final UserDetachableModel user = new UserDetachableModel(userByEmail);
// If the user is not active, there is no need to edit your profile.
if (!user.getObject().isActive()) {
redirectToInterceptPage(new ErrorPage404(null));
return;
}
// Only admins can see the profile of other users.
if (!loggedUser.getUserRole().equals(UserRole.ADMIN) && !loggedUser.getEmail().equalsIgnoreCase(email)) {
redirectToInterceptPage(new ForbiddenPage403(null));
return;
}
......PROCESS TO SEE PROFILE OR EDIT PROFILE........
}
I use a CustomMountedPage that i use to hide the serial number of wicket.
Example http://HOST/Page/subPage?ID&PARAMS to see http://HOST/Page/subPage?PARAMS and access to another profile
How prevent duplicate code!!
You can use Panels. They have their own markup file like a normal page but you can use them in any other Wicket-Page as a component.
Have a look at this page to see how to use panels correctly.

How to get the webview's content which was clicked on the webview

I want to add the bookmark function to my app, when I clicked on the webview which display the HTML files (The file's main part is string), I want to capture the first line of the content which display on the screen. Anyone knows the answer?
Thanks very much in advance.
-Shawn
you can identify the some content of the page as It contains img tag or not
Use this API of webView click here
WebView.HitTestResult hr = ((WebView)v).getHitTestResult();
int i=hr.getType() ;
and use the int values of this class for the content
Hope it help
If there is a link into the WebView and you want to do a specific action when the user click on this link you must catch the link click using the following code:
Somewhere in your activity code (commonly in the onCreate method):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.news_details);
...
mWebView.setWebViewClient(new MyWebViewClient());
...
}
And the WebViewClient class:
class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (DEBUG) {
Log.d(TAG, "shouldOverrideUrlLoading url= " + url);
}
if ( the url is like you want) {
// TODO: add the code to do what you need to do with the url
// the webview should not do anything with this link.
return true;
} else {
// let the webview normally handle the link
return false;
}
}
}
If what you want to do is get the actual displayed content of the WebView, there is no API to do that.
Have a look on those post:
Is it possible to get the HTML code from WebView
Retrieve webview content
Both redirect on this website:
http://lexandera.com/2009/01/extracting-html-from-a-webview/

ASP.NET Connection Reset on Upload

I'm running into a problem with my app (ASP.NET MVC 2) where I can't upload files (images in my case). I've changed the web.config to accept up to 20MB, and I'm trying to upload a file that's only 3MB.
The app itself has two ways to upload. The initial upload which starts a Gallery and then an additional upload to append to a Gallery.
The initial works like a charm, but the appending one fails with no explanation. Even if I re-upload the initial image as an append it still fails.
I'm a little stuck on this so I would appreciate any help you guys can offer.
Thanks in advance!
EDIT
If I "hack" the form with Firebug and direct it to the initial upload Url it works, but when it's directing to the Url it should be posting to it fails...
EDIT 2
Per Rob's request, here's the code handling the initial gallery and appending image:
[HttpPost, ValidateAntiForgeryToken]
public RedirectToRouteResult PutGallery( // Move to Ajax
[Bind(Prefix = "Gallery", Include = "ClubId,EventId,RHAccountId,RHCategoryId,Year")] Gallery Gallery,
HttpPostedFileBase File) {
if (ModelState.IsValid && (File.ContentLength > 0)) {
if (Gallery.RHAccountId > 0) {
Gallery.RHUser = this.fdc.RHAccounts.Single(
a =>
(a.RHAccountId == Gallery.RHAccountId)).RHUser;
} else {
if (!this.fdc.RHUsers.Any(
u =>
(u.User.Name == Gallery.Username))) {
if (!this.fdc.Users.Any(
u =>
(u.Name == Gallery.Username))) {
Gallery.RHUser = new RHUser() {
User = new User() {
Name = Gallery.Username
}
};
} else {
Gallery.RHUser = new RHUser() {
User = this.fdc.Users.Single(
u =>
(u.Name == Gallery.Username))
};
};
} else {
Gallery.RHUser = this.fdc.RHUsers.Single(
u =>
(u.User.Name == Gallery.Username));
};
};
Image Image = new Image() {
Gallery = Gallery
};
this.fdc.Galleries.InsertOnSubmit(Gallery);
this.fdc.Images.InsertOnSubmit(Image);
this.fdc.SubmitChanges();
Files.Save(Image.ImageId, File);
return RedirectToAction("Default", "Site");
} else {
return RedirectToAction("Default", "Site");
};
}
[HttpPost, ValidateAntiForgeryToken]
public RedirectToRouteResult PutImage(
[Bind(Prefix = "Image", Include = "GalleryId")] Image Image,
HttpPostedFileBase File) {
Gallery Gallery = this.fdc.Galleries.Single(
g =>
(g.GalleryId == Image.GalleryId));
if (File.ContentLength > 0) {
this.fdc.Images.InsertOnSubmit(Image);
this.fdc.SubmitChanges();
Files.Save(Image.ImageId, File);
};
return RedirectToAction("Gallery", "Site", new {
Category = Gallery.RHCategory.Category.EncodedName,
GalleryId = Gallery.GalleryId
});
}
SIDENOTE:
Could Cassini, VS 2010's built in web server, be the cause?
Ok, so I figured it out, it only took a lengthy install of IIS locally on my machine + the configuration, to have it tell me that I miss-spelled controller as controlls in the routes.
Really annoying that it took all of that to get the real error, so Cassini was partially at fault...
So, the moral of the story is, make sure you spell everything correctly.