Widget with Dialog

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Widget with Dialog

Post by husky » 14 Dec 2016 22:24

Hello,

I'm trying to build a Widget to convert Celsius to Fahrenheit.

The process is as follows:

Define widget (named C-to-F) where:
text_1 should return the temperature in Celsius as input from Input Dialog
text_2 should return the converted temperature in Fahrenheit
a CLICK from the Widget Clickable Actions pointing to the flow containing the Input Dialog and conversion calculation.

The flow contains:
The Input Dialog, the capture of the input temperature from the Input Dialog variable called value, as per https://automagic4android.com/en/help/c ... put_dialog.
A Script to convert the temperature into Fahrenheit.

Widget setup:
An AM Custom Widget points to the above named Widget.

Once the Widget Icon is pressed(clicked) the Widget Icon, an Input Dialog opens and expects the temperature in Celsius.

Stand alone run of the flow (without the widget):
Works correctly. It does the conversion using Input Dialog using variable value as input data.

Expected Outcome:
In text_1 the temperature from the Input Dialog (Celsius).
in text_2 the tempearature converted to Fahrenheit.
Both temperatures should be shown inside the Widget.

What I'm unable to figure out:

Why the temperatures are not updated inside the AM Custom Widget after execution.?
What am I missing?

Example:
If Celsius = 0, Fahrenheit = 32. So Text_1 = 0, Text_2 = 32.
If Celsius = 100, Fahrenheit = 212. So Text_1 = 100, Text_2 = 212.


I'd appreciate any help

Thanks

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

User avatar
Scotty
Posts: 78
Joined: 26 Aug 2016 20:29
Location: Southern California

Re: Widget with Dialog

Post by Scotty » 15 Dec 2016 20:36

I think there are 2 ways to do what you want. I've used only #2 below, so #1 is (for me) untested; if what I say is incorrect, I hope someone else will chime in ....

1. In order for the widget to be able to "see" the variables, you need to make them global;, so, for example, name them global_value , or global_text1

2. See this page, and exploit SetWidgetElementProperty.

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Widget with Dialog

Post by husky » 16 Dec 2016 01:52

Scotty,


Thanks for the reply.

I'm missing something when using getWidget.ElementProperty.

Widget: named C-to-F.
in C-to-F the flow called from Clickable Actions is named CtoF.
The Text_1 field (shows the input data) has {global_c}
The Text_2 field (shows the converted input) has {global_f}

Flow CtoF:
1. Input Dialog to receive the input data and passes it to the script as follows:

global_value = value; (I take that the variable value has the input I typed in)
global_f = (global_c * 9) /5 +32;

getWidgetElementProperty("C-to-F", {global_c}, "visible");
getWidgetElementProperty("C-to-F", {global_f}, "visible");

Questions in my mind:

1. Am I using the parameters correctly?
2. If so, the processing why (Text_1, Text_2) in the widget are not updated?

Funny behavior:

If I press(click) the widget nothing happens (the fields in the widget do not get updated).
If I just run the flow, the widget gets updated correcly in both fields.
Like it's working backwards????
What I want is to click the widget and have the flow update the fields.

Regards

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

User avatar
Scotty
Posts: 78
Joined: 26 Aug 2016 20:29
Location: Southern California

Re: Widget with Dialog

Post by Scotty » 16 Dec 2016 16:50

In my post, I described two methods. #1 used global variables. #2 suggested using SetWidgetElementProperty.

You seem to be using global variables (method #1) together with the function getwidgetelementproperty (i.e., the GET function, not the SET function that I suggested in #2). I haven't used the GET function myself, but it looks to me as though the flow is getting its value from the widget, when you really want it to work the other way around.

So, I'd remove everything related to that function.

Your flow should be very simple, something like:
1. trigger (leave this "blank")
2. Action - input dialog (make sure you use number type)
3. Action - Script with only 2 lines:
global_c = value;
global_f = (global_c * 9) /5 +32;

Then, I think, your widget (as you've described it) should work

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Widget with Dialog

Post by husky » 17 Dec 2016 01:37

Scotty,

I tried all combinations of what you said with all other ones I could think of. Neither works.


Regards

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

User avatar
Scotty
Posts: 78
Joined: 26 Aug 2016 20:29
Location: Southern California

Re: Widget with Dialog

Post by Scotty » 17 Dec 2016 21:05

Not sure why, because before posting, I made the flow & widget - and it works perfectly for me. Tap the widget - the flow starts - input dialog opens - I enter a value (say, 0), tap OK - the widget shows 0 and 32. Screenshot below (I made no attempt to make the widget pretty - just functional).

Image

I attach the flow, and the (ugly) widget.....
Attachments
CtoF.zip
(1.88 KiB) Downloaded 826 times

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Widget with Dialog

Post by husky » 18 Dec 2016 11:40

Scotty,

I'm sorry being so obtuse.

I downloaded your flow/widget zip file into Windows 10 and moved it to a Windows folder but I don't know how to load the .xml files into the phone.

I never done that and my research on the Forum came up empty.

Could you give me some idea on how to do that. I'm eager to see your "ugly" :) Widget and flow.


Thank You

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Widget with Dialog

Post by MURTUMA » 18 Dec 2016 12:16

Open the forums with Automagic app: menu > forums. Open the links containing flows or widgets with Automagic and they will get imported. If the xml files are opened by some other app, go to the app settings and clear the defaults. After that your phone should ask you about which app you want to use to open the link. Then select Automagic.

If you download the xml by some other methods, save them on your phone and use action Import Flows/Widgets to import them to AM.

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Widget with Dialog

Post by husky » 18 Dec 2016 12:47

Murtuma,

Thank You for the guide to success.

I was able to import the .xml and it is working.

Regards


Husky
"Basic research is what I'm doing when I don't know what I'm doing"

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Widget with Dialog

Post by husky » 18 Dec 2016 12:57

Scotty,

I have to confess I need a lot to learn from you guys, and with everybody helping out a braindead like me probably my IQ will grow from negative to some positive value. :D

Scotty, Your widget is FAR from "ugly". :!: :!:

Thank You very much.

I'll try to keep out of everybody's hair the best I can. You guys have more important problems to solve than mine.

Excellent work everybody and

I wish a Merry Christmas and Happy New Year for you folks.


Husky
"Basic research is what I'm doing when I don't know what I'm doing"

Post Reply