I want to know how to perform these actions in holoeverywhere:
Get reference to the currently visible and active fragment from the activity when using slider addon in combination with tabber.
Get reference to TabsTabsSwipeFragment from the activity/other fragments and dynamically disable/enable swiping.
For getting the current active and visible Fragment, it's my understanding that HoloEverywhere uses Android's Support Library. Try something similar to "get currently displayed fragment."
public Fragment getActiveFragment() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
return null;
}
String tag = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName();
return getSupportFragmentManager().findFragmentByTag(tag);
}
That said, when using ActionBar tabs this may get complicated because two or more Fragments can be visible at any given time (i.e. swiping between the two). You may wish to give your Fragments tags and search for them manually by querying the isVisible
method.
Now for disabling swiping, I have no idea what TabsTabsSwipeFragment is but you can get a reference to any Fragment by querying their tag from the Fragment manager, of if you really want by looping through all Fragments and comparing the class (Object.getClass
). Disabling a ViewPager from being swiped can be accomplished by something similar to "How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?"
package com.yourcompany;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class SwipeableViewPager extends ViewPager {
private boolean swipeable = true;
public SwipeableViewPager(Context context) {
super(context);
}
public SwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setSwipeable(boolean swipe) {
this.swipeable = swipe;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return (swipeable) super.onInterceptTouchEvent(event) : false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return (swipeable) super.onTouchEvent(event) : false;
}
}