Save canvas as a file and putting to scrollview as a search result - basic4android

In short I would like to know how to do this:
Saving a canvas with all the output of label/edittext/views as an (image)file on sdcard.
Using a search function, it will catch this canvas and display it on a scrollview or
listview.
I hope someone out there knows the answer or having a nice example of the code.
Thanks for now,
JackD

The following code saves the canvas bitmap to a file:
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "Test.png", False)
Canvas1.Bitmap.WriteToStream(out, 100, "PNG")
Out.Close
You can draw the views to the canvas by using Canvas.DrawDrawable with the views background.
Not sure what you mean with the search function. You can later load this bitmap and display it on a ScrollView (with an ImageView) or ListView (with AddTwoLinesAndBitmap).

Related

Only display a specific part of a WebKitWebView in swift

It`s probably a very easy question but I'm new at coding.
In my app I display the normal Webpage of Wikipedia in a WebKitWebView.
I want to display the whole page but without for example the last 100px. Is there a way to "cut off" the content of a Webview respectively a scrollview. For some reason
print(webView.scrollView.contentSize.height)
is 0.0.
I hope you can help me.
You can try when the webView finishes the load
webView.scrollView.contentSize = CGSize(width: webView.scrollView.contentSize.width, height: webView.scrollView.contentSize.height - 100)

How to fetch image size and image resolution from HTML content loaded from UIWebview in Swift?

I am using 'SwiftSoup' SDK to parse HTML content from UIWebView. I want the image size and resolution for each and every image fetched from HTML content. How to get the image size and resolution as soon as an image is loaded and from HTML content received from SwiftSoup?
Assuming you know when all images from the HTML are loaded, here's a javascript code that can be used to grab a list of sizes for all images:
let script = "JSON.stringify([].slice.call(document.getElementsByTagName('img')).map(function(img) { return {url: img.src, width: img.clientWidth, height: img.clientHeight} }))"
Executing this javascript via stringByEvaluatingJavaScript(from:) should give you a JSON that you can parse to obtain the desired info.
For example the output for this page is
[{"url":"https://i.stack.imgur.com/rQQMq.png?s=48&g=1","width":24,"height":24},{"url":"https://www.gravatar.com/avatar/46be6ae9d14855f5ab1aaf1d510ab8bc?s=32&d=identicon&r=PG&f=1","width":32,"height":32},{"url":"https://clc.stackoverflow.com/impression.gif?an=49ocs77evOWqh-6LVv8gJiaWI_07xL9f6GBcyDt7dl3NWtNsxo9-twOOBzKwMPRsYGBosGdkZGCRZuqawDHjMeecj4L_WRhSDiyObbJ82JRhP5vp7j6Og2e4ru0W9mRhmNs0gbnc8pVcsT0jc2Z-sTTTwxaOliucyy4LsrAwFLRcfRVt-e6KDEjTco4LjVyda4XkgZqaJcJzLa9Oj4RoMrJk4eJgYpBgYGDg4o1ij5VnYhAHsvk4o9gSmZgYRIBsfmYbtrvCTAxiIHH2ALapwv3t9i1z_NRrAA&md=291","width":0,"height":0}]
I'd recommend though to switch to WKWebView since it's recommended also by Apple, and because stringByEvaluatingJavaScript(from:) is blocking (WKWebView provides an async version of this function, and one that also will do the parsing for you, so you can remove the JSON.stringify() call from the script).

Take screenshot of host app using iOS share/action extensions?

I will like to know how to take a screenshot of the iOS host app with the use of a share/action extension.
My use case is as follows:
use the Safari browser to access a webpage (https such as gmail)
tap on the Share button and select the extension
the extension will take a screenshot of the current webpage
An working example for this use case is the Awesome Screenshot iOS app.
I had tried the following methods
reload the baseURI (loadRequest) on a UIWebView/WKWebkit (would not be able to access https contents such as Gmail). So not doing any reload (Awesome Screenshot is not doing a reload btw)
Used the ExtensionPreprocessingJS to obtain the DOM contents through the arguments.completionFunction function. I could not extract the document.body here although i could get the source etc. loadHTMLString with the baseURI will mess up the presentation layer.
Used html2canvas in the ExtensionPreprocessingJS to obtain an image and appended it to the host app's webpage as a child but do not know how to extract it. Also, the image got lost for some webpages such as Gmail.
Mobile Safari does not have the visibleContentsAsDataURL method.
I think a viable approach will be to use the html2canvas in the ExtensionPreprocessingJS but how do I save this image somehow?
Edit: So the below works in the Simulator but does not work on the device. I'm presently looking for a solution as well.
Here's a solution that I think the Awesome Screenshot app uses:
func captureScreen() -> UIImage
{
// Get the "screenshot" view.
let view = UIScreen.mainScreen().snapshotViewAfterScreenUpdates(false)
// Add the screenshot view as a subview of the ShareViewController's view.
self.view.addSubview(view);
// Now screenshot *this* view.
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, false, 0);
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Finally, remove the subview.
view.removeFromSuperview()
return image
}

Page number of pdf inside uiwebview

In my app i am using UIWebView for displaying the pdf from an External url. Its get loaded perfectly. While scrolling page number is displayed inside a box. Is there any way to get the page number in code?
You can use the next code:
- (int)getActualPage
{
float scrollViewHeight = self.webView.frame.size.height;
float pageOffset = self.webView.scrollView.contentOffset.y;
return ((int)pageOffset / (int)scrollViewHeight)+1;
}
This code gives you the page number of the document when you see the full page on the UIScrollView. If you want to get the same page number that the UIWebView gives you, just change the final operation. I think that using the module you can get what you want. I know it's not the perfect solution but it's the best I got.

Resize by default TinyMCE

I'm using TinyMCE for the first time, and I love it, but is a bit closed.
I'd like to get images resized by default, this is, when adding an image, put it by default on 300px width, for example (then the user can make it bigger or smaller dragging).
I don't know where to touch! Is there a command within the lists of images (the js you can attach to make TinyMCE show a list of images)? Or I have to hack css? Or I have to dive into TinyMCE code?
Thank you in advance
Marc
If you are OK with changing code files then proceed as follows
Open tiny_mce/plugins/advimage/js/image.js
Locate insertAndClose : function()
Insert after
var ed = tinyMCEPopup.editor, ......;
if(f.width.value == ""){
f.width.value = 300;
}
Hope it helps!
There are several options. I would go the css way. Check out the tinycme init configuration setting content_css. Using an additioanl own css file enables you to setthe width of images to 300px easily.