I have this.setVolumeControlStream(AudioManager.STREAM_MUSIC); at the start of all activities in my application so when the user presses the volume up or down buttons, he controls the media volume.
I have a popup window in my program and when that appears the user can no longer control the volume.
Looking at similar questions it seems that setting up onKeyup/down listeners can interfere with the process - but I have not set any up - the only listeners I have for the popup window are setOnClickListeners for the buttons and a setOnDismissListener for the window.
How can I fix this?
Looks like you have to call setOwnerActivity on the Dialog object.
Documentation from the method:
Sets the Activity that owns this dialog. An example use: This Dialog will use the suggested volume control stream of the Activity.
While not tested, this should do the trick. There is also the possibility to use setVolumeControlStream.
I had been creating the popup window with
my_popup_window = new PopupWindow(layout, x, y, true);
I then change it to this...
my_popup_window = new PopupWindow(layout);
my_popup_window.setWidth(x);
my_popup_window.setHeight(y);
and the volume control started to work again. I don't understand why - but it worked.
I just do this pop.setFocusable(false). and it worked.
though the Mick's answer didn't work for me, this is for posterity.
//Declaration
PopupWindow mWindow;
...
//Constructor
mWindow = new PopupWindow(context);
...
//Prepare to Show
mWindow.setContentView();
mWindow.setBackgroundDrawable();
mWindow.setFocusable(false);
...
setting setFocusable to false helped my activity capture onKeyDown() again.
Related
I can't see my Vaadin Dialog which I'm trying to add on a simple Vertical Layout
Here is my code:
Dialog d = new Dialog(new Label("Simple label"));
d.setCloseOnEsc(false);
d.setCloseOnOutsideClick(false);
Button cancelBtn = new Button("Cancel", event -> {
d.close();
});
d.add(cancelBtn);
add(d);
I hope anyone can help me :)
Dialog::open
A Dialog is a specific component - it is not normally rendered within the given container, but opens as a popup. Therefore, it has special semantics to make it to render - after creating a dialog, you have to call dialog.open() to make it display.
This is also not specific to Vaadin - in many frameworks, dialogs (and other popups) are displayed in a special manner - it's somewhat of a pattern.
I have a WebView.
When loading stuff that takes a long time, I want the WebView to be overlaid with a loading dialog that looks like the progress dialog in phones - the one with the circular spinning thing, and darken the screen area that is not covered by the dialog.
Additionally, I want to make it impossible for the user to click on anything on the WebView until it is ready.
How do I achieve this effect in Java 8?
when you need the loading call this
private void inUrFace(){
Dialog<Void> dialog = new Dialog<>();
dialog.initModality(Modality.WINDOW_MODAL);
dialog.initOwner(stage);//stage here is the stage of your webview
dialog.initStyle(StageStyle.TRANSPARENT);
Label loader = new Label("LOADING");
loader.setContentDisplay(ContentDisplay.DOWN);
loader.setGraphic(new ProgressIndicator());
dialog.getDialogPane().setGraphic(loader);
DropShadow ds = new DropShadow();
ds.setOffsetX(1.3); ds.setOffsetY(1.3); ds.setColor(Color.DARKGRAY);
dialog.getDialogPane().setEffect(ds);
dialog.showAndWait();}
double check the code. should give you something of that sort.
I'm new to robotium and i'm trying to write a quick and dirty script to run through all screens in an app.
The problem i have mainly with the 'home button' in the app. I've tried lots of options but i cant seem to get it to click there except with index, which is not what i want.
When i check out the button with the hierarchyviewer it looks like this:
Link
However when i try for example:
assertTrue(
"Wait for text (id: myapp.R.id.home) failed.",
solo.waitForImageById("myapp.R.id.home", 20000));
solo.clickOnImage((ImageView) solo.findViewById("myapp.R.id.home"));
solo.waitForActivity("MenuActivity");
It fails at the waitForImageByID line. Ive tried multiple options like waitForImageButton etc, but i just cant seem to get it clicked. What am i missing here?
junit.framework.AssertionFailedError: View with id: '0' is not found!
at com.jayway.android.robotium.solo.Solo.getView(Solo.java:1990)
at com.jayway.android.robotium.solo.Solo.getView(Solo.java:1970)
at com.bitbar.recorder.extensions.OtherUtils.a(OtherUtils.java:246)
at com.bitbar.recorder.extensions.OtherUtils.b(OtherUtils.java:241)
at com.bitbar.recorder.extensions.v.a(Waiter.java:71)
at com.bitbar.recorder.extensions.ExtSolo.waitForImageButtonById(ExtSolo.java:4176)
at com.example.android.apis.test.Test.testRecorded(Test.java:137)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1740)
Use the following line to press the home button in the action bar
solo.clickOnActionBarHomeButton();
The issue is that the id that it is referring is not in your application, it is in androids default R file, try android.R.id.home and it should work fine. It is worth noting though that if your application uses action bar sherlock to support the action bar pre 4.0 that this will have a different ID there and you will have to handle this in your test.
You can see this for yourself looking at: http://developer.android.com/reference/android/R.id.html
When you are using ActionBarSherlock there are two different Ids you have to check, android.R.id.home for API-Level>11 and abs__home for lower levels (provided by ActionBarSherlock):
View homeButton = activity.findViewById(android.R.id.home);
if (homeButton == null) {
homeButton = activity.findViewById(R.id.abs__home);
}
What about this code:
ArrayList<LinearLayout> ll = solo.getCurrentViews(LinearLayout.class);
//You can change 1 with the ordinal number of LinearLayout you want to click.
solo.clickOnView(ll.get(1));
or also
ArrayList<ImageView> iv = solo.getCurrentViews(ImageView.class);
//You can change 0 with the ordinal number of Image you want to click.
solo.clickOnView(iv.get(0));
I think if you identify the correct id for view or linear layout or image view it should work.
Dave C's answer was working only partially for me. The button was clicked but before the preceding screen was loaded assertions had started and thus were always false. The solution is to run "home click" on the main thread (Robotium 5.2.1):
getInstrumentation().runOnMainSync(new Runnable() {
#Override
public void run() {
solo.clickOnActionBarHomeButton();
}
});
From your question I can see that it is an image view. You can click on any view using the following piece of code.
View view = solo.getView("View_name_from_hierachy_viewer");
solo.clickOnView(view);
View_name_from_hierachy_viewer in your case will be "home".
Let me know if this does not work.
I can see how to instantiate a second MVC group, e.g.
def (loginPaneModel, loginPaneView, loginPaneController) =
createMVCGroup('LoginPane', 'LoginPane', [:]);
view.loginPanel = loginPaneView.loginPanel
But I don't want to show as part of my main window. I want it to pop up over it. What do I call to do that? Thanks!
The easiest way would be to use the view panel as the root of a dialog in the parent MVC group. In the view for the group that yor code snippet is the controller of you could do something like this...
application(title:'your app', ....) {
// your existing code...
loginDialog = dialog(title:'Login Panel', visible:false) {
panel(loginPanel)
}
}
And then when you need to show the dialog (in the same controller)
view.loginDialog.visible = true
Nesting a dialog inside of another window has the side effect of setting the dialog's owner to the frame or dialog of the parent. Having a dialog owned by another dialog/window is what causes the dialog to be linked with the parent and always float on top of that parent. It will also raise/lower with the parent as well.
Well, it seems that only the first line is needed. That was enough to pop up a window. I believe the key, though, was to make the view a frame.
def frame = frame(title:'Login', pack:true, locationByPlatform:true) {
...
}
frame.pack()
frame.show()
I'm developing a SWT/JFace application using the libraries from Eclipse 3.4.1.
I encounter the following problem on Windows (Vista 32bit) and Ubuntu 8.10 32bit:
I create a menu bar in the createMenuManager method of the JFace ApplicationWindow. I add MenuManagers for file, edit and help.
I then add an ExitAction to the file MenuManager like so:
filemenu.add(new ExitAction(this));
The ExitAction is defined this way:
public class ExitAction extends Action {
final ApplicationWindow window;
public ExitAction(ApplicationWindow w) {
this.window = w;
setText("E&xit");
setToolTipText("Exit the application");
setAccelerator(SWT.MOD1 + 'Q');
}
}
Now when my application starts I want be able to press "CTRL+Q" to quit the application. This does however not work. Only AFTER I click on "File" in the menu bar and THEN clicking "CTRL+Q" the application will quit.
I've tried this with different accelerators- same behavior.
It does work however if I create a "MenuItem" instead of an "Action" to contribute to the menu bar.
Is this a SWT bug or do I miss something?
Torsten.
Update: There is a duplicate bug of mine which also contains a workaround.
The bug url is: https://bugs.eclipse.org/bugs/show_bug.cgi?id=243758
Basically the workaround is to call create() on the ApplicationWindow and then getMenuBarManager().updateAll(true); which will force all menu items to get initialized.
Of course you have to call the above methods after you created the menu items.
AFAIK setAccelerator(.) does nothing else than adding the appropriate text to your MenuItem. You are responsible to register for an KeyUp event and react on it.
You can use Display.addFilter(SWT.KeyUp, myListener) to register your Listener independently of your widgets.
Turns out that this is a bug in Eclipse 3.4.
I have submitted a bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=253078