Get Application Icon Id - Monodroid - c#

I need to get the int id of my application icon. Is there any way I can do this?
I'm aware that there's GetApplicationIcon in PackageManager, but this returns a drawable. How can I get the Id of the drawable?
Drawable drawable = ApplicationContext.PackageManager.GetApplicationIcon(applicationInfo);
I was thinking of looping through all the resources in Android, but I'm not sure how, and I think it would be expensive. Any efficient way I can get the icon id?
EDIT: I understand that I can just easily get the resource id from R.drawable.myicon, but I was hoping to get the Id with the use of PackageManager or ApplicationContext.Resources.
EDIT #2: I got it. See my answer below.

R.drawable.ic_launcher (or other name you gave it) should represent the id you need.

Okay, I got it.
Intent intent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);
ResolveInfo resolveInfo = context.PackageManager.ResolveActivity(intent, PackageInfoFlags.MatchDefaultOnly);
int appIcon = resolveInfo.IconResource;

Well, since it's your application, you can just look in your manifest. Your icon appears in the <application> tag, in the android:icon attribute. Just look at that file and see what it says.
You don't need to program that, just do it yourself one time.

Related

Cannot get insides of the element from other app

I want to find specific button with text(find it by text) and press it.
I'm trying to get insides from 'group'('группа' on screanshot) element of a teleramm desctop app, i know there is defenetly list of buttons there, but i cant find anything with UIA and inspect.exe. I tried both raw automtaion dll and nuget UIAComWrapper.
SendMessage(to get text) and EnumChildWindows didn't help me as well, as SendMessage enum does not return other handles inside of app.
AutomationElementCollection automation_element_collection = group_element.FindAll(TreeScope.Children, Condition.TrueCondition); //empty collection
AutomationElement automation_element_collection = group_element.FindFirst(TreeScope.Children, Condition.TrueCondition); //returns null
TreeWalker raw_view_walker = TreeWalker.RawViewWalker;
AutomationElement automation_element = raw_view_walker.GetFirstChild(group_element); //returns null
What am i doing wrong and may there be any other projects to help me with this?
screanshot from inspector.exe
Telegram Desktop app just doesn't support accessibility features like UIA for ages, look at the Github ticket. Formally, it works, but on a really basic level - there is no option to retrieve the message history textual content, group and contact names, etc.
So, until any of those implemented, there is just no way to programmatically traverse the UI elements. But if you really need it, you could look at OCR.

Filter elements in Revit and set parameter

Hello everybody,
around two or three month ago I started to learn Dynamo for Revit... finally :)
After learning and testing a lot, I got a few own scripts working. Then I learned Python, because I couldn't create the next script only with Dynamo-Nodes.
Then I thought "Let's see how difficult it is to get something done as a PlugIn".
I watched some Videos and read a lot of stuff.
Finally I got the Revit-AddIn-Wizard installed and made my first small Test-PlugIn.
Great...
Now I have a few problems which I do not understand... so I thought I will try my luck here... because I got so much information and help, reading through this site.
My goal was/is the following: (I tell you what I have now)
A form with a few buttons, comboboxes and a DataGridView.
I can load an Excelfile, click on "Show" to show it in the DataGridView.
The header of each row will be automatically put into 3 comboboxes.
In the first combobox you select the first search-parameter, in the second you CAN select another search-parameter and in the third combobox you select the parameter you want to set.
I have a checkbox to switch from type- to instance-parameter for the search- and the set-operation.
There is also a button which shows another small form with a list of categories (I won't search for ALL, only nearly all modelcategories).
PlugIn
I took me a lot of "watching Videos, reading through the internet, testing, testing and testing".
Thanks to this site here and a few others... I managed to get this whole PlugIn nearly 100% working.
But now I have a few strange issues and I have absolutely no clue on how to fix them or if it is possible. And I really hope that someone can help me.
First... I just tell you my problems and perhaps someone can say "this really IS an issue!" or that it is possible to get it done. Then I would post some code.
So... what do I do?!
1. I have a FilteredElementCollector which filters ALL elements.
2. Depending on my "Type/Instance-Checkboxes" I do .WhereElementIsElementType OR .WhereElementIsNotElementType.
3. Then it passes a MultiCategoryFilter to get the big list down to only the modelcategories.
4. Next, the collection passes one of ten different "methods" depending on all settings. There I filter this collection depending on the searchlists-comboboxes. When the combobox says "Familie" or "Typ" then it filters for ".BuiltInParameter.SymbolFamilyName" or ".Name" otherwise it just uses ".LookupParameter".
After that I have a collection with only the elements of selected categories which contains the values from the Excellist.
5. Depending on what my search- and set-settings are (e.g. search for type and set instance) I have to get the instances from the collected types or the other way around.
6. Then I pass it down to another method where I finally set the parameter.
So... Excelheader goes into comboboxes, depending on what you select in there it creates lists with the values of the selected rows.
I hope you all understand.
Now... where are my problems?
When I search for type-familynames or instance-parameter and set a typeparameter it works for ALL categories without any error.
1. When I try to set an instanceparameter (doesn't matter what my search-setting are) it works for all "normal" families but not for the systemfamilies (e.g. walls, floors, pipes etc.). No error, just nothing happens WHY? It seems that I cannot set an instance-parameter for system-families.
2. Roofs, Stairs, CurtainPanels and GenericModel make problems when I search for a typeparameter Error is something like "The object reference was not set to an object instance". Only with these 4 categories and it doesn't matter what I want to set... but when I search for family-/typeNAME or Instance-Parameter, then I can set type or instance and it works (except instance for sysfam).
3. When I try to search AND set an instance-parameter it works for ALL categories EXCEPT if one wall does not contain a search value... it really is enough that ONE wall does not have a search-param-value that everything will be cancelled.
I have a few other small problems... but I hope someone can help me with these problems... I would be extremely thankfull
greetings and have a nice day or night :)
Philipp
Tl; dr.
The three problems you describe sound like your own. I have no heard anybody else runAsk three separate questions and provide three separate minimal code snippets describing how they arise,. into those. I suggest that you create three separate independent minimal reproducible cases to demonstrate all three issues. Chances are, when you simplify and minimalise your code, the problem will go away. If it does not, it might just possibly be in a small and manageable enough state for other people to help you take a look at it. Given the long-winded description above, nobody in the world can help you.
Thank you for your answer Jeremy,
as I said, as a first start it is ok for me if you don't say "With theses categories, there are indeed some issues!"
I think I've managed to create 3 small examples of my problems.
For each problem I made a zip-file containing the complete visual-studio folder, a small exampleproject and a readme.txt with (I hope) enough information to understand everything in detail.
Problem1
Problem3
You only need to compile them or copy the .addin and .ddl files into the Revit AddIn folder. Then you get the new ribbons.
Short problem summary = I get problems when searching for parametervalues and setting values to another parameter.
Edit: I just solved the 2. problem when searching for familynames and setting system-families-parameter.
I used:
ElementClassFilter ecf = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementColletor colle2 = new FilteredElementCollector(doc);
colle2.WherePasses(ecf);
I simply deleted the ClassFilter and do it now like in the other cases where I need instances.
FilteredElementCollector colle2 = new FilteredElementCollector(doc);
colle2.WhereElementIsNotElementType();
The 1. and 3. problem still exist :/
I would be thankful for any help someone can provide :)

Getting a resource in Xamarin

I am trying to do something very basic: Have an ImageButton load an image and an associated sound and have that sound play. I thought it would be easy to do, but I'm having two problems (although it probably is two symptoms of the same problem).
One, I don't see the images I added to the Resources/drawable folder show up in the Resource.Drawable class, all I see there is the default Icon from icon.png. I added 20 images with a .jpg extension and set them to AndroidResource in properties. They were numerically named, so I modified them to start with a letter (in case that was the problem), got rid of a dot in the name (in case that was the problem), and finally renamed them to .jpeg (in case that was it). These don't seem to be reasons why they don't show up.
The Resource.Designer.cs works, though, because the two mp3s I added to the Resources/raw do show up in the class.
The other problem I have is that I can't tell how to load them programatically, so I can pass them to
imageButton.SetImageResource(imageId);
I tried
var imageId = this.Resources.GetIdentifier("DigiBord.Sunete:i00011", null, null);
which didn't work, but maybe the items were not in the project. So I tried again with an item I knew was in the project:
var imageId = this.Resources.GetIdentifier("DigiBord.Sunete:Icon", null, null);
which again yielded 0. There must be a way to load them without knowing the int id of the item ahead of time.

Is there a reason I can't pass null as the title to the UIActionSheet constructor in MonoTouch?

I'm trying to make a delete confirmation action sheet like what you see in OmniGraffle, GarageBand, and several other apps. I want an action sheet with no title and one big red delete button.
In reading the documentation for the constructor of UIActionSheet, it says:
title
A string to display in the title area of the action sheet. Pass nil if you do not want to display any text in the title area.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html
However, if I do this in MonoTouch:
UIActionSheet actionSheet = new UIActionSheet(
null,
null,
null,
"Delete"
);
I get a NullArgumentException. Same if I try to workaround by passing in a dummy string and then do actionSheet.Title = null;. Passing in string.Empty works fine, but gives me extra space above the button I do not want.
So:
Is there a reason for this behavior, or is it just a MonoTouch bug?
Is there a workaround I can use to get the look and feel I want?
This (with a big red delete button) can't be too hard in MonoTouch!
But I'm stuck with this:
See the extra space at the top? What do I do?
Many thanks for filling the bug report. This has been fixed for future releases of MonoTouch.
Until then you should be able to replace this:
UIActionSheet actionSheet = new UIActionSheet(
null,
null,
null,
"Delete"
);
with
UIActionSheet actionSheet = new UIActionSheet ();
actionSheet.DestructiveButtonIndex = actionSheet.AddButton ("Delete");
Let me know if this does not cover the use case you had in mind and I'll try to find another workaround.
According to teh Apple documentation, passing nil for the title is perfectly valid.
This sounds like a bug in the MonoTouch binding of the UIActionSheet designated initializer. I searched the Xamarin Bugzilla and this does not seem to be a known issue.
I would file a bug, and link to this question, should be an easy fix. They may even be able to provide you with a workaround ;-)
Yes, there is. Null is not part of objective-c.
You need to use Nil. Look closely at the documentation you've posted.
The difference between them is that null is not an object and comes from c, while nil is an object and is a part of the objective-c superset.

Implementing a save function in a C# image manipulation app

I started thinking about how to handle the save functionality of my app, and thought about 2 options:
The application has nodes like:
Blur
Contrast
Sharpen
Invert
...
1. Interpreting the saved file, like:
Blur name:"Blur01" Amount:5
...
2. Having the saved file in a self executable format, like:
Blur blur = new Blur ();
blur.Name = "Blur01"
blur.Amount = 5
...
Which one should I go for? Is there a better way to handle this?
I want the saved file to be backwards and forwards compatible.
EDIT: Thanks for all the replies. Anyone can please explain why #2 would not be future proof? Is it because one can change the load/open code for #1, but not for #2?
You could probably use XML Serialization, since it's widely accepted and human readable.
Here's a tutorial on that: XML Serialization
I would go with something more like the first option.
Although, in general, I think XML would be a better approach to this than making your own syntax. This is much better from a compatibility/future-proofing standpoint than trying to make your own syntax parsers for your file.
What about something like:
<Filters>
<Blur Name="Blur01" />
<Sharpen Name="Sharpen01" Amount=5 />
</Filters>
I too would go with an XML file as this will allow you to ensure compatibility both forwards and backwards.
This is because you look for properties rather than parsing the file line by line.
For example, if blur changes from:
<Blur>
<name>Blur01</name>
<amount>5</amount>
</Blur>
to:
<Blur>
<name>Blur01</name>
<amount>5</amount>
<feather>true</feather>
</Blur>
Older versions of the app will still be able to read the file as they won't look for the feather property. All you need to do is ensure that you set default values when you create your objects so that the older files can be read without leaving unset data.
In response to the update - there's no reason why you couldn't make #2 future proof. You'd just have to do the versioning yourself.
The reason having a self-executing "save format" is generally bad is that today your "Blur" function might look like:
public class Blur
{
int Amount = 5;
}
but in the future, you might improve your blur "system" to instead have something like:
public class Blur
{
int HorizontalAmount = 5;
int VerticalAmount = 10;
}
and now when you execute that saved file, it will no longer compile because there is no longer an 'Amount' property. Then to get backwards compatibility you will need to 'interpret' the Amount value to now mean HorizontalAmount = 5 AND VerticalAmount = 5 (or whatever).
So really, in the long run, you will be better off by having an interpreted file format from the start.
Are you saving it in a text file?
If that is so wouldn't it be better to save it as XML?
<Blur>
<name>Blur01</name>
<amount>5</amount>
</Blur>
Otherwise I am not sure I understand the question :)

Categories