Formula or API for calulating desktop icon spacing on Windows XP - windows-xp

I've built a simple application that applies grid-lines to an image or just simple colors for use as desktop wallpaper. The idea is that the desktop icons can be arranged within the grid. The problem is that depending on more things than I understand the actual spacing in pixels seems to be different from system to system. I've learned that at least these things play a factor:
Resolution (duh)
Taskbar size and placement
Fonts
There has to be more than this. Maybe there's some api call that I don't know about?

there are a 1001 ways to get/set this (but I only know 2) :-D
Windows Register:
HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics
values are IconSpacing and IconVerticalSpacing
by code:
using System.Management;
public string GetWinIconSpace()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Desktop");
foreach (ManagementObject wmi in searcher.Get())
{
try
{
return "Desktop Icon Spacing: " + wmi.GetPropertyValue("IconSpacing").ToString();
}
catch { }
}
return "Desktop Icon Spacing: Unknown";
}
and the 3rd that I never tried you can find it here

They might also be a size problem due to scaling algorithm if the requested size of the icon is not available.
(since an icon file is actually a collection of icons, as explained in this thread about Icons and cursors know where they came from, from the The Old New Thing)

Related

Change brightness of markers in Flutter

I made PNGs for custom markers on my GoogleMap view. By using e.g.:
BitmapDescriptor bikeBlack = await BitmapDescriptor.fromAsset(const ImageConfiguration(), "assets/images/bike_black.png")
I obtain an object that I can use as a marker directly. However, I need to be able to change the brighness as well for about 50 markers of 4 different types, during runtime. The only possible solution I have come up with so far is creating 1024 different PNGs. This will increase app size by about 2MB but it might be a lot of work to do..
I cannot really afford using await statements since they slow the app down considerably. But if I have to, I can force myself to live with that.
As far as I can tell, a marker icon has to be a BitmapDescriptor. But I cannot find a way to change the brightness of such a BitmapDescriptor.
I'm close to just giving up and just writing a python script that will generate the 1,024 PNGs for me. But there must be a nicer and more efficient solution. If you have one, please let me know.
[EDIT]:
I went with creating 1024 images. For anybody in the same situation, this is the script I used:
from PIL import Image, ImageEnhance
img = Image.open("../img.png")
enhancer = ImageEnhance.Brightness(img)
for i in range(256):
img_output = enhancer.enhance(i / 255)
img_output.save("img_{}.png".format(i), format="png")

Using the same control instance in different views or windows

I have a (chart) control with huge data (x curves a ~10'000 points) inside. I need to show the control with same data in different views or windows.
Since speed and consistency matters (ca 150ms to redraw), I have tried use the same (read only) control instance in diffent views or windows.
This scheme seems to work:
void CMyview::OnInitialUpdate()
{
..
if (NULL == m_pCurveTempCtrl)
{
m_pCurveTempCtrl = new CCurveCtrl;
..
}
void COtherView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
CWnd* m_pCurveCtrl = Pointer to CMyView::m_pCurveCtrl;
if (bActivate)
m_pCurveCtrl->SetParent(pActivateView);
else
m_pCurveCtrl->SetParent(pDeactiveView);
CFormViewEx::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
But is this allowed?
No. What happens if both view needs to be displayed? Only one will have a window...
The Doc View architecture is ideal for this.
Keep the data in the Document and use different views, that use the same data pool from the document.

Can I tell Google Cloud vision to isolate the largest (font size) text it reads in an image?

I would like to use cloud vision to recognize and isolate the "main" text in a picture (say for instance the largest writing on packaging). I assume cloud vision would be able to do that on the backend by looking at the font size/how many pixels each letter takes up, but I am not sure whether there is an output for that in the API.
My best guess at where this info would be in the documentation is at the following link but I couldn't see anything related to this: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText
TEXT_DETECTION Vision API
(https://cloud.google.com/vision/docs/samples#detecting_text_in_images)
can return arrays of (string + boundingPoly).
The json representation AnnotateImageResponse is below.
"textAnnotations": [
{
object(EntityAnnotation)
}
]
EntityAnnotation
https://cloud.google.com/vision/reference/rest/v1/images/annotate#EntityAnnotation
You can get the font size (in pixels) from BoundingPoly
https://cloud.google.com/vision/reference/rest/v1/images/annotate#BoundingPoly

Eclipse setInitialSize doesn't work

I'm trying to set my Eclipse RCP Application's initial size in the suggested way but it doesnt affect the actual size of the window. It doesn't matter what I set the size to the window always appears as fixed with 1020*765 dimensions.
See attached picture (I blanked out some sensitive info). I set the point to 600*400 yet the window appears with the same dimensions. So far no values entered affected the actual size.
I clear the workspace each time and even use -clearPersistedState
Any help would be appreciated
If you are running Eclipse 4.3 or 4.2 this is Eclipse bug 418615 the fix is scheduled for 4.3.2
By Greg's suggestion I looked for a different way and I could manage by using this code. Seems that under 4.3.1 the configurer's initialSize property never gets used but set to 1024*768 by default. This sets the Application window to the display's size:
#Override
public void postWindowOpen() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setBounds(getDisplaySize());
}
private Rectangle getDisplaySize() {
try {
Display display = Display.getCurrent();
Monitor monitor = display.getPrimaryMonitor();
Rectangle rect = monitor.getBounds();
return rect;
}
catch ( Throwable ignore ) {
return new Rectangle(0,0,1024,768);
}
}
Also for a maximized state you can use:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setMaximized(true);

Some beginner questions

I guess I'll start by saying I am very new to B4A, and to programming in general. I have some very basic java and html exp. but that's it. I do not have any basic4ppc or really any IDE experience. Been using B4A for a few days now and can't get over the hump. Here are my noob questions:
Does having many activities (20-30+) slow down the app? Is there a downside to having a lot of activities?
I can't figure out how to scroll in the designer. I am trying to make a screen that has 25 buttons down in 1 column. However I can't scroll down to add more buttons below. I am able to add buttons programmically and in the fashion that I want (using a for loop), but is it normal to create views at runtime like this?
How do you ensure your app looks the same across all devices? Tablets? I have a scroll view that fits perfect in the emulator, but on my phone (droid x), the bottom of the scroll view is not stretched to the bottom of the phone. I use the code: scvScreen1.Initialize(100%y). Is that not right?
I have a Email screen in which is comprised of an edittext and a Send button, so that the users can send me questions from the app. However the Send button gives me this error on the 'URI =' line: "LastException java.lang.NumberFormatException: mailto:" here is the code:
Sub btnSendEmail_Click
Dim Uri As String
Uri="mailto:me#gmail.com?subject=Test Email&body=" + edtHelpEmail.Text
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW,Uri
StartActivity(Intent1)
End Sub
Or is there another way to open the device's default email program?
Regarding last question, how do I copy error messages to clipboard?? I selected the red error message on the bottom right of the IDE and tried ctrl-c, but didn't work.
In B4A, what is a good method of storing persistent data? All I really need to store are some strings. Nothing fancy. These strings are to be stored locally. AI made this easy by using TinyDB.
When using the designer, how do you ensure your views are centered on all devices? For instance, I have a screen that has several rows made up of: (label, edittext, label). And I want each row to be center aligned. Do I do this programmically? I'm thinking I would have to append each row of (label, edittext, label) to a panel, then in the code center the panel. Is this correct?
That's all I got for now, but I'm sure there will be plenty more questions later.
1) The whole idea of android is to small components i.e. Apps working together, so no need to worry about opening lots of activities. Memory is very well managed behind the scenes in Android.
2) Sure. That sounds fine to me. Use the Layout designer as much as you can and then add the dynamic stuff later. It's all about striking a balance between the size of your code and the number of activities.
3) In the Designer there's an option called 'Send to UI Cloud'. This compares your app over multiple screen sizes. You can also scale your design and programmatically resize specific controls within your app in the Activity_Create Lifecycle
4) What you're doing is almost correct. I corrected your code:
Sub MailTo(StrAddress As String, StrSubject As String, StrBody As String)
Dim StrMethod As String = "Sub MailTo(StrAddress As String, StrSubject As String, StrBody As String)"
Try
Dim StrUri As String
StrUri = "mailto:" & StrAddress & "?subject=" & StrSubject & "&body=" & StrBody
Dim Intent As Intent
Intent.Initialize(Intent.ACTION_VIEW, StrUri)
StartActivity(Intent)
Catch
If BlnLoudExceptions Then CdException.Show(StrClass, StrMethod, LastException)
End Try
End Sub
I tend to have a code module called CdIntent.bas for these functions as it both keeps the project organised and makes it easier to implement the same functionality across projects.
Then to call you would use
CdIntent.MailTo("me#yes.no", "Subject!", "Body!")
5) I have a file called CdException.bas
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Show(StrClass As String, StrMethod As String, Ex As Exception)
LogColor("Exception: " & Ex.Message & " - Class: " & StrClass & " - Method: " & StrMethod, Colors.Magenta)
End Sub
and then wrap functions in the following way:
Sub FunctionName(...Parameters...) as Int
Dim StrMethod As String = "Sub Sleep(LngMilliseconds As Long)"
Dim IntResult As Int = 0
Try
[code here inc. IntResult = ???]
Catch
If BlnLoudExceptions Then CdException.Show(StrClass, StrMethod, LastException)
End Try
Return IntResult
End Sub
BlnLoudExceptions is a global boolean that you'd declare in
Process_Globals that you can switch on an off exception logs.
StrClass is a global String that you'd declare in Process_Globals
that contains the name of the class e.g. "CdIntent.bas"
The exceptions then appear in magenta in the log screen along with the method name and class in which they occurred allowing you to home in on them.
6) I have a table in an SQLLite database called TabletSettings, which has two TEXT colums called 'Name' and 'Value'. It works well and gets you into a (what I think is a) good habit of always having a database available to your app from the get-go.
7) I'll get back to you on this as I haven't done this before.
Until then, the following thread will help you in the B4A forum http://www.basic4ppc.com/android/forum/threads/convert-integer-to-dip.18800/
I agree with Jim's point but will attempt to answer 1.
I'm new to android myself but as I understand it activities on the whole are only running when active. Unless you are using the app to continuously do something there is only one activity at a time. The number of activities is likely to affect the ram available more than anything. Lastly it might be worth walking first rather than running so to speak but trying a single and then add multiple activities.
You could try adding a ListView or ScrollView where the items are the buttons, this seems to be the std way of doing things otherwise a tabbed view.