How does the API 24 AccessibilityService.dispatchGesture() method work? - android

With API 24 we got a way to dispatch a gesture to the device, however there is no solid documentation or examples out there yet. I am trying to get it to work but currently the gesture is hitting the "onCancelled" callback every time.
Here is my code that calls the method:
#TargetApi(24)
private void pressLocation(Point position){
GestureDescription.Builder builder = new GestureDescription.Builder();
Path p = new Path();
p.lineTo(position.x, position.y);
p.lineTo(position.x+10, position.y+10);
builder.addStroke(new GestureDescription.StrokeDescription(p, 10L, 200L));
GestureDescription gesture = builder.build();
boolean isDispatched = dispatchGesture(gesture, new GestureResultCallback() {
#Override
public void onCompleted(GestureDescription gestureDescription) {
super.onCompleted(gestureDescription);
}
#Override
public void onCancelled(GestureDescription gestureDescription) {
super.onCancelled(gestureDescription);
}
}, null);
Toast.makeText(FingerprintService.this, "Was it dispatched? " + isDispatched, Toast.LENGTH_SHORT).show();
}`
Has anyone used this new method yet or know of an example of how to get it functioning?

Your path is just lineTos, which doesn't specify a starting point. Try changing the first one to a moveTo.

Related

Appium: How to execute multiple test cases one after the other?

After running this,
App run.
TestMethod1() executed.
App closed.
TestMethod2() executed.
But I don't want the app to be closed (Step3). I want TestMethod2() to be executed after TestMethod1() is done:
App run.
TestMethod1() execute.
TestMethod2() execute.
App close.
--> I also tried with AddAdditionalCapability("NoReset, true") and AddAdditionalCapability("FullReset, False"), which didn't work.
=> I am using Appium.WebDriver(4.3.1) and C#.
[TestClass]
public class Walkthrough
{
private string _appPath = #"PathToMyApp\MyApp.apk";
private AppiumDriver<AndroidElement> _driver;
[TestInitialize]
public void Setup()
{
var appiumOption = new AppiumOptions();
appiumOption.AddAdditionalCapability(MobileCapabilityType.App, _appPath);
appiumOption.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
appiumOption.AddAdditionalCapability(MobileCapabilityType.DeviceName, "Pixel 4");
appiumOption.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "12");
appiumOption.AddAdditionalCapability(MobileCapabilityType.Udid, "99171FFAZ000GE");
appiumOption.AddAdditionalCapability(MobileCapabilityType.NoReset, true);
_driver= new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), appiumOption);
}
[TestCleanup]
public void TestCleanup()
{
_driver.CloseApp();
}
[TestMethod]
public void TestMethod1()
{
_driver.FindElement(By.ID("ELEMENT1")).Click();
}
[TestMethod]
public void TestMethod2()
{
_driver.FindElement(By.ID("ELEMENT2")).Click();
}
}
I finally solved the problem by adding [ClassInitialize] and TestContext in Setup method.
Make sure your method is "Static".
[ClassInitialize]
public static void Setup(TestContext testContext)
{
{
var appiumOption = new AppiumOptions();
appiumOption.AddAdditionalCapability(MobileCapabilityType.App, _appPath);
appiumOption.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
appiumOption.AddAdditionalCapability(MobileCapabilityType.DeviceName, "Pixel 4");
appiumOption.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "12");
appiumOption.AddAdditionalCapability(MobileCapabilityType.Udid, "99171FFAZ000GE");
appiumOption.AddAdditionalCapability(MobileCapabilityType.NoReset, true);
_driver= new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), appiumOption);
}
}

Using .getSpeedLimit() also makes warning sounds . How to Override?

Unable to override Here SDK to disable sound effect on the onSpeedExceeded event.
Using the Here Developer tutorial, (https://developer.here.com/blog/android-premium-sdk-speed-limit-warning-example), I succeeded in running the sample app. But...
While driving, when I exceed the speed limit, there is a doot doot doot. I want to override this behaviour as I intend to use my own sounds.
I guessed that I might override the code by creating a NavigationManager.SpeedWarningListener. Unfortunately I can not disable or defeat the 'onSpeedExceeded' sound effects.
NavigationManager.SpeedWarningListener speedWarningListener = new NavigationManager.SpeedWarningListener() {
#Override
public void onSpeedExceeded(String s, float v) {
//super.onSpeedExceeded(s, v);
//Log.v(Global.TAG, "onSpeedExceeded");
Global.SpeedLimitExceeded = true;
}
#Override
public void onSpeedExceededEnd(String s, float v) {
//super.onSpeedExceededEnd(s, v);
//Log.v(Global.TAG, "onSpeedExceededEnd");
Global.SpeedLimitExceeded = false;
}
};
EDITED ANSWER: This method needs to be amended to stop the speed warning:
private void startNavigationManager() {
NavigationManager.Error navError = NavigationManager.getInstance().startTracking();
// added by suggestion from stackoverflow
NavigationManager.getInstance().stopSpeedWarning();
if (navError != NavigationManager.Error.NONE) {
Log.d(Global.TAG, "NavigationManager: false");
//handle error navError.toString());
} else {
//Log.d(Global.TAG, "NavigationManager: true");
}
}
Please set speedWarningEnabled accordingly for NMANavigationManager
navigationManager:didUpdateSpeedingStatus:forCurrentSpeed:speedLimit: will be sent to the delegate when speeding is detected or when a correction is made.
Also refer http://developer.here.com/documentation/ios-premium/api_reference_jazzy/Classes/NMANavigationManager.html

TransferUtility Does not trigger onProgresschanged

I am working on a project where I want to upload files after developer authentication is complete. I am using AWS Cognito for authentication. Problem here is sometimes TransferUtility does not trigger onProgresschanged. Although it does not trigger onprogresschanged but the file is getting uploaded. I want to show a progressbar on the UI for every upload.It is working sometimes and sometimes it is not working.
Here is how I am uploading files.
public void upload() {
ClientConfiguration configuration = new ClientConfiguration();
configuration.setProtocol(Protocol.HTTP);
configuration.setSocketTimeout(5 * 10000);
configuration.setConnectionTimeout(5 * 10000);
configuration.setMaxErrorRetry(3);
if(sS3Client==null) {
sS3Client = new AmazonS3Client(credentials,configuration);
}
sTransferUtility = new TransferUtility(sS3Client,
this.ctx);
observer = sTransferUtility.upload("bucketer", "Filename", "file");
observer.setTransferListener(new UploadListener(progress));
}
private class UploadListener implements TransferListener {
ProgressBar progressBar;
public UploadListener(ProgressBar progress){
this.progressBar = progress;
}
#Override
public void onStateChanged(int i, TransferState transferState) {
Log.d("STATUS CHANGED:".concat(String.valueOf(i)),transferState.toString());
switch (transferState.toString())
{
case "IN_PROGRESS":
{
Log.d("IN_PROGRESS", "IN_PROGRESS");
}
break;
case "COMPLETED":
{
Log.d("COMPLETED COMPLETED", "COMPLETED");
}
break;
}
}
#Override
public void onProgressChanged(int i, long l, long l1) {
updator();
this.progressBar.setProgress(transferprogres);
}
#Override
public void onError(int i, Exception e) {
Log.d("UPOLADING ERROR:",String.valueOf(e));
}
}
public void updator(){
transferprogres = (int) ((double) observer.getBytesTransferred() * 100 / observer.getBytesTotal());
}
The code above is a part of total project. For more details comment.
Why is it showing weird performance?
See Aws S3 TransferService Upload failing without errors and https://github.com/aws/aws-sdk-android/issues/101. In short, v2.2.12 requires user to manage the life cycle of transfer listeners as transfer utility keeps only weak references of them. You can make the listener or the observer as class variable to prevent it from garbage collected. Anyway, we are tweaking the listeners in future releases. Sorry for the trouble and please stay tuned.

Gdx.input.justTouched() is not working on all devices

I am developing a game in LibGdx for android device. I could see a strange issue in using Gdx.input.justTouched(). It is working in some device and not in some device. Could you please help me if my code needs any correction?
#Override
public void create() {
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true);
}
public void render(SpriteBatch sb) {
if (Gdx.input.justTouched()){
System.out.println("inside : " );
dragNew = new Vector2(Gdx.input.getX(), Gdx.input.getY());
dragOld = dragNew;
}
}

ektorp couchDB to android replication

I am trying to synchronize my CouchDB with my android in a way that it works as good offline as online and as far as I understand the .continues(true/false) is the way to go for this. But is there some way to actually change it on runtime some way? I am thinking of having a BroadcastReciever listening to if there is any CONNECTIVITY_SERVICE and set the value of .continues() accordingly but I can't get it to work... any suggestions?
protected void startEktorp() {
httpClient = new TouchDBHttpClient(server);
dbInstance = new StdCouchDbInstance(httpClient);
HamsterSyncEktorpAsyncTask startupTask = new HamsterSyncEktorpAsyncTask() {
#Override
protected void doInBackground() {
// create a local database
dbConnector = dbInstance.createConnector(DATABASE_NAME, true);
}
#Override
protected void onSuccess() {
// Create the query and get the results
queryDB();
// Start doing the replications!
startReplications();
}
};
startupTask.execute();
}
public synchronized void queryDB() {
ViewQuery viewQuery = new ViewQuery()
.designDocId("_design/" + dDocName).viewName(viewName)
.reduce(false).includeDocs(true);
ViewResult viewResult = dbConnector.queryView(viewQuery);
Log.v("SUCCESS", viewResult.getRows().toString());
notifyHandlers(viewResult);
}
/**
* Replicates the database from server to the phone and vice versa.
*/
public void startReplications() {
// pull this database to the test replication server
pullCommand = new ReplicationCommand.Builder().source(DATABASE_PATH)
.target(DATABASE_NAME).continuous(true).build();
pushCommand = new ReplicationCommand.Builder().source(DATABASE_NAME)
.target(DATABASE_PATH).continuous(true).build();
HamsterSyncEktorpAsyncTask pushReplicaton = new HamsterSyncEktorpAsyncTask() {
#Override
protected void doInBackground() {
dbInstance.replicate(pullCommand);
ReplicationStatus status = dbInstance.replicate(pushCommand);
Log.e(TAG, status.getSessionId().toString());
}
};
pushReplicaton.execute();
}
I am also wondering if there are any way to know if and when the replication actually sent/got something new and update my listview in the app showing all the documents in my database (the queryDB() function)?

Categories

Resources