Cannot scroll in upward direction - android

I am using
action = TouchAction(self.driver)
action.press(self.element).perform()
height = self.element.size["height"]
action.move_to(x=0, y=height*int(height_multiplier)).perform()
to scroll in android.But if i give height_multiplier as 1 or 2 it works fine.Scroll downward too.But when i give it -1 or -2 expecting it too go upwards it gives an error
The coordinates provided to an interactions operation are invalid.
I have already tried scroll(element1,element2) but it doesnt scroll ,just flicks to end.also driver.execute doesnt work as well as mobile:scroll is not yet implemented for android.Does anybody know a workaround?Partial scroll is what i want precisely

I have implemented scrolling up as follows: driver.swipe(0, scrollStart, 0, scrollEnd, 2000) where scrollStart < scrollEnd. Both values still must be positive to fit in the resolution range.

Related

cannot figure out how withIconOffset works

I have been messing with withIconOffset to move center of anchor to exactly bottom of the icon.
It says "Positive values indicate right and down, while negative values indicate left and up", what does it mean? passing some values does move my marker around but cannot postion it correctly.
Also tried to divide my png icon height in half and move it up by that amount but it goes too far up.
.withIconOffset(arrayOf(0f, -image.height/2f))
Im using .withIconSize(2f) too, will it have any effect on offsets?
my bad, forgot to convert image height to dp.
something like this works fine
val Int.dp: Int
get() = (this / Resources.getSystem().displayMetrics.density).toInt()
//...
.withIconOffset(arrayOf(0f, -image.height.dp/2f))`
edit:
I also found another way .withIconAnchor(Property.ICON_ANCHOR_BOTTOM)

Android bottomsheet - How i can set onSlide offset to 1 when card state is half_expanded?

i have set my bottomsheet ot be half expanded using the folloiwng code:
bottomSheetBehavior?.isFitToContents = false
bottomSheetBehavior?.halfExpandedRatio = 0.6f
and it works fine. The issue is I have some content that changes alpha property as the card slides to halfway point. At the halfway expanded point, the alpha of the content should be 1. it works great without using isFitToContents = false, but when I do use it to half expand the card the slideOffset does not end at 1, for example, it ends at .019 because I just moved up a little bit to reach halfway expanded.
Therefore to my issue: How to make the half_expanded state slideOffSet end at 1 ?
another approach: if I could know the very last half expanded offset value then I can use that ahead of time as a scale factor. let's say that value was called halfExpandedOffSetEnd. then I could create a scale factor like this:
val multiplier = 1/halfExpandedOffSetEnd
I could then multiply that by all my offsets to get the desired effect. but how would i get the very last offset value for half expanded ahead of time?

Unable to scroll in android with appium using python

I tried this piece of code:
scrollObject = dict(direction="down", text="some_text", element=appium_driver_elem.id)
self.driver.execute_script("mobile: scrollTo", scrollObject)
But I am getting an error saying:
"appium_driver_elem does not have attribute like id" or sometimes nosuchelementexception.
What is the simplest way to scroll with appium in android using python? Any full test examples?
self.driver.swipe(470, 1400, 470, x, 400)
self.driver.swipe(start_x, start_y, end_x, end_y, duration)
start_y value represents bottom Y value & end_y value represents top Y value of the screen in your app.
Since to scroll we hold screen at bottom & move up.
value of x depends on how much you wish to scroll in one shot.
Example: To scroll to the bottom, try 300. To scroll little x can be 1200
Still haven't found an answer. So maybe you need to play a little bit rough.
You can use the self.driver.scroll(self,SrcElem,DestElem) function to swipe screen from bottom to top and check the element you seek.
Or You can also try to do
from appium.webdriver.common.touch_action import TouchAction
...
action = TouchAction(self.driver)
action.press(start_element).move_to(end_element).release().perform()
Actually, that's how scroll() function works. Once, I had an issue with self.driver.scroll(), so this can also be a workaround.

jump to some line of EditText or TextView with multiline

I have a multi-line EditText/TextView, say 1000 line.
The contents can't be shown on one page, actually there will automatically be a vertical scroll bar.
I want to make a button that can jump to line 500, and the result view start from exactly at line 500.
Anybody know how to achieve this?
You should be able to calculate the scroll in the Y direction using TextView.getLineHeight(), TextView.getLineCount() and TextView.getHeight().From there you can call TextView.scrollTo(0, calculatedY).I'm assuming you always want to have the left side of the view visible. Of course, if your lines were longer than the current View could display, you could similarly calculate an X scroll position also.

Synchronous scrolling of a partial ListView Header

This question is very specific, What I am trying to do (with a list view) is described in great detail in the following article: http://www.pushing-pixels.org/2011/07/18/android-tips-and-tricks-synchronized-scrolling.html
Thanks #kaushal trivedi for the link
Details:
I have an android application I am working on that uses a list view with a custom adapter. The Listview Contains a Custom header of a non-fixed height. Also please note that the list items are also of variable height. My goal is to mimic the effect produced in the latest gmail app (as an example) where when you are viewing an email, and scroll past the header, it sticks to the top of the screen just under the action bar and the content continues to scroll under it. What I would like to do, is stick the bottom half of my header to the top of the screen.
My initial reasoning was to create an invisible view fixed in the desired location, and when the user scrolled to or past that location, make the view visible. The issue in this logic, is I need the exact pixel scroll height, which after many attempts I have determined very difficult to do. The exact issue I ran into is, it is not possible from what I can gather to retrieve the pixel level Y-scroll in an onScroll event, I have only been able to retrieve the value in the onScrollStateChanged event. Which as described above will not achieve the desired functionality.
Working with the onScroll event "int firstVisibleItem, int visibleItemCount, int totalItemCount" parameters is also not an option because of the fact that the content I want to "stick" is not the size of a list item, but a fraction of the size of the variable height header.
Is there a correct way to accomplish this effect? My current minSDK level is 10.
Update 10/10/13
I made some progress. The following code syncs the Y position floating view I have on the screen with the list view. b is the view I am setting just as an example.
NOTE: This is used in the onScroll event of the list view.
View c = view.getChildAt(0);
if (c != null) {
int currY = c.getTop();
int diffY = currY - lastY;
lastY = currY;
b.setTop(b.getTop() + diffY);
}
Now the issue is, the header of my List is a non fixed height as I said earlier. So I need to get the height of the header and apply an offset to "b" to place it at the bottom of the list header floating above the list.
This is the code I've tried so far.
header.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
The issue here us header.getMeasuredHeight(); always resolves to the same value no matter how tall the actual height is.
I understand I cannot get the height until after it is displayed. Is there a way I can get that value and set the offset after it is rendered?
Update 10/11/13
I Answered my last question as soon as I woke up this morning.
While the View.measure() code was returning a height. It appears to be the default height of the view, assuming there was no text (that would ultimately stretch the view). So I used the below event to listen for when the view is displayed, and then record its actual height (which works exactly as I had hoped :) )
ViewTreeObserver vto = header.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
b.setY(header.getMeasuredHeight() - 80); //80 is a temp offset
}
});
I have to go to work soon and being that I have still not fully achieved the desired effect, I will not mark this as answered yet. Hopefully I will be able to sit down and finish this in the next day or two. I am still open to suggestions on better ways of doing this.
Okay, so after a lot of time and research, I have found an answer to my question.
First off, Thank you #kaushal for this link: http://www.pushing-pixels.org/2011/07/18/android-tips-and-tricks-synchronized-scrolling.html
My solution ended up being somewhat complex. So instead of trying to describe it here, I made an example app and posted it here: https://github.com/gh123man/Partial-Header-ListView-Scroll-Sync
The specific file containing the code for the solution is here: https://github.com/gh123man/Partial-Header-ListView-Scroll-Sync/blob/master/src/com/example/partialheaderlistviewscrollsync/MainActivity.java

Categories

Resources