I've written an application with the following in the Program.cs:
rsCursor.Wait();
// Load the settings
rsAppConfig.LoadConfig("iVirtualDocket.exe.config");
fSplash splash = new fSplash(IvdConfig.VERSION);
splash.Initialise();
DialogResult result = splash.ShowDialog();
rsCursor.Go();
if (result == DialogResult.Yes)
{
IvdInstances.Main.Initialise();
Application.Run(IvdInstances.Main);
}
I use full screen on all my forms, so there is no X button, however I thought using Form.Close() performed the same function?
I want to be able to minimise my application from my main menu (Main) and then have it instantly appear again when the user re-runs the application. At the moment, my application executes the loading screen every time I re-run the application.
What am I doing wrong?
Thanks in advance.
EDIT: I need to be able to detect when my application is running and then restore the main menu when it is so that it's not constantly loading itself into memory.
Form.Close closes the Form. There is no Minimize - use Hide and Show.
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
ShowWindow(this.Handle, SW_MINIMIZED);
This did the trick, this.Hide() didn't work as it didn't maximise the window again when I re-ran the app.
Related
I have an issue with setting value of AutomationElement by using method ValuePattern.SetValue().
Everything works just fine until some dialog appears. When the dialog appears the code execution got stuck. No exception is thrown. After the dialog is confirmed, the code exection continues. Bellow is a sample of the code:
BasePattern basePattern = null;
ValuePattern valuePattern = null;
AutomationElement elementA = Window.GetElement(SearchCriteria.ByText(propertyName));
object patternObjectA = null;
elementA.TryGetCurrentPattern(ValuePattern.Pattern, out patternObjectA);
basePattern = (BasePattern)patternObjectA;
valuePattern = (ValuePattern)patternObjectA;
valuePattern.SetValue(optionToSet);
// Window.GetElement() is a method from TestStack.White framework
// The code execution got stuck on the last line until the dialog is confirmed
Is there any other way to set AutomationElement value?
Is somehow possible to avoid of getting stuck by dialog?
I'll by grateful for any help.
Thanks advance.
It could be that this dialog is not supporting UI Automation correctly or that you simply target the wrong element.
To verify that you may use Inspect.exe from Microsoft or similiar tools.
If it works, check if you really target the correct component with your code again.
If it does not work and:
if you are able to change the application
you can change the so called AutomationPeer of the UI component - here is a link for more infos
Or simply use another UI component that supports UI Automation correctly.
if you are not able to change the application, and also do not need to run in background, parallel, etc.. you might just focus the component (call setFocus() onto the AutomationElement, or expand it (via IsExpandCollapsePatternAvailable or simulated MouseClick onto the components coordinates)) and then use the SendKeys.SendWait("test") method.
EDIT: There is one more thing you should have a look at, and I wonder why I didn't mentioned it in the first place: Register to UI Automation Events
For example you could register a callback for the Structure change event type, and check if the dialog you talk about appeared.
If so --> click the confirmed button of the dialog.
Probably you will have to synchronize your execution, so that every further action in the UI Automation script waits until the registered callback got executed and the confirmed button got clicked.
For some reason, TestStake.White is not able to open an old windows application (which i can successfully run(win 7) by doubliclicking on the exe). I want to use an existing window to perform some action using White. I have no idea as to how to take control of an already opened window using White.
I tried to open the exe using batch command, but I still couldn't get any success. It shows me a yellow screen(app background) with no mouse control. Hence I want to launch the app manually and perform some automation actions on it.
If you know the text in the title bar of the window:
using TestStack.White;
public static class Demo
{
public static Window GetWindow(string windowTitle)
{
var window = Desktop.Instance.Windows().FirstOrDefault(x => x.Name == windowTitle);
}
}
I found an interesting bug that I can not replicate, but think someone here could provide some insight.
I have an activity that for now is partially native, partially web-based. By that I mean one element is simply a WebView until implementation on a native level can be achieved.
When I made a change in the page I am loading, I saw an immediate change using Chrome Developer Tools in a mobile interface. However, I was unable to immediately see the change in my WebView in my MainApp. As a test, I installed a new app that loaded the page in a WebView where I saw the changes. After clearing the data in my MainApp, I was able to see said changes.
I made a few more changes, but now these are being reflected immediately in my WebView (upon backing out of the activity and re-entering).
These are my WebView settings, can you see a reason for me not initially seeing these changes? I'm not very savvy (yet :) ) when dealing with how data is stored in a WebView and want to ensure that updates I make to my webpage are reflected immediately in the app. Thank you!
// Initialize WebView
if (Build.VERSION.SDK_INT >= 19)
mWebView.setWebContentsDebuggingEnabled(false);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// Hide ProgressBar
mProgressBar.setVisibility(View.GONE);
}
});
final ActionBarActivity activity = this;
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
mProgressBar.setProgress(progress);
}
});
// Settings for WebView data
WebSettings ws = mWebView.getSettings();
ws.setSaveFormData(false);
ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecated)
You probably need to disable the cache for your webview. When your data changes you need to reload the webview using mWebView.reload()
In case if you want to reload the the webview every time when you reopen.
use this setting for webview
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
This will not load the cache and the requirement will get fulfilled.
I'm starting a new activity to display a leaderboard in my Android App.
When the leaderboard activity is displayed, and the user presses the home key and then resumes the app (so the leaderboard activity comes up again), and then navigates back to the main activity by pressing the back key, the back key and volume keys stop working).
I've attempted to override onBackPressed in my activity class. I can confirm that when this problem occurs, onBackPressed is not called (When back / volume is working, pressing back does trigger onBackPressed).
Normally I get a message in LogCat when I press the back key 'Unimplemented WebView method onKeyDown called from android.webkit.WebView,onKeyDown(WebView.java.2178)' - Again I can confirm that this message doesn't come up when the back key isn't working
Armed with the above information, I can only assume that it's something to do with the View not having focus or something along those lines. I would point out that touch input on the screen itself does work. It just seems to be the back and volume keys/buttons that have no effect.
It's an openGL ES 2.0 app so in my onPause() I'm calling view.onPause(); and in onResume, I'm calling view.onResume();
I really have no idea what's going on and I've been on this for 3 days straight so if anyone can point me in the right direction, that would be great.
If the user comes out of the leaderboard and back into the main app before they press the home key, then everything is OK, it's just if the home key is pressed while the leaderboard activity is displayed as described above.
So when I'm at the point where the back / volume keys aren't working, if I click my scores button and fire up the leaderboard activity again, they work. On returning to my activity, they stop working again.
Not sure if this is relevant at all but the following shows how I'm starting my leaderboard activity:
if (scoresButtonPresses){
displayLeaderBoard();
}
void displayLeaderBoard(){
//Display the leaderboard if already signed in
if (checkSignedIn()){
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), leaderboardID), 1);
}
//if not already connected, then set flag and connect to play services before displaying leaderbaord
else{
signInAction=SHOW_LEADERBOARD;
getGameHelper().beginUserInitiatedSignIn();
}
}
#Override
public void onSignInSucceeded() {
//If the flag is set, then display the leaderboard
if (signInAction==DISPLAY_LEADERBOARD){
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), leaderboardID), 1);
}
//Otherwise, reset the flag and take no action
else {signInAction=NO_ACTION;}
}
This is driving me crazy so any help or even a nudge in the right direction would be very much appreciated!!
Edit
After much testing I have learned a couple of things:
If I remove the view.onPause() && view.onResume() the problem seems to go away. So this appears to be something to do with the way key events are captured by the view. Pausing and resuming seems to mess something up.
I have also tried removing the view.onPause() and view.onResume() as above, but instead, putting in View.setVisibility(View.GONE); and then making it visible again in public void onWindowFocusChanged(boolean hasFocus). Again, I get the same problem. Interestingly, when I open the leaderboard, as expected the view's staus is 'gone' then hitting the home key and running the app again, it's set back to 'visible' - I don't understand this behaviour but I'll ask another question for that.
Lastly, and this I find really odd. If I put my app back to as I had it, then after hitting the home key and relaunching the app via Eclipse (and I can do this multiple times) the problem doesn't seem to occur. So in that respect, it appears to be something to do with touching the screen.
Edit
It appears as though this isn't limited to my app. I've tested this on a couple of other apps from the Play store and get the same result.
One app clearly uses a single activity model like mine and the back and volume stop working throughout the app.
The other may use a different activity for it menu and game. When I test on this app, the back/volume breaks but if you start a game (therefore a second activity), the back key starts working again, even when you return to the first activity (recreated this activity?!)
So maybe I can get around this by ensuring the activity is recreated? I thought i was already but maybe I'm not getting something. Maybe it's something to do with the stack.........
I have no solution to your problem but some additional insights since I'm facing the same bug/problem with the leaderboards and the back button (and it's driving me crazy).
I'm using a single activity with fragments from which I login to Google Play, open Leaderboards and Achievements in the exact way you are doing it (startActivityForResult). Always when I come back from any Google Play Service activity my back button is broken. Sometimes it's even enough if I try to login to Google Play for it to break, meaning the login popup sometimes breaks the back button (but not always).
Some more insights which might help to solve the problem:
I'm not using OpenGL, so it's not related to this - I'm just using a single activity and fragments
It's also breaking for me when I just use the back button for going back from any Google Play Activity (I don't even need to go via the home key, just normal back is enough).
When the back button is broken the Activity is not receiving any Key Events (OnKeyDown, OnKeyUp, dispatchKeyEvent) are all not working, although using the activity and touching it fully works. My guess is that some view is catching the events...
Edit:
I also tried checking activity.getCurrentFocus() and activity.hasWindowFocus() as well as the parent and context classes of activity.getCurrentFocus() to see if there is any difference between when it's working and when it's not - and there isn't any difference...
Edit:
It seems that a simple call to View.requestFocus() is fixing the problem. For my single activity (using fragments implementation) I have now added:
#Override
public void onResume(){
super.onResume();
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
fragment.getView().requestFocus();
}
and this seems to be fixing the problem. Sill have to do long term checking if it's always fixed. In your OpenGL implementation I guess you will have to get the main view of the activity in some other way since you are not using fragments.
I know it's pretty old question, but for clarification: accepted answer is correct, but incomplete. Focus requesting should be done in onResume, onActivityResult, onSignInSucceeded and onSignInFailed. In first two you have! to call super. Some code:
private void requestFocusAfterGooglePlay(){
if(gimmeFocus==null)
return;
View currFocus=getCurrentFocus();
gimmeFocus.setFocusableInTouchMode(true);
gimmeFocus.setFocusable(true);
gimmeFocus.requestFocus();
gimmeFocus.setFocusableInTouchMode(false);
gimmeFocus.setFocusable(false);
if(currFocus!=null)
currFocus.requestFocus();
}
#Override
public void onSignInFailed() {
requestFocusAfterGooglePlay();
}
#Override
public void onSignInSucceeded() {
requestFocusAfterGooglePlay();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
requestFocusAfterGooglePlay();
super.onActivityResult(requestCode, resultCode, data);
}
#Override
public void onResume(){
super.onResume();
requestFocusAfterGooglePlay();
}
in my case gimmeFocus is a dummy View created as below:
<View
android:id="#+id/gimme_focus"
android:layout_width="0px"
android:layout_height="0px"
android:focusable="false"
android:focusableInTouchMode="false"/>
I have dynamic layout so I can't never be sure that any view exists in my layout, so I've created this dummy View, it might be also added programmatically. You might choose your fixed View for gaining focus, but rembember that changing focus might change view's look (drawable state).
In an eclipse RCP application, a splash.bmp is used as the splash screen. It closes after about 5-6 minutes of the application being run. I want it to close as soon as some UI displays. I tried using Platform.endSplash() and also applicationRunning() of the application context just before PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()).
It fails to close the splash screen.
Any suggestions would be helpful. It would also be okay if I could close the splash screen after about 10 -15 seconds.
public Object start(IApplicationContext arg0) throws Exception {
Display display = PlatformUI.createDisplay();
int returnCode = 0;
try {
//arg0.applicationRunning();
Platform.endSplash();
returnCode = PlatformUI.createAndRunWorkbench(display,
new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return PlatformUI.RETURN_RESTART;
}
return PlatformUI.RETURN_OK;
} finally {
//some other code here.
display.dispose();
}
}
I would expect the splash screen to close when everything is initialized, not after a set amount of seconds. Otherwise you don't even need one.
According to this thread, you should make sure to call the Platform.endSplash() method in the right context, meaning the method start(IApplicationContext context)
If you already do this, please provide some code to help us understand your problem
The closing of a splash screen is handled by the created StartupMonitor in Workbench.
After the workbench part is created (as you say, "as soon as some UI displays"), it will be cycling through all registered startup services. The fact that you have your workbench visible and have to wait ~5-6 minutes (or seconds) for your splash screen to close means you have another startup monitor preventing your desired UI transition.