How to assert keyboard is closed? - cucumber

I want to check my mobile keyboard is closed with an assertion.
public void keyboardIsClosed() {
boolean isKeyboardShown = driver.isKeyboardShown();
Assert.assertFalse("Keyboard is opened.",isKeyboardShown());
}
It doesn't accept last isKeyboardShown()in the code? How should i write?
I want to test whether or not the soft keyboard is shown with java

Also
public void keyboardIsClosed() {
Boolean isKeyboardShown;
isKeyboardShown = driver.isKeyboardShown();
Assert.assertFalse("Keyboard is opened.",isKeyboardShown==true);
}
works🚀

Related

32Feet.NET. How to pair PC with a device?

I write an application for Windows Form. I have a problem with pairing a device with PC. Now the program works next way: switch on the divece, start the program, add divece to Bluetooth device, push connect button. I use the next functions:
public BluetoothClient client = new BluetoothClient();
public string selectedItem { get; set; }
public BluetoothDeviceInfo[] AllDevices;
public void GetDevices()
{
AllDevices = client.DiscoverDevicesInRange();
foreach (BluetoothDeviceInfo Device in AllDevices)
{
if(Device.DeviceName.Contains("Kortes"))
onSetDevices(Device.DeviceName); // event to get device name and add it to ComoBox element on form
}
onSetProgress(); // event, that all devices were found, set progress bar and etc.
}
public void GoConnect()
{
foreach (BluetoothDeviceInfo Device in AllDevices)
{
if (Device.DeviceName.Equals(selectedItem)) // item from ComboBox
{
if (!client.Connected)
client = new BluetoothClient();
client.BeginConnect(Device.DeviceAddress, Device.InstalledServices[0], this.BluetoothClientConnectCallback, client);
break;
}
else
{
MessageBox.Show("Choose the device");
}
}
}
private void BluetoothClientConnectCallback(IAsyncResult ar)
{
//Have no problem with this
}
These functions work very well. I can find and connect with needed device. But the problem is that firstly I need to add my device to Bluetooth device in OS and enter PIN code. How can I improve my code to solve this problem?
I don't want to add device. I want to work with it directly. Which methods can I use to enter PIN code programmatically? The program must work the next way: switch on the device, start the program, and push connect button.
You are trying to connect without pairing.Your code is not working because you have to pair before connecting.
replace
client = new BluetoothClient();
client.BeginConnect(Device.DeviceAddress, Device.InstalledServices[0], this.BluetoothClientConnectCallback, client);
by
BluetoothSecurity.PairRequest(Device.DeviceAddress,"123456");
Check out http://mrbikash.com/bluetooth-discovery-pairing-32feet-net/#pairing for a more detailed explanation.

Android: "Application level" Pause and Resume [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I've been trying to get Application Level Pause and Resume similar to an activity's onPause and onResume. I know there's no API that has this functionality.
I try to follow this post: http://curioustechizen.blogspot.com/2012/12/android-application-level-pause-and.html
But I've had no luck so far.
Has anyone been able to achieve this? What paradigm did you use?
Let me know if you need me to paste some code into this question.
Thanks for the help
Another solution to the problem would be to just keep track of the count of onStart() and onStop() calls from every activity. Example:
First, create a class to hold the counts:
public class ActiveActivitiesTracker {
private static int sActiveActivities = 0;
public static void activityStarted()
{
if( sActiveActivities == 0 )
{
// TODO: Here is presumably "application level" resume
}
sActiveActivities++;
}
public static void activityStopped()
{
sActiveActivities--;
if( sActiveActivities == 0 )
{
// TODO: Here is presumably "application level" pause
}
}
}
Then in every activity, simply call the activityStarted() and activityStopped() methods:
#Override
public void onStart() {
super.onStart();
ActiveActivitiesTracker.activityStarted();
}
#Override
public void onStop() {
super.onStop();
ActiveActivitiesTracker.activityStopped();
}
I had the same problem. My aim was to lock the App, if the user abandons it. A simple aim, which i thought would be easy to implement. But all the solutions I found were way to complex. So I came to a simple solution: A time based lock.
Basically it works like this:
Start countdown to lock app in onPause
Stop countdown in onResume
If onResume is not called in time, change to locked
Therefor I created a small little class:
public class ApplicationLock {
private static final String TAG = ApplicationLock.class.getSimpleName();
private static final int LOCK_TIME = 1000; //lock after a second
private static boolean lock = true; //default is locked
private static Handler handler = new Handler();
private static Runnable runnable = new Runnable() {
#Override
public void run() {
lock = true;
Log.i("ActivityTracker", "App locked");
}
};
public static boolean activityStarted()
{
handler.removeCallbacks(runnable);
if(lock)
{
Log.i(TAG, "App resumed - LOCKED");
return true;
}else{
Log.i(TAG, "App resumed - NOT LOCKED");
return false;
}
}
public static void activityStopped()
{
handler.postDelayed(runnable, LOCK_TIME);
Log.i(TAG, "App paused - Starting countdown");
}
Just call activityStopped() in your activities onPause() and activityStarted() in onResume(). Check the result of activityStarted(). If it returns true, lock your app. If the orientation of the app is changed, onResume will be called very quickly after onPause, so the app will not lock.
This solution might not fit every scenario, but in my case it was the best solution. Additionally you can change the countdown, to increase the user experience (The user pressed a wrong button and returns to the app in a few seconds, no need to lock the app). Hope this is useful to someone else.
I have done something very similar to this in an app which used a service that provided GPS functions by several activities. The idea was to only have the service there when one of the activities that used it is visible, and not there when none are visible. In your case, every activity would hook into a service, and you will know when the entire application was paused or resumed by hooking into the service's onCreate() and onDestroy() methods.
Here is a stripped-down example:
Components needed (these could probably be placed into a utility class if you want to reuse them, or I just had them for each activity class):
private boolean mAppActiveServiceBound = false;
private AppActiveService mAppActiveService = null;
private ServiceConnection mAppActiveConnection = new ServiceConnection() {
public void onServiceConnected( ComponentName className, IBinder service ) {
mAppActiveService = ( (AppActiveService.AppActiveBinder) service ).getService();
}
public void onServiceDisconnected( ComponentName className ) {
mAppActiveService = null;
}
};
Then in your onStart() and onStop() methods for each activity:
#Override
public void onStart() {
super.onStart();
mAppActiveServiceBound = bindService( new Intent( this, AppActiveService.class ), mAppActiveConnection, Context.BIND_AUTO_CREATE );
}
#Override
public void onStop() {
super.onStop();
if( mAppActiveServiceBound ) {
unbindService( mAppActiveConnection );
mAppActiveServiceBound = false;
}
}
And finally, the service itself:
public class AppActiveService extends Service {
// Receives interactions from clients:
private final IBinder mBinder = new AppActiveBinder();
/**
* Provides a handle to the bound service.
*/
public class AppActiveBinder extends Binder {
AppActiveService getService() {
return AppActiveService.this;
}
}
#Override
public void onCreate(){
// TODO: Here is presumably "application level" resume
}
#Override
public void onDestroy(){
// TODO: Here is presumably "application level" pause
}
}

ObservableList#contains() returns false for existing item

I try to use the OberservableLists contains function to check if the given element is already in the List and if not add it.
My Code looks like:
ObservableList<Device> devicesScannerList = FXCollections.observableArrayList()
deviceScannerList.add((Device)dev);
Later on i do
Device dev = (Device)devices.get(0);
boolean deviceExists = devicesScannerList.contains(dev);
if (deviceExists){....}
The problem is that deviceExists is always false but i can see in debug mode that devicesScannerList already contains the given device and i don`t want to add it again.
Do i missunderstand the contains function?
Help would be great
Thx
Ingo
Make sure your Device class implements equals and hashCode methods correctly.
E.g. if you create 2 Device objects with exactly same data they will not be considered the same by ObservableArrayList (or any List) unless Device have equals/hashCode implemented.
See next example:
public class ObsListTest {
static class Device {
int value;
public Device(int value) {
this.value = value;
}
}
public static void main(String[] args) {
ObservableList<Device> list = FXCollections.<Device>observableArrayList();
Device data1 = new Device(1);
Device anotherData1 = new Device(1);
list.add(data1);
System.out.println(list.contains(data1)); // true
System.out.println(list.contains(anotherData1)); // false
}
}
But this code will work (prints true both times) if you add next to Device:
#Override
public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
return this.value == ((Device) obj).value;
}
#Override
public int hashCode() {
return 7 + 5*value; // 5 and 7 are random prime numbers
}
See more details here: What issues should be considered when overriding equals and hashCode in Java?

How can I develop a custom "non-fullscreen" softkeyboard for tablets?

I have the sample of softkeyboard. When I install it on a android 2.x, it has the following non-fullscreen view:
But when I install it on tablet 10in it gets whole of the screen like this:
How can I change the sample to have a non-fullscreen custom keyboard on tablet pcs like this image (default keyboard of tablet)?
The following code in InputMethodService solved my problem:
#Override
public boolean onEvaluateFullscreenMode() {
return false;
}
overide the following two methods from InputmethodService as bellow, this works always
#Override
public void onUpdateExtractingVisibility(EditorInfo ei) {
// TODO Auto-generated method stub
setExtractViewShown(false);
}
#Override
public boolean onEvaluateFullscreenMode() {
return false;
}
This worked for me :) and if you want to show keyboard in fullscreen mode always then change both false to true.

How to access the Keyboard in an Eclipse RCP / LWJGL app?

I am working my way through the NeHe OpenGL examples, using the LWJGL for the OpenGL binding inside an Eclipse RCP application.
My OpenGL graphics are displayed inside the RCP canvas, not in a separate window.
Lesson 07 shows how to use the keyboard. If I try to do a:
Keyboard.create();
I get an error that the (OpenGL) "Display" has not been created.
If I create an OpenGL "Display" with org.lwjgl.opengl.Display.create(), then I get a new Window.
So how do I access the Keyboard without creating a new Window?
You cannot use the Keyboard without a Display, because of how LWJGL works behind the scenes. The best way is to just use AWT events. You can write your own input class, that could go something like this.
public class Input implements KeyListener {
private boolean aDown; //is the A key down?
//Ect, for all needed keys
public void keyPressed(KeyEvent ke) {
switch (ke.getKeyCode()) {
case KeyEvent.VK_A: aDown = true; break;
//and so on for all other needed keys.
}
}
public void keyReleased(KeyEvent ke) {
switch (ke.getKeyCode()) {
case KeyEvent.VK_A: aDown = false; break;
//and so on for all other needed keys.
}
}
public void keyTyped(KeyEvent ke) {} //Do nothing
public void isADown() {return aDown;}
}

Resources