I want to launch an contact-activity when a input-field (text) in a webview is pressed. Not sure how I can do this. Have tried to search the web but the only results I get is how to launch a filebrowser when a "input-file-field" is pressed.. And it seems like Android have an option that is exactly for that purpose, but not when another input-type is pressed?
What I actually want to do is;
when the input field is pressed, I want to give the user an option to launch the contact manager (or something similar) to choose one or more contacts from its contactlist.
Then fill the input-field with the contacts emails, separated with commas.
Is it possible to do this? Any idea what I should search the web for?
Solved! Added a new class:
import android.content.Context;
import android.content.Intent;
public class JSFromPage {
Context mContext;
JSFromPage(Context c) {
mContext = c;
}
public void openContact() {
Intent intent = (Intent) new Intent( mContext, ListContacts.class );
mContext.startActivity( intent );
}
}
And uses this is my WebView class:
mWebView.addJavascriptInterface(new JSFromPage(this), "Android");
And this is my html on the input:
onclick="Android.openContact();"
Then i created the class "ListContacts.class" with a new activity.
Related
I want to create a popup box (or similar) where the user will make some inputs that will be used during the application. For example selecting language or counrty.
Firstly can this be done in Processing 2+?
How do I go about this? Where do I start?
Sample code would be appriciated or a link to sample code if its available. I have not been able to find anything useful. (Maybe I have not looked in the right places.)
Here's a minimal test to pop up some import dialogs in setup() with the help of Swing, done in Processing 2.0.1. Notice that if you press Cancel in the popup, it will return a null which you need to account for.
import javax.swing.*;
int op1,op2;
void setup() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
String preset="2";
String op1s = JOptionPane.showInputDialog(frame, "Option 1", preset);
if(op1s != null) op1=Integer.parseInt(op1s);
String op2s = JOptionPane.showInputDialog(frame, "Option 2", preset);
if(op2s != null) op1=Integer.parseInt(op1s);
}
You could use the library controlP5 for that. There are several possibilities:
create a new window, where the user can adjust the settings – have a look at the example Conttibuted Libraries/ControlP5/extras/ControlP5frame
Create the input elements in your main sketch and hide them when a user hits the submit button: yourGuiElement.isVisible(false)
I'm using GWT 2.4 with JUnit 4.8.1. When writing my class that extends GWTTestCase, I want to simulate clicking on a button on the page. Currently, in my onModuleLoad method, this button is only a local field ...
public void onModuleLoad() {
final Button submitButton = Button.wrap(Document.get().getElementById(SUBMIT_BUTTON_ID));
...
// Add a handler to send the name to the server
GetHtmlHandler handler = new GetHtmlHandler();
submitButton.addClickHandler(handler);
How do I simulate clicking on this button from the GWTTestCase? Do I have to expose this button as a public member accessor is there a more elegant way to access it? Here is what I have in my test case so far ...
public class GetHtmlTest extends GWTTestCase {
// Entry point class of the GWT application being tested.
private Productplus_gwt productPlusModule;
#Override
public String getModuleName() {
return "com.myco.clearing.productplus.Productplus_gwt";
}
#Before
public void prepareTests() {
productPlusModule = new Productplus_gwt();
productPlusModule.onModuleLoad();
} // setUp
#Test
public void testSuccessEvent() {
// TODO: Simulate clicking on button
} // testSuccessEvent
}
Thanks, - Dave
It can be as easy as buttonElement.click() (or ButtonElement.as(buttonWidget.getElement()).click(), or ButtonElement.as(Document.get().getElementById(SUBMIT_BUTTON_ID)).click())
But remember that a GWTTestCase doesn't run in your own HTML host page, but an empty one, so you'll first have to insert your button within the page before simulating your module's load.
gwt-test-utils seems to be the perfect framework to answer your need. Instead of inheriting from GWTTestCase, extend the gwt-test-utils GwtTest class and implement your click test with the Browser class, like shown in the getting starting guide :
#Test
public void checkClickOnSendMoreThan4chars() {
// Arrange
Browser.fillText(app.nameField, "World");
// Act
Browser.click(app.sendButton);
// Assert
assertTrue(app.dialogBox.isShowing());
assertEquals("", app.errorLabel.getText());
assertEquals("Hello, World!", app.serverResponseLabel.getHTML());
assertEquals("Remote Procedure Call", app.dialogBox.getText());
}
If you want to keep your button private, you'd be able to retrieve it by introspection. But my advice is to make you view's widgets package protected and to write your unit test in the same package so it could access them. It's more convinent and refactoring-friendly.
gwt-test-utils provide introspection convinence. For example, to retrieve the "dialogBox" field which could have been private, you could have do this :
DialogBox dialogBox = GwtReflectionUtils.getPrivateFieldValue(app, "dialogBox");
But note that using GwtReflectionUtils is not mandatory. gwt-test-utils allows you to use ANY java classes in GWT client side tests, without restriction :)
You can do it like this:
YourComposite view = new YourComposite();
RootPanel.get().add(view);
view.getSubmitButton.getElement().<ButtonElement>cast().click();
I want to if it is possible to disable the auto-close MenuBar when I click on a MenuItem?
I have several MenuItem that are like checkboxes, so I can check more than one MenuItem and don't want my menu close everytime I checked one.
Thanks.
I was facing same problem and I will share with you my solution:
1) Create new class MyMenuItemWithCheckBox that extends the MenuItem.
In the constructor set element ID to (forexample) menuItemWIthCheckBox + Unique text.
this.getElement().setId("menuItemWithCheckBox_" + menuItemLabel);
2) Create new class MyMenuBar that extends the MenuBar.
Override the onBrowserEvent method by following:
Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && getSelectedItem().getElement().getId().contains("CheckBox")) {
Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
#Override
public void execute() {
getSelectedItem().getScheduledCommand().execute();
}
});
event.stopPropagation();
} else {
super.onBrowserEvent(event);
}
}
Now scheduled command of MenuItem is always called, but in the case of your
menu checkBox item there is no close of a menubar.
I hope this help you, I spend more than day to create this solution. :-)
First, directly it's not possible because the popup-panel which displays the submenu is private in the MenuBar class.
Buuut, there is a way to do so ...
Simpley fetch the current MenuBar.java code out of googles code repository and include it in your eclipse gwt-project.
You don't have to change anything e.g. package deklaration or something. Just put your source in your project and it will simply replace the original MenuBar-class from the gwt-sdk during compilation (works also with hosted development mode).
Then you can simply set the property autoHide of the popup-Panel to false and the popup shouldn't disappear after clicking.
You can set hideOnClick to false on the menuItems
See here.
I am using MenuBar control in gwt and want to get the selected item. I read the API document API document for MenuBar but could not find any method that could help me. Please tell me the way how can I trap the selected item of the MenuBar.I want to get the selected item when the user click on it.
The answer to your question is Command.
http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/user/client/Command.html.
When you add an item to the menubar (or to any of its children) you specify
Command helloCmd = new Command() {
public void execute() {
Window.alert("Hello");
}
};
addItem("Hello", helloCmd);
or
menuItem.setCommand(helloCmd);
You could also execute the command independent of any menu items:
helloCmd.execute();
I don't see why the method getSelectedItem() wouldn't work. Maybe it is because you want to have the item when the user clicks? Just create your MenuItems with a Command that asks the MenuBar which item is selected. Maybe it might even be better to use a separate command for some of your items.
Nico
I've the same problem and solved as follow:
public class CustomMenuBar extends MenuBar {
public CustomMenuBar(boolean isVertical) {
super(isVertical);
}
public MenuItem getSelected() {
return super.getSelectedItem();
}
public void clearSelected() {
super.selectItem(null);
}
}
and you can check it for null (if not null then clear it)
I have followed the tutorial for android tab host and been able to run on emulator. Now what I want to do is just implement a text box and button in one tabview. As soon as user enter in text box and press button the value entered in text box shouls pass to second tab and I can use that value for further calculations.
Please guide me how to do this?
Thanks,
Alok.
I think what you should to do is to declare a global variable:
class foobarApp extends Application {
private String txtValue;
public String getTxtValue(){
return txtValue;
}
public void setTxtValue(String aString){
txtValue= aString;
}
}
So, when the user presses the button:
foobarApp myApp = ((foobarApp)getApplicationContext());
setTxtValue(myTextEdit.getText());
And then, when the second tab loaded, you can get your value by doing this:
foobarApp myApp = ((foobarApp)getApplicationContext());
theOtherEditText.setText(myApp.getTxtValue());