solo.searchtext() deos not scroll expandable list - android

I am using robotium to test my app. Issue is with solo.searchText function. In my app I am using expandale listview to display category values. While testing using robotium I am cross checking whether all the categories are present. I am using the below code for that.
boolean ifCategoryLoadingFailed = false;
for(String cat: UnitTestHelperSuite.getInstance().categories){
if(solo.searchText(cat,1,true)){
//LogAdapter.verbose(TAG, "***********Found Category::"+ cat);
UnitTestingFramework.expdata.exportResult("****","Found Category::"+cat,"Success");
continue;
}
else{
ifCategoryLoadingFailed = true;
//LogAdapter.verbose(TAG, "***********Failed to Found Category::"+ cat);
UnitTestingFramework.expdata.exportResult("****","Found Category::"+cat,"Failed");
break;
}
}
It was working fine before. But now the list is not scrolling. So it is identifying only visible categories. But it is not entering the else condition.Testing is stopping here. How can I make it scrollable? please help me. I am stuck with this.

In my experience solo always scrolls down when searching for text. It does not scroll back up though. If your problem is caused by scrolling to the bottom while searching for one value, then the solution is to always call solo.scrollListToTop(listIndex) right before you call searchText() .

Related

JQuery Mobile swipe event only firing every other swipe

I have set up a swipeleft event in my app to move between fields of a form. All of the fields are dynamically generated, so I'm not swapping between pages, I'm clearing and re-generating all the DOM elements. The problem is the swipe event only fires every other time I swipe on the page or if I touch or tap anything on the page.
Here's the code that sets up the events:
$(document).delegate("#scorePage", "pageshow", function() {
$.event.special.swipe.scrollSupressionThreshold = 10;
$.event.special.swipe.horizontalDistanceThreshold = 30;
$.event.special.swipe.durationThreshold = 500;
$.event.special.swipe.verticalDistanceThreshold = 75;
$('#divFoo').on("swipeleft", swipeLeftHandler);
$('#divFoo').on("swiperight", swipeRightHandler);
tableCreate(traits[0].keyboardID);
});
For context, tableCreate is putting a dynamically generated table into divFoo that contains information a user can pick from. Here's the event code itself:
function swipeLeftHandler() {
$("#divFoo").empty();
traitIndex++;
tableCreate(traits[traitIndex].keyboardID);
}
Why is my swipe event only firing every other time there is a swipe on the page?
Primarily testing on Android right now, if that makes a difference.
Edit I'm using JQuery Mobile version 1.4.4
I figured out a way around this problem by simply rolling my own implementation of these events. There's some sample code on how to do something similar here:
https://snipt.net/blackdynamo/swipe-up-and-down-support-for-jquery-mobile/
If anyone else uses this code to fix my same problem, make sure to be aware that the article is implementing swipeup and swipedown so you will have to adapt it. In the end, I'm not entirely sure about the differences between this code and the actual implementations of swipeleft and swiperight, but this works consistently so I'm cutting my losses and going with it.

Moving between "pages" ( CCLayer ) in cocos2dx

I have 2 MyGameScreen objects that extends cocos2d::CCLayer. I am capturing the ccTouchesMove of the first screen so that I can create the moving effect exactly like sliding between pages of iOS application screen.
My class is like so:
class MyGameScreen: public cocos2d::CCLayer {
cocos2d::CCLayer* m_pNextScreen;
}
bool MyGameScreen::init() {
m_pNextScreen = MyOtherScreen::create();
}
void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event){
// it crashes here... on the setPosition... m_pNextScreen is valid pointer though I am not sure that MyOtherScreen::create() is all I need to do...
m_pNextScreen->setPosition( CCPointMake( (fMoveTo - (2*fScreenHalfWidth)), 0.0f ) );
}
EDIT: adding clear question
It crashed when I try to setPosition on m_pNextScreen...
I have no idea why it crashed as m_pNextScreen is a valid pointer and is properly initialized. Could anybody explain why?
EDIT: adding progress report
I remodelled the whole system and make a class CContainerLayer : public cocos2d::CCLayer that contains both MyGameScreen and MyOtherScreen side by side. However, this looked like not an efficient approach, as when it grows I may need to have more than 2 pages scrollable side by side, I'd prefer to load the next page only when it is needed rather than the entire CContainerLayer that contains all the upcoming pages whether the user will scroll there or not... Do you have any better idea or github open source sample that does this?
Thank you very much for your input!
Use paging enable scrollview.download files from following link and place in your cocos2d/extenision/gui/ after that you have to set property of scrollview to enablepaging true with paging view size.
https://github.com/shauket/paging-scrollview
For Scene Transitions you can do this:
void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event)
{
CCScene* MyOtherScene = CCTransitionFadeUp::create(0.2f, MyOtherScreen::scene());
CCDirector::sharedDirector()->replaceScene(MyOtherScene);
}

Chrome on Android: 'click' event doesn't work but 'touchstart' does, but interferes with swiping

I have this scrollable list of elements that aren't responding to the 'click' event on Chrome for Android. However, 'touchstart' does work. The problem is, using 'touchstart' interferes with the swiping behavior of the list. Is there an alternative to 'click' I could use?
Doesn't work:
jQuery(document).on('click', '.items section', function(e) {
// code
});
Does:
jQuery(document).on('touchstart', '.items section', function(e) {
// code
});
You might need to let us see the code that you are using before anyone can be of much help.
But your problem might be that touch start is bind to what ever the user does so you may need to unbind it.
Without seeing the code its hard to diagnose the problem.

jQuery.mobile popup immediately hides after showing

I have a small phonegap application with jquery mobile and backbone.
I'm trying to show popup to user by manually calling .popup() method.
Everything works fine on iOS but on android I got strange issue: popup is showing for few moments and than disappear.
Here the actual code:
var PostView = Backbone.View.extend({
events: {
'touchend .add-comment-button': 'addComment'
},
addComment: function() {
this.$(".comment-popup").popup('open', { history: false });
return false; // Stop bubbling.
}
});
I'm using history: false because this popup is actualy part of subpage.
The code looks very simple, I'm just can't understand why it can disappear, and why this happen only on android devices.
Thanks, and sorry for my bad english.
I spent hours trying to fix this problem.
Finally I ended up doing the following two things that seemed to fix the problem.
1 - Use the uncompressed jqm file. i.e jquery.mobile.1.2.0.js
2 - I was triggering the popup programatically using the 'tap' option - once changed to the 'click' option it worked.
$('.option').live('click', function() {
$('#popup-div').popup('open');
});
I spent hours trying to fix this problem.
Finally I ended up doing the following two things that seemed to fix the problem.
this code snippet may help you ->
$('#testBtn').on('tap',function(e){
console.log("button clicked");
e.preventDefault();
$('#testPOPUP').popup("open");
});
Please note i have used e.perventDefault().
I didn't feel like changing my .tap() events to the click event and I didn't have a case where I could use preventDefault()so I just added a timeout to the popup('open') line. My hoverdelay in jqm is set to 150 so I set this timeout to 600 just to be on the safe side. Works fine, doesn't feel sluggish for the user.
One way to 'fix' it is by setting data-history="false" on the popup div
See also this question
JQuery Mobile popup with history=false autocloses
I have the exact same problem when trying to use popup('open') on an android 2.3 device (both in native browser and in firefox) and it works just fine on browsers on other devices. I'm also using backbone event management to open my popup (used the tap event and no aditionnal options to popup).
What I did to 'correct' the problem is that I removed the backbone event management for this event and added a listener in the render function. In your case this would look something like this :
events: {
// 'touchend .add-comment-button': 'addComment'
},
render: function() {
$(this.el).html(this.template(this.model));
$(this.el).find('.add-comment-button').tap(function(el){
this.addComment(el);
return false;
}.bind(this));
}
I have no idea where the problem comes from (must be some incompatibility between backbone and jquery mobile) and why we only see it on android but for the moment with this workaround my app seems to work fine on any device.
Edit: oops, it turns out that in my case the problem was I was missing "return false;" in the function dealing with the event.
Now that I added it, it works correctly with the backbone event management.
Sadly that doesn't explain why you have the issue and why I was seeing it only on android.
In case it helps anyone, I had the same problem occurring with Bing Maps, with the Microsoft.Maps.Events.addHandler(pin, 'click', callback) method.
Not particularly nice, but instead I stored an ID in pushpin._id and did the following:
$("#page").on('vclick', function (event) {
if (event.target.parentElement.className === "MapPushpinBase") {
$("#stopPopup").popup('open');
}
});
One brute force option is to check whether popup was hidden and reopen it.
In a loop, because the exact time the popup becomes hidden seems to be varied.
var hidden = $('#' + id + '-popup') .hasClass ('ui-popup-hidden')
if (hidden) $('#' + id) .popup ('open')
A working example: http://jsfiddle.net/ArtemGr/hgbdv9s7/
Another option could be to bind to popupafterclose:
var reopener = function() {$('#' + id) .popup ('open')}
$('#' + id) .on ('popupafterclose', reopener)
$('#' + id) .popup ('open')
Like here: http://jsfiddle.net/ArtemGr/gmpczrdm/
But for some reason the popupafterclose binding fails to fire on iPhone 4 half of the time.

Android: code acts crazy

I have an extremely strange Problem, while trying to develop for android on eclipse
my program always returned non-sense statements, so I tried debugging it.
And Now I understand what the problem is....
...the code acts literally crazy - it's absolutely illogical
this is my code:
ArrayList<String[]> formatedVerses = readAndSplitDatabaseFile(database, books);
if (formatedVerses.size() < 1) { // check if readAndSplitDatabaseFile worked
createDatabase(database, false); // if not. the database wasnt initialized
formatedVerses = readAndSplitDatabaseFile(database, books); // try again
}
return formatedVerses;
basically I create this ArrayList
But when I debug, it doesnt just go trough the code from top to bottom, it makes weird illogical jumps
the debugger arrives at the line:
ArrayList<String[]> formatedVerses = readAndSplitDatabaseFile(database, books);
then jumps to the if-statement (so far so good)
if (formatedVerses.size() < 1) {
but "formatedVerses.size() < 1" is false, so it should jump over the if-block
but instead the debugger not only jumps INTO the if-block, but it actually jumps into THE SECOND LINE of the block:
formatedVerses = readAndSplitDatabaseFile(database, books);
which makes no sense whatsoever.
I feel like somebody is playing jokes on me.
I just cant wrap my mind around this.....
I've also tried restructuring the code...
but it only gets weirder.
I've also tried other implementations. for example like this:
if (formatedVerses.size() < 1) {
return array1;
} else{
doSomethingElse();
return array2;
}
in that case, it jumps into the true-statement of the if-block
return array1;
and then, when I click on next-step, it actually JUMPS from that line to the
return array2 line inside of the else-block, while completely leaving out the doSomethingElse()-line
anybody got any ideas?
because I'm going crazy right now...
Usually when I see behavior like this, it is because I am not running the code I think I am running. I have not done Android development, so I can't speak specifically to that, but do you have "build automatically" under the project menu checked? I have found that to reduce the number of times I see this behavior tremendously.
Have you tried cleaning the code and doing a complete rebuild? Are you running this out of Eclipse or on a remote device? If on a remote device, have you published the code to the device?
As I said, I haven't done any Android development, so some of these questions may seem obvious from an Andriod developing standpoint.
Hope those ideas help.
To me, it actually sounds like your braces are misaligned in some way. It appears to be ignoring the braces around the if statement, treating it like this.
if (formatedVerses.size() < 1) // check if readAndSplitDatabaseFile worked
createDatabase(database, false); // if not. the database wasnt initialized
formatedVerses = readAndSplitDatabaseFile(database, books); // try again
Doesn't really explain your second example though.
EDIT: Or maybe your second block is also parsing oddly.. doesn't explain why the code continues after a return statement though.
if (formatedVerses.size() < 1)
return array1;
else
doSomethingElse();
return array2;
just to elaborate on what aperkins said, which is all correct, the Eclipse debugger uses line number information from when your code was compiled into a .class file, and uses your source .java file to display what line of code is being run. So say you write this :
if (readAndSplitDatabaseFile(database, books).size() < 1) {
createDatabase(database, false); // if not. the database wasnt initialized
formatedVerses = readAndSplitDatabaseFile(database, books); // try again
}
return formatedVerses;
and you build and run, and then you add a line of code and a blank line:
ArrayList<String[]> formatedVerses = readAndSplitDatabaseFile(database, books);
if (formatedVerses.size() < 1) { // check if readAndSplitDatabaseFile worked
createDatabase(database, false); // if not. the database wasnt initialized
formatedVerses = readAndSplitDatabaseFile(database, books); // try again
}
return formatedVerses;
now when you are debugging, you are stepping through the first example, but looking at the second. The solution as aperkins mentioned is just to build and run again, or to undo your changes until they match up with what you had when you last compiled.
Okay, I figured it out.
Strangely it was something completely different.
I made some mistakes on the complete other side of my program. It had nothing to do with this code-segment (the problems weren't even in the same class.)
once that was fixed, it started to act normal again.
I don't understand it and at this point, I don't want to understand it.
Thanks for the help, everybody.

Categories

Resources