Is it possible to create a button which when pressed it replaces an existing object on the screen to another object in Smartface App Studio? - smartface.io

Is it possible to create a button which when pressed it replaces an existing object on the screen to another object in Smartface App Studio?
I've tried using the Onshow event on the text however it wasn't successful.
Thankyou

It is possible to replace an existing object to another object. You should create objects and add to page both of them but visible property of an object should be false on start and then you can change visible of object when button is pressed.I create a simple example for you:
var btn = new SMF.UI.TextButton({
top : "80%",
left : "10%",
onPressed : page1_btn_onPressed
});
Pages.Page1.add(btn);
var myImage = new SMF.UI.Image({
top: "20%",
left: "15%",
height: "20%",
width: "70%",
image: "default.png",
imageFillType: SMF.UI.ImageFillType.stretch,
visible : true
});
Pages.Page1.add(myImage);
var myImage2 = new SMF.UI.Image({
top: "20%",
left: "15%",
height: "20%",
width: "70%",
image: "icon.png",
imageFillType: SMF.UI.ImageFillType.stretch,
visible : false
});
Pages.Page1.add(myImage2);
function page1_btn_onPressed(e) {
myImage.visible= false;
myImage2.visible = true;
}

Related

SAPUI5 - Table rerenders after data call

I am using sap.m.Table to display some documents as a sap.m.Dialog.The UI looks as below:
Everything works as expected but when I scroll to the last Item (growing=true) the table rerenders and moves back to the top. Ideally that would happen only when I refresh a model. I am using bindAggregation to bind the odataModel to the UI. Please see a snippet below (Note:Partial snippet).
var dialog = new Dialog({
title: title,
buttons: [
new sap.m.Button({
text: "{i18n>close}",
press: function(oEvt) {
dialog.close();
}
})
]
});
var table = new sap.m.Table({
width: "100%",
inset: true,
growing: true,
growingThreshold: 100,
growingScrollToLoad: true
})
dialog.addContent(table);
if (!dialog.isOpen()) {
dialog.open();
}
var oDModel = new ODataModel(kmURL, {
json: true
});
oDModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
table.setModel(oDModel);
var mParams = {
path: "/DocumentQuerySet",
template: template,
};
table.bindAggregation("items", mParams);
I think that bindAggregation internally refreshes the model which forces the table to rerender after every data call. How can I avoid the model to refresh/rerender the table so that it does not scroll to the top every time the user scrolls down to see more data.
Appreciate any help.
Thanks.
You could fix this problem by placing the Table control within a ScrollContainer. The ScrollContainer will handle the growing feature of the table, which causes the change in height of the control. This will retain the current position without moving back to the top.
....
var table = new sap.m.Table({
width: "100%",
inset: true,
growing: true,
growingThreshold: 100,
growingScrollToLoad: true
})
var oScroll = new sap.m.ScrollContainer({
width: "100%",
height: "500px",
vertical: true,
content: table
})
dialog.addContent(oScroll);
....

Overriding the always-top property of the navigation bar in Titanium

In Titanium for iPhone is it possible to display something above the navigation bar – or just disabling the always-top property of the navigation bar?
This is how it looks right now:
This is part of the actual Photoshop-mock-up:
The code-snippet invoking this is:
var win1 = Titanium.UI.createWindow({
title: 'Home',
navBarHidden: false,
barImage: 'topbar.png',
backgroundImage: 'bga.png'
});
c = Titanium.UI.createImageView({
image: 'logobar.png',
top: -13,
right: 7,
width: 74,
height: 108,
exitOnClose: !0
})
try {
win1.add(c);
c.animate({zIndex:3});
win1.addEventListener('focus', function () {
Titanium.App.Analytics.trackPageview('/win1')
});
}catch(e){
alert(e);
}
The try-catch was implemented as I didn't trust the existence of .animate, however it did exist but did not work.
Answer(, or maybe not what it should be like)
Titanium itself does not support the feature of manipulating the zIndex or rather the onTop-properties. However, I've found a workaround allowing the overlay to be shown.
This workaround works by the way Titanium handles windows. First, we define the main window (e.g. win1) and fill it. Then we create an assistant window (e.g. win1a) and assign the ImageView to it. Then we position the new window on top of the other window and voilà.
var win1 = Titanium.UI.createWindow({
title: "*******",
navBarHidden: false,
barImage: 'topbar.png',
backgroundColor: "gray",
});
var win1l = Titanium.UI.createWindow({
title: "",
navBarHidden: true,
height: 84,
width: 64,
right: 0,
top: 0
});
// Inject ImageView into top-most window
win1l.add(Titanium.UI.createImageView({
image: "logobar.png",
top: 2,
right: 5,
width: 60.3, //74, // 74/108 = 0.6851851852
height: 88, //108, // ((108-20)*(74/108)) = 60.29629 ~ 60.3
exitOnClose: !0
}));
win1l.open();
I hope this might have been helpful for you.
Thanks, -Kenan.

Titanium: Create fields like the ones in iPhone Contacts (Edit Mode) app

Note: The divider aka separator is the main point of this question. It must be visible.
Is there a way to create fields like the ones in the iPhone Contacts (Edit Contact Mode) app?
I want to create a separator that separates the titleLabel from the textField.
Like " First Name | hinttext "
Instead of " First Name hinttext "
I think what I am trying to do is similar to this... except that I am using Titanium. Is there any way to do this using Titanium?
How is iPhone Contact app's detail View implemented
#MRT and anyone who knows:
How would you make the combined view such that it looks like this?
____________________
( Name | hinttext )
--------------------
You will have to create a new TableViewRow and customize it.
You can put labels, fields, images, etc. in the TableViewRow.
Example:
var row = Ti.UI.createTableViewRow();
var label = Ti.UI.createLabel({
text: "Name",
width: 50,
top: 5,
bottom: 5,
left: 5,
font: {fontSize:10}
});
row.add(label);
Try it this really usefull to you
var view1 = Ti.UI.createView({
height : 50,
width: 150,
top: 5,
bottom: 5,
left: 5,
font: {fontSize:10}
});
var text1 = Ti.UI.createTextField({
hintText : 'First Name',
height : 50,
width: 75,
top: 0,
left: 0,
font: {fontSize:10}
});
var text2 = Ti.UI.createTextField({
hintText : 'hint text',
height : 50,
width: 75,
top: 0,
left: 75,
font: {fontSize:10}
});
view1.add(text1);
view1.add(text2);
you have 2 way to do this.
take 2 TextField and adjust (top and left margin) and joint it.
or
1 Take 1 TextField
2. take 1 Label and its width 2 and height is equal to the textfield height.
3. TextField.add(lable1)
var win1 = Ti.UI.createWindow({
title : 'Window1',
backgroundColor : '#f00',
id : 0,
});
var text1 = Ti.UI.createTextField({
width : 150,
height : 50,
borderRadius : 9,
backgroundColor : '#fff',
top : 50,
left : 20,
});
var label1 = Ti.UI.createLabel({
width : 2,
height : 50,
top : 0,
left : 75,
});
text1.add(label1);
win1.add(text1);
win1.open();
To add a vertical line
var vline = Ti.UI.createView({
height: 44,
width: 1,
top: 0,
left: 85,
backgroundColor:'#CCC'
});
row.add(vline);
You just have to create a TableViewRow and add labels to it. There is not a ready template to this rows. But you can create an wrapper to it, if you will use it a lot. For example:
var createTableViewRowWithTitleAndValue(title, value) {
// TableViewRow
row = Ti.UI.createTableViewRow({
backgroundColor: "#FFFFFF"
});
// Title
row.add(Ti.UI.createLabel({
text: title,
left: 5,
font: { fontWeight: "bold" }
}));
// Value
row.add(Ti.UI.createLabel({
text: value,
right: 5,
textAlign: "right"
}));
}
Then, when you set data to TableView, instead you create a new TableViewRow, you create a new tableViewRowWithTitleAndValue, with title and value needed. For example:
rows.push(new createTableViewRowWithTitleAndValue("Foo", "Bar"));

Browse button in ExtJS

I need to have a browse button in a window. I need something like...
var myWindow = new Ext.window.Window({
id:'my-window',
height: 200,
width: 400,
layout: 'fit',
buttons:[browseButton]
});
So I guess I can't use the filefield in there since I need it to be in the window's button config.
Is there any button or maybe a handler I can use to create a button that pops up a browse window like the ones in filefield do?
You can set a config item on the field to only show the button for example, this works:
myButton = Ext.create('Ext.form.field.File', {
buttonOnly: true,
hideLabel: true,
listeners: {
'change': function(button, value){
alert('Selected: '+ value);
}
}
});
// your window example
var myWindow = new Ext.window.Window({
id:'my-window',
height: 200,
width: 400,
layout: 'fit',
buttons:[myButton]
});
myWindow.show();

Appcelerator - Newbie in the mix!

Quick one for any developers using appcelerator out there. I have two labels (This may even bew wrong) which are populated from an RSS feed. One label houses the title and another the description. The content for these comes from an RSS list which all works fine. THe issue I'm having is that some titles are longer than others so I cant fix label heights or it just wont work.
So with that in mind I set the titles height to be auto. The only problem is I cant reference this height from my second label to use the top: property to space it correctly.
Has anyone got any good suggestions?, Am I using the wrong type of Titanium UI method?
My current code is as follows
try
{
var current = Titanium.UI.currentWindow;
var selectedItem = current.item;
var description = selectedItem.getElementsByTagName("description");
var story = description.item(0).text;
var label = Ti.UI.createLabel({
text:selectedItem.getElementsByTagName("title").item(0).text,
left:5,
top:0,
height:"auto",
font:{fontSize:40}
});
current.add(label);
var story = Ti.UI.createLabel({
text:story,
left:5,
top:label.height,
height:"auto"
});
label.add(story);
}
catch(E)
{
alert(E)
}
minimumFontSize
the minimum size of the font when the font is sized based on the contents. Enables font scaling to fit and forces the label content to be limited to a single line
On the containing window / view, set the layout property to 'vertical' - this means the views are stacked on top of one another so your top value doesn't have to know the height of the previous component.
// Windows
var window = Ti.UI.createWindow({
layout: 'vertical',
backgroundColor: '#FFF'
});
var label = Ti.UI.createLabel({
width: 200,
height: 'auto',
text: 'some long text'
});
var label2 = Ti.UI.createLabel({
width: 200,
height: 'auto',
text: 'more long text',
top: 10 // This just adds some padding between the two labels
});
window.add(label);
window.add(label2);
window.open();