Load HTML file through file naming in Android Studio - html

I need to load a random image, according to the outcome and based on that I need to load a certain HTML file. Can I link them through naming?
When I load a drawable house.jpg it has to link dynamically with house.html.
(The image and HTML file have to be separate. So no need to say you can put everything in one HTML file.)

You can only do such a thing if our image is inside your /assets folder. Also, you must load your html with a baseUrl that's inside your assets folder
You can use WebView.loadUrl() or WebView.loadDataWithBaseURL():
webView.loadUrl("file:///android_asset/file.html");
or
webView.loadDataWithBaseURL("file:///android_asset/", "<img src='file.jpg' />", "text/html", "utf-8", null);
(file.jpg should be inside your assets folder)
To compare which button :
Use getDrawable() method in ImageButton and compare them using .getConstantState().equals()
Sample code:
ImageButton btn = (ImageButton) findViewById(R.id.myImageBtn);
Drawable drawable = btn.getDrawable();
if (drawable.getConstantState().equals(getResources().getDrawable(R.drawable.myDrawable).getConstantState())){
//Do your work here
}
References:
Get drawable of image button

Related

Embed image in HTML r markdown document that can be shared

I have an R markdown document which is created using a shiny app, saved as a HTML. I have inserted a logo in the top right hand corner of the output, which has been done using the following code:
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"FILEPATH/logo.png\" style=\"float: right;padding-right:10px;height:125px;width:250px\"/>')
});
</script>
However, when I save the HTML output and share the output, of course the user cannot see the logo since the code is trying to find a file path which will not exist on their computer.
So, my question is - is there a way to include the logo in the output without the use of file paths? Ideally I don't want to upload the image to the web, and change the source to a web address.
You can encode an image file to a data URI with knitr::image_uri. If you want to add it in your document, you can add the html code produced by the following command in your header instead of your script:
htmltools::img(src = knitr::image_uri("FILEPATH/logo.png"),
alt = 'logo',
style = 'float: right;padding-right:10px;height:125px;width:250px')

Basic Image Uploader for CKEditor in WebPages in ASP.NET

I am using CKEditor in a web application in ASP.NET WebPages (Razor).
I spent a number of days trying to figure out how to make and integrate a basic file manager to support uploading images to CKEditor. The documentation in this area is next to useless. Nothing addressed the WebPages environment. Lots of PHP and WebForms and MVC, but nothing specifically for WebPages.
I finally figured out how to do it and am sharing it here.
CK Editor has an attribute that can be added to the .Replace which tells CKEditor to add an "Upload" tab (that had a built-in file browser) to the Image Properties panel:
CKEDITOR.replace('editor1'
, {
filebrowserImageUploadUrl: 'imageUpload2'
}
);
where "imageUpload2" was the name of the cshtml file (imageUpload2.cshtml) that contained the upload logic. Adding that filebrowserImageUploadUrl caused the CKEditor image properties panel to be modified to display (in the newly added "Upload" menu tab) a "Browse" button and a "Send to Server" button.
The "Browse" button activates CKEditor's Built-in file browser patterned after the html input filetype "file"; the "Send To Server" button executes the file manager you coded (see below).
The procedure would be for the user to:
click on the Insert Image icon in the CKEditor menu
Click on the "Upload" tab in the image properties dialog
Click on the "Browse" button to browse folders on the client machine and select ("Open") the desired image file
Click on the "Send to Server" button to execute the file manager's code (imageUpload2.cshtml), saving the image file to the folder specified in the cshtml file and passing the url of the file back to CKEditor.
The code in the file manager is minimal - no bells or whistles:
#{
Layout = null;
var context=HttpContext.Current;
HttpPostedFile uploads = context.Request.Files["upload"];
//get full filename
string file = System.IO.Path.GetFileName(uploads.FileName);
//get extension (including the period)
string ext = System.IO.Path.GetExtension(uploads.FileName);
//CKEditorFuncNum is passed in from the image propoerties panel in CKEditor
string CKEditorFuncNum = context.Request["CKEditorFuncNum"];
//use whatever folder name you prefer - make sure it has read/write permissions on the server
string url = Href("~/imageUploads/" + file);
var message = " .jpg .jpeg .gif .png ".Contains(ext.ToLower())?"":ext+" is invalid file type";
//Save file if it is one of the allowable extensions
if(String.IsNullOrEmpty(message))
{
uploads.SaveAs(context.Server.MapPath(".") + url );
}
//create return javascript to CKEditor (must have <script></script> tags)
var responseFormat = "<script>window.parent.CKEDITOR.tools.callFunction({0}, \"{1}\", \"{2}\");</script>";
var responseText = String.Format(responseFormat, CKEditorFuncNum, url, message);
//send script back to CKEditor image properties popup and close this page
context.Response.Write(responseText);
context.Response.End();
}
I hope this saves someone else the time I wasted trying to figure out what worked.

How to display word file in popup windows using mvc 4 razor

I want make display word file in pop window using mvc 4 razor. the file has been taken from specific path and the file already stored in my project.
If you need a popup with smaller size than the full-screen window, you could try with some javascript:
fileDownloadLink variable is your download link, pointing to the Action method in your controller
The second and third arguments are explained in MDN reference for window.open function here MDN: Window.open
window.open(fileDownloadLink, 'insertPopupNameHere', 'width=400,height=400')
Otherwise you can just use an anchor tag with atribute target="_blank" (this will just open new tab in most browsers).
Preview File
The code for your action method:
//Insert your mime type here, if you know it
var fileType = "application/octet-stream";
if (inline)
{
var showInlineHeader = new System.Net.Mime.ContentDisposition
{
// for example foo.bak
FileName = result.FileName,
// always prompt the user for downloading, set to true if you want
// the browser to try to show the file inline
Inline = inline,
};
Response.AppendHeader("Content-Disposition", showInlineHeader.ToString());
return File(result.Content, fileType);
}
I have added to my method the if statement in order to directly download files that I don't want to be previewed.
Original answer for forcing preview if availabale, taken from Returning a file to View/Download in MVC

HTML from external file in MovieClip?

I have a client that is requesting an area be built on the stage of an existing .fla file (that I built as well) that loads html content from an external file. This area will serve as a dynamic ad banner that displays the contents of the external file. Ideally, the external file would contain links to different .html files that can easily be edited as the content needs change.
I have tried HTMLloader, but I am limited to a .swf file only and cannot use AIR.
Any thoughts on the best way to do this?
Thanks in advance!
If you are in fact needing to pull content from an external .html file, the following code showcases how to load external html content. In my example, I stored some content in a file named 'MyBannerAd.html', but you can point it to wherever you want and whatever filename you wish. Once the file has loaded, the externalFileLoadComplete function is called at which time I created a textfield and stored the contents of the file that was loaded from the external file as the htmlText property of the TextField. If you already have a textfield created, you can simply reference that one instead. The code shown below executed successfully using Flash CC 2014.
import flash.text.TextField;
function externalFileLoadComplete(e:Event):void
{
var myTextField:TextField = new TextField();
myTextField.htmlText = e.target.data;
addChild(myTextField);
}
var fileLoader:URLLoader = new URLLoader();
var fileRequest:URLRequest = new URLRequest("MyBannerAd.html");
fileLoader.addEventListener(Event.COMPLETE, externalFileLoadComplete);
fileLoader.load(fileRequest);

Render Html as Image

I have a page with a form and button called preview. I need a method to generate a preview, converting the generated HTML to an image.
Clicking on the preview button starts an ajax call to a controller action (I'm using Yii Framework), so I collected all the data from the form and generated a preview with the filled data.
I need to convert the generated HTML to an image; in this way I'm able to re-size to my needed dimension.
I've tried generating a .pdf on the fly and then generate the image from the pdf, and using mpdf extension and imagick. But imagick requires the pdf to be an existing file, while I prefer to generate a .pdf string with mpdf (I can't generate and delete a pdf for each click on preview button).
What is a good method to generate an image from html or from pdf string generated "on the fly"?
This is the code that I've used, but it return an error from imagick, saying image without dimension:
$html2pdf = Yii::app()->ePdf->mpdf('','A4');
$html2pdf->WriteHTML($this->render('preview', array("data" => $data, "imageProvider" => $arrayImage),true));
$content_PDF = $html2pdf->Output('', EYiiPdf::OUTPUT_TO_STRING);
$im = new Imagick();
$im->readImageBlob( $content_pdf );
//$im->setIteratorIndex(0);
$im->setResolution( 800, 600 );
$im->setImageFormat( "jpeg" );
header( "Content-Type: image/jpeg" );
echo $im->getImage();
You need to rethink the requirement to take HTML and generate an image file of it.
I need to convert the generated HTML to an image; in this way I'm able
to re-size to my needed dimension.
You can easily resize the dimension and all elements within a form using proper CSS. This is the route I would take.
Generating an image seems like overkill.
In order to use Imagick, you need to set the SIZE of the picture, not only the solutions:
Can you try something like this first and see what happens?
$thumb = new imagick("/path/".$filename);
$thumb->setImageFormat( "png" );
$thumb->thumbnailImage( 128, 128);