To change the windows size depending on another view - titanium

My application has two views.
One view is fixed 50pt height.
the other view must be 100% - 50pt.
How can I do this calculate in tss?
or is it impossible?
If so how can I decide the windowsize?
index.tss
"#tableView": {
width: "100%" -50,
height: "98%",
top:0
}
"#adView": {
backgroundColor:"black",
width: "100%",
height: 50,
bottom: 0
}

Use the Titanium.Platform.DisplayCaps.platformWidth property to get the size of the window, assuming that the #tableview's parent is the app window:
#tableview : {
width : Titanium.Platform.DisplayCaps.platformWidth - 50,
height: "98%",
top:0
}
Option 2 is you can calculate this inside your controller using the postlayout event like this:
function adjustTableWidth(e) {
$.tableView.width = $.tableView.rect.width - 50;
// Remove the listener so it doesn't keep calling infinitely
$.tableview.removeEventListener('postlayout, adjustTableWidth);
}
$.tableview.addEventListener('postlayout, adjustTableWidth);
Just make sure if you use option two, you set the TSS to this:
"#tableView": {
width: "100%",
height: "98%",
top:0
}

Related

How to pass an array of color for rectangle in qml

I want to pass the colorModelData for rectangle shown below.
Requirement is: on click of button i want to open a popup. And inside popup want to display multiple number of circles with different colors. Using button can i create a popup which will give me list of colors? ALso list of color should be exposed from outside.
How can i do it?
Rectangle {
id: control
property var colorModelData: ["Red", "Green", "Blue"]
Button{
id: btn
width: 100
height: 100
onClicked: {
rect.visible = true
}
}
Rectangle{
id: rect
visible: false
width: 400
height: 300
color: "gray"
anchors.top: btn.bottom
GridView{
width: rect.width
height: rect.height
model: colorModelData
delegate: Column{
Rectangle {
width: 20
height: 20
radius: width/2
//color: colorModelData [..... getting error]
}
}
}
}
}
I tested your code and it works for me. So I assume the only part you're missing is the line you have commented out. Use this:
color: colorModelData[index]

Cloudinary - add overlay text to thumbnailTransformation in image upload widget

I am using the upload image widget and I want to add a text overlay but don't know how, can someone answer me?
thumbnailTransformation: [{ width: 300, height: 300, crop: 'fill', border: "2px_solid_red" }],
You'll need to include an overlay key that's an object with overlay parameters, in this case, text specific.
For example -
thumbnailTransformation: [
{
width: 300,
height: 300,
crop: 'fill',
border: "2px_solid_red"
},
{
overlay: {
font_family: "Arial",
font_size: 20,
text: "Test"
},
gravity: "north_east"
}
]
Below is a JSFiddle you can try: https://jsfiddle.net/rhdvgy19/
All the other available text styling options can be found here -
https://cloudinary.com/documentation/image_transformations#styling_parameters

How to specify maxWidth and maxHeight in using SimpleModal

When I call the simplemodal method, I do that like so:
jQuery("#stats").modal({
maxWidth: 400,
maxHeight: 300,
onOpen: function (dialog) {
dialog.overlay.fadeIn('slow', function () {
dialog.data.hide();
dialog.container.fadeIn('slow', function () {
dialog.data.slideDown('slow');
});
});
},
onClose: function (dialog) {
dialog.data.fadeOut('slow', function () {
dialog.container.hide('slow', function () {
dialog.overlay.slideUp('slow', function () {
jQuery.modal.close();
});
});
});
}
});
However, when the modal is rendered, both max values are ignored. The resulting element with inline styles is
<div id="simplemodal-container"
class="simplemodal-container"
style="height: 697px; width: 1861px; left: 231px; top: 85.5px; position: fixed; z-index: 1002;">
Is there an issue with the way I specified the max values? Or, is there an issue with simplemodal?
Thanks! E
I think those min/max settings are used to just set the actual height/width for SimpleModal. The modal's container will be sized according to the content as long as the content's size is within the min/max settings. Otherwise, the modal container size will be set at to the min/max values. That's all it does. For example, if the content is bigger than maxHeight & maxWidth settings, then there will be scroll bars:
See this fiddle here
Your content
<div id="stats" style="width:400px; height:400px;">
Your content will show in modal with scroll bars,
because it is bigger than maxWidth, maxHeight.
</div>
The modal
jQuery("#stats").modal({
maxWidth: 300,
maxHeight: 300,
minWidth: 100,
minHeight: 100,
...
If you don't want the modal to shrink/expand with the content, you can force the modal to stay at a specified width & height. Some people even swap out classes (one for normal modal, one for long modal, etc.):
#simplemodal-container {
height: 360px;
width: 600px;
}
If you dynamically change the content of the div (like from an ajax call) you can also do this:
$("#simplemodal-container").css('height', 'auto'); //Resets container height
$("#simplemodal-container").css('width', 'auto'); //Resets container width
$(window).trigger('resize.simplemodal'); //Refresh the modal dialog

How can I get my title and my bottom to show in Titanium?

var galWin = Ti.UI.createWindow({
title: "Alejandro's Big Adventure",
modal: true,
backgroundColor: "828F99",
layout: "horizontal"
});
var border = Ti.UI.createView({
backgroundColor: "2585CC",
height: 1,
width: pWidth,
top: 30
});
var bottomButton = Ti.UI.createView({
backgroundColor: "828F99",
height: "10%",
width: pWidth,
bottom: 0
});
var galContainer = Ti.UI.createScrollView({
top: 0,
width: pWidth,
height: pHeight - border.height - border.top,
backgroundColor: "2585CC",
layout: "horizontal",
contentWidth: pWidth,
showVerticalScrollIndicator: true
});
for(var i = 0; i < myImages.length; i++){
var view = Ti.UI.createView({
borderRadius: 10,
top: margin,
left: margin,
width: size,
height: size
});
var img = Ti.UI.createImageView({
image: "images/" + myImages[i],
top: 0,
width: view.width * 1.25,
height: view.height * 2
});
view.add(img);
galContainer.add(view);
};
Firstly: for the title if you want to get the title of the window
so you can get it with getTitle() method like this
galWin.getTitle()
secondly: for the bottom
if you want to get the bottom of the window here you can't do that because the window is the top element in you hierarchy and is the doc
Window's bottom position, in platform-specific units.
On Android, this property only works with lightweight windows. See "Android Heavyweight and Lightweight Windows" in the main description of Titanium.UI.Window for more information.
so you get the bottom of the element according to it's parent so here the window have no parent
but in general if you want to get the bottom of any element
you can use getBottom() but be aware that this method will return a number only if you provide a bottom property inside the element other than that you will get Nan
and if you want to get the bottom of an element after the layout drawn on the screen you can you postlayout event and using rect.y to get the top of the element and then you can add the element height and finally minus it from the window height and for that if you don't have the window height you can use displayCaps.contentHeight to get the screen height
sorry for Long hope it help

How to enable button focus on touchStart?

I have created a button, I need some response from button like, on touch of the button, the button focus should enable like change in background color. How can I do that?
My code is,
View:
<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>
Style:
".button":{
width: '50%',
top: '25dp',
borderRadius: 8,
borderWidth: 1,
borderColor: '#808080',
backgroundGradient: {
type: "linear",
startPoint: { x: "0%", y:"0%"},
endPoint: { x: "0%", y:"100%"},
colors: [
{ color: "#4F94CD", offset: 0.0 },
{ color: "#4F94CD", offset: 1.0 }
]
}
}
Controller:
$.proceedButton.addEventListener('touchstart', function() {
$.proceedButton.isFocused = true;
});
$.proceedButton.addEventListener('touchend', function() {
$.proceedButton.isFocused = false;
});
The above code is not working. Just I need to slight chage in background color while touch of the button.
Any solution!!
Use this property and pass colour code
backgroundSelectedColor : "RED"
focusable must be true for normal views.
for more you can refer this http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Button-property-backgroundSelectedColor
I hope it may help you,
Alloy xml would be like this
<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>
Then the button property would be like this
".button":{
width: '50%',
top: '25dp',
borderRadius: 8,
borderWidth: 1,
borderColor: '#808080',
backgroundSelectedColor : "red",
backgroundSelectedImage : "/my_image.png",
backgroundGradient: {
type: "linear",
startPoint: { x: "0%", y:"0%"},
endPoint: { x: "0%", y:"100%"},
colors: [
{ color: "#4F94CD", offset: 0.0 },
{ color: "#4F94CD", offset: 1.0 }
]
}
}
You can set your selected image or background color on touch focus.
You wont need the controller code you have written in the controller.
Also for some object you can also have selectedColor.
You can also set backgroundFocusedImage,
As #CodeForFun mentioned you can use backgroundSelectedColor property of button.
Also following are all the states which can be used by a button in Titanium.
Disabled : backgroundDisabledImage and backgroundDisabledColor
Normal : backgroundImage and backgroundColor
Focus : backgroundFocusedImage and backgroundFocusedColor
Selected : backgroundSelectedImage and backgroundSelectedColor
Hope this would be helpful.
Edit : An example of usage:
View :
<Button class="button" >Proceed</Button>
TSS :
".button":{
width: '50%',
top: '25dp',
backgroundSelectedColor : "#4F94CD" //usage
}