tabbedBar, showing different views titanium - titanium-alloy

Here is my code for tabbed bar:
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Hello, World</Label>
<TabbedBar id="bb1" platform="ios" backgroundColor="#369" top="50" height="25" width="200">
<!-- The Labels tag sets the TabbedBar.labels property. -->
<Labels>
<!-- Specify text with node text or the title attribute. -->
<!-- Can also specify the enabled, image and width attributes. -->
<Label>One</Label>
<Label>Two</Label>
<Label>Three</Label>
</Labels>
<!-- Place additional views for the TabbedBar here. -->
<Views>
<View backgroundColor='red'>1</View>
<View>2</View>
<View><Label>Does this work!</Label></View>
</Views>
</TabbedBar>
</Window>
</Alloy>
When I click on a tab, how can I make sure that the view corresponds to the button pressed - I know how to do this in titanium but not alloy.
Cheers.

I had the same problem yesterday. I'm sure there must be a better way but I couldn't see anything in the documentation, this was my solution:
var animation = require('alloy/animation');
var previousIndex = $.tabbedBar.getIndex();
$.tabbedBar.addEventListener('click', function(){
var currentIndex = $.tabbedBar.getIndex();
var viewArr = [];
viewArr[0] = $.view1;
viewArr[1] = $.view2;
viewArr[2] = $.view3;
animation.crossFade(viewArr[previousIndex], viewArr[currentIndex], 700)
previousIndex = currentIndex;
});
EDIT:
(In case you don't know, on Android there's a module to give you similar functionality: https://github.com/ricardoalcocer/viewpager but check issue #5 on the original repo as you'll have to incorporate that into any build. On the Android version, you don't need to handle the clicks yourself.)

Related

CSS Selector: Clicking on child element based upon value of other child element

Here is the code snippet:
I am trying to click on Building Div based upon the title attribute value of class card-details__title.
Thanks
U need javascript for this.
Add the following code just before the </body> tag.
<script>
<!-- get elements from DOM -->
var titleDiv = document.getElementsByClassName('card-details__title')[0];
var detailDiv = document.getElementsByClassName('card-details__action')[0];
<!-- get title from tag -->
var titleTxt = titleDiv.getAttribute("title");
if (titleTxt==='add your condition text here'){
<!-- click the div if title matches the one you need -->
detailDiv.click();
}
</script>
Thanks #Charitra, I need this piece of code for automation and I tweak around and end up having a following code which go through all the listed owners and found the intended one and then click on its building link.
<!-- get the total number of elements from DOM -->
var totalOwners = document.querySelector('app-landlords-list > div > div').childElementCount;
var j=0;
for (var i = 0; i < totalOwners; i++) {
<!-- get elements from DOM -->
var titleDiv = document.getElementsByClassName('card-details__title')[i];
var detailDiv = document.getElementsByClassName('card-details__action')[j];
<!-- get title from tag -->
var titleTxt = titleDiv.getAttribute("title");
if (titleTxt=='Condition text')
{
<!-- click the div if title matches the one you need -->
detailDiv.click();
break;
}
j=j+3;
}

Connect selected bar (vizframe barchart) to a button

I already have a barplot ui5 vizframe, but I would like to allow the user to select some of those bars, add each element id to a list and then send the list through a button in order to display a more detailed graph on a fragment.xml view.
On my picture example, the selection is mathematics, ASP and C#.
Here is the view.xml for the main graph panel:
<f:Card class="sapUiTinyMargin tileLayout" width="96%" visible="{config>/useFeatureEnableDemoFunctionality}">
<f:layoutData>
<grid:GridItemLayoutData gridRow="span 2"/>
</f:layoutData>
<f:header>
<card:Header title="Skills popularity" subtitle="List of skills and tools ordered by how many people mentioned it in their profile"/>
</f:header>
<f:content>
<viz:VizFrame id="idVizFrame" uiConfig="{applicationSet:'fiori'}" height='100%' width="100%" vizType='bar'>
<viz:dataset>
<viz.data:FlattenedDataset data="{path:'/PopularSkills', length: 30, sorter:{ path: 'MembersCount', descending: true }}">
<viz.data:dimensions>
<viz.data:DimensionDefinition name="Label" value="{Label}"/>
</viz.data:dimensions>
<viz.data:measures>
<viz.data:MeasureDefinition name="Popularity" value="{MembersCount}"/>
</viz.data:measures>
</viz.data:FlattenedDataset>
</viz:dataset>
<viz:feeds>
<viz.feeds:FeedItem id='valueAxisFeed' uid="valueAxis" type="Measure" values="Popularity"/>
<viz.feeds:FeedItem uid="categoryAxis" type="Dimension" values="Label"/>
</viz:feeds>
</viz:VizFrame>
<!--<Button icon="sap-icon://log" class="sapUiTinyMargin" text='Analyse selection' press="ButtonSkillSelection"/>-->
</f:content>
</f:Card>
Rendered chart:
[
This is a method to retrieve selected items in the VizFrame:
<Button press=".onPress"/>
onPress: function(){
const selectedSkills = this.getView().byId("idVizFrame").vizSelection();
//Do something useful with your selection
}

How to set a background image to a Grid in xamarin.forms?

I want to set a background image to my Grid in code behind. I found in internet that we can do using XAML like this.
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Pages.PhotoPage">
<Grid >
<Image Source="background.png" Aspect="AspectFit" />
<!-- Place here the rest of the layout for the page. -->
</Grid >
But how can I set this in code behind. I cannot see anyImage or BackgroundImage property for Grid. Please help me.
Thanks
You can just create an empty Image element in the Grid and set it.
<Grid>
<Image x:Name="BackgroundImage" Aspect="AspectFit" />
<!-- Place here the rest of the layout for the page. -->
</Grid>
And now set it in code:
backgroundImage.Source = ...;
If you are building the whole UI in code, you can do this as well:
var myGrid = new Grid();
var backgroundImage = new Image();
backgroundImage.Source = ...;
myGrid.Children.Add( backgroundImage );
If your Grid has multiple rows and columns, you will want to set the Grid.ColumnSpan and Grid.RowSpan properties on the image to make it span the whole grid.

How to display button over a map / MapLayer in windows phone 8?

I'm new in Windows phone 8 development and I have problem to add button on MapLayer.
I'd like to display a button over a map so I just draw it on the map widget like this:
<Grid x:Name="MyMapGrid" Margin="10,-15,15,0" VerticalAlignment="Top" Height="296" >
<maps:Map x:Name="MyMapi" Center="31.765537,35.106812" ZoomLevel="7" Margin="0,0,0,0" VerticalAlignment="Top" Height="296" Width="442" />
<Button x:Name="myCustomButton" Visibility="Visible" Content="" HorizontalAlignment="Left" Margin="347,0,0,0" VerticalAlignment="Top" Width="84" Height="84" BorderThickness="0">
<Button.Background>
<ImageBrush ImageSource="/myZoom.png"/>
</Button.Background>
</Button>
</Grid>
After this action I need to put some icons on the map so I used MapOverlay and MapLayer like this:
Map MyMap = new Map();
MapOverlay overlay = new MapOverlay
{
GeoCoordinate = MyMap.Center,
Content = new Image()
{
Source = new BitmapImage(new Uri("customIcon.png", UriKind.Relative)),
}
};
MapLayer layer = new MapLayer();
layer.Add(overlay);
MyMap.Layers.Add(layer);
MyMapGrid.Children.Add(MyMap);
I also need my button (myCustomButton) will stay visible - but it disappear.
how can I still have some button over the map and also view some icons on it?
Thank you all!
For button Change the path to definite like ImageSource="/Assets/Icon/location.png" with the folder name and make sure that BuildAction is set to content for that image
For icon also try the same.

In Flex 4.5, how to add a toolTip to an InlineGraphicElement inside a TextFlow (TLF) using ActionScript (not MXML)?

var newParagraph : ParagraphElement = new ParagraphElement();
var icon : InlineGraphicElement = MY_ICON;
// icon.toolTip = "boo" ????
newParagraph.addChild( icon );
I want a specific toolTip for "icon". I have read about using HTML and rollOver and rollOut (e.g. Thanks, Mister), but I'm building this as part of a larger text block; it's difficult to switch from incremental objects to HTML in the middle.
If I cannot set an event on the icon, can I create an HTML bit in ActionScript as part (but not all) of a paragraph ?
Cheers
I just came across the same problem.
The easiest solution i found was wrapping my InlineGraphicElement in a LinkElement.
The LinkElement already dispatches mouse events.
The problem (as I'm sure you found out) is that text flow elements are not display objects, and so do not implement the normal display object behavior.
What you need to do is create a custom InlineGraphicElement that attaches the event listeners you need, then dispatch an event off of the textFlow instance so it can be read in somewhere in your display object hierarchy (or whatever your method of choice is to target that event).
You can see a good example of how to add mouse interaction by looking at the source to the LinkElement (see the createContentElement function).
Unfortunately the InlineGraphicElement is marked final, so you will need to duplicate it's functionality rather then extend it. Just make sure to use the custom graphic element in your code in lieu of the normal one.
Best of luck!
edit
Just in case the point was lost, the idea is that you can capture the mouse event somewhere in your app by attaching a listener to the textFlow, then programmatically create and position a tool tip over the element using the standard methods to find the bounds of a text flow element.
You can do some hit-testing when the mouse is over the textflow component.
Suppose you have some textflow like this:
<s:RichEditableText width="100%" height="100%" mouseOver="toggleTooltip()">
<s:textFlow>
<s:TextFlow>
<s:p>
<s:span>Some text before</s:span>
<s:img id="myImg" source="myImg.png" />
<s:span>Some text after</s:span>
</s:p>
</s:TextFlow>
</s:textFlow>
</s:RichEditableText>
And you listen for mouseOver events on the entire textcomponent.
Then to test if the mouse is over your image, implement the mouseOver handler:
private function toggleTooltip():void {
var graphic:DisplayObject = myImg.graphic;
var anchor:Point = graphic.localToGlobal(new Point(0, 0));
if (mouseX >= anchor.x && mouseX <= anchor.x + graphic.width &&
mouseY >= anchor.y && mouseY <= anchor.y + graphic.height)
{
trace('show tooltip');
}
else {
trace('hide tooltip');
}
}

Resources