Scroll up and scroll down using AccessibilityNodeInfo in Accessibility Service - android

I want to perform scroll using Accessibility service and i am doing this
public boolean scrollView(AccessibilityNodeInfo nodeInfo) {
if (nodeInfo == null) return false;
if (nodeInfo.isScrollable()) {
return nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
for (int i = 0; i < nodeInfo.getChildCount(); i++) {
if (scrollView(nodeInfo.getChild(i)) {
return true;
}
}
return false; }
But problem is when there are four option to perform up,down left and right it performs left and right but i want to perform up and down there also.
like in facebook app it scroll on top section where notifications and news feed are.But not on page.
is there any way to scroll where is focus of user.

You're probably scrolling the wrong container. There are likely multiple views in your heirarchy that are "scrollable". Try finding different scrollable views within your heirarchy.
Also, in Android M they added APIs to do things like specifically scroll different directions. So, if you are in fact on the correct View, you can scroll in different directions using these actions instead:
ACTION_SCROLL_FORWARD
ACTION_SCROLL_LEFT
ACTION_SCROLL_RIGHT
etc.
https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.AccessibilityAction.html

Related

Is it possible to show staggered layout in pure list view

I want to make collapsible custom action bar. So I used RadListView with staggered layout. then with the help of its scroll events as below.
let lastOffset;
exports.onScrollStarted = function (args) {
lastOffset = args.object.getScrollOffset();
}
exports.onScrollDragEnded = function (args) {
let currentOffset = args.object.getScrollOffset();
let direction = currentOffset < lastOffset ? "up" : "down";
var scroll_difference = currentOffset - lastOffset
console.log(scroll_difference);
if (scroll_difference >= 5 || scroll_difference <= -5) {
console.log(direction)
if (direction == "down") {
wrap_animate.actionbar_hide(id_action_bar, id_content);
wrap_animate.shrink_view(id_bottom, id_selornt_logo);
} else if (direction == "up") {
wrap_animate.actionbar_show(id_action_bar, id_content);
wrap_animate.expand_view(id_bottom, id_selornt_logo);
}
lastOffset = currentOffset;
}
}
I achieved the collapsible view. but it will not work properly when I test it rigorously, i.e. when I scroll down and up without giving time.sometimes action bar will not hide or show properly. But it will work fine with normal list view as it supports scroll gesture event which gives top, down, left and right swipe event. But how to put staggered gird layout in normal list view. If that is possible then I can go for list view only as it fits all my requirement. except staggered gird layout which is common in all on line shopping apps. I want to want list view supports staggered list or not. and is there any better way to achieve this.

How can I change the background of views inside a recyclerview for certain items?

So essentially, I have a recyclerview that has a list of levels. But essentially, I want certain items to have a black colored background to suggest that they are not locked yet.(kind of like in video games)
my current method:
#Override
public void onBindViewHolder(BracketsAdapter.ViewHolder viewHolder, int position) {
// Get the data model based on position
Bracket bracket = bracketsList.get(position);
int color = UserPreferences.getInstance().getBracket();
// Set item views based on your views and data model
TextView textView = viewHolder.nameTextView;
textView.setText(bracket.toString());
Log.d("Bracket level", ""+bracket.getId());
if(color < bracket.getId()) {
textView.setBackgroundResource(R.color.black); // suggests level is locked
}
}
The issue with this method, is that it works initially but the moment I scroll down and back up, items that should not be colored end up being colored. Why is this? Is there a better way of implementing this?
Recycle view always reuses the old view so you are getting that problem, To solve the problem, you should set color every time calling bindViewHolder, So try to do like this,
if(color < bracket.getId()) {
textView.setBackgroundResource(R.color.black); // suggests level is locked
} else {
textView.setBackgroundResource(R.color.defaultcolor); // default color
}
this will work fine.

Compare Drawables on ImageViews

I'm trying to create a One-armed Bandit app.
I have created an animation xml file to go through multiple images. When a button is clicked, the animation stops.
My question is how to compare the picture that one animation stopped on with that of another? So far I've tried something like this:
if(wheel1.getBackground().getConstantState().equals(wheel2.getBackground().getConstantState())) matches++;
Any help is appreciated.
you must be starting the animation with .animationStart()
just use .onAnimationStop() and it will trigger the event automatically.
A View should not maintain application logic, the controller (your hosting Activity or Fragment) should.
That said, to achieve what you want use View.setTag() to apply a logical description of each View to it.
Then when stopping animation, loop through all Views you have and get their position on screen, get the Views mostly visible in each column of your bandit machine and compare their tags (View.getTag())
for example, if the items animate vertically use below method to determine where the bandit stopped.
//the area where to compare views
int BOUND_TOP, BOUNT_DOWN;
//your content view
ViewGroup rootLayout;
//method to get information about what is visible
public List<Object> getVisibleViewTags() {
List<Object> list = new LinkedList<>();
int count = rootLayout.getChildCount();
for (int pos = 0; pos < count; pos++) {
View child = rootLayout.getChildAt(pos);
float translationY = child.getTranslationY();
if (translationY > BOUND_TOP && translationY < BOUND_DOWN) {
list.add(child.getTag());
}
}
return list;
}
Now you just need to attach information about a view as tag to it.
example:
view.setTag("view_apples");
or
view.setTag("view_bananas");

Android RatingBar aligned right

I have a custom rating bar in which i edited from this tutorial (http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/)
I only want to show full cookies and not empty ones hence i replaced the empty-cookie.png with just a transparent image.
My problem is, in my UI i want my visible cookies to be right aligned, in other words, to be shown from right to left instead of the current left to right.
How can i achieve that? i DO NOT NEED to show half cookies and this is only used as an indicator (android:isIndicator="true")
Alternate non-ratingbar solutions are welcomed too. :)
i solved this by setting visibilities of multiple ImageViews stored in an array and displayed using a RelativeLayout in the end.
private void setClocksVisible(int numClocks) {
if(numClocks == 0 || numClocks == -1) {
for(int i=0; i< holder.ratingClocks.length; i++) {
holder.ratingClocks[i].setVisibility(View.INVISIBLE);
}
} else {
for(int i=0; i<numClocks; i++) {
holder.ratingClocks[i].setVisibility(View.VISIBLE);
}
}
}

Autoadvancing gallery animation

I have a Gallery widget set up to auto advance every 10000ms. However the transition between views is instantaneous and I would prefer to have a transition.
My advancing method is like so:
private void tickerAdvance() {
int selectedItemPosition = mTickerGallery.getSelectedItemPosition();
if (selectedItemPosition + 1 == mTickerGallery.getCount()) {
mTickerGallery.setSelection(0, true);
} else {
mTickerGallery.setSelection(selectedItemPosition + 1, true);
}
}
I was under the impression that setting the animation to true would cause it to animate between states. In my XML I've also added animationDuration="500", however the transition still pops between states instantly.
The problem is because you have used the setSelection() which obviously won't give you the feel of an Gallery being scrolled. SO instead of using setSelection() you have to override the onScroll() of gallery.
Here is how you do it.
Assuming that you have made the necessary steps for auto advancing periodically, now do this code.
MotionEvent e1, e2;
gallery.onScroll(e1, e2, scroll_limit , 0); //scroll limit is your integer variable for scroll limit.
The answer I came up with is that the Gallery API is terribly non-extensible. There are multiple package private or private methods that would unlock this functionality without a kludge including moveNext, FlingRunnable.startwithdistance, and scrollToChild. Alas, they are all unavailable.
Instead the best answer I was able to come up with was to override setSelection to get all the behaviors I needed. In the setSelection method I reverse the deceleration algorithm to calculate a velocity for a calculated distance and then call onFling. This is a nasty kludge could be made a ton better by making any of the above methods protected or public (I can't fathom a reason why at least moveNext and scrollToChild shouldn't be).
i had a similar task to make item to item animation and i decided to choose gallery, so i tried a lot of things, but the best way is to subclass gallery and add this:
boolean avoidSound = false;
public void showNext() {
avoidSound = true;
this.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
}
public void playSoundEffect(int soundConstant) {
if (avoidSound) {
avoidSound = false;
} else {
super.playSoundEffect(soundConstant);
}
}
just call showNext() and it will do an animation

Categories

Resources