Trying to add google maps to a Vaadin view - java

I'm trying to use the Vaadin GoogleMaps plugin on our web application to show a small window with Google maps. I have this:
private GoogleMap googleMap;
private LatLon mapMarkerlatLon;
private GoogleMapMarker googleMapMarker;
private final String apiKey = "https://maps.googleapis.com/maps/api/js?key=<ourKey>=initMap";
#Override
public void enter(ViewChangeEvent event) {
//googleMap = new GoogleMap(apiKey, null, null);
//As suggested:
googleMap = new GoogleMap(apiKey, null, "english");
mapMarkerlatLon = new LatLon(0,0);
googleMap.setCenter(mapMarkerlatLon);
googleMapMarker = new GoogleMapMarker("Tal", mapMarkerlatLon, false);
googleMap.addMarker(googleMapMarker);
initializeViewContent();
}
A bit further down my class..
protected CssLayout initializeViewContent() {
CssLayout sideBarLayout = new CssLayout();
sideBarLayout.addStyleName("sidebar");
/* ... */
sideBarLayout.addComponent(googleMap);
return sideBarLayout;
}
There's more stuff around the class,but basically this is the "important" bit. When I load the page, I got this:
More or less, translated to english, it says "An error occured. This webpage did not load Google Maps correctly. Discover the technical details on the Javascript console."
EDITED: Firfeox Console is as empyt as my knowledge of this topic.
Chrome's console is telling me about a missing keyMapError.
I've tried changin the key format to:
{ourKey}
{ourKey}=initMap
key={ourKey}=initMap
And, well, I'm getting tired of playing with combinatory. The key works, as it was given to me with a small demo that works flawlessly.
What I'm doing wrong?

Related

How can I add a new Item to fabric?

I'm trying to code a mod, which adds a new Item to the game and I'm following a tutorial on youtube. I also looked everything up on the fabric website, but the code doesn't work.
Here is the code I used. It is from the fabric wiki:
public static final Item CUSTOM_ITEM = new Item(new FabricItemSettings().group(ItemGroup.MISC));
#Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("tutorial", "custom_item"), CUSTOM_ITEM);
}
Somehow in my library the .group() function doesn't exist and that's the same with other functions.
Do I have to download something or how can I fix this?
I tried adding a new Item to my mod, but it didn't work.

Initialize a Stripe Object in new Android Studio

Currently, I am working to create a Stripe payment method in an Android Studio App. This will involve a credit card object which will be stored by Stripe into my Firestore DB. Unfortunately, one of the lines in the tutorial that I have used is outdated since it uses getContext() without a view.
Background on Stripe:
https://www.youtube.com/watch?v=JeyxolsJ3aE
Background on Firestore:
https://firebase.google.com/docs/firestore
Here is the link to the tutorial that I am following:
https://stripe.com/docs/mobile/android
Unfortunately, I have not had much luck finding a tutorial that is knew, uses the same format and does not use getContext().
I have already completed all steps up to inserting the line:
final Stripe stripe = new Stripe(
getContext(),
"pk_test_TYooMQauvdEDq54NiTphI7jx"
);
In my version of Android Studio (3.4.1), it seems getContext() cannot be used without a View (shows up as red). As a result, I have tried to substitute a variety of commands. However, they all produce the same crash with message "Invalid Content Provider: null". I believe that "Content Provider" refers to the Context passed in.
I should mention that the Stripe object is created within an On-Click listener. Further, I know that the "pk_test" key is correct and I have tested other valid ids also to no avail. Further, through tests with commenting out code, I am certain that this is the line producing my error.
My theory is that the context is being rejected by Stripe or Firebase. This is because the Stripe Context is known as a "Stripe Provider" (https://lh3.googleusercontent.com/-ByYW3X0ua38/XQ_kRpmddLI/AAAAAAAAAAI/YfhjxSJ9iO0aJwZ8RtANeCXKXyYglWX1QCK8BGAs/s0/2019-06-23.png)
Some of the commands that I have tried are:
getContext() (not recognized)
getApplicationContext()
getBaseContext()
this
this.getApplicationContext()
ClassName.this.getApplicationContext()
ClassName.this.getBaseContext()
Submit.getContext()
WrappingLayoutView.getContext()
I have also tried to capture the Context in OnCreate above the OnClick listener in a variable.
Since none of these are working, I am rather stuck as to what to do.
Here is my Java Code:
public class AddCardActivity extends AppCompatActivity {
private Button submit;
public Context mContext;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_card);
init();
mContext = this.getApplicationContext();
//Not working
/**View mV=findViewById(R.id.myLView);
mContext=mV.getContext();**/
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Use stripe to add new payment to firestore
//This line causes a crash
Stripe stripe = new Stripe(submit.getContext(),
"pk_test_t6NMvJpXDEZd3eOn5SU4y6DA"
);
// The Card class will normalize the card number
final Card card = Card.create("4242-4242-4242-4242", 12, 2020, "123");
//Update this with more useful error messages
if (card == null) {
Toast.makeText(getApplicationContext(), "Invalid Card!", Toast.LENGTH_LONG).show();
}
card.validateNumber();
card.validateCVC();
stripe.createToken(
card,
new TokenCallback() {
public void onSuccess(#NonNull Token token) {
// Send token to your server
}
public void onError(#NonNull Exception error) {
// Show localized error message
Toast.makeText(getApplicationContext(), "Invalid Card!", Toast.LENGTH_LONG).show();
}
}
);
}
});
}
private void init() {
submit = (Button) findViewById(R.id.addCardActivityButton);
}
Here you go:
Token token = null;
final Card card = new Card(cardNumber, month, year, cvc);
final Stripe stripe = new Stripe(getApplicationContext());
try {
token = stripe.createTokenSynchronous(card, "pk_test_TYooMQauvdEDq54NiTphI7jx");
} catch (StripeException stripeEx) {
errorMessage = stripeEx.getLocalizedMessage();
}

How can I switch perspective programmatically after starting an E4 application?

Scenario
I have a pure E4 application in which I want to select the initial perspective for the user depending on the user's roles. I therefore have a perspective to start with which contains one part only. In that part, I use the #PostConstruct-Method to check the user's roles and afterwards trigger the command for switching perspective:
Initial View
#Inject
private IEclipseContext eclipseContext;
#PostConstruct
public void initialize() {
// checking credentials and retrieving roles come here which is pretty long
// that's why switching perspective is a seperate method
// and EclipseContext is injected to instance instead of method
this.switchPerspective(_usersInitialPerspectiveId)
}
private void switchPerspective(String pTargetPerspectiveId) {
final ECommandService _commandService = this.eclipseContext.get(ECommandService.class);
final EHandlerService _handlerService = this.eclipseContext.get(EHandlerService.class);
final Map<String, Object> _commandParameter = new HashMap<>();
_commandParameter.put(PluginIdConstants.ID_OF_PARAMETER_FOR_SWITCH_PERSPEKTIVE,
pZielPerspektiveId);
final ParameterizedCommand _switchPerspectiveCommand =
_commandService.createCommand(COMMAND_ID_FOR_SWITCH_PERSPECTIVE,
_commandParameter);
_handlerService.executeHandler(_switchPerspectiveCommand);
}
For switching perspective from here, I use the exact same handler as from menu items configured in Application.e4xmi, which looks like this:
Perspective Switch Handler
#Execute
public void execute(final MWindow pWindow,
final EPartService pPartService,
final EModelService pModelService,
#Named(PluginIdConstants.ID_OF_PARAMETER_FOR_SWITCH_PERSPEKTIVE)
final String pPerspectiveId) {
final List<MPerspective> _perspectives =
pModelService.findElements(pWindow, pPerspectiveId, MPerspective.class, null);
if (!(_perspectives.isEmpty())) {
// Show perspective for looked up id
pPartService.switchPerspective(_perspectives.get(0));
}
}
The Problem
The problem is pretty simple: When using the above handler triggered by a menu item, it works as intended and switches perspective. But using the same handler by my initial view (triggering it programmatically) does not switch perspective. I debugged the code to check if the handler gets identical information in both cases and it does.
Maybe my application has not finished starting and that's why the handler has no effect, but if this is the problem, how can I check this?
Any ideas on what I maybe missed are welcome!
Based on Christoph Keimel's hint I could create a working solution (thank you very much!). Here's the code that solves the problem:
#ProcessAdditions
private void switchPerspective(final MApplication pApplication,
final IApplicationContext pApplicationContext,
final EModelService pModelService) {
final MWindow _window =
(MWindow) pModelService.find(PluginIdConstants.WINDOW_ID_FOR_MAIN, pApplication);
final String _appName = pApplicationContext.getBrandingName();
initializeWindowTitle(_window, _appName);
final MPerspectiveStack pPerspectiveStack =
(MPerspectiveStack) pModelService.find(PluginIdConstants.PERSPECTIVE_STACK_ID_FOR_MAIN,
pAnwendung);
for (final MPerspective _perspective : pPerspectiveStack.getChildren()) {
if (_perspektive.getElementId().equalsIgnoreCase(this.startingPerspectiveId)) {
pPerspectiveStack.setSelectedElement(_perspective);
break;
}
}
}
On how to register a LifeCycleHandler you can take a look at Lars Vogel's Tutorial.
My main problem finding this solution was how to access the perspective stack. As the UI is not up while the method annotated with ProcessAdditions is running, I have to access the application model via the MApplication type - which is the root element of my application model. Combining the EModelService I can access all UI elements I want and manipulate them accordingly.
Injecting any UI element like the MPerspectiveStack or the MWindow leads to a skipped method as these result in null values due to not being initalized yet.

Migration to wicket 1.5 - resource (path) issue

I got the task to migrate to wicket 1.4 to wicket 1.5. Despite lack of information in migration guide I was somehow able to refactor most issues. Unfortunetly I'm stuck with "resource" - atm I'm getting this error
java.lang.IllegalArgumentException: Argument 'resource' may not be null.
What I understand by that is that something was change and wicket can no longer "get" to my resources. So I used to have (in wicket 1.4) that piece of code that was responsible for creating image and passing it (the method is in class that extends WebPage) :
private void addImageLogo() {
Resource res = new Resource() {
#Override
public IResourceStream getResourceStream() {
String logo = ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH);
return new FileResourceStream(new File(logo));
};
Image logo = new Image("logo", res);
add(logo);
}
Now Resource class no longer exists or I can't find it. While searching internet I was able to change it into this
private void addImageLogo() {
String logoTxt = ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH);
ResourceReference res = new ResourceReference(logoTxt) {
#Override
public IResource getResource() {
return null;
}
};
Image logo = new Image("logo", res);
add(logo);
}
This is responsible for obtaining path (and its working): ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH)
Unfortunetly I'm still getting this error that I mentioned above. The method getResource() generated automaticly and I believe this is an issue because I'm retuning null but I have no idea what (or how) should I return.
Since it worked with a IResourceStream in 1.4.x then you can just use org.apache.wicket.request.resource.ResourceStreamResource as a IResource for the Image.
Your first code snippet is not complete so I cannot give you exact replacement code.

how to retrieve info from datastore using google app engine and display it in a list view on an android app using java?

I am trying to make an android app that retrieves info from google app engine datastore and display it as a listview in the android app..can anyone help me out with some code or explain what exactly needs to be done for this purpose? i have already made modifications on the server side to store data on the datastore..what i dont know is how to get that data onto the android app..i am using eclipse indigo and language is java
EDIT : I am putting my code that i am using to retrieve a set of strings from datastore and put it in a list view...the code is gonna look all haywire but i request you to bear with me and explain how exactly to write it..presently the application is force-closing whenever i get to the page where this list of retrieved strings is supposed to be displayed...
public class Display extends ListActivity
{
private LayoutInflater mInflater;
private Vector<RowData> data;
RowData rd;
static String[] title;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displaylayout);
MyRequestFactory factory = (MyRequestFactory)Util.getRequestFactory(Display.this,MyRequestFactory.class);
FebfourthRequest febfourthRequest = factory.febfourthRequest();
final List<TrialDBProxy> list= new ArrayList<TrialDBProxy>();
febfourthRequest.queryTrialDBs().fire(new Receiver<List<TrialDBProxy>>()
{
#Override
public void onSuccess(List<TrialDBProxy> arg0) {
// TODO Auto-generated method stub
list.addAll(arg0);
}
});
for(int i=0;i<list.size();i++)
{
title[i] = list.get(i).getMessage();
}
mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
data = new Vector<RowData>();
for(int i=0;i<title.length;i++)
{
rd = new RowData(i,title[i]);
data.add(rd);
}
int[] to = new int[] { R.id.text1, R.id.text2 };
#SuppressWarnings("deprecation")
Cursor mCursor = this.getContentResolver().query(People.CONTENT_URI, null, null, null, null);
ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.displaylayout,mCursor,title,to);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
}
private class RowData
{
protected int mId;
protected String mTitle;
RowData(int id,String title)
{
mId=id;
mTitle = title;
}
#Override
public String toString()
{
return mId+" "+mTitle;
}
} '
NOTE : TrialDB is the file that contains all my fields that i want to store on the datastore.
displaylayout is the xml file where i have created a listview.
i am guessing the main part where i have to put code for displaying stuff is in the onCreate() method.
PLEASE HELP !
This is already a very good starting point for learning both Google App Engine and Android Development.
I may write the steps to follow:
Write a Google App Engine application which reads data from datastore and gives as JSON. You can use GAE web framework, or maybe Django. After doing that, you will have a url which gives you your data in your browser.
Write a hello world application for Android. This step gives you an opportunity to understand and setup Android development environment.
Write an Android app which uses a listview with static data.
Extend your Android app with calling a single simple url from web, then print it on your screen.
Extend your application via calling your Google App Engine application url inside your app. Now you have your datastore data in your app.
Populate your listview with your data.

Categories