What is the difference between createImageView and createView (Titanium Studio) - titanium-mobile

I am using Titanium Studio for mobile development.
The following two things used to display image. But may i know the difference between following,
1. Ti.UI.createImageView({ width:100, height:50, Image:'image path' });
2. Ti.UI.createView({ width:100, height:50, backgroundImage:'image path' });
Both displaying specified image.
what is the difference between these two.
craeteView also displaying image then , why we use createImageView.
can any one please..

View is an empty drawing surface or container, which is the base type for all UI widgets in Titanium where as image view is a view used to display a single image or series of animated images. All events of Titanium.UI.ImageView is Inherited from Titanium.UI.View. You can not make an animation using view and also an image view has some additional events like start, stop, pause, load etc.

The main difference is you can show URL image (or Remote image) in ImageView, while you can only show resource image in View
var view = Ti.UI.createView();
var imageView = Ti.UI.createImageView();
//Valid:
view.backgroundImage = 'image.png';
imageView.backgroundImage = 'image.png';
imageView.image = 'http://somesite.com/image.png';
//Invalid:
view.backgroundImage = 'http://somesite.com/image.png';
imageView.backgroundImage = 'http://somesite.com/image.png';
Also, as #Anand said, you can show series of images in ImageView

Related

Attribution text not getting captured when using the image of the map canvas Mapbox-GL-JS

I am using ESRI basemaps with Mapbox-GL-JS. I am trying to capture a screenshot of the map using the following code:
this.map.getCanvas().toBlob(function (blob) {
canvasContext.strokeStyle = '#CCCCCC';
canvasContext.strokeRect(leftPosition, topPosition, width, height);
var img = new Image();
img.setAttribute("crossOrigin", "anonymous");
var srcURL = URL.createObjectURL(blob);
img.onload = function () {
canvasContext.drawImage(img, leftPosition, topPosition, width, height);
URL.revokeObjectURL(srcURL);
};
img.src = srcURL;
});
I am not able to figure out why the attribution on the Map is not getting captured in the screenshot. I understand that here I am just trying to get the canvas of the map. I even tried adding text elements to the map canvas and that doesn't work either. I have markers & routes, which get in the image correctly. I also tried using the Mapbox basemap and try the same, but faced the same issue.
Any help is highly appreciated!
map.getCanvas() will only return the Map's canvas not any of the HTML Elements which sit over the map like the controls, Mapbox logo or attribution text. Sam Murphy has been working on an example showing how to capture the Map including the Logo and Attribution text to an image which you can see at https://github.com/mapbox/mapbox-gl-js/pull/6518/files.
Since we can't easily capture an HTML Element to an image in JavaScript the attribution text is re-created in a canvas drawn into the Image.

Adding a new view on top in NativeScript

Anyone got a tip how to add a View over the current view (modal)? I'm creating an app with a video recorder, and the video screen is presented modally on the screen. I want some text to show up above the video modal, and I think I've tried any approach I can think of atm.
Currently im stuck with something like:
var topMost = frameModule.topmost();
var View = new ViewModule.View(questionHolder);
topMost.currentPage._addView(View, 0);
But with no success. questionHolder is a view I fetch with
currentpage.getViewById
Edit:
From the answer of #davecoffin where I understood you could not mix native views and nativescripts views, I was able to solve this in my case by accessing the native view directly and adding a subview to it. In my case:
var sharedApplication = utils.ios.getter(UIApplication, UIApplication.sharedApplication);
var overlay = UIView.alloc().initWithFrame({
origin : {
x: 0,
y: 44,
},
size: {
height: 100,
width: platform.screen.mainScreen.widthPixels
}
});
overlay.backgroundColor = UIColor.blackColor;
overlay.alpha = .6;
sharedApplication.keyWindow.rootViewController.presentedViewController.cameraOverlayView = overlay;
You can directly create and use modal pages as described in this article.
If I am understanding your approach correctly...
You cant add Nativescript views on top of native views.
Check out this forum question: https://discourse.nativescript.org/t/appending-nativescript-views-to-a-native-ui-view/1412
Basically once you have appended a native view (not a nativescript layout or ui view), then every view you append after that must be a native view. For iOS you use addSubview, not sure about android atm.

Titanium ImageView wont display images?

I created an image directory in my projects in the UI folder to place my images.
So the full path is currently Resources/UI/Images.
When i create an image view it wont display the images.
I tried different options, even a web image but nothing works?
var self = Ti.UI.createView({
backgroundColor:'white'
});
var imgv = Titanium.UI.createImageView({url:"http://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Volkswagen_Logo.png/600px-Volkswagen_Logo.png"});
self.add(imgv);
var imgv = Titanium.UI.createImageView({url:"../images/sb02.jpg"});
self.add(imgv);
var imgv = Titanium.UI.createImageView({url:"Resources/ui/images/sb03.jpg"});
self.add(imgv);
There is an error in your code. There is no url property for ImageView control. You should use image property. Try the following code
var imgv = Titanium.UI.createImageView({
image:"../images/sb02.jpg"
});
self.add(imgv);
To answer my question thanks to Anand for the tips:
Images should be placed in the Resources dir
Afterwards reference them just by /folder/image.jpg in my case /images/sb1.jpg

Creating image with hyperlink using google-apps-script

I have been trying to put an image with a hyperlink on it into a google apps script ui. I first thought of using createAnchor(), but that only allows text. Then I thought of using a button, but as far as I know you cannot open a new tab/window and redirect in a callback function.
I also tried createHTML(), but the element is not handled by it as yet.
I have seen people overlay transparent buttons over images, but still have same issue in callback.
My research has not found an answer to this. Does anyone have any solutions/examples?
Thanks
This worked for me on Chrome20 and IE9
// Container for box and results
var imageContainer = app.createFlexTable();
// Setup the button
var button = app.createButton("ImageButton");
button.setStyleAttribute("background", "url(dontshowimagehere.JPG) no-repeat");
button.setStyleAttribute("position", "absolute");
button.setStyleAttribute("color", "transparent");
button.setStyleAttribute('zIndex','1');
button.setStyleAttribute("border", "0px solid black");
imageContainer.setWidget(0, 0, button);
// image to click
var image = app.createImage("image.jpg").setId(imageId);
imageContainer.setWidget(1,0, image);
The image has a slight (3px) offset. If important, this looks to fix it http://www.w3schools.com/css/css_positioning.asp (use relative for the flex table and top etc for the image and button)
Did you try a transparent Anchor overlaying the image?
function doGet() {
var app = UiApp.createApplication().setTitle("Image Anchor");
var panel = app.createAbsolutePanel().setWidth('50%').setHeight('50%');
var image = app.createImage().setUrl("https://lh6.googleusercontent.com/-v0Q3gPQz03Q/T_y5gcVw7LI/AAAAAAAAAF8/ol9uup7Xm2g/s512/GooglePlus-512-Red.png").setStyleAttribute("width", "28px").setStyleAttribute("height", "28px");
var anchor = app.createAnchor("?", "https://plus.google.com/u/1/116085534841818923812/posts").setHeight("28px").setWidth("28px").setStyleAttribute("opacity", "0.1").setTarget("blank");
panel.add(image,100,50);
panel.add(anchor,100,50);
app.add(panel);
return app.close();
}
app.createAbsolutePanel()
.add(app.createImage('https://www.google.com/images/logos/google_logo_41.png'))
.add(app.createAnchor('','https://www.google.co.uk/intl/en/about/')
.setStyleAttributes({position:'absolute',top:'0px',left:'0px',width:'201px',height:'47px',opacity:'0'}))
This is a tested one. It works fine.
It doesn't work with positioning the image (as 'absolute').
It doesn't work with .setHorizontalAlignment(UiApp.HorizontalAlignment.CENTER)
I don't believe this is possible with the widgets available. I would suggest altering your UI's design to utilize an Anchor widget instead.
Use HTML Box if you are coding directly on your page. Click "Edit" to edit your page and go to "Insert>HTML Box" in your menu. It will accept javascript too! There are a few caveats - when using javascript, HTML Box will not accept links...too bad, but too many exploits there.
If you are coding in apps script, you could try to place the image on a panel and use absolute panel and position your link over your image. Another method could be to use the .setStyleAttribute for CSS styling and utilize the zIndex parameter to place a panel over top of your image....like so:
var panel = app.createSimplePanel();
// add your image to the simple panel or whatever panel you wish to choose in your GUI
var popPanel = app.createSimplePanel()
.setStyleAttribute('top','Y')
.setStyleAttribute('left','X')
.setStyleAttribute('zIndex','1')
.setStyleAttribute('position','fixed');
// add your anchor to the popPanel
app.add(panel).add(popPanel);
Not 100% sure if you can make this panel transparent, but you could try something like:
.setStyleAttribute('background',transparent')
or change the opacity via:
.setStyleAttribute('opacity','.5')
Hopes this gives you a few ideas!
I managed to do it with a single Anchor object and using CSS3.
It works on Chrome, I did not test it in other Browsers.
gui.createAnchor("", false, "$DESTINATION_URL$")
.setStyleAttributes({ "display":"block",
"width":"$IMAGE_WIDTH_IN_PIXEL$",
"height":"$IMAGE_HEIGHT_IN_PIXEL$",
"background":"url($URL_OF_THE_IMAGE$)",
"background-size":"100% 100%",
"background-repeat":"no-repeat" })
Of course you have to replace the $......$ with your data.
Thierry
If you first create all your HTML in a string, you can then replace the content of a page with the HTML you want like this:
var myString = 'the html you want to add, for example you image link and button';
var page = SitesApp.getSite('example.com', 'mysite').getChildByName('targetpage');
var upage = page.setHtmlContent('<div>' + myString + '</div>');

Appcelerator Titanium - How do I place an image at the bottom of the screen

I have a main view, then on that view I have, as children, two labels and an image. I want the labels to flow one after another from the top of the screen and I want the image at the bottom. I get the labels to flow properly by setting layout:'vertical' in the main window. But once that is done, I can't seem to force the image to the bottom. Here is a snippet of my code:
var self = Ti.UI.createView({
backgroundColor:'#fff',
layout:'vertical'
});
var l1 = Titanium.UI.createLabel({
text:quote,
color:'#000',
shadowColor:'#ddd',
shadowOffset:{x:2,y:2},
font:{fontFamily:'Marker Felt',fontSize:24},
top:20,
left:15,
right:15,
height:'auto'
});
self.add(l1);
var l2 = Titanium.UI.createLabel({
text:author,
color:'#000',
shadowColor:'#ddd',
shadowOffset:{x:2,y:2},
font:{fontSize:16},
top:10,
left:15,
right:15,
height:'auto',
textAlign:'right'
});
self.add(l2);
var imgView = Titanium.UI.createImageView({
image:myimage,
setBottom:10,
height:100
});
self.add(imgView);
I have tried setting the image layout and that doesn't work. If I change the 'self' window layout to 'absolute' then I can't seem to get the labels to flow cleanly after one another. The first label is of variable height so I need them to follow each other.
I am using Titanium 1.82.
Thanks. In advance.
You might need to add another view. The 'base' view would have what you are calling 'self' added at top:0 and height: 'auto'
Then add imgView to 'base' with bottom: 10 (not setBottom like you have).
Just set the bottom:0; position: fixed; i think this will help u to set the image bottom of the screen.. If it still not working means try with Html,Css and Javascript for design it will be very easy.

Resources