Vaadin - pass data to different UI - java

I am new to Vaadin and I tried to find the answer to this by searching SO as well as Google so any help will be appreciated or at least point me in the right direction.
My app navigates from one view to another using the following logic
ActivitiesUI startUpActivity = new ActivitiesUI();
UI.getCurrent().setContent(startUpActivity.buildMainArea());
I need to know how I can pass data (like a String or an int) from the current UI to the one being navigated to (in this case startUpActivity)
Coming from an Android background, I am thinking along the lines of an Intent

After some digging into the Wiki, I ended up using the Http Session to set and get the variables and it is working fine.

Related

So am building an app and it has this feature that i dont know exactly how to go about it

I hope this makes a bit sense, basically, I have this feature in my app for tracking calories which consists of having this page that only appears the first time you use the feature and it asks you to add personal details (so it can make the right calculations), after that you get faced with a simple page that tracks your nutrition with a button for the user to insert the meals he has eaten, this page has to save the inserted data (via firebase) and then restart from 0 each and every day.
my first problem is I don't know how I make the page that only appears one time to save personal data(to be more precise I don't know how to make only appears the first time). and the second problem is how do I make the app automatically sends the given data at the end of each day?
interface in normal state, interface when adding the meals
hopefully, this 2 images will help you get a better grasp of what am trying to explain
don't worry am not looking for someone to straight up solve it all for me, I just need some orientation about what type of things/functions I need to do to solve these 2 problems
While #Narendra_Nath's answer might work, please note that is not a bulletproof solution. Why? Because a SharedPreferences doesn't persist across app uninstalls. This means that your user can install and uninstall the app and see the page as much as they want. So if you indeed want a user to see a screen only once, then you should consider storing that data in a database. Please note that SQLite isn't also a solution because when a user uninstalls the app, everything that is stored locally is wiped out. So what's the solution?
The best way to solve this would be to store the data in the cloud, either in Cloud Firestore or in the Realtime Database. So you can set a boolean variable and always check against it.
If you however intend to implement Firebase Authentication, then another solution would be to display the screen when your users are authenticated for the first time. So even if they will try to sign in on another device, install and uninstall the app, they won't be able to see the screen again.
Regarding the second problem, you should consider using Cloud Function for Firebase. It's the most elegant solution. If you want to somehow schedule an operation, then you should consider using Cloud Scheduler, as explained in my answer in the following post:
Is it not possible to have a code in the background who will be called every 24h?
Make the page that only appears one-time -> store a value in the shared preferences "isInfoShownToUser -> false" then do a check when the app starts to check if this value is false or true. If it is false show the "take the info" page .. then turn the value to false in the shared preferences.
How do I make the app automatically send data -> Use a Workmanager implementation to send data to the server (Firebase) at a particular time ..
Or use a implementation like the first one which uploads the data to the server just once everyday

How to follow redirect in WebDriver

I'm very new to WebDriver, and the whole concept of a headless browser is hard to wrap my head around, and I could use some help...
This might be a stupid Idea for a project in the first place, but I thought I'd give it a shot, so please bear with me.
So I'm using cappex.com as my starting website, and then from there my program will search for GiveAway scholarships. And I have a big ol' set of variables that it will search for then attempt to imput. I'm having a lot of fun with this, the only problem I'm having is when ever it clicks a new scholarship it redirects in a new tab. see linked video for ex.
Is there a way to follow that redirect, like so I can now interact with that website.
there is no method of selenium web diver that I can see for redirects, so I'm not sure how to proceed.
I would share my code, but there's basically nothing yet, and given the nature of the project there is a lot of personal information. I'm programming using Java, in eclipse.
Thank you for your time, and help.
I had the same problem in past so what I did.
Get the WindowHandles
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
Switch to new opened tab
driver.switchTo().window(tabs.get(1));
then do whatever you want.
And if you want to switch to previous tab then
driver.switchTo().window(tabs.get(0));
You can switch to other tabs as well based on the their index.

How to get a web page source code with GeckoView

I am an android developer and I knew about GeckoView recently.
I can get source code of a web page by android WebView (java code).
However with my new website, android Webview can't load the webpage but GeckoView can.
Now I want to get source code of a web page by GeckoView.
Is there any body know the solution to resolve this problem ?
Thank in advance
As far as I know, you cannot use GeckoView to get the source code, but the geckoview library does have GeckoWebExecutor. Take a look at the fetch method and the WebResponse it returns.
By converting the WebResponse.body InputStream to a String you can get the source code.
One option for doing this could follow these steps:
detect which page my geckoview loaded;
save the loaded url into a sharedpref;
if user wants to see the source of the page, load the url saved within that sharedpref.
So...
(1-2) as you already know, geckoview doesn't have that handy shouldOverrideUrlLoading() method, so you will have to deal with the NavigationDelegate class, which has the onLocationChange(), where i put this line, which does nothing more than save the current url as a string into a sharedpref string named "geckoViewUrl":
sharedprefs.edit().putString("geckoViewUrl", url).apply();
having all setup before (sharedprefs etc). Detected the loaded page and saved the url into a sharedpref, let's go to the final step 3.
(3) for my use, wishing only to allow the user to see (and copy) the source, for the law of the minimum effort i used another activity with a plain and old webview to display it. This is very easy to implement and rises no confusion to the user. He/She wants to see the code, i show it in another activity. When it's done, he/she closes the new activity and life continues.
So, user wants source? Load another activity with a webview and make it load that saved sharedpref string:
addr2open = pref_out.getString("geckoViewUrl", "");
Doing this (for example), you get the url user wants to see source assigned to a string var. To finish, all you have to do is to make the webview load this string preceded by the precious word view-source:, this way:
webView.loadUrl("view-source:" + addr2open);
That's it. Of course you could implement a solution relying on the same activity, or using geckoView, showing multiple options, menus etc. I only wanted to show you a way to solve your problem in a nice 'n' easy way. You asked for "How to get a web page source code with GeckoView". Here is the answer. Works perfectly. If this is good for you, please, accept this as the correct answer. Thank you. Happy coding.
One example on the use of "view-source", from the creators of GeckoView: https://firefox-source-docs.mozilla.org/devtools-user/view_source/index.html (see item "Link to a line number").

Trasparent intro overlay to introduce user the app

I was wondering to create something like a setup wizard for when the user first starts my app. This is needed due to the complexity of the app to help the user. Searching for something like this I found a library that isn't a setup wizard, but lets you point an element on the screen and give some info about it.
The library is this link. (Showcase View Library by Espin)
I'm able to show one indication using this, but I can't concatenate more than one indication, you know, the first is shown, you pulse next and goes to the nex indication, this way until you arrive to the end and pulse finish.
Looking for any tutorial or step-by-step guide that could help me doing this, I found one, but it was done with old code, and the newest version of the library has some changes that doesn't fit the example. I've tried modifiying the code of this example to match with the new version of the library, but I don't get to view the indication one by one, I just get all them overlapped.
This is the link to the library's ShowcaseView class where all this logic is defined: ShowcaseView.java
And this is how the doc says to implement it ot your app:
new ShowcaseView.Builder(this)
.setTarget(new ActionViewTarget(this, ActionViewTarget.Type.HOME))
.setContentTitle("ShowcaseView")
.setContentText("This is highlighting the Home button")
.hideOnTouchOutside()
.build();
Has someone worked with this library and knows how could I concatenate few indications?
What's missing in v5
ShowcaseViews: the class which queues up ShowcaseViews in a
tutorial-type method. I never really liked this class (generally, you
should use SCV sparingly); I'll add it back in based on the Builder
class when I can.
So either:
implement it by yourself and submit a pull request.
Or wait for the next release.
Or use v4
Or submit an issue on github to directly ask the author when this will be released.

How to call an external web-service from Joomla

I am going to create a webservice (I think in java) which role is to treat a picture (IN) and to return a result (OUT). I would like to use that web service from my Joomla website.
The process will be :
1- upload of a picture from the website
2- we call the web service to treat the picture
3- we receive the result and display it in a new page
I really don't know how to proceed to do these 3 steps. My first question is : how do I call a web service with Joomla (2.5)?
Thanks
You can always use a wrapper which basically means have external websites appear inside where the article/components usually are.
Simply create a new menu item, change the type to "wrapper" and select the URL.
I think this is what you are looking for, if not please explain in more detail.
Maelkun,
I tried the example below in Joomla! using Jumi and it worked. If you have php 5.3 you can try with Sourcerer too.
http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/

Categories

Resources