I am having trouble finding out how to set layout properties in my code.
My controls are being generated at runtime so I can't set the layout in my xml.
I would like to be able to set properties such as
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_weight="1"
However I can't find any documentation or examples on how to do this in code.
Is it possible with the current version of Mono for Android?
Relevant thread on the Mono for Android mailing list.
Many of the constructors take an IAttributeSet instance, so (worst case) you could always provide the XML custom attributes through that parameter when invoking the e.g. RelativeLayout(Context, IAttributeSet) constructor.
Resource attributes are handled specifically in Java code, and thus can potentially vary from one class to another. For example, the RelativeLayout constructor implementation.
Because of this, attributes can (and will be) specific to a given type. For example, as best as I can tell from quickly perusing the Android source, it's not valid for a type to have both android:layout_alignParentBottom and android:layout_weight attributes, as android:layout_alignParentBottom appears to be specific to the RelativeLayout type, while android:layout_weight is specific to LinearLayout, and there is no inheritance relationship between RelativeLayout and LinearLayout.
That said, to programmatically assign the android:layout_alignParentBottom property, it looks like you'd want to do:
// Get a RelativeLayout.LayoutParams instance
// Option 1, if you have an existing RelativeLayout instance already:
var p = (RelativeLayout.LayoutParams) layout.LayoutParameters;
// Option 2: if you don't.
var p = new RelativeLayout.LayoutParams (context, null);
// Enable layout_alignParentBottom:
p.AddRule ((int) LayoutRules.AlignParentBottom);
This uses the RelativeLayout.LayoutParams.AddRule method to enable the layout option. The int cast is necessary because we didn't realize that AddRule() should take a LayoutRules enum; oops.
To programmatically assign the android:layout_alignParentRight property:
p.AddRule ((int) LayoutRules.AlignParentRight);
As noted above, it appears that android:layout_weight is specific to LinearLayout, so we can't use RelativeLayout.LayoutParams to set this. Instead, we need to use LinearLayout.LayoutParams to set the LinearLayout.LayoutParams.Weight property:
// Just like before, but get a LinearLayout.LayoutParams instance
// Option 1, if you have an existing LinearLayout instance already:
var p = (LinearLayout.LayoutParams) layout.LayoutParameters;
// Option 2: if you don't.
var p = new LinearLayout.LayoutParams (context, null);
// Enable layout_weight:
p.Weight = 1.0f;
Related
I am new to Umbraco, can anyone tell me why I am seeing these 2 values instead of the expected string?
I get Umbraco.Web.Models when I use this code to get a link
var businessLink = child.Value("websiteLink");
And Umbraco.Web.PublishedModels when trying to use this code to get the name of the previous child to my current node:
var business = child.AncestorsOrSelf("Business").Last();
Any advice would be greatly appreciated.
I'm not sure what you're trying to accomplish, but for Umbraco v8, all of the following extension methods are available on Umbraco.Core.Models.IPublishedContent so you can have strongly typed access to all of them with intellisense for both content and media. These methods return IEnumerable<IPublishedContent>.
Children() // this is the same as using the Children property on the content item.
Ancestors()
Ancestors(int level)
Ancestors(string nodeTypeAlias)
AncestorsOrSelf()
AncestorsOrSelf(int level)
AncestorsOrSelf(string nodeTypeAlias)
Descendants()
Descendants(int level)
Descendants(string nodeTypeAlias)
DescendantsOrSelf()
DescendantsOrSelf(int level)
DescendantsOrSelf(string nodeTypeAlias)
Siblings()
SiblingsAndSelf()
Alternatively, you have other methods that return a single IPublishedContent.
Ancestor()
AncestorOrSelf()
AncestorOrSelf(int level)
AncestorOrSelf(string nodeTypeAlias)
AncestorOrSelf(Func<IPublishedContent, bool> func)
More information can be found here: https://our.umbraco.com/documentation/Reference/Templating/Mvc/querying
Im trying to use the Genexus Extensions SDK to place buttons on the IDE, in this case, i want to place it in the "context" menu, avaliable only in objects of type "Webpanel/Webcomponent" and "Transaction", Just like WorkWithPlus does here:
So far, digging up into the avaliable documentation, i've noticed that you need tu put the context type string into the xml tag and the GUID of the package that you're aiming to add the menu item, such as below in GeneXusPackage.package:
The Context ID above will add the item into the "Folder View" Context.
My questions:
Where can I find a list with all the possible ID Context strings?
What is that package attribute for, where can i get it's possible values?
I am using the SDK for Genexus 16 U11
I'm sorry to say that there is no extensive list of all the menus available. I'd never thought of it until now, and I see how it could be useful, so we'll definitely consider making it part of the SDK so that any package implementor may use it for reference.
In the meantime, in order to add a new command in the context menu you mentioned, you have to add it to the command group that is listed as part of that menu. That group is KBObjectGrp which is provided by the core shell package whose id is 98121D96-A7D8-468b-9310-B1F468F812AE.
First define your command in your .package file inside a Commands section:
<Commands>
<CommandDefinition id='MyCommand' context='selection'/>
</Commands>
Then add it to the KBObjectGrp mentioned earlier.
<Groups>
<Group refid='KBObjectGrp' package='98121D96-A7D8-468b-9310-B1F468F812AE'>
<Command refid='MyCommand' />
</Group>
</Groups>
Then in order to make your command available only to the objects you said before, you have to code a query handler for the command, that will rule when the command is enabled, disabled, or not visible at all. You can do that in the Initialize method of your package class.
public override void Initialize(IGxServiceProvider services)
{
base.Initialize(services);
CommandKey myCmdKey = new CommandKey(Id, "MyCommand");
AddCommand(myCmdKey, ExecMyCommand, QueryMyCommand);
}
private bool QueryMyCommand(CommandData data, ref CommandStatus status)
{
var selection = KBObjectSelectionHelper.TryGetKBObjectsFrom(data.Context).ToList();
status.Visible(selection.Count > 0 && selection.All(obj => obj.Type == ObjClass.Transaction || obj.Type == ObjClass.WebPanel));
return true;
}
private bool ExecMyCommand(CommandData data)
{
// Your command here
return true;
}
I'm using some helper classes here in order to get the objects from the selection, and then a class named ObjClass which exposes the guid of the most common object types. If you feel something isn't clear enough, don't hesitate to reach out.
Decompiling the Genexus dll and looking for the resource called package, you can infer what the names are.
It's cumbersome but it works
In c++ we have iterators that act as reference to some element in list. Assigning to the iterator it is possible to change elements inside the list.
for example:
std::map<std::pair<int,int> ,Ship> playgroundMap;
playgroundMap.insert(std::make_pair(std::make_pair(2,2),Ship(100,Cannon(50))));
playgroundMap.insert(std::make_pair(std::make_pair(3,3),Ship(200,Cannon(60))));
std::cout<<"Iterators : "<<std::endl;
auto shipPtr = playgroundMap.find(std::make_pair(2,2));
std::cout<<" address of ship Before : "<<&shipPtr->second<<std::endl;
shipPtr->second.cannon.firepower = 1000;
auto tmp = Ship(200,Cannon(90));
shipPtr->second = tmp;
std::cout<<" address of ship After newly Assigned : "<<&shipPtr->second<<std::endl;
std::cout<<"finalList : "<<std::endl;
for(auto a : playgroundMap)
{
std::cout<<a.second.durability<<std::endl<<a.second.cannon.firepower<<std::endl;
}
Let alone the fact that reference in c++ are enough to achieve this. References in c++ do not rebound on assignment like they do in dart.
for example in c++:
std::map<std::pair<int,int> ,Ship> playgroundMap;
playgroundMap.insert(std::make_pair(std::make_pair(2,2),Ship(100,Cannon(50))));
playgroundMap.insert(std::make_pair(std::make_pair(3,3),Ship(200,Cannon(60))));
std::cout<<"Reference : "<<std::endl;
auto &shipRef = playgroundMap[std::make_pair(2,2)];
std::cout<<" address of ship Before : "<<&shipRef<<std::endl;
shipRef.cannon.firepower = 1000;
auto tmp = Ship(200,Cannon(90));
auto &tmpRef = tmp;
std::cout<<" address of tmpref (newly created ship) : "<<&tmpRef<<std::endl;
shipRef = tmpRef;
std::cout<<" address of ship After newly Assigned : "<<&shipRef<<std::endl;
std::cout<<" address of finalList : "<<std::endl;
for(auto a : playgroundMap)
{
std::cout<<a.second.durability<<std::endl<<a.second.cannon.firepower<<std::endl;
}
This would modify the list element in c++ while in dart the reference would rebind and element in list would not change.That is whole another thing i understand that both these concepts are different in both languages.
My question is, Is there some kind of c++ iterator like way in dart that allows me to do these kind of operations. I know i can just store the index but i don't want to do that.
There is nothing like that in the platform libraries.
In general, Dart iterators give access to the values of a collection, not to changing the collection itself.
One of the reasons for this restriction could be that Dart doesn't have reference variables to begin with, but nothing inherently prevents Dart from having an iterator that allows you to change the value of the current element. At least for a list, it could work. A hash set probably wouldn't work, because the changed value wouldn't be in the same place of the iteration.
All in all, it's not something the platform libraries support, or have wanted to support. The Dart platform libraries are, in most places, slightly more functional programming like than C++.
I created Java user defined node in IntegrationToolkit (9.0.0.1) and assigned it with several properties. Two of the node properties are simple (of String type) and one property is complex (table property with predefined type of User-defined) that is consisted of another two simple properties.
By following the documentation I was able to read two simple properties in my Java extension class (that extends MbNode and implements MbNodeInterface) by making getters and setters that match the names of the two simple properties. Documentation also states that getters and setters should return and set String values whatever the real simple type of a property may be. Obviously, this would not work for my complex node property.
I was also able to read User Defined Properties that are defined on the message flow level, by using CMP (Integration Buss API) classes, which was another impossible thing to do from user defined node without CMP. At one point I began to think that my complex property would be among User Defined Properties, (although UDPs are defined on the flow level and my property is defined on the custom node level) based on some other random documentation and some other forum discussion.
I finally deduced that the complex property should map to MbTable type (as it is so stated in that type's description), but I was not able to use that.
Does anyone know how to access user defined node's complex(table) property value from Java?
I recently started working with WebSphere Message Broker v 8.0.0.5 for one of my projects and I was going to ask the same question until SO suggested your question which answered my question. It might be a little late for this question but it may help others having similar questions.
After many frustrating hours consulting IBM documentation this is what I found following your thread:
You're correct about the properties being available as user-defined properties (UDP) but only at the node level.
According to the JavaDoc for MbTable class (emphasis added to call out the relevant parts):
MbTable is a complex data type which contains one or more rows of simple data types. It structure is very similar to a * standard java record set. It can not be constructed in a node but instead is returned by the getUserDefinedAttribute() on the MbNode class. Its primary use is in allowing complex attributes to be defined on nodes instead of the normal static simple types. It can only be used in the runtime if a version of the toolkit that supports complex properties is being used.
You have to call com.ibm.broker.plugin.MbNode.getUserDefinedAttribute which will return an instance of com.ibm.broker.plugin.MbTable. However, the broker runtime doesn't call any setter methods for the complex attributes during the node initialization process like it does for simple properties. Also, you cannot access the complex attributes in either the constructor or the setter methods of other simple properties in the node class. These are available only in the run or evaluate method.
The following is the decompiled method definition of com.ibm.broker.plugin.MbNode.getUserDefinedAttribute.
public Object getUserDefinedAttribute(String string) {
Object object;
String string2 = "addDynamicTerminals";
if (Trace.isOn) {
Trace.logNamedEntry((Object)this, (String)string2);
}
if ((object = this.getUDA(string)) != null && object.getClass() == MbElement.class) {
try {
MbTable mbTable;
MbElement mbElement = (MbElement)object;
object = mbTable = new MbTable(mbElement);
}
catch (MbException var4_5) {
if (Trace.isOn) {
Trace.logStackTrace((Object)this, (String)string2, (Throwable)var4_5);
}
object = null;
}
}
if (Trace.isOn) {
Trace.logNamedExit((Object)this, (String)string2);
}
return object;
}
As you can see it always returns an instance of MbTable if the attribute is found.
I was able to access the complex attributes with the following code in my node definition:
#Override
public void evaluate(MbMessageAssembly inAssembly, MbInputTerminal inTerminal) throws MbException {
checkUserDefinedProperties();
}
/**
* #throws MbException
*/
private void checkUserDefinedProperties() throws MbException {
Object obj = getUserDefinedAttribute("geoLocations");
if (obj instanceof MbTable) {
MbTable table = (MbTable) obj;
int size = table.size();
int i = 0;
table.moveToRow(i);
for (; i < size; i++, table.next()) {
String latitude = (String) table.getValue("latitube");
String longitude = (String) table.getValue("longitude");
}
}
}
The documentation for declaring attributes for user-defined extensions in Java is surprisingly silent on this little bit of detail.
Please note that all the references and code are for WebSphere Message Broker v 8.0.0 and should be relevant for IBM Integration Bus 9.0.0.1 too.
I want to do this in Actionscript:
typeof(control1) != typeof(control2)
to test if two objects are of the same type. This would work just fine in C#, but in Actionscript it doesnt. In fact it returns 'object' for both typeof() expressions because thats the way Actionscript works.
I couldn't seem to find an alternative by looking in the debugger, or on pages that describe typeof() in Actionscript.
Is there a way to get the actual runtime type?
The best way is to use flash.utils.getQualifiedClassName(). Additionally, you can use flash.utils.describeType() to get an XML document the describes more about the class.
Actionscript 3 has an is operator which can be used to compare objects. Consider the following code:
var mySprite:Sprite = new Sprite();
var myMovie:MovieClip = new MovieClip();
trace(mySprite is Sprite);
trace(myMovie is MovieClip);
trace(mySprite is MovieClip);
trace(myMovie is Sprite);
Which will produce the following output:
true
true
false
false
This will work for built-in classes, and classes you create yourself. The actionscript 2 equivalent of the is operator is instanceof.
You'll want to use the Object.prototype.constructor.
From the documentation:
dynamic class A {}
trace(A.prototype.constructor); // [class A]
trace(A.prototype.constructor == A); // true
var myA:A = new A();
trace(myA.constructor == A); // true
(Conveniently, this is also how to check types in javascript, which is what originally led me to this in the docs)
So, to test this out before I posted here, I tried it in an app I have, in a class called Player. Since the prototype property is static, you can't call it using "this" but you can just skip the scope identifier and it works:
public function checkType():void {
trace(prototype.constructor, prototype.constructor == Player);
// shows [class Player] true
}
Is there a way to get the actual runtime type?
Yes.
var actualRuntimeType:Class = Object(yourInstance).constructor;
Some other answers already refer to .constructor, but you can't always directly access .constructor in ActionScript 3. It is only accessible on dynamic classes, which most classes are not. Attempting to use it on a regular class will cause a compile-time error under the default settings.
However, because every class inherits from Object, which is dynamic, we can look up their .constructor property just by casting an instance to Object.
Therefore if we are not interested in subclasses, we can confirm that two instances are of exactly the same class by simply evaluating this:
Object(instanceA).constructor === Object(instanceB).constructor;
I learned of this from the post "Get the class used to create an object instance in AS3" by Josh Tynjala.
A even simpler alternative that also works for me is just:
var actualRuntimeType:Class = yourInstance["constructor"];
The runtime is entirely capable of giving you the .constructor, it's just that the compiler complains if you use that syntax. Using ["constructor"] should produce the same bytecode, but the compiler isn't clever enough to stop you.
I included this second because it hasn't been tested anywhere except my current Flash environment, whereas several users have said that the method described above works for them.
If you want to account for inheritance, then you might want to try something like this:
if (objectA is objectB.constructor || objectB is objectA.constructor)
{
// ObjectA inherits from ObjectB or vice versa
}
More generally, if you want to test whether objectA is a subtype of objectB
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
...
if (objectA is getDefinitionByName(getQualifiedClassName(objectB)))
{
...
}
Object obj = new Object();
Object o = new Object();
if(o.getClass().getName().endsWith(obj.getClass().getName())){
return true;
}else{
return false;
}